akhauriyash/Code-Regression huggingface dataset:
import java.util.HashMap;
import java.util.Scanner;

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

        java.util.Map<Integer, Integer> oddMap = new HashMap<>();
        java.util.Map<Integer, Integer> evenMap = new HashMap<>();

        oddMap.put(0,0);
        evenMap.put(0,0);
        int currentKey = 0;
        for (int i = 0; i < n; i++) {
            currentKey = sc.nextInt();
            if (i % 2 == 0) {
                oddMap.put(currentKey, oddMap.getOrDefault(currentKey, 0) + 1);
            } else {
                evenMap.put(currentKey, evenMap.getOrDefault(currentKey, 0) + 1);
            }
        }

        int o1_k = -1;
        int e1_k = -1;
        int o2 = -1;
        int e2 = -1;

        int o1 = -1;
        int e1 = -1;

        for (java.util.Map.Entry<Integer, Integer> entry : oddMap.entrySet()) {
            if (entry.getValue() > o1) {
                o2 = o1;
                o1_k = entry.getKey();
                o1 = entry.getValue();
            } else if (entry.getValue() > o2){
                o2 = entry.getValue();
            }
        }

        for (java.util.Map.Entry<Integer, Integer> entry : evenMap.entrySet()) {
            if (entry.getValue() > e1) {
                e2 = e1;
                e1_k = entry.getKey();
                e1 = entry.getValue();
            } else if (entry.getValue() > e2){
                e2 = entry.getValue();
            }
        }

        if (o1_k == e1_k) {
            System.out.println(Math.min(n - o2 - e1, n - o1 - e2));
        } else {
            System.out.println(n - o1 - e1);
        }


    }
}

Measured memory_bytes: 64032
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
map<ll, ll> prime_factor(ll n) {
	map<ll, ll> ret;
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}

//const long long MOD = 1000000007;
const long long MOD = 998244353;
const long long INF = 1LL << 60;



const long double PI = 3.14159265359;
const int MAX_N = 100010;


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	VE a(3); rep(i, 3)cin >> a[i];
	sort(ALL(a));
	cout << a[0] + a[1] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

pair<ll, int> naive(int a, int b, ll c) {
  ll res = 0; 
  while (c > 0) {
    int s = a + b;
    ++res;
    --c;
    while (s > 9) {
      int ns = (s / 10) + (s % 10);
      ++res;
      s = ns;
    }
    a = s;
  }
  return { res, a };
}

pair<ll, int> solve(int a, int b, ll c) {
  ll res = 0;
  vector<ll> mem_c(10, -1), mem_res(10, -1);
  while (c > 0) {
    if (mem_c[a] != -1) {
      ll use_c = mem_c[a] - c;
      ll cost = res - mem_res[a];
      ll cnt = c / use_c;
      res += cnt * cost;
      c -= cnt * use_c;
      auto v = naive(a, b, c);
      res += v.fst;
      a = v.snd;
      break;
    }
    mem_c[a] = c;
    mem_res[a] = res;
    int s = a + b;
    ++res;
    --c;
    while (s > 9) {
      int ns = (s / 10) + (s % 10);
      ++res;
      s = ns;
    }
    a = s;
  }
  return {res, a};
}

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int M;
  while (cin >> M) {
    ll res = 0;
    int a = 0;
    for (int i = 0; i < M; i++) {
      int d;
      ll c;
      cin >> d >> c;
      auto r = solve(a, d, c);
      res += r.fst;
      a = r.snd;
    }
    cout << res - 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
/*

*/
int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  
  ll N; cin>>N;
  N %= 10;
  if (N == 3)
    cout<<"bon"<<endl;
  else if(N==0 || N==1 || N==6 || N==8)
    cout<<"pon"<<endl;
  else
    cout<<"hon"<<endl;
}


Measured memory_bytes: 3644
#include<iostream>
using namespace std;
int main(){
	int h, w;
	char draw;
	while (true){
		cin >> h >> w;
		if (h == 0 && w == 0){
			break;
		}
		for (int i = 0; i < h; i++){
			if (i % 2 == 0){
				draw = '#';
			}
			else{
				draw = '.';
			}
			for (int j = 0; j < w; j++){
				cout << draw;
				if (draw=='.'){
					draw = '#';
				}
				else{
					draw = '.';
				}
			}
			cout << endl;
		}
		cout << endl;
	}
}


Measured memory_bytes: 3084
// ConsoleApplication1.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include<vector>
using namespace std;

int main()
{
	int n, x;
	cin >> n;
	int a[4][15] = {};
	char s;
	for (int i = 0; i < n; i++)
	{
		cin >> s >> x;

		if (s == 'S') {
			a[0][x] = 1;

		}
		if (s == 'H') {
			a[1][x] = 1;

		}
		if (s == 'C') {
			a[2][x] = 1;

		}
		if (s == 'D') {
			a[3][x] = 1;

		}

	}
	for (int i = 0; i < 4; i++) {
		for (int j = 1; j < 14; j++) {
			if (a[i][j] == 0) {
				if (i==0) {
					cout << "S " << j << endl;

				}else if (i == 1) {
					cout << "H " << j << endl;

				}else if (i == 2) {
					cout << "C " << j << endl;

				}else if (i == 3) {
					cout << "D " << j << endl;

				}
			}


		}
	}
}
// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント: 
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します 
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します



Measured memory_bytes: 3072
import java.util.*;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            // in
            int N = Integer.parseInt(sc.next());
            long[] A = new long[N];
            for (int i = 0; i < N; i++) {
                A[i] = Integer.parseInt(sc.next());
            }

            // calc
            long sum = 0;
            for (int i = 1; i < N; i++) {
                long sub = A[i-1] - A[i];
                if (sub > 0) {
                    A[i] += sub;
                    sum += sub;
                }
            }
            System.out.println(sum);
        }
    }
}

