akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main(){
	int a[4],b[4],sum_a=0,sum_b=0;

	cin >> a[0] >> a[1] >> a[2] >> a[3];
	cin >> b[0] >> b[1] >> b[2] >> b[3];

	for(int i=0; i<4; ++i){
		sum_a += a[i];
		sum_b += b[i];
	}

	if(sum_a >= sum_b){
		cout << sum_a << endl;
	}else{
		cout << sum_b << endl;
	}
}	

Measured memory_bytes: 1160
N,K=gets.split.map(&:to_i)

m=10**9+7
a=[]
ret = K.downto(1).sum{|i|
  t = K/i
  a[i]=t.pow(N,m) - (2..t).sum{|j|a[i*j]}
  i*a[i]
} % m

p ret


Measured memory_bytes: 15200
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

void solve() {
    int N;
    cin >> N;
    VVI D(N, VI(2));
    REP(i, N) {
        REP(j, 2) cin >> D[i][j];
    }

    REP(i, N) {
        bool f = true;
        REP(j, 3) {
            if (i + j >= N) f = false;
            else {
                if (D[i + j][0] != D[i + j][1]) f = false;
            }
        }
        if (f) {
            cout << "Yes" << endl;
            return;
        }
    }

    cout << "No" << endl;
}

int main(void) {
#ifndef ONLINE_JUDGE
    const auto in_stream = freopen("../in.txt", "r", stdin);
    if (in_stream == nullptr) {
        cerr << "ERROR!" << endl;
        return 1;
    }
#endif

    solve();

#ifndef ONLINE_JUDGE
    fclose(in_stream);
#endif
}


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

vector<int> to[200005]; //木の構造
//double memo[200005][200005];//この様に2次元配列を外に置くと危ない
//int done[200005][200005];
vector<vector<int>> done(3000, vector<int>(3000));
vector<vector<double>> memo(3000, vector<double>(3000));
ll n;
vector<double> data;
double dp(int u, int nq)
{
    if (done[u][nq] == 1)
    {
        return memo[u][nq];
    }
    if (n - 1 - u < nq) //使える枚数が残りのカードより多い。
    {
        return 1;
    }
    if (nq == -1)
    {
        return 0;
    }
    double res;
    res = dp(u + 1, nq - 1) * (1 - data[u]) + dp(u + 1, nq) * (data[u]);
    //uスタートのカードは使えるカードがnq-1だけのものとnqだけのものの和(これらに重なりはない) //
    done[u][nq] = 1;
    memo[u][nq] = res;
    return res;
}
int main()
{

    cin >> n;
    data.resize(n);
    rep(i, n)
    {
        cin >> data[i];
    }
    //裏の数がn/2枚まで行ける。
    cout << fixed << setprecision(10) << dp(0, n / 2); //0枚目からスタートで使っていいカードがn/2だけ残っているとき。(ここは以下の様な曖昧な言葉を使わない。)
}

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

#define N 200010
typedef long long LL;
const int mod = 1e9 + 7; 
const double EPS = 1e-12;

int n;
int v[N];
LL s[N];

LL work(LL a, LL b, LL c, LL d)
{
	return max(a, max(b, max(c, d))) - min(a, min(b, min(c, d)));
}

