akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);i++)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;i>=(int)(m);i--)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
//constexpr long long MOD = (ll) 1e9 + 7;
constexpr long long MOD = 998244353LL;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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;
}

struct Edge {
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
	to = _to; cap = _cap; rev = _rev;
	}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}


void solve(){
    ll n,m;
    cin>>n>>m;
    ll sum=0;
    REP(i,m){
        ll a;
        cin>>a;
        sum+=a;
    }
    cout<<max(n-sum,-1LL)<<en;
}

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

    solve();
    //ll t;cin>>t;REP(i,t) solve();

    return 0;
}


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

using namespace std;
vector<int> v[15];
int n,m;
int sh[15];
int check[15];
int bigcont;
int f ;

bool checkf(){
    for (int i = 1 ; i <= m ; i++){
            int cont = 0;
            for (int j = 0 ; j < v[i].size(); j++){
                if (check[v[i][j]-1])cont++;
            }
            if (cont%2 != sh[i])return 0;

    }

    return 1;

}





int main()
{



    cin>>n>>m;

    for (int i = 1 ; i <= m ; i++){
        int k;
        cin>>k;
        for (int j = 0 ; j < k ; j++){
            int z;
            cin>>z;
            v[i].push_back(z);
        }
    }
    for (int i = 1 ; i <= m ; i++)cin>>sh[i];

    for (int i = 0 ; i < pow(2,n) ; i++){

        for (int j = 0 ; j < n ; j++){
            if (i & (1<<j))check[j] = 1;
            else check[j] = 0;
        }


    bigcont+=checkf();

    }




    cout<<bigcont<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int a,min,max,p,mmax=0,mm,i,b;
    while(1){
        mmax=0;
        cin>>a>>min>>max;
        if(a==min && min==max && a==0) break;
        for(i=0;i<a;i++){
            cin>>p;
            if(i>=min && i<max+1){
                if(mm-p>=mmax) {
                    mmax=mm-p;
                    b=i;
                //  cout<<mm<<" "<<p<<" "<<mmax<<endl;
                }
            }
            mm=p;
        }
        cout<<b<<endl;
    }
    return 0;
}

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

int main() {
  struct Range {int l, r;};
  int N, M, O;
  cin >> N >> M >> O;
  vector<Range> E(M);
  for(auto& i: E) cin >> i.l >> i.r;
  vector<Range> Q(O);
  for(auto& i: Q) cin >> i.l >> i.r;

  vector<vector<long long>> dp(N+1, vector<long long>(N+1));
  auto sum = [&](auto i1, auto j1, auto i2, auto j2) {return dp[i2][j2] - dp[i2][j1-1] - dp[i1-1][j2] + dp[i1-1][j1-1];};
  for(auto& i: E) ++dp[i.l][i.r];
  for(auto i=1; i<=N; ++i) for(auto j=1; j<=N; ++j) dp[i][j] += dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1];

  for(auto& q: Q) cout << sum(q.l, max(1,q.r-(q.r-q.l)), min(N,q.l+(q.r-q.l)), q.r) << endl;
}


Measured memory_bytes: 5248
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <functional>
#include <cstring>

using namespace std;

typedef pair<int, int> P;
#define mp make_pair
#define FOR(i, a, b) for(int (i)=a;(i)<(b);++(i))
#define rep(i, n)  FOR(i,0,n)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort((v).begin(), (v).end());					//小さい順
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());		//大きい順
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define all(c) (c).begin(),(c).end()
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define Print(p) cout<<(p)<<endl
#define F first
#define S second
#define pb push_back
#define mod 1000000007LL
#define INF 1234567890

const int maxn = 2e5 + 10;


//initialization here
//

int idx[100005];

//
//initialization finish


// your function is here
//

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


//
// your function finished



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

	// your code is here
	//
	int n; cin >> n;

	if (n % 2 == 0)rep(i, n / 2)idx[1 + 2 * i] = 2;
	else
	{
		rep(i, (n + 1) / 2) idx[i * 2] = 2;
		idx[0] = 1;
	}

	int a;
	rep(i, n)
	{
		cin >> a;
		idx[a]--;
		if (idx[a] < 0)
		{
			Print(0);
			return 0;
		}
	}
	
	Print(beki(2, n/2));

	//
	// your code finished

	return 0;
}

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


int main(){
    char str[4];
    char tex[4];
    int r=0;

    scanf("%s %s",str,tex);

    for(int i=0;i<3;i++){
        if(str[i]==tex[i]){
            r++;
        }
    }
    printf("%d\n",r);

    return 0;
}