Measured memory_bytes: 60824
#include <iostream>
#include <vector>
#include <algorithm>
#include <list>
#include <map>
using namespace std;

int main(){
    
    long long AC[220000];
    long long ac_sum = 0;
    for(int i = 0; i < 220000 ; i++){
        ac_sum += i;
        AC[i] = ac_sum;
    }
    
    int N;
    int A[220000];
    cin >> N;

    vector<long long> SUM;
    long long sum = 0;
    SUM.push_back(sum);
    for(int i = 0 ; i < N ; i++){
        cin >> A[i];
        sum += A[i];
        SUM.push_back(sum);
    }

    long long all_count = 0;
    map<long long, int> mp;
    for(auto s : SUM){
        auto fitr = mp.find(s);
        if(fitr != mp.end()){
            mp[s] += 1;
        } else{
            mp[s] = 1;
        }
    }

    for(auto _mp : mp){
        for(int i = 1 ; i < _mp.second ; i++){
            all_count += i;
        }
    }

    cout << all_count << endl;

    return 0;
}


Measured memory_bytes: 15088
#include <iostream>
#include <iomanip> //setprecision()
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <set>
using ll = long long;
using namespace std;

double Mcos(double k){return cos(k*atan(1.0)*4/180);}

void monmo(){
    
}

int main() {
    int n;
    char s;
    cin>>s;
    if(isupper(s))cout<<"A";
    else cout<<"a";
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
typedef pair<int,int>P;
typedef pair<int,P>P2;
#define fi first
#define se second
 
signed main(){
  int n,k;
  cin>>n>>k;
 
  if(k==0){
    r(i,(1<<n)){
      if(i)cout<<' ';
      cout<<i<<' '<<i;
    }
    cout<<endl;
    return 0;
  }
 
  if(pow(2,n)<=k){
    cout<<-1<<endl;
    return 0;
  }
 
  int s=0;
  r(i,(1<<n))if(i!=k)s^=i;

 
  if(s!=k){
    cout<<-1<<endl;
    return 0;
  }
 
  cout<<k;
  for(int i=(1<<n)-1;i>=0;i--){
    if(i==k)continue;
    cout<<' '<<i;
  }
  cout<<' '<<k;
  r(i,(1<<n)){
    if(i==k)continue;
    cout<<' '<<i;
  }
  cout<<endl;
 
}

Measured memory_bytes: 1792
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long li;

const int maxn = 1e5;
int n, a[3 * maxn];

int main(void) {
  scanf("%d", &n);
  for (int i = 0; i < 3 * n; ++i) scanf("%d", a + i);
  sort(a, a + 3 * n);
  li ans = 0;
  for (int i = 0, j = 3 * n - 2; i < n; ++i, j -= 2) {
    ans += a[j];
  }
  printf("%lld\n", ans);
}


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

int main(){
  int N, W;
  cin >> N >> W;
  W++;
  
  vector<int> v(N), w(N);
  vector<long> dp(W, 0);
  
  for(int i=0; i<N; i++){
    cin >> w[i] >> v[i];
  }
  
  for(int i=0; i<N; i++){
    for(int s=W-1; s>=w[i]; s--){
      dp[s] = max(dp[s], dp[s-w[i]] + v[i]);
    }
  }
  
  cout << dp[W-1] << endl;
  return 0;
}

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left != NIL){
    x=x->left;
  }
  return x;
}
Node treeMaximum(Node x){
  while(x->right != NIL){
    x=x->right;
  }
  return x;
}
Node treeSearch(Node u, int k){
  if(u==NIL||k==u->key){
    return u;
  }
  if(k<u->key){
      return treeSearch(u->right,k);
    }
}
Node treeSuccessor(Node x){
  Node y;
  if(x->right !=NIL){
    return (Node)treeMinimum(x->right);
  }
  y=x->parent;
  while(y !=NIL && x==y->right){
    x=y;
    y=y->parent;
    }
  return y;
}
void treeDelete(Node z){
  Node y; // node to be deleted                                                 
  Node x; // child of y                                                         

  if(z->left ==NIL || z->right ==NIL){
    y=z;
  }
  else{
    y=(Node)treeSuccessor(z);
  }
  if(y->left !=NIL){
    x=y->left;
  }
  else{
    x=y->right;
  }
  if(x !=NIL){
    x->parent=y->parent;
  }
  if(y->parent ==NIL){
    root=x;
  }
  else if(y==y->parent->left){
    y->parent->left;
  }
  else{
    y->parent->right=x;
  }
  if(y != z){
    z->key=y->key;
  }
}
void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x !=NIL){
    y=x;
    if(z->key <x->key){
      x=x->left;
    }
    else{
      x=x->right;
    }
}
  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->left !=NIL){
      inorder(u->left);
  }
    printf(" %d",u->key);
  if(u->right !=NIL){
    inorder(u->right);
  }
  }
void preorder(Node u){
  printf(" %d",u->key);
  if(u->left !=NIL){
    preorder(u->left);
  }
  if(u->right !=NIL){
    preorder(u->right);
  }
 }
 int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 25140
#include <stdio.h>
#include <math.h>
int main(void){
	double r;
	scanf("%lf",&r);
	
	double S=r*r*M_PI;
	double L=2*r*M_PI;
	
	printf("%lf %lf\n",S,L);
	return 0;
	
	}

Measured memory_bytes: 648
x1,y1,x2,y2=map(int,input().split())
def addrad(a,b):
    return -b,a
