akhauriyash/Code-Regression huggingface dataset:
// Last Change: 08/26/2019 03:45:08.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

int main() {
  ll N, a, b;
  cin >> N;
  vector<vector<ll>> edge(N, vector<ll>());
  for (ll i = 0; i < N - 1; ++i) {
    cin >> a >> b;
    --a, --b;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }

  vector<int> reached(N, 0);
  ll dist = 0;
  queue<tuple<ll, ll>> q;
  q.push(make_tuple(0, 0));
  while (!q.empty()) {
    auto cur = q.front();
    dist = get<1>(cur);
    reached[get<0>(cur)] = dist;
    if (get<0>(cur) == N - 1) {
      break;
    }
    q.pop();
    for (auto &&e : edge[get<0>(cur)]) {
      if (reached[e] == 0) {
        q.push(make_tuple(e, get<1>(cur) + 1));
      }
    }
  }

  // cout << endl;
  // cout << dist << endl;
  // for (auto &&e : reached) {
  //  cout << e << ' ';
  //}
  // cout << endl;
  // cout << endl;

  queue<ll> q2;
  q2.push(N - 1);
  ll cnt = 1;
  ll x = dist / 2;
  while (!q2.empty()) {
    auto cur = q2.front();
    q2.pop();
    reached[cur] = -1;
    for (auto &&e : edge[cur]) {
      if (reached[e] == 0 or reached[e] > x) {
        q2.push(e);
        ++cnt;
      }
    }
  }

  //以下修正必須
  if (N - cnt > cnt) {
    cout << "Fennec" << endl;
  } else {
    cout << "Snuke" << endl;
  }
}


Measured memory_bytes: 6912
#include <bits/stdc++.h>
#define rep(i,x) for(long long i=0;i<x; i++)
#define INF 100010000
typedef long long  ll;
using namespace std;


int main(){
 int X,Y,Z;
  cin>>X>>Y>>Z;
  cout<<Z<<' '<<X<<' '<<Y;
}


Measured memory_bytes: 256
import java.util.*

fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

data class Edge(val from: Int, val to: Int)

fun main(args: Array<String>) {
    val N = readInt()
    val graph = Array(N) { mutableListOf<Int>() }
    val edges = Array(N - 1) { Edge(-1, -1) }

    for (i in 0 until N - 1) {
        val tmp = readIntList()
        edges[i] = Edge(tmp[0] - 1, tmp[1] - 1)
        graph[edges[i].from].add(edges[i].to)
        graph[edges[i].to].add(edges[i].from)
    }

    val colorMap: MutableMap<Edge, Int> = mutableMapOf()
    var K = 0
    val isUsed = Array(N) { false }
    isUsed[0] = true
    val parentColor = Array(N) { 0 }

    val queue = ArrayDeque<Int>()
    queue.add(0)

    while (queue.isNotEmpty()) {
        val node = queue.pop()
        K = graph[node].size.coerceAtLeast(K)
        var currentColor = 1

        for (i in graph[node]) {
            if (isUsed[i]) continue
            if (currentColor == parentColor[node]) currentColor++
            parentColor[i] = currentColor
            colorMap[Edge(node, i)] = currentColor
            colorMap[Edge(i, node)] = currentColor
            currentColor++
            isUsed[i] = true
            queue.add(i)
        }
    }

    println(K)
    for (edge in edges) {
        println(colorMap[edge])
    }
}


Measured memory_bytes: 102280
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define F first
#define S second
//#define biGinf 9e+18
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define inpv(v) for(auto &x:v) cin>>x
#define otpv(v) for(auto &x:v) cout<<x<<nwl
#define otpv2(v) for(auto &x:v) cout<<x<<" "
#define CASES int tt;cin>>tt; while(tt--)
#define for0(i,n) for(int i=0; i<n; i++)
#define sz(v) (int)(v).size()
using vi = vector < int >;
using vii = vector < vi >;
using pii = pair < int , int >;
using vpii = vector < pii >;
using int64 = long long;
//const int64 biGinf = 9e+18;
//const string yo = "YES", no = "NO";
const int inf = 2e9 + 7;
const char nwl = '\n';

int64 dp[105][101010];


int64 fun(vpii &v, int64 w, int64 n, int64 i = 0, int64 s = 0) {
	if (s == w or i == n)
		return 0;
	//if (dp[i] == -1) {
	if (dp[i][s] == -1) {
		int64 a;
		int64 b = fun(v, w, n, i + 1, s);
		if (s + v[i].F <= w) {
			int64 a = v[i].S + fun(v, w, n, i + 1, s + v[i].F);
			dp[i][s] = max(a, b);
		}
		else {
			dp[i][s] = b;
		}
	}
	return dp[i][s];


}


int main() {
#ifndef ONLINE_JUDGE
	if (fopen("input.txt", "r")) {
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	}
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//ur code
	for (int64 i = 0; i < 105; i++)
		for0(j, 100005) dp[i][j] = -1;
	int64 n, w;
	cin >> n >> w;
	vpii v;
	for0(i, n) {
		int64 x, y;
		cin >> x >> y;
		v.pb({x, y});
	}
	cout << fun(v, w, n);

	return 0;
}

Measured memory_bytes: 83072
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i,n) for(int i = 0; i < n; i++)

int f(int n) {
	int ret = 0;
	while (n) {
		ret += n % 10;
		n /= 10;
	}
	return ret;
}

