akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClarss
{
	public const long Giri = 1000000007;
	
	public static void Main(string[] args)
	{
		int n = int.Parse(Console.ReadLine());
		string[] sbs = Input();
		int[] bs = new int[n];
		int[] kekka = new int[n];
		
		for(int i = 0; i < n; i++)
		{
			bs[i] = int.Parse(sbs[i]);
		}
		
		//半分埋める
		int max = n-1;
		int cnt = 0;
		for(int i = n; i >= 1; i--)
		{
			int allwa = 0;
			for(int j = i; j <= n; j += i)
			{
				allwa += kekka[j-1];
			}
			if(allwa % 2 != bs[i-1])
			{
				kekka[i-1]=1;
				cnt++;
			}
		}
		/*
		while(max > 0)
		{
			//Console.WriteLine("max"+max);
			for(int i = max; i >= max/2 && i >= 0; i--)
			{
				//Console.WriteLine(i);
				if(i*2>=n)
				{
					//baisuu jyanai
					if(bs[i] == 1)
					{
						kekka[i] = 1;
						cnt++;
					}
				}
				else
				{
					int allwa = 0;
					for(int j = i; j < n; j += Math.Max(1,i))
					{
						allwa = (allwa+kekka[j]) % 2;
					}
					if(allwa != bs[i])
					{
						kekka[i]=1;
						cnt++;
					}
				}
			}
			max = max / 2;
		}
		*/
		//Console.WriteLine("cnt:"+cnt);
		Console.WriteLine(cnt);
		
		//Console.WriteLine("ppp;"+ppp);
		//Console.WriteLine(ppp);
		
		/////syuituryopku

		StringBuilder strb = new StringBuilder();
		int c = 0;
		for(int i = 0; i < n; i++)
		{
			if(kekka[i]==0)
				continue;
			strb.Append(string.Format("{0} ", i+1));
			c++;
		}
		
		
		Console.WriteLine(strb.ToString().Trim());
	}
	
	public static long GCD(long a, long b)
	{
		if(b == 1)
			return a;
		long p = b / a;
		return GCD(a, b - a*p);
	}
	
	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));
	}

}



Measured memory_bytes: 32852
#include <queue>
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <iomanip>
#include <cstdio>
#define rep(i, n) for(long long i = 0;(i) < (n);(i)++)
using namespace std;
using ll = long long;

int main()
{
	ll a, b, c, d;
	cin >> a >> b;
	cin >> c >> d;
	if (a != c)
	{
		cout << 1 << endl;
	}
	else
	{
		cout << 0 << endl;
	}
	return 0;
}

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

using namespace std;

mt19937 engine(0);

template<typename T>
void quick_sort(vector<T>& a, int l, int r) {
    if (l >= r) return;
    T pivot = a[uniform_int_distribution<>(l, r)(engine)];
    int i = l, j = r;
    while (true) {
        while (a[i] < pivot) ++i;
        while (pivot < a[j]) --j;
        if (i >= j) break;
        swap(a[i], a[j]);
        ++i, --j;
    }
    quick_sort(a, l, i-1);
    quick_sort(a, j+1, r);
}


int main() {

    int n; cin >> n;
    vector<int> a(n+1);
    for (int i = 1; i <= n; ++i) cin >> a[i];

    quick_sort(a, 1, n);

    int alice = 0, bob = 0;
    for (int i = 1; i <= n; ++i) {
        (i & 1 ? alice : bob) += a[n+1-i];
    }

    cout << alice - bob << endl;

    return 0;
}


Measured memory_bytes: 3628
import itertools
import math
import sys
from collections import Counter
from fractions import gcd
from functools import reduce

n = int(input())
s = input()
leader = 1
ans = s[1:].count("E")
old = ans
while leader < n:
    num = old
    if s[leader - 1] == "W":
        num += 1
    if s[leader] == "E":
        num -= 1
    ans = min(ans, num)
    old = num
    leader += 1
print(ans)


Measured memory_bytes: 5928
#include<iostream>
#include<cmath>
using namespace std;
typedef long long ll;

int main()
{
    int x,flag=0;
    ll a[125];
    scanf("%d",&x);
    for(int i=0;i<121;i++)
    {
        a[i]=pow(i,5);
    }
    for(int i=0;i<121&&flag==0;i++)
    {
        for(int j=0;j<121;j++)
        {
            if(a[i]-a[j]==x)
            {
                printf("%d %d",i,j);
                flag=1;
                break;
            }
            else if(a[i]+a[j]==x)
            {
                printf("%d -%d",i,j);
                flag=1;
                break;
            }
        }
    }
    
    return 0;
}


Measured memory_bytes: 4228
#include <iostream>

using namespace std;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    string as = to_string(a);
    string bs = to_string(b);
    string cs = to_string(c);

    string s;
    if (a <= b && a <= c) // aが最小
    {
        s += (as + " ");
        if (b <= c) s += (bs + " " + cs);
        else s += (cs + " " + bs);
    }
    else if (b <= a && b <= c) // bが最小
    {
        s += (bs + " ");
        if (a <= c) s += (as + " " + cs);
        else s += (cs + " " + as);
    }
    else if (c <= a && c <= b) // cが最小
    {
        s += (cs + " ");
        if (a <= b) s += (as + " " + bs);
        else s += (bs + " " + as);
    }
    cout << s << endl;

    return 0;
}

Measured memory_bytes: 1232
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long t[100100];
    int n;
    cin>>n;
    int i=1;
    while(n --)
    {
        cin>>t[i];
        i++;
    }
    long long m;
    cin >> m;
    while(m --)
    {
        int p, x;
        cin >> p >> x;
        int c;
        c = t[p];
        t[p] = x;
       long long sum = 0;
        for(int j = 1; j < i; j ++)
        {
            sum += t[j];
        }
        cout << sum <<endl;
        t[p] = c;
    }
}

