akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<algorithm>
using namespace std;
int main(void)
{
	int n,a[200][3],i,j,k,sum,flg[200][3]={0};
	scanf("%d",&n);
	for(i=0;i<n;i++){
		for(j=0;j<3;j++){
			scanf("%d",&a[i][j]);
		}
	}
	for(i=0;i<3;i++){
		for(j=0;j<n-1;j++){
			for(k=j+1;k<n;k++){
				if(a[j][i]==a[k][i]){
					flg[j][i]=1;
					flg[k][i]=1;
				}
			}
		}
	}
	for(i=0;i<n;i++){
		sum=0;
		for(j=0;j<3;j++){
			if(flg[i][j]==0){
				sum+=a[i][j];
			}
		}
		printf("%d\n",sum);
	}
	return 0;
}


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

bool comp(const pair<string,int> a, const pair<string,int> b) {
  if (a.first != b.first)
    return a.first < b.first; // 高い順に並べたいので演算子を逆に
  else{
      return a.second > b.second;
  }
}

int main(){
  int N;
  vector<pair<string,int>> list;
  vector<pair<string,int>> copy;

  cin >>N;

  cout <<(N-2)*180<<endl;

  return 0;
  }

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

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    set<string> ss;
    ss.insert(s);
    rep(i,n-1) {
        string ns;
        cin >> ns;
        if(ss.count(ns)) {
            cout << "No" << endl;
            return 0;
        }
        ss.insert(ns);
        if(ns[0] != s[s.size()-1]) {
            cout << "No" << endl;
            return 0;
        }
        s = ns;
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#むりくぼ
n = int(input())
p = list(map(int,input().split()))
count = 0

for i in range(1,n+1):
    if p[i-1] != i:
        count += 1

if count == 2:
    print("YES")
elif count == 0:
    print("YES")
else:
    print("NO")

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

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

int main() {
	int N, K;
	cin >> N >> K;
	vector<long long> H;
	long long tmp;
	for (int i = 0; i < N; i++)
	{
		cin >> tmp;
		H.push_back(tmp);
	}
	sort(H.begin(), H.end());
	long long res = 9223372036854775807;
	for (int i = 0; i < N - K + 1; i++)
	{
		if (res > H[i + K - 1] - H[i]) {
			res = H[i + K - 1] - H[i];
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 1400
#include <cstdio>
#include <vector>
#include <algorithm>

#define fin stdin
#define fout stdout
//FILE *fin = fopen("a.in", "r"), *fout = fopen("a.out", "w");

struct myc {
    int l, c, a;
    inline bool operator < (const myc &u) const {
        return a > u.a;
    }
};
std::vector < int > t;

int sef(int x) {
    if (t[x] == x) return x;
    else return t[x] = sef(t[x]);
}

int main() {
    int n, h, w;
    fscanf(fin, "%d%d%d", &n, &h, &w);

    t.resize(h + w);

    std::vector < myc > input;
    for (int i = 0; i < n; i++) {
        int a, b, c;
        fscanf(fin, "%d%d%d", &a, &b, &c);

        input.push_back({a, b, c});
    }

    std::sort(input.begin(), input.end());

    std::vector < bool > avem(h + w);
    for (int i = 0; i < h + w; i++)
        t[i] = i;

    long long ans = 0;
    for (auto &x : input) {
        int a = sef(x.l - 1), b = sef(x.c + h - 1);
        if (a != b && (avem[a] == 0 || avem[b] == 0)) {
            if (avem[b])
                avem[a] = 1;
            t[b] = a;
            ans += x.a;
        } else if (avem[a] == 0){
            avem[a] = 1;
            ans += x.a;
        }
    }

    fprintf(fout, "%lld\n", ans);

    fclose(fin);
    fclose(fout);
    return 0;
}


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;
//typedef tree<
//        pair<long long, int>, // change type
//        null_type,
//        less<pair<long long, int> >, // change type
//        rb_tree_tag,
//        tree_order_statistics_node_update>
//        ordered_set;

template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;


vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
        vector<string> __attribute__ ((unused)) args,
        __attribute__ ((unused)) int idx,
        __attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}

#ifdef LOCAL
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) ;
#endif


typedef long long ll;
typedef long double ld;
#define rep(i, start, end) for(int i = start; i < end; ++i)
#define sz(x) (int)((x).size())
#define pb push_back
#define all(x) x.begin(), x.end()
#define clr(d, v) memset(d, v, sizeof(d))
#define pii pair<int, int>
#define X first
#define Y second
//#define debug(x) cerr << #x << " : " << (x) << " "
const double PI = 3.14159265358979323846;
const double eps = (1e-9);

const int MAX_D = 64;
struct VectorSpace{
    vector<long long> basis;
    VectorSpace()
    {
        basis.resize(MAX_D);
    }
    void init()
    {
        fill(all(basis), 0);
    }
    bool insert(long long v, bool add)
    {
        for (int i = 0; i < MAX_D; ++i)
        {
            if ((1LL<<i)&v)
            {
                if (!basis[i])
                {
                    if (add)
                        basis[i] = v;
                    return true;
                }
                else
                    v ^= basis[i];
            }
        }
        return false;
    }
};

void myMain()
{
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,0,n)
        cin >> a[i];
    string s;
    cin >> s;
    VectorSpace space;
    for (int i = sz(s) - 1; i >= 0; --i)
    {
        if (s[i] == '1')
        {
            if (space.insert(a[i], false))
            {
                cout << 1 << '\n';
                return;
            }
        }
        else
            space.insert(a[i], true);
    }
    cout << 0 << '\n';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
//    freopen("AC.txt", "w", stdout);
#endif
    int tc;
    cin >> tc;
    while(tc--)
    {
        myMain();
        
    }

}

Measured memory_bytes: 3584
def c_sentou(N, T, time):
    time.append(float('inf'))  # 番兵
    ans = 0
    for i in range(N):
        ans += min(T, time[i + 1] - time[i])
    return ans

N,T = [int(i) for i in input().split()]
time = [int(i) for i in input().split()]
print(c_sentou(N, T, time))

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

int main() {
  int n; cin >> n;
  vector<ll> sum(sz), diff(sz);
  rep(i,n) {
    int a; cin >> a;
    if (i + a < sz) sum[i + a]++;
    if (i - a > 0) diff[i - a]++;
  }
  ll ans = 0;
  rep(i,sz) ans += sum[i] * diff[i];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6404
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
int main()
{
    int a, b, x = 1;
    cin >> a >> b;
    int ans = 0;
    while(1){
        if(b <= x) break;
        x += a-1;
        ans++;
    }
    cout << ans << endl;
    return 0;
}

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

vector<int> Z_algorithm(vector<int> &S){
	vector<int> A(S.size());
	A[0] = S.size();
	int i = 1, j = 0;
	while (i < S.size()) {
		while (i+j < S.size() && S[j] == S[i+j]) ++j;
		A[i] = j;
		if (j == 0) { ++i; continue;}
		int k = 1;
		while (i+k < S.size() && k+A[k] < j) A[i+k] = A[k], ++k;
		i += k; j -= k;
	}
	return A;
}

int main(){
	int N, i;
	scanf("%d", &N);
	vector<int> a(N), b(N);
	for(i = 0; i < N; i++){
		scanf("%d", &a[i]);
	}
	for(i = 0; i < N; i++){
		scanf("%d", &b[i]);
	}
	vector<int> c(N), d(N);
	for(i = 0; i < N; i++){
		c[i] = (a[i] ^ a[(i + 1) % N]);
		d[i] = (b[i] ^ b[(i + 1) % N]);
	}
/*	printf("c:");
	for(i = 0; i < N; i++){
		printf("%d ", c[i]);
	}
	printf("\n");
	printf("d:");
	for(i = 0; i < N; i++){
		printf("%d ", d[i]);
	}
	printf("\n");
*/	vector<int> cdd(3 * N);
	for(i = 0; i < N; i++){
		cdd[0 * N + i] = c[i];
		cdd[1 * N + i] = d[i];
		cdd[2 * N + i] = d[i];
	}
	vector<int> A = Z_algorithm(cdd);
/*	printf("cdd:");
	for(i = 0; i < 3 * N; i++){
		printf("%d ", cdd[i]);
	}
	printf("\n");
	printf("A  :");
	for(i = 0; i < 3 * N; i++){
		printf("%d ", A[i]);
	}
	printf("\n");
*/	for(i = 0; i < N; i++){
		if(A[2 * N - i] >= N){
			printf("%d %d\n", i, a[i] ^ b[0]);
		}
	}
	return 0;
}

Measured memory_bytes: 11264
/*
    Author : DemonStar
*/

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

#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update>
#define fast                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
#define ll long long
#define pi pair<int, int>
#define pl pair<long long, long long>
#define pld pair<long double, long double>
#define endl '\n'
#define loop(i, n) for (ll i = 0; i < n; i++)
#define rep(i, begin, end) for (__typeof(begin) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define all(x) x.begin(), x.end()
#define vl vector<ll>
#define vi vector<int>
#define ml map<ll, ll>
#define vpl vector<pair<ll, ll>>
const ll mod = 1e9 + 7;

template <typename T, typename TT>
ostream &operator<<(ostream &os, const pair<T, TT> &t)
{
    return os << t.first << " " << t.second;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &t)
{
    for (auto &i : t)
        os << i << " ";
    return os;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v)
{
    for (T &t : v)
        is >> t;
    return is;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, vector<pair<T1, T2>> &v)
{
    for (pair<T1, T2> &t : v)
        is >> t.first >> t.second;
    return is;
}

int main()
{
    fast;
    int n;
    cin >> n;
    vector<vi> v(n, vi(3));
    cin >> v;
    vector<vi> dp(3, vi(n + 1, 0));
    rep(i, 1, n + 1)
    {
        dp[0][i] = v[i - 1][0] + max(dp[1][i - 1], dp[2][i - 1]);
        dp[2][i] = v[i - 1][2] + max(dp[1][i - 1], dp[0][i - 1]);
        dp[1][i] = v[i - 1][1] + max(dp[0][i - 1], dp[2][i - 1]);
    }
    cout << max(dp[0][n], max(dp[1][n], dp[2][n])) << endl;

#ifdef LOCAL
    cerr
        << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif

    return 0;
}

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

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> ac(n), pena(n);
    for(int i=0; i<m; i++) {
        int p;
        string s;
        cin >> p >> s;
        --p;
        if(ac[p]) continue;
        if(s == "AC"){
            ac[p] = 1;
        } else{
            pena[p]++;
        }
    }
    int AC = 0, PENA = 0;
    for(int i = 0; i < n; i++){
        AC += ac[i];
        if(ac[i]) PENA += pena[i];
    }
    cout << AC << " " << PENA << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define sz(x) x.size()
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair



using namespace std;
typedef unsigned long long ull;
typedef vector<int>vi;
typedef pair<int,int> pii;
typedef map<int,int> mii;
typedef set<int> si;


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int h,w;
	string a[1000];
	vector<string>b;
	cin >> h >> w;
	for(int i=0;i<h;i++){
		cin >> a[i];
	}	
	vi v,vv;	
	string comp1,comp2;
	for(int i=0;i<w;i++){
		comp1 += '.';
	}
	for(int i=0;i<h;i++){
		comp2 += '.';
	}
	

	for(int i=0;i < h;i++){
		if(a[i] == comp1){
			v.pb(i);
		}
	}
	
	string q;
	for(int i=0;i<w;i++){
		for(int j=0;j<h;j++){
//			cout << a[j][i];
			q += a[j][i];
		}
		b.pb(q);
		q.clear();
	}
	for(int i=0;i<b.size();i++){
		if(b[i] == comp2){
			vv.pb(i);	
		}
	}
	
	
	for(int i=0;i<h;i++){
		bool xx = false;
		for(int j=0;j<w;j++){
			if(find(v.begin(),v.end(),i) == v.end() && find(all(vv),j) == vv.end()){
				cout << a[i][j];
				xx = true;
			}
		}
		if(xx)cout << endl;
	}
	return 0;
	
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>

using namespace std;
using lli = long long int;
// #define DEBUG
#ifdef DEBUG
#define debug(var) cout << (#var) << ": " << (var) << endl;
template<class T> void dump_array_impl(const T& a) {
  bool first = true;
  for (auto&& x : a) {
    if (!first) { cout << ", "; first = false; }
    cout << x;
  }
}
#define debug_array(a) cout<<(#a)<<": ";dump_array_impl(a);cout<<endl
#else
#define debug(var) {}
#define debug_array(a) {}
#endif
template<class T> void read_n(vector<T>& v, size_t n) {
  v = vector<T>(n);
  for (lli i=0; i<n; ++i) cin >> v[i];
}

vector<lli> factmem, factinvmem;
lli n, m, mod = 1e9 + 7;

lli fact(lli n) {
  if (factmem[n] == 0) factmem[n] = n * fact(n-1) % mod;
  return factmem[n];
}

lli modinv(lli a) {
  lli b = mod, u = 1, v = 0;
  while (b) {
    lli t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= mod;
  if (u < 0) u += mod;
  return u;
}

lli factinv(lli n) {
  if (factinvmem[n] == 0) factinvmem[n] = modinv(fact(n));
  return factinvmem[n];
}

lli conb(lli n, lli k) {
  return fact(n) * (factinv(k) * factinv(n - k) % mod) % mod;
}

int main() {
  factmem = vector<lli>(200000, 0);
  factinvmem = vector<lli>(200000, 0);
  factmem[0] = 1;

  cin >> n >> m;
  lli lim = sqrt((double)m);
  lli mm = m;
  lli ans = 1;
  for (lli i=2; i <= lim; ++i) {
    lli cnt = 0;
    while (mm % i == 0) {
      mm /= i;
      ++cnt;
    }
    if (cnt > 0) {
      ans = ans * conb(cnt + n - 1, n - 1) % mod;
    }
  }
  if (mm > 1) ans = ans * conb(1 + n - 1, n - 1) % mod;
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 6528
//#pragma GCC optimize("-O3")
/*
				C++
				encoding: UTF-8
				Last Modified: 01/Mar/20 05:39:00 PM
*/

#include <bits/stdc++.h>
#ifdef H4wk3ye
#	include <prettypr.hpp>
#endif

using namespace std;

// clang-format off

#define		int                    long long
#define		ve                     vector
#define		pb                     push_back
#define		endl                   "\n"
#define		ff                     first
#define		ss                     second
#define		pii                    pair<int, int>
#define		len(v)                 (int)v.size()
#define		all(v)                 v.begin(), v.end()
#define		reset(a, b)            memset(a, b, sizeof(a));
#define		fr(i, s, n)            for (int i = s ; i < n ; ++i)
#define		dfr(i, s, n)           for (int i = s ; i > n ; --i)

template < typename T > void pr (const T& t) {
    cout << t << "\n";
}

template < typename T, typename U, typename... ARGS >
void pr (const T& t, const U& u, const ARGS&... args) {
    cout << t << " ";
    pr (u, args...);
}

// clang-format on


signed main () {
	ios_base::sync_with_stdio (false), cin.tie (nullptr);
	int arr[3][3];
	fr (i, 0, 3) fr (j, 0, 3) cin >> arr[i][j];
	int n;
	cin >> n;
	fr (i, 0, n) {
		int k;
		cin >> k;
		fr (p, 0, 3) fr (q, 0, 3) if (arr[p][q] == k) arr[p][q] = -1;
	}
	bool flag = 0;
	fr (i, 0, 3) {
		if (arr[i][0] == -1 and arr[i][1] == -1 and arr[i][2] == -1) flag = 1;
	}
	fr (i, 0, 3) {
		if (arr[0][i] == -1 and arr[1][i] == -1 and arr[2][i] == -1) flag = 1;
	}

	if (arr[0][0] == -1 and arr[1][1] == -1 and arr[2][2] == -1) flag = 1;
	if (arr[0][2] == -1 and arr[1][1] == -1 and arr[2][0] == -1) flag = 1;
	pr (flag ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
 
int main(void){
  char S[5];
  scanf("%s",S);
  for(int i=0;i<3;i++){
    if(S[i]==S[i+1]){
      printf("Bad");
      break;
    }else if(i==2){
      printf("Good");
    }
  }
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0;i<n;i++)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (b>a) { 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; }
const long long INF = 2LL << 60;
using ll = long long;
using P = pair<ll, ll>;

int main(int argc, char const *argv[]) {
    int n, m;
    int cnt=0;
    cin >> n >> m;
    vector<int> a(n);
    rep(i,n){
        cin >> a.at(i);
        cnt+=a.at(i);
    }
    sort(a.rbegin(), a.rend());
    if(a.at(m-1)*(4*m)<cnt){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
from time import time
from random import random

limit_secs = 2
start_time = time()

D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]

def calc_score():
    score = 0
    S = 0
    last = [-1] * 26
    for d in range(D):
        S += s[d][t[d]]
        last[t[d]] = d
        for i in range(26):
            S -= c[i] * (d - last[i])
        score += max(10 ** 6 + S, 0)
    return score

def solution():
    return [i % 26 for i in range(D)]

t = solution()
score = calc_score()
while time() - start_time + 0.14 < limit_secs:
    d = int(random() * D)
    q = int(random() * 26)
    old = t[d]
    t[d] = q
    new_score = calc_score()
    if new_score < score:
        t[d] = old
    else:
        score = new_score
print('\n'.join(str(e + 1) for e in t))


Measured memory_bytes: 79076
import sys

while True:
	m, f, r = [ int( val ) for val in sys.stdin.readline().split( " " ) ]
	if -1 == m and -1 == f and -1 == r:
		break
	
	mf = ( m + f )
	if -1 == m or -1 == f:
		print( "F" )
	elif 80 <= mf:
		print( "A" )
	elif 65 <= mf and mf < 80:
		print( "B" )
	elif 50 <= mf and mf < 65:
		print( "C" )
	elif 30 <= mf and mf < 50:
		if 50 <= r:
			print( "C" )
		else:
			print( "D" )
	else:
		print( "F" )	

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(ll i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;
#define MAX_N 310

ll N;

list<char> S[MAX_N];

bool check() {
    vector<char> forComp[MAX_N];
    REP(i, N) {
        for(auto& val : S[i]) {
            forComp[i].push_back(val);
        }
    }
    REP(i, N) {
        REP(j, N) {
            if(forComp[i][j] != forComp[j][i]) { return false; }
        }
    }
    return true;
}
signed main()
{
    cin >> N;
    REP(i, N) {
        string s;
        cin >> s;
        REP(j, s.length()) {
            S[i].push_back(s[j]);
        }
    }
    ll cnt = 0;
    REP(i, N) {
        REP(j, N) {
            S[j].push_front(S[j].back());
            S[j].pop_back();
        }
        if(check()) { cnt++; }
    }
    // ベストかどうかの判定
    bool isBest = true;
    list<char> l = S[0];
    for(ll i = 1; i < N; ++i) {
        l.push_back(l.front());
        l.pop_front();
        vector<char> forComp;
        for(auto& val : l) { forComp.push_back(val); }
        ll j = 0;
        for(auto& val : S[i]) {
            if(forComp[j] != val) {
                isBest = false;
                break;
            }
            ++j;
        }
        if(!isBest) { break; }
    }
    if(isBest){
        printf("%lld\n", N * N);
    }
    else {
        printf("%lld\n", cnt * N);
    }
    return 0;
}


Measured memory_bytes: 3296
n, a, b = map(int, input().split())
ls = [int(input()) for _ in range(n)]
m = max(ls)
lo = (m + a - 1) // a
hi = (m + b - 1) // b + 1
mi = (hi + lo) // 2
while hi > lo + 1:
    mi = (hi + lo) // 2
    if sum([(x - mi * b + a - b - 1) // (a - b)
            for x in ls if x - mi * b > 0]) <= mi:
        hi = mi
    else:
        lo = mi
if sum([(x - lo * b + a - b - 1) // (a - b)
        for x in ls if x - lo * b > 0]) <= lo:
    print(lo)
else:
    print(hi)

Measured memory_bytes: 11020
#include<stdio.h>
#include<stdlib.h>

typedef struct bridge_t {
    int a;
    int b;
} bridge;

int comp(const void *a, const void *b)
{
    return ((bridge*)a)->a - ((bridge*)b)->a;
}

int main()
{
    int n,m;
    int i;
    int mb;
    int cnt;
    bridge b[1<<17];
    scanf("%d%d", &n,&m);
    for(i=0;i<m;i++)scanf("%d%d",&(b[i].a),&(b[i].b));
    qsort(b,m,sizeof(bridge),comp);
    cnt = 0;
    mb = 0;
    for(i=0;i<m;i++){
        if(b[i].a>=mb)mb=b[i].b,cnt++;
        if(b[i].b<mb)mb=b[i].b;
    }
    printf("%d\n",cnt);
    return 0;
}



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

using namespace std; 
#define reps(i, a, b) for(int i = a; i < b; i++)
#define rep(i, a) reps(i, 0, a)

int main()
{
	int a, ma = 0, su = 0;
	rep(i, 3) {
		cin >> a;
		su += a;
		ma = max(a, ma);
	}
	int k;
	cin >> k;
	cout << su - ma + (1 << k) * ma << endl;
    return 0;
}


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

using namespace std;
typedef long long ll;

const int N = 1010;
const ll MOD = 1e9 + 7;
char a[N][N];
int h, w;
ll dp[N][N];

int main() {
	ios_base::sync_with_stdio(false);

	cin >> h >> w;
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			cin >> a[i][j];
		}
	}
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			if (i == 1 && j == 1)
				dp[i][j] = 1;
			else {
				if (i - 1 > 0 && a[i - 1][j] == '.')
					dp[i][j] = (dp[i][j] + dp[i - 1][j]) % MOD;
				if (j - 1 > 0 && a[i][j - 1] == '.')
					dp[i][j] = (dp[i][j] + dp[i][j - 1]) % MOD;
			}
		}
	}
	cout << dp[h][w];

	return 0;
}

Measured memory_bytes: 9216
fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(& mut buf).ok();
    let s = buf.trim();
    //println!("{}", s);
    let mut v: Vec<char> = s.chars().collect();
    //println!{"pre len {}", v.len()};
    for i in &mut v {
        if *i == '1' {*i = '9';}
        else if *i == '9' {*i = '1';}
        //println!("{}", *i);
    }
    //println!{"aft len {}", v.len()};
    println!{"{}{}{}", v[0], v[1], v[2]};
}


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

int main() {
	int n, k; cin >> n >> k;
	int d, tmp;
	set<int> s;
	for(int i = 0; i < k; i++) {
		cin >> d;
		for(int j = 0; j < d; j++) {
			cin >> tmp;
			s.insert(tmp);
		}
	}
	cout << (n - int(s.size())) << endl;
	return 0;
}


Measured memory_bytes: 3632
#binary search
import bisect

if __name__ == '__main__':

	input()
	A = list(map(int,input().split()))
	n = int(input())

	for _ in range(n):
		x = int(input())
		
		bi_l = bisect.bisect_left(A,x)
		bi_r = bisect.bisect_right(A,x)
		print(bi_l,bi_r)




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

using namespace std;

typedef long long int64;
const int mod = 1e9 + 7;

inline int64 modPow(int64 x, int64 n)
{
  if(n == 0) return (1);
  int64 ret = modPow(x, n / 2);
  (ret *= ret) %= mod;
  if(n & 1) (ret *= x) %= mod;
  return (ret);
}

inline int64 modInv(int64 a)
{
  return (modPow(a, mod - 2));
}

inline int64 modCombination(int p, int q)
{
  static int64 fact[302020], rfact[302020];
  if(fact[0] == 0) {
    fact[0] = rfact[0] = 1;
    for(int i = 1; i < 302020; i++) {
      fact[i] = fact[i - 1] * i % mod;
      rfact[i] = modInv(fact[i]);
    }
  }
  if(q < 0 || p < q) return (0);
  return (fact[p] * rfact[q] % mod * rfact[p - q] % mod);
}

void solve()
{
  int N, A[100010];
  cin >> N;
  ++N;
  for(int i = 0; i < N; i++) cin >> A[i], --A[i];

  int appear[100010] = {};
  for(int i = 0; i < N; i++) {
    appear[A[i]]++;
  }
  vector< int > st;
  for(int i = 0; i < N; i++) {
    if(appear[A[i]] > 1) st.emplace_back(i);
  }
  int left = st[0], right = N - st[1] - 1;
  int sub[100010] = {};
  for(int i = 2; i <= N; i++) {
    sub[i - 1] += modCombination(right + left, i - 1);
  }
  sub[0]++;
  for(int i = 1; i <= N; i++) {
    cout << (modCombination(N, i) + mod - sub[i - 1]) % mod << endl;
  }
}

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

Measured memory_bytes: 7168
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        long X = scan.nextLong();
        long answer = 0;
        for (long i = 1; i <= 100000; i++) {
            if (X <= i * (i+1) / 2) {
                answer = i;
                break;
            }
        }
        System.out.println(answer);
    }
}


Measured memory_bytes: 25300
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

#define fs first
#define sc second

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

    if(N >= 10) {
        cout << R << endl;
    } else {
        cout << R + 100 * (10 - N) << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <functional>
#include <map>
#include <array>
#include <cmath>

long long PRIME = 1e9 + 7;
using namespace std;


int main(){ 
    long long N;
    cin >> N;
    string S, T;

    cin >> S >> T;

    for(int i = 0; i < S.size(); ++i){
        cout << S[i] << T[i];
    }



}



Measured memory_bytes: 256
#include<stdio.h>
int main()
{
int a,b,c,f=0,i,g=0;
scanf("%d%d%d",&a,&b,&c);
while(f==0)
{
if((g>=c)||(b<a))
 f=1;
else
 {
  b=b-a;
  g++;
 }
}
printf("%d",g);
return 0;
}

Measured memory_bytes: 128
using System;

class AGC001A
{
	static public void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		int[] L = new int[2*N];
		string[] vals = Console.ReadLine().Split(' ');
		for(int i=0; i < 2*N; i++)
		{
			L[i] = int.Parse(vals[i]);
		}
		Array.Sort(L);
		
		int sum = 0;
		for(int i = 0; i < 2*N; i+=2)
		{
			sum += L[i];
		}

		Console.WriteLine(sum);
	}
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

ll N, K;

ll fact(ll n){
    if(n ==1) return 1;
    if(n == 0) return 1;

    return (n * fact(n-1)) % MOD;
}

const int MAX = 1000000;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

vector<bool> seen;  // 訪問済みの点
ll ans = 1;

// BFSのための再帰関数
void dfs(const Graph &G, int v, int counter) {
    seen[v] = true;
    // dist[v] = counter;

    ll child = G[v].size();
    // cout << v << " " << child << endl;

    if(counter == 0){
        ans *= COM(K-1, child);
        ans = ans % MOD;
        ans *= fact(child);
        ans = ans % MOD;
    }
    else{
        ans *= COM(K-2, child-1);
        ans = ans % MOD;
        ans *= fact(child-1);
        ans = ans % MOD;
    }
    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue;
        dfs(G, next_v, counter+1); // 再帰的に値を追加していく
    }
}

int main()
{
    cout << fixed << setprecision(15);
    cin >> N >> K;

    // 前処理
    COMinit();

    // REP(i, K){
    //     cout << (COM(N-K+1, i+1) % MOD * COM(K-1, i) % MOD)% MOD << endl;
    // }

    // グラフ
    Graph G(N);
    seen.assign(N, false);

    REP(i, N-1){
        int a, b;
        cin >> a >> b;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
    }

    dfs(G, 0, 0);

    ans *= K;
    cout << ans % MOD << endl;

    return 0;
}

Measured memory_bytes: 32640
using System;
using System.Linq;

namespace AtCoder
{
	class MainClass
	{

		public static void Main (string[] args)
		{
			var line = Console.ReadLine ().Split (' ');
			var a = int.Parse (line[0]);
			var b = int.Parse (line[1]);

			if (b % a == 0) {
				Console.WriteLine ("{0}", a + b);
			} else {
				Console.WriteLine ("{0}", b - a);
			}
		}

	}
}


Measured memory_bytes: 13140
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

constexpr int MOD = 1e9+7;

unsigned int msb( unsigned int v )
{
  v = v | (v >>  1);
  v = v | (v >>  2);
  v = v | (v >>  4);
  v = v | (v >>  8);
  v = v | (v >> 16);
  v = (v & 0x55555555) + (v >>  1 & 0x55555555);
  v = (v & 0x33333333) + (v >>  2 & 0x33333333);
  v = (v & 0x0f0f0f0f) + (v >>  4 & 0x0f0f0f0f);
  v = (v & 0x00ff00ff) + (v >>  8 & 0x00ff00ff);
  v = (v & 0x0000ffff) + (v >> 16 & 0x0000ffff);
  return v;
}

void make(vc<vc<int>> &a, int lv, int fs){
    For(i, 1 << (lv-1)) For(j, 1 << (lv-1)){
        a[fs + i][fs + (1 << (lv-1)) + j] = lv;
    }
}

int main(void){
    Cin(int, n);
    int ub = msb(n-1);
    vc<vc<int>> a(1 << ub, vc<int>(1 << ub, 0));

    for(int lv = 1; lv <= ub; lv ++){
        For(i, 1 << (ub-lv)) make(a, lv, (1 << lv)*i);
    }
    // For(i, 1 << ub) Couts(a[i]);
    
    For(i, n){
        for(int j = i+1; j < n; j ++){
            cout << a[i][j] << " ";
        }
        cout << endl;
    }
}




Measured memory_bytes: 1536
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <limits.h>
#include <cmath>
#include <map>
#include <utility>
using namespace std;
using P = pair<int,int>;
using ll = long long;
const int MOD=1e9+7;
int main(){
    int n,m,k;
    cin>>n>>m>>k;
    vector<ll> a(n+1,0),b(m+1,0);
    for(int i=1;i<=n;i++){
        cin>>a[i];
        a[i]=a[i]+a[i-1];
    }
    for(int i=1;i<=m;i++){
        cin>>b[i];
        b[i]=b[i]+b[i-1];
    }
    int ret=0;
    for(int i=0;i<=n;i++){
        if(k<a[i])continue;
        ret=max(ret,(int)(upper_bound(b.begin(),b.end(),(ll)k-a[i])-b.begin()+i-1));
    }
    cout<<ret<<endl;
}

Measured memory_bytes: 6428
int(input())
l=[int(x) for x in input().split()]
arr={}
for i in l:
	if not arr.get(i):
		arr[i]=1
	else:
		arr[i]+=1
max1=0
max2=-1
sqr=0
for i in arr:
	if arr[i]>=2:
		if i > max1:
			max1=i
		if arr[i]>=4:
			sol=i**2
			if sqr < sol :
				sqr=sol
for i in arr:
	if arr[i]>=2:
		if i > max2 and i < max1:
			max2=i

rec=max1 * max2
if rec > sqr:
	print(rec)
else:
	print(sqr)
					

Measured memory_bytes: 17960
#include <iostream>
#include <string>
#include <algorithm>
#include <map>

using namespace std;

string S;


int main(void) {

	int A, B, X[11];
	
	cin >> A >> B >> X[0];

	for (int i = 1; i < 11; i++) {
		X[i] = A * X[i - 1] - B;
		printf("%d", X[i]);
		if (i < 10) {
			printf("\n");
		}
	}

	

	return 0;
}

Measured memory_bytes: 256
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>  // https://boostjp.github.io/tips/math.html
#include <boost/dynamic_bitset.hpp>  // https://boostjp.github.io/tips/dynamic_bitset.html

constexpr int64_t DIV1097 = 1000000007LL;

using namespace std;

int main()
{
    std::string S, T;
    std::cin >> S;
    std::cin >> T;

    std::vector<int64_t> SC(26);
    std::vector<int64_t> TC(26);

    for (size_t i = 0; i < S.size(); ++i) {
        SC[S[i]-'a']++;
        TC[T[i]-'a']++;
    }

    std::sort(std::begin(SC), std::end(SC));
    std::sort(std::begin(TC), std::end(TC));

    for (size_t i = 0; i < SC.size(); ++i) {
        if (SC[i] != TC[i]) {
            std::cout << "No" << std::endl;
            return 0;
        }
    }

    std::cout << "Yes" << std::endl;

    return 0;
}


Measured memory_bytes: 776
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

alias Point = Tuple!(int, "x", int, "y", int, "c");

void main() {
    int n;
    scan(n);
    auto ps = new Point[](2*n);
    foreach (i ; 0 .. 2*n) {
        int ai, bi;
        scan(ai, bi);
        ps[i] = Point(ai, bi, (i < n ? 0 : 1));
    }
    ps.sort!"a.x < b.x"();

    int ans;
    auto cnt = new int[](2*n + 1);
    foreach (i ; 0 .. 2*n) {
        if (ps[i].c == 0) {
            cnt[ps[i].y]++;
        }
        else {
            foreach_reverse (h ; 0 .. ps[i].y) {
                if (cnt[h] > 0) {
                    cnt[h]--;
                    ans++;
                    break;
                }
            }
        }
    }
    writeln(ans);
}
































void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 256
from __future__ import print_function
# import numpy as np
# import numpypy as np
import sys
import math
import string
import fractions
import re
import array
import copy
import functools
import operator

import collections
import itertools
import bisect
import heapq


from heapq import heappush
from heapq import heappop

# from itertools import accumulate
# from collections import deque
import random




def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)