int main() {
	int n, a, b;
	cin >> n >> a >> b;
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		int sum = f(i);
		if (a <= sum && sum <= b) ans += i;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#!/mnt/c/Users/moiki/bash/env/bin/python
N, K = map(int, input().split())
# = int(input())
h = []
sums = [0]
for i in range(N):
    h.append(int(input()))

h = sorted(h)
diff = []
bef = 0
for e,i in enumerate(h):
    if e == 0:
        bef = i
    else:
        diff.append(i - bef)
        bef = i
        # sums.append(diff[e-1])

diffin = 0
for n in diff:
    sums.append(sums[diffin] + n  )
    diffin += 1

# print("sums: {}".format(sums))
mins = 10e9
leng = len(sums)
for i in range(leng-K+1):
    # print("sums[{}]: {}, sums[{}]: {}".format(i+K-1,sums[i+K-1], i, sums[i]))
    mins = min(mins, sums[i+K-1] - sums[i])
print(mins)



Measured memory_bytes: 15680
from itertools import accumulate

def divisors(N):
    U = int(N ** 0.5) + 1
    L = [i for i in range(1, U) if N % i == 0]
    return L + [N // i for i in reversed(L) if N != i * i]

N, K, *A = map(int, open(0).read().split())

for d in reversed(divisors(sum(A))):
    R = [0] + list(accumulate(sorted(a % d for a in A)))
    for i in range(N):
        l = R[i]
        r = (N - i) * d - (R[N] - R[i])
        if max(l, r) <= K:
            print(d)
            quit()


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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n; cin>>n;
	vector<int> a(n+1,-1);
	for (int i=1; i<=n; i++)
		cin>>a[i];
	stack<int> stk;
	while(1) {
		bool up=false;
		int sz=a.size();
		for (int i=sz-1; i>=1; i--)
			if(a[i]==i) {
				up=true;
				stk.push(i);
				a.erase(a.begin()+i);
				break;
			}
		if(!up) break;
	}
	if(stk.size()!=n) {
		cout<<-1<<"\n";
		return 0;
	}
	while(!stk.empty())
		cout<<stk.top()<<"\n", stk.pop();
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>


using namespace std;



const map<string, int> command = { 
	{"r", 0},
	{"s", 1}, 
	{"p", 2}
};


int main()
{
	int n, k;

	int point[3];

	cin >> n >> k;
	for (int i = 0; i < 3; i++) cin >> point[i];


	vector<string> mod(k,"");

	string str;
	cin >> str;

	int answer = 0;


	for (int i = 0; i < n; i++) {

		string te = str.substr(i, 1);

		if (mod[i % k] == te) {
			mod[i % k] = "";
			answer += 0;
		}
		else {
			mod[i % k] = te;
			auto a = command.find(te);
			answer += point[(a->second + 2) % 3];
		}
	}

	cout << answer << endl;


	return 0;
}


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

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

Measured memory_bytes: 3632
#include<stdio.h>
int main()
{
	char s;
	long long t,a,b;
	while(scanf("%lld %c %lld",&a,&s,&b)!=EOF)
	{
		if(s=='+')
			t=a+b;
		else if(s=='-')
			t=a-b;
		printf("%lld\n",t);
	}
	return 0;
}

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

#define int long long

using namespace std;

#define MOD 1000000007
#define SZ 105


int32_t main()
{
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);

        int a,b,c;
        cin>>a>>b>>c;

        int freq[11]={0};

        freq[a]++;
        freq[b]++;
        freq[c]++;

        if(freq[5]==2 && freq[7]==1)
        {
                cout<<"YES"<<endl;
        }
        else
        {
                cout<<"NO"<<endl;
        }

        return 0;

}

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

int main()
{
    int n,k;
    string s;
    //char ch = 'A' + 32;
    //cout << ch<<endl;
    cin >> n >> k >> s;
    s[k - 1] = s[k - 1] + 32;
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int,int>;
using PLL = pair<LL, LL>;
const int INF = 1e9;
const int MXN = 0;
const int MXV = 0;
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define FOR(i, L, R) for(int i = L; i != (int)R; ++i)
#define FORD(i, L, R) for(int i = L; i != (int)R; --i)
#define IOS cin.tie(nullptr); cout.tie(nullptr); ios_base::sync_with_stdio(false);

int main()
{
    IOS;
    string s, t, u;
    int m, n;
    cin >> s >> t >> m >> n >> u;
    if(s == u)
    {
        cout << m - 1 << ' ' << n << '\n';
    }
    else
    {
        cout << m << ' ' << n - 1 << '\n';
    }
}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
bool before[100500];
bool after[100500];

int main() {
    //cout.precision(10);
    int N, Q;
    cin >> N >> Q;
    before[1] = true;
    after[2] = true;
    while(Q--) {
        int a, b;
        cin >> a >> b;
        swap(before[a], before[b]);
        swap(after[a], after[b]);
        /*
        before[a] |= before[b];
        before[b] |= before[a];
        after[a] |= after[b];
        after[b] |= after[a];
        */
        after[a+1] |= (before[b] || before[a]);
        after[a-1] |= (before[b] || before[a]);
        after[b-1] |= (before[a] || before[b]);
        after[b+1] |= (before[a] || before[b]);
        after[a] |= (before[a-1] || before[a+1]);
        after[b] |= (before[b-1] || before[b+1]);
    }
    int ans = 0;
    for(int i = 1; i <= N; i++) {
        if(after[i] || before[i]) {
            cerr << i << endl;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#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;

using u128 = __uint128_t;

#define int long long
#define index_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define atIndex find_by_order
#define indexOf order_of_key
#define MOD 1000000007
#define MAX 200005

int dp[MAX];

void solve() {
    int a , b , h;
    cin>>a>>b>>h;
    cout<<h * (a + b) / 2 <<endl;
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    //cin>>t;
    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;

const ll MOD = 1e9 + 7; 

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF_INT (1<<30)
#define INF_LL (1ll<<62)

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

ll N,R,W,LR;
string tmp;

int main(){
    cin>>N;
    cin>>tmp;
    rep(i,N){
        char tt = tmp[i];
        if(tt=='R')R++;
        else W++;
    }
    rep(i,R){
        if(tmp[i]=='R')LR++;
    }
    out(min(R-LR,min(N-R,N-W)));

    
    
}

Measured memory_bytes: 3680
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>
#include <bitset>
#define range(i, r) for(int i=0;i<r;i++)
#define ranges(i, l, r) for(int i=l;i<r;i++)
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
#define MODn 1000000009;
typedef long long int ll;
using namespace std;
#define MAX_N 300000
std::vector<int> par(MAX_N);
int dep[MAX_N];
int size[MAX_N];

void init(int nu) {
  for(int iu=0;iu<nu;iu++){
    par[iu] = iu;
    dep[iu] = 0;
    size[iu] = 1;
  }
}
int find(int xu){
  if(par[xu] == xu) return xu;
  return par[xu] = find(par[xu]);
}
void unite(int xu, int yu){
  xu=find(xu);
  yu=find(yu);
  if(xu == yu) return;
  if(dep[xu] < dep[yu]){
    par[xu] = yu;
    size[yu] += size[xu];
  }else{
    par[yu] = xu;
    size[xu] += size[yu];
    if(dep[xu] == dep[yu]) dep[xu]++;
  }
}
bool same(int xu, int yu){
  return find(xu) == find(yu);
}

int main(int argc, char const *argv[]) {
  int N, M;
  std::cin >>  N >> M;
  init(N);
  int x, y, z;
  range(i, M) {
    std::cin >> x >> y >> z;
    unite(x-1, y-1);
  }
  int count=0;
  for(int i=0;i<N;i++) {
    if(!same(0, i)) count++, unite(0, i);
  }
  std::cout << count + 1 << '\n';
  return 0;
}


Measured memory_bytes: 2176
#include<iostream>

using namespace std;

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

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

int main() {
  string s;
  cin >> s;
  
  int n = s.size();
  int ans = 0;
  REP(i,n/2){
    if(s[i] != s[n-i-1]) ans++;
  }
  cout << ans << endl;
}

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


class Main{
	public static void main(String[] args) {
		FastReader f = new FastReader();
		int n = ii(f), k = ii(f);
		int[] arr = new int[n+1];
		for(int i=1; i<=n; i++)
			arr[i] = ii(f);
		int[] dp = new int[n+1];
		dp[1] = 0;
		for(int i=2; i<=n; ++i){
			int j=i-1;
			int m = Integer.MAX_VALUE;
			while(j >= 1 && i-j <= k){
				m = min(m, Math.abs(arr[i] - arr[j]) + dp[j]);
				j--;
			}
			dp[i] = m;
//			System.out.println(m);
		}
		printn(dp[n]);
	}


	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new
					InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

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

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

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

	public static int ii(FastReader fr){
		return fr.nextInt();
	}

	static long il(FastReader fr){
		return fr.nextLong();
	}

	static double id(FastReader fr){
		return fr.nextDouble();
	}

	static void printArray(Object[] arr) {
		for (Object x : arr)
			print(x, " ");
		printn("");
	}

	static void print(Object s, String sep) {
		System.out.print(s + sep);
	}

	static void printn(Object s) {
		System.out.println(s);
	}

	static long[] inputArrL(int n, FastReader fr) {
		long[] arr = new long[n];
		for (int i = 0; i < n; i++)
			arr[i] = fr.nextLong();
		return arr;
	}

	static int[] inputArr(int n, FastReader fr) {
		int[] arr = new int[n];
		for (int i = 0; i < n; i++)
			arr[i] = fr.nextInt();
		return arr;
	}

	static int max(int... args) {
		int max = Integer.MIN_VALUE;
		for (int x : args) {
			max = Math.max(x, max);
		}
		return max;
	}

	static int min(int... args) {
		int min = Integer.MAX_VALUE;
		for (int x : args) {
			min = Math.min(x, min);
		}
		return min;
	}

	static long max(long... args) {
		long max = Integer.MIN_VALUE;
		for (long x : args) {
			max = Math.max(x, max);
		}
		return max;
	}

	static long min(long... args) {
		long min = Integer.MAX_VALUE;
		for (long x : args) {
			min = Math.min(x, min);
		}
		return min;
	}

	static int lenDigit(int d) {
		if (d == 0)
			return 1;
		int l = 0;
		while (d != 0) {
			l++;
			d /= 10;
		}
		return l;
	}

}



Measured memory_bytes: 89664
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] a = new int[n];
		int aSum = 0;
		for (int i = 0; i < n; ++i) {
			a[i] = sc.nextInt();
			aSum += a[i];
		}

		Arrays.sort(a);
		double required = 1.0 * aSum / (4 * m);
		if (a[n - m] >= required) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}

}


Measured memory_bytes: 21844
#include <stdio.h> 

int main() {
  int n,x;
  int b,i,j,k,a;

  while(1) {
    scanf("%d %d",&n,&x);   
    b = 0;
    if( n == 0 && x == 0){
      break;
    }
    for(k = 1; k <= n ; k++) {


      for(j = 1; j <= n ; j++) {

	for(i = 1; i <= n; i++) {
	  
	  if(i == j || j == k || i ==k) {
	    
	  }else{
	    a = i + j + k;
	    if(a == x) {
	     
	      b += 1;
 
	    }
	  }
	  
	}//i
	
      }//j

    }//k
    printf("%d\n",b/6);
  }


  return 0;
}


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

using namespace std;

using ll = long long;
using ull = unsigned long long;

int main(int argc, char const *argv[]) {
	int a,b;
	std::cin >> a >> b;
	std::cout << (a+b)/2 + (a+b)%2 << '\n';
	return 0;
}


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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int n, k; cin >> n >> k;
  int ans = 0;
  for(int i=0;i<n;++i) {
    int tmp; cin >> tmp;
    ans += 2 * min(tmp, abs(k - tmp));
  }
  cout << ans << endl;

  

}


Measured memory_bytes: 256
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long ll;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set; 
const ll INF = 1e18 + 10 ; 
int main(){
    fastio
    ll n ;
    cin >> n ; 
    vector<ll> v(n+1) ; 
    for(ll i=1;i<=n;i++){
    	cin >> v[i] ; 
    }
    ll dp[n+1] ; // the minimum cost up the current stone
    for(ll i=0;i<=n;i++){
    	dp[i] = INF ; 
    }
    dp[0] = dp[1] = 0 ; 
    dp[2] = abs(v[2]-v[1]) ;
    for(ll i=3;i<=n;i++){
    	dp[i] = min(abs(v[i]-v[i-1])+dp[i-1],abs(v[i]-v[i-2])+dp[i-2]);
    }
    cout << dp[n] << endl;
    return 0 ;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define endl "\n"
#define ll long long int
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second
#define MAXN 1000007
#define fr(i, s, e, st) for(ll (i) = (s); (i) < (e); (i) += (st))
#define fre(i, s, e, st) for(ll (i) = (s); (i) <= (e); (i) += (st))
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);

using namespace std;
bool equals(ll a[], ll b[], ll n)
{
    fr(i, 0, n, 1)
        if(a[i]!=b[i]) return false;
    return true;
}

int main()
{
    fastio;
    int T = 1;
    while(T--){
        ll n;
        cin>>n;
        ll a[n], b[n];
        fr(i, 0, n, 1) cin>>a[i];
        fr(i, 0, n, 1) cin>>b[i];
        ll c[n];
        fr(i, 0, n, 1) c[i] = i+1;
        ll a1=0, b1=0;
        while(!equals(a, c, n) and !equals(b, c, n))
        {  
            a1++; b1++;
            next_permutation(c, c+n);
        }
        if(equals(a, c, n))
            while(!equals(b, c, n))
            {  
                b1++;
                next_permutation(c, c+n);
            }
        else
            while(!equals(a, c, n))
            {  
                a1++;
                next_permutation(c, c+n);
            }
        cout<<abs(a1-b1)<<endl;
    }                                               
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define x first
#define y second
#pragma gcc optimize("O3")
#pragma gcc optimize("Ofast")
#pragma gcc optimize("unroll-loops")
using namespace std;
const long long INF = 1e18;
const long long mod = 998244353;
typedef long long ll;
typedef long double ld;
typedef pair <int,int> pi;
typedef pair <ll,ll> pl;
typedef vector <int> vec;
ll n,X,m,sum,ans;
ll d[300005],sd[300005];
int c[200005],st,i,en;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n >> X >> m;
	d[1] = sd[1] = ans = X;
	c[X] = 1;
	st = en = n+1;
	for(i = 2;i <= min(n,m+5);i++) {
		d[i] = d[i-1]*d[i-1]%m;
		sd[i] = sd[i-1]+d[i];
		ans += d[i];
		if(c[d[i]]) {
			st = i;
			break;
		}
		c[d[i]] = 1;
	}
	for(i = st+1;i <= min(n,m*2+10);i++) {
		d[i] = d[i-1]*d[i-1]%m;
		sum += d[i];
		sd[i] = sd[i-1]+d[i];
		if(d[i] == d[st]) {
			en = i;
			break;
		}
	}
	if(st == n+1) cout << ans;
	else {
		if(en == n+1) cout << ans+sum;
		else {
			cout << ans+sum*((n-st)/(en-st))+(sd[st+(n-st)%(en-st)]-sd[st]);
		}
	}
 	return 0;
}

Measured memory_bytes: 5456
#include<bits/stdc++.h>
#define f(i,n) for(int i=0;i<n;i++)
#define fo(i,a,n) for(int i=a;i<n;i++)
#define ll long long int
#define li long int
using namespace std;
int main()
{
    int n;
    cin>>n;
    vector<int> h(n);
    vector<int> dp(n);
    f(i,n)
        cin>>h[i];
    dp[1]=abs(h[0]-h[1]);
    fo(i,2,n)
    {
        dp[i]=min(abs(h[i]-h[i-2])+dp[i-2],abs(h[i]-h[i-1])+dp[i-1]);
    }
    cout<<dp[n-1];
}


Measured memory_bytes: 3980
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const int INF = 2e9;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
  ll l, r;
  cin >> l >> r;
  if(r-l>=2019){
    print(0);
  }
  else{
  l %= 2019;
  r %= 2019;
  if(l>r){
    swap(l, r);
  }
  ll ans = INF;
  for (ll i = l; i < r; i++){
    for (ll j = i+1; j <= r;j++){
      ll tmp = i * j;
      tmp %= 2019;
      chmin(ans, tmp);
    }
  }
  print(ans);
  }
}

Measured memory_bytes: 256
import math
dig_six = math.radians(60)

def koch(d, p1, p2):
    if d == 0:
        return d
    #calc s, u, t from p1, p2
    s_x = (2*p1[0]+1 * p2[0]) / 3
    s_y = (2*p1[1]+1 * p2[1]) / 3
    s = (s_x, s_y)
    t_x = (1*p1[0]+2 * p2[0]) / 3
    t_y = (1*p1[1]+2 * p2[1]) / 3
    t = (t_x, t_y)
    u_x = (t_x - s_x)*math.cos(dig_six) - (t_y - s_y)*math.sin(dig_six) + s_x
    u_y = (t_x - s_x)*math.sin(dig_six) + (t_y - s_y)*math.cos(dig_six) + s_y
    u = (u_x, u_y)
    
    koch(d-1, p1, s)
    print (' '.join([str(x) for x in s]))
    koch(d-1, s, u)
    print (' '.join([str(x) for x in u]))
    koch(d-1, u, t)
    print (' '.join([str(x) for x in t]))
    koch(d-1, t, p2)

if __name__ == '__main__':
    iterate = int(input())
    p1 = (0.0, 0.0)
    p2 = (100.0, 0.0)
    print (' '.join([str(x) for x in p1]))
    koch(iterate, p1, p2)
    print (' '.join([str(x) for x in p2]))


Measured memory_bytes: 5748
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1e9;
int MOD = 1e9+7;
main(){
    int H,W,N,A[100000];
    cin >> H >> W >> N;
    for(int i = 0;i < N;i++)cin >> A[i];
    for(int i = 0,idx = 0;i < H;i++){
        vector<int> num(W);
        for(int j = 0;j < W;j++){
            if(!A[idx])idx++;
            num[j] = idx+1;
            A[idx]--;
        }
        if(i % 2){
            reverse(num.begin(),num.end());
        }
        for(int n:num)cout << n << " ";
        cout << endl;
    }
}

Measured memory_bytes: 384
const main = (input) => {
  const [s, t] = input.trim().split('\n')
  let ans = Infinity

  for (let x=0; x <= s.length-t.length; x++) {
    let count = 0
    for (let tx=x, y=0; y<t.length; tx++, y++) if (s[tx] !== t[y]) count++
    ans = Math.min(ans, count)
  }

  return console.log(ans)
}

process.env.MYTEST ? test() : main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 32596
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int d = sc.nextInt();
    
    int ab = a * b;
    int cd = c * d;
    
    if (ab == cd) {
      System.out.println(ab);
    } else if (ab > cd) {
      System.out.println(ab);
    } else if (cd > ab) {
      System.out.println(cd);
    }
  }
}