#B 0 base and get C with addrad*3

x=x1-x2
y=y1-y2
x,y=addrad(x,y)
x,y=addrad(x,y)
x,y=addrad(x,y)
x+=x2
y+=y2
cx=x
cy=y


#A 0 base and get D with addrad*1
x=x2-x1
y=y2-y1
x,y=addrad(x,y)
x+=x1
y+=y1
dx=x
dy=y
print('{} {} {} {}'.format(cx,cy,dx,dy))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m; i >= n; --i)
#define ALL(v) (v).begin(),(v).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
	int n,a;cin >> n >> a;
	vector<int> x(n);
	REP(i,n) cin >> x[i];
	vector<vector<vector<ll>>> dp(n+1,vector<vector<ll>>(n+1,vector<ll>(2501)));
	dp[0][0][0]=1;
	REP(i,n){
		REP(j,n){
			REP(k,2501){
				if(!dp[i][j][k]) continue;
				dp[i+1][j][k]+=dp[i][j][k];
				dp[i+1][j+1][k+x[i]]+=dp[i][j][k];
			}
		}
	}
	ll ans=0;
	FOR(i,1,n+1){
		ans+=dp[n][i][i*a];
	}
	cout << ans << endl;
}

Measured memory_bytes: 55188
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

using namespace std;
typedef long long ll;

ll N, Q;

bool fixed_h[200001];
bool fixed_w[200001];

ll cnt_h[200001];
ll cnt_w[200001];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N >> Q;
    ll ans = (N-2)*(N-2);
    ll cur_w = N;
    ll cur_h = N;
    for(int i = 0; i < Q; i++){
        int q, x; cin >> q >> x;
        if(q == 1){
            if(x < cur_w){
                ans -= (cur_h-2);
                for(int w = x; w < cur_w; w++) cnt_w[w] = cur_h;
                cur_w = x;
            }else{
                ans -= (cnt_w[x]-2);
            }
        }else{
            if(x < cur_h){
                ans -= (cur_w-2);
                for(int h = x; h < cur_h; h++) cnt_h[h] = cur_w;
                cur_h = x;
            }else{
                ans -= (cnt_h[x]-2);
            }
        }
    }
    cout << ans << endl;
}

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

ll modpower(ll a, ll r, ll mod){ //a^r
    ll x = 1;
    a %= mod;
    while (r > 0) {
        if (r & 1) x = x * a % mod;
        r >>= 1;
        a = a * a % mod;
    }
    return x;
}

ll modinv(ll a, ll mod){
    return modpower(a, mod-2, mod);
}

int main(){
    int N, K;
    cin >> N >> K;
    ll mod = 1e9+7;
    vector<pair<ll, ll>> A(N);
    bool negaonly = true;
    bool zero = false;
    for (int i = 0; i < N; i++) {
        ll T;
        cin >> T;
        A[i] = {abs(T), T};
        if (T > 0) negaonly = false;
        if (T == 0) zero = true;
    }
    sort(A.begin(), A.end(), greater<pair<ll, ll>>());
    
    
    if (negaonly && K%2 == 1) {
        if (zero) {
            cout << 0 << endl;
            return 0;
        }else {
            ll ans = 1;
            for (int i = 0; i < K; i++) {
                ans *= A[N-1-i].second;
                ans = (ans%mod+mod)%mod;
            }
            cout << ans << endl;
            return 0;
        }
    }
    
    if (N == K) {
        ll ans = 1;
        for (int i = 0; i < K; i++) {
            ans *= A[i].second;
            ans = (ans%mod+mod)%mod;
        }
        cout << ans << endl;
        return 0;
    }
    
    ll cand = 1;
    bool nega = false;
    for (int i = 0; i < K; i++) {
        cand *= A[i].second;
        cand = (cand%mod+mod)%mod;
        if (A[i].second < 0) nega = !nega;
    }
    
    if (!nega) {
        cout << cand << endl;
        return 0;
    }
    
    ll n1=-1, n2 = -1, p1 = -1, p2 = -1;
    for (int i = K-1; i >= 0; i--) {
        if (p1 == -1 && A[i].second >= 0) p1 = A[i].first;
        if (n1 == -1 && A[i].second <= 0) n1 = A[i].first;
    }
    for (int i = K; i < N; i++) {
        if (p2 == -1 && A[i].second >= 0) p2 = A[i].first;
        if (n2 == -1 && A[i].second <= 0) n2 = A[i].first;
    }
    
    if (p1 == -1 || n2 == -1 || n2 == 0) {
        cand *= modinv(mod-n1, mod) * p2 % mod;
        cand = (cand%mod+mod)%mod;
    }else if (n1 == -1 || p2 == -1 || p2 == 0) {
        cand *= modinv(mod-p1, mod) * n2 % mod;
        cand = (cand%mod+mod)%mod;
    }else {
        if (n2 == 0 && p2 == 0) {
            cout << 0 << endl;
            return 0;
        }
        if (n1*n2 > p1*p2) {
            cand *= modinv(mod-p1, mod) * n2 % mod;
        }else {
            cand *= modinv(mod-n1, mod) * p2 % mod;
        }
        cand = (cand%mod+mod)%mod;
    }
    cout << cand << endl;
    
    return 0;
}

Measured memory_bytes: 6420
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    //*
    int a, b, c;
    cin >> a >> b >> c ;
    //*/

    /*
    vector<int> vec(3);
    cin >> vec.at(0) >> vec.at(1) >> vec.at(2) ;
    
    sort(vec.begin(), vec.end());
    //*/
    
    /*
    if( a < 3200 ){
        cout << "red" << endl;
    } else {
        cout << str << endl;
    }
    //*/
    
    cout << max(c - a + b, 0) << endl;

    return 0; 
}


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

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