int main()
{ 
    //freopen("in.txt", "r", stdin);
   	
   	scanf("%d", &n);
   	
   	for (int i = 1; i <= n; ++i)
   		scanf("%d", &v[i]), s[i] = s[i - 1] + v[i];
   	
	
	LL ans = 1e18;
	int k1 = 1, k2 = 3;
    for (int i = 2; i <= n - 2; ++i)
    {
    	while (k1 + 1 < i && s[k1 + 1] <= s[i] - s[k1 + 1]) ++k1;
    	while (k2 + 1 < n && s[k2 + 1] - s[i] <= s[n] - s[k2 + 1]) ++k2;
    	
    	ans = min(ans, work(s[k1], s[i] - s[k1], s[k2] - s[i], s[n] - s[k2]));
    	if (k1 + 1 < i) ans = min(ans, work(s[k1 + 1], s[i] - s[k1 + 1], s[k2] - s[i], s[n] - s[k2]));
    	if (k2 + 1 < n) ans = min(ans, work(s[k1], s[i] - s[k1], s[k2 + 1] - s[i], s[n] - s[k2 + 1]));
    	if (k1 + 1 < i && k2 + 1 < n) ans = min(ans, work(s[k1 + 1], s[i] - s[k1 + 1], s[k2 + 1] - s[i], s[n] - s[k2 + 1]));
    }
    cout << ans << endl;
 
    
    
    
	return 0;
}

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

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

	vector<vector<int>> g(n+1);
	for (int i=0;i<m;++i)
	{
		int a,b;
		cin >> a >> b;
		g[a].push_back(b);
		g[b].push_back(a);
	}

	vector<int> shirube(n+1);
	for (int i=0;i<=n;++i)
	{
		shirube[i]=-1;
	}

	queue<int> q;
	q.push(1);

	while (q.empty()==false)
	{
		int node=q.front();
		q.pop();

		for (int i=0;i<g[node].size();++i)
		{
			int nn=g[node][i];
			if (shirube[nn]<0)
			{
				shirube[nn]=node;
				q.push(nn);
			}
		}
	}

	for (int i=2;i<=n;++i)
	{
		if (shirube[i]<0)
		{
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;
	for (int i=2;i<=n;++i)
	{
		cout << shirube[i] << endl;
	}
}






Measured memory_bytes: 10216
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<ll,ll> pi;
#define inf 1000000000000000000
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define f first
#define ss second
#define pb push_back
#define mp make_pair

ll n, z, w, a[2020];


int main(){
cin >> n >> z >> w;
a[0]=w;
rep(i, 1, n)cin >> a[i];
cout << max(abs(a[n]-w), abs(a[n-1]-a[n]));

return 0;}


Measured memory_bytes: 256
n, k = map(int, input().split())
s = str(input())

count = 1
Nums_count = []
now = s[0]
start = 0
for i in range(1,n):
    if s[i] == str(now):
        count += 1
    else:
        Nums_count.append([start, count])
        now = s[i]
        start = i
        count = 1
    if i == n-1:
        Nums_count.append([start, count])
if len(s) == 1:
    Nums_count.append([0,1])

Nums_count_rui = [[-1, 0]]
for i in range(len(Nums_count)):
    Nums_count_rui.append([Nums_count[i][0],Nums_count[i][1]+Nums_count_rui[-1][1]])

# print(Nums_count_rui)
ans = 0
m = len(Nums_count_rui)

if s[0] == '0' and m <= 2*k:
    ans = n
elif s[0] == '1' and m <= 2*k+1:
    ans = n

for i in range(1,m):
    if s[Nums_count_rui[i][0]] == '0':
        if i+2*k-1 >= m:
            tot = Nums_count_rui[-1][1] - Nums_count_rui[i-1][1]
        else:
            tot = Nums_count_rui[i+2*k-1][1] - Nums_count_rui[i-1][1]
    else:
        if i+2*k >= m:
            tot = Nums_count_rui[-1][1] - Nums_count_rui[i-1][1]
        else:
            tot = Nums_count_rui[i+2*k][1] - Nums_count_rui[i-1][1]
    ans = max(tot, ans)
print(ans)

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

#define MOD (1000000000+7)

int main()
{
	long long n, k;
	cin >> n >> k;

	long long ans = 0;
	if( n <= k ) {
		ans = 1;
		for( int i = 0; i < n; i++ ) {
			ans = ans * k % MOD;
			k--;
		}
	}
	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 3136
#include<bits/stdc++.h>
#define INF 100000000000000000
using namespace std;

int main()
{
  long long Q,H,S,D;scanf("%lld %lld %lld %lld",&Q,&H,&S,&D);
  H=min(Q*2,H);S=min(H*2,S);D=min(S*2,D);
  long long N;scanf("%lld",&N);
  printf("%lld",N/2*D+N%2*S);
}

Measured memory_bytes: 3716
mo=10**9+7
n,m=map(int,input().split())
x=[int(i) for i in input().split()]
y=[int(i) for i in input().split()]
X,Y=0,0
for i in range(n):
    X+=x[i]*(n-2*i-1)
    X%=mo
for i in range(m):
    Y+=y[i]*(m-2*i-1)
    Y%=mo
print(X*Y%mo)

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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		List<Integer> list = new ArrayList<>();
		
		for (int i=0; i<3; i++) {
			list.add(sc.nextInt());
		}
		
		sc.close();
		
		insertionSort(list);
		
		String str = "";
		for (int i : list) {
			str += String.valueOf(i) + " ";
		}
		System.out.println(str.trim());
	}
	
	static List<Integer> insertionSort(List<Integer> list) {
		for (int i=1; i<list.size(); i++) {
			int v = list.get(i);
			int j = i - 1;
			while (j >= 0 && list.get(j) > v) {
				list.set(j + 1, list.get(j));
				j--;
			}
			list.set(j + 1, v);
		}
		return list;
	}
}

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

int abs(int x) {
  if (x < 0) {
    x *= -1;
  }
  return x;
}

int main(){
  long long a , v , b , w , t;
  cin >> a >> v >> b >> w >> t;
  if (abs(a - b) <= (v - w) * t) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 3632
import java.util.Scanner;

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

    int n = sc.nextInt();
    int[] results = new int[n + 1];

    for (int i = 1; i <= 105; i++) {
      for (int j = 1; j <= 105; j++) {
        for (int k = 1; k <= 105; k++) {
          int multiply = i * (i + j + k) + j * (j + k) + k * k;
          if (multiply <= n) {
            results[multiply]++;
          }
        }
      }
    }
    for (int i = 1; i <= n; i++) {
      System.out.println(results[i]);
    }
  }
}


Measured memory_bytes: 38728
def q3():
    from collections import deque
    N = int(input())
    S = deque(list(input()))
    ans = deque()
    for i in range(len(S)):
        s = S.popleft()
        #print(S)
        if len(S) > 0 and s != S[0]:
            ans.append(s)
    print(len(ans) + 1)


if __name__ == '__main__':
    q3()


Measured memory_bytes: 4916
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n,a,b = LI()
    r = 0
    for i in range(1,n+1):
        s = sum([int(_) for _ in str(i)])
        if a <= s <= b:
            r += i

    return r



print(main())




Measured memory_bytes: 5464
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

signed main() {
        int n;scanf("%d",&n);
        set<int>s;
        rep(i,n){
                int a;scanf("%d",&a);
                if(s.count(a))s.erase(a);
                else s.insert(a);
        }
        cout<<s.size()<<endl;
}