Measured memory_bytes: 21972
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include <cassert>
    #include <cmath>

    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))

    using namespace std;
    using ll = long long;
    using Graph = vector<vector<int>>;
    using P = pair<int,int>;

    int main(){
      ll n;cin>>n;
      map<ll,ll>mp;
      rep(i,n){
          ll a;cin>>a;
          mp[a]++;
          if(mp[a]>1){
              cout<<"NO";return 0;
          }
      }
      cout<<"YES";
    }
    


Measured memory_bytes: 12800
N = int(input())
A,B=[int(_) for _ in input().split()]
aP=[int(_) for _ in input().split()]
dA=[0]*3
for i in range(N):
    p = aP[i]
    if p <= A:
        dA[0] += 1
    elif p <= B:
        dA[1] += 1
    else:
        dA[2] += 1
print (min(dA))


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,u) for(int i=start[u];i;i=e[i].next)
#define fi first
#define se second
#define mkr(a,b) make_pair(a,b)
#define SZ(A) ((int)A.size())
template<class T>inline void chkmin(T &a,T b){ if(a>b)a=b;}
template<class T>inline void chkmax(T &a,T b){ if(a<b)a=b;}
inline void myassert(bool a,string s){ if(!a)cerr<<s<<endl,exit(0);}
inline int read()
{
	int s=0,f=1;char ch=getchar();
	while(!isdigit(ch) && ch!='-')ch=getchar();
	if(ch=='-')ch=getchar(),f=-1;
	while(isdigit(ch))s=s*10+ch-'0',ch=getchar();
	return ~f?s:-s;
}

