akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <climits>
#include <string.h>
#include <algorithm>

using namespace std;
#define fast ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define pb push_back
#define sz(s) (int)s.size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)

typedef long long ll;
typedef pair<ll, ll> pll;
const int N = 77;

ll n,A,x[N];
ll dp[N][N][2555];

ll rec(ll idx, ll select, ll sum){
    if(idx==0){
        if(select > 0 and select*A == sum) return 1;
        return 0;
    }
    
    if(dp[idx][select][sum]!=-1) return dp[idx][select][sum];
    
    ll ret = 0;
    
    ret = rec(idx-1,select+1,sum+x[idx]) + rec(idx-1, select,sum);
    
    return dp[idx][select][sum] = ret;
}

int main(){
    fast;
    cin>>n>>A;
    for1(i,n) cin>>x[i];
    memset(dp, -1, sizeof dp);
    cout<<rec(n,0,0)<<endl;
    return 0;
}


Measured memory_bytes: 118656
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double db;
#define endl '\n'
#define fi first
#define se second
#define pi pair<ll,ll>
#define pii pair<ll,pi>
#define pb push_back
#define mk make_pair
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, m;
	cin >> n >> m;
	vector<vector<int>>dis(n, vector<int>(n, 1e8));
	vector<int>s(m), d(m), l(m);
	for (int i = 0; i < m; i++) {
		cin >> s[i] >> d[i] >> l[i];
		s[i]--, d[i]--;
		dis[s[i]][d[i]] = l[i];
		dis[d[i]][s[i]] = l[i];
	}
	for (int i = 0; i < n; i++)dis[i][i] = 0;
	for (int k = 0; k < n; k++) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
			}
		}
	}
	int ans = 0;
	for (int i = 0; i < m; i++) {
		if (l[i] != dis[s[i]][d[i]])ans++;
	}
	cout << ans << endl;
}






Measured memory_bytes: 3704
// 解き直し.
// https://img.atcoder.jp/cf17-final/editorial.pdf
#include <bits/stdc++.h>
using namespace std;
#define repx(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
int d[2020][50];

int main(){
    
    // 1. N, K の 条件.
    // -> ある1枚の紙に着目した場合に, この紙に書かれている K個 の 整数を, 
    // 残りの (N - 1)枚 の 紙に振り分ける必要があるので, 
    // N - 1 = K * (K - 1) となっている必要があるはず.
    // ex.
    // N = 3, K = 2
    // 1 2
    // 2 3
    // 3 1
    // 
    // N = 7, K = 3
    // 1 2 3
    // 1 4 5
    // 1 6 7
    // 2 4 7
    // 2 5 6
    // 3 4 6
    // 3 5 7
    // 
    // N = 13, K = 4
    // 1 2 3 4
    // 1 5 6 7
    // 1 8 9 10
    // 1 11 12 13
    // 2 5 8 11
    // 2 6 9 12
    // 2 7 10 13
    // 3 5 10 12
    // 3 6 8 13
    // 3 7 9 11
    // 4 5 9 13
    // 4 6 10 11
    // 4 7 8 12
    // 
    // int N = 3, K = 2;
    // int N = 7, K = 3;
    // int N = 13, K = 4;
    // int N = 21, K = 5;
    // int N = 1057, K = 33; // WA版.
    int N = 1407, K = 38; // AC版(解説上, P = K - 1 が素数である必要があるとの指摘あった).
    
    // 2. 条件を満たす整数を保存.
    // 2-1. 0列目 を 整備.
    d[0][0] = 1;
    repx(i, 1, N){
        if(i < K) d[i][0] = 1;
        else      d[i][0] = d[i - K + 1][0] + 1;
    }
    
    // 2-2. セル(0, 1) ～ セル(K - 1, K - 1) を 整備.
    rep(i, K) repx(j, 1, K) d[i][j] = (K - 1) * i + j + 1;
    
    // 2-3. セル(K, 1) ～ セル(N - 1, K - 1) を 整備.
    int r, c;
    repx(i, K, N){
        repx(j, 1, K){
            // 開始地点を調整.
            c = i - (K - 1) * (d[i][0] - 1);
            c -= (j - 1) * (d[i][0] - 2);
            while(c < 1) c += (K - 1);
            d[i][j] = d[j][c];
        }
    }
    
    // 3. 出力.
    printf("%d %d\n", N, K);
    rep(i, N){
        rep(j, K){
            printf("%d", d[i][j]);
            if(j < K - 1) printf(" ");
        }
        printf("\n");
    }
    return 0;
    
}

Measured memory_bytes: 768
#include <iostream>
#include<algorithm>
#include<set>
#include<queue>
#include<bitset>
#include<vector>
#define rep(i,j,n) for(int i=j;i<n;i++)
using namespace std;
#define int long long
struct edge{long long to,cost;};
struct st{int rate,way,num;};
typedef pair<int,int>P;
#define inf 1000000007
string alph("abcdefghijklmnopqrstuvwxyz");
vector<int> es[25];
signed main(){
    int n;cin>>n;
    string s=to_string(n);
    int ans=(s.size()-1)*9;
    int key=1;
    rep(i,0,s.size()-1){
        key*=10;
    }int count=key;key--;
    rep(i,1,10){
        int h=count*i+key;
        if(n>=h)ans++;
        else break;
    }
    cout<<ans<<endl;
    return 0;
}


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