Measured memory_bytes: 4864
#include<stdio.h>
int main(){
  long long n,i,j,all=0;
  scanf("%lld",&n);
  long long a[n];
  for(i=0;i<n;i++){
    scanf("%lld",&a[i]);
  }
  for(i=0;i<n-1;i++){
      for(j=0;j<n-1-i;j++){
	if(a[j]<a[j+1]){
	  long long temp = a[j];
	  a[j] = a[j+1];
	  a[j+1] = temp;
	}
      }
    }
  for(i=0;i<n;i++){
    all += a[i];
  }
  printf("%lld %lld %lld\n",a[n-1],a[0],all);
  return 0;
}

Measured memory_bytes: 680
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

#define REP(i,x,y) for(int i=(x);i<(y);i++)
#define RREP(i,x,y) for(int i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
//#define int long long

using namespace std;

// conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

#define dump(x)  cout << #x << " = " << (x) << endl
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

typedef long long ll;

const ll MOD = 1e9 + 7;

class EGluttony {
public:
    void solve(std::istream& in, std::ostream& out) {
        ll N, K;
        in >> N >> K;
        vector<ll> A(N), F(N);
        REP(i,0,N) in >> A[i];
        REP(i,0,N) in >> F[i];
        sort(all(A));
        sort(all(F), greater<ll>());

        ll left = -1, right = (ll)1e12 + 1;
        while (right - left > 1) {
            ll mid = (left + right) / 2;
            ll k = K;
            REP(i,0,N) {
                if (A[i] * F[i] <= mid) continue;
                k -= A[i] - (mid / F[i]);
                if (k < 0) break;
            }
            if (k < 0) { // NG
                left = mid;
            } else {
                right = mid;
            }
        }
        ll answer = right;
        out << answer << "\n";
    }
};


int main() {
	EGluttony solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3456
# C - Multiple Clocks
# import math mathはatcoderでは使えない
from fractions import gcd
N = int(input())
T = [int(input()) for i in range(N)]
# 最小公倍数を求める
if N == 1:
    print(T[0])
else:
    DP = [0]*(N-1)
    DP[0] = (T[0]*T[1])//gcd(T[0],T[1])
    for i in range(1,N-1):
        DP[i] = (DP[i-1]*T[i+1]) // gcd(DP[i-1],T[i+1])
    print(DP[-1])

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

#define ll long long
#define MOD 1000000007
#define FASTREAD ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

int main() {
    ll n, k;
    cin >> n >> k;

    vector<ll> arr;
    map<ll,ll> chk;
    for(ll i=0; i<n; i++) {
        ll temp;
        cin >> temp;
        if(chk[temp]==0) {
            arr.push_back(temp);
            chk[temp]++;
        } else chk[temp]++;
    }

    vector<ll> pac;
    for(ll i=0; i<arr.size(); i++) pac.push_back(chk[arr[i]]);
    sort(pac.begin(), pac.end());

    ll sum=0;
    if(k>=pac.size()) cout << sum << endl;
    else {
        for(ll i=pac.size()-1; i>=0; i--) {
            if(k!=0) k--;
            else sum+=pac[i];
        }
        cout << sum << endl;
    }
}


Measured memory_bytes: 17392
#https://atcoder.jp/contests/dp/tasks/dp_c
#input
n = int(input())
happiness = [list(map(int,input().split())) for _ in range(n)]
#initialization
dp = [[0,0,0] for _ in range(n+1)]

#dp algorithm
for day in range(n):
  for j in range(3):
    for k in range(3):
      #skip same activity
      if j==k:
        continue
      #calculate max happiness day by day
      dp[day+1][k] = max(dp[day+1][k],dp[day][j]+happiness[day][k])

#print(dp)
print(max(dp[n]))

Measured memory_bytes: 47328
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
pair<ll, int> a[100010];
ll mem[2010][2010], n;
ll dp(int x, int y){
	if(x+y==n){
		return 0;
	}
	if(mem[x][y]!=-1){
		return mem[x][y];
	}
	ll res=0;
	int tmp=n-x-y-1;
	res=max(a[tmp].fs*abs(a[tmp].sc-x)+dp(x+1, y), a[tmp].fs*abs(a[tmp].sc-(n-y-1))+dp(x, y+1));
	mem[x][y]=res;
	return res;
}
int main(){
    while(cin>>n){
        ll ans=0;
        int x;
        for(int i=0; i<n; ++i){
            scanf("%d",&x);
            a[i]=mk(x, i);
        }
        sort(a, a+n);
        memset(mem, -1, sizeof mem);
        ans=dp(0, 0);
        cout<<ans<<endl;
    }
  return 0;
}




Measured memory_bytes: 35476
#include "bits/stdc++.h"
using namespace std;
using ll = long long; using ull = unsigned long long;
//#define int ll
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(ll i = (ll)(n)-1;i >= 0;--i)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1);
const double EPS = 1e-10;
const ll MOD = 1e9+7;
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}
signed main(){
  string in;
  vi a(4);
  cin >> in;
  REP(i,4) a.at(i)=in.at(i)-'0';
  REP(i,2){
    int val = a.at(0);
    if(i==0) val+=a.at(1);
    else val -= a.at(1);
    REP(j,2){
      if(j==0) val += a.at(2);
      else val -= a.at(2);
      REP(k,2){
        if(k==0) val += a.at(3);
        else val -= a.at(3);
        if(val==7){
          cout << a.at(0);
          if(i==0) cout << "+";
          else cout << "-";
          cout << a.at(1);
          if(j==0) cout << "+";
          else cout << "-";
          cout << a.at(2);
          if(k==0) cout << "+";
          else cout << "-";
          cout << a.at(3) << "=7" << endl;
          return 0;
        }
        if(k==0) val -= a.at(3);
        else val += a.at(3);
      }
      if(j==0) val -= a.at(2);
      else val += a.at(2);
    }
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		int N = sc.nextInt();
		int R = sc.nextInt();

		if (N >= 10) {
			System.out.println(R);
		} else {
			System.out.println(R + (100 * (10 - N)));
		}

		sc.close();
	}

}


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

