akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

int a[100010];

int main(){
    int n;
    cin >> n;
    int m = n, k = 0;
    rep(i, n){
        cin >> a[i];
        m = min(m, a[i]);
        k = max(k, a[i]);
    }
    if (k > m+1) {
        cout << "No" << endl;
    }
    else if (k == m){
        if (k == n-1 || 2*k <= n) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    else {
        int x = 0;
        rep(i, n) if (a[i] == m) x++;
        if (x < k && 2*(k-x) <= n-x) cout << "Yes" << endl;
        else cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3960
/*Alohomora*/
#include<bits/stdc++.h>
#define ll         long long
#define fl(i,n)    for(i=0;i<n;i++)
#define fld(i,a,b) for(i=a;i>b;i--)
#define fli(i,a,n) for(i=a;i<n;i++)
#define inp(i,a,n) for(i=0;i<n;i++) {cin>>a[i];}
#define op(i,a,n)  for(i=0;i<n;i++) {cout<<a[i]<<" ";}
#define pb         push_back
#define mp         make_pair
#define mod1       100000000000007
#define speedup    ios_base::sync_with_stdio(false),cin.tie(0)
using namespace std;
ll fact(ll n){ if(n==0){return 1;}return (n*fact(n-1))%mod1;}
ll power(ll x, ll y)
{
    ll temp;
    if( y == 0)
        return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return temp*temp;
    else
        return x*temp*temp;
}
ll gcd(ll a,ll b){if(b==0){return a;}gcd(b,a%b);}
ll a[2000000];
void sieve(){ll i,j;fli(i,2,1000001){if(a[i]==0){for(j=i*i;j<1000001;j+=i){a[j]=1;}}}}
map<ll,vector<ll> >m1;
vector<ll>v1;
bool compar(const pair<ll,ll> &a, const pair<ll,ll> &b) 
{ 
    return (a.second < b.second);
} 
ll level[1000000];
vector<ll>root;
set<ll>s1;
void factorise(long long n) 
{ 
    while (!(n%2)) 
    { 
        n >>= 1; 
        s1.insert(2);
    } 
    for (long long i=3; i<=sqrt(n); i+=2) 
    { 
        while (n%i==0) 
        { 
        	s1.insert(i);
            n=n/i; 
        } 
    } 
  	if (n>2) 
  	{
       s1.insert(n);
	}
} 

void comp()
{
	ll a,b,c,d,e,i;
	cin>>a;
	map<string,ll>m1;
	string s;
	fl(i,a)
	{
		cin>>s;
		sort(s.begin(),s.end());
		m1[s]++;
	}
	map<string,ll> :: iterator it = m1.begin();
	ll ans=0;
	while(it!=m1.end())
	{
		ans+=(it->second*(it->second-1))/2;	
		it++;
	}
	cout<<ans<<"\n";
	
}	 
int main()
{
	speedup;
	ll i=0,t;
	ll n;
	//cin>>t;
	t=1;
	while(t--)
	{
	 comp();
	}
}

Measured memory_bytes: 13312
N=input()
A=input().split()

def validate(i):
    I=i%2
    if I==0:
        I1=i%3
        I2=i%5
        if I1==0 or I2==0:
            return "Yes"
        else:
            return "No"
    else:
        return "Yes"

X = []
for i in A:
    X.append(validate(int(i)))

if "No" in X:
    print("DENIED") 
else:
    print("APPROVED") 

Measured memory_bytes: 3060
#include<stdio.h>

int main(void)
{
    int w, h, x, y, r;
    while(1)
    {
        char buffer[256];
        fgets(buffer, 256, stdin);
        sscanf(buffer, "%d %d %d %d %d", &w, &h, &x, &y, &r);
        if((x >= -100 && x <= 100) &&
        (y >= -100 && y <= 100)&&
        (w > 0 && w <= 100)&&
        (h > 0 && h <= 100)&&
        (r > 0 && r <= 100)) break;
        
    }
    if((x + r <= w)&& (x - r >= 0) &&
    (y + r <= h)&& (y - r >= 0)) printf("Yes\n");
    else printf("No\n");
    
    
    return(0);
}


Measured memory_bytes: 2100
#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define il inline
#define db double
#define ls rt << 1
#define rs rt << 1 | 1
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define X first
#define Y second
#define pcc pair<char, char>
#define vi vector<int>
#define vl vector<ll>
#define rep(i, x, y) for(int i = x; i <= y; i ++)
#define rrep(i, x, y) for(int i = x; i >= y; i --)
#define rep0(i, n) for(int i = 0; i < (n); i ++)
#define per0(i, n) for(int i = (n) - 1; i >= 0; i --)
#define ept 1e-9
#define INF 0x3f3f3f3f
#define sz(x) (x).size()
#define All(x) (x).begin(), (x).end()
#define lowbit(x) ((x) & -(x))
using namespace std;
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
inline ll read1()
{
	ll x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
const ll mod = 1e9 + 7;
const int N = 4e6 + 10;
const db pi = acos(-1);

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	cout << min(min(a, b), c) << " " << max(max(a, b), c) << endl;
	return 0;
}



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

#define MAX 500000
#define SENTINEL 2000000000

int L[MAX/2+2], R[MAX/2+2];
int cnt;

void merge(int A[], int n, int left, int mid, int right) {
	int n1 = mid - left;
	int n2 = right - mid;
	for (int i = 0; i < n1; i++) L[i] = A[left + i];
	for (int i = 0; i < n2; i++) R[i] = A[mid + i];
	L[n1] = R[n2] = SENTINEL;
	int i = 0, j = 0;
	for ( int k = left; k < right; k++) {
		cnt++;
		if(L[i]<= R[j]) {
			A[k] = L[i++];
		} else {
			A[k] = R[j++];
		}
	}
}

void mergeSort(int A[], int n, int left, int right) {
	if ( left+1 < right ) {
		int mid = (left + right) / 2;
		mergeSort(A, n, left, mid);//左半分から
		mergeSort(A, n, mid, right);
		merge(A,n,left,mid,right);
	}
}

int main(){
	int A[MAX], n, i;
	cnt = 0;

	cin >> n;
	for ( i = 0; i<n; i++) cin >> A[i];
	mergeSort(A,n,0,n);

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

	cout << cnt << endl;

	return 0;
}



Measured memory_bytes: 6912
#include <bits/stdc++.h>
using namespace std;
int main(){
    string a;
    string b;
    cin >> a >> b;
    size_t size = a.length();
    
    int i;
    int cnt=0;
    for (i = 0; i < size ;i++){
        if (a[i] != b[i]){cnt++;}
    }
    cout << cnt << endl;
    
    return 0;
}

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



int main(){

	int A, B, N, Q, R;




	scanf("%d %d %d", &N, &A, &B);

	if (N*A > B){
		printf("%d\n",  B);
	}
	else{
		printf("%d\n", N*A );
	}

	return 0;

}
    


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <set>
#include <numeric>

#include <map>
#include <math.h>
#include <iomanip>
#include <stack>
#include <queue>
#include <bitset>
#include <math.h>

#define INF 100100100

typedef long long int llint;

using namespace std;

typedef pair<int, int>Pii;

#define pi 3.141592653589793
#define mod 1000000007

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	for (int i = a; i <= a * b; i++) {
		if (a*i%b == c) {
			puts("YES");
			return 0;
		}
	}
	puts("NO");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <map>
#include <utility>
#include <numeric>
#define ll long long
#define REP(i, x) for(int (i) = 0; (i) < (x); (i) ++)
#define pi 3.1415926535
const int MOD = 1000000007;
using namespace std;

int main() {
	int n, l;
	cin >> n >> l;
	int sum = 0;
	int m = 10000000;
	REP(i, n) {
		int num = l + i;
		if (abs(num) < abs(m)) {
			m = num;
		}
		sum += num;
	}
	cout << sum - m << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll a, b, n, k;
  in3(a, b, n);
  k = (n + 1) / b;
  k = b * k - 1;
  ll c, d, e;
  c = (a * k) / b - a * (k / b);
  d = (a * n) / b - a * (n / b);
  e = (a * (n - 1)) / b - a * ((n - 1) / b);
  out(max({c, d, e}));
  memi;
}

Measured memory_bytes: 3504
/*
I believe on myself and I will achieve
this->author = Fuad Ashraful Mehmet, CSE-UAP
Todo:
https://codeforces.com/contest/1398/problem/E
https://codeforces.com/problemset/problem/374/C
*/
#include<bits/stdc++.h>
#define forn(i,n) for(int i=0;i<(int)n;++i)
#define all(o) (o).begin(),(o).end()
#define dbg(o)  cerr<<"at "<<__LINE__<<" response = "<<o<<endl;
#define pb push_back
using namespace std;

const int N=2e5+5;
int n,k,m;

int father[N];
int grp[N];

int find_father(int node)
{
      if(father[node]==node)return node;
      return father[node]=find_father(father[node]);
}// end func

void HalfDead()
{
      
      cin>>n>>m;

      int x,y;

      forn(i,n+2)
      {
            father[i]=i;
      }
      forn(i,m)
      {
            cin>>x>>y;
            int p1=find_father(x);
            int p2=find_father(y);
            if(p1!=p2)
            {
                  father[p1]=p2;
            }
      }

      for(int i=1;i<=n;++i)
      {
            int p=find_father(i);
            grp[p]+=1;
      }

      int res=0;
      for(int i=1;i<=n;++i)
      {
            res=max(res,grp[i]);
      }

      cout<<res<<endl;
      
}
int main()
{
      ios_base::sync_with_stdio(0); cin.tie(nullptr);  cout.tie(0);
      int tc=1;
     // cin>>tc;
      while(tc--)
      {
            HalfDead();
      }
      return 0;
}

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

int main(){
  string s;
  cin >> s;
  int a = s[0] - '0';
  int b = s[1] - '0';
  int c = s[2] - '0';
  int d = s[3] - '0';

  int ans;
  rep (i, 8){
    int temp1;
    if (i & 0x1) temp1 = a + b;
    else temp1 = a - b;
    int temp2;
    if (i & 0x2) temp2 = temp1 + c;
    else temp2 = temp1 - c;
    int temp3;
    if (i & 0x4) temp3 = temp2 + d;
    else temp3 = temp2 - d;

    if (temp3 == 7) ans = i;
  }
  string op = "   ";
  int temp = ans;
  rep (i, 3){
    if (temp & 0x1) op[i] = '+';
    else op[i] = '-';
    temp >>= 1;
  }
  cout << a << op[0] << b << op[1] << c << op[2] << d << "=7" << endl;
  return 0;
}

Measured memory_bytes: 3592
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")
#define FOR(i,j,n) for (int i=(j);i<(n);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define REPN(i,n) for (int i=(n);i>=0;i--)
#define I(n) scanf("%d", &(n))
#define pb(n) push_back((n))
#define mp(i,j) make_pair((i),(j))
#include <bits/stdc++.h>
using namespace std;

//------------------------------typedef集
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef vector<vi> vvi;
typedef vector<vpi> vvpi;
typedef vector<vvi> vvvi;
typedef long long ll;

int s[30001],n;
ll sum;

int main(){
    cin >> n;
    if (n==3){
        cout << "2 5 63" << endl;
        return 0;
    }
    s[3] = 1;
    s[29997] = 1;
    n -= 2;
    if (n&1) {
        s[30000] = 1;
        n--;
    }
    int hoge = 2;
    while(n && hoge < 15000){
        s[hoge] = 1;
        s[30000-hoge] = 1;
        n -= 2;
        hoge += 2;
    }
    hoge = 5;
    while (n && hoge < 15000){
        if (hoge%3 != 0 && hoge%5 != 0){
            hoge += 2;
            continue;
        }
        s[hoge] = 1;
        s[30000-hoge] = 1;
        n -= 2;
        hoge += 2;
    }

    REP(i,30001) if(s[i]) printf("%d ",i);
    printf("\n");
}


Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.List;

class Main {

    public static void main(String[] args) throws Exception {

        try {

            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            List<String> strings = Arrays.asList(br.readLine().split(" "));
            String result = strings.get(1) + strings.get(0);

            System.out.println(result);
        } catch (IOException | NumberFormatException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (final Exception e) {
            e.printStackTrace();
            System.exit(0);
        }
    }
}

Measured memory_bytes: 21076
#include <iostream>

using namespace std;

int N;
int a[100005];
int cnt[100005];

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

for(int i = 0; i < N; i++){
cnt[a[i]]++, cnt[a[i] + 1]++, cnt[a[i] + 2]++;
}

int max = -1;
for(int i = 0; i < 100005; i++){
if(max < cnt[i]){
max = cnt[i];
}
}

cout << max << endl;
return 0;
}

Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string.h>
#include<cmath>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;i++)
int N, M;
typedef struct _Node {
	vector<struct _Node*> next;
}Node;
int main() {
	scanf("%d%d", &N, &M);
	int a, b, ans = 0;
	vector<int>data(N, -1);
	rep(i, 0, M) {
		scanf("%d%d", &a, &b);
		if (data[a - 1] != -1 && data[a - 1] != b || N >= 2 && a == 1 && b == 0) {
			printf("-1");
			return 0;
		}
		data[a - 1] = b;
	}
	if (data[0] == -1 && N >= 2)data[0] = 1;
	rep(i, 0, N)ans *= 10, ans += data[i] == -1 ? 0 : data[i];
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e17;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define RREP(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N; cin >> N;
    vvl X(N, vl(3));
    REP(i, N) cin >> X[i][0] >> X[i][1] >> X[i][2];
    
    vvl dp(N+1, vl(3, 0));
    REP(i, N){
        REP(j, 3){
            REP(k, 3){
                if(j == k) continue;
                dp[i+1][j] = max(dp[i+1][j], dp[i][k] + X[i][j]);
            }
        }
    }
    cout << max({dp[N][0], dp[N][1], dp[N][2]}) << endstr;

    return 0;
}


Measured memory_bytes: 11264
#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>

using namespace std;

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

	vector<bool> D(10, false);
	while (K--) {
		int i;
		cin >> i;
		D[i] = true;
	}

	int ans = N;
	while (true)
	{
		int a = ans;
		bool b = true;
		while (a > 0)
		{
			int d = a % 10;
			a /= 10;
			if (D[d]) { b = false; break; }
		}

		if (b) break;
		ans++;
	}

	cout << ans << endl;

	return 0;
}

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

using namespace std;
typedef long long LL;
const int INF=1000000000;

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> a(N), b(N), c(M), d(M);
  rep(i,N) cin >> a[i] >> b[i];
  rep(i,M) cin >> c[i] >> d[i];
  rep(i,N){
    int dist=INF, ans=0;
    rep(j,M){
      int D=abs(a[i]-c[j])+abs(b[i]-d[j]);
      if(dist>D) dist=D, ans=j+1;
    }
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;

const int len = 3;

int main()
{
    vector<int> A(len);
    for (int i = 0; i < len; i++)
    {
        cin >> A.at(i);
    }
    sort(A.begin(), A.end());
    for (int i = 0; i < len - 1; i++)
    {
        A.at(i) = A.at(i + 1) - A.at(i);
    }
    A.pop_back();
    cout << accumulate(A.begin(), A.end(), 0) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF (((ll)1<<31)-1)
#define eps LDBL_EPSILON
#define moder (1000000007)
#define pie 3.141592653589793238462643383279
#define P std::pair<int,int>
#define prique priority_queue
#define ggr getchar();getchar();return 0;
using namespace std;
int n,a[5010],b[5010];
signed main(){
	while(true){
		cin>>n;
		if(!n)break;
		rep(i,n){
			cin>>a[i];
			if(i)a[i]+=a[i-1];
		}
		rep(i,n){
			if(i)b[i]=min(b[i-1],a[i]);
			else b[i]=min((ll)0,a[i]);
		}
		int ans=-INF;
		rep(i,n){
			ans=max(ans,a[i]-b[i-1]);
		}
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 3044
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> void get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'; t=getchar());
	if(t=='-')neg=true,t=getchar();
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) get1(a),get1(b)
#define get3(a,b,c) get1(a),get2(b,c)
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

vector<int> g[100111];
int n,sz[100111];
LL a[100111],add[100111];
void dfs(int x,int f=0)
{
	int mx=0;
	for(int i=0;i<(int)g[x].size();i++)
		if(g[x][i]!=f)
		{
			dfs(g[x][i],x);
			sz[x]+=sz[g[x][i]];
			mx=max(mx,sz[g[x][i]]);
			add[x]+=add[g[x][i]];
		}
	if((int)g[x].size()==1)
	{
		add[x]=-a[x];sz[x]=a[x];
		return ;
	}
	if(a[x]+add[x]>0)
	{
		puts("NO");
		exit(0);
	}
	int t=min(sz[x]/2,sz[x]-mx);
	if(a[x]+add[x]+t<0)
	{
		puts("NO");
		exit(0);
	}
	t=-a[x]-add[x];
	add[x]+=t*2;
	sz[x]-=t*2;
}
int main()
{
	get1(n);
	for(int i=1;i<=n;i++)get1(a[i]);
	for(int i=1,u,v;i<n;i++)
	{
		get2(u,v);
		g[u].pb(v);
		g[v].pb(u);
	}
	int rt=0;
	for(int i=1;i<=n;i++)if((int)g[i].size()>1)
	{
		rt=i;
		break;
	}
	if(rt==0)
	{
		if(a[1]==a[2])puts("YES");
		else puts("NO");
		return 0;
	}
	dfs(rt);
	if(sz[rt]==0)puts("YES");
	else puts("NO");
	return 0;
}

Measured memory_bytes: 14336
#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000000;

struct edge {
	int from, to, cost;
	bool used;
};

int main() {
	int N, M;  cin >> N >> M;
	vector<vector<int>> dist;
	vector<edge> e;
	dist = vector<vector<int>>(N, vector<int>(N, 0));

	for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) {
		if (i == j) { dist[i][j] = 0;  dist[j][i] = 0; }
		else { dist[i][j] = inf;  dist[j][i] = inf; }
	}

	for (int i = 0; i < M; i++) {
		edge temp;  cin >> temp.from >> temp.to >> temp.cost;
		temp.from--;  temp.to--;
		temp.used = false;
		e.push_back(temp);
		dist[temp.from][temp.to] = temp.cost;
		dist[temp.to][temp.from] = temp.cost;
	}

	for (int k = 0; k < N; k++) for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) {
		dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
	}

	for (int i = 0; i < N - 1; i++) for (int j = i + 1; j < N; j++) {
		for (int m = 0; m < M; m++) {
			int a = e[m].from, b = e[m].to, c = e[m].cost;
			if (dist[i][j] == dist[i][a] + c + dist[b][j] || dist[i][j] == dist[i][b] + c + dist[a][j]) {
				e[m].used = true;
			}
		}
	}

	int ans = 0;
	for (int i = 0; i < M; i++) {
		if (!e[i].used) ans++;
	}

	cout << ans << endl;
}

Measured memory_bytes: 384
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// ここまで

#[derive(Eq, PartialEq, Clone, Copy)]
struct State {
    v: usize,
    d: u64,
}

use std::cmp::Ordering;
impl Ord for State {
    fn cmp(&self, other: &Self) -> Ordering {
        other.d.cmp(&self.d)
    }
}

impl PartialOrd for State {
    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
        Some(self.cmp(&other))
    }
}

fn dijkstra(src: usize, g: &Vec<Vec<(usize, u32)>>) -> Vec<u64> {
    let inf: u64 = 10000000000000000;
    let mut dp = vec![inf; g.len()];
    dp[src] = 0;
    let mut h = std::collections::BinaryHeap::new();
    h.push((src, 0));
    while let Some((v, d)) = h.pop() {
        if d > dp[v] {
            continue;
        }
        for &(u, t) in &g[v] {
            let c = d + t as u64;
            if c < dp[u] {
                dp[u] = c;
                h.push((u, c));
            }
        }
    }
    dp
}

use std::io::BufWriter;
use std::io::Write;

fn run() {
    input! {
        n: usize,
        m: usize,
        s: usize1,
        t: usize1,
        e: [(usize1, usize1, u32, u32); m],
    }
    let mut g = vec![vec![]; n];
    let mut h = vec![vec![]; n];
    for (u, v, a, b) in e {
        g[u].push((v, a));
        g[v].push((u, a));
        h[u].push((v, b));
        h[v].push((u, b));
    }
    let x = dijkstra(s, &g);
    let y = dijkstra(t, &h);
    let mut prev = 0;
    let mut ans = vec![0; n];
    for ((x, y), dp) in x.iter().zip(y.iter()).zip(ans.iter_mut()).rev() {
        let z = 1000000000000000 - (*x + *y);
        prev = std::cmp::max(prev, z);
        *dp = prev;
    }
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    for ans in ans {
        writeln!(out, "{}", ans).unwrap();
    }
}

fn main() {
    run();
}


Measured memory_bytes: 36976
#include<stdio.h>
int main(){
	int A[100], n, i, j, f, g, h, k = 0;
	scanf("%d", &n);
	for (i = 0;i < n; i++) {
		scanf("%d", &A[i]);
	}
	for (g = 0; g < n - 2; g++) {
		f = 1;
		i = g;
		while (f == 1) {
			f = 0;
			for (j = n - 1; j > i; j--) {
				if (A[j] < A[j - 1]) {
					h = A[j];
					A[j] = A[j - 1];
					A[j - 1] = h;
					f = 1;
					k++;
				}
			}
			i++;
		}
	}
	for (i = 0; i < n; i++) {
		if (i == 0) {
			printf("%d", A[i]);
		}
		if (i != 0) {
			printf(" %d", A[i]);
		}
	}
	putchar('\n');
	printf("%d\n", k);
	return 0;
}

	


Measured memory_bytes: 2088
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

int maxdepth;
int n;
int p[110];
int t[110];
int memo[5][110];

int calc(int balloon, int depth) {
  assert(balloon <= 3);
  maxdepth = max(maxdepth, depth);
  if (memo[balloon][depth] != -1) { return memo[balloon][depth]; }
  if (depth == n - 1) { return 0; }
  int ret = 1 << 20;
  if (t[depth] + (balloon + 1) * p[depth] + p[depth + 1] <= t[depth + 1]) {
    ret = min(ret, calc(1, depth + 1) + p[depth] + p[depth + 1]);
  }
  if (balloon <= 2 && t[depth] + (balloon + 1) * abs(p[depth] - p[depth + 1]) <= t[depth + 1]) {
    ret = min(ret, calc(balloon + 1, depth + 1) + abs(p[depth] - p[depth + 1]));
  }
  return memo[balloon][depth] = ret;
}

int main() {
  while (scanf("%d", &n), n) {
    maxdepth = -1;
    MEMSET(memo, -1);
    REP(i, n) {
      scanf("%d %d", &p[i + 1], &t[i + 1]);
    }
    p[0] = 0;
    t[0] = 0;
    p[n + 1] = 0;
    t[n + 1] = 1 << 20;
    n += 2;
    calc(0, 0);
    if (maxdepth + 1 != n) {
      printf("NG %d\n", maxdepth + 1);
    } else {
      printf("OK %d\n", memo[0][0]);
    }
  }
}

Measured memory_bytes: 0
import Data.ByteString.Char8 as B

solve :: ByteString -> Int
solve ss =
    let (a, b) = B.splitAt (B.length ss `div` 2) ss
    in if a == b then B.length ss else solve (B.init ss)

main :: IO ()
main = print =<< solve . B.init <$> B.getLine


Measured memory_bytes: 380
#include <iostream>

using namespace std;
int dsum(int x)
{
    if(!x) return 0;
    return dsum(x/10)+x%10;
}
int n,i;
int main()
{
    cin>>n;
    int mn=10000005;
    for(i=1;i<n;i++)
        mn=min(mn,dsum(i)+dsum(n-i));
    cout<<mn;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<map>
#include<algorithm>
#include<set>

using namespace std;
typedef long long int lli;

lli tejun2(int s) {
    lli res=0;

    for(lli i=1; i<1e7; i*=10)
        res = max(res, (s%i)*(s/i));
    return res;
}

int main(void) {
    int q;
    scanf("%d", &q);
    for(int i=0; i<q; i++) {
        int n;
        scanf("%d", &n);

        set<lli> hist;
        lli last=n;
        for(int i=0; i<100000; i++) {
            if(last/10 == 0) {
                printf("%d\n", i);
                goto BR;
            }
            if(hist.find((last = tejun2(last))) == hist.end()) {
                hist.insert(last);
            }
        }
        printf("-1\n");
BR:
        ;
    }
    return 0;
}

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

ll GCD(ll a, ll b) { return (b == 0)? a: GCD(b, a % b); }
ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }

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

  int N; cin >> N;
  vector<ll> A(N, 0);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  vector<ll> l(N);
  l[0] = A[0];
  for (int i = 1; i < N; i++) {
    l[i] = GCD(l[i - 1], A[i]);
  }

  vector<ll> r(N);
  r[N - 1] = A[N - 1];
  for (int i = N - 2; i >= 0; i--) {
    r[i] = GCD(r[i + 1], A[i]);
  }

  ll ans = max(r[1], l[N - 2]);
  for (int i = 1; i < N - 1; i++) {
    ll temp = GCD(l[i - 1], r[i + 1]);
    ans = max(ans, temp);
  }

  cout << ans << '\n';

  return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
using namespace std;
int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	int pre[n], suf[n];
	for (int i = 0;i < n;i++) pre[i] = suf[i] = 0;
	for (int i = 0;i < n;i++) {
		if (s[i] == 'W') pre[i]++;
		if (i) pre[i] += pre[i - 1];
	}
	for (int i = n - 1;i>= 0;i--) {
		if (s[i] == 'E') suf[i]++;
		if (i < n - 1) suf[i] += suf[i + 1];
	}
	int ans = 10000000;
	for (int i = 0;i < n;i++) {
		int l = i ? pre[i - 1] : 0;
		int r = i == n - 1 ? 0 : suf[i + 1];
		ans = min(ans, l + r);
	}
	cout << ans << endl;
}

Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;

int main(){
    string s;
    cin >> s;
    int N = s.size();
    ll ans = 0;

    for(int bit=0; bit<1<<(N-1); bit++) {
        ll tmp = 0;
        for(int i=0; i<N-1; i++) {
            tmp *= 10;
            tmp += s[i]-'0';
            if(bit>>i&1) ans += tmp, tmp = 0;
        }
        tmp *= 10;
        tmp += s.back()-'0';
        ans += tmp;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3592
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cassert>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
#define REP(i, n) for (int64_t i = 0; i < (int64_t)n; i++)
#define REP_FOR(i, a, b) for (int64_t i = (int64_t)a; i < (int64_t)b; i++)
#define REP_REV(i, a, b) for (int64_t i = (int64_t)a; i > (int64_t)b; i--)
#define FORALL(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int64_t, int64_t> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int64_t> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int64_t infi = 1147483600;
const ll infl = 4e18 + 5;
const char EOL = '\n';
//cout << fixed << setprecision(17) << res << endl;
const ll MOD = 998244353;
 
int main() {
    string s;
    cin >> s;
    if (s[0] == s[1] && s[1] == s[2]) {
        cout << "No" <<endl;
    } else {
        cout << "Yes" << endl;
    }
}


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

Xp = [x for x in X if x>=0]
Xn = [x for x in X if x<0]
Xp.sort()
Xn.sort(reverse=True) #絶対値の小さい順に
#print(Xp, Xn)

answer = 1e9
for i, x in enumerate(Xp):
  if len(Xn) >= K-(i+1) > 0:
    #print(i,x, Xn[K-(i+1)-1], x -Xn[K-(i+1)-1])
    answer = min(answer, 2*x -Xn[K-(i+1)-1])
  if K-(i+1)==0:
    answer = min(answer, x)
for i, x in enumerate(Xn):
  if len(Xp) >= K-(i+1) > 0:
    #print(i,x, Xp[K-(i+1)-1], -x -Xp[K-(i+1)-1])
    answer = min(answer, -2*x + Xp[K-(i+1)-1])
  if K-(i+1)==0:
    answer = min(answer, -x)
print(answer)

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

int main() {
  	int N, X[N], Souwa[100];
  cin>>N;
  for(int t=1;t<=N;t++){cin>>X[t];}
  for(int i=1;i<=100;i++){Souwa[i]=0;
                     for(int j=1;j<=N;j++){Souwa[i]+=(X[j]-i)*(X[j]-i);}}
  for(int i=1;i<=100;i++){if(Souwa[i]<=Souwa[i+1]){cout<<Souwa[i];break;}}
}

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

int main(){
	ll n,c,k;
	cin >> n >> c >> k;
	vector<ll> t(n);
	rep(i,n) cin >> t[i];
	sort(t.begin(),t.end());
	ll ans = 1;
	ll now = t[0] + k;
	ll count = 1;
	REP(i,n-1){
		if(t[i] > now || count >= c) {
			ans++;
			now = t[i] + k;
			count = 1;
		}else{
			count++;
		}
	}
	cout << ans << endl;
	
    return 0;
}



Measured memory_bytes: 3980
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl
#define int ll

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7;

signed main()
{
	IO_OP;
	
	int a, b, n;
	cin >> a >> b >> n;
	cout << a * min(b - 1, n) / b << endl;
	
}





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

main(){
  int N;
  cin >> N;
  int V[51],C[51];
  for(int i = 0; i<N; i++){
    cin >> V[i];
  }
  for(int i = 0; i<N; i++){
    cin >> C[i];
  }
  int ans = 0;
  for(int i =0; i<N; i++){
    if(V[i]>C[i]){
      ans += V[i] - C[i];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
<?php
fscanf(STDIN, '%d', $N);
for ($i  = 0; $i < $N; $i++) {
    fscanf(STDIN, '%s %d', $S[], $P[]);
    $a[$i] = $i + 1;
}
array_multisort(
    $S, SORT_ASC, SORT_STRING,
    $P, SORT_DESC, SORT_NUMERIC,
    $a
);

for($i = 0; $i < $N; $i++) {
    echo $a[$i].PHP_EOL;
}

Measured memory_bytes: 4728
#include <iostream>
#include <map>
#include <cstring>
using namespace std;

const int size = 101;
int G[size][size];
int C[size];
map <int, int> M;
int M_index;
bool flag;

void set_index( int a ) 
{
  if ( M.find( a ) != M.end() ) return;
  M[a] = M_index; 
  M_index++;
}

void init()
{
  memset( G, 0, sizeof(G) );
  memset( C, 0, sizeof(C) );
  M.clear();
  M_index = 0;
  flag = false;
}

int main( void ) 
{
  int a, b;
  flag = true;
  while ( cin >> a >> b ) {
    if ( a == 0 && b == 0 ) {
      for ( int i = 0; i < size; i++ ) {
        for ( int j = 0; j < size; j++ ) {
          if ( G[i][j] > 0 ) C[i] += G[i][j];
        }
      }
      bool ok = true;
      int start = M[1], goal = M[2];
      for ( int i = 0; i < size; i++ ) {
        if ( !C[i] ) continue;
        if ( i == start || i == goal ) {
          if ( C[i] % 2 == 0 ) ok = false;
        } else {
          if ( C[i] % 2 != 0 ) ok = false;
        }
      }
      // output
      cout << ( ok ? "OK" : "NG" ) << endl;
      flag = true;
    } else {
      if ( flag ) {
        init();
      }
      set_index( a );
      set_index( b );
      int index_a = M[a], index_b = M[b];
      G[index_a][index_b]++;
      G[index_b][index_a]++;
    }
  }
  return 0;
}

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

int main() {
    string s;
    cin >> s;

    set<string> v;
    v.insert("KIHBR");
    v.insert("AKIHBR");
    v.insert("KIHABR");
    v.insert("KIHBAR");
    v.insert("KIHBRA");
    v.insert("AKIHABR");
    v.insert("AKIHBAR");
    v.insert("AKIHBRA");
    v.insert("KIHABAR");
    v.insert("KIHABRA");
    v.insert("KIHBARA");
    v.insert("AKIHABAR");
    v.insert("AKIHABRA");
    v.insert("AKIHBARA");
    v.insert("KIHABARA");
    v.insert("AKIHABARA");

    cout << (v.count(s) == 1 ? "YES" : "NO") << endl;
}


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

using namespace std;
long long a[100005];
long long n,m,v,p;
bool check(int x){
	if(x<=p)return true;
	if(a[x]+m<a[p])return false;
	long long can=0;
	can+=m*(p-1);
	can+=m*(n-x+1);
	for(int i=p;i<x;i++){
		can+=(a[x]+m-a[i]);
	}
    if(can>=m*v)return true;
	return false;
}
int main(){
	cin>>n>>m>>v>>p;
	long long l=0,r=n+1;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	sort(a+1,a+n+1);
	reverse(a+1,a+n+1);
	while(l+1<r){
		long long mid=(l+r)/2;
		if(check(mid))l=mid;
		else r=mid;
	}
	long long ans=0;
	for(int i=1;i<=n;i++){
		if(a[i]>=a[l])ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
from collections import deque
n=int(input())
ans=[0 for i in range(n)]
l=[[] for i in range(n+1)]
for i in range(n-1):
  a,b=map(int,input().split())
  l[a].append(b)
  l[b].append(a)
l1=sorted(list(map(int,input().split())))
l1=l1[::-1]
sum=0
for i in range(1,n):
  sum+=l1[i]
q=deque(l1)
q1=deque([[1]])
while q:
  l2=q1.popleft()
  for i in l2:
    if ans[i-1]!=0:
      pass
    else:
      n2=q.popleft()
      ans[i-1]=n2
      q1.append(l[i])
print(sum)
answ=""
for i in range(n):
  answ+=str(ans[i])+" "
print(answ)

Measured memory_bytes: 6260
#include <stdio.h>
#include <inttypes.h>

#define KI_MAX (1 << 18) /* 262144 */

#define INF 1010101010

struct ki_t {
	int data[KI_MAX * 2 - 1];
	int all_data[KI_MAX * 2 - 1];
};

int ayaneru(int a, int b) {
	return a <= b ? a : b;
}

void ki_init(struct ki_t* ki) {
	int i;
	for (i = 0; i < KI_MAX * 2 - 1; i++) {
		ki->data[i] = ki->all_data[i] = INF;
	}
}

void ki_upd_i(struct ki_t* ki, int idx, int qs, int qe, int ss, int se, int value) {
	if (qe <= ss || se <= qs) { /* はずれ */
		/* nop */
	} else if (qs <= ss && se <= qe) { /* セグメントがクエリに完全に含まれる */
		ki->all_data[idx] = ayaneru(ki->all_data[idx], value);
	} else {
		int sm = ss + (se - ss) / 2;
		int li = idx * 2 + 1, ri = idx * 2 + 2;
		ki->all_data[li] = ayaneru(ki->all_data[li], ki->all_data[idx]);
		ki->all_data[ri] = ayaneru(ki->all_data[ri], ki->all_data[idx]);
		ki->all_data[idx] = INF;
		ki_upd_i(ki, li, qs, qe, ss, sm, value);
		ki_upd_i(ki, ri, qs, qe, sm, se, value);
		ki->data[idx] = ayaneru(ayaneru(ki->all_data[li], ki->data[li]), ayaneru(ki->all_data[ri], ki->data[ri]));
	}
}

void ki_upd(struct ki_t* ki, int qs, int qe, int value) {
	if (qs < qe) ki_upd_i(ki, 0, qs, qe, 0, KI_MAX, value);
}

int ki_get_i(const struct ki_t* ki, int idx, int qs, int qe, int ss, int se) {
	if (qe <= ss || se <= qs) { /* はずれ */
		return INF;
	} else if (qs <= ss && se <= qe) { /* セグメントがクエリに完全に含まれる */
		return ayaneru(ki->data[idx], ki->all_data[idx]);
	} else {
		int sm = ss + (se - ss) / 2;
		int l = ki_get_i(ki, idx * 2 + 1, qs, qe, ss, sm);
		int r = ki_get_i(ki, idx * 2 + 2, qs, qe, sm, se);
		return ayaneru(ayaneru(l, r), ki->all_data[idx]);
	}
}

int ki_get(const struct ki_t* ki, int qs, int qe) {
	return qs < qe ? ki_get_i(ki, 0, qs, qe, 0, KI_MAX) : INF;
}

int N, Q;
int type[212345], x[212345];

struct ki_t tate_ni_limit, yoko_ni_limit;

int main(void) {
	int i;
	int64_t minus_count = 0;
	if (scanf("%d%d", &N, &Q) != 2) return 1;
	for (i = 0; i < Q; i++) {
		if (scanf("%d%d", &type[i], &x[i]) != 2) return 1;
	}
	ki_init(&tate_ni_limit);
	ki_init(&yoko_ni_limit);
	ki_upd(&tate_ni_limit, 1, N + 1, N);
	ki_upd(&yoko_ni_limit, 1, N + 1, N);
	for (i = 0; i < Q; i++) {
		if (type[i] == 1) { /* 縦 */
			int limit = ki_get(&yoko_ni_limit, x[i], x[i] + 1);
			minus_count += (limit - 1) - 1;
			ki_upd(&tate_ni_limit, 1, limit, x[i]);
		} else if (type[i] == 2) { /* 横 */
			int limit = ki_get(&tate_ni_limit, x[i], x[i] + 1);
			minus_count += (limit - 1) - 1;
			ki_upd(&yoko_ni_limit, 1, limit, x[i]);
		}
	}
	printf("%" PRId64 "\n", (int64_t)(N - 2) * (N - 2) - minus_count);
	return 0;
}


Measured memory_bytes: 11436
#include<iostream>
#include<stack>
#include<cstdlib>
#include<string> 
using namespace std;
/*
用逆波兰表示法描述的算式可以借助栈进行运算。
程序在计算时从算式开 头逐一读取字符串，
如果字符串是操作数（ 数值 ）则压人栈，
如果是运算符（ + 、 - 、 ) 则 从栈中取出两个数值算出结果再压入栈，（后出栈-先出栈） 
如此循环。最终栈中剩下的数值便是答案。
*/
int main()
{
	stack<int> myStack;
	string s;
	while(cin>>s)	//以空格为分界，一次输入一个字符串 
	{
		if(s[0]=='+') {
			int a=myStack.top();
			myStack.pop();
			int b=myStack.top();
			myStack.pop();
			myStack.push(b+a);
		}
		else if(s[0]=='-') {
			int a=myStack.top();
			myStack.pop();
			int b=myStack.top();
			myStack.pop();
			myStack.push(b-a);
		}
		else if(s[0]=='*') {
			int a=myStack.top();
			myStack.pop();
			int b=myStack.top();
			myStack.pop();
			myStack.push(b*a);
		}
		else if(s[0]=='/') {
			int a=myStack.top();
			myStack.pop();
			int b=myStack.top();
			myStack.pop();
			myStack.push(b/a);
		}
		else myStack.push(atoi(s.c_str()));	//atoi()把字符串转化成数字,在cstdlib中 
	}
	cout<<myStack.top()<<endl; 
	return 0;
}


Measured memory_bytes: 3172
#include <iostream>
#include <tuple>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if( c>= a && c<=b)
		cout<<"Yes";
	else
		cout<<"No";
	cout<<"\n";
	return 0;
}

Measured memory_bytes: 256
while True:
    H, W = map(int, input().split())
    if H == W == 0:
        break
    for i in range(H):
        for j in range(W):
            if (i + j) % 2 == 0:
                print('#', end='')
            else:
                print('.', end='')
        print('')
    print('')

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

fn main() {
    let (a, b) = get!(i32, i32);
    let x = a + b;
    if x < 10 {
        println!("{}", x);
    } else {
        println!("error");
    }
}

Measured memory_bytes: 4352
#include <iostream>
#include <stdlib.h>
#include <vector> //vector
#include <algorithm> //sort()
#include <numeric>

#define rep(i, n) for(int i=0; i<(int)(n);i++)
#define all(x) (x).begin(), (x).end()
#define debug(a) cout << "debug (" #a "):" << endl << (a) << endl;

typedef uint64_t ulint;
typedef int64_t lint;

using namespace std;

template<class T> inline bool chmin(T& a, T b);
template<class T> inline bool chmax(T& a, T b);
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v);

template<class T> lint sum(vector<T> a);
template<class T> double ave(vector<T> a);

uint64_t a, b, c, d;
//uint64_t i, j;
lint n, m;

int main(){
//////////////////////////////////////////////////////

    cin >> a >> b >> c;

    if(a>b)
    {
        if(a>c)
        {
            cout << b+c;
        }
        else
        {
            cout << a+b;
        }

        
    }
    else
    {
        if(b>c)
        {
            cout << a+c;
        }
        else
        {
            cout << a+b;
        }
        
    }
    cout << endl;
    

// Ctrl + Opt + N to make
    return 0;
}


//最小化用関数
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;
}


// vectorprint用
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	int len = v.size();
	for (int i = 0; i < len; ++i) {
		s << v[i]; if (i < len - 1) s << "\t";
	}
	return s;
}

// //合計
// template<class T> lint sum(vector<T> a)
// {
//     return std::accumulate(a.begin(), a.end(), 0);
// }


// //平均
// template<class T> double ave(vector<T> a)
// {
//     return std::accumulate(a.begin(), a.end(), 0.0) / a.size();
// }


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

int main(){
    int a,b;
    cin >> a >> b;
    if(b == 1){
        cout << 0 << endl;
        return 0;
    }
    int cnt = a;
    int ans = 1;
    while(cnt < b){
        cnt--;
        cnt += a;
        ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <map> // pair
using namespace std;
int main(){
    int A,B,K;
    cin >>A>>B>>K;
    for(int i=A;i<B+1;i++){
      if(i<A+K||i>B-K)cout<<i<<endl;
    }
  }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;  
typedef long long ll;
int main() {
  ll n;
  cin >> n;
  vector<ll> v(87);
  v.at(0)=2;
  v.at(1)=1;
  for (ll i=2;i<87;i++) {
    v.at(i)=v.at(i-1)+v.at(i-2);
  }
  
  cout << v.at(n);
}

Measured memory_bytes: 256
// agrawal117
//chahatagrawal117
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef unsigned long long int ll;
int main()
{
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
     
       
  ll n;
  cin>>n;
  ll ans=(n-1)*n;
  ans/=2;
  cout<<ans<<endl;
   
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <map>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
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; }

int main(){
    char a;
    scanf("%c",&a);
    if(a > 93) cout << "a"<<endl;
    else cout << "A" <<endl;
    return 0;
}


Measured memory_bytes: 3684
import java.math.BigDecimal;
import java.util.*;

class Main {
	Scanner sc = new Scanner(System.in);

	public void run() {
		int n=sc.nextInt();
		for(int c=0;c<n;c++){
			double[] x=new double[3],y=new double[3];
			x[0]=sc.nextDouble();
			y[0]=sc.nextDouble();
			x[1]=sc.nextDouble();
			y[1]=sc.nextDouble();
			x[2]=sc.nextDouble();
			y[2]=sc.nextDouble();
			double[] center=
			getSol(new double[]{
				x[2]-x[1]
				,y[2]-y[1]
				,(x[2]*x[2]+y[2]*y[2]-x[1]*x[1]-y[1]*y[1])/2					
			},new double[]{
				x[2]-x[0]
				,y[2]-y[0]
				,(x[2]*x[2]+y[2]*y[2]-x[0]*x[0]-y[0]*y[0])/2					
			});
			double r=Math.sqrt(
				(center[0]-x[0])*(center[0]-x[0])+
				(center[1]-y[0])*(center[1]-y[0]));
			ln(String.format("%.3f %.3f %.3f",center[0],center[1],r));
		}
	}
	public static double[] getSol(double[] f1,double[] f2){
		return new double[]{
			(f1[2]*f2[1]-f1[1]*f2[2])/(f1[0]*f2[1]-f1[1]*f2[0]),
			(f1[2]*f2[0]-f1[0]*f2[2])/(f1[1]*f2[0]-f1[0]*f2[1])
		};
	}
	
	public static String join(double[] array, String separator) {
		StringBuilder str = new StringBuilder(array[0] + "");
		for (int i = 1; i < array.length; i++) {
			str.append(separator).append(array[i] + "");
		}
		return str.toString();
	}

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

	public static void pr(Object o) {
		System.out.print(o);
	}

	public static void ln(Object o) {
		System.out.println(o);
	}

	public static void ln() {
		System.out.println();
	}
}

Measured memory_bytes: 12000
#include<stdio.h>
#include<stdlib.h>
int partition(int*, int, int);
int main(){
  int n, *A, i, temp;
  scanf("%d",&n);
  A = (int *)malloc(sizeof(int) * n);
  for(i=0; i<n; i++)
    scanf("%d",&A[i]);
  temp = partition(A, 0, n-1);
  for(i=0; i<n; i++){
    if(i == temp)printf("[");
    printf("%d",A[i]);
    if(i == temp)printf("]");
    i!=n-1 ? printf(" ") : printf("\n");
  }
  free(A);
  return 0;
}

int partition(int *A, int p, int r){
  int x, i, j, temp;
  x = A[r];
  i = p - 1;
  for(j=p; j<=r-1; j++){
    if(A[j] <= x){
      i = i + 1;
      temp = A[i];
      A[i] = A[j];
      A[j] = temp;
    }
  }
  temp = A[i+1];
  A[i+1] = A[r];
  A[r] = temp;
  return i+1;
}

Measured memory_bytes: 888