long int M = 1e+9+7;
int main(void){
    int w,h,n;
    cin >> w >> h >> n;
    vi x(n),y(n),a(n);
    int l=0,r=w,u=h,d=0;
    rep(k,n){
        cin >> x[k] >> y[k] >> a[k];
        if(a[k]==1) chmax(l,x[k]);
        else if(a[k]==2) chmin(r,x[k]);
        else if(a[k]==3) chmax(d,y[k]);
        else chmin(u,y[k]);
    }
    int ww=0,hh=0;
    chmax(ww, (r-l));
    chmax(hh, (u-d));
    cout << ww*hh << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			String str = sc.next();
			int a = Integer.parseInt(str.substring(0, 1));
			int b = Integer.parseInt(str.substring(1, 2));
			int c = Integer.parseInt(str.substring(2, 3));
			int d = Integer.parseInt(str.substring(3, 4));
			String ans = null;
			for (int i = 0; i < 8; i++) {
				int tmp = a;
				StringBuilder sb = new StringBuilder(String.valueOf(a));
				if ((i & (1 << 0)) == 0) {
					tmp += b;
					sb.append("+");
					sb.append(String.valueOf(b));
				} else {
					tmp -= b;
					sb.append("-");
					sb.append(String.valueOf(b));
				}
				if ((i & (1 << 1)) == 0) {
					tmp += c;
					sb.append("+");
					sb.append(String.valueOf(c));
				} else {
					tmp -= c;
					sb.append("-");
					sb.append(String.valueOf(c));
				}
				if ((i & (1 << 2)) == 0) {
					tmp += d;
					sb.append("+");
					sb.append(String.valueOf(d));
				} else {
					tmp -= d;
					sb.append("-");
					sb.append(String.valueOf(d));
				}
				if (tmp == 7) {
					sb.append("=7");
					ans = sb.toString();
					break;
				}
			}
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 26900
#include<stdio.h>
#include<queue>
#include<string.h>
const int N=2e5+10;
using namespace std;

struct Edge{
    int to,nex;
}e[N<<1];

int head[N],cnt;
void add_edge(int u,int v){
    e[cnt].to=v,e[cnt].nex=head[u],head[u]=cnt++;
}

queue<int>que;
int dis[N];
bool vis[N];
void spfa(int s){
    for(int i=1;i<N;i++) dis[i]=N;
    dis[s]=0;
    que.push(s);
    vis[s]=1;
    while(!que.empty()){
        int u=que.front();
        que.pop();
        vis[u]=0;
        for(int i=head[u];~i;i=e[i].nex){
            int v=e[i].to;
            if(dis[v]>dis[u]+1){
                dis[v]=dis[u]+1;
                if(!vis[v]) que.push(v),vis[v]=1;
            }
        }
    }
}

void solve(){
    int n,m;
    scanf("%d%d",&n,&m);
    memset(head,-1,sizeof(head));
    for(int i=1;i<=m;i++){
        int u,v;
        scanf("%d%d",&u,&v);
        add_edge(u,v);
        add_edge(v,u);
    }
    spfa(1);
    if(dis[n]==2)printf("POSSIBLE\n");
    else printf("IMPOSSIBLE\n");
}

int main(){
    solve();
}


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



// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    int N;
    cin >> N;
    bool flag = true;
    for (int i=0;i<N;i++){
        int A;
        cin >> A;
        if (A%2==0){
            if (A%3!=0 && A%5!=0){
                flag =false;
                break;
            }
        }
    }
    if (flag){
        printf("APPROVED\n");
    }else{
        printf("DENIED\n");
    }
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline


def main():
    A = [list(map(int, input().split()))for _ in range(3)]
    N = int(input())
    B = [int(input()) for _ in range(N)]
    for bn in B:
        for i in range(len(A)):
            for j in range(len(A[i])):
                if bn == A[i][j]:
                    A[i][j] = 0
    for m in range(len(A)):
        if all(A[m][n] == 0 for n in range(len(A))):
            print("Yes")
            exit()
        if all(A[n][m] == 0 for n in range(len(A))):
            print("Yes")
            exit()
        if all(A[n][n] == 0 for n in range(len(A))):
            print("Yes")
            exit()
        if all(A[n][len(A)-n-1] == 0 for n in range(len(A))):
            print("Yes")
            exit()
    print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<cstdio>
#include<algorithm>
using namespace std;
const int M=2e5+7;
int read(){
	int ans=0,f=1,c=getchar();
	while(c<'0'||c>'9'){if(c=='-') f=-1; c=getchar();}
	while(c>='0'&&c<='9'){ans=ans*10+(c-'0'); c=getchar();}
	return ans*f;
}
int n,s[M],v1[M],v2[M];
int main(){
	n=read();
	for(int i=1;i<=n;i++){
		s[i]=read();
		if(i&1) v1[s[i]]++;
		else v2[s[i]]++;
	}
	int id1=0,cnt1=0,id2=0,cnt2=0;
	for(int i=1;i<=1e5;i++) if(v1[i]>cnt1) cnt1=v1[i],id1=i;
	for(int i=1;i<=1e5;i++) if(i!=id1&&v1[i]>cnt2) cnt2=v1[i],id2=i;
	int id3=0,cnt3=0,id4=0,cnt4=0;
	for(int i=1;i<=1e5;i++) if(v2[i]>cnt3) cnt3=v2[i],id3=i;
	for(int i=1;i<=1e5;i++) if(i!=id3&&v2[i]>cnt4) cnt4=v2[i],id4=i;
	if(id1!=id3) printf("%d\n",n-cnt1-cnt3);
	else printf("%d\n",n-cnt1-max(cnt2,cnt4));
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)

const ll mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;

using namespace std;

int a[86][86],b[86][86],c[86][86];
bool ok[81][81][25602];

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int h,w; cin >> h >> w;
	rep(i,h)rep(j,w)cin >> a[i][j];
	rep(i,h)rep(j,w)cin >> b[i][j];
	rep(i,h)rep(j,w)c[i][j] = abs(a[i][j]-b[i][j]);
	int T = 12800;
	ok[0][0][T-c[0][0]] = true;
	ok[0][0][T+c[0][0]] = true;
	rep(i,h){
		rep(j,w){
			for(int k=0;k<=T*2;k++){
				if(ok[i][j][k]){
					if(j!=w-1){
						ok[i][j+1][k+c[i][j+1]] = true;
						ok[i][j+1][k-c[i][j+1]] = true;
					}
					if(i!=h-1){
						ok[i+1][j][k+c[i+1][j]] = true;
						ok[i+1][j][k-c[i+1][j]] = true;
					}
				}
			}
		}
	}
	rep(i,T+1){
		if(ok[h-1][w-1][i+T]||ok[h-1][w-1][T-i]){
			cout << i << endl;
			return 0;
		}
	}
}

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