int main(){
    int N, K;
    double sum=0;
    cin >> N >> K;
    for(int i=1;i<=N;i++){
        double tmp = 1.0 / static_cast<double>(N);
        int score = i;
        while(score<K){
            tmp /= 2.0;
            score *= 2;
        }
        sum += tmp;
    }
    cout << fixed << setprecision(12) << sum << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
namespace Sample
{
  class Sample
  {
    static void Main(string[] args)
    {
    int N=int.Parse(Console.ReadLine());
      if(N<1200){
        Console.WriteLine("ABC");
      }else if(N<2800){
        Console.WriteLine("ARC");
      }else{
        Console.WriteLine("AGC");
      }
    }
    
  }

}


Measured memory_bytes: 27384
// clang-format off
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i,n) for(ll i=n-1; i>=0; --i)
#define rrep1(i,n) for(ll i=n; i>0; --i)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define SORT_DESC(x) sort((x).rbegin(),(x).rend())
#define pb push_back
#define mp make_pair
#define coutl cout<<fixed<<setprecision(10)
#define ANS(ans) cout<<ans<<endl;
const ll LINF = (1LL << 62) - 1;
const int INF = (1 << 30) - 1;
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;}
// clang-format on

void solve(long long N, long long M, std::vector<long long> A) {
  ll sum = accumulate(all(A), 0LL);
  ANS((N >= sum ? N - sum : -1));
}

// clang-format off
int main() {
  long long N;
  scanf("%lld",&N);
  long long M;
  scanf("%lld",&M);
  std::vector<long long> A(M);
  for(int i = 0 ; i < M ; i++){
    scanf("%lld",&A[i]);
  }
  solve(N, M, std::move(A));
  return 0;
}


Measured memory_bytes: 3756
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

static const long long mod = 1000000007;

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n, l;
  cin >> n >> l;
  vector<string> lst(n);
  rep(i, n) cin >> lst[i];
  Sort(lst);

  string ans = "";
  rep(i, n) ans += lst[i];

  cout << ans << endl;

  return 0;
}


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

int main() {
    int N;
    cin >> N;
    vector <int> ans_list(N);

    for (int i = 0; i < N; i++) {
        int tmp;
        cin >> tmp;
        ans_list[tmp-1] = i+1;
    }

    for (int i = 0; i < N; i++) {
        cout << ans_list[i];
        if (i != N-1) {
            cout << " ";
        }
    }

    return 0;
}

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

int main() {
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  if (a+b >= k) cout << min(k, a) << endl;
  else cout << a - min(c, k-a-b) << endl;
  return 0;
}

Measured memory_bytes: 3612
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    int K;
    cin >> K;
    int A[K];
    for (int i = 0; i < K; i++) cin >> A[i];

    int x_max = 2;
    int x_min = 2;

    for (int i = K - 1; i >= 0; i--) {
        x_min = ceil(1.0 * x_min / A[i]) * A[i];
        x_max = (x_max / A[i]) * A[i] + (A[i] - 1);

        if (x_min > x_max) {
            cout << -1 << endl;
            return 0;
        }
    }

    cout << x_min << " " << x_max << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef long long ll;
const int N = 100005;
int p[N];
int rk[N];
int numComp;
int findset(int x){
    return p[x] == x ? x : p[x] = findset(p[x]);
}
bool sameset(int x, int y){
    return findset(x) == findset(y);
}
void unionset(int x, int y){
    x = findset(x), y= findset(y);
    if (x == y) return;
    numComp--;
    if (rk[x] > rk[y]) swap(x,y);
    p[y] = x;
    if (rk[x] == rk[y]) rk[x]++;
}
iii queries[N];
int n,q;
ll m;
ll f(int x){
    return n-x + (ll)x*(x-1)/2;
}
int main(){
    scanf("%d%lld%d",&n,&m,&q);

    for (int i = 0; i < q; i++){
        scanf("%d%d%d",&queries[i].se.fi,&queries[i].se.se,&queries[i].fi);
    }
    iota(p,p+n,0);
    sort(queries,queries+q);
    numComp = n;
    bool have1 = false;
    for (int i = 0; i < q; i++){
        int Q = queries[i].fi, u = queries[i].se.fi, v = queries[i].se.se;
        if (Q == 0){
            unionset(u,v);
        }
        else{
            have1 = true;
            if (sameset(u,v)){
                printf("No");
                return 0;
            }
        }
    }
    if (numComp == 1 || have1 == false) printf("%s\n",m == (ll)n-1 ? "Yes":"No");
    else printf("%s\n",m >= (ll)n && m <= f(numComp) ? "Yes":"No");

}


