akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const ll mx = LLONG_MAX;

int n, k;
vector<ll> h, dp;

int main(){
    cin>>n>>k;
    h.resize(n); dp.resize(n, mx);
    for(int i = 0; i < n; i++){
        cin>>h[i];
    }
    dp[0] = 0;
    for(int i = 1; i < n; i++){
        for(int j = i - 1; j >= i - k && j >= 0; j--){
            dp[i] = min(dp[i], dp[j] + abs(h[j] - h[i]));
        }
    }
    ll res = dp[n-1];
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 4708
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;
	public struct Pos
	{
		public int X {get;set;}
		public int Y {get;set;}
		public int Cost {get;set;}
		public Pos(int x, int y):this() {X=x; Y=y;}
	}
	public static void Main(string[] args)
	{
		var p = Input().ToInt();
		var h = p[0];
		var w = p[1];
		var goal = new Pos(w-1, h-1);
		var grid = new int[h, w];
		
		var poses = new Queue<Pos>();
		
		for(int i = 0; i < h; i++)
		{
			var str = Console.ReadLine();
			for(int j = 0; j < w; j++)
			{
				grid[i, j] = -1;
				if(str[j] == '#')
				{
					grid[i, j] = -2;
					poses.Enqueue(new Pos(j,i));
					
				}
			}
		}

		long maxCost = 0;
		for( ;poses.Count > 0; )
		{
			var pos = poses.Dequeue();
			if(pos.X < 0 || pos.Y < 0 || pos.X >= w || pos.Y >= h)
				continue;
			if((grid[pos.Y, pos.X] >= 0 && grid[pos.Y, pos.X] <= pos.Cost))
				continue;
			grid[pos.Y, pos.X] = pos.Cost;
			maxCost = Math.Max(maxCost, pos.Cost);
			poses.Enqueue(new Pos(pos.X + 1, pos.Y + 0){Cost = pos.Cost + 1});
			poses.Enqueue(new Pos(pos.X - 1, pos.Y + 0){Cost = pos.Cost + 1});
			poses.Enqueue(new Pos(pos.X + 0, pos.Y + 1){Cost = pos.Cost + 1});
			poses.Enqueue(new Pos(pos.X + 0, pos.Y - 1){Cost = pos.Cost + 1});
		}
		
		Console.WriteLine(maxCost);
	}
	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(' '); }
	public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt();
		return r;
	 }
}



Measured memory_bytes: 90656
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N,M,s,c,flag=0;
    cin >> N >> M;
    int A[N];
    for(int i=0; i<N; i++){
        A[i]=-1;
    }
    for(int i=0; i<M; i++){
        cin >> s >> c;
        if(N!=1&&(s==1&&c==0)){
            flag=1;
        }else if(A[s-1]==-1){
            A[s-1]=c;
        }else if(A[s-1]!=c){
            flag=1;
        }
    }
    if(flag){
        cout << -1;
    }else{
        for(int i=0; i<N; i++){
            if(A[i]==-1){
                if(i==0 && N!=1){
                    A[i]=1;
                }else{
                    A[i]=0;
                }
            }
            cout << A[i];
        }
        cout << endl;
    }
    return 0;
}

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

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

using namespace std;

int main(){
	
	long long int n;
	long long int a[200005];
	cin >> n;
	REP(i,n){
		cin >> a[i];
	}
	
	
	deque<long long int> b;
	
	if(n%2==0){
		REP(k,n/2){
			b.push_front(a[2*k]);
			b.push_back(a[2*k+1]);
		}
	}else{
//		cout << (a[0]);
		b.push_front(a[0]);
		REP(k,(n-1)/2){
			b.push_front(a[2*k+1]);
			b.push_back(a[2*k+2]);
		}
//		b.pop_back();
	}
	
	cout << b.back();
	b.pop_back();
	
	REP(i,n-1){
//		cout << "po" << endl;
		cout <<" " << b.back();
		b.pop_back();
	}
	cout << endl;
	return 0;
	
}


Measured memory_bytes: 5376
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <cmath>
#include <map>
#include <tuple>
#include <queue>
#include <iomanip>

#define MOD (1000000007)
using namespace std;

typedef long long ll;

typedef tuple<ll, ll> tup; // mp, tairyoku

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

    vector<int> P(N) ,Q(N), V(N);
    for(int i = 0; i < N; i++) {
        cin >> P[i];
        V[i] = i+1;
    }
    for(int i = 0; i < N; i++) cin >> Q[i];

    int ind = 0;
    int ind_a = 0, ind_b = 0;
    do {
        if(equal(V.begin(), V.end(), P.begin(), P.end())) ind_a = ind;
        if(equal(V.begin(), V.end(), Q.begin(), Q.end())) ind_b = ind;
        ind++;
    } while(next_permutation(V.begin(), V.end()));

    cout << abs(ind_a-ind_b);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define f first
#define s second
using namespace std;
int32_t main(){
	if(fopen("input.txt", "r"))
	freopen("input.txt", "r", stdin),
	freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(0),cin.tie(0);
	int a,b,c;
	cin >> a >> b >> c;
	if(4*a*b<(c-a-b)*(c-a-b) and (c-a-b)>0)
		cout << "Yes";
	else
		cout << "No";
}

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

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

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

typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1e9+7,INF=mod*mod*3;//M_PI
#define rep(i,N) for(ll i=0; i<(N); i++)
#define rep1(i,N) for(ll i=1; i<(N); i++)
#define pb push_back

ll N,M;
struct edge{ll to,cost;};
vector<edge> G[1005];
vector<ll> to[1005];
ll d[1005];
ll pre[1005];
void dijkstra(ll s){
    priority_queue<P,vector<P>,greater<P> > que;
    fill(d,d+N,INF);
    fill(pre,pre+N,-1);
    d[s]=0;
    que.push(P(0,s));
    while(!que.empty()){
        P p=que.top(); que.pop();
        ll v=p.second;
        if(d[v]<p.first) continue;
        for(ll i=0; i<G[v].size(); i++){
            edge e=G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                pre[e.to]=v;
                que.push(P(d[e.to],e.to));
            }
        }
    }
}
vector<ll> get_path(ll t){
	vector<ll> path;
	for(;t!=-1;t=pre[t]) path.pb(t);
	reverse(path.begin(),path.end());
	return path;
}