const int maxn=1e5+20;

int prime[maxn],ptot,mark[maxn];

inline void prepare()
{
	REP(i,2,1e5)
	{
		if(!mark[i])prime[++ptot]=i;
		for(int j=1,k;j<=ptot && i*prime[j]<=1e5;j++)
		{
			k=i*prime[j]; mark[k]=1;
			if(!(i%prime[j]))break;
		}
	}
}

int n;
ll a[520][520];
int mpa[maxn],mpb[maxn];

inline void init()
{
	int now=0;
	n=read();
	if(n==2)
	{
		printf("4 7\n23 10\n");exit(0);
	}
	REP(i,1,n)REP(j,1,n)if(~i+j&1)
	{
		if(!mpa[i+j])
			mpa[i+j]=prime[++now];
	}

	REP(i,1,n)REP(j,1,n)if(~i+j&1)
	{
		if(!mpb[i-j+n])
			mpb[i-j+n]=prime[++now];
		a[i][j]=1ll*mpa[i+j]*mpb[i-j+n];
	}
	REP(i,0,1e4)chkmax(mpa[i],1),chkmax(mpb[i],1);
	REP(i,1,n)REP(j,1,n)if(i+j&1)
	{
		a[i][j]=1ll*mpa[i+j-1]*mpa[i+j+1]*mpb[i-j-1+n]*mpb[i-j+1+n]+1;
		//if(a[i][j]>=(1e15))
			//	printf("%d %d %lld",i,j,a[i][j]),puts("GG"),exit(0);
	}
	REP(i,1,n)REP(j,1,n)printf("%lld%c",a[i][j],j==n?'\n':' ');
}