Measured memory_bytes: 256
n=int(input())
l=list(map(int,input().split()))
count=0
for i in range(2,n):
  if max(l[i-2],l[i-1],l[i])!=l[i-1] and min(l[i-2],l[i-1],l[i])!=l[i-1]:
    count+=1
print(count)

Measured memory_bytes: 3060
var input = '';
var readable = process.stdin;
readable.resume();
readable.setEncoding( 'utf-8' );
readable.on( 'data', function( chunk ) {
  input += chunk;
});
readable.on( 'end', function() {
  var data = input.split( '\n' );
  
  var output = [];
  for( var i=0; i<data.length; i++ ) {
    var aob = data[i].replace( '\n', '' ).split( ' ' );
    if( '?' == aob[1] ) { break; }
    
    var a = parseInt( aob[0] );
    var b = parseInt( aob[2] );
    switch( aob[1] ) {
      case '+':
        output.push( a+b );
        break;
      case '-':
        output.push( a-b );
        break;
      case '*':
        output.push( a*b );
        break;
      case '/':
        output.push( Math.floor( a/b ) );
        break;
    }
  }
  console.log( output.join( '\n' )  );
});

Measured memory_bytes: 7904
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD (1000000007)
#define INF (1e9)
#define INFL (1e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template<class T>using arr=vector<vector<T>>;
template<class T>int popcount(T &a){int c=0; rep(i, 8*(int)sizeof(a)){if((a>>i)&1) c++;} return c;}
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} pr(a[a.size()-1]);}
template<class T>void prarr(arr<T>& a){rep(i, a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main()
{
    int n; cin >> n;
    vector<int> b(n), dp(n+1, -1);
    rep(i, n) cin >> b[i];
    rep(i, n){
        int p = lower_bound(dp.rbegin(), dp.rend(), b[i]) - dp.rbegin() - 1;
        p = n - p;
        // pr(p);
        if(p==-1) dp[0] = b[i];
        else dp[p] = b[i];
        // prvec(dp);
    }

    rep(i, n+1){
        if(dp[i]==-1) {pr(i); break;}
    }

    vector<int> a = {8,5,2};
    // pr(3 - 1 - ((upper_bound(a.rbegin(), a.rend(), 1) - a.rbegin()) - 1));
    return 0;}

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

int main(){
  int x; cin>>x;
  if (x<=599) cout << 8;
  else if(x<=799)cout << 7;
  else if(x<=999)cout << 6;
  else if(x<=1199)cout << 5;
  else if(x<=1399)cout << 4;
  else if(x<=1599)cout << 3;
  else if(x<=1799)cout << 2;
  else if(x<=1999)cout << 1;
}

Measured memory_bytes: 3628
import math
while True:
    a=0
    A=0
    b=0
    n=int(input())
    if n==0:
        break
    s=list(map(int,input().split()))
    S=sum(s)
    m=S/n
    for i in range(n):
        b=(s[i]-m)**2
        a=a+b
    A=a/n
    C=math.sqrt(A)
    print(C)


Measured memory_bytes: 5696
# what is dp relation 
# dp[n][w]=max(dp[n-1][w-wt[n]]+p[n],dp[n-1][w])

n,W=map(int,input().split())
wt,p=[],[]
for _ in range(n):
    a,b=map(int,input().split())
    wt.append(a)
    p.append(b)
dp=[[0 for i in range(W+1)]for j in range(n+1)]
for x in range(1,n+1):
    for y in range(1,W+1):
        if wt[x-1]<=y:
            dp[x][y]=max(dp[x-1][y-wt[x-1]]+p[x-1],dp[x-1][y])
        else:
            dp[x][y]=dp[x-1][y]
print(dp[-1][-1])

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

int main(void) {
  int sum = 0, ldiag = 0, rdiag = 0, val;
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> val;
      sum += val;
      if (i + j == 2) rdiag += val;
      if (i == j) ldiag += val;
    }
  }

  if (ldiag == rdiag && sum % 3 == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,C,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;


int main(){
    cin>>N;
    mat a(N,vec(N-1));
    rep(i,N) {
        rep(j,N-1) {
            cin>>a[i][j];
            --a[i][j];
        }
    }
    /*rep(i,N){
        ll J = 0;
        rep(j,N-1){
            if(J == i) ++J;
            a[i][j] = J++;
        }
    }
    rep(i,N){
        rep(j,N-1) cout<<a[i][j]<<' ';
        cout<<endl;
    }*/
    set<ll> game;//敵*N + 自分
    queue<ll> gamed_person;
    vec next_game(N,0);
    gamed_person.push(-1);
    //1日目のみ特殊
    rep(i,N){
        ll vs = a[i][0];
        if(next_game[i] == 1) continue;
        if(a[vs][0] == i){
            ++next_game[vs]; ++next_game[i];
            gamed_person.push(i);
            gamed_person.push(vs);
        }else{
            game.insert(vs*N + i);
        }
    }
    //2日目以降
    ll ans = 1;
    while(!gamed_person.empty()){
        ll me = gamed_person.front();
        gamed_person.pop();
        if(me == -1){
            if(gamed_person.empty()) break;
            ++ans;
            gamed_person.push(-1);
            continue;
        }
        ll vs = a[me][next_game[me]];
        auto ite = game.lower_bound(me*N + vs);
        if(*ite == me*N + vs){
            if(++next_game[me] != N-1){
                gamed_person.push(me);
            }
            if(++next_game[vs] != N-1){
                gamed_person.push(vs);
            }
        }else{
            game.emplace(vs*N + me);
        }
    }
    bool ok = true;
    rep(i,N) if(next_game[i] != N-1) ok = false;
    cout<<(ok ? ans : -1)<<endl;
}

Measured memory_bytes: 31488
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
using namespace std;
const int MAXN = (int) 2e5 + 10;
const int INF = (int) 0x3f3f3f3f;
typedef long long LL;

int n;
int dp[MAXN];

void work(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        int x; scanf("%d",&x);
        for(int j=2000;j>=x;j--) dp[j]=max(dp[j],dp[j-x]+x);
    }
    int q; scanf("%d",&q);
    while(q--){
        int x; scanf("%d",&x);
        if(dp[x]==x) printf("yes\n");
        else printf("no\n");
    }
}

int main(){
    work();
    return 0;
}






Measured memory_bytes: 2708
#include <cstdio>
#include <vector>
#include <queue>

using namespace std;

int main() {
    int i;
    int n, m;
    queue<int> topologic;
    char is_duplicate = 0;

    vector<int> win[5000];
    int lose[5000];
    char has_pushed[5000];
    vector<int> ans;

    scanf("%d", &n);
    scanf("%d", &m);

    for (i=0;i<n;i++) {
       lose[i] = 0;
       has_pushed[i] = 0;
    }

    for (i=0;i<m;i++) {
        int p, q;
        scanf("%d %d", &p, &q);

        p--;
        q--;

        win[p].push_back(q);
        lose[q]++;
    }

    for (i=0;i<n;i++) {
        if (lose[i] == 0) {
            if (has_pushed[i] == 0) topologic.push(i);
            has_pushed[i] = 1;
        }
    }

    while (!topologic.empty()) {
        int t = topologic.front();

        ans.push_back(t+1);

        lose[t] = -1;

        for (i=0;i<n;i++) {
            if (lose[i] == 0) {
                if (has_pushed[i] == 0) topologic.push(i);
                has_pushed[i] = 1;
                is_duplicate = 1;
            }
        }

        vector<int>::iterator it = win[t].begin();
        while (it != win[t].end()) {
            lose[*it]--;
            if (lose[*it] == 0) {
                if (has_pushed[*it] == 0) topologic.push(*it);
                has_pushed[*it] = 1;
            }
            it++;
        }

        topologic.pop();
    }

    vector<int>::iterator it = ans.begin();
    while (it != ans.end()) {
        printf("%d\n", *it);
        it++;
    }

    printf("%d\n", is_duplicate);
}

Measured memory_bytes: 1888
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<functional>
#include <random>
using namespace std;

int main() {
    long long  W, H, x, y;
    double area;
    scanf("%lld %lld %lld %lld", &W, &H, &x, &y);
    printf("%f ", (double) W * (double) H / 2);
    if(2*x == W && 2*y == H){
        printf("1\n");
    }else{
        printf("0\n");
    }
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define fastio ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define fr(i,a,b) for(int i=a;i<=b;i++)
#define input(a) for(auto &t:a){cin>>t;}
#define maxe(a,b,c) max(a,max(b,c))
#define eb emplace_back
#define em emplace
#define print(x) cout<<x<<endl;
#define fill(a,val) memset(a,val,sizeof(a))
#define in(k) int k;cin>>k
#define edl cout<<"\n"
#define ll  long long
#define ld  long double
#define mp  make_pair
#define ff  first
#define ss  second
#define pii pair<ll,ll>
#define sq(x) ((x)*(x))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
const ll mod=1e9+7;
signed main()
{
    //cout<<fixed<<setprecision(20);
    fastio;
    ll amt=100;
    ll x;cin>>x;
    int c=0;
    while(x>amt)
    {
        amt=amt+(ll)(amt/100);
        c++;
    }
    cout<<c;
    //printclock;
    return 0;
}

Measured memory_bytes: 3652
while True:
    H, W = map(int, input().split())
    if H == 0 and W == 0:
        break
    else:
        for i in range(H):
            for j in range(W):
                if (i + j) % 2 == 0:
                    print('#', end='')
                else:
                    print('.', end='')
            print()
        print()


Measured memory_bytes: 7004
#include <stdio.h>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>
using namespace std;
map<string, bool> mp;
int main(){
    mp.clear();
    int n;
    string str;
    cin>>n;
    int ans = 0;
    for(int i=0; i<n; i++){
        cin>>str;
        if(mp[str]==0) ++ans;
        mp[str] = true;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 19152
#include <stdio.h>

const int Mod = 998244353;

int main()
{
	int i, N, a[301];
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%d", &(a[i]));
	
	int j, sum = 0;
	long long dp[2][90001] = {{3}, {6}}, ans = 1, tmp = 3;
	for (i = 1; i <= N; i++) {
		ans = ans * 3 % Mod;
		tmp = tmp * 2 % Mod;
	}
	ans = (ans - tmp + 3 + Mod) % Mod;
	for (i = 1; i <= N; i++) {
		for (j = sum; j >= 0; j--) {
			dp[0][j+a[i]] = (dp[0][j+a[i]] + dp[0][j]) % Mod;
			dp[1][j+a[i]] = (dp[1][j+a[i]] + dp[1][j]) % Mod;
			dp[0][j] = dp[0][j] * 2 % Mod;
		}
		sum += a[i];
	}
	for (j = (sum + 1) / 2; j < sum; j++) ans = (ans - dp[0][j] + dp[1][j] + Mod) % Mod;
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}

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

int main(){
  long long k;
  cin >> k;
  int ans = 0;
  long long d = 100.0;
  while(d<k){
    d = floor(1.01*d);
    ans ++;
  }
  cout << ans << endl;
      return 0;
}

Measured memory_bytes: 3744
#include <bits/stdc++.h>
 
#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)
 
using namespace std;
 
using ll = long long;
using ul = unsigned long long;
ll mod = 1000000007;
 
int main() {
source:
    ll n;
    cin >> n;
    ll a[n];
    rep(i, n) { cin >> a[i]; a[i]--;}
ll ans=0;
  if(a[n-1]==n-1){
      swap(a[n-1],a[n-2]);
    ans++;
    }
  	rep(i,n-1){
      if(a[i]==i){
        swap(a[i],a[i+1]);
        ans++;
      }
    }

  cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
constexpr int MOD = 1000000000 + 7;
constexpr int INF = 2000000000;
using namespace std;

int main() {
	vector<int> v;
	int n;
	cin >> n;
	int a;
	for (int i = 0; i < 2*n; i++) {
		cin >> a;
		v.emplace_back(a);
	}
	sort(v.begin(), v.end());
	v.emplace_back(0);
	int ans = 0;
	for (int i = 0; i < 2*n; i+=2) {
		ans += min(v[i], v[i+1]);
	}
	cout << ans << endl;
}

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

int main(){
	int N, M;
	cin>>N>>M;
	vector<vector<LL> > line(N, vector<LL>(3));
	foreach(i, line)
		foreach(j, i)cin>>j;
	LL ans = 0;
	REP(i, BIT(3)){
		vector<LL> sum;
		foreach(j, line){
			LL nd = 0;
			REP(k, 3){
				nd += j[k] * ((i&BIT(k))?-1:1);
			}
			sum.push_back(nd);
		}
		sort(ALL(sum), greater<LL>());
		LL nsum = 0;
		REP(j, M){
			nsum+=sum[j];
		}
		ans=max(ans, nsum);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
char a[10001];
int main()
{
	cin>>a;
	int a1=a[0]-'0';
	int b1=a[1]-'0';
	int c1=a[2]-'0';
	int d1=a[3]-'0';
	if((a1+b1+c1+d1)==7)
	{
		cout<<a1<<"+"<<b1<<"+"<<c1<<"+"<<d1<<"=7"<<endl;
		return 0;
	}
	if((a1+b1+c1-d1)==7)
	{
		cout<<a1<<"+"<<b1<<"+"<<c1<<"-"<<d1<<"=7"<<endl;
		return 0;
	}
	if((a1+b1-c1+d1)==7)
	{
		cout<<a1<<"+"<<b1<<"-"<<c1<<"+"<<d1<<"=7"<<endl;
		return 0;
	}
	if((a1-b1+c1+d1)==7)
	{
		cout<<a1<<"-"<<b1<<"+"<<c1<<"+"<<d1<<"=7"<<endl;
		return 0;
	}
	if((a1+b1-c1-d1)==7)
	{
		cout<<a1<<"+"<<b1<<"-"<<c1<<"-"<<d1<<"=7"<<endl;
		return 0;
	}
	if((a1-b1-c1+d1)==7)
	{
		cout<<a1<<"-"<<b1<<"-"<<c1<<"+"<<d1<<"=7"<<endl;
		return 0;
	}
	if((a1-b1+c1-d1)==7)
	{
		cout<<a1<<"-"<<b1<<"+"<<c1<<"-"<<d1<<"=7"<<endl;
		return 0;
	}
	if((a1-b1-c1-d1)==7)
	{
		cout<<a1<<"-"<<b1<<"-"<<c1<<"-"<<d1<<"=7"<<endl;
		return 0;
	}
	return 0;
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
int n; cin >> n;
vector<int> v(n);
for(int i=0; i<n; i++){
	cin >> v[i];
}

vector<int> b = v;
sort(b.begin(), b.end());
int j =0;
for(int i=0; i<n; i++){
	if(b[i]!=v[i]){
		j++;
	}
}

if(j ==0 || j == 2){
	cout << "YES" << endl;
	return 0;
}

else{
	cout << "NO" << endl;
	return 0;
}


}


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

using namespace std;

#define int long long

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

    string s;
    cin >> s;

    int n = s.size();

    int ans = 0;
    int cnt = 0;
    for (int i = 0; i < n; ++i) {
        if (s[i] == 'W') {
            ans += cnt;
        }
        else {
            ++cnt;
        }   
    }   
    
    cout << ans << '\n';
    return 0;
}   

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

using namespace std;

typedef long long int li;
typedef long double ld;
typedef vector<li> vi;
typedef pair<li,li> pi;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define B begin()
#define E end()
#define f(i,l,r) for(li i=l;i<=r;++i)
#define fr(i,l,r) for(li i=l;i>=r;--i)
#define u_map unordered_map
#define endl "\n"

li fastpow(li base,li exp,li M) 
{
    li res=1;
    while(exp>0) {
        if(exp&1)
            res=(res*base)%M;

        base=(base*base)%M;
        exp>>=1;
    }
    return res;
}

int main()
{    
    

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    li k;

    cin>>k;

    li a,b;

    cin>>a>>b;

    ld tp1=a/k,tp2=b/k;

    if(tp1==tp2)
    {
        if(a%k==0)
        {
            cout<<"OK";
        }
        else
        {
            cout<<"NG";
        }
    }   
    else
    {
        cout<<"OK";
    }

    return 0;
}

Measured memory_bytes: 3644
x , y = map(int,input().split())
ans = 0
if abs(x) < abs(y):
    if x < 0:
        ans += 1
    ans += abs(y) - abs(x)
    if y < 0:
        ans += 1
    
elif abs(x) > abs(y):
    if x > 0:
        ans += 1
    ans += abs(x) - abs(y)
    if y > 0:
        ans += 1
elif abs(x) == abs(y):
    ans = 1

print(ans)

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

// This file is a "Hello, world!" in Java language by OpenJDK for wandbox.

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

	void run(){
        Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		String[] s=new String[N];
		int[] t=new int[N];
		for(int i=0;i<N;++i){
			s[i]=sc.next();
			t[i]=sc.nextInt();
		}
		String X=sc.next();
		for(int i=0;i<N;++i){
			if(X.equals(s[i])){
				long ans=0;
				for(int j=i+1;j<N;++j)ans+=t[j];
				System.out.println(ans);
				return;
			}
		}
		throw new AssertionError();
    }
	
	void tr(Object...o){
		System.out.println(Arrays.deepToString(o));
	}
}
// OpenJDK reference:
//   http://openjdk.java.net/

// Java language references:
//   http://docs.oracle.com/javase


Measured memory_bytes: 21844
import sys,collections,math;sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

d = collections.defaultdict(int)
for i in range(3):
    a,b = Is()
    d[a] += 1
    d[b] += 1
ans = "YES"
for e in d:
    if d[e] >= 3:
        ans = "NO"
        break
print(ans)


Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5, mod = 1e9 + 7, inf = 0x3f3f3f3f;

int main()
{
    int n, k;
    cin >> n >> k;
    if (k == 1) cout << 0 << endl;
    else cout << n - k << endl;
    
    return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
D = list(map(int, input().split()))

while True:
    flag = 1
    N_str = list(str(N))
    
    for s in N_str:
        if int(s) in D:
            flag = 0
            break
    
    if flag:
        print(N)
        break
    
    N += 1

Measured memory_bytes: 3060
/*定义状态为：第i天选择第j件事所能获得的最大喜悦值
状态转移方程为：f[i][j]=max(f[i-1][k])+a[i][j],k枚举1~3天非j的*/
#include<bits/stdc++.h>
#define maxn 100001
using namespace std;
int f[maxn][4],a[maxn][4];
int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=3;j++)
			cin>>a[i][j];
	for(int i=1;i<=n;i++)
		for(int j=1;j<=3;j++)
			for(int k=1;k<=3;k++){
				if(k!=j) f[i][j]=max(f[i][j],f[i-1][k]+a[i][j]);
			}
	for(int i=1;i<=2;i++)
		f[n][3]=max(f[n][3],f[n][i]);
	cout<<f[n][3];
	return 0;
}

Measured memory_bytes: 3328
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    static final Scanner     sc = new Scanner(System.in);
    static final PrintStream so = System.out;
    static final int INF = Integer.MAX_VALUE;

    public static void main(String[] args) {
        int n = ni();
        int[][] cost = new int[n][n];
        for (int i = 0; i < n; i++) {
            Arrays.fill(cost[i], INF);
            cost[i][i] = 0;
        }
        
        for (int i_n = 0; i_n < n; i_n++) {
            int u = ni();
            int k = ni();
            for (int i_k = 0; i_k < k; i_k++) {
                int v = ni();
                int c = ni();
                cost[u][v] = c;
            }
        }
        
        int[] minCost = calcMinCostWithDijkstrsAlgorithm(cost, 0);
        for (int i = 0; i < n; i++) {
            so.println(i + " " + minCost[i]);
        }
    }

    private static int[] calcMinCostWithDijkstrsAlgorithm(int[][] cost, int start) {
        int len = cost.length;
        int[] minCosts = new int[len];
        Arrays.fill(minCosts, INF);
        minCosts[start] = 0;
        boolean[] fixed = new boolean[len];
        
        while (true) {
            int minCost = INF;
            int minIndex = -1;
            for (int i = 0; i < len; i++) {
                if (!fixed[i] && minCosts[i] < minCost) {
                    minIndex = i;
                    minCost = minCosts[i];
                }
            }
            
            if (minIndex == -1) break;
            fixed[minIndex] = true;
            
            for (int v = 0; v < len; v++) {
                if (!fixed[v] && cost[minIndex][v] != INF) {
                    minCosts[v] = Math.min(minCosts[v], minCosts[minIndex] + cost[minIndex][v]);
                }
            }
        }
        
        return minCosts;
    }

    private static int ni() {
        return sc.nextInt();
    }
}



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

int main() {

    int s,w;
    std::cin >> s>>w;
    if(w>=s)
    {
        std::cout << "unsafe" << std::endl;
    }
    else
    {
        std::cout << "safe" << std::endl;
    }

	return 0;
}

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


// define list


namespace  math{
    const double PI = 3.14;
    const int INF = 1000000007;
    int GCM(int a,int b); //最大公約数
    int LCM(int a,int b); //最小公倍数
    int Pemu(int n,int r); //順列
    int Comb(int n,int m); //組み合わせ
    
    int GCM(int a,int b){
        if(a<b){
            swap(a,b);
        }
        int r = a%b;
        while (r!=0)
        {
            a=b;
            b=r;
            r=a%b;
        }
        return b;
    }

    int LCM(int a,int b){
        return a*(b/GCM(a,b));
    }

    int Pemu(int n,int r){
        int ans = n;
        for(int i=1;i<r;i++){
            ans*=(ans-i);
        }
        return ans;
    }

    int Comb(int n,int m){
        int a=n,b=m;
        for(int i=1;i<m;i++){
            a *= (a-i);
        }
        for(int i=1;i<m;i++){
            b *= (b-i);
        }
        
        return a/b;
    }
}

namespace SubLib{
    #define int long long
    #define double long double
    #define incin(n) int (n); cin >> (n);
    #define incin2(a,b) int a,b; cin >> a >> b; 
    #define rap(n,i) for(int (i) = 0;i<(n);(i)++)
    #define input(n,v) (v) = SubLib::Input((n),(v))
    #define all(v) (v).begin(),(v).end()
    using intv = vector<int>;
    using strv = vector<string>;
    using charv = vector<char>;
    template <class T1>
    using pvec = vector<pair<T1,T1>>;
    template <typename T> vector<T> Input(int n,vector<T> v){
        for(int i=0;i<n;i++){
            cin >> v.at(i);
        }
        return v;
    }
}

using namespace math;
using namespace SubLib;

signed main(){
    incin2(n,k);
    intv l(n);
    input(n,l);

    sort(l.begin(),l.end(),[](const int &a,const int &b){return a>b;});
    int ans = 0;
    rap(k,i){
        ans += l[i];
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
const int NMAX = 201;
int gcdd[NMAX][NMAX];

int _gcd(int a,int b)
{
	return a%b == 0?b:_gcd(b,a%b);
}
int main()
{
	int n;
	scanf("%d",&n);
	for(register int i = 1;i <= n;i++)
		for(register int j = i;j <= n;j++)
			gcdd[j][i] = gcdd[i][j] = _gcd(i,j);
	ll ans = 0;
	for(register int i = 1;i <= n;i++)
		for(register int j = 1;j <= n;j++)
			for(register int k = 1;k <= n;k++)
				ans += gcdd[i][gcdd[j][k]];
	printf("%lld\n",ans );
	return 0;
}

Measured memory_bytes: 3868
#include<iostream>
#include<stack>
using namespace std;
static const int N=100;
static const int WHITE=0;
static const int GRAY=1;
static const int BLACK=2;

int n,M[N][N];
int color[N],d[N],f[N],tt;
int nt[N];

int next(int u){
    for(int v=nt[u];v<n;v++){
        nt[u]=v+1;
        if(M[u][v])return v;
    }
    return -1;
}

void dfs_visit(int r){
    for(int i=0;i<n;i++)nt[i]=0;
    stack<int>S;
    S.push(r);
    color[r]=GRAY;
    d[r]=++tt;

    while(!S.empty()){
        int u=S.top();
        int v=next(u);
        if(v!=-1){
            if(color[v]==WHITE){
                color[v]=GRAY;
                d[v]=++tt;
                S.push(v);
            }
        }else{
            S.pop();
            color[u]=BLACK;
            f[u]=++tt;
        }
    }
}

void dfs(){
    for(int i=0;i<n;i++){
        color[i]=WHITE;
        nt[i]=0;
    }
    tt=0;
    for(int u=0;u<n;u++){
        if(color[u]==WHITE)dfs_visit(u);
    }
    for(int i=0;i<n;i++){
        cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
    }
}

int main(){
    int u,k,v;
    cin>>n;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++)M[i][j]=0;
    }
    for(int i=0;i<n;i++){
        cin>>u>>k;
        u--;
        for(int j=0;j<k;j++){
            cin>>v;
            v--;
            M[u][v]=1;
        }
    }
    dfs();
    return 0;
}


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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const double EPS = 1e-10;

int main() {
    lint N;
    cin >> N;
    vector<lint> A(N);
    rep(i, N) cin >> A[i];

    const lint M = 1001000;
    vector<vector<lint>> primes(M + 1, vector<lint>(0));
    for (int p = 2; p <= M; p++) {
        if (primes[p].size() != 0) continue;
        for (int pk = p; pk <= M; pk += p) {
            primes[pk].push_back(p);
        }
    }

    lint G      = 0;
    rep(i, N) G = __gcd(G, A[i]);
    if (G != 1) {
        cout << "not coprime" << endl;
        return 0;
    }

    set<lint> used;
    for (int i = 0; i < N; i++) {
        for (auto p : primes[A[i]]) {
            if (used.count(p) == 1) {
                cout << "setwise coprime" << endl;
                return 0;
            } else {
                used.insert(p);
            }
        }
    }

    cout << "pairwise coprime" << endl;

    return 0;
}

Measured memory_bytes: 81120
#include <math.h>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;

int main()
{
string str;
int q;
cin >> str >> q;
for(int i=0;i<q;i++)
{
string command;
int a,b;
cin >> command >> a >> b;
if(command=="print"){for(int j=a;j<b+1;j++)cout<<str.at(j);cout << endl;}
else if(command=="reverse"){string bs=str;for(int j=a;j<b+1;j++)str.at(j)=bs.at(a+b-j);}
else{string p;cin >> p;str.replace(a,b-a+1,p);}
}
}


Measured memory_bytes: 3172
#include <stdio.h>
int switchgroup(int k){
		switch(k){
		case 1:
		case 3:
		case 5:
		case 7:
		case 8:
		case 10:
		case 12:
			return 0;
		case 4:
		case 6:
		case 9:
		case 11:
			return 1;
		case 2:
			return 2;

		
	}
}
int main(void){
	int a,b,c;
	scanf("%d %d",&a,&b);
	if(switchgroup(a)==switchgroup(b)){
		printf("Yes");
	}else{
		printf("No");
	}
}


Measured memory_bytes: 128
import java.util.*

//探索
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val branches = Array(n + 1) { mutableListOf<Pair<Int, Long>>() }
    (1 until n).forEach {
        val (a, b, c) = readLine()!!.split(' ').map(String::toLong)
        branches[a.toInt()].add(Pair(b.toInt(), c))
        branches[b.toInt()].add(Pair(a.toInt(), c))
    }
    val minCost = LongArray(n+1) { Long.MAX_VALUE / 3 }
    val (q, k) = readLine()!!.split(' ').map(String::toLong)

    var queue = ArrayDeque<Int>().apply { this.add(k.toInt()) }
    minCost[k.toInt()] = 0
    while (queue.isNotEmpty()) {
        val cur = queue.pollFirst()!!
        val curCost = minCost[cur]
        val bs = branches[cur]
        for (b in bs) {
            val (to, cost) = b
            if (minCost[to] > curCost + cost) {
                minCost[to] = curCost + cost
                queue.add(to)
            }
        }
    }
    (1..q).forEach {
        val (from, to) = readLine()!!.split(' ').map(String::toInt)
        println(minCost[from] + minCost[to])
    }
}

Measured memory_bytes: 127660
$,=$";$k=(4-($K=<>)%4)%4;print$n=$K+3>>2<<1,$K-1?map{map{($t=($'+$_)%$n)+1+($'%2?$n-$k:$t<$n-$k?0:$K-$n)}//..$n}1..$n:(1)x4

Measured memory_bytes: 11264
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int,int>;
/* ちゃんと考えてわかって実装 */

int main(void){
    int n, m;
    cin >> n >> m;
    map<int, string> mp;
    map<int, int> tmp_pen;
    for(int i=1; i<=n; i++){
        mp[i] = "WA";
    }

    int cor = 0, pen = 0;
    for(int i=0; i<m; i++){
        int p; cin >> p;
        string s; cin >> s;
        if(mp[p] == "WA" && s == "WA"){
            tmp_pen[p]++;
        }
        else if(mp[p] == "AC" && s == "WA"){
            continue;
        }
        else if(mp[p] == "WA" && s == "AC"){
            cor++;
            pen += tmp_pen[p];
            mp[p] = "AC";
        }
        else if(mp[p] == "AC" && s == "AC"){
            continue;
        }
    }
    cout << cor << ' ' << pen << endl;

    return 0;
}

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

int main(){
	int s,w;
	cin>>s>>w;
	if(s>w){
		cout<<"safe"<<endl;
	}else{
		cout<<"unsafe"<<endl;
	}
}


Measured memory_bytes: 3676
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int N,cnt=0,a[]={3,5,7};

bool ck(ll num){
    map<int,int> dic;
    while(num){
        dic[num%10]++;
        num/=10;
    }
    return (dic.size()>=3);
}

void dfs(ll num,bool is753){
    if(N<num) return;
    if(!is753&&ck(num)) is753=1;
    cnt+=is753, num*=10;
    rep(i,3) dfs(num+a[i],is753);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>N;
    dfs(0,0);
    cout1(cnt);
}

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 a[] = new int[n];
		int b[] = a.clone();
		int c[] = new int[n - 1];

		for(int j = 0;j < n;j++) {
			a[j] = sc.nextInt();
		}

		for(int j = 0;j < n;j++) {
			b[j] = sc.nextInt();
		}

		for(int j = 0;j < n - 1;j++) {
			c[j] = sc.nextInt();
		}

		int result = java.util.Arrays.stream(b).sum();
		int beforeEat = -1;
		for(int x : a) {
			result += ((beforeEat + 1) == x) ? c[x - 2] : 0;
			beforeEat = x;
		}

		System.out.println(result);
	}
}