Measured memory_bytes: 128
/*--------------------------------------------------------
テ」ツδ敕」ツδォテ」ツδウテ」ツつャテ」ツ?ョテ」ツつイテ」ツδシテ」ツδ?・ツョツ淌ヲツウツ?
  https://www.youtube.com/user/oXpolungaXo

テッツシツ榲ッツシツ榲」ツδ?」ツδ」テ」ツδウテ」ツδ催」ツδォテァツ卍サテゥツ個イテ」ツ?甘ゥツ。ツ佚」ツ??」ツ?療」ツ?セテ」ツ?凖ッツシツ?ッツシツ?ッツシツ愿ッツシツ?
  --------------------------------------------------------*/


#include<bits/stdc++.h>
using namespace std;
int memo[61][2];
int main(){
  int A,B,C;
  cin >> A >> B >> C;
  int time = 0,ok=1;
  int res = 0;
  bool f = false;
  while( !memo[time][ok] ){
    memo[time][ok] = 1;   
    for(int i=1;i<=60;i++){
      time++;
      //      cout << time << " " << ok << endl;
      if( ok == 1 ) {
        if( C == i ) {
          res += i;
          f = true; break;
        }            
        if( time == A ) {
          time = 0; ok = 0;
        }
      } else if( time == B ){
        time = 0; ok = 1;
      }                  
    }
    if( f ) break;
    res += 60;
  }
  if( f ) cout << res << endl;
  else cout << -1 << endl;
}

Measured memory_bytes: 1164
#include <stdio.h>

long long fib_memo[44]={};
long long fib(int n)
{
    if(n==0 || n==1) return 1;
    fib_memo[0]=1; fib_memo[1]=1;
    
    if(fib_memo[n]==0)
    {
        fib_memo[n]=fib(n-1)+fib(n-2);
    }
    
    return fib_memo[n];
}

int main(void)
{
    int n;
    scanf("%d",&n);
    printf("%lld\n",fib(n));
    
    return 0;
}



Measured memory_bytes: 2104
import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void log(A...)(A arg) {
    stderr.writeln(arg);
}
int size(T)(in T s) {
    return cast(int)s.length;
}

// graph for bridge finding
class Edge {
    int from, to;
    this(int from, int to) {
        this.from = from;
        this.to = to;
    }
    override string toString() {
        return [from, to].to!string;
    }
}
class Graph {
    Edge[][] G;
    int V;
    this(int V) {
        this.V = V;
        G = new Edge[][V];
    }
    void addEdge(int from, int to) {
        G[from] ~= new Edge(from, to);
        G[to] ~= new Edge(to, from);
    }
    Tuple!(int, int)[] findBridges() {
        auto dfs_order = new int[V];
        auto lowlink = new int[V];
        dfs_order[] = -1;
        int c = 0;
        Tuple!(int, int)[] bridges;
        void dfs(int v, int prev) {
            dfs_order[v] = c++;
            lowlink[v] = dfs_order[v];
            foreach (e; G[v]) {
                auto next = e.to;
                if (next == prev) continue;
                if (dfs_order[next] >= 0) { 
                    // already visited. this 'e' is backedge.
                    lowlink[v] = min(lowlink[v], dfs_order[next]);
                } else {
                    dfs(next, v);
                    lowlink[v] = min(lowlink[v], lowlink[next]);
                }
                if (dfs_order[v] < lowlink[next]) {
                    auto l = min(v, next);
                    auto g = max(v, next);
                    bridges ~= Tuple!(int, int)(l, g);
                }
            }
        }
        dfs(0, -1);
        return bridges;
    }
}

void main() {
    int V, E; scanf("%d %d\n", &V, &E);
    auto graph = new Graph(V);
    foreach (i; 0 .. E) {
        int s, t; scanf("%d %d\n", &s, &t);
        graph.addEdge(s, t);
    }
    auto ans = graph.findBridges();
    ans.sort;
    foreach (a; ans) {
        writefln("%d %d", a[0], a[1]);
    }
}

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


int N,Ma,Mb;
const int inf = 1000000;

int A[40], B[40], C[40];
int dp[41][410][410];


int solve(){
	int ans = inf;
	for(int i=0; i<N+1; i++){
		for(int a=0; a<=N*10; a++){
			for(int b=0; b<=N*10; b++){
				dp[i][a][b] = inf;
			}
		}
	}
	dp[0][0][0] = 0;

	for(int i=1; i<N+1; i++){
		for(int a=0; a<=10*N; a++){
			for(int b=0; b<=10*N; b++){
				if(dp[i-1][a][b] == inf) continue;
				dp[i][a][b] = min(dp[i][a][b], dp[i-1][a][b]);
				dp[i][a+A[i-1]][b+B[i-1]] = min(dp[i][a+A[i-1]][b+B[i-1]] ,dp[i-1][a][b]+C[i-1]);
			}
		}
	}

	for(int n=1; n*Ma<=10*N && n*Mb<=10*N; n++){
		ans = min(ans, dp[N][n*Ma][n*Mb]);
	}

	if(ans >= inf) cout << -1 << endl;
	else cout << ans << endl;
	return 0;
}



