akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
enum {LE = -1, EQ = 0, GE = 1};
int A[100000 + 1];
int main() {
  int N; cin >> N;
  int total{1}, flag{EQ};
  if (N <= 2) {
    goto END;
  }
  cin >> A[0];
  for (size_t i{1}; i < N; ++i) {
    cin >> A[i];
    if (A[i] < A[i - 1]) {
      if (flag == GE) {
        ++total;
        flag = EQ;
        continue;
      }
      flag = LE;
    } else if (A[i] > A[i - 1]) {
      if (flag == LE) {
        ++total;
        flag =EQ;
        continue;
      }
      flag = GE;
    }
  }

  END:
  cout << total << "\n";
  return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String a =scanner.nextLine();
        String b = a+a;
        String c = scanner.nextLine();
        if(b.contains(c))
            System.out.println("Yes");
        else
            System.out.println("No");
         
    }
}


Measured memory_bytes: 26268
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<stack>
#define MAXN 100000
#define LL long long
#define pb push_back
#define mp make_pair
#define X first
#define Y second
using namespace std;
int n,m,a[12],b[12];
int main()
{
//    #ifndef ONLINE_JUDGE
//        freopen("in.txt", "r", stdin);
//        //freopen("out.txt", "w", stdout);
//    #endif
    int i,j;
    while(scanf("%d %d",&n,&m)!=EOF)
    {
        if(n==0&&m==0)break;
        for(i=0;i<n;i++)scanf("%d",&a[i]);
        for(i=0;i<m;i++)scanf("%d",&b[i]);
        sort(a,a+n);
        sort(b,b+m);
        int sum=0;i=j=0;
        while(i<n&&j<m)
        {
            if(a[i]<b[j])sum+=a[i++];
            else if(a[i]>b[j])sum+=b[j++];
            else
            {
                sum+=a[i];
                i++,j++;
            }
        }
        if(i==n)for(;j<m;j++)sum+=b[j];
        else if(j==m)for(;i<n;i++)sum+=a[i];
        printf("%d\n",sum);
    }
    return 0;
}

Measured memory_bytes: 1188
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ClassLibrary1
{
    public class ListNode
    {
        public int val;
        public ListNode next;
        public ListNode(int x) { val = x; }
    }


    public class Class1
    {
        static int[][] mtx ;
        static List<int>[] tm;
        static int n;
        static int[] results;
        static List<string> cons = new List<string>();
        static void Main(string[] args)
        {
          //  string[] s = Console.ReadLine().Split(' ');
            int n = int.Parse(Console.ReadLine());
       //     int k = int.Parse(s[1]);
            string[] s2 = Console.ReadLine().Split(' ');
   //         int cnt = 0;
            int[] a = new int[n];
            int[] b = new int[n];
            string res = "";
            for (int i = 0; i < n; i++)
            {
                int x = int.Parse(s2[i]);
                b[x-1] = i+1;
            }
            res = string.Join(" ", b);
            Console.WriteLine(res);

        }


        static int rec(int[] n, int i, int j, int x)
        {
            if (i+1 == j)
            {
                return Math.Min(n[j], x);
            }
            return rec(n, i + 1, j, n[i]) + rec(n, i, j - 1, n[j]);
        }
    }

}

Measured memory_bytes: 27612
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define all(a) a.begin(),a.end()
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
const long long MOD = 1000000007, INF = 1e18;
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
string get_str(string s) {
	s+=',';
	string ret="";
	for(int i=0; i<s.size(); i++) {
		if(s[i]==',') ret+="=%ld, ";
		else ret+=s[i];
	}
	return ret;
}
#define dump(...) printf(get_str(#__VA_ARGS__).c_str(),__VA_ARGS__);cout<<endl
 
#define endl '\n'
#define IOS()                     \
	ios_base::sync_with_stdio(0); \
	cin.tie(0)
 
//******************************************************************************
template<typename T>vector<T>
make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}
 
template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
	for(auto &e:t) fill_v(e,v);
}

int N,flag = 1;
int p[1010],x[1010];
vint g[1010];

pair<int,int>dfs(int now,int par){
	vector<pair<int,int>>tmp;
	for(auto e:g[now]){
		if(e==par)continue;
		tmp.push_back(dfs(e,now));
	}

	auto dp = make_v<int>(tmp.size()+10,5050);
	fill_v(dp,0);
	dp[0][0] = 1;
	int sum = 0;

	rep(i,0,tmp.size()){
		sum+=tmp[i].fi+tmp[i].se;
		rrep(j,0,5050){
			if(dp[i][j]==0)continue;
			if(j+tmp[i].fi<5050)chmax(dp[i+1][j+tmp[i].fi],dp[i][j]);
			if(j+tmp[i].se<5050)chmax(dp[i+1][j+tmp[i].se],dp[i][j]);
		}
	}
	rrep(j,0,x[now]+1){
		if(dp[tmp.size()][j]){
			return{x[now],sum-j};
		}
	}
	flag = 0;
	return{INF,INF};
}

signed main()
{
	//IOS();
	cin>>N;
	for(int i = 0;i < N-1;i++){
		cin>>p[i];
		p[i]--;
		g[p[i]].push_back(i+1);
		g[i+1].push_back(p[i]);
	}
	for(int i = 0;i < N;i++){
		cin>>x[i];
	}
	dfs(0,-1);
	if(flag)cout<<"POSSIBLE"<<endl;
	else cout<<"IMPOSSIBLE"<<endl;
}