Measured memory_bytes: 2176
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long

signed main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, K;
	cin >> N >> K;
	int a[N], b[N];
	rep(i, N) cin >> a[i] >> b[i];
	int c[100010] = {};
	rep(i, N) c[a[i]] += b[i];
	int sum = 0;
	rep(i, 100010) {
		sum += c[i];
		if (sum >= K) {
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n=3;
    int i;
    int a[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    cout<<min(abs(a[2]-a[1])+abs(a[1]-a[0]),min(abs(a[2]-a[1])+abs(a[1]-a[0]),abs(a[2]-a[1])+abs(a[2]-a[0])))<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int mod=1e9+7;

ll memo[22][1<<22];
ll a[22][22],n;
ll go(ll pos,ll val){
    if(pos==n){
        if(val+1==(1<<n)) return 1;
        return 0;
    }
    if(memo[pos][val]!=-1){
        return memo[pos][val];
    }
    ll ans=0;
    for(ll i=0;i<n;i++){
        if(a[pos][i]==0) continue;
        if(((val)&(1<<i))==(1<<i)) continue;
        ans+=go(pos+1,(1<<i)|val);
        ans%=mod;
    }
    return memo[pos][val]=ans;
}

int main(){
    //ll n;
    cin>>n;
    memset(memo,-1,sizeof(memo));
    for(ll i=0;i<n;i++){
        for(ll j=0;j<n;j++){
            cin>>a[i][j];
        }
    }
    cout<<go(0,0);
}

Measured memory_bytes: 721152
#include "bits/stdc++.h"

using namespace std;

long long dp[8][10][10];
bool memoize[8][10][10];
int arr[8];
int firstDigit;
int lastDigit;

long long solve(int pos, int fdigit, int ldigit, bool flag = 1, bool taken = 0) {
	if (pos < 0) {
		return (fdigit == firstDigit and ldigit == lastDigit);
	}
	long long &ret = dp[pos][fdigit][ldigit];
	bool &mem = memoize[pos][fdigit][ldigit];
	if (!flag and taken and mem) {
		return ret;
	}
	int loop = 9;
	if (flag) {
		loop = arr[pos];
	}
	long long sum = 0;
	for (int i = 0; i <= loop; i++) {
		if (!taken and i == 0) {
			sum += solve(pos - 1, 0, 0, 0, 0);
		}
		else {
			int nfdigit = fdigit;
			if (nfdigit == 0) {
				nfdigit = i;
			}
			sum += solve(pos - 1, nfdigit, i, flag and i == arr[pos], 1);
		}
	}
	if (!flag and taken) {
		mem = 1;
		ret = sum;
	}
	return sum;
}

long long digitDp(int n) {
	int len = 0;
	while (n) {
		arr[len++] = n % 10;
		n /= 10;
	}
	memset(memoize, 0, sizeof memoize);
	return solve(len - 1, 0, 0);
}

int mat[10][10];

int get(int n) {
	int f = -1;
	while (n) {
		f = n % 10;
		n /= 10;
	}
	return f;
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		int fst = get(i);
		int lst = i % 10;
		mat[fst][lst]++; 
	}
	long long ans = 0;
	for (int i = 1; i <= 9; i++) {
		for (int j = 1; j <= 9; j++) {
			firstDigit = j;
			lastDigit = i;
			long long res = digitDp(n);
			ans += res * mat[i][j];
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3604
N,L = map(int,input().split())
a = []
for i in range(1,N+1):
  a.append(L+i-1)
b = []
for i in a:
  b.append(abs(i))
for i in range(1,N+1):
  if abs(L+i-1) == min(b):
    print(sum(a)-L-i+1)

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

using namespace std;

int main()
{
    vector<int> H, W;
    for(;;){
        int h, w;
        cin >> h >> w;
        if(h == 0 && w == 0) break;
        H.push_back(h);
        W.push_back(w);
    }
    
    for(int i = 0; i < H.size(); i++){
        for(int h = 0; h < H.at(i); h++){
            for(int w = 0; w < W.at(i); w++){
                if(h == 0 || h == H.at(i)-1 || w == 0 || w == W.at(i)-1){
                    cout << "#";
                }else{
                    cout << ".";
                }
            }
            cout << endl;
        }
        cout << endl;
    }

}


Measured memory_bytes: 3128
import java.util.*;

class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        boolean[] prime = new boolean[123457*2];
        Arrays.fill(prime, true);
        prime[0] = prime[1] = false;
        
        for(int i = 2; i<prime.length;++i){
            if (prime[i]){
                for(long j = (long)i * i; j<prime.length; j +=i){
                    prime[(int)j]=false;
                }
            }
        }
        
        int[] count = new int[123457*2];
        count[0] = count[1] = 0;
        for(int i=2; i<count.length; i++){
            count[i] = count[i-1] + (prime[i] ? 1:0);
        }
        
        while(true){
            int N = sc.nextInt();
            if(N == 0) break;
            System.out.println(count[2*N] - count[N]);
        }
    }
}

Measured memory_bytes: 23416
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll ;
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
 const ll inf=1e9+7;

int main()
{
    fast;
    

	ll n,x;
	cin>>n>>x;
	
	ll a[n+1];
	
	a[0]=0;
	for(int i=1;i<=n;i++)cin>>a[i];
	
	ll ans=0;
	
	for(ll i=1;i<=n;i++)
	{
		if(a[i]+a[i-1]>x)
		{
			ll delta;
			delta=a[i]+a[i-1]-x;
			
			
			if(delta>a[i])a[i]=0,delta-=a[i],a[i-1]-=delta;
			else 
			a[i]-=delta;
			
			ans+=delta;
			
		}
	}
	


cout<<ans;
}



		
	
	
	
	


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

int main(void){
	char s[11],t[11];
  scanf("%s %s",s,t);
  int a,b;
  scanf("%d %d",&a,&b);
  char u[11];
  scanf("%s",u);
  if(strcmp(u,s)==0){
  	printf("%d %d\n",a-1,b);
  }
  else{
  	printf("%d %d\n",a,b-1);
  }
  return 0;
}

Measured memory_bytes: 128
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        A solver = new A();
        solver.solve(1, in, out);
        out.close();
    }

    static class A {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int N = in.Int();
            int A = in.Int();
            out.println(N % 500 <= A ? "Yes" : "No");

        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    return null;
                }
            }
            return st.nextToken();
        }

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

    }
}