def main():
    n,m = map(int, input().split())
    # g =[[] for i in range(m+1)]
    # for i in range(1,m+1):          # mコのgateを作る
    #     g[i]=[0 for i in range(100001)]
    left=-100000
    right=sys.maxsize
    for i in range(m):
        t1,t2 = map(int, input().split())
        # eprint(t1)
        # eprint(t2)
        if left<t1:
            # eprint(left)
            # eprint(t1)
            left =t1
        if t2<right:
            right = t2
        # eprint("left: "+str(left) + "   right: "+str(right) + "   n: "+str(n))

    if right<left or n<left:
        print(0)
    else :                      # 少なくともleft<right
        if n<right:
            print(n+1 - left)
        else:                    #
            print(right+1 - left)
        
            
        
            
        
        

if __name__ == '__main__':
    main()


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

int main() {
	// your code goes here
	long N,M,K;
	cin >> N >> M >>K;
	int flag=0;
	for(int k=0; k<=M; k++){
		for(int l=0; l<=N; l++){
			if(N*k+M*l-2*k*l==K)flag=1;
		}
	}
	if(flag==0){cout<<"No"<<endl;}
	if(flag==1){cout<<"Yes"<<endl;}
	return 0;
}

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

int main(){
    
    int in;
    int num = 1;
    while(1){
        
        cin >> in;
        
        if(in == 0){
            break;
        }
        
        cout << "Case " << num << ": " << in << endl;
        
        num++;
    }
    
    
    return 0;
    
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#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)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m , n) for(int i = (n);i >=(m);--i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define VSCD(v,N) REP(i,N){int (x); SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long (x); SCLLD(x); v.PB(x);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x,y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int,int> PII;
typedef pair<long long,long long> PLL;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1000000007;
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

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

int main(){
	int N,M;
    SCD2(N,M);
    vector<ll> X;
    REP(i,M){
        int x;
        SCD(x);
        X.PB(x);
    }
    sort(ALL(X));
    vector<ll> Y;
    REP(i,M-1){
        Y.PB(X[i+1] - X[i]);
    }

    ll sum = 0;
    sort(ALL(Y));
    REP(i,M-1-(N-1)){
        sum += Y[i];
    }

    if (N >= M) PRINTD(0);
    else PRINTLLD(sum);
}

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

vector<char> fronts, backs;
char temp;
string S;
int Q;
bool reversed = false;

int main(void) {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	cin >> S >> Q;
	int T, F;
	for (int i = 0; i < Q; i++) {
		cin >> T;
		if (T == 1) {
			// reverse
			if (reversed == true)
				reversed = false;
			else
				reversed = true;
		}
		else {
			cin >> F;
			if (F == 1) {
				if (reversed == false) {
					// add front
					cin >> temp;
					fronts.push_back(temp);
				}
				else {
					// add end
					cin >> temp;
					backs.push_back(temp);
				}
			}
			else {
				if (reversed == false) {
					// add end
					cin >> temp;
					backs.push_back(temp);
				}
				else {
					// add front
					cin >> temp;
					fronts.push_back(temp);
				}
			}
		}
	}

	if (reversed == true) {
		for (int i = backs.size() - 1; i > -1; i--)
			cout << backs[i];

		for (int i = S.size() - 1; i > -1; i--)
			cout << S[i];

		for (int i = 0; i < fronts.size(); i++)
			cout << fronts[i];
	}
	else {
		for (int i = fronts.size() - 1; i > -1; i--)
			cout << fronts[i];

		for (int i = 0; i < S.size(); i++) {
			cout << S[i];
		}

		for (int i = 0; i < backs.size(); i++)
			cout << backs[i];
	}

	return 0;
}

Measured memory_bytes: 976
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int a,i,b=0,c=0,d=0,j;
    cin>>a;
        for(i=-200;i<200;i++)
        {
            for(j=-200 ; j<200;j++)
            {
                b=i*i*i*i*i;
                c=j*j*j*j*j;
                if(b-c==a)
                {
                    cout<<i<<" "<<j<<endl;
                    d=1;
                }
            }
            if(d==1)
                break;
        }


}