Measured memory_bytes: 40212
n = int(input())
cnt = 0
ans = []
for i in range(n):
    cnt = 0
    y,m,d = map(int,input().split())
    if y % 3 == 0:
        cnt += (10-m)*20 + (20-d+1)
        y += 1
    else:
        cnt += ((10-m)- ((10-m)//2)) * 20 + ((10-m)//2) * 19 + (19-d+1) + 5
        y += 1
    cnt += ((1000-y)//3) * 200 + ((1000-y)-((1000-y)//3)) * 195
    ans.append(cnt)
for i in ans:
    print(i) 
            


Measured memory_bytes: 5616
S = list(input())
n = len(S)
ans = [0] * n
c = 0
for i in range(n):
    if S[i] == 'R':
        c += 1
    else:
        ans[i] += c // 2
        ans[i - 1] += (c + 1) // 2
        c = 0

S.reverse()
ans.reverse()

c = 0
for i in range(n):
    if S[i] == 'L':
        c += 1
    else:
        ans[i] += c // 2
        ans[i - 1] += (c + 1) // 2
        c = 0

ans.reverse()
print(' '.join(map(str, ans)))


Measured memory_bytes: 11180
#!/usr/bin/env python3
from collections import deque
# import sys
# input = sys.std.readline

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

que = deque()
dist = [float('inf')] * n
prev = [-1] * n
dist[0] = 0
que.append(0)
while que:
    now = que.popleft()
    for edge in edges[now]:
        if dist[edge] > dist[now] + 1:
            dist[edge] = dist[now] + 1
            prev[edge] = now + 1
            que.append(edge)


print('Yes')
for i in range(1, n):
    print(prev[i])



Measured memory_bytes: 37696
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

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



int main(){

    int n;
    cin >> n;
    string s;
    cin >> s;

    ll ans = 1;
    rep(i,0,n-1){
	if(s[i] != s[i+1])ans++;
    }
    P(ans);
    return  0;
}


Measured memory_bytes: 512
def main():
    n = int(input().strip())
    A = [int(s) for s in input().strip().split()]
    if all(a % 2 == 1 or a % 3 == 0 or a % 5 == 0 for a in A):
        print("APPROVED")
    else:
        print("DENIED")


main()


Measured memory_bytes: 38384
#include <stdio.h>
int main(){
  int i,n,m,ans,tmp,r;
  
  while(1){             /*条件を満しているか*/
    scanf("%d %d",&n,&m);
    if(n>=1 && m <= 1000000000){
      break;
    }
  }

  if(n<m){              /*n>mの確認*/
    tmp = n;
    n = m;
    m = tmp;
  }

  
  while((r = n % m)!=0){
    n = m;
    m = r;
  }
  printf("%d\n",m);
  
  return 0;
}



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

public class MainClass
{
	public const long Giri = 1000000007;
	
	public static void Main(string[] args)
	{
		var n = Console.ReadLine().ToInt();
		var p = Input();
		var a = new long[n];
		long hucnt = 0;
		for(int i = 0; i < n; i++)
		{
			a[i] = p[i].ToLong();
			if(a[i] <= 0)
			{
				hucnt++;
			}
		}
		long wa = 0;
		if(hucnt % 2 == 0)
		{
			for(int i = 0; i < n; i++)
			{
				wa += Math.Abs(a[i]);
			}
		}
		else
		{
			bool calced = false;
			Array.Sort(a, (s, t) => (int)(Math.Abs(s) - Math.Abs(t)));
			for(int i = 0; i < n; i++)
			{
				if(!calced)
				{
					wa += -Math.Abs(a[i]);
					calced=true;
				}
				else
				{
					wa += Math.Abs(a[i]);
				
				}
			}
		}
		Console.WriteLine(wa);
	}
	
	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: 29404
#include <bits/stdc++.h>
using namespace std;

int main(){
  int a,b,c,d,e,f,s=0,w=100;cin>>a>>b>>c>>d>>e>>f;
  for(int i=0;100*i*a<=f;i++){
    for(int j=0;100*(i*a+j*b)<=f;j++){
      for(int k=0;100*(i*a+j*b)+k*c<=f;k++){
        for(int l=0;100*(i*a+j*b)+k*c+l*d<=f;l++){
          if(i||j){
            int wa=100*(i*a+j*b),su=k*c+l*d;
            if(su*(100+e)<=e*(wa+su)&&s*(wa+su)<=su*(w+s)){
              w=wa;
              s=su;
            }
          }
        }
      }
    }
  }
  cout<<w+s<<" "<<s<<endl;
}

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

int main() {
  int n,m;
  cin >> n >> m;
  int L = 0, R = n + 1;
  for(int i = 0; i < m; i++) {
    int l,r;
    cin >> l >> r;
    L = max(l,L);
    R = min(r,R);
  }
  cout << max(R - L + 1,0) << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace sumitrust2019_D
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var s = Console.ReadLine();

            var ans = 0;

            for (int i = 0; i < 10; i++)
            {
                var c = s.IndexOf(i.ToString());
                if (c == -1) continue;

                for (int j = 0; j < 10; j++)
                {
                    var c2 = s.IndexOf(j.ToString(), c + 1);
                    if (c2 == -1) continue;

                    for (int k = 0; k < 10; k++)
                    {
                        var c3 = s.IndexOf(k.ToString(), c2 + 1);
                        if (c3 != -1) ans++;
                    }
                }
            }

            Console.WriteLine(ans);

        }
    }
}


Measured memory_bytes: 13408
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int a = 0;
        HashMap<Integer, Integer> map = new HashMap<>();
        for(int i = 0; i < n; i++){
            a = scan.nextInt();
            map.put(a, i+1);
        }
        
        for(int i = 0; i < n; i++){
            System.out.print(map.get(i+1)+" ");
        }
    }
}