Measured memory_bytes: 21588
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <deque>

int main()
{
    long a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    long K;
    std::cin >> K;
    std::cout << a[K-1] << std::endl;
    return 0;
}

Measured memory_bytes: 256
// Hint: Don't look, No need

#pragma optimize("O2")
#include <bits/stdc++.h>
#include "bits/stdc++.h"

using namespace std;

#define int long long
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#ifndef bhupixb
  #define var(...)
  #define stl(...)
#endif

signed main() {
  fast;
  int n;
  cin >> n;
  vector<int> a(n);
  bool f = 0;
  for (int &x: a) {
    cin >> x;
    f |= x == 0;
  }
  if (f) {
    cout << 0 << '\n';
    return 0;
  }
  const int inf = 1e18 + 4;
  int cur = 1;
  for (int &x: a) {
    if (cur <= inf / x) {
      cur *= x;
    }
    else {
      return cout << -1 << '\n',0;
    }
  }

  cout << cur << '\n';
  return 0;
}

Measured memory_bytes: 3964
s = int(input())

la = [s]

i = 0
while la.count(la[i]) == 1:
    if la[i] % 2 == 0:
        la.append(la[i]//2)
    else:
        la.append(3 * la[i] + 1)
    i += 1
    
print(len(la))

Measured memory_bytes: 3060
import math

N = int(input())

if N%2 == 0:
    print(N, N, N//2)
    
else:
    flag = False
    
    for h in range(1, 3501):
        if flag == True:
            break
        
        for n in range(1, 3501):
            if flag == True:
                break
            
            if ((n*(h*4-N)-N*h) > 0) and (N*h*n)%(n*(h*4-N)-N*h) == 0:
                print(h, n, (N*h*n)//(n*(h*4-N)-N*h))
                flag = True
            

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <utility>
#include <numeric>
#include <functional>
#include <stdio.h>
#include <math.h>
#include <string>
#include <algorithm>
#include <deque>
#include <queue>
#include <map>

#define rep(i, m, n) for (int (i)(m); (i)<(n); ++(i))
#define repr(i, m, n) for (int (i)(m - 1); (i)>=(n); --(i))
#define repv(i, v) for (unsigned (i)(0); (i)<(v.size()); ++(i))
#define all(v) (v).begin(), (v).end()
#define sortv(v) sort(all(v))
#define sortgi(v) sort(all(v), greater<int>())
#define sortgd(v) sort(all(v), greater<double>())
#define sortgll(v) sort(all(v), greater<ll>())
#define debug(x) cerr << #x << ": " << x << '\n'

using namespace std;
using pii = pair<int, int>;
using pss = pair<string, string>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using ll = long long;
using pllll = pair<ll, ll>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using vpii = vector<pii>;
using pqi = priority_queue<int>;
using pqd = priority_queue<double>;
using pqll = priority_queue<ll>;
using pqvi = priority_queue<vi>;
using pqvll = priority_queue<vll>;

int main() {
	int n, x;
	cin >> n >> x;
	int sum = 0;
	vi a;
	rep(i, 0, n) {
		int aa;
		cin >> aa;
		a.push_back(aa);
	}
	sort(all(a));
	rep(i, 0, a.size() - 1) {
		x -= a[i];
		if (x < 0) {
			break;
		}
		++sum;
	}
	if (x == a[a.size() - 1]) {
		++sum;
	}
	cout << sum << endl;
}


Measured memory_bytes: 768
#include <iostream>
using namespace std;
using Int = long long;
int main()
{
    int N; cin >> N;
    Int L[87];
    L[0] = 2;
    L[1] = 1;
    for (int i = 2; i <= 86; i++) {
        L[i] = L[i-1] + L[i-2];
    }
    cout << L[N] << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextInt();
        long mod = 1000000007;
        long ans = 1;
        for (int i = 1 ; i <= n ; i++) {
            ans *= i ;
            ans %= mod;
        }
        System.out.println(ans);
    }

}

Measured memory_bytes: 22612
//ABC164 A

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

    int S=sc.nextInt();
    int W=sc.nextInt();

    if(W>=S){
      System.out.println("unsafe");
    }else{
      System.out.println("safe");

    }

  }
}


