akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30);
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T>
bool chmin(T& a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T>
bool chmax(T& a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for(int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
template <typename T>
vector<T> make_v(size_t a) {
    return vector<T>(a);
}
template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T& t, const V& v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T& t, const V& v) {
    for(auto& e : t) {
        fill_v(e, v);
    }
};
struct UnionFind {
    vector<int> par, siz;
    UnionFind(int n) {
        par.resize(n);
        siz.resize(n, 1);
        for(int i = 0; i < n; i++)
            par[i] = i;
    }
    int find(int x) {
        if(par[x] == x) {
            return x;
        } else {
            return par[x] = find(par[x]);
        }
    }
    bool unite(int u, int v) {
        u = find(u), v = find(v);
        if(u == v)
            return false;
        if(siz[u] < siz[v])
            swap(u, v);
        par[v] = u;
        siz[u] += siz[v];
        return true;
    }
    bool same(int u, int v) { return find(u) == find(v); }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int m, k;
    cin >> m >> k;
    if(k >= (1 << m)) {
        cout << -1 << endl;
        return 0;
    }
    if(m == 0) {
        if(k == 0) {
            cout << 0 << " " << 0 << endl;
        } else {
            cout << -1 << endl;
        }
    } else if(m == 1) {
        if(k == 0) {
            cout << 0 << " " << 0 << " " << 1 << " " << 1 << endl;
        } else {
            cout << -1 << endl;
        }
    } else {
        for(int i = 0; i < (1 << m); i++) {
            if(i == k) {
                continue;
            }
            cout << i << " ";
        }
        cout << k << " ";
        for(int i = (1 << m) - 1; i >= 0; i--) {
            if(i == k) {
                continue;
            }
            cout << i << " ";
        }
        cout << k << endl;
    }
}


Measured memory_bytes: 1792
#include<iostream>
#define LL long long
using namespace std;
int main() {
	LL sum, min, max, n, d;
	cin >> n;
	cin >> d;
	sum = d;
	min = d;
	max = d;
	n--;
	while (n--) {
		cin >> d;
		sum += d;
		if (min > d)min = d;
		if (max < d)max = d;
	}
	cout << min << ' ' << max << ' ' << sum << endl;
	return 0;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
int main()
{	
  	bool S=false;
	string A;
  	cin >> A;
  	if(A.at(2)==A.at(3)&&A.at(4)==A.at(5))
    {
      S=true;
    }
  	if(S)
      cout << "Yes" << endl;
  	else
      cout << "No" << endl;
}

Measured memory_bytes: 384
// clang-format off
#include <cassert>
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
#include <iomanip>
#include <queue>
#include <map>

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (b)-1; i >= (a); i--)
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep(i, n) for(int i = (n)-1; i >= 0; i--)

#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define pii pair<int, int>
#define vi vector<int>

using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T>& p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T>& vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
typedef long long ll;
constexpr ll MOD = 1000000007;



int main()
{
    char c1,c2;
    cin >> c1 >> c2;
    if(c1 == 'H'){
        if(c2 == 'H'){
            cout << 'H' << endl;
            return 0;
        }
        if(c2 == 'D'){
            cout << 'D' << endl;
            return 0;
        }
    }
    if(c1 == 'D'){
        if(c2 == 'D'){
            cout << 'H' << endl;
            return 0;
        }
        if(c2 == 'H'){
            cout << 'D' << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T>
bool chmin(T& a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T>
bool chmax(T& a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for(int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
template <typename T>
vector<T> make_v(size_t a) {
    return vector<T>(a);
}
template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T& t, const V& v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T& t, const V& v) {
    for(auto& e : t) {
        fill_v(e, v);
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, t;
    cin >> a >> b >> t;
    cout << (t / a) * b << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstdlib>

using namespace std;

int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

int lcm(int a, int b) {
    return a / gcd(a, b) * b;
}

int main() {
    int a, b;
    while (scanf("%d %d", &a, &b) != EOF) {
        printf("%d %d\n", gcd(a, b), lcm(a, b));
    }
    return 0;
}



Measured memory_bytes: 3156
#include<cstdio>
#include<iostream>
#include<cstdlib>
using namespace std;
struct Node
{
    int key;
    Node *right,*left,*parent;
};
Node *root,*NIL;
void insert(int k)
{
    Node *z=(Node*)malloc(sizeof(Node));
    z->key=k;
    z->left=NIL;
    z->right=NIL;
    Node *x=root;
    Node *y=NIL;
    while(x!=NIL)
    {
        y=x;
        if(x->key<z->key)
        {
            x=x->right;
        }
        else
        {
            x=x->left;
        }
    }
    z->parent=y;
    if(y==NIL)
    {
        root=z;
    }
    else
    {
        if(z->key<y->key)
        {
            y->left=z;
        }
        else
        {
            y->right=z;
        }
    }
}
void inorder(Node *u)
{
    if(u==NIL)return;
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
}
void preorder(Node *u)
{
    if(u==NIL)return;
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
}
bool findNode(int k)
{
    Node *u=root;
    while(u!=NIL)
    {
        if(u->key<k)
        {
            u=u->right;
        }
        else if(u->key>k)
        {
            u=u->left;
        }
        else
        {
            return true;
        }
    }
    return false;
}
int main()
{
    int n,i,x;
    string com;
    scanf("%d",&n);
    for(i=0; i<n; i++)
    {
        cin>>com;
        if(com=="insert")
        {
            scanf("%d",&x);
            insert(x);
        }
        else if(com=="print")
        {
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
        else if(com=="find")
        {
            scanf("%d",&x);
            if(findNode(x))
            {
                printf("yes\n");
            }
            else
            {
                printf("no\n");
            }
        }
    }
    return 0;
}

Measured memory_bytes: 21996
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    int N,R;
    cin >> N >> R;
    if (N >= 10) cout << R << endl;
    else cout << R + 1000 - 100 * N << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
//l={1,2,3,4}
//greater<int>()
//sort(l,l+n)

int main(void)
{
	int x, a, b;
	cin >> x >> a >> b;
	x -= a;
	cout << x % b << endl;

}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cmath>
using namespace std;
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	int l=m/n+1;
	for(int i=l;i>=1;i--)
	{
		if(m%i==0&&m/i>=n)
			return printf("%d\n",i),0;
	}
	return 0;
}



Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>

static const int MOD = 1000000007;
using ll = int64_t;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;


int main() {
    int n;
    cin >> n;
    vector<ll> v(n), v2(n);
    for (int i = 0; i < n; ++i) {
        scanf("%li", &v[i]);
    }
    vector<vector<int>> G(n);
    for (int i = 0; i < n - 1; ++i) {
        int a, b;
        cin >> a >> b;
        G[a-1].emplace_back(b-1);
        G[b-1].emplace_back(a-1);
    }
    deque<int> Q;
    vector<int> num(n);
    {
        stack<int> s;
        int cnt = 0;
        vector<int> visited(n, 0);
        s.emplace(0);
        while(!s.empty()){
            int a = s.top(); s.pop();
            visited[a]++;
            num[a] = cnt++;
            Q.emplace_front(a);
            for (auto &&i : G[a]) {
                if(!visited[i]) s.emplace(i);
            }
        }
    }
    while(!Q.empty()){
        int i = Q.front(); Q.pop_front();
        int cnt = 0;
        ll m = -INF<ll>, sum = 0;
        for (auto &&j : G[i]) {
            if(num[i] < num[j]) {
                sum += v2[j];
                m = max(m, v2[j]);
                cnt++;
            }
        }
        if(cnt == 0 || m == -INF<ll>) {
            v2[i] = v[i];
            continue;
        }
        ll M = min((sum-m), sum/2);
        ll x = sum-v[i];
        if(x < 0 || x > M){
            puts("NO");
            return 0;
        }
        v2[i] = sum - x*2;
    }
    if(G[0].size() != 1 && v2[0] != 0){
        puts("NO");
        return 0;
    }
    puts("YES");
    return 0;
}


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

class B
{
	static void Main()
	{
		var s = Console.ReadLine();

		var dp = new int[s.Length + 1];
		for (int i = 0; i < s.Length; i++)
			dp[i + 1] = "ACGT".Contains(s[i]) ? dp[i] + 1 : 0;
		Console.WriteLine(dp.Max());
	}
}


Measured memory_bytes: 13268
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int N = sc.nextInt();
      	
      	long sum=0;
      
      	for(int i=1;i<=N;i++){
        if(i%3!=0&&i%5!=0){
        sum=sum+i;
        }
        
        }
      System.out.println(sum);
      
        
		
		
	}
}

Measured memory_bytes: 27140
#include<bits/stdc++.h>
using namespace std;
#define SZ(v) ((int)(v).size())
#define zero(v) memset(v,0,sizeof(v))
#define rep(i,n) for(int i=0;i<(n);i++)
#define foreach(it,c) for(__typeof(c.begin()) it=c.begin();it!=c.end();it++)
#define all(v) (v).begin(),(v).end()
template<typename T>inline bool chkmin(T &a,const T &b){return a>b?a=b,1:0;}
template<typename T>inline bool chkmax(T &a,const T &b){return a<b?a=b,1:0;}
typedef long long ll;
typedef unsigned uint;
const int INF=0x3f3f3f3f;
const double EPS=1e-10;
typedef pair<int,int> pii;
int inline in(){int x=0,c;for(;(uint)((c=getchar())-'0')>=10;)
{if(c=='-')return -in();if(!~c)throw ~0;}do{x=(x<<3)+(x<<1)+(c-'0');}
while((uint)((c=getchar())-'0')<10);return x;}
int n;
const int Maxn=3000;

double p[Maxn],dp[Maxn];

int main(){
	scanf("%d",&n);
	rep(i,n){
		scanf("%lf",&p[i]);
	}
	dp[0]=1;
	rep(i,n){
		for(int j=n;j>=0;j--){
			dp[j]*=(1-p[i]);
			if(j-1>=0){
				dp[j]+=dp[j-1]*p[i];
			}
		}
	}
//	for(int i=0;i<=n;i++){
//		printf("%.10lf ",dp[i]);
//	}
//	printf("\n");
	double ans=0;
	for(int i=0;i<=n;i++){
		if(i>(n-i)){
			ans+=dp[i];
		}
	}
	printf("%.10lf\n",ans);
	return 0;
}

Measured memory_bytes: 3788
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

ll mod = 1e9+7 ;
const ld error = 1e-8;
const ld PI = acosl(-1); //const ld PI = acosl(-1)

#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define eq(x, y) (fabs((x)-(y))<error)
#define bt(i) (1LL<<(i))

#define debug(x) cerr<<#x<<" = "<<(x)<<"\n"
#define hoise cerr<<"hoise - "<<__LINE__<<"\n"
#define tham getchar()
//mt19937 rng((unsigned)chrono::system_clock::now().time_since_epoch().count()); //mt199937_64 for ll
//mt19937 rng(199);

inline ll MOD(ll x, ll m = mod){
    ll y = x % m;
    return (y >= 0) ? y: y+m;
}

const int inf = 1e9;
const ll infl = 1e18+1;
const int nmax = 1e5 + 10;
///===========================================  template  =======================================================

int arr[nmax];

int main(){
    FASTIO;
    ll N, K;
    cin>>N>>K;

    N = N % K;
    N = min(N, K-N);

    cout<<N;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<fstream>
#include<math.h>
#include<vector>
#define _cin ios_base::sync_with_stdio(0);  cin.tie(0);
#define ll long long 
using namespace std;

int main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
    #endif
    _cin;

    int x,n,a;
    cin>>x>>n;
    vector<int> arr;
    if(n==0)cout<<x<<endl;
    else{
        for(int i=0;i<n;i++){
            cin>>a;
            arr.push_back(a);
        }
        sort(arr.begin(),arr.end());
        int el = 0, flag =1,count = 0;
        while(flag){
            if(find(arr.begin(),arr.end(), x- el) == arr.end()){
                cout<<x-el<<endl;
                flag = 0;
            }
            if(count%2==0){
                el-=1;
                el*=-1;
            }
            else el *= -1;
            count++;
        }
    }
}

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

void print_array(int A[], int N) {
  for(int i = 0; i < N-1; ++i) {
    std::cout << A[i] << " ";
  }
  std::cout << A[N-1] << std::endl;
}

void insertionSort(int A[], int N) {
  int v;
  int j;
  for(int i = 1; i < N; ++i) {
    print_array(A, N);
    v = A[i];
    j = i-1;
    while( j >= 0 and A[j] > v ) {
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = v;
  }
  print_array(A, N);
}

int main(void) {

  int N;
  int A[128];

  std::cin >> N;
  for(int i = 0; i < N; ++i) {
    std::cin >> A[i];
  }

  insertionSort(A, N);
  
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>

int main() {
    int x, y;
    while (std::cin >> x >> y) {
        if (x == 0 && y == 0) break;
        if (x > y) {
            std::cout << y << " " << x << std::endl;
        } else {
            std::cout << x << " " << y << std::endl;
        }
    }

    return 0;
}

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <cstring>
#include <cctype>
using namespace std;

char my_tolower(char ch)
{
	return static_cast<char>(std::tolower(static_cast<unsigned char>(ch)));
}

int main(void)
{
	int N, K;
	string S;

	cin >> N >> K;
	cin >> S;

	S[K - 1] = my_tolower(S[K - 1]);

	cout << S << endl;

	return 0;
}

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

int main()
{
	char arr[9];
	string a="";
	for(int i=0;i<9;i++)
	{
		cin >> arr[i];
	}
	a+=arr[0];
	a+=arr[4];
	a+=arr[8];
	cout << a << endl;
}

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

#define INF 0x3fffffffffffff

typedef long long int LLI;

int N;
int M;
LLI L;
LLI K[11451419];
LLI S[11451419];
LLI ssum[11451419];
LLI dp[2010][2010];

LLI sum(int a, int b) {
  if (a > b) swap(a, b);
  return (ssum[b] - ssum[a-1])/L;
}

int main() {
  scanf("%d%d%lld", &N, &M, &L);
  for (int i=1; i<=N; i++) {
    scanf("%lld", &K[i]);
  }
  sort(K+1, K+N+1);
  
  for (int i=1; i<=M; i++) {
    scanf("%lld", &S[i]);
    ssum[i] = ssum[i-1]+S[i];
  }

  for (int i=0; i<=N; i++) {
    for (int j=0; j<=N; j++) {
      dp[i][j] = INF;
    }
  }

  dp[1][0] = 0;
  for (int i=2; i<=N; i++) {
    for (int j=0; j<i-1; j++) {
      dp[i][j] = min(dp[i][j], dp[i-1][j]+sum(K[i-1], K[i]));
      if (j != 0) {
        dp[i][i-1] = min(dp[i][i-1], dp[i-1][j]+sum(K[j], K[i]));
      } else {
        dp[i][i-1] = min(dp[i][i-1], dp[i-1][j]+sum(K[1], K[i]));
      }
    }
  }

  LLI ans = INF;
  for (int j=0; j<=N; j++) {
    if (j != 0) {
      dp[N][j] += sum(K[j], K[N]);
    } else {
      dp[N][j] += sum(K[1], K[N]);
    }
    ans = min(ans, dp[N][j]);
  }
  printf("%lld\n", ans);
}

Measured memory_bytes: 36276
#include<stdio.h>

int solve(int , int);
int n,A[2000];

int main()
{
  int q,m,i;

  scanf("%d",&n);

  for(i = 0; i < n; i++){
    scanf("%d",&A[i]);
  }

  scanf("%d",&q);

  for(i = 0; i < q; i++){
    scanf("%d",&m);
    if(solve(0,m))printf("yes\n");
    else printf("no\n");
  }

  return 0;
}

int solve(int i, int m)
{
  int res;
  
  if(m == 0)return 1;
  if(i >= n)return 0;

  res = solve(i + 1, m) || solve(i + 1, m - A[i]);
  return res;
}



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

using namespace std;
const int nn = 2e5 + 5;
int hitam[nn], putih[nn];

int main() {
	int ans = 1e9, n;
	string s;
	cin >> n >> s;
	for (int i = 0; i < n; i++) {
		if (s[i] == '#') hitam[i] = 1;
		else putih[i] = 1;
		if (i > 0) hitam[i] += hitam[i - 1];
		if (i > 0) putih[i] += putih[i - 1];
	}
	for (int i = 0; i < n; i++) {
		ans = min(ans, hitam[i] + putih[n - 1] - putih[i]);
	}
	ans = min(ans, putih[n - 1]);
	cout << ans << endl;
}

Measured memory_bytes: 2180
object Main extends App {
	val pw = new java.io.PrintWriter(System.out)

	pw.println(if ((Scanner.next())(0).isUpper) "A" else "a")
	pw.flush()
}

object Scanner {
	private val buf = new Array[Byte](1024); private var ptr = 0; private var len = 0

	@inline private def isPrintableChar(c: Int): Boolean = 33 <= c && c <= 126
	@inline private def hasNextByte(): Boolean = if (ptr >= len) { ptr = 0; len = System.in.read(buf); len > 0 } else true
	@inline private def hasNext(): Boolean = {
		while (hasNextByte() && !isPrintableChar(buf(ptr))) ptr += 1
		hasNextByte()
	}
	@inline private def readByte(): Byte = if (hasNextByte()) { val res = buf(ptr); ptr += 1; res } else -1

	def next(): String = {
		if(!hasNext()) ???
		val sb = new StringBuilder; var b = readByte()
		while (isPrintableChar(b)) { sb.append(b.toChar); b = readByte() }
		sb.toString
	}

	def nextInt(): Int = {
		val n = nextLong()
		if (n < Int.MinValue || Int.MaxValue < n) ???
		n.toInt
	}

	def nextLong(): Long = {
		if(!hasNext()) ???
		var minus = false; var b = readByte()
		if (b == '-') { minus = true; b = readByte() }

		@scala.annotation.tailrec
		def go (b: Byte, n: Long = 0): Long = if ('0' <= b && b <= '9') go(readByte(), n * 10 + b - '0') else if (minus) -n else n

		go(b)
	}

	def nextDouble(): Double = next().toDouble
}


Measured memory_bytes: 54660
import re
def Main():
  s = input()
  r = re.findall("A.+Z",s)
  # print(r)
  cnt = 0
  for i in r:
    cnt = max(cnt, len(i))

  print(cnt)
# QWERTYASDFZXCV

if __name__ == '__main__':
  Main()

Measured memory_bytes: 3756
#include <bits/stdc++.h>
#define int long long
using namespace std;
using pii = pair<int, int>;
const int INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

signed main()
{
    int n, m;
    cin >> n >> m;
    map<int, vector<int> > v;
    std::priority_queue<int> q;
    for (int i = 0; i < n; i++)
    {
        int a, b;
        cin >> a >> b;
        v[a].push_back(b);
    }
    int sum = 0;
    for (int i = 1; i <= m; i++) {
        for (int j = 0; j < v[i].size(); j++)
        {
            q.push(v[i][j]);
        }
        if (!q.empty()) {
            sum += q.top();
            q.pop();
        }
    }
    cout << sum << "\n";
}

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

using namespace std;

typedef long long ll;

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

signed main(){
    ll n, m;
    cin >> n >> m;
    vector<ll> a(m);
    for(auto& x : a)
        cin >> x;
    sort(a.begin(), a.end());
    vector<ll> dist;
    for(ll i = 0; i < m - 1; ++i)
        dist.emplace_back(a[i + 1] - a[i]);
    sort(dist.begin(), dist.end(), greater<ll>());
    ll ans = a.back() - a.front();
    for(ll i = 0; i < min((ll)dist.size(), n - 1); ++i){
        ans -= dist[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 2168
#include <stdio.h>
void qsort(int a[],int l,int r){
    int i,j,t,p;
    if(l < r){
        i = l;
        j = r + 1;
        p = l;
        do{
            do{
                i ++;
            }while(a[i] < a[p]);
            do{
                j --;
            }while(a[p] < a[j]);
            if(i < j){
                t = a[i];
                a[i] = a[j];
                a[j] = t;
            }
        }while(i < j);
        t = a[p];
        a[p] = a[j];
        a[j] = t;
        p = j;
        qsort(a,l,p - 1);
        qsort(a,p + 1,r);
    }
}
int main(void){
    int n, a[300000];
    int i,j;
    int flg = 0;
    scanf("%d", &n);
    for(i = 0;i < n;i ++){
        scanf("%d", &a[i]);
    }
    qsort(a, 0, n - 1);
    for(i = 0;i < n;i ++){
        if(a[i] == a[i + 1]){
            flg = 1;
            break;
        }
    }
    if(flg == 0){
        printf("YES\n");
    }else{
        printf("NO\n");
    }
    return 0;
}

Measured memory_bytes: 896
class BIT:
  def __init__(self, n):
    self.N = n
    self.tree = [0]*(n+1)
  
  def BIT_add(self, i):
    while i <= self.N:
      self.tree[i] += 1
      i += i&(-i)
  
  def BIT_sum(self, i):
    s = 0
    while i:
      s += self.tree[i]
      i -= i&(-i)
    return s
  
  def BIT_search(self, x):
    i = 0
    s = 0
    step = 1<<(self.N.bit_length()-1)
    
    while step:
      if i+step <= self.N and s+self.tree[i+step] < x:
        i += step
        s += self.tree[i]
      step >>= 1
    return i+1

N = int(input())
bit = BIT(N)
p = [None]+[int(c) for c in input().split()]
p_to_i = [None]*(N+1)
for i, x in enumerate(p[1:], 1):
  p_to_i[x] = i
  
ans = 0
for x in range(N,0,-1):
  c = p_to_i[x]
  L = bit.BIT_sum(c)
  bit.BIT_add(c)
  R = N-x-L
  a = bit.BIT_search(L-1) if L>=2 else 0
  b = bit.BIT_search(L) if L >= 1 else 0
  d = bit.BIT_search(L+2) if R >= 1 else N+1
  e = bit.BIT_search(L+3) if R >= 1 else N+1
  
  coef = 0
  if b != 0:
    coef += (b-a) * (d-c)
  if d != 0:
    coef += (e-d) * (c-b)
  
  ans += x*coef
print(ans)

Measured memory_bytes: 62956
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<functional>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PA;
const int MOD = 1000000007;
const ll INF=2e18;

ll N,M;
ll a,b,c;
string s;
map<char,ll> mp; 
int main(){
    cin>>s;
    for(auto c:s){
        mp[c]++;
    }
    if(mp['0']>mp['1']){
        swap(mp['0'],mp['1']);
    }
    cout<<s.length()-(mp['1']-mp['0'])<<endl;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, n) for(int i = 1; i <= (int)(n); i++)
const long long INF = 1LL << 60;
const double PI=3.14159265358979323846;
int main() 
{
    int n;
    cin >> n;

    rep(i,3){
        if(n%10==7){
            cout << "Yes" <<endl;
            return 0;
        }
        n/=10;
    }

    cout<< "No" <<endl;

}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
using namespace std;
//cout <<  << endl;
typedef long long int ll;
typedef long double ld;
const ll INF = 1LL << 60;
#define MOD 1000000007
#define MAX_V 100010
#define MAX_N 100010

bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}

ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}

ll junnretu(ll n){
    ll ans=1;
    for (ll i=1;i<=n;i++){
        ans*=i;
    }
    return ans;
}

int main(){
    ll s,count=1;
    cin >> s;
    bool x[1000100];
    fill(x,x+100010,false);
    x[s]=true;
    while (true){
        if (s%2==1){
            s=3*s+1;
            count++;
            if (x[s])break;
            x[s]=true;
        }else{
            s/=2;
            count++;
            if (x[s])break;
            x[s]=true;
        }
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 384
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
#define mp make_pair
#define MAX 20000
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef vector<long long> vll;
typedef vector<ii> vii;
#define EPS 1e-9
#define LSOne(S) (S & (-S))
#define INF 1000*1000*1000+889
const int N = 1e5+10;
int w[110],v[110];
int n,weight;
ll dp[101][N];
int main(void)
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>weight;
    for(int i = 0; i < n; ++i)
    {
        cin>>w[i]>>v[i];
    }
    dp[0][w[0]]=v[0];
    for(int i = 1; i < n; ++i)
    {
        for(int j = 0; j <= weight; ++j)
        {
            if(j-w[i]>0)
            {
                dp[i][j] = max(dp[i-1][j],v[i]+dp[i-1][j-w[i]]);
            }
            else
                dp[i][j] = dp[i-1][j];
        }
    }
    ll ans = 0;
    for(int i = 0; i <= weight; ++i)
        ans = max(ans,dp[n-1][i]);
    cout<<ans;
}


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

int main(){

	ios_base::sync_with_stdio(0);
	cout.tie(0);
	cin.tie(0);

	int n,k,s;
	cin>>n>>k>>s;

	vector<int> ans(n,0);
	for(int i=0 ; i<k ; ++i)
		ans[i] = s;

	if(s == 1e9)	s = 1;
	else	s = s+1;

	for(int i=0 ; i<n ; ++i){
		if(!ans[i]) cout<<s<<" ";
		else	cout<<ans[i]<<" ";
	}

}

Measured memory_bytes: 1792
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        String[] lines = getStdin();
        String str = lines[0];
        long num = Long.parseLong(str);
        long sum = 100;
        int count = 0;

        while (sum < num){
            sum = sum + (sum * 1 / 100);
            count++;
        }
        System.out.println(count);
             
    }
  
  private static String[] getStdin() {
    Scanner scanner = new Scanner(System.in);
    ArrayList<String> lines = new ArrayList<>();
    while (scanner.hasNext()) {
      lines.add(scanner.nextLine());
    }
    return lines.toArray(new String[lines.size()]);
  }
  
}


Measured memory_bytes: 35696
N=int(input())
S={}
for n in range(N):
  s=input()
  S[s]=S.get(s,0)+1
  
S=sorted(S.items(), key=lambda x:(-x[1],x[0]))
maxS=S[0][1]
for s, cnt in S:
  if cnt!=maxS:
    break
  print(s)

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

int main(){
	int n, a, i, ans=0;
	cin>>n;
	for(i=0; i<n; i++){
		cin>>a;
		if(a%2!=0) ans++;
	}
	if(ans%2==0) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 256
A,B = map(int,input().split())
S = input()
ans = 0
ls = ["1","2","3","4","5","6","7","8","9","0"]
if S[A] == "-":
    for i in range(A+B+1):
        if S[i] in ls:
            ans += 1
if ans == (A+B):
    print("Yes")
else:
    print("No")

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

const double PI = 3.14159265358979323846;
//using namespace boost::multiprecision;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 1e15;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<int> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
//const ll mod = 1e10;
typedef priority_queue<string, vector<string>, greater<string> > PQ_ASK;

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

    priority_queue<ll> shopping;
    rep(i, n) {
        ll a;
        cin >> a;
        shopping.push(a);
    }

    rep(i, m) {
        ll t = shopping.top();
        shopping.pop();
        shopping.push(t / 2);
    }

    ll sum = 0;
    while (!shopping.empty()) {
        sum += shopping.top();
        shopping.pop();
    }
    cout << sum << endl;

}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
string a;
int main() {
	cin>>a;
	int len = a.length();
	for(int i = 0; i < len; i++) {
		if(a[i] == '9')a[i] = '1';
		else if(a[i] == '1')a[i] = '9';
	}
	cout<<a;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

int cmp(const void *a, const void *b) {
    return *(int*)a - *(int*)b;
}

int main() {
    int N, M, *X, *diff, ans = 0;
    if (scanf("%d %d%*c", &N, &M) == -1) return -1;
    X = (int *)malloc(sizeof(int) * M);
    diff = (int *)malloc(sizeof(int) * (M - 1));
    if (!X || !diff) return -1;
    for (int i = 0; i < M; i++) if (scanf("%d%*c", &X[i]) == -1) return -1;

    qsort(X, M, sizeof(int), cmp);
    for (int i = 0; i < M - 1; i++) diff[i] = X[i+1] - X[i];
    qsort(diff, M - 1, sizeof(int), cmp);
    for (int i = 0; i < M - N; i++) ans += diff[i];
    printf("%d\n", ans);
    free(X); free(diff);
    return 0;
}

Measured memory_bytes: 1396
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
 
//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};
 
int main()
{
	string s;
	int n;
	cin >> s >> n;

	string ring;
	int count = 0;
	REP(i, n){
		cin >> ring;
		ring += ring;

		REP(j, (int)(ring.size() - s.size())){
			if (ring.substr(j, (int)s.size()) == s){
				count++;
				break;
			}
		}

	}

	cout << count << endl;

}



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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
typedef long long ll;

int main() {
    string O,E; cin >> O >> E;
    rep(i,O.size()){
        cout << O[i];
        if(i < E.size()) cout << E[i];
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	if(n%2!=0){
    	cout << "No" << endl;
    	return 0;
    }
	string s;
	cin >> s;
	for(int i=0;i<n/2;i++){
    	if(s.at(i)!=s.at(i+n/2)){
        	cout << "No" << endl;
    		return 0;
        }
    }
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 200

int V;
vector<int> G[NUM];
int match[NUM];
bool used[NUM];

void add_edge(int from,int to){
	G[from].push_back(to);
	G[to].push_back(from);
}

int dfs(int node_id){
	used[node_id] = true;

	for(int i = 0; i < G[node_id].size(); i++){
		int adj_node_id = G[node_id][i],pair_id = match[adj_node_id];
		if((pair_id < 0)||(used[pair_id] == false && dfs(pair_id) == true)){
			match[node_id] = adj_node_id;
			match[adj_node_id] = node_id;
			return true;
		}
	}
	return false;
}


int bipartie_matching(){
	int ret = 0;
	for(int i = 0; i < V; i++)match[i] = -1;
	for(int node_id = 0; node_id < V; node_id++){
		if(match[node_id] < 0){
			for(int i = 0; i < V; i++)used[i] = false;
			if(dfs(node_id)){
				ret++;
			}
		}
	}
	return ret;
}


int main(){

	int X,Y,E;

	scanf("%d %d %d",&X,&Y,&E);

	int from,to;

	for(int loop = 0; loop < E; loop++){
		scanf("%d %d",&from,&to);
		add_edge(from,X+to);
	}

	V = X+Y;

	printf("%d\n",bipartie_matching());

	return 0;
}




Measured memory_bytes: 3384
#include <iostream>
#include <cmath>
#define N 120
typedef long long int ll;

int main(void){
	long x;
	int a = 0, b = 0;
	std::cin >> x;
	for(a = 0; a < N; a++){
		for(b = 0; b < N; b++){
			ll a5 = pow(a, 5);
			ll b5 = pow(b, 5);
			if(a5 - b5 == x){
				std::cout << a << " " << b << std::endl;
				return 0;
			}
			else if(a5 + b5 == x){
				std::cout << a << " " << b*(-1) << std::endl;
				return 0;
			}
		}
	}
}


Measured memory_bytes: 3980
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
l=[]
m=[]
ans=0
for x,y in zip(a,b):
    if x-y>=0:
        l+=[x-y]
    else:
        m+=[x-y]
        ans+=1

if ans==0:
    print(0)
    exit()
l=sorted(l,reverse=True)
msum=sum(m)
if sum(m)+sum(l)<0:
    print(-1)
    exit()

for i in l:
    msum+=i
    ans+=1
    if msum>=0:
        print(ans)
        exit()


Measured memory_bytes: 18524
#include <stdio.h>

void trace(int a[],int n){
  int i;
  for(i=0;i<n;i++){
    if(i>0)printf(" ");
    printf("%d",a[i]);
  }
  printf("\n");
}

void insertionSort(int a[],int n){
  int j,i,v;
  for(i=1;i<n;i++){
    v=a[i];
    j=i-1;
    while(j>=0 && a[j]>v){
      a[j+1]=a[j];
      j--;
    }
    a[j+1]=v;
    trace(a,n);
  }
}    

int main(){
  int N,i,j;
  int A[100];

  scanf("%d",&N);
  for(i=0;i<N;i++)
    scanf("%d",&A[i]);

  trace(A,N);
  insertionSort(A,N);

  return 0;
}

Measured memory_bytes: 604
#!/usr/bin/env python3

def main():
    na = list(map(int, input().split()))
    N, M = na[0], na[1]
    ab_list = []
    for i in range(M):
        na = list(map(int, input().split()))
        ab_list.append(na)

    ab_list.sort(key = lambda x:x[0])

    pb = N + 1
    for i in range(M - 1, -1, -1):
        b = ab_list[i][1]
        if pb <= b:
            ab_list.pop(i)
        else:
            pb = b

    pb = 1
    count = 0
    for ab in ab_list:
        if pb <= ab[0]:
            pb = ab[1]
            count += 1


    print(count)


if __name__ == '__main__':
    main()



Measured memory_bytes: 29096
a = int(input())
b = int(input())
c = int(input())
x = int(input())
ans = 0
for na in range(a+1):
  for nb in range(b+1):
    for nc in range(c+1):
      if na*500 + nb*100 + nc*50 ==x:
        ans += 1
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
#define repe(i,s,n)for(ll i = s;i<=n;i++)

int main() {
	ll N; cin >> N;
	ll A[100002];

	ll sum = 0;
	A[0] = 0, A[N + 1] = 0;
	repe(i, 1, N) {
		cin >> A[i];
		sum += abs(A[i] - A[i - 1]);
	}
	sum += abs(A[N]);

	repe(i, 0, N + 1) {
		ll t = sum;
		if (i != 0 && i != N + 1) {
			ll a = abs(A[i] - A[i - 1]);
			ll b = abs(A[i + 1] - A[i]);
			t -= a + b;
			ll c = abs(A[i + 1] - A[i -1]);
			t += c;
			cout << t << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 2048
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define repi(i, a, b) for (long long i = (long long)(a); i < (long long)(b); i++)
#define pb push_back
#define all(x) (x).begin(), (x).end()

using namespace std;

int main()
{
    int a, b, sum, arg, seki;
    cin >> a >> b;
    sum = a + b;
    arg = a - b;
    seki = a * b;

    cout << max(sum, max(arg, seki)) << endl;

    return 0;
}

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

typedef long long LL;

LL N, A, B, res;

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

    cin >> N >> A >> B;
    
    if (A == B) {
        cout << 1 << endl;
    } else if (A > B){
        cout << 0 << endl;
    } else {
        if (N == 1) {
            cout << 0 << endl;
        } else {
            LL l = N - 2;
            res += l * (B - A) + 1;
            cout << res << endl;
        }
    }
        
    
    return 0;
}


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

using namespace std;

bool is_valid(const vector<size_t> &q, size_t r) {
    for (size_t j=0; j<8; ++j)
        if (j!=r && q[j]==q[r])
            return false;

    for (size_t i=0; i<r; ++i) {
        if (q[i]-i == q[r]-r) return false;
        if (q[i]+i == q[r]+r) return false;
    }

    return true;
}

bool solve_equeen(vector<size_t> &q, size_t r=0) {
    if (r == 8) return true;

    if (!~q[r]) {
        for (size_t c=0; c<8; ++c) {
            q[r] = c;
            if (is_valid(q, r))
                if (solve_equeen(q, r+1))
                    return true;
        }
        q[r] = -1;
    } else {
        if (is_valid(q, r))
            if (solve_equeen(q, r+1))
                return true;
    }

    return false;
}

int main() {
    size_t k;
    scanf("%zu", &k);

    vector<size_t> q(8, -1);
    for (size_t i=0; i<k; ++i) {
        size_t r, c;
        scanf("%zu %zu", &r, &c);

        q[r] = c;
    }

    solve_equeen(q);

    for (size_t i=0; i<8; ++i)
        for (size_t j=0; j<8; ++j)
            printf("%c%s", q[i]==j? 'Q':'.', j<7? "":"\n");

    return 0;
}

Measured memory_bytes: 2752
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

INF = float('inf')

def solve():
    n, m = MI()
    H = LI()
    S = [True] * n
    for i in range(m):
        a, b = MI1()
        # print(H[a], H[b])
        if H[a] > H[b]:
            S[b] = False
        elif H[a] < H[b]:
            S[a] = False
        else:
            S[a] = S[b] = False
    # print(S)
    print(sum(S))


if __name__ == '__main__':
    solve()


Measured memory_bytes: 20152
"use strict";
process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = []
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

reader.on('line', (line) => {
  lines.push(line);
});
/* 入力は 
123
55
1000
0
*/

reader.on('close', () => {
    for (var line of lines) {
	if (line==="0") {
	    break;
	}
	console.log(aux(line));
    }
});

function aux(s)
{
    return(s.split('').map(Number).reduce((s,x)=>{return s+x}))
}


Measured memory_bytes: 18172
// V solo
#include <bits/stdc++.h>

#define forn(i, a, b) for (int i = a; i <= b; ++i)
#define forr(i, a, b) for (int i = a; i >= b; --i)

using namespace std;

const int N = (int)2e5 + 1;
const long long INF = 1e18;

typedef long long ll;
typedef long double ld;

typedef pair < int, int > pii;
typedef pair < ll, ll > pll;

int n, a[N];
pll res1[N], res2[N];
ll pr[N];

ll s (int l, int r){
  return pr[r] - pr[l - 1];
}

int main (){
  scanf ("%d", &n);
  forn (i, 1, n){
    scanf ("%d", a + i);
    pr[i] = pr[i - 1] + a[i];
  }
  int ind = 1;
  forn (i, 2, n){
    while (ind + 1 < i && abs(s(1, ind) - s(ind + 1, i)) >= abs(s(1, ind + 1) - s(ind + 2, i)))ind++;
    res1[i] = {s(1, ind), s(ind + 1, i)};
    //cout << ind << "\n";
  }
  //cout << "ok\n";
  ind = n;
  forr (i, n - 1, 1){
    while (ind - 1 > i && abs(s(ind, n) - s(i, ind - 1)) >= abs(s(ind - 1, n) - s(i, ind - 2))) ind--;
    res2[i] = {s(ind, n), s(i, ind - 1)};
  }
  ll ans = INF;
  forn (i, 2, n - 2){
    ll cur1 = max(max(res1[i].first, res1[i].second), max(res2[i + 1].first, res2[i + 1].second));
    ll cur2 = min(min(res1[i].first, res1[i].second), min(res2[i + 1].first, res2[i + 1].second));
    ans = min(ans, cur1 - cur2);
  }
  printf ("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 8832
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define mod 1000000007
#define modulo 998244353
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
ll fact[2*100000+7];
ll power[2*100000+7];
void factorial()
{
    fact[0]=1;
    ll i;
    for(i=1;i<=2*100000;i++)
    {
        fact[i]=(i*fact[i-1])%modulo;
    }
}
void power1(ll m,ll n)
{
    power[0]=1;
    ll i;
    for(i=1;i<=n;i++)
    {
        power[i]=(power[i-1]*m)%modulo;
    }
}
ll powerr(ll x,ll y)
{
    ll ml=1;
    while(y>0)
    {
        if(y&1)
        {
            ml=(ml*x)%modulo;
        }
        x=(x*x)%modulo;
        y/=2;
    }
    return ml;
}
ll inverse(ll x)
{
    return powerr(x,modulo-2);
}
int main()
{
    FAST;
    ll n,m,k,i,j,l;
    cin>>n>>m>>k;
    factorial();
    power1(m-1,n);
    ll sm=0;
    for(i=k;i>=0;i--)
    {
        ll x=fact[n-1];
        ll y=inverse((fact[n-1-i]*fact[i])%modulo);
        ll p=power[n-1-i];
        sm=(sm+(((((x*y)%modulo)*m)%modulo)*p)%modulo)%modulo;
    }
    // ll sm1=powerr(m,n);
    // ll sm2=(sm1-sm+modulo)%modulo;
    cout<<sm;
}

Measured memory_bytes: 6776
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
#define INF 1e9 //10^9
#define MOD 1000000007
#define INFL 100000000000000000//10^18 = 2^60


int main(void){
    int N;
    cin >> N;
    vector<ll> vec(5, 0);
    for(int i = 0; i < N; i++){
        string S;
        cin >> S;
        if(S[0] == 'M') vec[0]++;
        if(S[0] == 'A') vec[1]++;
        if(S[0] == 'R') vec[2]++;
        if(S[0] == 'C') vec[3]++;
        if(S[0] == 'H') vec[4]++;
    }
    ll ans = 0;
    for(int i = 0; i < 5; i++){
        for(int j = i+1; j < 5; j++){
            for(int h = j+1; h < 5; h++){
                ans += vec[i] * vec[j] * vec[h];
            }
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int w = in.nextInt();
        int h = in.nextInt();
        int n = in.nextInt();
//        int[] x = new int[n];
//        int[] y = new int[n];
//        int[] a = new int[n];
        int e = 0, f = 0;
        for (int i = 0; i < n; i++) {
            int x = in.nextInt();
            int y = in.nextInt();
            int a = in.nextInt();
            if(a == 1){
                if(e < x)
                    e = x;
            }
            else if(a == 2){
                if(w > x)
                    w = x;
            }
            else if(a == 3) {
                if(f < y)
                    f = y;
            }
            else{
                if(h > y)
                    h = y;
            }
        }
        int b = (int)Math.sqrt(Math.pow(f - h, 2));
        int l = (int)Math.sqrt(Math.pow(e - w, 2));
//        System.out.println(e + " " + f);
//        System.out.println(w + " " + h);
        if(e < w && f < h)
            System.out.println(l * b);
        else{
            System.out.println("0");
        }
    }
}


Measured memory_bytes: 27648
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using in6 = int64_t;
using ind = double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int n;
  cin >> n;
  vi data(n);
  rep(i,n) cin >> data[i];
  int check = 0;
  rep(i,n) {
    if(data[i] % 2 == 1) {
      check++;
      continue;
    }
    else if(data[i] % 3 == 0 || data[i] % 5 == 0) {
      check++;
      continue;
    }
    else continue;
  }
  if(check == n) cout << "APPROVED" << endl;
  else cout << "DENIED" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;

int main() {
  int n;
  cin >> n;
  vector<int> x(n);
  for (int i = 0; i < n; ++i) {
    cin >> x[i];
  }
  int mn = INF;
  for (int p = 1; p <= 100; ++p) {
    int y = 0;
    for (int i = 0; i < n; ++i) {
      y += (x[i] - p) * (x[i] - p);
    }
    mn = min(mn, y);
  }
  cout << mn << endl;
}


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

#define PI 4*atan(1)
#define INF 1e8

typedef long long ll;

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

int main(){
  int n;
  while(cin >> n, n){
    vector<pair<int, int>> I(n);
    int t, w;
    for(int i = 0; i < n; i++){
      cin >> t >> w;
      I.push_back(make_pair(w, t));
    }
    sort(I.begin(), I.end());
    int a = 0;
    bool flag = true;
    for(int i = 0; i < I.size(); i++){
      a += I[i].second;
      if(a > I[i].first){
        flag = false;
      }
    }
    if(flag)cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}

Measured memory_bytes: 3036
S = input()
p = 10 ** 9 + 7
DP = [0, 0, 0, 1]
dp = [0] * 4
for i in range(len(S) - 1, -1, -1):
  for j in range(3, -1, -1):
    if j == 3:
      dp[j] = DP[3] * (3 if S[i] == '?' else 1) % p
    elif S[i] == '?':
      dp[j] = (3 * DP[j] + DP[j + 1]) % p
    elif S[i] == chr(65 + j):
      dp[j] = (DP[j] + DP[j + 1]) % p
    else:
      dp[j] = DP[j]
  DP = [x for x in dp]
print(DP[0] % p)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e19;
const int MOD = (int)1e9 + 7;

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

    int s;
    cin >> s;
    map<int, int> mp;
    int ans = 1;
    while(mp[s] == 0){
        mp[s]++;
        s = (s&1 ? 3*s+1 : s/2);
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int k,ans;
int gcd(int a,int b){return b==0?a:gcd(b,a%b);}
int main()
{
    cin>>k;
    for(int i=1;i<=k;i++)for(int j=1;j<=k;j++)for(int l=1;l<=k;l++)ans+=gcd(gcd(i,j),l);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3564
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const int mod = 1000000007;
const int inf = 1ll << 61;
typedef pair<int, int> P;
typedef pair<int, P>PP;

signed main() {
	int a, b, c; cin >> a >> b >> c;
	if (a + b + c > 21)puts("bust");
	else puts("win");
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
#define ll long long
#define pi acos(-1.0)
#define pb push_back
#define vi vector<int>
#define mapii map<int , int>
#define mapci map<char, int>
#define mapsi map<string,int>
#define FOR(i,n) for(int i = 0;i<n;i++)
#define CP(n) cout<<"Case "<<n<<": "
#define fr freopen("input.txt","r",stdin)
#define fw freopen("output.txt","w",stdout)
#define MAX 1000007
#define all(x)(x.begin(),x.end())
#define debug(x,c) cout<<x<<": "<<c<<" ";
#define fast_io ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
int main()
{
	int n;
	cin>>n;
	int r = n%10;
	if(r == 3)
		cout<<"bon"<<endl;
	else if(r == 0 || r == 1 ||r == 6 ||r == 8 )
		cout<<"pon"<<endl;
	else
		cout<<"hon"<<endl;
	return 0;
}


Measured memory_bytes: 3608
#include<stdio.h>
int main(void){
  while(1){
  int i ,total,m[9];
  scanf("%d",&total);
  if(total == 0) break;
  else{
  for(i=0;i<9;i++){
    scanf("%d",&m[i]);
    total -= m[i];
  }
  printf("%d\n",total);
  }
  }
  return 0;
}


Measured memory_bytes: 2036