Measured memory_bytes: 3604
#[allow(unused_macros)]
macro_rules! input {
    ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } };
    ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ( $ next : expr ) => { };
    ( $ next : expr , ) => { };
    ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } };
}
#[allow(unused_macros)]
macro_rules! read_value {
    ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) };
    ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) };
    ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) };
    ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 };
    ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) };
}

fn main() {
    input! {
        n: usize,
        s: [chars; n]
    }
    let mut hmap = std::collections::HashMap::<char, u64>::new();
    for i in 0..n {
        *hmap.entry(s[i][0]).or_insert(0) += 1;
    }

    let mut cnt = 0u64;
    let march = "MARCH".chars() .collect::<Vec<_>>();
    for subset in enum_fixed_size_subsets(&march, 3) {
        let (c1, c2, c3) = (subset[0], subset[1], subset[2]);
        cnt += *hmap.get(&c1).unwrap_or(&0)
            * (*hmap.get(&c2).unwrap_or(&0))
            * (*hmap.get(&c3).unwrap_or(&0));
    }
    println!("{}", cnt);
}

#[allow(dead_code)]
pub fn bit_filter<T: Clone>(b: usize, v: &[T]) -> Vec<T> {
    let mut ret = vec![];
    for i in 0..v.len() {
        if (b >> i) & 1 == 1 {
            ret.push(v[i].clone());
        }
    }
    ret
}
#[allow(dead_code)]
pub fn enum_fixed_size_subsets<T: Clone>(v: &[T], k: usize) -> Vec<Vec<T>> {
    let mut ret = vec![];
    let mut comb = (1 << k) - 1;
    while comb < 1 << v.len() {
        ret.push(bit_filter(comb, v));
        let x = (comb as i64 & -(comb as i64)) as usize;
        let y = comb + x;
        comb = ((comb & !y) / x >> 1) | y;
    }
    ret
}