Measured memory_bytes: 28748
n, m = map(int, input().split())

keys = []

for i in range(m):
    cost, num = map(int, input().split())
    C = list(map(int, input().split()))
    can_open = 0
    for c in C:
        can_open += 2 ** (c-1)
    keys.append([cost, can_open])

DP = {}
for i in range(2**n):
    DP[i] = float('INF')
DP[0] = 0

for cost, can_open in keys:
    for key in DP.keys():
        pre_cost = DP[key]
        next_key = key | can_open
        DP[next_key] = min(DP[next_key], pre_cost+cost)


full_open = (1 << n) - 1

if DP[full_open] == float('INF'):
    print(-1)
else:
    print(DP[full_open])

Measured memory_bytes: 48344
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <string>
#include <cctype>
#include <stack>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;

const int MaxN = 50, MaxC = 1000;
int n;
string s;
int cnt[MaxC + 5], ans[MaxC + 5];

int main()
{
	scanf("%d", &n);
	memset(ans, -1, sizeof(ans));
	for (int i = 1; i <= n; i++) {
		cin >> s;
		memset(cnt, 0, sizeof(cnt));
		for (int j = 0; j < s.length(); j++) cnt[s[j]]++;
		for (char ch = 'a'; ch <= 'z'; ch++) {
			if (ans[ch] == -1) ans[ch] = cnt[ch];
			else ans[ch] = min(ans[ch], cnt[ch]);
		}
	}
	for (char ch = 'a'; ch <= 'z'; ch++) {
		for (int i = 1; i <= ans[ch]; i++) printf("%c", ch);
	}
	return 0;
}