using namespace std;


int main(){
	int a,b;
	cin>>a>>b;
	if(b>a){
	cout<<2*b-1;
	}
	else if(a==b){
		cout<<2*a;
	}
	else if(a>b){
		cout<<2*a-1;
	}
}

Measured memory_bytes: 3544
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define F first
#define S second
#define um map <ll,ll>
#define rep(i,z,n)  for(int i=z;i<n;i++)
#define repi(i,z,n) for(int i=z;i<=n;i++)
#define repn(i,z,n) for(int i=n-1;i>=z;i--)
#define vec vector<ll>
#define vecp vector<pair<ll,ll>>
#define pi (double)3.14159265358979323846
#define ld long double
#define all(z) z.begin(),z.end()

ll power(ll a, ll b, ll m) { ll ans = 1; a = a % m; if (a == 0) return 0; while (b) { if (b & 1) ans = (ans * a) % m; b /= 2; a = (a * a) % m; } return ans; }
ll modInverse(ll a, ll m) {return power(a, m - 2, m);}
ll binpow(ll a, ll b) {ll res = 1; while (b > 0) {if (b & 1)res = res * a; a = a * a; b >>= 1;} return res;}
ll binlog2(ll n) {ll logValue = -1; while (n) {logValue++; n >>= 1;} return logValue;}
void print(vec a) {rep(i, 0, a.size())cout << a[i] << " "; cout << endl;}
const ll mod = 1e9 + 7;
const ll N = 1e5 + 5;
const ll inf = 2e18;




void solve() {
    ll n, k;
    cin >> n >> k;
    vec a(n);
    rep(i, 0, n)
    cin >> a[i];
    vec dp(n, inf);
    dp[0] = 0;
    rep(i, 1, n) {
        repi(j, 1, k) {
            int t1 = i - j;
            if (t1 < 0)
                break;
            else {
                dp[i] = min(dp[i], dp[t1] + abs(a[i] - a[t1]));
            }
        }

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


}





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

    speed;
    int test = 1;
    // cin >> test;
    while (test--) {
        // cout << "Case #" << t1 << ": ";
        solve();
    }
    return 0;
}

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