Measured memory_bytes: 71140
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#define DBG(x) cout<<#x<<":"<<x<<endl
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
const ll p = 1e9+7;
const ll INF = 1LL << 60;

double dp[2][555][333];

int main(){
  int n;
  cin>>n;
  int a[333],c[3]={},sum=0;
  for(int i=0;i<n;i++){
    cin>>a[i];
    c[a[i]-1]++;
    sum+=a[i];
  }

  double ans=0;
  dp[0][c[1]][c[2]]=1.0;
  for(int i=0;i<sum;i++){
    
	 for(int z=0;sum-i-z*3>=0;z++)
	   for(int y=0;sum-i-z*3-y*2>=0;y++){
		dp[(i+1)%2][y][z]=0;
	   }
	 
	 for(int z=0;sum-i-z*3>=0;z++)
	   for(int y=0;sum-i-z*3-y*2>=0;y++){
	   int x=sum-i-y*2-z*3;
	   double s=x+y+z;
	   double t=n;
	   double tmp;
	   if(s==0)continue;
	   if(s==t)tmp=1;
	   else tmp=s/(t-s)*((t-s)/t)/pow(1.0-(t-s)/t,2.0);
	   /*
		if(dp[i%2][x][y][z]*tmp>0){
		cout<<endl;
		DBG(dp[i%2][x][y][z]*tmp);
		DBG(x);
		DBG(y);
		DBG(z);
		}
	   */
	   ans+=dp[i%2][y][z]*tmp;
	   double tdp=dp[i%2][y][z];
	   if(x>0)dp[(i+1)%2][y][z]+=tdp*(double)x/s;
	   if(y>0)dp[(i+1)%2][y-1][z]+=tdp*(double)y/s;
	   if(z>0)dp[(i+1)%2][y+1][z-1]+=tdp*(double)z/s;
	 }
    //DBG(ans);
  }
  printf("%.10lf\n",ans);
  return 0;
}


Measured memory_bytes: 2560
open Batteries
open Printf
let () =
  let n = Scanf.scanf "%d " (fun a -> a) in
  let k = Scanf.scanf "%d " (fun a -> a) in
  let a_lst = Array.to_list @@ Array.init n (fun _ -> Scanf.scanf "%d " (fun a -> a)) in

  let l = List.sort (fun x y -> compare y x) a_lst in
  let (ans_l,_) = List.split_nth k l in

  Printf.printf "%d\n" @@
  List.fold_left (+) 0 ans_l


Measured memory_bytes: 1152
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;

public class Main {
  public static void main(String[] args) throws IOException{
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(in.readLine());
    int[] d = new int[n];
    String[] str = in.readLine().split(" ");
    for(int i=0; i<n; i++) {
      d[i] = Integer.parseInt(str[i]);
    }
    Arrays.sort(d);
    System.out.println(d[n/2]-d[n/2-1]);
  }
}

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

int main() {
    string s;
    cin >> s;
    if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3]) {
        puts("Bad");
    } else {
        puts("Good");
    }
}


Measured memory_bytes: 256
use proconio::input;

macro_rules! chmin {
    ($min_v: expr, $v: expr) => {
        if $v < $min_v {
            $min_v = $v;
            true
        } else {
            false
        }
    };
}

fn main() {
    input! {
        n: usize,
        h: [i64; n],
    };
    // h[i]: 足場 i - 1 の高さ
    // dp[i]: 足場 i - 1 辿り着くまでに支払うコストの総和の最小値
    // 足場 1 は最初から居るのでコスト 0 、それ以外は最小値を求めるため大きな値で初期化する
    let inf = 1_000_000_000_000_i64; // 10^4 * 10^5 が最大。それを超える値。
    let mut dp = vec![inf; n];
    dp[0] = 0;
    for i in 0..n {
        if i + 1 < n {
            chmin!(dp[i + 1], dp[i] + (h[i + 1] - h[i]).abs());
        }
        if i + 2 < n {
            chmin!(dp[i + 2], dp[i] + (h[i + 2] - h[i]).abs());
        }
    }
    let ans = dp[n - 1];
    println!("{}", ans);
}


Measured memory_bytes: 3976
#include<stdio.h>

int	main()
{
  int a[3][3];
  
  int i;
  i=0;
  int j,k;
  while (i<3)
  {
    if(scanf("%d %d %d",&a[i][0],&a[i][1],&a[i][2])==3);
  	i++;
  }
  int N;
  if (scanf("%d",&N)==1);
  int b[N];
  i=0;
  while (i<N)
  {
    if (scanf("%d",&b[i]));
  	j=0;
  	while (j<3)
    {
      k=0;
      while(k<3)
      {
        if(a[j][k]==b[i])
          a[j][k]=0;
        k++;
      }
    	j++;
  	}
    i++;
  }
  
   if((a[0][0]==a[1][0] && a[1][0]==a[2][0]) || (a[0][1] == a[1][1] && a[2][1] ==a[1][1]) || (a[0][2] == a[1][2] && a[1][2] == a[2][2]) || (a[0][0]==a[0][1] && a[0][1]==a[0][2]) ||(a[1][0]==a[1][1] && a[1][1]==a[1][2]) || (a[2][0]==a[2][1] &&a[2][1]==a[2][2]) || (a[0][0]==a[1][1] &&a[1][1]==a[2][2]) ||(a[0][2]==a[1][1] && a[1][1]==a[2][0]))
     printf("Yes");
  else
    printf("No");
    
  
        
  return (0);
}

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