Measured memory_bytes: 256
// g++ macro.cpp -std=c++14
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;

#define dump(x)  cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

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

#define FOREACH(x,a) for(auto& (x) : (a) )

#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j])

#define SCOUT(x) cout<<(x)<<" "
#define ENDL cout<<endl

#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECIN2(x,y) REP(i,x.size())cin>>x[i]>>y[i]
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl

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

#define EXIST(n,x) (find(ALL(n),x)!=n.end())
#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end())
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__);
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__);


#define P pair<int,int>
#define V vector<int>
#define M map<int,int>
#define S set<int>
#define L list<int>

#define pb(a) push_back(a)
#define mp make_pair


int main(){

    CIN(x,a,b);
    SANKOU(abs(x-a)<abs(x-b),A,B);

    return 0;


}


Measured memory_bytes: 256
N, M = gets.chomp.split.map(&:to_i)
X = gets.chomp.split.map(&:to_i).sort

diffs = X.each_cons(2).map { |a, b| b - a }.sort

ans = 0

0.upto(diffs.size - N) do |i|
  ans += diffs[i]
end

puts ans


Measured memory_bytes: 14656
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:512000000")
#include<utility>
#include<iostream>
#include<fstream>
#include<vector>
#include<array>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<functional>
#include<random>
#include<climits>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
#include<ccomplex>