inline void doing()
{
	
}

int main()
{
	prepare();
	init();
	doing();
	return 0;
}


Measured memory_bytes: 5632
n,m=map(int,input().split())
AC=[0 for _ in range(n)]
WA=[0 for _ in range(n)]
pen=0
for _ in range(m):
    p,s=input().split()
    p=int(p)
    if s=="AC":
        if AC[p-1]==0:
            AC[p-1]=1
            pen += WA[p-1]
        else:
            pass
    else:
        if AC[p-1]==0:
            WA[p-1] +=1
        else:
            pass
print(AC.count(1),pen)
            

Measured memory_bytes: 4656
PROGRAM piyo
      IMPLICIT NONE
      INTEGER,PARAMETER :: p = 16
      character(3) :: s
      integer(p) :: i,ans,temp
      
      read*,s
      
      ans = 0
      temp = 0
      do i = 1,3
        if( s(i:i)=='R' )then
          temp = temp + 1
          ans = max(temp,ans)
        else
          temp = 0
        end if
      end do
      
      print*,ans
      
      
      
      stop
      !debugg
      
      
      
      END PROGRAM

Measured memory_bytes: 2852
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
#define INF ((ll)1e18)

int n;
const int sz=1e6;
ll a[sz],lmax[sz],rmin[sz];
void solve()
{
    priority_queue<ll,vector<ll>,greater<ll> >que;
    lmax[0]=0;
    for(int i=0;i<n;i++)
    {
        lmax[0]+=a[i];
        que.push(a[i]);
    }
    for(int i=1;i<=n;i++)
    {
        que.push(a[n+i-1]);
        lmax[i]=lmax[i-1]-que.top()+a[n+i-1];
        que.pop();
    }
    for(int i=0;i<=n;i++)cerr<<i<<": "<<lmax[i]<<endl;

    priority_queue<ll> que2;
    rmin[0]=0;
    for(int i=0;i<n;i++)
    {
        rmin[0]+=a[3*n-1-i];
        que2.push(a[3*n-1-i]);
    }
    for(int i=1;i<=n;i++)
    {
        que2.push(a[2*n-i]);
        rmin[i]=rmin[i-1]-que2.top()+a[2*n-i];
        que2.pop();
    }
    for(int i=0;i<=n;i++)cerr<<i<<": "<<rmin[i]<<endl;

    ll res=-INF;
    for(int i=0;i<=n;i++)
    {
        ll ch;
        ch=lmax[i]-rmin[n-i];
        if(ch>res)res=ch;

    }
    cout<<res<<endl;
    return;
}
main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    scanf("%d",&n);
    for(int i=0;i<3*n;i++)scanf("%lld",a+i);
    solve();
    return 0;
}