int main() {
  string S;
  vector<char> a(3);
  cin >> a.at(0) >> a.at(1) >> a.at(2);
  int count = 0, count_tmp=0;
  for (int i = 0; i < 3; i++) {
    if(a.at(i)=='R') {
      count ++;
    } else {
      if(count_tmp < count){
          count_tmp = count;
      }
      count = 0;
    }
  }
    if(count_tmp < count){
    count_tmp = count;
    }

  cout << count_tmp << endl;
}

Measured memory_bytes: 3620
# include <iostream>
# include <stdio.h>
# include <cstring>
# include <string>
# include <cctype>
#include <algorithm>
using namespace std;
int main(){
  string W,T;
  int count = 0;
  cin >> W;
  while(1){
    cin >> T;
    if(T == "END_OF_TEXT"){
      break;
    }
    // transformを使う方法
    transform(T.begin(),T.end(),T.begin(),::tolower);
    // c風にやるにはcharを使わないと行けないので若干面倒
    if(T == W){
      count++;
    }
  }
  cout << count << endl;
  return 0;
}



Measured memory_bytes: 3172
#include <utility>
#include <algorithm>
#include <iostream>
using namespace std;

int T, N, K, X[100000+10], A[100000+10];
int main() {
  int sum;
  cin >> T; // Read-in T, the number of data sets
  for (int t=0; t<T; ++t) {
    cin >> N >> K; // Read N, number of houses, K, number of generators
    for (int i=0; i<N; ++i) cin >> X[i]; // the locations of houses
    for (int i=0; i+1<N; ++i) A[i] = X[i+1]-X[i]; // distance between houses
    sort(A, A+N-1);
    sum = 0; // initialize sum as 0
    for (int i = 0; i < N-K; ++i) sum += A[i];
    cout << sum << endl;
  }
}

Measured memory_bytes: 1956
import sys
x,k,d=map(int,input().split())
if x + k*d < 0:
    print(abs(x+k*d))
    sys.exit()
elif x - k*d > 0:
    print(abs(x- k*d))
    sys.exit()
else:
    n0 = -x//d
    ans = [n0-3,n0-2,n0-1,n0,n0+1,n0+2,n0+3]
    if k%2==0:
        ans = [i for i in ans if i%2==0]
    else:
        ans = [i for i in ans if i%2!=0]
    ans = [abs(x+i*d) for i in ans]
print(min(ans))