Measured memory_bytes: 35500
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define pi pair<int,int>
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define sz(x) ((int)x.size())
#define ln(x) ((int)x.length())
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define dbg(x) cout<<#x<<": "<<x<<endl
#define clr(x,v) memset(x, v, sizeof(x))
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
const double eps = 1e-9;
const double PI = acos(-1.0);
const ll mod = 1e9 + 7;
const int MAXN = 1e6 + 5;

void cp()
{
    int n;
    cin >> n;
    vector<ll> arr(n);
    for(ll &x : arr)
        cin >> x;
    ll mx = -1;
    ll ans = 0;
    for(int i = 0; i < n; i++)
    {
        if(arr[i] >= mx)
            mx = arr[i];
        else
            ans += mx - arr[i];
    }
    cout << ans;
}

int main()
{
    FASTIO;
    int t;
    t = 1;
    // cin >> t;
    while(t--)
    {
        cp();
    }
    return 0;
}

Measured memory_bytes: 4732
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, s, e) for (int i = s; i < e; i++)
#define endl '\n'
const ll MOD = 1000000007;
ll lpowmod(ll a, ll N)
{
    ll res = 1;
    for (ll i = 0; i < N; i++)
    {
        res = res * a % MOD;
    }
    return res;
}

int main()
{
    ll N;
    cin >> N;
    ll res = lpowmod(10, N) - lpowmod(9, N) - lpowmod(9, N) + lpowmod(8, N);
    res%=MOD;
    res=(res+MOD)%MOD;
    cout << res << endl;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

ll N,P;
map<ll,ll> M;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>P;
	for(i=2;i<=1000000;i++) {
		while(P%i==0) {
			M[i]++;
			P/=i;
		}
	}
	if(P>1) M[P]++;
	
	ll ret=1;
	FORR(m,M) {
		while(m.second>=N) {
			m.second-=N;
			ret*=m.first;
		}
	}
	cout<<ret<<endl;
	
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
	"strings"
)

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

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

	nums := map[string]int{}
	ans := 0
	for i := len(ss) - 1; i >= 0; i-- {
		fields := strings.Split(ss[i], "")
		sort.Strings(fields)
		str := strings.Join(fields, "")
		ans += nums[str]
		nums[str]++
	}
	fmt.Println(ans)
}


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

int main() {
  
  int a, b;
  cin >> a >> b;
  
  if (a <= 5) {
    cout << 0 << endl;
  } else if (a >= 13) {
    cout << b << endl;
  } else {
    cout << b / 2 << endl;
  }
  
}

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

public class Main {

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

	String s = sc.next();
		int count =0;
		for (int i = 1; i < 4; i++) {
			if (s.charAt(i) == s.charAt(i - 1)) {
				System.out.println("Bad");
				count++;
				break;
			}
		}
		if(count==0) {
			System.out.println("Good");
		}

	}

}


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

using namespace std;

int main(){
    int n; cin >>n;
    for(int i=0;i<n;i++){
        int house,generator; cin >> house >> generator;
        int a[house];
        for(int j=0;j<house;j++){
            cin >> a[j];
        }
        int b[house-1];
        int sum = 0;
        for(int j=0;j<house-1;j++){
            b[j] = a[j+1]-a[j];
            sum += b[j];
        }
        sort(b,b+house-1);
        reverse(b,b+house-1);
        int j=0;
        while(generator-1 != 0 && sum!=0){
            sum -= b[j];
            j++;
            generator--;
        }
        cout << sum << endl;
    }
}

Measured memory_bytes: 1960
#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;
const int K = 1e5+10;
int n, k;
int a[K], dp[K];
 
int main() 
{
  cin >> n >> k;
  memset(dp, 0, sizeof dp);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  
  for (int i = 0; i <= k; i++) {
    for (int j = 0; j < n; j++) {
      if (i >= a[j] && !dp[i-a[j]]) {
        dp[i] = 1;
        break;
      }
    }
  }
  
  cout << (dp[k] ? "First" : "Second") << endl;
  
  return 0;
  
}

Measured memory_bytes: 640
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#define PI 3.1415926535897932384626433
using namespace std;
int main(){
    int days[13]={0,31,29,31,30,31,30,31,31,30,31,30,31};
    int rui[13]={0};
    for(int i=1;i<=12;i++)rui[i]=rui[i-1]+days[i];
    while(1){
        int a,b;
        cin>>a>>b;
        if(a==0&&b==0)break;
        int p=rui[a-1]+b;
        if(p%7==0)cout<<"Wednesday"<<endl;
        if(p%7==1)cout<<"Thursday"<<endl;
        if(p%7==2)cout<<"Friday"<<endl;
        if(p%7==3)cout<<"Saturday"<<endl;
        if(p%7==4)cout<<"Sunday"<<endl;
        if(p%7==5)cout<<"Monday"<<endl;
        if(p%7==6)cout<<"Tuesday"<<endl;
    }
    return 0;
}

Measured memory_bytes: 1152
w = STDIN.gets.to_i

arr=[]
(1..w).each do |i|
  arr.push(i)
end

n = STDIN.gets.to_i

n.times do 
  a, b = STDIN.gets.split(',').map { |item| item.to_i }
  arr[b-1], arr[a-1] = arr[a-1], arr[b-1]
end

arr.each do |e|
  puts e
end

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