int main(){
	cin >> N >> Ma >> Mb;
	for(int i=0;i<N;i++){
		cin >> A[i] >> B[i] >> C[i];
	}
	solve();
	return 0;
}

Measured memory_bytes: 27136
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod= 1e+9+7;

int main(){
    int n,x,y; cin>>n>>x>>y;
    vector<int>ans(n-1,0);
    Graph G(n);
    for(int i=0;i<n-1;i++){
        G[i].push_back(i+1);
        G[i+1].push_back(i);
    }
    G[x-1].push_back(y-1);
    G[y-1].push_back(x-1);
 
    for(int i=0;i<n;i++){
   vector<int>dist(n,-1);
   queue<int>q;
   dist[i]=0;
   q.push(i);
   while(!q.empty()){
       int v=q.front();
       q.pop();
       for(auto nv:G[v]){
       if(dist[nv]!=-1)continue;
       dist[nv]=dist[v]+1;
       ans[dist[nv]-1]++;
       q.push(nv);
       }
   }
    
    }
    rep(i,n-1){
      
        cout<<ans[i]/2<<endl;
    }
    
}





Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF (1 << 30) - 1
#define LLINF (1LL << 61) - 1
// #define int ll
using namespace std;
const int MOD = 1000000007;
const int MAX = 510000;

struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    
    int find(int x) {
        if (par[x] < 0) return x;
        else return par[x] = find(par[x]);
    }
    
    bool same(int x, int y) {
        return find(x) == find(y);
    }
    
    bool unite(int x, int y) {
        x = find(x); y = find(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[find(x)];
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,Q;
    cin >>N>>Q;
    int P[200010],A[200010],B[200010];
    rep(i,Q) cin >>P[i]>>A[i]>>B[i];
    UnionFind uf(N);
    rep(i,Q){
        if(P[i] ==0){
            uf.unite(A[i],B[i]);
        }
        else{
            if(uf.same(A[i],B[i])) cout <<1<<endl;
            else cout <<0<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 4320
# coding=utf-8

N, Q = map(int, input().split())
S = [[] for i in range(N)]

for j in range(Q):
    query = list(map(int, input().split()))
    if query[0] == 0:
        S[query[1]].append(query[2])
    elif query[0] == 1:
        if S[query[1]]:
            print(S[query[1]][-1])
    elif query[0] == 2:
        if S[query[1]]:
            S[query[1]].pop()



Measured memory_bytes: 13708
#include<bits/stdc++.h>
using namespace std;
bool et(vector<long long> &v,long long A,long long B,long long T)
{
	long long bt=0;
	for(int i=0;i<v.size();i++)
	{
		long long tmp=max((long long)0,(v[i]-B*T));
            bt+=(tmp+(A-B)-1)/(A-B);
		
	}

	

	if(bt<=T)
	{
		return true;
	}
	else
	{
		return false;
	}
}
main()
{
	long long N,A,B;
	cin>>N>>A>>B;
	vector<long long> v(N);
	long long mt=-1;
	for(int i=0;i<N;i++)
		{cin>>v[i];
			mt=max(mt,v[i]);
		}

	long long l= 0;
	long long r= mt/B;
	r+=1;
	while((r-l)>1)
	{
		long long mid=(l+r)/2;
		if(et(v,A,B,mid))
		{
			r=mid;
		}
		else
		{
			l=mid;
		}
	}

	cout<<r<<"\n";

}

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


int MOD=1000000007;
int main(void){
	string S;
	cin >> S;
	if(S=="SUN") cout << 7 << endl;
	if(S=="SAT") cout << 1 << endl;
	if(S=="FRI") cout << 2 << endl;
	if(S=="THU") cout << 3 << endl;
	if(S=="WED")
		cout << 4 << endl;
		if(S=="TUE")
			cout << 5 << endl;
			if(S=="MON")
				cout << 6 << endl;
}


Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A, B, N = MAP()

x = min(N, B-1)

print(int(A*x/B))

Measured memory_bytes: 27300
#include<iostream>
using namespace std;
 
int main() {
    long n, a,  max = -1e8, min = 1e8, sum = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a;
        if (a < min) min = a;
        if (a > max) max = a;
        sum += a;
    }
    cout << min << ' ' << max << ' ' << sum << endl;
}

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

public class Main {
		public static void main(String[] args) throws IOException {
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 
		long N = Long.parseLong(br.readLine());
		
		System.out.println(N*(N-1)/2);
	}
}

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

int main() {
  ll N;
  cin >> N;
  vector<string> S(N);
  REP(i, N) cin >> S[i];
  sort(all(S));
  unique(S);

  cout << S.size() << endl;
}

Measured memory_bytes: 9548
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<long long> A(N), S(N);
    for(long long &i: A)
        cin >> i;
    partial_sum(A.begin(), A.end(), S.begin());
	long long ans = INT64_MAX;
	for(int i = 0; i < N - 1; i++)
	{
		ans = min(ans, abs(S[S.size() - 1] - 2 * S[i]));
	}
	cout << ans << endl;
}


Measured memory_bytes: 3328
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)
#define Yes(condition) if(condition){ cout << "Yes" << '\n'; }else{ cout << "No" << '\n'; }
#define YES(condition) if(condition){ cout << "YES" << '\n'; }else{ cout << "NO" << '\n'; }
#define yes(condition) if(condition){ cout << "yes" << '\n'; }else{ cout << "no" << '\n'; }





int main() {
    ll a, b, k;
    cin >> a >> b >> k;
    REP(i, k){
        if(i % 2 == 0){
            if(a & 1) a--;
            b += a / 2;
            a /= 2;
        }
        else{
            if(b & 1) b--;
            a += b / 2;
            b /= 2;
        }
    }
    cout << a << ' ' << b << endl;
}


Measured memory_bytes: 256
def inpl():
    return list(map(int, input().split()))


def f(a, b):
    if a == 0 and b == 0:
        return True
    elif a * b == 0:
        return False
    else:
        return True


S = input()
# print(S)
cN = S.count('N')
cW = S.count('W')
cS = S.count('S')
cE = S.count('E')

if f(cN, cS) is True and f(cW, cE) is True:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define SZ(x) ((int)(x).size())
#define rep(i,n) for(int i=0;i<(n);++i)
#define fore(i,a) for(auto &i:a)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define answer cout << ans << endl;
signed _main(); signed main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
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; }
template<class T> using v = vector<T>;
template<class T> using vv = vector<v<T>>;
const int MOD=1e9+7;
const long long INF = 1LL << 60;