Measured memory_bytes: 61948
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#define rep(i,n) for (int i = 0; i <= (n); ++i)
using namespace std;
int main() {
	int a, b;
	string ans = "No";
	cin >> a >> b;
	for (int k = 1; k <= 3; ++k) {
		if ((a * b * k) % 2 == 1)ans = "Yes";
}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>
#include <cassert>
#include <bitset>
#include <stack>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define EL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using Graph = std::vector<std::vector<int> >;
const int INF = 1e17;
/* libraries */

signed main() {
	int n,a[3];
	std::cin >> n >> a[0] >> a[1] >> a[2];
	std::vector<std::pair<int,int> > moves;
	rep(i,n) {
		std::string s;
		std::cin >> s;
		int x=s[0]-'A';
		int y=s[1]-'A';
		moves.emplace_back(x,y);
	}
	std::vector<int> ans;
	rep(i,n) {
		int x=moves[i].first;
		int y=moves[i].second;
		if(a[x]==0 && a[y]==0) {
			print("No");
			return 0;
		}
		if(i==n-1) {
			if(a[x]>a[y]) std::swap(x,y);
			ans.emplace_back(x);
			break;
		}
		int nx=moves[i+1].first;
		int ny=moves[i+1].second;
		if(a[x]==0) {
			ans.emplace_back(x);
			a[x]++; a[y]--;
			continue;
		}
		if(a[y]==0) {
			ans.emplace_back(y);
			a[y]++; a[x]--;
			continue;
		}
		if(x==nx || x==ny) {
			ans.emplace_back(x);
			a[x]++; a[y]--;
		} else {
			ans.emplace_back(y);
			a[y]++; a[x]--;
		}
	}
	print("Yes");
	debug(ans);
	rep(i,n) {
		print((char)('A'+ans[i]));
	}
	return 0;
}


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

#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pb push_back
#define all(v) v.begin(), v.end()
#define ar array

#define F first
#define S second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using pii = pair <int, int>;
using pll = pair <ll, ll>;
using ld = long double;

// const int mod = 1e9 + 7;
const int mod = 998244353;
const ll inf = 2e9;
const ll INF = 1e18;
const ld EPS = 1e-7;

const int N = 1e6 + 5;

ll a[N];

int n;

ll check (ll x) {
	ll res = 0;
	for (int i = 1 ; i <= n ; ++ i) {
		ll cur = -99;
		if (a[i] == 0) {
			if (x >= 0) {
				cur = n - i;
				res += cur;
			}
		}
		else if (a[i] > 0) {
			// l, r, x, y
			int l = i + 1, r = n, ans = 0;
			while (l <= r) {
				int m = (l + r) / 2;
				if (a[m] * a[i] <= x) {
					ans = m - i;
					l = m + 1;
				}
				else {
					r = m - 1;
				}
			}
			cur = ans;
			// cur = upper_bound (a + i + 1, a + 1 + n, (x + a[i] - 1) / a[i]) - (a + 1 + i);
			res += cur;
		}
		else {
			int l = i + 1, r = n, ans = 0;
			while (l <= r) {
				int m = (l + r) / 2;
				if (a[m] * a[i] <= x) {
					ans = n - m + 1;
					r = m - 1;
				}
				else {
					l = m + 1;
				}
			}
			cur = ans;
			// cur = (a + n + 1) - lower_bound (a + i + 1, a + 1 + n, x / a[i]);
			res += cur;
		}
		// cerr << a[i] << " " << cur << '\n';
	}
	return res;
}

void solve () {
	ll k;
	cin >> n >> k;
	for (int i = 1 ; i <= n ; ++ i) {
		cin >> a[i];
	}
	cerr << "output\n";
	sort (a + 1, a + 1 + n);
	for (int i = 1 ; i <= n ; ++ i) {
//		cerr << a[i] << " ";
	}
//	cerr << '\n';
	// cerr << check (-7);
	// return;
	ll l = -INF, r = INF, ans = INF;
	while (l <= r) {
		ll m = (l + r) / 2;
		if (check (m) >= k) {
			ans = m;
			r = m - 1;
		}
		else {
			l = m + 1;
		}
	}
	cout << ans;
}

int main () {
	ios;
	int tt = 1;
	// cin >> tt;
	while (tt--) {
		solve();
		cout << "\n";
	}
}




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

using namespace std;
typedef long long ll;

const int MN = 200010;
int n, m;
int a[MN];
ll s1[MN], s2[MN];

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

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

    ll sm = 0;
    for (int i = 0; i < n-1; i++) {
        int l = a[i], r = a[i+1];
        int d = r - l;
        if (d < 0) d += m;
        sm += d;
        if (l < r) {
            s1[l+1]++;
            s2[l+1] += l+1;
            s1[r+1]--;
            s2[r+1] -= l+1;
        } else  {
            s1[l+1]++;
            s2[l+1] += l+1;
            s1[r+m+1]--;
            s2[r+m+1] -= l+1;
        }
    }
    for (int i = 0; i < 2*m-1; i++) {
        s1[i+1] += s1[i];
        s2[i+1] += s2[i];
    }

    ll ma = 0;
    for (int i = 0; i < m; i++) {
        ll cur = i * s1[i] - s2[i] + (i+m) * s1[i+m] - s2[i+m];
        ma = max(ma, cur);
    }
    cout << sm - ma << endl;
    return 0;
}

Measured memory_bytes: 3840
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<functional>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<queue>
#include<random>
#include<set>
#include<stack>
#include<string>
#include<utility>
#include<vector>

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

using namespace std;
typedef pair<int, int> pii;

int n,h[100010]={0};
int dp[100010]={0};