int main(void){
    int N,M;
    cin >> N >> M;
    int H[N];
    rep(i,N) cin>>H[i];
    int A[M],B[M],C[M]={},D[M]={};
    int bicount = 0;
    rep(i,M){
        cin >> A[i] >> B[i];
        if(H[A[i]-1]>H[B[i]-1]){
            int tmp = A[i];
            A[i] = B[i];
            B[i] = tmp;
        }
        if(H[A[i]-1]==H[B[i]-1]){
            C[i] = A[i];
            D[i] = B[i];
        }
    }
    int count[N]={};
    rep(i,M){
        count[A[i]-1] = 1;
        if(C[i]!=0) count[C[i]-1] = 1;
        if(D[i]!=0) count[D[i]-1] = 1;
        
    }
    int ans = N;
    rep(i,N) ans-=count[i];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5968
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define BOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
typedef long long ll;

ll dp[2001][2001];

int main(){
    
    ll N,x;
    cin>>N>>x;
    REP(i,N)cin>>dp[0][i];
    
    for(int i=1;i<N;i++){
        for(int j=0;j<N;j++){
            dp[i][j]=min(dp[i-1][j],dp[0][(N+j-i)%N]);
        }
    }
    
    REP(i,N){
        dp[i][0]+=i*x;
        for(int j=1;j<N;j++){
            dp[i][0]+=dp[i][j];
        }
    }
    
    ll ans=1e18;
    REP(i,N)ans=min(ans,dp[i][0]);
    
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 31488
N, M = gets.split(' ').map(&:to_i)
x = gets.split(' ').map(&:to_i)
x.sort!
y = []
(M - 1).times do |i|
  y.push(x[i + 1] - x[i])
end
y.sort!

ans = 0
if N < M
  ans = y[0..(M - N - 1)].inject(:+)
end

puts ans

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

int main(){
  int a, b;
  cin >> a >> b;
  --a; --b;
  cout << 100 << " " << 100 << endl;
  vector<string> s1(100,"..................................................");
  vector<string> s2(100,"##################################################");
  
  for(int i=0; i<100; i+=2){
    if(a == 0) break;
    for(int j=49; j>=0; j-=2){
      if(a == 0) break;
      s2[i][j] = '.';
      --a;
    }
  }
  for(int i=0; i<100; i+=2){
    if(b == 0) break;
    for(int j=0; j<50; j+=2){
      if(b == 0) break;
      s1[i][j] = '#';
      --b;
    }
  }
  for(int i=0; i<100; ++i){
    cout << s1[i] << s2[i] << endl;
  }
}

Measured memory_bytes: 3656
n,l=map(int,input().split())
taste_list=[]
for i in range(1,n+1):
    taste_list.append(l+i-1)
taste=sum(taste_list)
if taste_list[0]>0:
    print(taste-taste_list[0])
elif 0 in taste_list:
    print(taste)
else:
    print(taste-taste_list[n-1])

Measured memory_bytes: 3064
// https://atcoder.jp/contests/abc140/tasks/abc140_c

#include <bits/stdc++.h>
using namespace std;

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

    int p;
    cin >> p;
    long ans = p;
    for (int i = 0; i < n - 2; i++)
    {
        int b;
        cin >> b;
        ans += min(b, p);
        p = b;
    }
    ans += p;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define take freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);freopen("error.txt","w",stderr);
#define speed ios_base::sync_with_stdio(false);
#define int long long
#define endl "\n"
#define maxi 10000007
#define rof(i,a,b) for(int i=a;i<b;i++)
int32_t main()
{
    speed
    //take
    int n;
    cin>>n;
    int a[n];
    int b[n+1];
    rof(i,0,n)
    {
        cin>>a[i];
    }
    b[0]=INT_MAX;
    b[1]=0;
    for(int i=2;i<=n;i++)
    {
        b[i]=min(b[i-1]+abs(a[i-1]-a[i-2]),b[i-2]+abs(a[i-1]-a[i-3]));
    }
    cout<<b[n]<<endl;
}

Measured memory_bytes: 5100
#include <bits/stdc++.h>
using namespace std;
int n,ans;
int sum(int a) {
	int res=0;
	while (a) {
		res+=a%10; a/=10;
	}
	return res;
}
int main() {
	//freopen("1.txt","r",stdin);
	scanf("%d",&n);
	ans=1<<30;
	for (int i=1;i<n;i++)
		ans=min(ans,sum(i)+sum(n-i));
	printf("%d\n",ans);
	return 0;
}

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

a = [0,0,0,0]

for i in range(0,4):
    if N[i] == 1:
        a[0] = 1
    elif N[i] == 9:
        a[1] = 1
    elif N[i] == 7:
        a[2] = 1
    elif N[i] == 4:
        a[3] = 1

if sum(a) == 4:
    print("YES")
else :
    print("NO")

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <array>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

struct before_main {
  before_main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
  }
} before_main;

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

typedef long long ll;

int N;
map<string, int> id;
bool adjacent[41][41];
int weight[41];
int weight_sum[41];
int ans;

void dfs(ll S, int wsum, int curr) {

  if (curr == N) {
    ans = max(ans, wsum);
    return;
  }

  if (wsum + weight_sum[N-1] - (curr ? weight_sum[curr - 1] : 0) <= ans)
    return;

  dfs(S, wsum, curr + 1);

  rep(k, curr) {
    if (adjacent[curr][k] && (S >> k & 1)) {
      return;
    }
  }

  dfs(S | (1LL << curr), wsum + weight[curr], curr + 1);
}

int main() {

  while (cin >> N && N) {
    rep(i, 41) rep(j, 41) adjacent[i][j] = 0;
    id.clear();
    int v = 0;

    rep(_, N) {
      string s;
      cin >> s;
      if (id.find(s) == id.end())
        id[s] = v++;
      cin >> weight[id[s]];
      int n;
      cin >> n;
      rep(_, n) {
        string t;
        cin >> t;
        if (id.find(t) == id.end())
          id[t] = v++;
        adjacent[id[s]][id[t]] = 1;
      }
    }

    rep(i, N) weight_sum[i] = weight[i] + (i ? weight_sum[i-1] : 0);

    ans = 0;
    dfs(1, weight[0], 1);
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 3160
// #include <bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define exf(x)	 for(auto&& tmp : x) { cout << tmp << endl; }	// 拡張for
#define PI 3.14159265358979323846264338327950288
const int MOD{ int(1e9 + 7) };	// = 1000000007
const int inf{ 2100000000 };	// = 2100000000 (MAX:2147483647)
typedef long long ll;
using namespace std;

// -------------------------------------------------- //
// ------------------ ここから本編 ------------------ //
// -------------------------------------------------- //

int main(void) {

	int N; cin >> N;
	vector<int> P(N); rep(i, N)cin >> P[i];

	int t = inf;
	int ans = 0;
	for (auto x : P) {
		if (t >= x) ans++;
		t = min(t, x);
	}

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


Measured memory_bytes: 4036
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] a = new int[m + 1];
		int[] cnt = new int[n + 1];
		cnt[0] = 1;
		final int MOD = 1000000007;

		for (int i = 1; i < a.length; i++) {
			a[i] = sc.nextInt();
		}

		int num = 1;
		if (m > 0) {
			if (a[1] == 1) {
				cnt[1] = 0;
				if (num < m) {
					num++;
				}
			} else {
				cnt[1] = 1;
			}
		} else {
			cnt[1] = 1;
		}

		for (int i = 2; i < cnt.length; i++) {

			cnt[i] = cnt[i - 2] + cnt[i - 1];
			cnt[i] %= MOD;
			if (m > 0) {
				if (i == a[num]) {
					cnt[i] = 0;
					if (num < m) {
						num++;
					}
				}
			}

		}

		System.out.println(cnt[n]);
		sc.close();
	}
}