signed _main(){
  int N; cin >> N;
  v<int> a(N);
  int sum=0;
  rep(i,N){
    cin >> a[i];
    sum+=a[i];
  }
  sort(a.begin(),a.end());
  for(int i=N-1;i>=0;i--){
    sum-=a[i];
    if(sum*2<a[i]){
      cout << N-i << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 1024
using namespace std;

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <limits>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <numeric>
typedef long long ll;
typedef pair<int,int> p;

int main()
{
  int n;
  cin >> n;
  cout << n / 3 << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<utility>
using namespace std;
int main () {
  int N, H;
  cin >> N >> H;
  vector<pair<int, int>>da(N);
  for (int i = 0; i < N; i ++) cin >> da[i].second >> da[i].first;
  sort(da.begin(), da.end());
  int ma = 0;
  for (int i = 0; i < N; i ++) {
    if (ma < da[i].second) ma = da[i].second;
  }
  int mi = N - 1;
  while(da[mi].first >= ma && mi >= 0) mi --;
  for (int i = N - 1; i > mi; i --) {
    H -= da[i].first;
    if (H <= 0) {
      cout << N - i << endl;
      return 0;
    }
  }
  int ans = H / ma;
  if (H % ma) ans ++;
  cout << N - 1 - mi + ans << endl;
}


Measured memory_bytes: 1024
//y13-5 魚の生息範囲 (解説見た後解き直し)
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define segment_size 65536
#define ROOP() while(true)

//classは初期値がprivate、structはpublic
struct CUBE{
    int x1;
    int x2;
    int y1;
    int y2;
    int d1;
    int d2;
    LL volume(){
        LL x = x2 - x1;
        LL y = y2 - y1;
        LL dd = d2 - d1;
        return x * y * dd;
    }
};

int N,K;
vector<CUBE> li;
vector<int> x;
vector<int> y;
vector<int> d;

bool check(CUBE a, CUBE b){
    if(a.x1 <= b.x1 && a.x2 <= b.x1) return false;
    if(b.x1 <= a.x1 && b.x2 <= a.x1) return false;
    if(a.y1 <= b.y1 && a.y2 <= b.y1) return false;
    if(b.y1 <= a.y1 && b.y2 <= a.y1) return false;
    if(a.d1 <= b.d1 && a.d2 <= b.d1) return false;
    if(b.d1 <= a.d1 && b.d2 <= a.d1) return false;
    return true;
}

int main(){
    cin >> N >> K;
    for(int i=0; i<N; i++){
        CUBE tmp;
        cin >> tmp.x1 >> tmp.y1 >> tmp.d1 >> tmp.x2 >> tmp.y2 >> tmp.d2;
        li.push_back(tmp);
        x.push_back(tmp.x1);
        x.push_back(tmp.x2);
        y.push_back(tmp.y1);
        y.push_back(tmp.y2);
        d.push_back(tmp.d1);
        d.push_back(tmp.d2);
    }
    sort(x.begin(), x.end());
    sort(y.begin(), y.end());
    sort(d.begin(), d.end());

    LL ans = 0;
    for(int i=0; i+1<x.size(); i++){
        for(int j=0; j+1<y.size(); j++){
            for(int k=0; k+1<d.size(); k++){
                CUBE tmp;
                tmp.x1 = x[i];
                tmp.x2 = x[i+1];
                tmp.y1 = y[j];
                tmp.y2 = y[j+1];
                tmp.d1 = d[k];
                tmp.d2 = d[k+1];
                int c = 0;
                for(int l=0; l<li.size(); l++){
                    if(check(li[l], tmp)) c++;
                }
                if(c >= K){
                    //cout << tmp.x1 << " " <<  tmp.x2 << " " <<  tmp.y1 << " " <<  tmp.y2 << " " <<  tmp.d1 << " " <<  tmp.d2 << " " << tmp.volume() << endl;
                    ans += tmp.volume();
                }
            }
        }
    }
    cout << ans << endl;
    

    return 0;
}


Measured memory_bytes: 3116
N, M = gets.split.map(&:to_i)
S = gets.chomp.chars.reverse
T = gets.chomp.chars.reverse
L = N.lcm(M)

si = 0
ti = 0

while !S.empty? && !T.empty?
  if si == ti
    if S.last != T.last
      puts -1
      exit
    end

    ti += L / M
    si += L / N
    S.pop
    T.pop
  elsif si < ti
    si += L / N
    S.pop
  else
    ti += L / M
    T.pop
  end
end

puts L


Measured memory_bytes: 11900
//#define _GRIBCXX_DEBUG
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;


// ?????¬???????????¬??????
#pragma region MACRO
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define PED cout << "\n"
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define ILP while(true)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

// ???
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
#pragma endregion

// Effective std
#pragma region ESTD
template<typename C, typename T>
constexpr int count(C& c, T t) { return count(ALL(c), t); }
template<typename C, typename F>
constexpr int count_if(C& c, F f) { return count_if(ALL(c), f); }
template<typename C, typename T>
void erase(C& c, T t) { remove(ALL(c), t), c.end(); }
template<typename C>
void remove(vector<C>& c, unsigned int index) { c.erase(c.begin()+index); }
template<typename C, typename T, typename U>
constexpr void replace(C& c, T t, U u) { replace(ALL(c), t, u); }
template<typename C, typename F, typename U>
constexpr void replace_if(C& c, F f, U u) { (ALL(c), f, u); }
template<typename C>
constexpr void reverse(C& c) { reverse(ALL(c)); }
template<typename C>
constexpr void sort(C& c) { sort(ALL(c)); }
template<typename C, typename Pred>
constexpr void sort(C& c, Pred p) { sort(ALL(c), p); }
#pragma endregion

// ?????°
#pragma region CONST_VAL
#define PI (2*acos(0.0))
#define EPS (1e-9)
#define MOD (int)(1e9+7)
#pragma endregion


int main()
{
    int n;
    while(cin>>n) {
        if(n==0) break;
        vi v(n);
        rep(i,n) {
            cin >> v[i];
        }
        sort(v);
        remove(v,n-1);
        remove(v,0);
        P(accumulate(ALL(v),0)/v.size());
    }
    return 0;
}

Measured memory_bytes: 3052
import sys
#sys.stdin=open("data.txt")
input=sys.stdin.readline

def gcd(a,b):
    while b:
        a,b=b,a%b
    return a

def good(a,b,c,d):
    # easy cases
    if b>a: return 0
    if b>d: return 0
    if b<=c: return 1
    # normal case
    # think about the number of cans mod b
    # this shouldn't be in the interval (c,b)
    a%=b
    d%=b
    g=gcd(b,d)
    a+=((b-a-1)//g)*g
    return not c<a<b

for _ in range(int(input())):
    a,b,c,d=map(int,input().split())
    if good(a,b,c,d): print("Yes")
    else: print("No")


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

/**
 * Built using CHelper plug-in Actual solution is at the top
 */

public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();
	}

	static class Task {
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			int N = in.nextInt();
			int A = in.nextInt();
			out.println(N * N - A);
		}
	}
	
	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

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

Measured memory_bytes: 21460
n = gets.chomp.to_i
t_b = gets.chomp
b = t_b.split(' ').map{|v| v.to_i}

a = Array.new(n, 0)

b.each_with_index do |v, i|
  if i >= 1 && v > a[i]
    a[i+1] = v
  else
    a[i] = v
    a[i+1] = v
  end
end

result = 0
a.each do |v|
  result += v
end
p result

Measured memory_bytes: 3836
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		ArrayList<Integer> list = new ArrayList<>();
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int Q = sc.nextInt();
		
		while(list.size() != N) {
			list.add(0);
		}
		
		for(int i=0; i<Q; i++){
			int x = sc.nextInt();
			list.set(x-1, list.get(x-1)+1);
		}
		
		for(int j = 0; j<list.size();j++) {
			if(Q-list.get(j) < K) {
				System.out.println("Yes");
			}else {
				System.out.println("No");
			}
		}
	}
}

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

int main() {
    int a, b, c, d;
    scanf("%d%d%d%d" , &a, &b, &c, &d);
    cout << min({a+c, a+d, b+c, b+d}) << endl;
    return 0;
}

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


int main(){
    int n;
    cin >> n;
    vector<int> x(n);
    int sum = 0;
    rep(i,n){
        int a,b;
        cin >> a >> b;
        x[i] = b-a+1;
        sum += x[i];
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.stream.LongStream;

public class Main implements Runnable {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        // Run with 32MB stack
        Thread thread = new Thread(null, new Main(), "", 32 * 1024 * 1024);
        thread.start();
    }

    @Override
    public void run() {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    static void solve(Scanner scanner) {
        int n = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).sum();
        System.out.println(n >= 22 ? "bust" : "win");
    }

}


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

int main() {
	string s;
	cin >> s;
	for (int i = 0;i < 4;++i) {
		cout << s[i];
	}
	cout << " ";
	for (int i = 4;i < 12;++i) {
		cout << s[i];
	}
	cout << endl;
	return 0;
}

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

int main(){
  	long int i,ans(753);
  	cin >> i;
  	for( i ; i > 100 ; i /= 10) ans = min(abs(i % 1000 - 753),ans);
  	cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int y=1,len=s.length(),i,j=len-1;
	for(i=0;i<len;i++,j--){
		if(s[i]!=s[j]){
          	y=0;
			break;
		}
	}
	if(y){
		int n=(len-1)/2;
		int j=n-1;
		for(i=0;i<n;i++,j--){
			if(s[i]!=s[j]){
				y=0;
				break;
			}	
		}
		n=(len+3)/2-1;
		j=len-1;
		for(i=n;i<len;i++,j--){
			if(s[i]!=s[j]){
				y=0;
				break;
			}
		}
	}
	if(y==0){
		cout<<"No"<<endl;
	}
	else{
		cout<<"Yes"<<endl;
	}
	return 0;
}


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

struct UnionFind{
  Int n;
  vector<Int> r,p;
  UnionFind(){}
  UnionFind(Int sz):n(sz),r(sz,1),p(sz,0){iota(p.begin(),p.end(),0);}
  Int find(Int x){
    return (x==p[x]?x:p[x]=find(p[x]));
  }
  bool same(Int x,Int y){
    return find(x)==find(y);
  }
  void unite(Int x,Int y){
    x=find(x);y=find(y);
    if(x==y) return;
    if(r[x]<r[y]) swap(x,y);
    r[x]+=r[y];
    p[y]=x;
  }
};

//INSERT ABOVE HERE
signed main(){
  Int n,m;
  cin>>n>>m;
  vector<Int> v(n);
  for(Int i=0;i<n;i++) cin>>v[i],v[i]--;
  vector<Int> x(m),y(m);
  for(Int i=0;i<m;i++) cin>>x[i]>>y[i],x[i]--,y[i]--;

  UnionFind uf(n);
  for(Int i=0;i<m;i++) uf.unite(x[i],y[i]);

  Int ans=0;
  for(Int i=0;i<n;i++)
    if(uf.find(i)==uf.find(v[i])) ans++;
 
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 4224
from copy import deepcopy


def solve(N, abc):
    dp = [[0, 0, 0] for i in range(N+1)]

    for i in range(1, N+1):
        for j in range(3):
            tmp = []
            for d in dp[i-1]:
                tmp.append(d)
            tmp.pop(j)
            dp[i][j] = max(tmp) + abc[i-1][j]

    return(max(dp[N]))


if __name__ == "__main__":
    N = int(input())
    abc = [list(map(int, input().split())) for _ in range(N)]
    print(solve(N, abc))


Measured memory_bytes: 50236
#include<iostream>
using namespace std;
static const int N=100;

int main()
{
	int M[N][N];
	int n, u, k, v;

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

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (j) cout << " ";
			cout << M[i][j];
		}
		cout << endl;
	}

    return 0;
}

Measured memory_bytes: 3096
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int main()
{
    string a, b, c;
    cin >> a;
    cin >> b;
    cin >> c;
    int a_ptr, b_ptr, c_ptr;
    a_ptr = b_ptr = c_ptr = 0;
    char curr_player = 'a';
    if(a == ""){
        return 'A';
    }
    while(true){
        if((curr_player == 'a' && a_ptr >= a.length()) || (curr_player == 'b' && b_ptr >= b.length()) ||
           (curr_player == 'c' && c_ptr >= c.length()) ){
            cout << (char)(curr_player-32) << endl;
            break;
        }
        
        if(curr_player == 'a'){
            curr_player = a[a_ptr++];
        }
        else if(curr_player == 'b'){
            curr_player = b[b_ptr++];
        }
        else{
            curr_player = c[c_ptr++];
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int bubbleSort(int A[], int N){
  int i, j, temp;
  int sw = 0;
  int flag = 1;

  for (i=0; flag == 1; i++) {
    flag = 0;
    for (j=N-1; j>=i+1; j--) {
      if (A[j-1] > A[j]) {
        temp   = A[j-1];
        A[j-1] = A[j];
        A[j]   = temp;
        sw++;
        flag = 1;
      }
    }
  }
  return sw;
}


int main(){
  int A[100], N, sw, i;
  scanf("%d", &N);
  for (i=0; i<N; i++)
    scanf("%d", &A[i]);

  sw = bubbleSort(A, N);

  for (i=0; i<N; i++) {
    if (i>0)
      putchar(' ');
    printf("%d", A[i]);
  }
  printf("\n%d\n", sw);
  return 0;
}

Measured memory_bytes: 1804
import itertools,sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N,M,K = LI()
A = LI()
B = LI()
accumulate_A = [0]+list(itertools.accumulate(A))
accumulate_B = [0]+list(itertools.accumulate(B))
ans,j = 0,M
for i in range(N+1):
    if accumulate_A[i]>K:
        break
    while accumulate_A[i]+accumulate_B[j]>K:
        j -= 1
    ans = max(ans,i+j)
print(ans)


Measured memory_bytes: 51240
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S,T; cin >> S >> T;
  
  if(S.at(0) == T.at(2) && S.at(1) == T.at(1) && S.at(2) == T.at(0)) {
    cout << "YES" << endl; 
  }
  else cout << "NO" << endl;    
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 55;
const int MOD = 1e9 + 7;
#define int long long
vector < vector < int > > arr;
vector < vector < int > > I;
vector< vector < int > > mul(vector < vector < int > > &a, vector < vector < int > > &b){
    int n = a.size();
    vector < vector < int > > result;
    result.resize(n);
    for(int i = 0; i < n; i++) result[i].resize(n);
    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++) {
            long long tmp = 0;
            for(int k = 0; k < n; k++) {
                tmp += a[i][k] * 1ll * b[k][j];
                tmp %= MOD;
            }
          result[i][j] = tmp % MOD; 
      }
    return result;
}
vector < vector < int > > modpow(int b){
    if(b == 0) return I;
    int nesf = b / 2;
    vector < vector < int > > a = modpow(nesf);
    if(b & 1){ vector < vector < int > > b = mul(a, arr); return mul(a,b); }
    return mul(a, a);
}
int32_t main(){
    int n, k;
    cin >> n >> k;
    arr.resize(n);
    I.resize(n);
    for(int i = 0; i < n; i++){
        arr[i].resize(n);
        I[i].resize(n);
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++)
            cin >> arr[i][j];
        I[i][i] = 1;
    }
    modpow(k);
    vector < vector < int > > res = modpow(k);
    int ans = 0;
    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++){
            ans += res[i][j];
            ans %= MOD;
        }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 384
a, b, c, d = map(int, raw_input().split())
ac = a - c
ab = a - b
bc = b - c
if ac < 0:
    ac = ac * -1
if ab < 0:
    ab = ab * -1
if bc < 0:
    bc = bc * -1
if ac <= d:
    print "Yes"
elif ab <= d and bc <= d:
    print "Yes"
else:
    print "No"

Measured memory_bytes: 2568
#include<iostream>
using namespace std;
int main(){
	for (int i = 1; i <= 9; ++i){
		for (int j = 1; j<= 9; ++j){
			cout << i << 'x' << j << '=' << i*j;
			cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1116
#include <bits/stdc++.h>
using namespace std;
int main(){

  int N;
  cin>>N;
  vector<int> p(N);
  for(int i=0;i<N;i++){
    cin>>p.at(i);
  }

  int count = 0;
  
  for(int i=0;i<N-1;i++){
    if(p.at(i)!=i+1){
      count++;
    }
  }
  
  if(count<=2){
    cout<<"YES"<<endl;
  }
  else {
    cout<<"NO"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let n = get!(usize);
    let a = get!([usize]);
    let mut b = get!([usize]);

    for i in 0..n {
        if a[i] > b[i] {
            println!("-1");
            return;
        }
    }

    let mut count = 0;
    let mut flag = true;
    while flag {
        flag = false;
        for i in 0..n {
            let left = if i==0 {
                b[n-1]
            } else {
                b[i-1]
            };
            let right = if i==n-1 {
                b[0]
            } else {
                b[i+1]
            };
            let center = b[i];
            let tmp = (center-a[i])/(right+left);
            if center > right && center > left && tmp > 0 {
                flag = true;
                count += tmp;
                b[i] -= tmp*(right+left);
            }
        }
    }
    for i in 0..n {
        if a[i] != b[i] {
            println!("-1");
            return;
        }
    }
    println!("{}", count);
}


Measured memory_bytes: 17656
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int W = sc.nextInt();
        int H = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
        int r = sc.nextInt();
        
        if (x - r < 0 || x+ r > W || y+r > H || y-r <0){
            System.out.println("No");
        }else {
            System.out.println("Yes");
        }
        
       
    }


}


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

int main(){
	int A, B, K; cin >> A >> B >> K;

	int count = 0;
	for(int i = 100; i > 0; i--){
		if(A % i == 0 && B % i == 0){
			count++;
			if(count == K){
				cout << i;
				break;
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

int main() {

	int N, M;
	cin >> N >> M;
	vector <int> X(M);

	for (int i = 0; i < M; i++) {
		cin >> X[i];
	}
	if (N >= M) {
		cout << 0 << endl;
		return 0;
	}

	sort(X.begin(), X.end());

	int sum_difference = 0;
	vector <int> difference(M-1);
	for (int i = 0; i < M - 1; i++) {
		difference[i] = abs(X[i + 1] - X[i]);
		sum_difference += difference[i];
	}
	sort(difference.begin(), difference.end());

	//for (int i = 0; i < M - 1; i++) {
	//	cout << i << ":" << difference[i] << endl;
	//}

	int answer = sum_difference;
	for (int i = 0; i < N - 1; i++) {
		answer -= difference[(M - 1) - 1 - i];
	}
	cout << answer << endl;

	return 0;
}

Measured memory_bytes: 1024
#include<cassert>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>

using namespace std;
#define sz(x)(int)(x.size())
#define fi(a, b) for(int i=a;i<b;++i)
#define fj(a, b) for(int j=a;j<b;++k)
#define fk(a, b) for(int k=a;k<b;++j)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
////////////




void solve(){
	string s;
	cin >> s;
	string n = "CODEFESTIVAL2016";
	int ans = 0;
	fi(0 ,16) if(s[i] != n[i]) ++ans;
	cout << ans << endl;
}

int main(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	solve();

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(){
    char s[3];
    int i,m=0,n;
    scanf("%s",&s);
    for(i=0;i<3;i++){
        if(s[i]=='A'){
            m++;
        }
        n=3-m;
    }
     if(n==3 || m==3){
        printf("No\n");
    }
    else{
        printf("Yes\n");
    }

return 0;
}

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

using namespace std;
typedef long long ll;
struct Node {
  Node *children[26]{};
  int req[26]{};
};
int main() {
  int n;
  cin >> n;
  vector<string> a(n);
  Node *root = new Node();
  ll ans = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    Node *p = root;
    for (int j = (int)a[i].size() - 1; j > 0; --j) {
      int c = a[i][j] - 'a';
      if (!p->children[c])
        p->children[c] = new Node();
      p = p->children[c];
    }
    p->req[a[i][0] - 'a']++;
  }
  for (int i = 0; i < n; ++i) {
    vector<int> cnt(26);
    for (char c : a[i])
      cnt[c - 'a']++;
    Node *p = root;
    for (int j = (int)a[i].size() - 1; j > 0; --j) {
      for (int k = 0; k < 26; ++k)
        if (cnt[k])
          ans += p->req[k];
      int c = a[i][j] - 'a';
      cnt[c]--;
      if (!p->children[c])
        p->children[c] = new Node();
      p = p->children[c];
    }
  }
  printf("%lld", ans);
}

Measured memory_bytes: 316948
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
using ll = long long;
using namespace std;
//LLONG_MAX = 90^18
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No"); }
void Yes() { cout << "Yes"; }
void No() { cout << "No"; }
//max_element

int N, M, X;
int C[20];
int A[20][20];

int min_cost = INT_MAX;

bool flg[20];
void func(int n)
{
	if (n == N)
	{
		int c = 0;
		int x[20] = {};
		for (int i = 0; i < N; i++)
		{
			if (flg[i])
			{
				c += C[i];
				for (int j = 0; j < M; j++)
				{
					x[j] += A[i][j];
				}
			}
		}

		bool is_good = true;
		for (int i = 0; i < M; i++)
		{
			if (x[i] < X)
			{
				is_good = false;
			}
		}

		if (is_good)
		{
			min_cost = min(min_cost, c);
		}

		return;
	}

	flg[n] = false;
	func(n + 1);
	flg[n] = true;
	func(n + 1);
}


signed main()
{
	cin >> N >> M >> X;
	REP(i, N)
	{
		cin >> C[i];
		REP(j, M)
		{
			cin >> A[i][j];
		}
	}

	func(0);

	if (min_cost == INT_MAX)
		cout << -1 << endl;
	else
		cout << min_cost << endl;
}




Measured memory_bytes: 3632