int main(){

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

cin>>N>>M;
rep(i,M){
	ll a,b; 
	cin>>a>>b;
	a--;b--;
	G[a].pb((edge){b,1});
	to[b].pb(a);
}
ll dis=INF;
P vtx={INF,INF};
rep(i,N){
	dijkstra(i);
	for(auto&k:to[i]){
		if(d[k]<dis){
			dis=d[k];
			vtx.first=i;
			vtx.second=k;
		}
	}
}
if(vtx.first!=INF){
	dijkstra(vtx.first);
 	vector<ll> ans=get_path(vtx.second);
 	cout<<ans.size()<<endl;
 	for(auto&k:ans) cout<<k+1<<endl;
}
else cout<<-1<<endl;

}
	

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

int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max({a*c, a*d, b*c, b*d}) << endl;
    return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(a) cout << #a << ": " << a << endl
#define sz(a) int(a.size())
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) (v).begin(),(v).end()
#define fast cin.tie(0); ios::sync_with_stdio(false)
bool option(pair<int, int> a, pair<int, int> b){
	return a.second < b.second;
}
int32_t main(){ fast;
	int n,k; cin>>n>>k;
	set<int> set;
	int cnt = 0;
	map<int, int> map;
	rep(i, n){
		int x; cin>>x;
		if(!set.count(x)){
			cnt++;
			set.insert(x);
		}
		map[x]++;
	}
	if(cnt <= k){
		cout<<0<<endl;
		return 0;
	}
	vector<pair<int, int>> a;
	for(auto it: map){
		a.emplace_back(make_pair(it.second, it.first));
	}
	int need = cnt - k;
	sort(all(a));
	int ans = 0;
	for(int i = 0; i < need; i++){
		ans += a[i].first;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 21236
import sys
sys.setrecursionlimit(10 ** 6)  # 再帰関数の再帰の深さを設定
to_index = lambda x: int(x) - 1  # 入力した数字に1を引いたものを返す
print_list_in_2D = lambda x: print(*x, sep="\n")  # リストの要素を改行を挟んで表示する関数

# 入力を整数に変換して受け取る
def input_int():
    return int(input())

def map_int_input():
    return map(int, input())

MII = map_int_input

def MII_split():
    return map(int, input().split())

def MII_to_index():
    return map(to_index, input())

def MII_split_to_index():
    return map(to_index, input().split())

# 入力全てを整数に変換したものの配列を受け取る
def list_int_inputs():
    return list(map(int, input()))

LII = list_int_inputs

def LII_split():
    return list(map(int, input().split()))

# 2次元リスト化
def LII_2D(rows_number):
    return [LII() for _ in range(rows_number)]

def LII_split_2D(rows_number):
    return [LII_split() for _ in range(rows_number)]

K, N = MII_split()
A_list = LII_split()

max = 0
for i in range(len(A_list)):
    if i + 1 < len(A_list):
        dist = abs(A_list[i] - A_list[i + 1])
    else:
        dist = abs(K - A_list[i] + A_list[0])
    if dist > max:
        max = dist

print(K - max)

Measured memory_bytes: 26444
#include <bits/stdc++.h>
using namespace std;
//to set precision use fixed,setprecision(number_of_points_after_decimal)
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define mod 1000000007
#define sz(x) (int)(x).size()
#define ff first
#define ss second
#define pb push_back
#define debugvector(h) for(auto &l:h)cout<<l<<" "
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef map<int,int> mii;
typedef long double ld;
void solution(){
  int n,weight;cin>>n>>weight;
  int v[n],w[n];
  rep(i,0,n) cin>>w[i]>>v[i];
  ll dp[n+1][weight+1];



  rep(i,0,n+1)rep(j,0,weight+1)
  if(i==0|| j==0) dp[i][j]=0;







  rep(i,1,n+1)
  { 



    rep(j,1,weight+1){



    if(w[i-1]>j){ 
      dp[i][j]=dp[i-1][j];
      }


    else{
    dp[i][j]=max((dp[i-1][j-w[i-1]] + v[i-1]), dp[i-1][j]  );
    
      }
  }
    
  }




  ll maximum=0;
  rep(i,0,weight+1) maximum=max(maximum,(ll)dp[n][i]);
  cout<<maximum<<endl;
}



int main() {
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
  #endif
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);
  //int t;cin>>t;
  //while(t--){
  solution();
  //}
  return 0;
}

Measured memory_bytes: 82496
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
#define endn "\n"
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 


////////////////////////////////////////////////////////////////////

int n;P p[210000], q[210000];
signed main(){
  cin>>n;rep(i,n)cin>>p[i].first>>p[i].second;
  sort(p,p+n);
  rep(i,n){
    q[i].first = p[i].first + p[i].second;
    q[i].second = i;
  }
  sort(q,q+n, greater<P>());
  int ans = 0;
  rep(i,n){
    int t = q[i].second;
    if(i%2 == 0){
      ans += p[t].first;
    }else{
      ans -= p[t].second;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 5888
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

int main(void) {
    int r, g;
    std::scanf("%d %d", &r, &g);
    int ans = 2 * g - r;
    std::printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <map>
#include<iomanip>
#include<vector>

using namespace std;
typedef long long ll; 


ll ans,mx,sum,mn=1e18,flag;

int main(){
	ll x;
	cin>>x;
	ll fiosh = x /500;
	x -= (fiosh*500);
	ll five = x/5;
	cout<<(fiosh*1000) +(five*5)<<endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h" // {{{
using namespace std;
#define val         const auto
#define eb          emplace_back
#define emp         emplace
#define fi          first
#define se          second
#define X           first
#define Y           second
#define outl(x)     cout << (x) << '\n'
#define rep(i,n)    for(int i=0; i < (int)(n); ++i)
#define ALL(x)      begin(x), end(x)
#define TMPLT(T,U)  template<class T, class U>
#define ten(p)      ((long long)(1e##p))
#define FILL(a,v)   memset((a), (v), sizeof(a))
#define FAST()      ios::sync_with_stdio(false), cin.tie(nullptr)
#ifndef DEBUG
#define debug(...)
#define show(x)
#define show2(x,y)
#define LN()
#endif
typedef long long ll;
typedef pair<int,int> pii;
namespace ydk{
TMPLT(T,U) inline bool chmax(T &a, U b){return b>a ? a=b,1 : 0;}
TMPLT(T,U) inline bool chmin(T &a, U b){return b<a ? a=b,1 : 0;}
TMPLT(T,U) inline constexpr common_type_t<T,U> gcd(T x, U y)
{ return (x<y)? gcd(y,x) : (y <= 0)? x : gcd(y, x % y); }
TMPLT(T,U) inline constexpr ll lcm(T x, U y) { return (ll)x/gcd(x,y) * y; }
constexpr int INF   = 0x3f3f3f3f;
constexpr ll LINF   = 0x3f3f3f3f3f3f3f3fLL;
// }}}

constexpr int MX = 5 *ten(4) + 10;

void Xx_main_xX()
{
    int N, M;
    int c[22];
    static int dp[MX];

    cin >> N >> M;
    rep(i, M) { cin >> c[i]; }

    FILL(dp, INF);
    dp[0] = 0;

    for (int i = 0 ; i < M; ++i) {
        for (int v = 0; v <= N; ++v) {
            if (v + c[i] > N) continue;
            chmin(dp[v + c[i]], dp[v] + 1);
        }
    }

    outl(dp[N]);

    return;
}

} // {{{

signed main(){cout << fixed << setprecision(9); ydk::Xx_main_xX(); return 0;} // }}}




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

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

    cout << n * n - a << endl;

    return 0;
}

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

int main(void) {
  char a[30], b[30], c[30];
  scanf("%s%s%s", a, b, c);
  if(a[strlen(a) - 1] == b[0] && b[strlen(b) - 1] == c[0]) printf("YES");
  else printf("NO");
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;

typedef pair<int, double> i_d;
#define rep(i, n)for((i) = 0;(i) < (n);++(i))

bool dsort(i_d qwe, i_d rty){
	return qwe.second < rty.second;
}
i_d pt[3][8], f[18];
int hd = 0;

int main(void){
	int i, j, n = 24;
	rep(i, n)scanf("%d %lf", &pt[i/8][i%8].first, &pt[i/8][i%8].second);
	rep(i, 3)sort(pt[i], pt[i] + 8, dsort);
	rep(i, 3)rep(j, 8){
		if(j < 2)printf("%d %.2lf\n", pt[i][j].first, pt[i][j].second);
		else f[hd++] = pt[i][j];
	}
	sort(f, f + hd, dsort);
	rep(i, 2)printf("%d %.2lf\n", f[i].first, f[i].second);

	return 0;
}

Measured memory_bytes: 3204
import numpy as np
N=int(input())
dp=[0]*(N+1)
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr
for i in range(1,N+1):
  p=factorization(i)
  for x,y in p:
    dp[x]+=y
nplist=np.array(dp)
a=nplist[nplist>=2]
b=nplist[nplist>=4]
c=nplist[nplist>=14]
d=nplist[nplist>=24]
e=nplist[nplist>=74]
f=len(e)
g=len(d)*(len(a)-1)
h=len(c)*(len(b)-1)
k=len(b)*(len(b)-1)*(len(a)-2)//2
print(f+g+h+k)

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

using namespace std;

int main(){

	int N; cin >> N;
	vector<int> arr(N);
	vector<int> F(100001,0);
	long long int sum = 0;
	for(int i = 0; i < N; ++i){
	       	cin >> arr[i];
		sum += arr[i];
		++F[arr[i]];
	}

	int Q; cin >> Q;
	for(int i = 0; i < Q; ++i){
		int x,y;
		cin >> x >> y;
		sum = (y-x)*F[x] + sum;
		cout << sum << "\n";
		F[y] += F[x];
		F[x] = 0;
	}


}

Measured memory_bytes: 4032
using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;

class Program
{
    static void Main(string[] args)
    {
        string[] cin = Console.ReadLine().Split();
        int n = int.Parse(cin[0]);
        int m = int.Parse(cin[1]);

        var dist = Enumerable.Repeat(long.MaxValue, n).ToList(); // 開始点からの距離dist

        if (Bellman_ford(n, 0, m, dist)) Console.WriteLine("inf");
        else Console.WriteLine(-dist[n - 1]);
    }

    static bool Bellman_ford(int n, int s, int m, List<long> dist)
    {
        // グラフの受け取りはこっちでやる
        // a→b(コストc)
        string[] cin;
        int[] a = new int[m];
        int[] b = new int[m];
        long[] c = new long[m];
        for (long i = 0; i < m; i++)
        {
            cin = Console.ReadLine().Split();
            a[i] = int.Parse(cin[0]) - 1;
            b[i] = int.Parse(cin[1]) - 1;
            c[i] = -long.Parse(cin[2]);
        }

        dist[s] = 0;

        for (int i = 1; i < n; i++)
        {
            for (int j = 0; j < m; j++)
            {
                if (dist[a[j]] != long.MaxValue && dist[b[j]] > dist[a[j]] + c[j])
                    dist[b[j]] = dist[a[j]] + c[j];
            }
        }

        var dist2 = new List<long>(dist);

        bool[] negative = new bool[n];

        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < m; j++)
            {
                if (dist2[a[j]] != long.MaxValue && dist2[b[j]] > dist2[a[j]] + c[j])
                {
                    dist2[b[j]] = dist2[a[j]] + c[j];
                    negative[b[j]] = true;
                }
                if (negative[a[j]]) negative[b[j]] = true;
            }
        }

        if (negative[n - 1]) return true;
        else return false;
    }
}


Measured memory_bytes: 13464
#include <utility>
#include <stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<cmath>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define YES(b) std::cout<< (b ? "Yes" : "No")
using namespace std;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, a[100], ans = 0;
	double sum = 0;
	cin >> n;
	REP(i, n) {
		cin >> a[i];
		sum += a[i];
	}
	sum /= n;
	sum = round(sum);
	REP(i, n) {
		ans += pow(a[i] - sum, 2);
	}
	cout << ans;
}


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

int main(){
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  int ans=0;
  for(int i=0; i<=min(A,40); i++){
      for(int j=0; j<=B; j++){
          for(int k=0; k<=C; k++){
              if(500*i + 100*j + 50*k == X){
                  ans=ans+1;
              }
          }
      }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
# C版からの移植

sx, sy, tx, ty = map(int,input().split())
dx = tx - sx
dy = ty - sy
ans = ""

# 4点を結ぶ長方形：最短経路
for _ in range(dy):
    ans += "U"
for _ in range(dx):
    ans += "R"
for _ in range(dy):
    ans += "D"
for _ in range(dx):
    ans += "L"

# 上記の１まわり外側
ans += "L";
for _ in range(dy + 1):
    ans += "U"
for _ in range(dx + 1):
    ans += "R"
ans += "D";
ans += "R";
for _ in range(dy + 1):
    ans += "D"
for _ in range(dx + 1):
    ans += "L"
ans += "U";

print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
#define li long int
#define ld long double
#define pl pair<long long, long long>
#define pi pair<int, int>
#define ppl pair<pl, ll>
#define ppi pair<int, pi>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LLFOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define MOD 1000000007
#define M2 998244353
//std::cout <<setprecision(30) << av << endl;
using namespace std;

int a[200000];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen("input.txt", "r", stdin);
    int n, k;
    cin >> n >> k;
    FOR(i, 0, n){
        cin >> a[i];
    }
    set<int> s;
    FOR(i, 0, k){
        s.insert(a[i]);
    }
    int cnt=1;
    FOR(i, 0, n-k){
        s.insert(a[i+k]);
        auto it1 = s.begin();
        auto it2 = s.rbegin();
        if(a[i]==*it1&&a[i+k]==*it2){
        }else{
            cnt++;
        }
        s.erase(a[i]);
    }
    //number of sorted sequences len>=k
    int st=0, en=0;
    int p=0;
    FOR(i, 1, n){
        if(a[i]>a[en]){
            en++;
        }else{
            if(en-st+1>=k)p++;
            st=i;
            en=i;
        }
    }
    //cout << n-k+1 << " " << p << " " << cnt << endl;
    if(en-st+1>=k)p++;
    if(p>=1)cnt=cnt-p+1;
    cout << cnt << endl;
}


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

using namespace std;

const int MAX_N = 100000, INDEX = 1;
const int MAX_A = 1000000000;
const long long INF = 3ll * (long long)(MAX_N) * (long long)(MAX_A) + 1ll;

int n, a[3 * MAX_N + INDEX];
long long psgreatest[3 * MAX_N + INDEX], psleast[3 * MAX_N + INDEX];

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

    cin >> n;

    for (int i = 1; i <= 3 * n; i++) {
        cin >> a[i];
    }

    multiset<int, less<int>> greatest;
    multiset<int, greater<int>> least;
    long long s;

    s = 0;
    for (int i = 1; i <= n; i++) {
        s += a[i];

        greatest.insert(a[i]);

        psgreatest[i] = s;
    }
    for (int i = n + 1; i <= 3 * n; i++) {
        s += a[i];

        greatest.insert(a[i]);

        s -= *greatest.begin();

        greatest.erase(greatest.begin());

        psgreatest[i] = s;
    }

    s = 0;
    for (int i = 3 * n; i > 2 * n; i--) {
        s += a[i];

        least.insert(a[i]);

        psleast[i] = s;
    }
    for (int i = 2 * n ; i > 0; i--) {
        s += a[i];

        least.insert(a[i]);

        s -= *least.begin();

        least.erase(least.begin());

        psleast[i] = s;
    }

    long long ans = -INF;
    for (int i = n; i <= 2 * n; i++) {
        ans = max(ans, psgreatest[i] - psleast[i + 1]);
    }

    cout << ans << endl;

    return 0;
}


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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

void func(long long N, std::vector<long long> B){

    lli ans = 0;
    
    for(lli i=N-1;i>=0;i--){

        if(i==N-1){
            ans += B[i-1];
        }
        else if(i==0){
            ans += B[0];
        }
        else{
            ans += min(B[i],B[i-1]);
        }
    }

    cout<<ans<<endl;

}

int main(){
    // cout << fixed << setprecision(5);

    long long N;
    scanf("%lld",&N);
    std::vector<long long> B(N-1);
    for(int i = 0 ; i < N-1 ; i++){
        scanf("%lld",&B[i]);
    }
    func(N, std::move(B));
    return 0;
}


Measured memory_bytes: 3672
# Vector class
class Vector:
    def __init__(self, x, y):
        self.x = x
        self.y = y
    def is_orthogonal(self, v):
        if self.x * v.x + self.y * v.y == 0:
            return True
        else:
            return False
    def is_parallel(self, v):
        if self.x * v.y - self.y * v.x == 0:
            return True
        else:
            return False
    def dot_product(self, v):
        return self.x * v.x + self.y * v.y
    def quadrance(self):
        return self.x ** 2 + self. y ** 2
    def mul(self, k):
        return Vector(self.x * k, self.y *k)
    def __add__(self, v):
        return Vector(self.x + v.x, self.y + v.y)
    def __str__(self):
        return "{0:.8f} {1:.8f}".format(self.x, self. y)
    def project_vector(self, v):
        return v.mul(self.dot_product(v) / v.quadrance())

# Acceptance of input and Print the projection point
import sys

file_input = sys.stdin

x_p1, y_p1, x_p2, y_p2 = map(int, file_input.readline().split())
p1_p2 = Vector(x_p2 - x_p1, y_p2 - y_p1)
o_p1 = Vector(x_p1, y_p1)

q = int(file_input.readline())

for line in file_input:
    x_p, y_p = map(int, line.split())
    p1_p = Vector(x_p - x_p1, y_p - y_p1)
    print(o_p1 + p1_p.project_vector(p1_p2))

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

 public class Main{
// taking inputs
static BufferedReader s1;
static BufferedWriter out;
static String read() throws IOException{String line="";while(line.length()==0){line=s1.readLine();continue;}return line;}
static int int_v (String s1){return Integer.parseInt(s1);}
static long long_v(String s1){return Long.parseLong(s1);}
static int[] int_arr() throws IOException{String[] a=read().split(" ");int[] b=new int[a.length];for(int i=0;i<a.length;i++){b[i]=int_v(a[i]);}return b;}
static long[] long_arr() throws IOException{String[] a=read().split(" ");long[] b=new long[a.length];for(int i=0;i<a.length;i++){b[i]=long_v(a[i]);}return b;}
static void assign(){s1=new BufferedReader(new InputStreamReader(System.in));out=new BufferedWriter(new OutputStreamWriter(System.out));}

//......................................@uthor_Alx..............................................
//Atlanta       83 71  8  0 1 6 1
//Atlanta       83 71  8  0 1 6 1
   public static void main(String[] args) throws  IOException{
	        		  assign();
	        		  int[] n1=int_arr();
	        		  int a=n1[0],b=n1[1],c=n1[2],k=n1[3];
	        		 // int[] arr=int_arr();
	        		 int res=Math.min(a,k);
	        		 k-=res;
	        		 k-=Math.min(b,k);
	        		 if(k>0){res-=k;}
	        		  out.write(res+"");
	        		  
	        	
                      out.flush();
	        		 
	}
}
	       
	          



	
  





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

#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
 
const long long INF = 1LL << 60;
#define PI 3.14159265359 
bool dp[100100];

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}



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

    cout << 6-(A+B) << endl;

}


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

int main() {
  int N;
  cin >> N;
  for(int i=0; i<N; i++){
    string color;
  cin >> color;
    
    if(color == "Y"){
    cout << "Four" << endl;
   break;
    }
    if((i<N-1)&&(color != "Y"))
    continue;
    
    if((i=N-1)&&(color != "Y"))
    cout << "Three" << endl;
  }
 
}










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

using namespace std;

void swap(long long int& a, long long int& b) {
	long long int tmp;
	tmp = a;
	a = b;
	b = tmp;
}



long long int gcd(long long int c, long long int d) {

	if (c < d)swap(c, d);

	if (c % d == 0)return d;

	return (gcd(d, c % d));

}




int main() {

	long long int a, b, c, d;

	cin >> a >> b >> c >> d;


	long long int lcmcd;
	lcmcd = c * d / gcd(c, d);


	

	long long int n[6];

	n[0] = b / c;
	n[1] = b / d;
	n[2] = b / lcmcd;

	n[3] = (a - 1) / c;
	n[4] = (a - 1) / d;
	n[5] = (a - 1) / lcmcd;

	long long int ans = 0;

	ans = (b - n[0] - n[1] + n[2]) - ((a - 1) - n[3] - n[4] + n[5]);

	cout << ans << endl;

	return 0;

}



Measured memory_bytes: 256
;;;; mod
(let ((p 1000000007))
  (defun mod+ (a b)
    (mod (+ a b) p))

  (defun mod* (a b)
    (mod (* a b) p))

  (defun mod_expt (a z)
    (loop :with ans := 1
          :with pow := a
          :while (> z 0)
          :do (multiple-value-bind (x y) (floor z 2)
                (setf z x)
                (if (= y 1) (setf ans (mod* ans pow)))
                (setf pow (mod* pow pow)))
          :finally (return ans)))

  (defun mod_inv (a)
    ; TODO use Euclidean
    (mod_expt a (- p 2))))

;;;; main
(let* ((s (read))
       (f (make-array (list (1+ s))))
       (f-1 (make-array (list (1+ s))))
       (ans 0))
  (setf (aref f 0) 1)
  (setf (aref f-1 0) 1)
  (setf (aref f 1) 1)
  (setf (aref f-1 1) 1)
  (loop :for i :from 2 :to s
        :do (setf (aref f i) (mod* (aref f (1- i)) i))
        :do (setf (aref f-1 i) (mod_inv (aref f i))))
  ;;
  (loop :for i :from 1
        :while (<= 0 (- s (* 3 i)))
        :for n := (- s (* 2 i) 1)
        :for m := (- i 1)
        :for x := (mod* (aref f n) (mod* (aref f-1 (- n m)) (aref f-1 m)))
        :do (setf ans (mod+ ans x)))
  ;;
  (format t "~A~%" ans))


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

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	int w,h;
	cin>>w>>h;
	for(int i=0;i<w;++i){
		string s;
		cin>>s;
		cout<<s<<'\n'<<s<<'\n';
	}
}