int main(){

    int n,m;
    cin >> n >> m;
    vector<int> ab[51];

    rep(i,m){
        int t,s;
        cin >> s >> t;
        ab[s].push_back(t);
        ab[t].push_back(s);
    }

    for(int i=1;i<=n;i++){
        cout << ab[i].size() <<endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<map>
#include<queue>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
using namespace std;


int main(){

  int n;
  while( cin >> n ){
    if( n == 0 ) break;
    vector< vector<bool> > b(21, vector<bool>(21, false));
    for(int i=0; i<n; i++){
      int x, y;
      cin >> x >> y;
      b[y][x] = true;
    }
    int m;
    cin >> m;
    int px = 10;
    int py = 10;
    for(int i=0; i<m; i++){
      char d;
      int l;
      cin >> d >> l;
      while( l > 0 ){
        if( d == 'N' ) py++;
        if( d == 'S' ) py--;
        if( d == 'E' ) px++;
        if( d == 'W' ) px--;

        if( b[py][px] ){
          n--;
          b[py][px] = false;
        }
        l--;
      }
    }
    cout << ( n == 0 ? "Yes" : "No" ) << endl;

  }

  return 0;
}








// EOF

Measured memory_bytes: 3016
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

char a[52][52];
int main() {
	ll h,w;
	cin>>h>>w;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin>>a[i][j];
		}
	}
	ll x[4]={0,0,1,-1},y[4]={1,-1,0,0};
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(a[i][j]=='#'){
				bool ch=false;
				for(int k=0;k<4;k++){
					ll H=i+x[k],W=j+y[k];
					if(H<0||H>h||W<0||W>w){
						continue;
					}
					if(a[H][W]=='#'){
						ch=true;
						break;
					}
				}
				if(ch==false){
					cout <<"No";
					return 0;
				}
			}
		}
	}
	cout << "Yes";
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
function Main(input) {
  input=input.split("\n");
  var N=input[0].split(" ")[0]-0;
  var M=input[0].split(" ")[1]-0;
  if(N*2>=M){
    console.log(Math.floor(M/2));
    return;
  }
  console.log(N+Math.floor((M-N*2)/4));
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
  
  


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

int main(){
    int n,m;

    cin >> n >> m;

    string s;

    for(int i=0; i < n+2; i++){
        if(i == 0 || i == n+1){
            for(int j=0; j < m+2; j++)
                cout << "#";
            cout << '\n';
        }
        else{
            cin >> s;
            cout << '#' << s << '#' << endl;
        }
    }

}

Measured memory_bytes: 504
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPP(i, n) for(int i = 1; i <= n; ++i)
#define REPR(i, n) for(int i = n-1; i >= 0; --i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;
const ll INF = 1000000000;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,w; cin >> h >> w;
    vector<string> a(h);
    REP(i,h) cin >> a[i];
    bool ans = true;
    [&] {
        REP(i,h) {
            REP(j,w) {
                if(a[i][j]=='#') {
                    if(i<h-1 && j<w-1) ans = ((a[i+1][j]=='#' && a[i][j+1]=='.') || (a[i][j+1]=='#' && a[i+1][j]=='.'));
                    if(i<h-1 && j==w-1) ans = (a[i+1][j]=='#');
                    if(i==h-1 && j<w-1) ans = (a[i][j+1]=='#');
                    if(i>0 && j>0) ans = !(a[i-1][j]=='#' && a[i][j-1]=='#');
                }
                if(!ans) return;
            }
        }
    }();
    cout << (ans ? "Possible" : "Impossible") << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
m = 0
for i in range(N):
    m += B[A[i] - 1]
for t in range(N-1):
    if A[t] + 1 == A[t + 1]:
        m += C[A[t] - 1]
print(m)

Measured memory_bytes: 3064
#!/usr/bin/env python

n = int(input())
a = list(map(int, input().split()))
d = [0 for _ in range(n-1)]
for i in range(n-1):
    d[i] = a[i+1]-a[i]

ans = 1 
flg = [False, False]

for i in range(n-1):
    if d[i] > 0:
        flg[0] = True
    elif d[i] < 0:
        flg[1] = True

    if flg[0] == flg[1] == True:
        ans += 1
        flg = [False, False]

print(ans)


Measured memory_bytes: 20108
M,A,B = [int(x) for x in input().split()]

mod = 10**9+7

def cmb(n, r, mod):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) % mod * pow(i+1, mod-2, mod) % mod
    return res

def binary(n):
    return bin(n)[2:]


def pow_by_binary_exponentiation(a, x, n): # a^x mod n
    x = [int(b) for b in binary(x)]
    y = a
    for i in range(1, len(x)):
        y = (y**2) % n
        if x[i] == 1:
            y = (y * a) % n
    return y
d = pow_by_binary_exponentiation(2,M,mod)-1
    
d1 = cmb(M,A,mod)
d2 = cmb(M,B,mod)
print((d-d1-d2)%mod)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;

int main(){
  string s[3];
  while(cin>>s[0]&&s[0]!="0"){
    cin>>s[1]>>s[2];
    bool ak=false,bk=false;
    for(int i=0;i<3;i++){
      bool ak1=true,ak2=true;
      bool bk1=true,bk2=true;
      for(int j=0;j<3;j++){
	if(s[i][j]!='w')ak1=false;
	if(s[j][i]!='w')ak2=false;
	if(s[i][j]!='b')bk1=false;
	if(s[j][i]!='b')bk2=false;
      }
      if(ak1||ak2)ak=true;
      if(bk1||bk2)bk=true;
    }
    int dx[2][3]={{0,1,2},{0,1,2}};
    int dy[2][3]={{0,1,2},{2,1,0}};
    for(int i=0;i<2;i++){
      bool ak1=true,bk1=true;
      for(int j=0;j<3;j++){
	if(s[dx[i][j]][dy[i][j]]!='w')ak1=false;
	if(s[dx[i][j]][dy[i][j]]!='b')bk1=false;
      }
      if(ak1)ak=true;
      if(bk1)bk=true;
    }
    if(ak)cout<<"w"<<endl;
    if(bk)cout<<"b"<<endl;
    if(!(ak+bk))cout<<"NA"<<endl;
  }
  return 0;
}