int main()
{
    string s;
    cin >> s;
    if (s[0] == s[1] && s[2] == s[3] && s[0] != s[2] ||
        s[0] == s[2] && s[1] == s[3] && s[0] != s[3] ||
        s[0] == s[3] && s[1] == s[2] && s[0] != s[1])
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#define ll long long int
// 入れ替えても同じかな
int main() {
  ll n, a, b, c, d, e;
  std::cin >> n >> a >> b >> c >> d >> e;
  std::vector<ll> v;
  v.push_back(a);
  v.push_back(b);
  v.push_back(c);
  v.push_back(d);
  v.push_back(e);
  std::sort(v.begin(), v.end());
  std::cout << ((n + (v[0] - 1)) / v[0]) + 4 << std::endl;
}

Measured memory_bytes: 256
n = int(input())
lst = list(map(int, input().split()))
s = sum(lst)
q = int(input())
dic = {}
for i in range(n):
  dic.setdefault(lst[i], 0)
  dic[lst[i]] += 1
for i in range(q):
  b, c = map(int, input().split())
  dic.setdefault(b, 0)
  dic.setdefault(c, 0)
  dic[c] += dic[b]
  s += ((c - b) * dic[b])
  print(s)
  dic[b] = 0

Measured memory_bytes: 23904
#include<cstdio>
#include<algorithm>
#include<cmath>
#define N 200005
#define ll long long
using namespace std;
int n, k;
int a[N], b[N];
int main(){
	scanf("%d%d", &n, &k);
	for(int i=1; i<=n; ++i) scanf("%d", &a[i]);
	for(int j=1; j<=k; ++j){
		bool flag=true;
		for(int i=1; i<=n; ++i){
			++b[max(i-a[i], 1)];
			--b[min(i+a[i], n)+1];
		}
		for(int i=1; i<=n; ++i){
			a[i]=a[i-1]+b[i], b[i]=0;
			if(a[i]<n) flag=false;
		}
		if(flag) break;
	}
	for(int i=1; i<=n; ++i) printf("%d ", a[i]);
	return 0;
}

Measured memory_bytes: 3284
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES	// M_PI=3.1415...
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 20桁出力 cout << setprecision(20) << double;
#include <queue>
#include <bitset>	// bitset<8> bs1(131uL); // 10000011 bs1[0]は1 01stringからビット集合生成可
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef vector<pair<int, int> > VPII;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<int, int> P;
typedef pair<int, pair<P, P> > PP;

#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORL(i,a,b) for(LL i=(a);i<(b);i++)
#define FOR_REV(i,a,b) for(int i=(a);i>=(b);i--)
//for gcc (未test)
// #define FOREACH_IT(it,c) for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
#define FOR_ITR(d) for(auto itr=d.begin(),d_end=d.end();itr!=d_end;++itr)	// C++11
// for Debug.
#define DUMP_VVI(b) FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}
// 入力をpush_back(d)やarray[d]に使う時に1行で書ける
// int INPUT_INT() {int d;cin>>d;return d;}
template<class T>T IN() { T d; cin >> d; return d; }
// 最大公約数（Greatest Common Divisor）
LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a%b) : a; }
// 最小公倍数（Least Common Multiple）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
// Y年はうるう年か否か
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); }

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

// vector注意
// vec[i][j]の形に入力を入れるとき、vecは初期化してある必要がある.

// ------------------- include, typedef, define END. -------------------

int main() {
	FAST_IO;
	// for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;
	bool dbgF = true;

	//コードはここから書く.

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

	int ans = min(b, d) - max(a, c);
	if (ans < 0)
		ans = 0;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl

typedef long long ll;
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a, b;
    cin >> a >> b;
    cout << max(a + b, max(a - b, a * b));

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

ll mpow(ll x, ll n) {
  ll ans=1;
  while(n>0) {
    if(n&1) {
      ans=ans*x%mod;
    }
    x=x*x%mod;
    n>>=1;
  }
  return ans;
}

//階乗,factで初期化
vec tfact(1e7+1);
void fact(ll n) {
  for(ll i=0;i<=n;i++) {
    if(i==0) {
      tfact[i]=1;
    }
    else {
      tfact[i]=tfact[i-1]*i%mod;
    }
  }
}

//nCk 繰り返し高速
ll comb(ll n, ll k) {
  return tfact.at(n)*mpow(tfact.at(k),mod-2)%mod*mpow(tfact.at(n-k),mod-2)%mod;
}

int main() {
  ll h,w,n;
  cin >> h >> w >> n;
  fact(h+w+10);
  vector<pll> G(n+1);
  for(ll i=0;i<n;i++) {
    ll y,x;
    cin >> y >> x;
    y--,x--;
    G[i]={y,x};
  }
  G[n]={h-1,w-1};
  vec dp(n+1);
  sort(G.begin(),G.end());
  for(ll i=0;i<=n;i++) {
    ll y=G[i].first;
    ll x=G[i].second;
    dp[i]=comb(y+x,y);
    for(ll j=0;j<i;j++) {
      ll dx=G[i].first-G[j].first;
      ll dy=G[i].second-G[j].second;
      if(dx>=0&&dy>=0) dp[i]=(dp[i]-dp[j]*comb(dx+dy,dy)%mod+mod)%mod;
    }
  }
  cout << dp[n] << endl;
}

Measured memory_bytes: 78464