signed main() {
	cin>>n;
    REP(i,n){
        cin>>h[i];
    }

    dp[1]=abs(h[0]-h[1]);
    FOR(i,2,n){
        dp[i]=min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]));
    }
	
    cout<<dp[n-1]<<endl;
	
	return 0;
}


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

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int main(){
    int n; cin >> n;
    vector<int> lis(2*n);
    REP(i, 0, 2*n){cin >> lis[i];}
    sort(ALL(lis), greater<>());
    ll ans = 0;
    for(int i = 1; i < 2*n; i += 2){
        ans += lis[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
//import java.util.ArrayList;
//import java.io.BufferedReader;
//import java.io.InputStreamReader;
//import java.io.IOException;
import java.io.*;
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Main test = new Main();
		test.run();
	}
	

	
	//Data????¨??????\???????????\?????????
	private void run(){
		BufferedReader buf= new BufferedReader(new InputStreamReader(System.in));
		
		do {
			int[] linedata;
			try{
				linedata = changeTestdata(buf.readLine());
			}catch(IOException e){
				System.err.println(e.toString());
				System.err.println("Input Error");
				continue;
			}
			
			if (checkInputDataLast(linedata)) break;
			System.out.println(judgeData(linedata));
			
		}while(true);
	}
	
	private int[] changeTestdata(String line){
		String[] sdata = line.split(" ");
		
		int[] data = new int[sdata.length];
		for (int i = 0; i < sdata.length; i++){
			try {
				data[i] = Integer.parseInt(sdata[i]);
			}catch(NumberFormatException e){
				data[i] = -2;
			}
		}
		
		return data;
	}
	
	private boolean checkInputDataLast(int[] data){
		if (data.length != 3) return false;
		return (data[0] == -1 &&data[1] == -1 &&data[2] == -1) ;
	}
	
	private char judgeData(int[] test){
		if (test.length < 2) return 'F';
		if (test[0] == -1 || test[1] == -1) return 'F';
		if (test[0] + test[1] >= 80) return'A';
		if (test[0] + test[1] >= 65) return 'B';
		if (test[0] + test[1] >= 50) return 'C';
		if (test[0] + test[1] >= 30){
			if (test[2] >= 50) return 'C';
			else return 'D';
		}
		
		return 'F';
	}
}

Measured memory_bytes: 24076
// ABC161E - Yutori

#include <bits/stdc++.h>
using namespace std;

int main() {
	int N, K, C;
	cin >> N >> K >> C;
	string S;
	cin >> S;

	vector<int> early, late;

	for (int i = 0; i < N; i++) {
		if (S[i] == 'o') {
			early.push_back(i);
			if (early.size() == K) {
				break;
			}
			i += C;
		}
	}
	for (int i = N - 1; i >= 0; i--) {
		if (S[i] == 'o') {
			late.push_back(i);
			if (late.size() == K) {
				break;
			}
			i -= C;
		}
	}
	reverse(late.begin(), late.end());

//	for (int i = 0; i < K; i++) {
//		cout << early[i] << " " << late[i] << endl;
//	}

	for (int i = 0; i < K; i++) {
		if (early[i] == late[i]) {
			cout << early[i] + 1 << endl;
		}
	}

	return 0;
}


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

#define loop(n, i) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;

using namespace std;
typedef long long ll;


int main()
{
    int max = 110000;
    vector<int> mat(max, 1);
    vector<int> primes;
    for (int i=2; i<sqrt(max); i++) {
        if (mat[i]) {
            for (int j=i*2; j < max; j+=i) mat[j] = 0;
        }
    }
    for (int i=2; i<max; i++) {
        if (mat[i]) primes.push_back(i);
    }

    int n, p;
    while (cin >> n >> p) {
        if (n == -1) break;

        int start;
        for (int i = 0; i < primes.size(); i++) {
            if (n < primes[i]) {
                start = i;
                break;
            }
        }

        vector<int> nums;
        for (int i = start; i < start+100; i++) {
            for (int j = i; j < start+100; j++) {
                nums.push_back(primes[i]+primes[j]);
            }
        }

        sort(all(nums));
        cout << nums[p-1] << endl;

    }
}

Measured memory_bytes: 3236
#include<bits/stdc++.h>
using namespace std;
char str1[100],str2[100];
int main(void)
{
    cin>>str1;
    cin>>str2;
    bool flag = false;
    for(int i = 0,j = strlen(str1);i < strlen(str1);i++,j--)
    {
        if(str1[i]!=str2[j-1])
            flag = true;
    }
    if(flag)
        printf("NO\n");
    else printf("YES\n");
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
                                                                                                
  
int main(void){
                                                                                                
   
    long long x, t;
   
    char s[100];
   
      
    scanf("%lld %lld", &x, &t );
   

    if( x >= t ){

        printf("%lld\n", x - t );

        return 0;

        }

    else{
   
          printf("0\n");

          return 0;

          }

    return 0;
                                                          
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) { a = b; return 1;} return 0;}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) { a = b; return 1;} return 0;}
#define dame {cout<< "-1" <<"\n"; return;}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
#define PI (acos(-1))
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------

//--MAIN-----------------------------------
void Main() {
    ll N,M; cin>>N>>M;
    vector<ll> A(N);
    rep(i,N) cin>>A[i];
    sort(ALL(A),greater<ll>());
    vector<ll> B(N);
    rep(i,N) B[i]=A[i];
    SORT(B);
    map<ll,ll> mp;
    /*bis*/ ll low= -1 , high= INF2 ; // min-1, max+1
    while( abs(high-low)>1 ){ ll mid=(high+low)/2;
        bool ok=false;
        // mid以上の組で握手
        ll ct=0;
        rep(i,N) if(A[i]*2>=mid) ++ct;
        rep(i,N){
            ll x=mid-A[i];
            ll ind=lower_bound(ALL(B), x)-B.begin();
            ind=N-1-ind;
            if(ind<=i) break;
            ct+=2*(ind-i);
        }
        mp[mid]=ct;
        if(ct>=M) ok=true;
        ( ok ? low : high ) = mid;
    }// if ok, okdir = mid
    vector<ll> sum(N+1,0);
    vector<ll> summ(N+1,0);
    rep(i,N){
        ll x=low-A[i];
        ll ind=lower_bound(ALL(B), x)-B.begin();
        ind=N-1-ind;
        if(ind<=i) break;
        ++sum[i+1];
        ++sum[i+1];
        --sum[ind+1];
        --sum[ind+1];
        summ[i]+=2*(ind-i);
    }
    rep(i,N) if(A[i]*2>=low) summ[i]+=2;
    rep(i,N) sum[i+1]+=sum[i];
    rep(i,N) sum[i]+=summ[i];
    ll ans=0;
    rep(i,N){
        ans+=A[i]*sum[i];
    }
    ans-=(mp[low]-M)*low;

    cout<< ans <<"\n";

    
}

//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


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

void solve()
{
    int N; cin >> N;    
    if (N == 1){
        cout << 0 << endl;
        return;
    } else if (N == 2){
        cout << 2 << endl;
        return;
    }
    const int MOD = 1000000007;

    long long ten=1,nine=1,eight=1;
    for (int i = 0; i < N; ++i) ten = (ten*10) % MOD;
    for (int i = 0; i < N; ++i) nine = (nine*9) % MOD;
    for (int i = 0; i < N; ++i) eight = (eight*8) % MOD;
    long long a = (ten-nine+MOD) % MOD;
    long long b = (ten-eight+MOD) % MOD;
    cout << (2*a-b+MOD) % MOD << endl;
}