Measured memory_bytes: 10996
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define INF 1LL<<50
#define fst first
#define sec second
#define pb push_back
#define int long long
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ITR(itr,mp) for(int itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(int itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define debug(x)  cout << #x << " = " << (x) << endl;
typedef long long ll;
typedef pair<ll,ll> P;

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

  int a[3];
  cin >> a[0] >> a[1] >> a[2];
  
  sort(a,a+3);
  
  if(a[0] == 5 && a[1] == 5 && a[2] == 7) cout << "YES" << endl;
  else 									  cout << "NO"  << endl;

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

int isPrime(int);

int main(){
  int n,i,j,c=0;
  int a[10000];

  scanf("%d",&n);

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

  for(i=0 ; i<n ; i++){
    c += isPrime(a[i]);
  }

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

  return 0;
}

int isPrime(int a){
  int i;

  if(a == 2) return 1;

  if(a<2 || a%2==0) return 0;

  i = 3;
  while(i<=sqrt(a)){
    if(a % i == 0) return 0;
    i += 2;
  }
  return 1;
}

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

int a[20200],b[20200];
int in[20200];
int ord[20200];

main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&in[i]);
		ord[in[i]]=i;
	}
	for(int i=1;i<=n;i++)
	{
		a[i]=a[i-1]+ord[i];
		printf("%d ",a[i]);
	}
	printf("\n");
	for(int i=n;i>=1;i--)
	{
		b[i]=b[i+1]+ord[i];
	}
	for(int i=1;i<=n;i++)
	{
		printf("%d ",b[i]);
	}
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