#ifdef ONLINE_JUDGE
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("unroll-loops")
#endif

#define all(x) x.begin(), x.end()
#define mp make_pair
#define X first
#define Y second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(nullptr));

ll const mod = 998244353;

namespace {
	ll mul(ll a, ll b) {
		ll val = a * b - (ll)((ld)a * b / mod) * mod;
		if (val < 0) val += mod;
		if (val >= mod) val -= mod;
		return val;
	}

	ll poww(ll a, ll b) {
		ll val = 1;
		a %= mod;
		while (b > 0) {
			if (b % 2) val = mul(a, val);
			a = mul(a, a);
			b >>= 1;
		}
		return val % mod;
	}

	ll inv(ll a) {
		return poww(a, mod - 2);
	}
}

int const maxn = 3e5 + 5;

ll a[16][16];
ll dp[1 << 16];

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n; cin >> n;
	for (ll i = 0; i < n; i++) {
		for (ll j = 0; j < n; j++) {
			cin >> a[i][j];
		}
	}
	for (int mask = 0; mask < (1 << n); mask++) {
		ll sum = 0;
		for (int i = 0; i < n; i++) {
			if (mask & (1 << i)) {
				for (int j = i + 1; j < n; j++) {
					if (mask & (1 << j)) {
						sum += a[i][j];
					}
				}
			}
		}
		dp[mask] = sum;
	}

	for (int mask = 0; mask < (1 << n); mask++) {
		for (int mask1 = mask; mask1 > 0; mask1 = (mask1 - 1) & mask) {
			dp[mask] = max(dp[mask], dp[mask1] + dp[mask ^ mask1]);
		}
	}

	cout << dp[(1 << n) - 1] << endl;



	return 0;
}