int main()
{
    cin.tie();
    ios::sync_with_stdio(false);
    // int ti = clock();
    // input();
    solve();
    // printf("Execution Time: %.4lf sec\n", 1.0 * (clock() - ti) / CLOCKS_PER_SEC);
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define s second
#define int long long
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define pb push_back

using namespace std;
const int N = 1e6 + 7;
const int INF = 1e9 + 7;
const int LOG = 20;
ll ans;
string t,s;
main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
	cin >> s >> t;
    for(int i = 0; i<s.size(); i++)
    {
        if(s[i] == t[i])
        {
            ans++;
        }
    }
    cout << ans;
}


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

int main(){
    string s;
    cin >> s;
    int flag = 0;
    int s1, s2;
    for(int i=0; i<3; i++){
        s1 = s[i] - '0';
        s2 = s[i+1] - '0';
        if(abs(s1-s2) == 0){
            flag = 1;
        }
    }
    if(flag == 1){
        cout << "Bad" << endl;
    }else{
        cout << "Good" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <queue>
#include <vector>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
    string s;
    cin >> s;
    if(s == "ABC") cout << "ARC" << endl;
    else cout << "ABC" << endl;
    return 0;
}


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

int main()
{
    string s;
    cin >> s;
    int n = (s.size() - 2) / 2;
    int cnt = 1;
    
    for(int i = n; i >= 0; i--){
        int t = 1;
        for(int j = 0; j < i; j++){
            if(s[j] != s[i+j]){
                t = 0;
            }
        }
        if(t == 1){
            cout << s.size() - 2 * cnt;
            return 0;
        }else{
            cnt++;
        }
    }
}

Measured memory_bytes: 256
import sys
a=sys.stdin.readline()
res = [int(i) for i in a.split() if i.isdigit()] 
A,B = [res[i] for i in (0,1)]
if B%2==0 and (B>=2 and B<= 1000) and (A>=0 and A<=100):
	if A>=13:
		print(B)
	elif A>=6 and A<=12:
		print(int(B/2))
	elif A<=5:
		print(0)
else:
	print("Error")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
#define Yes "Yes"
#define No "No"
#define YES "YES"
#define NO "NO"
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

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

    
    ll N,A,B;
    cin>>N>>A>>B;
    if(A == 0||A+B==0){
        cout<<0<<endl;
        return 0;
    }
    ll ans = N / (A + B) * A + min(A, (N % (A+B)));
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    long long X;
    cin >> X;
    long long Y = 0;
    long long A = 0;
    if(X == 2){
        cout << X << endl;
    }
    else{
    for(long long i = X; i < 1000000; i++){
        for(long long j = 2; j < X; j++){
        if(X % j == 0){
            break;
        }
        if(j == X - 1){
            Y = X;
            A = 1;
            break;
        }
        }
        if(A == 1){
            break;
        }
        X++;
    }
    cout << Y << endl;
    }
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Bytes, Chars, Isize1, Usize1},
};

#[allow(unused_macros)]
macro_rules! echo {
    ($($e:expr),+) => ( { $(println!("{}", $e))+ } );
}

fn main() {
    input! {
        s: String,
        t: String,
    }

    let t = t[0..t.len() - 1].to_owned();

    if s == t {
        echo!("Yes");
    } else {
        echo!("No");
    }
}


Measured memory_bytes: 2072
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>
#include <sys/time.h>
#include <random>


#define fs first
#define sc second
#define endl "\n"

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef pair<string, int> P;


class Graph{
    struct edge{
        int vertice;
        ll weight;
    };

    vector<vector<edge>> g;
    unsigned int n;

public:
    Graph(unsigned int n): n{n}{
        g.resize(n);
    }

    void add_edge(int u, int v){
        g[u].emplace_back(edge{v, 1});
    };

    void add_edge(int u, int v, ll w){
        g[u].emplace_back(edge{v, w});
    }

    vector<edge>& get_edge(int v){
        return g[v];
    }

    unsigned int size(){
        return n;
    }

    vector<edge>& operator[](int v){
        return get_edge(v);
    }
};

int retCityNum(int u, int cur){
    return u * 2502 + cur;
}

/**
 *
 * @param s 始点
 * @param g グラフ
 * @return sから各頂点への距離
 */
vector<ll> dijkstra2(int s, Graph g, ll INF=LONG_LONG_MAX / 3){
    typedef pair<ll, int> Ptmp;  // firstは最短距離、secondは頂点の番号

    unsigned int n = g.size();
    priority_queue<Ptmp, vector<Ptmp>, greater<Ptmp>> que;
    vector<ll> d(n, INF);

    d[s] = 0;
    que.push(Ptmp(d[s], s));

    while(!que.empty()){
        Ptmp p = que.top();   que.pop();
        int v = p.second;
        if(d[v] < p.first) continue;
        for(auto e: g[v]){
            if(d[e.vertice] > d[v] + e.weight){
                d[e.vertice] = d[v] + e.weight;
                que.push(Ptmp(d[e.vertice], e.vertice));
            }
        }
    }

    return d;
}