int main() {
    int H, N;
    cin >> H >> N;
    rep(i, N) {
        int a;
        cin >> a;
        H -= a;
    }
    if (H <= 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
// AOJ DSL_4_A Union of Rectangles
// 2018.5.14 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
int in()
{
	int n = 0, c = gc();
	if (c == '-') {	c = gc();
		do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
		return -n;
	}
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

#define MAX_N 2005
#define MAX   4005

int x1[MAX_N], y1[MAX_N], x2[MAX_N], y2[MAX_N];
int x[MAX], xs;
int y[MAX], ys;
char s[MAX][MAX];

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

int xbsch(int a)
{
	int m, l = 0, r = xs;

    while (l < r) {
        m = (l + r) >> 1;
        if (x[m] < a) l = m + 1; else r = m;
    }
	return l;
}
int ybsch(int a)
{
	int m, l = 0, r = ys;

    while (l < r) {
        m = (l + r) >> 1;
        if (y[m] < a) l = m + 1; else r = m;
    }
	return l;
}

int uniq(int *a, int n)
{
	int i, j;
	
	for (i = 0, j = 1; j < n; j++) {
		while (j < n && a[j] == a[i]) j++;
		if (j < n) if (++i != j) a[i] = a[j];
	}
	return i+1;
}

int main()
{
	int N, i, r, c, r1, c1, r2, c2;
	long long ans;

	N = in(); xs = ys = 0;
	for (i = 0; i < N; i++) {
		x1[i] = c = in(), y1[i] = r = in();
		x[xs++] = c, y[ys++] = r;
		x2[i] = c = in(), y2[i] = r = in();
		x[xs++] = c, y[ys++] = r;
	}
	qsort(x, xs, sizeof(int), cmp); xs = uniq(x, xs);
	qsort(y, ys, sizeof(int), cmp); ys = uniq(y, ys);

	for (i = 0; i < N; i++) {
		c1 = xbsch(x1[i]), c2 = xbsch(x2[i]);
		r1 = ybsch(y1[i]), r2 = ybsch(y2[i]);
		for (r = r1; r < r2; r++) for (c = c1; c < c2; c++) s[r][c] = 1;
	}

	ans = 0;
	for (r = 0; r < ys; r++) for (c = 0; c < xs; c++) {
		if (s[r][c]) {
			c1 = c++; while (s[r][c]) c++;
			ans += (long long)(x[c]-x[c1])*(y[r+1]-y[r]);
		}
	}
	printf("%lld\n", ans);
	return 0;
}



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

//#pragma gcc optimize("O3,unroll-loop")
//#pragma gcc target("sse,sse2,sse3,ssse3,sse4,avx,avx2,fma,abm,mmx,popcnt,tune=native")
//#define int long long
//#define double long double

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

    int a, b, c, d;
    cin >> a >> b >> c >> d;

    int ans = 0;
    if (d < a)
        ans += d, d = 0;
    else
        ans += a, d -= a;
    if (d < b)
        d = 0;
    else
        d -= b;
    cout << ans - d << '\n';

    return 0;
}

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

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


Measured memory_bytes: 3636
n = int(input())
a = list(map(int, input().split()))
B=[]
for i,ai in enumerate(a,start=1):
  B.append(ai-i)
c=sorted(B)
b=c[len(c)//2]

ans=0
for i in B:
  ans+=abs(i-b)
print(ans)

Measured memory_bytes: 26356
/* #                          */

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdint>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#include <string>
#include <deque>
#include <map>
//#pragma warning(disable:4996)

using namespace std;


/** Type Define **/
typedef long long int           ll;
typedef pair<int, int>          pii;
typedef pair<ll, ll>            pll;
typedef vector<string>          vs;
typedef vector<bool>            vb;
typedef vector<int>             vi;
typedef vector<long long>		vl;
typedef vector<vi>              vvi;
typedef vector<vl>				vvl;
typedef vector<char>            vch;

constexpr int               inf = 0x3f3f3f3f;
constexpr long long 		INF = 9123456789123456789;
constexpr long long         MOD = 1000000007LL;
/*************************************************/
int n, k;
vi a;
double p[1001];
double e[1001];
void prep() {
    p[0] = 0; e[0] = 0;
    for (int i = 1; i <= 1000; i++) {
        p[i] = p[i - 1] + i;
        e[i] = p[i] / i;
    }
}

void sol() {

}

int main() {
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cin.tie(nullptr);
    cin >> n >> k;
    prep();
    queue<double> a;
    double ans(0.0);
    int x;
    for (int i = 0; i < k; i++) {
        cin >> x;
        a.push(e[x]);
        ans += e[x];
    }
    double mx(ans);
    for (int i = k; i < n; i++) {
        cin >> x;
        a.push(e[x]);
        ans -= a.front();
        ans += e[x];
        a.pop();
        if (mx < ans) mx = ans;
    }

    cout << mx << endl;
    


    return 0;
}

Measured memory_bytes: 1920
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <climits> // FOO_MAX, FOO_MIN
#include <cmath> 
#include <cstdlib> // abs(int)
#include <iomanip>

using namespace std;

#define roundup(n,d) ( ((n) + ((d)-1)) / (d) )
#define assign_max(into, compared) (into = max((into), (compared)))
#define assign_min(into, compared) (into = min((into), (compared)))
#define rep(i,n) for(long long i = 0;i < n;i++)
using ll = long long;
using ull = unsigned long long;
using llv = vector<long long>;


int main(void){
    long double l;
    cin >> l;
    cout << fixed << setprecision(15) <<(l * l * l) / 27 << endl;
    return 0;
}

Measured memory_bytes: 3156
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define int long long
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18 * 5;

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

    int N, M, X;
    cin >> N >> M >> X;
    int lw =0, up =0;
    REP(i, M){
        int A;
        cin >> A;
        if(A<X) lw++;
        else up++;
    }
    cout << min(lw, up) << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  long long ans=1;
  cin>>n;
  for(int i=1;i<=n;i++){
    ans*=i;
    ans%=1000000007;
  }
  cout<<ans<<endl;
  return(0);
}
  


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def main():
    S = input().strip()
    K = int(input())
    
    for i, s in enumerate(S):
        if s != "1":
            print(s)
            exit()
        if i + 1 == K:
            print(s)
            exit()



if __name__ == '__main__':
    main()




Measured memory_bytes: 2940
'use strict';
(function(stdin) {
    var inputs = stdin.toString();
    var flines = inputs.split('\n')[0].split(' ').map(Number);
    var a = flines[0];
    var b = flines[1];
    var area = a * b ;
    var periphery = 2 * (a + b);
    console.log(area,periphery);
}(require('fs').readFileSync('/dev/stdin', 'utf8')));

Measured memory_bytes: 7376
#include<cstdio>
#include<algorithm>
using namespace std;
int t[100005],n,i,c,k,ans=0,sum=0,lm;
int main()
{
	scanf("%d%d%d",&n,&c,&k);
	for(i=1;i<=n;i++)scanf("%d",&t[i]);
	sort(t+1,t+n+1);lm=-1;
	for(i=1;i<=n;i++)
	{
		if(lm<t[i]||sum==c)
		{
			ans++;
			lm=t[i]+k;
			sum=0;
		}
		sum++;
	}
	printf("%d\n",ans);
	return 0;
 } 

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAX = 1e6+7;
const int MOD = 1e9+7;
const int INF = 0x3f3f3f3f;

int a, b, c, d;
int main()
{
    cin >> a >> b >> c >> d;
    a += b;
    c += d;
    if(a > c)
        puts("Left");
    else if(a < c)
        puts("Right");
    else
        puts("Balanced");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main(){
  string search, s;
  int cnt = 0;
  cin >> search;

  while(1){
    cin >> s;
    if(s == "END_OF_TEXT"){ break; }
    for(int i = 0; i < s.size(); i++){
      if('A' <= s[i] && s[i] <= 'Z'){
	s[i] = s[i] - 'A' + 'a';
      }
    }
    if(s == search){
      cnt++;
    }
  }

  cout << cnt << endl;
  
  return 0;
}



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

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
const int inf = 1000000001;
const ll INF = 1e16;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<<fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };

int main() {
	int a, b;
	cin >> a >> b;
	if (a == 1) {
		a = 14;
	}
	if (b == 1) {
		b = 14;
	}
	if (a > b) {
		cout << "Alice" << endl;
	}
	else if (b > a) {
		cout << "Bob" << endl;
	}
	else {
		cout << "Draw" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <tuple>
#include <vector>

using lli=long long int;
lli mod;

lli mod_normalize(lli a){
  return ((a%mod)+mod)%mod;
}

lli mod_inv(lli a){
  lli b=mod, u=1, v=0, tmp=0;
  while(b){
    lli t = a/b;
    a -= t*b;
    tmp = a; a = b; b = tmp; //swap(a, b);
    u -= t*v;
    tmp = u; u = v; v = tmp; //swap(u, v);
  }
  return mod_normalize(u);
}

class mod_comb_mul{
  std::vector<lli> fac, finv;
  public:
  mod_comb_mul() : fac(1,1), finv(1,1) {}
  lli comb(lli n, lli k){
    if(n < k || k < 0 || n < 0) return 0;
    int pre_size = fac.size();
    if(n >= pre_size){
      fac.resize(n+1);
      finv.resize(n+1);
      for(int i = pre_size; i <= n; i++) fac[i] = i*fac[i-1] % mod;
      finv[n] = mod_inv(fac[n]);
      for(int i = n; i > pre_size; i--) finv[i-1] = i*finv[i] % mod;
    }
    return fac[n] * (finv[k] * finv[n-k] % mod) % mod;
  }
};


int main(){
  std::cin >> mod;
  std::vector<int> ans(mod);
  mod_comb_mul mcm;
  for(int i = 0; i < mod; i++){
    int a;
    std::cin >> a;
    if(a == 0) continue;
    int tmp = 1;
    for(int j = mod-1; j >= 0; j--){
      ans[j] -= tmp*mcm.comb(mod-1, j)%mod;
      tmp = -i*tmp%mod;
    }
    ans[0] += 1;
  }
  for(int i = 0; i < mod; i++){
    std::cout << ((ans[i]%mod)+mod)%mod << (i==mod-1?"\n":" ");
  }

  return 0;
}



Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <iomanip>
using namespace std;

void solve(){
  int n; cin >> n;
  vector<int> a(n);
  int ans = 0;
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  for(int i = 0; i < n; i++){
    ans += a[i] - 1;
  }
  cout << ans << endl;
  return;
}
int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define ve vector
#define pq priority_queue
#define vi vector<int>
#define vl vector<long long>
#define vii vector<vector<int>>
using namespace std;
using ll = long long;
using ld = long double;
const ll mod = 1000000007;



int main()
{
    int n;
    cin >> n;
    ve<ve<ll>> a(10,ve<ll>(10,0));
    reps(i,1,n+1){
        string s = to_string(i);
        a[s.front()-'0'][s.back()-'0']++;
    }
    ll ans = 0;
    reps(i,1,10) reps(j,1,10) ans +=  a[i][j] * a[j][i];
    
    out(ans);


    return 0;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    int N;
    cin >> N;
    rep(i, N + 1) {
        if (i * 108 / 100 == N) {
            cout << i << '\n';
            return;
        }
    }
    cout << ":(" << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
typedef long long ll;
const char s[2]={'A','B'};
int a,b,c,d,q,k,nb;ll lim;
inline int calc(R int x){return (a-(b-x+k-1)/k)/k;}
inline int find(){
	R int l=0,r=b,mid,ans=0;
	while(l<=r){
		mid=(l+r)>>1;
		mid<=calc(mid)?(ans=mid,l=mid+1):r=mid-1;
	}
	return ans;
}
int main(){
//	freopen("testdata.in","r",stdin);
	for(scanf("%d",&q);q;--q){
		scanf("%d%d%d%d",&a,&b,&c,&d),--c;
		k=(a+b)/(a<b?a+1:b+1);
		if(k==1)fp(i,c,d-1)putchar(s[(i+(b>a))&1]);
		else{
			nb=find();
//			printf("qwq %d %d %d %d\n",a,b,k,nb);
			lim=nb+a-(b-nb+k-1)/k+1;
			fp(i,c,d-1)putchar(i<lim?s[i%(k+1)==k]:s[(a+b-i)%(k+1)>0]);
		}
		putchar('\n');
	}
	return 0;
} 

Measured memory_bytes: 384