Measured memory_bytes: 46028
n=int(input())
a=[0 for i in range(n)]
b=[0 for i in range(n)]
c=[0 for i in range(n)]
r=0
count=0
for i in input().split():
  a[int(i)-1]+=1
  b[count]=int(i)
  count+=1
for i in range(n):
  m=a[b[i]-1]
  c[i]=2*m-2
for i in range(n):
  r+=a[i]*(a[i]-1)
for i in range(n):
  print((r-c[i])//2)

Measured memory_bytes: 29660
n, m = map(int, input().split())
stu = []
for i in range(n):
    stu.append(list(map(int, input().split())))
chk = []
for i in range(m):
    chk.append(list(map(int, input().split())))
    
for i in range(n):
    near = 10**10
    for j in range(m):
        mht = abs(stu[i][0]-chk[j][0])+abs(stu[i][1]-chk[j][1])
        if near > mht:
            near = mht
            idx = j
    print(idx+1)


Measured memory_bytes: 3064
#include <iostream>

#ifdef _MSC_VER
#define getchar_unlocked _getchar_nolock
#endif

int * vec;
int n;
long long ans = 0;

bool check_mon_up(int * start, int * end)
{
	if (end - start <= 1)
		return true;
	
	for (auto i = start; i < end - 1; i++)
		if (*i >= *(i + 1))
			return false;
	return true;
}

bool chec_mon_do(int * start, int * end)
{
	if (end - start <= 1)
		return true;

	for (auto i = start; i < end - 1; i++)
		if (*i <= *(i + 1))
			return false;
	return true;
}

int * m_find_max(int * start, int * end)
{
	int max = -1;
	int * numb = nullptr;
	for (int * i = start; i < end; i++)
		if (max < *i) max = *i, numb = i;
	return numb;
}

void m_find_two_max(int * start, int * end, int *& max, int *& tax)
{
	int mm = -1, mt = -1;
	for (int * i = start; i < end; i++)
	{
		if (*i > mm)
		{
			mt = mm;
			mm = *i;
			tax = max;
			max = i;
		}
		else if (*i > mt)
		{
			mt = *i;
			tax = i;
		}
	}
}

void m_find_tax(int * start, int * end, int * max, int *& tax)
{
	int mm = *max, mt = -1;
	for (int * i = start; i < end; i++)
		if (*i > mt)
			if (i != max)
			{
				tax = i;
				mt = *i;
			}
}

void fu(int * start, int * end, int * max)
{
	if (end - start == 1)
		return;
	int * tax = 0;
	m_find_tax(start, end, max, tax);
	if (tax == max)
		return;
	if (tax > max)
	{
		ans += (long long)(*tax) * (max - start + 1) * (end - tax);
		fu(start, tax, max);
	}
	else
	{
		ans += (long long)(*tax) * (tax - start + 1) * (end - max);
		fu(tax + 1, end, max);
	}
	return;
}

void func(int * start, int * end)
{
	if (end - start <= 1)
		return;
	if (end - start == 2)
	{
		ans += (long long)(*(end - 1) > *start) ? *start : *(end - 1);
		return;
	}
	if (check_mon_up(start, end))
	{
		for (int i = 0; i < end - start - 1; i++)
			ans += (long long)(*(start + i)) * (i + 1);
		return;
	}
	if (chec_mon_do(start, end))
	{
		for (int i = 1; i < end - start; i++)
			ans += (long long)(*(start + i)) * (end - start - i);
		return;
	}
	int * max = m_find_max(start, end);
	fu(start, end, max);
	func(start, max);
	func(max + 1, end);
	return;
}

void read_int_unlocked(int * out)
{
	int c = 0;
	*out = 0;
	c = getchar_unlocked();
	for (; '0' <= c && c <= '9'; c = getchar_unlocked())
		*out = (*out) * 10 + c - '0';
}

int main()
{
	std::ios::sync_with_stdio(false);
	read_int_unlocked(&n);
	vec = new int[n];
	int * const start = vec;
	int * const end = vec + n;
	for (int * i = start; i < end; i++)
		read_int_unlocked(i);
	func(start, end);
	std::cout << ans;
	//system("pause");
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdlib>
#include <string>

int main()
{
    bool operetors[3] = {true, true, true};
    int nums;
    int num[4];
    int i = 0;
    int j = 0;
    int sum = 0;
    char c[3];
    
    std::cin >> nums;
    num[3] = nums % 10;
    nums = nums / 10;
    num[2] = nums % 10;
    nums = nums / 10;
    num[1] = nums % 10;
    nums = nums / 10;
    num[0] = nums % 10;
    
    for(i = 0; i < 8; i++){
        sum = num[0];
        j = 1;
        operetors[0] = (i >> 2) & 1;
        operetors[1] = (i >> 1) & 1;
        operetors[2] = i & 1;
        
        while(j < 4){
            if(operetors[j - 1]){
                sum += num[j];
            }else{
                sum += (num[j] * -1);
            }
            j++;
        }
        if(sum == 7){
            break;
        }
    }
    j = 0;
    while(j < 3){
            if(operetors[j]){
                c[j] = '+';
            }else{
                c[j] = '-';
            }
        j++;
    }
    std::cout << num[0] << c[0] << num[1] << c[1] << num[2] << c[2] << num[3] << "=7";
    return 0;
}


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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
vl modinv;
void fillModInv(ll n, ll mod){
  modinv = vl(n+1);
  modinv[1] = 1;
  FOR(i,2,n+1){
    modinv[i] = modinv[mod%i] * (mod - mod/i) % mod;
  }
}
/*}}}*/
int main() {
  ll n;
  cin >> n;

  FOR(a,-1001,1001){
    FOR(b,-1001,1001){
      ll ta = a*a*a*a*a;
      ll tb = b*b*b*b*b;
      if(ta-tb==n){
        cout << a << " " << b << endl;
        return 0;
      }
    }
  }
  
  //cout << fixed << setprecision(10);
  return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <cmath>
#include <utility> // pair make_pair
#include <algorithm>
#include <functional>
#include <iomanip>
#include <climits> // LLONG_MAX, LLONG_MIN, INT_MIN, INT_MAX
#include <assert.h>

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define ll long long
#define int ll
#define INF INT_MAX/10
#define MOD 1000000007

using namespace std;
using Pi = pair<int, int>;
using Graph = vector<vector<int> >;
using WeightGraph = vector<vector<Pi> >;

int Input[100100];


// returns gcd(a, b)
// x, y will contain the answer for ax + by = gcd(a, b) after the execution
// if answer for ax + by = c is needed,
// check if c % gcd(a, b) == 0
// get (c / gcd(a, b)) * (x, y)

long long extGCD(long long a, long long b, long long &x, long long &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  long long d = extGCD(b, a%b, y, x);
  y -= a/b * x;
  return d;
}

signed main() {
  int N; cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> Input[i];
  }

  int r = Input[0];
  for (int i = 0; i < N; i++) {
    int x, y;
    r = extGCD(r, Input[i], x, y);
  }
  cout << r << endl;
}




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

const int N=100100;
int a[N],b[N],n,m,vis[N],fa[N],c[N];
typedef long long ll;
vector<int>g[N];
ll sum[N],mn[N];
bool cmp(const int&x,const int&y){
	if(a[x]!=a[y])return a[x]<a[y];
	return b[x]>b[y];
}
int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>m;
	for(int i=1;i<=n;++i){cin>>a[i]>>b[i];c[i]=i;}
	sort(c+1,c+n+1,cmp);
	for(int i=1;i<=m;++i){
		int x,y;cin>>x>>y;
		g[x].push_back(y);g[y].push_back(x);
	}
	for(int i=1;i<=n;++i)fa[i]=i;//,sort(g[i].begin(),g[i].end(),cmp);
	for(int i=1;i<=n;++i){
		int u=c[i];sum[u]=b[u];mn[u]=max(0,a[u]-b[u]);
		vis[u]=1;
		for(int j:g[u])if(vis[j]){
			int v=find(j);if(u==v)continue;
			sum[u]+=sum[v];mn[u]=min(mn[u],max(a[u]-sum[v]-b[u],mn[v]));
			fa[v]=u;
		}
	}
	cout<<sum[c[n]]+mn[c[n]]<<'\n';
	return 0;
}


Measured memory_bytes: 9468
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <cmath>
#include <climits>
#include <unordered_map>

using namespace std;

#define size_t int

int get(long n) {
  long x = 0b1000000000000000000000000000000000000000000000000000000000000000;
  for (size_t i = 0; i <= 66; i++) {
    if (n & x) {
      return 64-i;
    }
    x /= 2;
  }
  return 0;
}

int main(int argc, char const *argv[]) {
  long N;
  scanf("%ld", &N);
  long A[N];
  // long X[1000000000];
  // long *X;
  // X = (long*)malloc(sizeof(long)*1000000000);
  unordered_map<int, int> X;
  for (size_t i = 0; i < N; i++) {
    scanf("%ld", &A[i]);
    X[A[i]]++;
  }
  sort(A, A + N);
  long r = 0;
  for (long i = N - 1; i >= 0; i--) {
    if (X[A[i]] == 0) {
      continue;
      // printf("AA\n");
    }
    X[A[i]]--;
    int n = get(A[i]);
    int k = pow(2, n) - A[i];
    // printf("%ld %d %d\n", A[i], n, k);
    if (X[k] != 0) {
      r++;
      X[k]--;
    }
  }
  printf("%ld\n", r);
}


Measured memory_bytes: 18548
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <cmath>
#include <string>
#define ALP 30

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int cnt[ALP];
char mp[105];
int all[ALP];

int main()
{
	int H,W;
	scanf("%d %d",&H,&W);
	for(int i=0;i<H;i++)
	{
		scanf("%s",&mp);
		for(int j=0;j<W;j++) cnt[mp[j]-'a']++;
	}
	for(int i=0;i<=H-i-1;i++)
	{
		for(int j=0;j<=W-j-1;j++)
		{
			int nm=1;
			if(i<H-i-1) nm*=2;
			if(j<W-j-1) nm*=2;
			all[nm]++;
		}
	}
	for(int i=0;i<ALP;i++)
	{
		while(all[4]>0&&cnt[i]>=4)
		{
			cnt[i]-=4;
			all[4]--;
		}
		while(all[2]>0&&cnt[i]>=2)
		{
			cnt[i]-=2;
			all[2]--;
		}
		if(all[1]<cnt[i])
		{
			puts("No");
			return 0;
		}
		all[1]-=cnt[i];
	}
	puts("Yes");
	return 0;
}


Measured memory_bytes: 128
H, W, A, B = list(map(int, input().split()))

if H == 1 and W == 1:
    print(0)
else:
    if A <= (W // 2) and B <= (H // 2):
        for i in range(H):
            b = ''
            if i < H - B:
                for j in range(W):
                    if j < A:
                        b += '1'
                    else:
                        b += '0'
            else:
                for j in range(W):
                    if j < A:
                        b += '0'
                    else:
                        b += '1'
            print(b)
    else:
        print('No')


Measured memory_bytes: 45532