/*
5
2 6 15 5 10

4
2 6 15 5

*/

Measured memory_bytes: 768
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define bug1( x ) {cerr << (#x) <<"="<< x << endl;}
#define bug2( x , y ) {cerr << (#x) <<"="<< (x) << "    " << (#y) << "="<< (y) << endl;}
#define bug3( x , y , z ) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << endl;}
#define bug4( x , y , z , w) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << endl;}
#define bug5( x , y , z , w ,p) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << endl;}
#define bug6( x , y , z , w ,p , q) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << "    " << (#q) <<"="<< q << endl;}
#define bugn( x , n ) {cerr << (#x) <<":";for(int i=0;i<n;i++)cerr << x[i] <<"  "; cerr << endl;}
#define bugnm( x , n , m ) {cerr << (#x)<<endl;for(int i=0;i<n;i++){cerr << "Row #" << i<< ":";for(int j=0;j<m;j++)cerr << x[i][j] << "   ";cerr << endl;}}
typedef long long ll;
typedef long double ld;
using namespace std;

int32_t main(){
	IOS
	int n,k;cin>>n>>k;
	int cost[3];
	for(int i=0;i<3;i++){
		cin>>cost[i];
	}
	int a[n+1];
	string s;cin>>s;
	for(int i=0;i<n;i++){
		a[i+1]=( s[i] =='r' ? 0 : s[i] =='s' ? 1 : 2 );
	}
	auto cur=[&](int i,int j){
		if( (j+1)%3 == a[i] ) return cost[j];
		return 0ll;
	};
	int dp[n+1][3];
	memset(dp,0,sizeof(dp));
	for(int i=1;i<=n;i++){
		for(int j=0;j<3;j++){
			if( i - k >= 1 ){
				dp[i][j] = max(dp[i-k][(j+1)%3],dp[i-k][(j+2)%3])+cur(i,j);
			}else{
				dp[i][j] = cur(i,j);
			}
		}
		//bug4(i,dp[i][0],dp[i][1],dp[i][2]);
	}
	int ans = 0;
	for(int j=0;j<k&&n-j>=1;j++){
		ans+=max({dp[n-j][0],dp[n-j][1],dp[n-j][2]});
	}
	cout<<ans<<endl;
}
 
/*
 * long long or int?
 * index out of bound? 
 * Tested on own test case?corner?
 * Make more general solution.
 * Read Read Read Read ....
 */


Measured memory_bytes: 6864
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();

		int[][] a = new int[2][n];
		// スペース区切りの整数の入力

		for (int i = 0; i < 2; i++) {
			for (int j = 0; j < n; j++) {
				a[i][j] = sc.nextInt();
			}
		}
		int ans = 0;
		for (int i = 0; i < n; i++) {
			int max = 0;
			for (int j = 0; j < n; j++) {
				if (i == j) {
					max = max + a[1][j] + a[0][j];
				} else if (i < j) {
					max = max + a[1][j];
				} else {
					max = max + a[0][j];
				}
			}
			if (ans < max) {
				ans = max;
			}
		}

		System.out.println(ans);

	}
}