Measured memory_bytes: 3652
# -*- coding: utf-8 -*-

# input
S = input()
T = input()

# solve
ans = False
for i in range(len(S)):
    S = S[len(S) - 1] + S[0:len(S) - 1]
    if S == T:
        ans = True
        break

# output
print('Yes' if ans else 'No')


Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int A, B, C, D;
    int ans = 0;
    bool AF, BF;
    cin >> A >> B >> C >> D;
    for (int i = 0; i <= 100; i++)
    {
        if (i >= A && i <= B)
        {
            AF = true;
        }
        else
        {
            AF = false;
        }

        if (i >= C && i <= D)
        {
            BF = true;
        }
        else
        {
            BF = false;
        }

        if (AF && BF)
            ans++;
    }
    cout << max(0, ans - 1) << endl;
    return 0;
}

Measured memory_bytes: 256
//بسم الله الرحمن الرحيم
///   ***   ---   |||		 In the name of ALLAH		|||   ---   ***   ///
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define el << endl
#define PI 3.141592653589793238
#define _test_ int t; cin >> t; while(t--)
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define file() freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout)
ll gcd ( ll  a, ll b ) { return __gcd ( a, b ); }
ll lcm ( ll a, ll b ) { return a * ( b / gcd ( a, b ) ); }
int dx[]={0,0,+1,-1,+1,-1,-1,+1};
int dy[]={+1,-1,0,0,+1,-1,+1,-1};
///*......................*//* LET'S BEGIN (-_^) *//*............................///
const int mx= 2e6+123;
int n,a[mx],ans,m,k=0;