int main(){
    ll N, M, S; cin >> N >> M >> S;
    Graph g(2502 * N);
    for(int i = 0; i < M; i++){
        int u, v;   ll a, b;
        cin >> u >> v >> a >> b;
        u--; v--;
        for(int j = 2501; j >= 0; j--){
            if(j - a < 0)   continue;
            g.add_edge(retCityNum(u, j), retCityNum(v, j - a), b);
            g.add_edge(retCityNum(v, j), retCityNum(u, j - a), b);
        }
    }
    for(int i = 0; i < N; i++){
        ll c, d;    cin >> c >> d;
        for(ll j = 0; j <= 2501; j++){
            if(j + c > 2501){
                g.add_edge(retCityNum(i, j), retCityNum(i, 2501), d);
                break;
            }
            else{
                g.add_edge(retCityNum(i, j), retCityNum(i, j+c), d);
            }
        }
    }

    if(S >= 2501)   S = 2501;
    vector<ll> resList = dijkstra2(retCityNum(0, S), g);

    for(int i = 1; i < N; i++){
        ll res = LONG_LONG_MAX;
        for(int j = retCityNum(i, 0); j <= retCityNum(i, 2501); j++) {
            res = min(res, resList[j]);
        }
        cout << res << endl;
    }


    return 0;
}


Measured memory_bytes: 37996
import java.io.*;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) {
  //      final FastScanner fs = new FastScanner("/Users/igorz/dev/google-prep/src/main/java/atcoder/abc100/input.txt");
        final FastScanner fs = new FastScanner();

        final int[] arr = fs.nextIntArray();

        int count = 0;

        for (int i : arr) {
            while (i % 2 == 0) {
                count++;
                i /= 2;
            }
        }
        System.out.println(count);
    }

    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

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

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

        int[] nextIntArray() {
            final int N = nextInt();
            int[] arr = new int[N];
            for (int i = 0; i < N; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }

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

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

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


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

int main(){

	int N, M, C;
	int x;
	//int A[20]; 
	int B[20];
	int sum = 0;
	int count = 0;
	cin >> N >> M >> C;

	for (int i = 0; i < M; i++){
		cin >> x;
		B[i] = x;
	}

	for (int i = 0; i < N; i++){
		sum = C;
		for (int j = 0; j < M; j++){
			cin >> x;
			//A[j] = x;
			sum += x * B[j] ;
		}
		if (sum > 0){
			count++;
		}
		
	}

	cout << count << endl;


	
	return 0;
}



Measured memory_bytes: 256
<?php
  list($n, $k) = explode(" ", trim(fgets(STDIN)));
  $h = explode(" ", trim(fgets(STDIN)));
  
  $dp = [];

  $dp[0]=0;
  for($i=1;$i<$n;$i++){
    $dp[$i]=PHP_INT_MAX;
    for($j=1;$j<=$k;$j++){
      if(($i-$j) < 0){
        continue;
      }
      if((abs($h[$i-$j]-$h[$i])+$dp[$i-$j]) < $dp[$i]){
        $dp[$i]=(abs($h[$i-$j]-$h[$i])+$dp[$i-$j]);
      }
    }
  }
  echo $dp[$n-1];

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

int main()
{
    int N, M;
    cin >> N >> M;
    cout << N * (N-1) / 2 + M * (M-1) / 2 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define DEBUG "::"
#define REPI(itei) for(long long int i = 0,ite=itei;i < ite;i++)
#define REPJ(itej) for(long long int j = 0,ite=itej;j < ite;j++)
#define REPK(itek) for(long long int k = 0,ite=itek;k < ite;k++)
using namespace std;
typedef long long int ll;
int main(){
    int N;
    cin >> N;
    vector<int>a;
    int sum = 0;
    REPI(N){
        int x;
        cin >> x;
        a.push_back(x);
        sum+=x;
    }
    double avg = (double)sum/N;
    double mi = 99999999;
    int ans = 0;
    REPI(N){
        double s = abs(a[i]-avg);
        if(s < mi){
            mi = s;
            ans = i;
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    int n; cin >> n;
    vint a(n);
    rep(i,n) cin >> a[i];
    bool ans = false;
    int mx = *max_element(all(a));
    int mn = *min_element(all(a));
    if (mx - mn == 1) {
        int ct_mx = 0, ct_mn = 0;
        rep(i,n) {
            if (a[i] == mx) ct_mx++;
            else ct_mn++;
        }
        if (ct_mn < mx && n + ct_mn >= 2 * mx) ans = true;
    }
    if (mx - mn == 0) {
        if (mx + 1 == n || n >= 2 * mx) ans = true;
    }
    if (ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3792
#!/usr/bin/env python3
import sys

NO = ":("
def solve(N: int):
    for i in range(1,50001):
        if int(i*1.08) == N:
            print(i)
            return
    
    print(NO)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
from collections import Counter
#先に数えておく
N=int(input())
A=list(map(int,input().split()))
low=min(A)
high=max(A)

c_l=Counter(A)
ans=-1
for x in range(low,high+1):
    #範囲
    a=x-1
    b=x
    c=x+1
    num=c_l[a]+c_l[b]+c_l[c]
    ans=max(num,ans)
print(ans)

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

using namespace std;

int main()
{
	long long a, b, c;

	cin >> a >> b >> c;

	//Keep a>b>c
	if (a < b)
		swap(a, b);
	if (a < c)
		swap(a, c);
	if (b < c)
		swap(b, c);

	if (a % 2)//最大边为奇数
	{
		cout << b * c << endl;
	}
	else
		cout << 0 << endl;
}

Measured memory_bytes: 256