Measured memory_bytes: 23764
import java.util.*;

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

        int count = 0;
        for (int i = 0; i < cs.length; i++) {
            if(cs[i] == '1'){
                count += 1;
            }
        }

        System.out.print(count);
    }
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define ld long double
#define pb push_back
#define all(x) (x).begin(), (x).end()
template <typename T> using ord_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 5e5 + 123, MOD = 1e9 + 7;
int n, m, fact[N], rev[N], inv[N];

int A(int x, int y) {
	if (x > y || x < 0) return 0;
	return (ll)fact[y] * rev[y - x] % MOD;
}

int C(int x, int y) {
	if (x > y || x < 0) return 0;
	return ((ll)fact[y] * rev[y - x] % MOD) * rev[x] % MOD;
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	
	inv[1] = rev[0] = fact[0] = 1;
	for (int i = 1; i < N; i++) {
		fact[i] = (ll)fact[i - 1] * i % MOD;
		if (i > 1) {
			int x = (i - MOD % i) % i;
			inv[i] = (ll)inv[x] * ((MOD + x) / i) % MOD;
		}
		rev[i] = (ll)rev[i - 1] * inv[i] % MOD;
	}
	cin >> n >> m;
	int res = 0;
	for (int k = 0; k <= n; k++) {
		int cur = ((ll)C(k, n) * A(n, m) % MOD) * A(n - k, m - k) % MOD;
		if (k & 1) {
			res -= cur;
			if (res < 0) res += MOD;
		}	else {
			res += cur;
			if (res >= MOD) res -= MOD;
		}
	}
	cout << res;
}


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

using namespace std;

int main()
{
	string s, t;
	cin >> s >> t;
	for (int i = s.size()-1; i >= t.size() - 1 ; i--)
	{
		bool isValid = true;
		for (int j = 0; j < t.size(); j++)
		{
			if (s[i-j] != '?' && s[i-j] != t[t.size()-j-1])
			{
				isValid = false;
				break;
			}
		}
		if (isValid)
		{
			s = s.substr(0, i + 1 - t.size()) + t + s.substr(i+1);
			replace(s.begin(), s.end(), '?', 'a');
			cout << s << endl;
			return 0;
		}
	}
	cout << "UNRESTORABLE" << endl;
	return 0;
}


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

int main() {
  vector<int> A = {0,1,3,1,2,1,2,1,1,2,1,2,1};
  int x,y; cin >> x >> y;
  if(A.at(x) == A.at(y))
    cout << "Yes";
  else cout << "No";
}

Measured memory_bytes: 3592