void _case_()
{
   cin >> n;
   for(int i=0;i<n;i++) cin >> a[i];
    m=a[0];
    for(int i=1;i<n;i++)
    {
        if(a[i]<=a[i-1])
            k++;
        else
        {
            ans=max(ans,k);
            k=0;
        }
    }
   cout << max(ans,k) el;
}

int main()
{

    optimize();
    //_test_
    _case_();
    return 0;

}

///////////*  N A Y E M  *///////////

Measured memory_bytes: 3908
import numpy as np

n, k = map(int, input().split())
a = list(map(int, input().split()))
a = np.array(a) # numpy の array で高速化

a = np.sort(a)
zero = np.count_nonzero(a == 0) # 整数が0の個数
pos = a[a > 0] # 整数が負の配列
neg = a[a < 0] # 整数が正の配列

def count(x): # 積がｘが以下のペアが何個あるか？
    ans = 0
    if x >= 0: # 片方が0の場合
        ans += zero * n 
    ans += np.searchsorted(a, x // pos, side="right").sum()
    ans += n * len(neg) - np.searchsorted(a, -(-x // neg), side="left").sum()
    ans -= np.count_nonzero(a * a <= x) # 同じものは2つ選べない
    return ans // 2

ok = 10 ** 18
ng = -ok - 1
while ok - ng > 1: # 二分探索
    cen = (ok + ng) // 2
    if count(cen) >= k:
        ok = cen
    else:
        ng = cen
print(ok)



Measured memory_bytes: 32312
import numpy as np
from functools import *
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readline


def array(size, init=0):
    return [[init for j in range(size[1])] for i in range(size[0])]


def acinput():
    return list(map(int, input().split(" ")))


def II():
    return int(input())


D, T, S = acinput()

if (D/S) <= T:
    print("Yes")
else:
    print("No")


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

int main()
{
	int m, f, r;
	while (cin >> m >> f >> r, m != -1 || f != -1 || r != -1) {
		if (m == -1 || f == -1) {
			cout << 'F' << endl;
		}
		else if (m + f >= 80) {
			cout << 'A' << endl;
		}
		else if (m + f >= 65) {
			cout << 'B' << endl;
		}
		else if (m + f >= 50) {
			cout << 'C' << endl;
		}
		else if (m + f >= 30) {
			cout << (r >= 50 ? 'C' : 'D') << endl;
		}
		else {
			cout << 'F' << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3036
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair<int,int> Q;
typedef pair<int,Q> P;
const int INF = 1<<29;

int main(){
  int n,m,a;

  while(cin >> n >> m >> a , n | m | a){
    vector<P> v;
    int h,p,q;
    for(int i = 0 ; i < m ; i++){
      cin >> h >> p >> q;
      v.push_back(P(h,Q(p,q)));
    }
    sort(v.begin(),v.end(),greater<P>());

    for(int i = 0 ; i < (int)v.size() ; i++){
      if(v[i].second.first == a) a = v[i].second.second;
      else if(v[i].second.second == a) a = v[i].second.first;
    }
    cout << a << endl;
  }

  return 0;
}

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

int main()
{
  long long int N;
  cin >> N;
  long long int a[N];
  long long int ans {0};
  for(long long int i = 0; i < N; ++i){
    cin >> a[i];
    ans += a[i]-1;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	long long n, m, a; cin >> n >> m;
	int test[1001] = { 0 }, uiop[1001] = { 0 };
	for (int h = 0; h <= 2 * n; h++) {
		test[h] = h; uiop[h] = h;
	}
	for (int h = 0; h < m; h++) {
		cin >> a;
		if (a != 0) {
			for (int i = a + 1; i <= 2 * n; i++) {
				test[i - a] = uiop[i];
			}
			for (int i = 1; i <= a; i++) {
				test[2 * n - a + i] = uiop[i];
			}
		}
		else {
			for (int i = 1; i <= 2 * n; i++) {
				if (i % 2 == 1) {
					test[i] = uiop[(i + 1) / 2];
				}
				else {
					test[i] = uiop[i / 2 + n];
				}
			}
		}
		for (int i = 1; i <= 2 * n; i++) {
			uiop[i] = test[i];
		}
	}
	for (int h = 1; h <= 2 * n; h++) {
		cout << test[h] << endl;
	}
	cin >> n;
}


Measured memory_bytes: 3104
/***********************
*  Author: xuziyuan    * 
***********************/

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++)
#define LL long long
#define pii pair <LL,LL>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

LL n,k,a[100010],pw[100],knum[100],ans=0;
pii num[100];

void dfs(LL times,LL res)
{
	ans=max(ans,res);
	if(times==-1) return;
	if(knum[times]==0)
	{
		dfs(times-1,res+num[times].se);
		return;
	}
	LL ret=res+num[times].se;
	for(LL i=times-1;i>=0;i--) ret+=max(num[i].fi,num[i].se);
	ans=max(ans,ret);
	if(num[times].fi>num[times].se) dfs(times-1,res+num[times].fi);
}

int main()
{
	pw[0]=1;
	repn(i,70) pw[i]=pw[i-1]*2;
	cin>>n>>k;
	rep(i,n)
	{
		cin>>a[i];
		LL times=0;
		while(times<=70)
		{
			num[times].fi+=(a[i]%2==1 ? 0LL:pw[times]);
			num[times].se+=(a[i]%2==1 ? pw[times]:0LL);
			a[i]/=2;
			times++;
		}
	}
	LL times=0,mx;
	while(k>0)
	{
		if(k%2==1) mx=times;
		knum[times++]=k%2;
		k/=2;
	}
	//for(int i=2;i>=0;i--) cout<<num[i].fi<<' '<<num[i].se<<endl;
	//cout<<endl;
	LL use=0;
	for(LL i=70;i>times;i--) use+=num[i].se;
	dfs(times,use);
	cout<<ans<<endl;
	rt0;
}

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




int main() {
    int n;
    cin>>n;
    vector<int>v(n);
    for(int i=0;i<n;i++)cin>>v[i];
    
    sort(v.begin(),v.end());
    cout<<v.back()-v.front()<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1ll << 60;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<pair<int, int>>
#define vvp vector<vector<pair<int, int>>>
#define pi pair<int, int>
//#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define itn int
#define asn ans
bool dbg = false;

int N, M;
string s;
set<int> G[202020];
int A[202020][3];

void solve() {
    set<int> st;
    FOR (N) {
        for (auto e : G[i]) {
            A[i][s[e]]++;
        }
        if (A[i][0] == 0 || A[i][1] == 0)
            st.insert(i);
    }
    int cnt = 0;
    while (!st.empty()) {
        int now = *st.begin();
        st.erase(st.begin());
        cnt++;
        for (auto nxt : G[now]) {
            if (now != nxt) {
                G[nxt].erase(now);
                A[nxt][s[now]]--;
                if (A[nxt][0] == 0 || A[nxt][1] == 0)
                    st.insert(nxt);
            }
        }
    }
    cerr << cnt << endl;
    No(cnt == N);
}

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

    cin >> N >> M >> s;
    for (auto& c : s)
        c -= 'A';

    FOR (M) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a].insert(b);
        G[b].insert(a);
    }

    solve();
    return 0;
}


Measured memory_bytes: 37840
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
//const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
 
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}
 
/*------------------------------------------------------------------*/
 
int main(){
    ll a, b, c; cin >> a >> b >> c;
    ll count = 0;
    if(a % 2 == 1 || b % 2 == 1 || c % 2 == 1){
        cout << count << endl;
        return 0;
    }
    while(true){
        ll t = a;
        ll s = b;
        ll u = c;
        a += s / 2 + u / 2 - t;
        b += u / 2 + t / 2 - s;
        c += t / 2 + s / 2 - u;

        count++;
        //cout << a << " " << b << " " << c << endl;
        if(a % 2 == 1 || b % 2 == 1 || c % 2 == 1){
            cout << count << endl;
            return 0;
        }
        if(a == b && c == a){
            cout << -1 << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
#include <iostream>

#include<algorithm>
#include<vector>
#include<queue>
#include<string>

using namespace std;

int main()
{
	int n, k;
	cin>> n >> k;
	int ans = 1;
	while (n >= k) {
		ans++;
		n = n / k;
	}
	cout << ans << endl;

}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)

int N, A[112345], L[112345], R[112345];

int gcd(int a, int b) {
	if (a < b) return gcd(b, a);
	if (!(a % b)) return b;
	return gcd(a % b, b);
}

int main() {


	scanf("%d", &N);
	rep(i, N) scanf("%d", &A[i]);

	L[0] = A[0];
	R[N - 1] = A[N - 1];
	rep(i, N - 1) L[i + 1] = gcd(L[i], A[i + 1]);
	rep(i, N - 1) R[N - 1 - i - 1] = gcd(R[N - 1 - i], A[N - 1 - i - 1]);

	int ans = 1;

	ans = max(ans, R[1]);
	ans = max(ans, L[N-2]);
	rep(i, N - 2) ans = max(ans, gcd(L[i], R[i + 2]));

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

	return 0;
}


Measured memory_bytes: 1408
#include <iostream>
using namespace std;
const int MAX = 110;
int a[MAX];
void insertionSort(int a[], int n)
{
	int key, j;
	for(int i = 1; i < n; ++ i)
	{
		key = a[i];
		j = i - 1;
		while(a[j] > key && j >= 0)
		{
			a[j + 1] = a[j];
			j --;
		}
		a[j + 1] = key;
		for(int k = 0; k < n; ++ k)
		{
			if(k == n - 1)
				cout << a[k];
			else
				cout << a[k] << " ";
		}
		cout << endl;
	}
	return ;
}
int main()
{
	int n;
	cin >> n;
	for(int i = 0; i < n; ++ i)
	{
		cin >> a[i];
	}
	for(int i = 0; i < n; ++ i)
	{
		if(i == n - 1)
			cout << a[i];
		else
			cout << a[i] << " ";
	}
	cout << endl;
	
	insertionSort(a, n);
	
	return 0;
} 


Measured memory_bytes: 3088
#include <bits/stdc++.h>
#include<math.h>
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950
#define INF 1e18 
int main(){
    double l ;
    cin >> l ;
    l = l / 3 ;
    cout << fixed << setprecision(10) ;
    cout << l * l * l << endl ;

} 

Measured memory_bytes: 3764
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//cout << fixed << setprecision (20);   小数点以下2０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'0'+=16;        で大文字に
//'大文字'+=32;    で小文字に
//s[i]-'0'でchar文字→int数に;
//string s = to_string(int数);
//int n = stoi(string文字列)
//実行時間制約2秒では２×10^8回くらいまで計算できる


int main() {
  int n,m;
  cin >> n >> m;
  vector<pair<int,int>> p(m);
  
  rep(i,m) {
  cin >> p[i].fi >> p[i].se;
  }
  
  vector<int> q={};
  rep(i,n-1) {
  q.pb(i+2);
  }
  
  int ans = 0;
  
  do{
    bool x = false;
    rep(j,m) {
      if((p[j].fi==1 && p[j].se==q[0]) || 
          (p[j].fi==q[0] && p[j].se==1)) {
      x = true;
      }
    }
    
    int aru = 0;
    repo(i,n-1) {
      rep(j,m) {
        if((p[j].fi==q[i-1] && p[j].se==q[i]) || 
          (p[j].fi==q[i] && p[j].se==q[i-1])) {
         aru++;
        }
      }
    } 
   if(x && aru==n-2) ans++;
    
  }while (np(all(q)));
  
  cout << ans << endl;  
  
}

Measured memory_bytes: 256
#include<stdio.h>

long fib(int n,int *memo,long *A){
	if(memo[n]==0){
		A[n]=fib(n-1,memo,A)+fib(n-2,memo,A);
		memo[n]=1;
	}
	return A[n];
}

main(){
	int i,n,memo[50];
	long A[50];
	scanf("%d",&n);
	for(i=2;i<=n;i++){
		memo[i]=0;
	}
	A[0]=1;memo[0]=1;
	A[1]=1;memo[1]=1;
	printf("%ld\n",fib(n,memo,A));
        return 0;
}
	

Measured memory_bytes: 596
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<utility>
#include<queue>
#include<deque>
#include<tuple>
#include<stdio.h>
#include<iomanip>
#define rep(i, n) for(int i=0;i<n;i++)
using namespace std;

int main(){
	int n, k;
	cin>>n>>k;
	vector<int> v;
	int p;
	rep(i, n){
		cin>>p;
		v.push_back(p);
	}
	sort(v.begin(), v.end());
	int a=0;
	rep(i, k){
		a+=v[i];
	}
	cout<<a<<endl;
	return 0;
}

Measured memory_bytes: 3596
#include <stdio.h>

int main(void)
{
        int n, i, j;

        scanf("%d", &n);

        for (i = 0; i < n; i++){
                for (j = 0; j < n; j++){
                        if (7 * i + 4 * j == n){
                                printf("Yes\n");
                                return 0;
                        }
                }
        }

        printf("No\n");

        return 0;
}


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

using namespace std;

using ll = long long;

#define ALL(A) A.begin(),A.end()

void ALLIN1_NUMBER(vector<ll>& V)
{
    for(auto& x : V)
    {
        cin >> x;
    }
}

void ALLOUT_NUMBERS(vector<ll> V)
{
    for(auto x : V)
    {
        cout << x << ' ';
    }
    cout << endl;
}

template<class T>
void OUT0(T N)
{
    cout << N << endl;
}

static const double pi = acos(-1.0);

double Cos(double D)
{
    return cos(pi/180 * D);
}

class numbers
{
    public:
    ll a,b,c,d;    
};

void ALLIN_POINTS(vector<numbers>& points)
{
    for(auto& x : points)
    {
        cin >> x.a >> x.b >> x.c >> x.d;
    }
}

void ALLOUT_POINTS(vector<numbers> points)
{
    for(auto x : points)
    {
        cout << x.a << ' ' << x.b << ' ' << x.c << ' ' << x.d << endl;
    }
}

void CREATE_AND_PUSH_ANY_NUMBERS(ll N, ll M, ll Q, ll depth, vector<ll> compare_numbers, vector<numbers>& points, ll& score)
{
    if(depth==N)
    {
        ll score_compare = 0;
        for(auto x : points)
        {
            if(compare_numbers[x.b-1]-compare_numbers[x.a-1]==x.c)
            {
                score_compare += x.d;
            }
        }
        score = max(score,score_compare);
    }
    else
    {
        ll Nsize = compare_numbers.size();
        for(ll i=compare_numbers[Nsize-1]; i<=M; i++)
        {
            vector<ll> numbers_copy = compare_numbers;
            numbers_copy.push_back(i);
            CREATE_AND_PUSH_ANY_NUMBERS(N,M,Q,depth+1,numbers_copy,points,score);
        }
    }
}

ll OUT_ANY_NUMBERS(ll N, ll M, ll Q, vector<numbers> points)
{
    vector<ll> numbers = {0};
    ll score = 0;
    for(ll i=1;i<=M;i++)
    {
        numbers[0] = i;
        CREATE_AND_PUSH_ANY_NUMBERS(N,M,Q,1,numbers,points,score);
    }
    return score;
}

int main()
{
    ll N,M,Q;
    cin >> N >> M >> Q;

    vector<numbers> points(Q);
    ALLIN_POINTS(points);

    OUT0(OUT_ANY_NUMBERS(N,M,Q,points));

    return 0;
}

Measured memory_bytes: 3628
from collections import deque

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

for _ in range(M):
  a, b = map(int, input().split())
  a, b = a-1, b-1
  G[a].append(b)
  G[b].append(a)

q = deque([0])
dist = [-1]*N
dist[0] = 0

while q:
  v = q.popleft()
  for nv in G[v]:
    if dist[nv] == -1:
      dist[nv] = v+1
      q.append(nv)

print("Yes")
print(*dist[1:], sep="\n")

Measured memory_bytes: 38396
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long n,m;cin>>n>>m;
  vector<pair<int,int>> v;
  for(int i=0;i<n;i++){
    int a,b;cin>>a>>b;
    v.push_back(make_pair(a,b));
  }
  sort(v.begin(),v.end());
  long long sum=0;
  long long ans=0;
  for(int i=0;i<n;i++){
    long long an=v[i].first,bn=v[i].second;
    if(sum+bn>=m){
      cout<<ans+an*(m-sum)<<endl;
      return 0;
    }
    else{
      ans+=bn*an;
      sum+=bn;
    }
  }
}

Measured memory_bytes: 1400