Measured memory_bytes: 3084
import collections

n = int(input())
card = list(map(int, input().split()))
cardcount = collections.Counter(card).most_common()
oddcount = 0
for k, v in cardcount:
    if v % 2 == 0:
        oddcount += 1
if oddcount % 2 == 0:
    print(len(set(card)))
else:
    print(len(set(card)) - 1)


Measured memory_bytes: 21972
#import collections as c
#ip = lambda : map(int, input().split())

#################
N = int(input())
if N%2==0:
    print(N*(N-1)//2-N//2)
    S = N + 1
    for i in range(1,N):
        for j in range(i+1,N+1):
            if i!=j and i+j!=S:
                print(i,j)

elif N%2==1:
    print(N*(N-1)//2-(N-1)//2)
    S = N
    for i in range(1,N):
        for j in range(i+1,N+1):
            if i!=j and i+j!=S:
                print(i,j)

# a = []
# b = []



# f = 1
# for i in range(N,0,-1):
#     if f%4==1 or f%4==0:
#         a.append(i)
#         f += 1
#     else:
#         b.append(i)
#         f += 1
# print(len(a)*len(b))
# for ia in a:
#     for ib in b:
#         print(ia,ib)

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

typedef long long ll;
const ll INF = 1e9, MOD = 1e9 + 7;
const double EPS = 1e-9, PI = 3.141592653589793;
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define REPR(i,a,b) for(ll i=b;i>=a;i--)
#define repr(i,n) REPR(i,0,n)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define fi first
#define se second
#define m_p make_pair

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

    ll a,b,ans=0;
    cin >> a >> b;
    ans = max(a,b);
    if(max(a,b)==a){
        if(a-1>b) ans += a-1;
        else ans += b;
    }else{
        if(b-1>a) ans += b - 1;
        else ans += a;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;
int n, m;
char W[100][100];

void dfs(int y, int x){
    W[y][x] = '0';
    for(int dx = -1; dx <= 1; dx++){
        for(int dy = -1; dy <= 1; dy++){
            int nx = dx + x;
            int ny = dy + y;
            if(W[ny][nx] == '1' and 0 <= nx and nx < n and 0 <= ny and ny < m) dfs(ny, nx);
        }
    }
    return ;
}

int main(void){
    while(true){
        cin >> n >> m;
        if(n == 0 and m == 0) return 0;
        REP(i, m){
            REP(j, n){
                cin >> W[i][j];
            }
        }

        int ans = 0;
        REP(i, m){
            REP(j, n){
                if(W[i][j] == '1'){
                    dfs(i, j);
                    ans++;
                }
            }
        }
        cout << ans << endl;
    }
}


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

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

    string S;

    cin >> S;

    int count = 0;

    if(S[0] == '0')
    {
        for(int i = 0; i < S.size(); i+= 2)
        {
            if(S[i] == '1')
            {
                count++;
            }
        }

        for(int i = 1; i < S.size(); i+= 2)
        {
            if(S[i] == '0')
            {
                count++;
            }
        }
    } else {
        for(int i = 0; i < S.size(); i+= 2)
        {
            if(S[i] == '0')
            {
                count++;
            }
        }

        for(int i = 1; i < S.size(); i+= 2)
        {
            if(S[i] == '1')
            {
                count++;
            }
        }
    }

    cout << count;
}

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

using namespace std;
using LL = long long;
using P = pair<int,int>;
const LL mod = 998244353;

int main(){
	LL N, K;
	cin >> N >> K;
	vector<LL> L(K), R(K);
	rep(i,K) cin >> L[i] >> R[i];
	vector<LL> dp(N+1), num(K), sum(N+1);
	dp[1]=1, sum[1]=1;
	for(int i=2; i<=N; i++){
		rep(j,K){
			if(R[j]<i){
				num[j]+=dp[i-L[j]];
				num[j]-=dp[i-R[j]-1];
				dp[i]+=num[j];
			}
			else if(L[j]<i){
				num[j]+=dp[i-L[j]];
				dp[i]+=sum[i-L[j]];
			}
			dp[i]%=mod;
			sum[i]=(sum[i-1]+dp[i]);
			sum[i]%=mod;
		}
	}
	LL ans=dp[N];
	while(ans<0) ans+=mod;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 6384
#include <iostream>
#include <vector>

using namespace std;

int main() {
    vector<vector<size_t>> a(3);
    for (size_t i = 0; i < 3; ++i) {
        vector<size_t> tmp(3);
        for (size_t j = 0; j < 3; ++j) cin >> tmp[j];
        a[i] = tmp;
    }
    size_t n;
    cin >> n;
    vector<vector<bool>> card(3);
    for (size_t i = 0; i < 3; ++i) card[i] = vector<bool>(3, false);
    for (size_t i = 0; i < n; ++i) {
        size_t b;
        cin >> b;
        for (size_t y = 0; y < 3; ++y) {
            for (size_t x = 0; x < 3; ++x) {
                if (a[y][x] == b) card[y][x] = true;
            }
        }
    }
    vector<bool> vertical(3, true);
    vector<bool> horizontal(3, true);
    vector<bool> diagonal(3, true);
    diagonal[2] = false;
    for (size_t i = 0; i < 3; ++i) {
        for (size_t j = 0; j < 3; ++j) {
            vertical[j] = vertical[j] & card[i][j];
            horizontal[i] = horizontal[i] & card[i][j];
            if (i == j) diagonal[0] = diagonal[0] & card[i][j];
            if ((i == 0 && j == 2) || (i == 1 && j == 1) || (i == 2 && j == 0)) diagonal[1] = diagonal[1] & card[i][j];
        }
    }
    bool enable = false;
    for (size_t i = 0; i < 3; ++i) {
        if (vertical[i] || horizontal[i] || diagonal[i]) {
            enable = true;
            break;
        }
    }
    cout << (enable ? "Yes" : "No") << endl;
    return EXIT_SUCCESS;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    int n, m;
    std::cin >> n >> m;
    std::vector<std::vector<int>> g(n);
    for (int i = 0; i < m; i++) {
        int s, t;
        std::cin >> s >> t;
        g[s - 1].push_back(t - 1);
    }

    double ret = n + 10;
    std::vector<double> dp(n);
    for (int i = n - 2; i >= 0; i--) {
        std::vector<double> tt(n), es;
        for (int j = n - 1; j > i; j--) tt[j] = dp[j];
        double sum = 0, max = 0;
        for (int to : g[i]) {
            es.push_back(dp[to]);
            max = std::max(max, dp[to]);
            sum += dp[to];
        }

        dp[i] = sum / es.size() + 1;
        if (es.size() > 1) {
            tt[i] = (sum - max) / (es.size() - 1) + 1;
        } else {
            tt[i] = sum + 1;
        }

        for (int j = i - 1; j >= 0; j--) {
            for (int to : g[j]) {
                tt[j] += tt[to];
            }
            tt[j] /= g[j].size();
            tt[j] += 1;
        }

        // std::cerr << i << "\n";
        // fprintf(stderr, "i = %d\n", i);
        // for (int j = 0; j < n; j++) fprintf(stderr, "\ttt[%d] = %lf\n", j, tt[j]);
        ret = std::min(ret, tt[0]);
    }

    std::cout << std::fixed << std::setprecision(10) << ret << std::endl;

    return 0;
}


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


int main()
{
    int i,j,mini,n,cnt=0;
    cin>>n;
    int arr[n];
    for(i=0; i<n; i++)
        cin>>arr[i];

    for(i=0; i<n; i++){
        mini = i;
        for(j=i; j<n; j++){
            if(arr[j] < arr[mini]){
                mini=j;
            }
        }
        swap(arr[mini],arr[i]);
            if(mini!=i){
                cnt++;
            }
    }

     for(i=0; i<n; i++){
        cout<<arr[i];
        if(i<n-1)
            cout<<" ";
    }
    cout<<endl<<cnt<<endl;

}

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

using namespace std;

typedef long long ll;

const int maxn = 1e6+10;

int n,m,q;
int da[maxn];

inline int read()
{
    int X=0,w=0; char ch=0;
    while(!isdigit(ch)) w|=ch=='-',ch=getchar();
    while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
    return w?-X:X;
}


int main()
{
    int n = read();
    cout<<(1000-(n%1000))%1000<<endl;
    return 0;
}


Measured memory_bytes: 3612
N = gets.to_i
A = gets.split(" ").map(&:to_i)

arr = Array.new(N, nil)
N.times do |i|
  arr[i] = [i, A[i]]
end

arr.sort! { |a, b| b[1] <=> a[1] }
dp = Array.new(N+1) { Array.new(N+1, 0) }

N.times do |i|
  loc = arr[i][0]
  val = arr[i][1]
  0.upto(i) do |left|
    right = i - left

    dp[left+1][right] = [dp[left+1][right], dp[left][right] + ((loc - left) * val).abs].max
    dp[left][right+1] = [dp[left][right+1], dp[left][right] + ((loc - (N-right-1)) * val).abs].max
  end
end

res = 0
N.times do |left|
  right = N - left
  res = [res, dp[left][right]].max
end

puts res


Measured memory_bytes: 45716
#include<cstdio>

int a,b,c,d,e,f,dp[3010],dp2[3010];

int main()
{
    scanf ("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);

    a*=100; b*=100;
    dp[0]=1;
    for (int i=a;i<=f;i++)
        if (dp[i-a]) dp[i]=1;
    for (int i=b;i<=f;i++)
        if (dp[i-b]) dp[i]=1;
    int br=-1;
    for (int i=f;i>=0;i--)
        if (!dp[i]) dp[i]=br;
        else { br=i; dp[i]=br; }
    dp[0]=dp[1];
    //for (int i=1699;i<=1710;i++) printf ("%d ",dp[i]);

    dp2[0]=1;
    for (int i=c;i<=f;i++)
        if (dp2[i-c]) dp2[i]=1;
    for (int i=d;i<=f;i++)
        if (dp2[i-d]) dp2[i]=1;
    //for (int i=0;i<=f;i++) printf ("%d ",dp2[i]);
    double ans=0;
    int p=a,q=0;
    for (int i=1;i<=f;i++)
        if (dp2[i])
        {
            int y=(100*i)/e;
            if ((100*i)%e) y++;
            if ((y>f)||(dp[y]==-1)) break;
            //if (i==10) printf ("y %d y",dp[y]);
            if ((dp[y]+i)<=f)
            {
                double r=100*i, t=(dp[y]+i);
                if ((r/t)>ans)
                {
                    ans=r/t;
                    p=dp[y]+i;
                    q=i;
                }
            }
        }
    printf ("%d %d",p,q);
    return 0;
}


Measured memory_bytes: 128
#include <cassert>
#include <iostream>
#include <functional>
#include <iomanip>
#include <set>
#include <unordered_map>
#include <queue>
#include <vector>
#include <deque>
#include <algorithm>
#include  <cstring>
#include <string>
#include <cmath> 
using namespace std;
typedef long long LL;
const int MAX = 210000;
const LL base = 1e9 + 7;


struct Node {
	int x, y, w;
};


void solve() {

	LL result = 0;
	int N;

	cin >> N;
	string S;
	cin >>S;
	int q;
	cin >>q;
	vector<int> zk(q);
	for (int i=0; i<q; ++i) {
		cin >>zk[i];
	}
	for (auto k : zk) {
		LL tm = 0, tc = 0, tmc = 0;
		result = 0;
		for (int i=0; i<k-1; ++i) {
			if (S[i] == 'M') {
				tm+=1;
			}
			else if (S[i] =='C') {
				tc +=1;
				tmc += tm;
			}
		}
		int tail = k-2;
		for (int i=0; i<N-2; ++i) {
		
		 
			tail += 1;

			if (S[i] == 'M' ){
				tm -=1;
				tmc -= tc;
			}
			else if (S[i] =='C' ){
				tc -=1;
			}
			if (tail <N) {
				if (S[tail]=='M') {
					tm += 1 ;
				}
				else if (S[tail] =='C') {
					tc += 1;
					tmc += tm;
				}
			} 
			
			if (S[i] =='D')
				result += tmc;
		}
		cout<<result<<endl;
	} 

}

int main() {
	const int inId = 0;
	const int outId = 0;
	if (inId>0) {
		cerr << "redirect stdin to input " << inId << endl;
		string s = "input";
		s += to_string(inId);
		s += ".txt";
		auto r = freopen(s.c_str(), "r", stdin);	
		if (r == nullptr) {
			cerr<< "invalid input file "<< s;
		}
	}
	if (outId>0) {
		cerr << "redirect stdout to stdout " << outId << endl;
		string s = "stdout";
		s += to_string(outId);
		s += ".txt";
		auto r = freopen(s.c_str(), "w", stdout);
		if (r == nullptr) {
			cerr<< "invalid output file "<< s;
		}		
	}
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // close sync between cout and printf
	cout.precision(10);
	solve();
}
 

Measured memory_bytes: 1948
#include <stdio.h>

int main() {
  int a,b, result;
  char op;
  while(1) {
    scanf("%d %c %d", &a, &op, &b);
    if(op=='?')break;
    if(op=='+')result=a+b;
    if(op=='-')result=a-b;
    if(op=='*')result=a*b;
    if(op=='/')result=a/b;
    printf("%d\n", result);
  }
  return 0;
}



Measured memory_bytes: 2072
//
//  CPlibrary
//
//  Created by Tanmay Singh on 3/03/2020.
// INDIAN INSTITUTE OF TECHNOLOGY (BHU) , VARANASI
//  Copyright © 2020 Tanmay Singh. All rights reserved.
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
 
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <climits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <ratio>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
 
#define FAST(); ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl "\n"
#define mod 1000000007
typedef long long int  bigint ;
typedef std::vector< int > vi;
typedef std::vector< long long int > vll;
typedef std::vector< vi > vvi;

using namespace std ;
bigint dp[100001] ;
bigint frogJump( string str , int N , int D ){
    for( int i = 0 ; i < N ; i++ ){
        dp[i] = INT_MAX ;
        if( str[i] == '0' )
            continue ;
            for( int j = i - D ; j < i ; j++ ){
                dp[i] = min( dp[i] , dp[j] + 1 ) ;
            }
    }
    return dp[N-1] ;
}
int main(){
    FAST();
    int N ; cin >> N ;
    int arr[N] ;
    for( int i = 0 ; i < N ; i++ )
        cin >> arr[i] ;
    bigint dp[100001] ;
    dp[0] = 0 ;
    dp[1] = abs( arr[1] - arr[0] ) ;
    for( int i = 2 ; i < N ; i++ ){
        dp[i] = min( abs( arr[i] - arr[i-1] ) + dp[i-1] , dp[i-2] + abs(arr[i] - arr[i-2]) ) ;
    }
    cout << dp[N-1] << endl ;
    return 0 ;
}



Measured memory_bytes: 4816
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;

int main(){
    int n, m, c;
    int ans = 0;
    cin >> n >> m >> c;
    vector<int> b(m);
    vector<vector<int>> a(n, vector<int>(m));
    REP(i, m) cin >> b[i];
    REP(i, n){
        REP(j, m){
            cin >> a[i][j];
        }
    }
    
    REP(i, n){
        int wa = c;
        REP(j, m){
            wa += a[i][j] * b[j];
        }
        if(wa > 0) ans++;
    }
    cout << ans << "\n";
}


Measured memory_bytes: 256
object Main extends App {
  val read = scala.io.StdIn.readLine()
  val array = read.split(" ").map(_.toInt).toVector
  val n = array(0)
  val k = array(1)
  var vec = Vector.empty[Double]

  for (i<-1 to n) {
    if (i < k) {
      var count = 0
      var temp = i
      while(temp < k) {
        count = count + 1
        temp = temp * 2
      }
      vec :+= (1d / n.toDouble) * Math.pow(0.5, count)
    } else {
      vec :+= (1d / n.toDouble)
    }
  }
  print(vec.sum)
}

Measured memory_bytes: 40324
#include <stdio.h>

int main(void){
	int x, y, z, buf;
	
	scanf("%d %d %d", &x, &y, &z);

	while(1){
		if(x > y){
			buf = x;
			x = y;
			y = buf;
		}
		if(y > z){
			buf = y;
			y = z;
			z = buf;
		}

		if((x <= y) && (y <= z)){
			printf("%d %d %d\n", x, y, z);
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
// #define int long long
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repa(i, s, n) for(int i = s; i < (int)n; i++)
#define MOD 1000000007
using namespace std;
using ll = long long;
typedef vector<int> vi;


signed main() {
    vi a(3);
    cin >> a[0] >> a[1] >> a[2];

    int cnt = 0;
    while(!(a[0] == a[1] && a[0] == a[2])){
        // cout << a[0] << " " << a[1] << " " << a[2] << endl;
        sort(a.begin(), a.end());
        if(a[2] - a[0] > 1){
            a[0] += 2;
            cnt++;
        }else if(a[2] - a[0] == 1){
            a[2] -= 1;
            cnt++;
        }
    }
    
    cout << cnt << endl;
}

Measured memory_bytes: 3628
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main
{
    public void run()
    {
        Scanner sc = new Scanner(System.in);
        String text = sc.next();

        String ans = "-1";

        Set<Character> chsSet = new HashSet();
        for (char ch : text.toCharArray()) chsSet.add(ch);
        System.err.println(chsSet);
        if (text.length() < 26)
        {
            for (int i = 0; i < 26; i++)
            {
                char ch = (char) ('a' + i);
                if (!chsSet.contains(ch))
                {
                    ans = text + ch;
                    break;
                }
            }

        } else
        {
            OUTER:
            for (int i = 24; i >= 0; i--)
            {
                if (text.charAt(i) < text.charAt(i + 1))
                {
                    for (int j = 25; j > i; j--)
                    {
                        if (text.charAt(i) < text.charAt(j))
                        {
                            ans = text.substring(0, i) + text.charAt(j);
                            break OUTER;
                        }
                    }
                }
            }
        }

        System.out.println(ans);
    }

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

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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    ll A, B, C, X, Y; cin >> A >> B >> C >> X >> Y;
    ll res = INF;
    rep(i, max(X, Y)+1){
        ll tmp = 0;
        tmp += 2 * C * i;
        if(X-i>0) tmp += (X-i)*A;
        if(Y-i>0) tmp += (Y-i)*B;

        res = min(res, tmp);
    }

    cout << res << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define INIT  ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define mp make_pair
#define pb push_back
#define ft first
#define sc second
#define ll long long
#define pii pair<int, int>
#define count_bits __builtin_popcount



int m1, h1, m2, h2, k;



int32_t main(){
INIT
cin>>h1>>m1>>h2>>m2>>k;


cout<<max(0, (h2-h1)*60-m1+m2-k);




return 0;
}


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

int INF=100001;

signed main(){
  int N;
  cin>>N;
  vector<int> ans(INF);
  rep(i,N){
    int A;
    cin>>A;
    ans[A]+=1;
  }
  int sum=0;
  rep(i,INF)sum+=i*ans[i];
  int Q;
  cin>>Q;
  rep(i,Q){
    int B,C;
    cin>>B>>C;
    sum-=B*ans[B];
    sum-=C*ans[C];
    ans[C]+=ans[B];
    ans[B]=0;
    sum+=B*ans[B];
    sum+=C*ans[C];
    cout<<sum<<endl;
  }
}

Measured memory_bytes: 4020
import sys
input = sys.stdin.readline
from collections import *

R, G, B, N = map(int, input().split())
ans = 0

for i in range(N+1):
    for j in range(N+1):
        if N-R*i-G*j>=0 and (N-R*i-G*j)%B==0:
            ans += 1

print(ans)

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

typedef long long int ll; 
#define MOD 1000000007
#define ON 200000
#define rep(i,n) fp(i,0,n)  
#define fp(i,a,b) for(ll i=(a);i<(b);++i)
#define fn(i,a,b) for(ll i=(a);i>(b);i--)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define FF first
#define SS second
typedef pair<ll, ll> pll; 
typedef vector<pll> vpll;
typedef vector<ll> vll;
#define rs(t) string t;cin>>t
#define ri(t) int t;cin>>t
#define rll(t) long long int t;cin>>t
#define MK make_pair
#define PB push_back
#define PO pop_back


int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  rll(n);
  cout << (ll)(pow(n,3)+0.5) << endl;
  return 0;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20)
#define int long long
#define double long double
const int INF = 1e18, MOD = 1e9 + 7;

int n, m, a;
int cnt[111111] = {};

signed main() {
    INCANT;
    cin>>n>>m;
    for (int i = 0; i < m; i++) {
        cin>>a;
        cnt[a]++;
        cin>>a;
        cnt[a]++;
    }
    for (int i = 1; i <= n; i++) {
        if (cnt[i] % 2) {
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
}

Measured memory_bytes: 1152
l = input().split()
r = int(l[0])
c = int(l[1])

a = []
for i in range(r):
    a.append(list(map(int, input().split())))

for i in range(len(a)):
    a[i].insert(c, sum(a[i]))

b = []
a.append(b)

for i in range(c): #4
    s = 0
    for j in range(r): #5
        s += a[j][i]
    a[-1].append(s)
a[-1].append(sum(a[-1]))

for i in range(len(a)):
    print(*a[i])

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

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

    vector<int> A(N + 2);
    A[0] = A[N + 1] = 0;
    int sum = 0;
    for (int i = 1; i <= N; i++)
    {
        cin >> A[i];
        sum += abs(A[i] - A[i - 1]);
    }
    sum += abs(A[N + 1] - A[N]);

    for (int i = 1; i <= N; i++)
    {
        cout << sum - abs(A[i] - A[i - 1]) - abs(A[i + 1] - A[i]) + abs(A[i + 1] - A[i - 1]) << endl;
    }
}

Measured memory_bytes: 1664
import scala.io.StdIn.{readInt, readLine}

object Main extends App {

  val n = readInt
  val cards1 = readLine.split(" ")
  val cards2 = cards1.clone()

  bubbleSort(n, cards1)
  selectionSort(n, cards2)

  val sortedCards1 = cards1.mkString(" ")
  val sortedCards2 = cards2.mkString(" ")

  println(sortedCards1)
  println("Stable")

  println(sortedCards2)
  if (sortedCards1.equals(sortedCards2)) {
    println("Stable")
  } else {
    println("Not stable")
  }

  def bubbleSort(n: Int, cards: Array[String]) = {
    for (i <- 0 to n - 1; j <- n - 1 to i + 1 by -1) {
      if (compareCards(cards(j), cards(j - 1)) < 0) {
        swapCard(cards, j, j - 1)
      }
    }
  }

  def selectionSort(n: Int, cards: Array[String]) = {
    for (i <- 0 until n) {
      var mini = i
      for (j <- i + 1 until n) {
        if (compareCards(cards(j), cards(mini)) < 0) {
          mini = j
        }
      }
      if (i != mini) {
        swapCard(cards, i, mini)
      }
    }
  }

  def compareCards(card1: String, card2: String): Int = {
    val value1 = card1.substring(1).toInt
    val value2 = card2.substring(1).toInt
    value1 - value2
  }

  def swapCard(cards: Array[String], i: Int, j: Int): Unit = {
    val tmp = cards(i)
    cards(i) = cards(j)
    cards(j) = tmp
  }
  
}



Measured memory_bytes: 44072
#include<iostream>
#include<iomanip>
#include<string>
#include<set>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<functional>
using namespace std;
#define LL long long
#define MOD 100000
#define inf 1999999999
#define ALL(x) (x).begin(), (x).end()
#define LBi(x, n) lower_bound(ALL(x), n) - (x).begin()
#define ZIP(x) (x).erase(unique(ALL(x)), (x).end())
#define Pi pair<int, int>
#define Vi vector<int>

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

string s, t;
char ch[10];
int n, a, b, c, d, x, m[5];

int main() {
	cin >> s;
	if(s[0] == '9' || s[1] == '9') 
		cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define rv(s) reverse(s.begin(),s.end());
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
 
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
 
int vtotal(vi& v){
  int total=0;
  rep(i,v.size()) total+=v[i];
  return total;
}
 
void printv(vi& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
 
int main()
{
  cin.tie( 0 );
  ios::sync_with_stdio( false );
  
  int n,q;cin>>n>>q;
  string s;cin>>s;
  vpii v(n);
  rep(i,q){
    int l,r;cin>>l>>r;
    v[i]=mp(l,r);
  }
  vi counter(n,0);
  irep(i,1,n){
    counter[i]=counter[i-1];
    if(s.substr(i-1,2)=="AC"){
      counter[i]++;
    }
  }
  rep(i,q){
    int l=v[i].first-1;
    int r=v[i].second-1;
    // cout<<l<<" "<<r<<" "<<counter[l]<<" "<<counter[r]<<endl;
    cout<<(counter[r]-counter[l])<<endl;
  }
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

struct vec3{
public:
  int x,y,z;
  vec3():x(0),y(0),z(0) {}
  vec3(int x,int y,int z):x(x),y(y),z(z) {}
};

int dp[200][200][200];

int main(){
  // ??´?????????K?????\???????????£???????????¨????????°????????????
  // 1<=K<=N<=50
  // ??§?¨???§??????
  // ?????????????????????
  // ?????????N^3 <= 125000
  // ????¬????imos??§????????°???????????¨???????????????
  int n,k;
  cin>>n>>k;
  vec3 A[n],B[n];
  set<int> Xs,Ys,Zs;
  REP(i,n){
    int x,y,z;
    cin>>x>>y>>z;
    A[i] = vec3(x,y,z);
    Xs.insert(x);
    Ys.insert(y);
    Zs.insert(z);
    cin>>x>>y>>z;
    B[i] = vec3(x,y,z);
    Xs.insert(x);
    Ys.insert(y);
    Zs.insert(z);
  }
  int Xc = Xs.size(), Yc = Ys.size(), Zc = Zs.size();
  vi Xa, Ya, Za;
  map<int,int> Xm,Ym,Zm;
  set<int>::iterator iter;
  iter = Xs.begin();
  while(iter!=Xs.end()){
    Xm[*iter] = Xa.size();
    Xa.push_back(*iter);
    ++iter;
  }
  iter = Ys.begin();
  while(iter!=Ys.end()){
    Ym[*iter] = Ya.size();
    Ya.push_back(*iter);
    ++iter;
  }
  iter = Zs.begin();
  while(iter!=Zs.end()){
    Zm[*iter] = Za.size();
    Za.push_back(*iter);
    ++iter;
  }
  // imos
  REP(i,n){
    vec3 a = A[i], b = B[i];
    int ax = Xm[a.x],
        ay = Ym[a.y],
        az = Zm[a.z],
        bx = Xm[b.x],
        by = Ym[b.y],
        bz = Zm[b.z];
    dp[ax][ay][az] += 1;
    dp[ax][ay][bz] -= 1;
    dp[ax][by][az] -= 1;
    dp[bx][ay][az] -= 1;
    dp[ax][by][bz] += 1;
    dp[bx][ay][bz] += 1;
    dp[bx][by][az] += 1;
    dp[bx][by][bz] -= 1;
  }
  REPR(x,200)REP(y,200)REP(z,200){
    dp[x][y][z] += dp[x-1][y][z];
  }
  REP(x,200)REPR(y,200)REP(z,200){
    dp[x][y][z] += dp[x][y-1][z];
  }
  REP(x,200)REP(y,200)REPR(z,200){
    dp[x][y][z] += dp[x][y][z-1];
  }
  ll result = 0;
  REP(x,Xc-1)REP(y,Yc-1)REP(z,Zc-1){
    if(dp[x][y][z] >= k){
      result += (ll)(Xa[x+1]-Xa[x])*(ll)(Ya[y+1]-Ya[y])*(ll)(Za[z+1]-Za[z]);
    }
  }
  cout<<result<<endl;
  return 0;
}

Measured memory_bytes: 32492
N,M = list(map(int,input().split()))
X = list(map(int,input().split()))

X.sort()

Y = []
for i in range(M-1):
  Y.append(abs(X[i]-X[i+1]))
  
Y.sort()
  
res=0
for i in range(M-N):
  res=res+Y[i]

print(res)

Measured memory_bytes: 13964
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <math.h>
#include <limits>

template <typename T>
void vc(T t) {
    std::cout << t << " ";
}

template<typename T, typename... Args>
void vc(T t, Args... args) {
// recursive variadic function
    std::cout << t << " ";
    vc(args...) ;
}

const int N = 100000;

int dp[3001][3001];
void once() {
  int h, w;
  std::cin >> h >> w;
  std::vector<std::string> vs(h);
  for (int i = 0; i < h; ++i) {
    std::cin >> vs[i];
  }
  std::vector<std::vector<int> > dp(h + 1, std::vector<int>(w + 1, 0));
  dp[0][0] = 1;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (j - 1 >= 0 && vs[i][j - 1] == '.') {
        dp[i][j] += dp[i][j - 1];
        dp[i][j] %= 1000000007;
      }
      if (i - 1 >= 0 && vs[i - 1][j] == '.') {
        dp[i][j] += dp[i - 1][j];
        dp[i][j] %= 1000000007;
      }
    }
  }

  std::cout << dp[h - 1][w - 1] << std::endl;
}

int
main() {
  int n = 1;
  std::ios::sync_with_stdio(false);
  // std::cin >> n;
  while (n--) {
    once();
  }
}

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

int bubbleSort(vector <int> &a,int N){
  int sw = 0;

  //bubblesortの終了は値の移動が’行われない時である
  bool flag = 1; //値の移動があるかないかのflag

  //flagが立たない限り、一番小さい値をvectorの右に移動 。iはsortする回数
  for (int i =0; flag ; i++){
    flag = 0;
    for (int j = N-1;j>=i+1;j--){
      if(a.at(j)<a.at(j-1)){//もし、右の値が左の値より小さいなら、
        swap(a.at(j),a.at(j-1));//交換
        flag = 1;//移動を検知するflagを立てる
        sw++;
     }
   }

  }
  return sw;
}

int main(){


  int  n,sw;
  cin >>n;
  vector <int> a(100);
  rep(i,n) cin>>a.at(i);


  sw = bubbleSort(a,n);
  rep(i,n){
    if(i)cout<<" ";//ゼロ以外で出力
    cout<<a.at(i);
  }
  cout <<endl;
  cout <<sw <<endl;

  return 0;

}



Measured memory_bytes: 3120
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;

class Program{
  static void Main(){
    var input = ReadLine().Split(' ');
    var result = input.GroupBy(a => a).Count();
    if(result == 2){
      Write("Yes");
    }else{
      Write("No");
    }
  }
}

Measured memory_bytes: 13396
#include<iostream>
#include<stdio.h>//printf("%.*f\n",*********);
#include<vector>//s.erase(n),vector
#include<algorithm>//next_permutation
#include<set>
#include<string>//char('a'=32+'A')
//to_string,string,substr
#include<sstream>
#include<complex>
#include<time.h>
#include<random>
#include<cmath>//min,max
#include<math.h>
#include<queue>
#include<time.h>
#include<map>//map
#include<iomanip>
#include<locale>
#include<utility>//swap

#define rt "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)//start==1
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)//end==1
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define Yay(ans) if(ans)cout<<"Yay!"<<rt;else cout<<":("<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(a,n) rep(i,n)cin>>a[i];//vcin(配列名),(繰り返し回数)
#define sort(s) sort(s.begin(),s.end())//昇順
#define reve(s) reverse(s.begin(),s.end())//反転
#define please return
#define AC 0
#define Inf 2147483647//int最大
#define llInf 9223372036854775807//llint最大
#define rapid cin.tie(0);ios::sync_with_stdio(false)
#define pi 3.1415926535897932384626//pi
#define nine 1000000000//10^9
#define print(a) printf("%.15f\n",a)

using namespace std;
typedef vector<int> vint;
typedef long double ldouble;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<double> vdou;
typedef vector<double> vdouble;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<bool>> vvbool;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;

long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

unsigned GetDigit(unsigned num) {
	return std::to_string(num).length();
}

int tow(int n) {//2のn乗
	if (n == 0)return 1;
	int x = tow(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;//@domino
}

int KETA(int n) { //Sum of Each Digit
	int sum = 0;
	while (n > 0) {
		sum += n % 10; n /= 10;
	}
	return sum;
}

unsigned ND(unsigned num) {//Number of Digits
	return std::to_string(num).length();//outmax=10
}

bool KIBN(string s) {
	rep(i, s.size() / 2) {
		if (s[i] != s[s.size() - 1 - i])return false;
	}
	return true;
}

bool inte(double n) {//整数かどうかの判定
	if (ceil(n) == floor(n)) {//切り上げ関数,切り下げ関数
		return true;
	}
	else return false;
}

// (char)toupper(a[n])=文字列のn文字目を大文字で出力

// pow(a,b)=aのb乗

//グローバル関数
int a = 0, n = 0, x = 0, y = 0, ans = 0, cnt = 0, sum = 0;
string s = "";

int main(void) {
	rapid;

	llint x;
	cin >> x;
	llint now = 100;
	llint ans = 0;
	while (x > now) {
		now *= 1.01;
		ans++;
	}
	cout << ans << rt;

	please AC;
}


//参考：---;


Measured memory_bytes: 3624
import java.util.*;


public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        long sum = 0;
        for (int i = 0; i < M; i++) {
            sum += sc.nextInt();
        }

        System.out.println(sum <= N ? N-sum : -1);
    }
}


Measured memory_bytes: 37924
import java.util.*;

class Main{
public static void main(String args[]){
Scanner scan = new Scanner(System.in);
int a = scan.nextInt();
int b = scan.nextInt();
int c = scan.nextInt();
if(a > b){
int i = a;
a = b;
b = i;
}
if(b > c){
int i = b;
b = c;
c = i;
}
if(a > b){
int i = a;
a = b;
b = i;
}
System.out.println(a + " " + b + " " + c);
}

}

Measured memory_bytes: 26032