Measured memory_bytes: 12540
#include <iostream>
#include <string>
#include <bitset>
  
class Baseball{
    u_int score, out_count;
    std::bitset<4> runners; 
public:
    Baseball() : score(), out_count(){} //initializer list
    ~Baseball() = default;
    void hit();
    void homerun();
    void out() {++out_count;}
    u_int getScore() {return score;}
    u_int getOutcount() {return out_count;}
};
 
void Baseball::hit(){
    runners <<= 1; //shift
	runners.set(0); //set runner
    if(runners.test(3)){
        ++score;
        runners.reset(3);
    }
}
 
void Baseball::homerun(){
    score += runners.count() + 1;
    runners.reset();
}
 
int main(){
    u_int inning;
    std::cin >> inning;
    for(u_int i = 0; i < inning; ++i){
        Baseball game;
        while(game.getOutcount() != 3){
            std::string event;
            std::cin >> event;
            if(event == "HIT"){
                game.hit();
            }
            else if(event == "HOMERUN"){
                game.homerun();
            }
            else if(event == "OUT"){
                game.out();
            }
        }
        std::cout << game.getScore() << std::endl;
    }
    return 0;
}

Measured memory_bytes: 3004
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	int len=s.size();
	int cnt=0;
	string ss="";
	string sss="";
	for(int i=0;i<len;i++){
		sss=sss+s[i];
		if(sss!=ss){
			cnt++;
			ss=sss;
			sss="";
		}
	}
	cout<<cnt<<endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define REP(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

#define ALL(x) (x).begin(),(x).end()
typedef long long ll;

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev

int main(){
  int K,N;
  cin >> K >> N;
  int A[N];
  REP(i,N) cin >> A[i];

  int maxlen = 0;
  REP(i,N-1){
    maxlen = max(maxlen, A[i+1] - A[i]);
  }
  maxlen = max(maxlen, K - (A[N-1] - A[0]));
  cout << K - maxlen << endl;

  return 0;
}

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

#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define RSORT(a) sort((a).rbegin(),(a).rend())
#define ll long long
#define pb(a) push_back(a)

#define PRINTV(v) {for(ll deB=0; deB<(v).size(); deB++){cout << (v)[deB] << " ";}cout << endl;}

int main(){
	
	
	ll N;
	vector<ll> check(1000001,0);
	vector<ll> memo(1000001,0);
	cin >> N;
	vector<ll> A(N,0);
	REP(i,N) cin >> A[i];

	REP(i,N){
		memo[A[i]] ++;
		if(memo[A[i]] > 1) continue;
		for(int j=A[i]+A[i]; j<=1000000; j+=A[i]){
			check[j] = 1;
		}
	}
	ll ret = 0;
	REP(i,N){
		if(check[A[i]] == 0 && memo[A[i]] == 1) ret++;
	}
	cout << ret << endl;
	
	return 0;
}

Measured memory_bytes: 20428