akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define rep3(i, n) for (int i = 1; i < (int)(n+1); i++)
#define rep4(i, s, n) for (int i = (s); i < (int)(n+1); i++)
#define repr(i,n) for (int i = (n-1); i>=0;i--)
#define repr2(i,s,n) for (int i = (n-1); i>=(int)(s);i--)
#define repr3(i,n) for(int i = (n);i>0;i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Grid = vector<vector<int>>;
const ll INF = 10011032323450010;
const ld PI = 3.14159265358979323846;



int main() {
    int N;
    string pre ,now;
    bool judge=true;
    string S[101];
    map<string,int> word;
    cin>>N;
    rep(i,N){
        cin>>S[i];
        word[S[i]]++;
    }
    rep2(i,1,N){
        if(S[i][0]!=S[i-1][S[i-1].size()-1]){
            judge=false;
        }
        if(word[S[i]]>1){
            judge=false;
        }
        
    }
    if(judge){
        cout<<"Yes"<<endl;

    }
    else{
        cout<<"No"<<endl;
    }



return 0;
}

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

using namespace std;


#define M_DEBUG if(0)


int main() {
    /*  */
    vector<int> w_list;
    int n;
    cin >> n;
    assert(n>= 2 && n <= 100);
    for (int i = 0; i < n; i++) {
        int w;
        cin >> w ;
        assert(1 <= w && w <= 100);
        w_list.push_back(w);
    }

    int min = 10000; // 超えない
    for (int t = 1; t < n; t++){
        int s1 = -1, s2 = -1;
        for (int i = 0; i < n; i++) {
            if (i > t) s2 += w_list[i];
            else s1 += w_list[i];
        }
        if (min > abs(s1-s2)) min = abs(s1-s2);

    }

    assert(min > -1);

    cout << min << endl;

	return 0;
}


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

int main() {
	int N=0;
	int X=0;
	int T=0;
	scanf("%d", &N);
	scanf("%d", &X);
	scanf("%d", &T);
	if (N < 1) cout << "error" << endl;
	else if(N > 1000) cout << "error" << endl;;
	if (X < 1) cout << "error" << endl;
	else if (X > 1000) cout << "error" << endl;;
	if (T < 1) cout << "error" << endl;
	else if (T > 1000) cout << "error" << endl;;

	int sum = 0;
	int i = 1;
	for (i; N > sum; i++) {
		sum = X * i;
	}

	printf("%d\n", (i - 1) * T);
	return 0;
}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef int ll;
typedef long double ld;
const ll N = 100005;
char en = '\n';
ll inf = 1e16;

ll power(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n, m;
  cin >> n >> m;
  ll arr[n + 5];
  memset(arr, 0, sizeof(arr));
  ll l = -inf, r = inf;
  for (ll i = 1; i <= m; i++) {
    ll a, b;
    cin >> a >> b;
    l = max(l, a);
    r = min(r, b);
  }

  cout << max(0ll, r - l + 1) << en;
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
const long long INF = 1LL<<40;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll n, k;
    cin >> n >> k;
    vector<ll> maxd(n, -INF), vals;
    multiset<ll> se;
    for (ll i = 0; i < n; i++) {
        ll s, v;
        cin >> s >> v;
        s--;
        chmax(maxd[s], v);
        vals.push_back(v);
    }
    sort(vals.begin(), vals.end(), greater<ll>());
    sort(maxd.begin(), maxd.end(), greater<ll>());
    ll sum = 0;
    for (ll i = 0; i < k; i++) sum += vals[i], se.insert(vals[i]);

    ll ans = 0, tmp = sum;
    for (ll x = 1; x <= k; x++) {
        ll add = maxd[x-1];
        ll back = *se.begin();
        tmp += add;
        if (back > add) {
            se.erase(se.begin());    
            tmp -= back;
        } else {
            se.erase(se.find(add));
            tmp -= add;
        }
        chmax(ans, tmp + x * x);
    }
    cout << ans << endl;
}

Measured memory_bytes: 6260
#include<bits/stdc++.h>
//#define GYD
using namespace std;
const int maxn = 10 + 5;

int main()
{
    #ifdef GYD
    freopen("..//out.txt", "w", stdout);
    #endif // GYD
    int n, ans = 0;
    scanf("%d", &n);
    ans = n;
    printf("ABC%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
/*
 * wafuIroha.cpp
 *
 *  Created on: 2020/02/23
 *      Author: black
 */
#include <iostream>
using namespace std;

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

	int *a = new int[m];
	int *b = new int[m];

	for (int i=0; i<m; ++i){
		cin >> a[i] >> b[i];
	}

	int count;
	for(int i=1; i<=n; ++i){
		count = 0;
		for(int j=0; j<m; ++j){
			if (a[j] == i){
				++count;
				continue;
			}
			else if(b[j] == i){
				count++;
			}
		}
		cout << count << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    int s[1010];
    cin >>n;
    for(int i = 0;i<n;i++)
        cin >>s[i];
    while(n >=2 &&n <= 1000)
    {
        sort(&s[0],&s[n]);
        int c;
        c = s[1]-s[0];
        if(c<0)
        {
            c= 0-c;
        }
        for(int i = 1;i<n-1;i++)
        {
            int t = s[i+1]-s[i];
            if(t<0)
        {
            t=0-t;
        }
            if(t <c)
                c = t;
        }
        cout <<c<<endl;

        cin >>n;

    for(int i = 0;i<n;i++)
        cin >>s[i];
    }
    return 0;
}



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

int main(){

    int N;
    cin >> N;
    map<string,int> S;
    int maxi = 0;
    rep(i, N){
        string s = "";
        cin >> s;
        S[s] += 1;
        maxi = max(maxi,S[s]);
    }

    vector<string> ans(0);
    for(auto pair : S){
        if(pair.second == maxi) ans.push_back(pair.first);
    }

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

    rep(i, ans.size()) cout << ans[i] << endl;

    return 0;
}

Measured memory_bytes: 26868
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define eb emplace_back
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define rzip(i,a,b) for(int i=a;i>=b;i--)
#define ll unsigned int
#define test int t;cin>>t; while(t--)
#define um unordered_map
#define en '\n'
#define us unordered_set
typedef pair<int, int>     pii;
typedef pair<char, int>    pci;
typedef pair<char, char>   pcc;
typedef vector<pii>       vii;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define INF (1e18+5)
#define inf (1e9+5)
#define mod 1000000007


void __print(int x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
// You should only debug a pair of simple data types. For example,
// the debug won't work if one of pair's elements is collection type
// (std::vector, std::map, std::set...).
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif


// bool check_prime(int n)  return whether a number is prime or not O(sqrt(N));
// int BE(int x,int n,int m)  return x^n%m; O(logN);
// void sieve()  from number 1-1000001 saare prime store kar lega  in bool is_prime[1000001] array
// vector<int> z_array(string s)  return vector which is Z-array of string s;
// vector<int> lps(string s)      return vector which is lps array of string s;
// int power(int x,int n) return x^n; O(logN);
// using_ordered_set (template for using ordered set , replace first 2 lines of this page with this code..);


int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	if (fopen("input.txt", "r"))
	{
		freopen ("input.txt" , "r" , stdin);
		freopen ("output.txt" , "w" , stdout);
	}
#endif
	//_______________________________-code starts-_______________________________________________


	int n;
	cin >> n;
	int a[n];
	zip(i, 0, n)cin >> a[i];
	int ans = 0;
	sort(a, a + n);
	zip(i, 0, n)
	zip(j, i + 1, n)
	zip(k, j + 1, n)
	if (a[i] + a[j] > a[k] && a[i] != a[j] && a[j] != a[k] && a[i] != a[k])
		ans++;


	cout << ans << en;

	return 0;
}




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

#define ll          long long
#define mp	    make_pair
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;
#define N 	 10000
vector<pair<string, int> >ans[N];	
void solve(){
	int n;
	cin>>n;
	vi score(n);
	vector<pair<string, int> > v;
	rep(i,0,n){
		string s;
		cin>>s;
		cin>>score[i];
		v.pb(mp(s, score[i]));
	}
	sort(all(v));
	ans[0].pb(v[0]); 
	ll j = 0;
	rep(i, 1, sz(v)){
		if(v[i].x == v[i-1].x)
			ans[j].pb(v[i]);
		else{
			j++;
			ans[j].pb(v[i]);
		}
	}
	rep(i, 0, 100) {
		sort(all(ans[i])); 
		reverse(all(ans[i]));
	}
	rep(i, 0, 100){
		rep(j, 0, sz(ans[i])){
			auto it = find(all(score), ans[i][j].y);
			cout << it - score.begin()+ 1<< endl;
		}
	}
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
     t =1;
//     cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


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

int main(){
 int A;
 int B;
 cin >> A >> B;
 int ans;
 if(A==1 && B==2){
  ans=3;
 }
 else if(A==1 && B==3){
  ans=2;
 }
 else if(A==2 && B==1){
  ans=3;
 }
 else if(A==2 && B==3){
  ans=1;
 }
 else if(A==3 && B==1){
  ans=2;
 }
 else{
  ans=1;
 }
 cout << ans << endl;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(700000)

def s_in():
    return input()

def n_in():
    return int(input())

def l_in():
    return list(map(int, input().split()))

n,m,x = l_in()

MAX = 10000000
res = MAX


C = []
A = []
for _ in range(n):
    tmp = l_in()
    c = tmp[0]
    a = tmp[1:]
    C.append(c)
    A.append(a)

stack = []

def evaluate():
    R = [0]*m
    c = 0
    for i, t in enumerate(stack):
        if t == 1:
            c += C[i]
            for j, b in enumerate(A[i]):
                R[j] += b

    if all(r >= x for r in R):
        return c
    else:
        return MAX
            

def do(i):
    tmp = MAX
    for t in [0,1]:        
        stack.append(t)
        if i == n-1:
            tmp = min(tmp, evaluate())
        else:
            tmp = min(tmp, do(i+1))
        stack.pop()
    return tmp

res = do(0)
    
if res == MAX:
    print(-1)
else:
    print(res)
    


Measured memory_bytes: 70644
d = {1:2, 2:3, 3:1}
while True:
    h = int(input())
    if h == 0:
        break
    h = [h] + [int(input()) for _ in range(4)]
    if len(set(h)) == 3 or len(set(h)) == 1:
        print(*[3]*5, sep='\n')
        continue
    for c in h:
        print([2, 1][d[c] in h])

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

using ll = long long;
using cd = complex<double>;

map<ll, ll> things;

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


    int k;
    string s;
    cin >> ws >> s >> ws >> k;

    if(all_of(begin(s), end(s), [&](char ch){ return ch == s[0]; })){
        things[(ll)s.size() * k] += 1;
    } else {
        if(s[0] == s.back()){
            int fr = 0, bk = 0;
            char target = s[0];

            while(s.back() == target){
                ++fr;
                s.pop_back();
            }
            reverse(begin(s), end(s));
            while(s.back() == target){
                ++bk;
                s.pop_back();
            }

            things[fr] += 1;
            things[bk] += 1;
            things[bk + fr] += k - 1;
        }
        while(!s.empty()){
            char target = s.back();
            int nr = 0;
            while(!s.empty() && s.back() == target){
                s.pop_back();
                ++nr;
            }
            things[nr] += k;
        }
    }

    ll ret = 0;
    for(auto x : things){
        ll val, nr;
        tie(val, nr) = x;
        ret += (ll)nr * (val / 2);
    }

    cout << ret << endl;

    return 0;
}



Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <climits>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
//#include <tuple>

#define INF INT_MAX>>1 
#define SIZE 100010
#define MOD 1000000007
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep2(i, from, to) for(int i=(from); i<(int)(to); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define LLPair pair<ll, ll>
#define vint vector<int>
#define vll vector<ll>
typedef long long ll;

using namespace std;

struct Point { int x, y; };
struct Edge { int from, to, cost; };
struct gNode { int from, to, cost; };
struct tNode { int value; int parent; vector<int> child; };

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

int gcd(int a, int b){ return a % b == 0 ? b : gcd(b, a%b); }
int lcm(int a, int b){ return a * b/ gcd(a, b); }
int extgcd(int a, int b, int& x, int& y){
	int d = a;
	if(b != 0){
		d = extgcd(b, a%b, y, x);
		y -= (a/b) * x;
	} else{
		x = 1; y = 0;
	}
	return d;
}
ll mod_pow(ll x, ll n){
	if(n == 0) return 1;
	ll res = mod_pow(x*x % MOD, n/2);
	if(n & 1) res = res * x % MOD;
	return res;
}

int main(void){
	int n; cin >> n;
	vector<vint> a(n);
	rep(i, n) a[i].resize(n-1);
	rep(i, n){
		rep(j, n-1){
			cin >> a[i][j];
			a[i][j]--;
		}
		reverse(a[i].begin(), a[i].end());
	}

	vector<int> prev_changed;
	rep(i, n) prev_changed.push_back(i);
	vector<int> can_game;
	vector<bool> flag(n);
	ll ans = 0;
	while(1){
		fill(flag.begin(), flag.end(), false);
		while(!prev_changed.empty()){
			int i = prev_changed[prev_changed.size()-1];
			prev_changed.pop_back();
			if(a[i].size() == 0) continue;
			if(flag[i]) continue;
			int opponent = a[i][a[i].size()-1];
			if(a[opponent][a[opponent].size()-1] == i){
				flag[i] = true;
				flag[opponent] = true;
				can_game.push_back(i);
				can_game.push_back(opponent);
			}
		}
		bool can = false;
		while(!can_game.empty()){
			int i = can_game[can_game.size()-1];
			can_game.pop_back();
			a[i].pop_back();
			prev_changed.push_back(i);
			can = true;
		}
		if(!can) break;
		ans++;
	}

	rep(i, n){
		if(!a[i].empty()){
			cout << -1 << endl;
			return 0;
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 4224
import java.io.*;
import java.util.*;
public class Main{
    public static void main(String[] args) throws IOException{
        MyReader r = new MyReader();     
        int A, B, C;
        {int[] a = r.ii(); A = a[0]; B = a[1]; C = a[2];}
        println(Math.max(C-A+B, 0));
    }
    static void print(Object o){
        System.out.print(o.toString());
    }
    static void println(Object o){
        System.out.println(o.toString());
    }
    static int Int(String s){
        return Integer.parseInt(s);
    }
    static long Long(String s){
        return Long.parseLong(s);
    }
    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }
        String s() throws IOException{
            return readLine();
        }
        String[] ss() throws IOException{
            return s().split(" ");
        }
        int i() throws IOException{
            return Int(s());
        }
        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }
        long l() throws IOException{
            return Long(s());
        }
        long[] ll() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            long[] ll = new long[size];
            for(int j = 0; j < size; j++) ll[j] = Long.parseLong(ss[j]);            
            return ll;
        }
    }
}

Measured memory_bytes: 21204
n=int(input())
c=list(map(int,input().split()))
c.sort(reverse=1)
ans=0
mod=10**9+7
m=pow(4,n-1,mod)
x=2*m%mod
for i in range(n):
  ans+=x*c[i]
  ans%=mod
  x+=m
  x%=mod
print(ans)

Measured memory_bytes: 27108
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long
#define mod107 1000000007
#define rep(i, n) for (int i = 0; i < n; ++i)
using Graph = vector<vector<int>>;
#define grepq priority_queue<double, std::vector<double>, std::greater<double>>
#define all(v) v.begin(), v.end()
#define PI acos(-1)

const ll INF = 10010001010;
const int inf = 1000034000;
typedef vector<ll> vecl;
typedef vector<int> veci;
typedef tuple<string, int, int> TUP;

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


int main()
{
    int N,T;
    cin >> N >> T;
    vector<int> t(N);
    ll ans = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> t[i];
    }
    for (int i = 0; i < N - 1;i++)
    {
        ans += min(t[i+1] - t[i],T);
    }
    cout << ans + T << endl;
}


Measured memory_bytes: 3868
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int N;
    cin >> N;

    vector<int> a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

    cout << a[N-1] << endl;
    
}


Measured memory_bytes: 256
#import numpy as np
import sys
input=sys.stdin.buffer.readline
n=int(input())
d=[list(map(int,input().split())) for _ in range(n) ]
#d=np.array(d,np.int64)
#do a floyd warshall and test if something improves 
for k in range(n):
    for i in range(n):
        for j in range(i+1,n):
            if d[i][k]+d[k][j]<d[i][j]:
                print(-1)
                exit()
ans=0
for i in range(n):
    for j in range(i+1,n):
        flag=True
        for k in range(n):
            if k!=i and k!=j and d[i][k]+d[k][j]==d[i][j]:
                flag=False
        if flag:
            ans+=d[i][j]
print(ans)



Measured memory_bytes: 43868
#include<bits/stdc++.h>
#define rpt(n) for(register int ttxyc=0;ttxyc<n;++ttxyc)//宏定义
using namespace std;
int ans=1,n,k;
main()
{
    scanf("%d%d",&n,&k);
    rpt(n)ans+=min(ans,k);
    printf("%d\n",ans);
}/**/

Measured memory_bytes: 256
import math

#入力
N, M = map(int, input().split())


#combination 関数
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

#main
if N <=1 and M <= 1:
  print(0)

elif N <= 1 and M>=2:
  print(combinations_count(M,2))

elif M <=1 and N>=2:
  print(combinations_count(N,2))
  
elif N >=2 and M >=2:
  print(combinations_count(N,2)+combinations_count(M,2))


Measured memory_bytes: 3060
#include<cstdio>
#include<cstring>
#include<algorithm>
#define x first
#define y second
using namespace std;
typedef long long LL;

const int maxn = 200009;
pair<int,int> a[maxn];
int n, tmp, _mx, _mn, mx, mn, best; 
LL ans = 1e18;

int main(){
	scanf("%d", &n);
	if (n == 1) { puts("0"); return 0; }
	a[0].x = 1e9 + 1;
	for (int i=1; i<=n; i++){
		scanf("%d%d", &a[i].x, &a[i].y);
		if (a[i].x > a[i].y) swap(a[i].x, a[i].y);
	}
	sort(a+1, a+n+1);
	for (int i=1; i<=n; i++)
		if (a[i].x <= a[_mn].x && a[i].y >= a[_mx].y) _mn = _mx = i;
		else if (a[i].x < a[_mn].x) _mn = i;
		else if (a[i].y > a[_mx].y) _mx = i;
	mn = 1e9 + 1;
	for (int i=1; i<=n; i++){
		mn = min(mn, a[i].y);
		mx = max(mx, a[i].x);
	}
	ans = 1LL * (mx-a[_mn].x) * (a[_mx].y-mn);
	if (_mn != _mx){
		best = 1e9 + 1; mn = mx = a[1].y;
		for (int i=2; i<=n; i++){
			best = min(best, max(a[n].x, mx) - min(a[i].x, mn));
			mn = min(mn, a[i].y);
			mx = max(mx, a[i].y);
		}
		ans = min(ans, 1LL * best * (a[_mx].y - a[_mn].x));
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
 
#define vi vector<int>
#define ll long long
#define pb push_back
#define mp make_pair
#define endl "\n"
#define ii pair<int,int>
#define qu queue <int>
#define qmax priority_queue <int>
#define qmin priority_queue <int, vector<int>,greater<int>>

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int a, b, c;

    cin>>a>>b>>c;

    cout<<(a*b)/2<<endl;

    return 0;
}

Measured memory_bytes: 3576
/* ex9_2
   TakayukiY*/

#include <stdio.h>
#include <stdlib.h>

//リストのノード（スタック内の各データ）の定義
typedef struct node
{
    char elem;
    struct node *next;
} node;

//スタックにデータを追加
void push(node **first, char elem)
{
    node *new = calloc(1, sizeof(node));
    if (new == NULL)
        exit(1);
    new->elem = elem;
    new->next = *first;
    *first = new;
}

//スタックからデータを取り出す
char pop(node **first)
{
    char elem;
    node *tmp = *first;
    if (tmp == NULL)
        return '\0';
    elem = tmp->elem;
    *first = tmp->next;
    free(tmp);
    return elem;
}

//スタックのメモリをすべて解放
void free_stack(node **first)
{
    node *tmp = *first, *next;
    while (tmp != NULL)
    {
        next = tmp->next;
        free(tmp);
        tmp = next;
    }
}

int main(void)
{
    char input[100000 + 1], *ptr;
    node *first = NULL;
    int count = 0;

    //入力を受け取る
    scanf("%s", input);
    ptr = input;

    //1文字ずつ走査
    while (*ptr != '\0')
    {
        if (first==NULL)
        {
            push(&first, *ptr);
        }
        else
        {
            //同じ文字が連続している場合
            if (first->elem == *ptr)
            {
                push(&first, *ptr);
            }
            //違う文字がつながったとき、消去
            else
            {
                pop(&first);
                count+=2;
            }
        }
        ptr++;
    }

    printf("%d", count);

    free_stack(&first);

    return 0;
}

Measured memory_bytes: 4876
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int N;
    cin >> N;
    vector<int> T(N), F(N);
    rep(i, N) {
        int a;
        cin >> a;
        rep(j, a) {
            int x, y;
            cin >> x >> y;
            x--;
            if (y) T[i] |= 1 << x;
            else F[i] |= 1 << x;
        }
    }

    int ans = 0;
    for (int bit = 0; bit < 1 << N; ++bit) {
        bool ok = true;

        rep(i, N) {
            if (bit >> i & 1) {
                rep(j, N) {
                    if ((T[i] >> j & 1) && ((bit >> j & 1) == 0)) ok = false;
                    if ((F[i] >> j & 1) && (bit >> j & 1)) ok = false;
                }
            }
        }

        if (ok) {
            int c = 0;
            rep(i, N) c += (bit >> i & 1);
            ans = max(ans, c);
        }
    }

    write(ans);
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
	int h,w,i,j;
	while(1){
		scanf("%d %d",&h,&w);
		if(h == 0 && w == 0) return 0;
		for(i = 0; i < h; i++){
			for(j = 0; j < w; j++){
				if((i == 0 || i == h-1) || (j == 0 || j == w-1))
					putchar('#');
				else
					putchar('.');
			}
			if(i < h-1) putchar('\n');
			else{
				putchar('\n');
				putchar('\n');
			}
		}
	}
	return 0;
}

Measured memory_bytes: 572
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    ll ans = 1;
    cin >> n;
    string s;
    cin >> s;
    vint abc(26,0);
    REP(i,n){
        abc[s[i]-'a']+=1;
    }
    REP(i,26){
        ans*=abc[i]+1;
        if(ans>=mod)ans%=mod;
    }
    cout << ans-1 << endl;
    return 0;
}

Measured memory_bytes: 512
#include <stdio.h>

int n, A[50];
int solve(int i, int m) {
    if(m==0) return 1;
    if(i>=n) return 0;
    int res = solve(i+1,m) || solve(i+1,m-A[i]);
    return res;
}

int main(void) {
    int q, M, i;

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


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

int main(){
	int n;
	while( cin >> n , n ){
		vector<pair<int,pair<int,pair<int,int> > > > vc;
		vector<int> ans;
		int u[1001] = {0};

		for(int i=0 ; i < n ; i++ ){
			int ID,Univ,AC,WA;
			cin >> ID >> Univ >> AC >> WA;
			pair<int,int> a(ID,Univ);
			pair<int,pair<int,int> > b(WA,a);
			pair<int,pair<int,pair<int,int> > > c(-AC,b);
			vc.push_back( c );
		}
		sort( vc.begin() , vc.end() );
		for(int i=0 ; i < n ; i++ ){
			int AC = -vc[i].first;
			int WA = vc[i].second.first;
			int ID = vc[i].second.second.first;
			int Univ = vc[i].second.second.second;
			if( ans.size() < 10 && u[Univ] < 3 ){
				ans.push_back( ID );
				u[Univ]++;
			}else if( ans.size() < 20 && u[Univ] < 2 ){
				ans.push_back( ID );
				u[Univ]++;
			}else if( ans.size() < 26 && u[Univ] < 1 ){
				ans.push_back( ID );
				u[Univ]++;
			}
		}
		for(int i=0 ; i < ans.size() ; i++ ){
			cout << ans[i] << endl;
		}
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cout << H << " "; debug_out(T...); }
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

struct Station {
  ll cost, f, start;
};

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int n;
  cin >> n;
  vector<Station> a(n-1);
  rep(i,n-1) {
    Station st;
    cin >> st.cost >> st.start >> st.f;
    a[i] = st;
  }
  rep(i,n-1) {
    ll cur = 0; //今の時間
    for (int j = i; j < n-1; ++j) {
      if (cur < a[j].start) cur += a[j].start - cur;
      ll m = (cur - a[j].start + a[j].f - 1) / a[j].f; //切り上げ
      cur += a[j].start - cur + a[j].f * m;
      cur += a[j].cost;
    }
    cout << cur << endl;
  }
  cout << 0 << endl; //駅n
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
signed main(){
    int n; cin >> n;
    ll inf = 1000000000000000;
    ll dist[5002],x[5001];
    vector<vector<pair<int,int>>>edge(n+1);
    map<string,int>mp;
    int source = n;
    for(int i = 0; i < 5001;i++){
        dist[i] = inf;
    }
    for(int i = 0; i < n;i++){
        string s;
        cin >> s >> x[i];
        mp[s] = i;
        edge[source].push_back(make_pair(i,x[i]));
    }
    int m; cin >> m;
    for(int i = 0; i < m;i++){
        string _s,_t; cin >> _s >> _t;
        int s = mp[_s],t = mp[_t];
        edge[s].push_back(make_pair(t,0));
        edge[t].push_back(make_pair(s,0));
    }
    priority_queue<vector<ll>,vector<vector<ll>>,greater<vector<ll>>>que;
    dist[source] = 0;
    que.push({dist[source],source});
    while(!que.empty()){
        auto top = que.top();
        que.pop();
        ll tdist = top.front();
        ll now = top.back();
        if(dist[now] > tdist)continue;
        for(int i = 0; i < edge[now].size();i++){
            int to =edge[now][i].first;
            int cost = edge[now][i].second;
            if(dist[to] > tdist  + cost){
                dist[to] = tdist + cost;
                que.push({dist[to],to});
            }
        }
    }
    int ans = 0;
    for(int i = 0; i < n;i++) ans += dist[i];
    cout << ans << endl;
}



Measured memory_bytes: 4252
#include <stdio.h>

int selectionSort(int A[], int N) {
  int i, j, t, sw = 0, mini;
  for(i=0; i<N-1; i++) {
    mini = i;
    for(j=i; j<N; j++) {
      if(A[j] < A[mini]) mini = j;
    }

  	t = A[i];
  	A[i] = A[mini];
  	A[mini] = t;

  	if(i != mini) sw++;
  }
  return sw;
}

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

  sw = selectionSort(A,N);

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

  return 0;
}



Measured memory_bytes: 2108
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]


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

sa = []
for i in range(n):
    #print(w[0:i+1])
    #print(w[i+1:n+1])
    s1 = sum(w[0:i+1])
    s2 = sum(w[i+1:n+1])
    sa.append(abs(s1-s2))
#print(sa)
print(min(sa))


Measured memory_bytes: 8952
#include <cstdio>
#define MOD 1000000007
#define INF 1e9
#define eps 1e-6
typedef long long ll;

ll x, y, xx, yy, inv[2000010], prod[2000010], ans;

int main(){

	scanf("%lld%lld", &x, &y);
	if((x + y) % 3){
		puts("0");
		return 0;
	}
	xx = x - (x + y) / 3;
	yy = y - (x + y) / 3;
	if(x < 0 || y < 0)
		puts("0");
	else{
		inv[0] = inv[1] = 1;
		for(ll i = 2; i <= (xx + yy); i++)
			inv[i] = (MOD - MOD / i) * inv[MOD % i] % MOD;
		for(ll i = 2; i <= (xx + yy); i++)
			inv[i] = inv[i - 1] * inv[i] % MOD;
		prod[0] = 1;
		for(ll i = 1; i <= (xx + yy); i++)
			prod[i] = prod[i - 1] * i % MOD;
		ans = prod[xx + yy] * inv[xx] % MOD * inv[yy] % MOD;
		printf("%lld\n", ans);
	}

	return 0;
}


Measured memory_bytes: 14464
#include <iostream>
#include <string>
#include <cctype>
#include <map>

using namespace std;

int to_num_from_mcxi(string inp);
string to_mcxi_from_num(int num);

int main()
{
    int n;

    cin >> n;

    for (int i = 0; i < n; i++) {
        string x1, x2;
        int num1, num2;

        num1 = num2 = 0;
        cin >> x1 >> x2;

        num1 = to_num_from_mcxi(x1);
        num2 = to_num_from_mcxi(x2);

        num1 += num2;

        cout << to_mcxi_from_num(num1) << endl;
    }

    return 0;
}


int to_num_from_mcxi(string inp)
{
    int num = 0;
    map<char, int> mcxi;

    mcxi['m'] = 1000;
    mcxi['c'] = 100;
    mcxi['x'] = 10;
    mcxi['i'] = 1;

    for (int i = 0; i < inp.size(); i++) {
        if (isdigit(inp[i])) 
            num += (inp[i] - '0') * mcxi[inp[++i]];
        else
            num += mcxi[inp[i]];
    }

    return num;
}


string to_mcxi_from_num(int num)
{
    string output;
    int dig[] = {1000, 100, 10, 1};
    char mcxi[] = {'m', 'c', 'x', 'i'};

    for (int i = 0; i < 4; i++) {
        if (num / dig[i] == 0)
            continue;
        else if (num / dig[i] == 1)
            output += mcxi[i];
        else {
            output += (num / dig[i]) + '0';
            output += mcxi[i];
        }
        num %= dig[i];
    }

    return output;
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REP1(i,n) for(int i = 1; i < n+1 ;i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
using namespace std;
typedef long long ll;
using p = pair<int, int>;
using P = pair<ll, ll>;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
using Graph = VV;

int main(){
    ios::sync_with_stdio(false); cin.tie(0);
    int n,m,x;
    cin >>n>>m>>x;
    V a(m);
    V b(n);
    
    REP(i,m) {
        cin >> a[i];
        b[a[i]]=1;
    }
    int ans1=0,ans2=0;
    REP(i,x+1){
        ans1+=b[i];
    }
    //cout << "Start" << endl;
    FOR(i,x+1,n){
        ans2+=b[i];
    }

    cout << min(ans1,ans2) << endl;
    //cout << "Finished" << endl;
    return 0;
    




}

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

const int INF = 1e9;

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

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

  queue<int> q;
  vector<int> d(n, -1);
  d[0] = 0;
  q.push(0);
  while ( !q.empty() ) {
    int p = q.front(); q.pop();
    for ( int i = 0; i < n; i++ ) {
      if ( G[p][i] && d[i] == -1 ) {
	q.push(i);
	d[i] = d[p]+1;
      }
    }
  }

  for ( int i = 0; i < n; i++ ) {
    cout << i+1 << " " << d[i] << endl;
  }
  
  return 0;
}



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

#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()
typedef long long ll;

int cou;

void merge(vector<int> &v, int left, int mid, int right){
//    cou++;
//    cout << left <<":"<<mid<<":"<<right<<endl;
    vector<int> lvc, rvc;
//    lvc.assign(v.begin()+left,v.begin()+mid-1);
//    rvc.assign(v.begin()+mid,v.begin()+right-1);
    for(int i=0;i<mid-left;i++)lvc.push_back(v[left+i]);
    for(int i=0;i<right-mid;i++)rvc.push_back(v[mid+i]);
//    for(int i=0;i<lvc.size();i++)cout << lvc[i]<<(i!=lvc.size()-1?" ":"\n");
    lvc.pb(INT_MAX);
    rvc.pb(INT_MAX);
    int lloc, rloc;
    lloc = rloc = 0;
    for(int k = left; k < right; k++){
        cou++;
        if(lvc[lloc]<=rvc[rloc]){
//            cout << lvc[lloc]<<endl;
            v[k]=lvc[lloc];
            lloc++;
        }else{
            v[k]=rvc[rloc];
            rloc++;
        }
    }
//    for(int i=left;i<right;i++)cout << v[i]<<(i!=right-1?" ":"\n");
}

void merge_sort(vector<int> &v,int left,int right){
//    cou++;
    if(right-left>1){
        int mid = (right + left) / 2;
        merge_sort(v, left, mid);
        merge_sort(v, mid, right);
        merge(v, left, mid, right);
    }
}

int main(){
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> s(n);
    REP(i,n)cin >> s[i];
    merge_sort(s,0,n);

    REP(i,n)cout << s[i] << (i!=n-1?" ":"\n");
    cout << cou << endl;
}



Measured memory_bytes: 7468
#include <iostream>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <string>
#include <cstring>
#include <algorithm>
typedef long long ll;
using namespace std;

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

    int N;
    cin >> N;
    ll sum=0;
    for (int i = 1; i <= N; ++i) {
        if(i%3 != 0 && i%5!=0) sum+=i;
    }
    cout<<sum<<endl;
    
}

Measured memory_bytes: 3652
# coding: utf-8

N, M = map(int,input().split())
H = list(map(int,input().split()))
flg = [True] * (N+1)

for i in range(M):
    a, b = map(int,input().split())
    if H[a-1] > H[b-1] and flg[b]:
        flg[b] = False
    elif H[a-1] < H[b-1] and flg[a]:
        flg[a] = False
    elif H[a-1] == H[b-1]:
        flg[a] = False
        flg[b] = False

ans = 0
#print(flg)
for i in flg:
    if i:
        ans += 1
ans -= 1
print(ans)

Measured memory_bytes: 84760
#include <vector> 
#include <list> 
#include <map> 
#include <set> 
#include <deque> 
#include <queue> 
#include <stack> 
#include <bitset> 
#include <algorithm> 
#include <functional> 
#include <numeric> 
#include <utility> 
#include <sstream> 
#include <iostream> 
#include <iomanip> 
#include <cstdio> 
#include <cmath> 
#include <cstdlib> 
#include <cctype> 
#include <string> 
#include <cstring> 
#include <ctime> 

using namespace std;

#define _int64 long long

int main()
{
  int n,tot;
  scanf("%d",&n);
  tot=0;
  while (n>0)
  {
    tot+=n%10;
    n/=10;
  }
  if (tot==1) tot=10;
  printf("%d\n",tot);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n,q;
string s,a;
vi b;

int f(){
	int l=-1,r=n;
	while(r-l>1){
		int m=(l+r)/2,x=m;
		for(int i=0;i<q;i++){
			if(s[x]==a[i]) x+=b[i];
			if(x==n||x==-1) break;
		}
		if(x==-1) l=m;
		else r=m;
	}
	reverse(s.begin(),s.end());
	for(int i=0;i<q;i++) b[i]*=-1;
	return l;
}

int main(){
	cin>>n>>q>>s;
	a=string(q,'.');
	b=vi(q,1);
	for(int i=0;i<q;i++){
		char c;
		cin>>a[i]>>c;
		if(c=='L') b[i]=-1;
	}
	cout<<n-2-f()-f()<<endl;
}

Measured memory_bytes: 1540
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//(a+b-1)/b
//priority_queue<ll, vector<ll>, greater<ll>> q;
template<int MOD> struct Fp {  
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};
using mint = Fp<MOD>;

mint mypow(mint a,ll b){
	if(b==0)return 1;
	if(b%2==0){
		mint t=mypow(a,b/2);
		return t*t;
	}
	return a*mypow(a,b-1);
}
mint combination(ll n,ll k){
	//n個の中からk個選ぶ
	ll cnt=0;
	mint a=1,b=1;
	for(ll i=n;cnt<k;i--){
		a*=i;
		cnt++;
	}
	cnt=0;
	for(ll i=k;i>0;--i){
		b*=i;
	}
	return (mint)a/b;
	 
}

signed main(){
	//cout << fixed << setprecision(10);
	ll n2,a2,b2; cin>>n2>>a2>>b2;
	mint n=n2,a=a2,b=b2;
	mint ans=mypow(2,n2)-1;
	ans-=combination(n2,a2);
	ans-=combination(n2,b2);
	cout<< ans << endl;

	return 0;
}

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


int32_t main(){

   char ch = 'z' + 1;
   string s;
   cin >> s;
   int dp[26] = {0};
   for(auto ch : s) dp[ch - 'a']++;
   for(int i = 0; i < 26; i++) 
      if(!dp[i]){
         ch = i + 'a';
         cout << ch << endl;
         return 0;
      }

   cout << "None" << endl;
   
}

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

using namespace std;

int main(){
  int W, H, N;
  cin >> W >> H >> N;

  vector<int> mx(W);
  for(int i=0;i<N;++i){
	int x, y;
	cin >> x >> y;
	mx[x] = max(mx[x], y);
  }

  int ans = 1e9;
  int mx_y = 0;
  for(int x=W-1;x>=0;--x){
	ans = min(ans, x + mx_y);
	mx_y = max(mx_y, mx[x]);	
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3092
def resolve():
    n, k = list(map(int, input().split()))
    xxx = list(map(int, input().split()))
    ans = float("inf")
    for i in range(n-k+1):
        max_l = xxx[i+k-1]
        min_l = xxx[i]
        if not min_l <= 0 <= max_l:
            ans = min(ans, max(abs(min_l), abs(max_l)))
        else:
            ans = min(ans, min(abs(min_l), abs(max_l))+abs(max_l-min_l))
    print(ans)
resolve()

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
#define ld long double
#define ll long long
#define mod 1000000007
#define IINF INT_MAX
#define INF 1LL << 30


int main() {
    int n, d; cin >> n >> d;
    V<V<int> > v(n);
    for(int i = 0; i < n; i++){
        for(int j = 0; j < d; j++){
            int x; cin >> x;
            v[i].push_back(x);
        }
    }

    int ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n; j++){
            double sum = 0;
            for(int k = 0; k < d; k++){
                sum += pow(abs(v[i][k] - v[j][k]), 2);
            }
            if(floor(sqrt(sum)) == sqrt(sum)) ans++;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3624
#include <cstdlib>
#include <iostream>


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

  int n;
  std::cin >> n;
  for (int i = 0; i < 100 / 4; i++) {
    for (int j = 0; j < 100 / 7; j++) {
      if (4 * i + 7 * j == n) {
        std::cout << "Yes" << std::endl;
        return EXIT_SUCCESS;
      }
    }
  }
  std::cout << "No" << std::endl;

  return EXIT_SUCCESS;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef pair<int, int>P;
/**********************************************/
int par[100005] = {0};
int r[100005] = {0};
struct edge{
	int from, to, cost;
};
int v, e;
edge es[100005];
int n;
void init(int n){
	for(int i = 0; i < n; i++){
		par[i] = i;
		r[i] = 0;
	}
}

int find(int x){
	if(par[x] == x){
		return x;
	}
	else{
		return par[x] = find(par[x]);
	}
}

void unite(int x,int y){
	x = find(x);
	y = find(y);
	if(x == y) return;
	if(r[x] < r[y]){
		par[x] = y;
	}
	else{
		par[y] = x;
	}
	if(r[x] == r[y]) r[x]++;
}

bool same(int x,int y){
	if(find(x) == find(y)) return true;
	else return false;
}

bool comp(edge esx, edge esy){
	return esx.cost < esy.cost;
}

int kruskal(){
	sort(es, es + e, comp);
	int res = 0;
	init(v);
	for(int i = 0; i < e; i++){
		if(!same(es[i].from, es[i].to)){
			res += es[i].cost;
			unite(es[i].from, es[i].to);
		}
	}
	return res;
}

int main() {
	int q;
	cin >> n >> q;
	init(n + 5);
	for (int i = 0; i < q; i++) {
		int com, x, y;
		cin >> com >> x >> y;
		if (com) {
			if (same(x, y)) cout << "1" << endl;
			else cout << "0" << endl;
		}
		else unite(x, y);
	}
}


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

int main() {
	int n;
	char s[100];
	int ans = 0,temp = 0;
	cin >> n >> s;

	for (int i = 1;i < n;++i) {
		temp = 0;
		map<char,bool> x;
		for (int j = 0;j < n;++j) {
			if (j < i && !(x[s[j]])) x[s[j]] = true;
			else if (j >= i && x[s[j]]) {
				x[s[j]] = false;
				temp++;
			}
		}
		ans = max(ans,temp);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int size = sc.nextInt();
        int n = sc.nextInt();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            int y = sc.nextInt();
            int idx = Math.min(Math.min(x - 1, size - x), Math.min(y - 1, size - y));
            idx %= 3;
            sb.append(idx + 1).append("\n");
        }
        System.out.print(sb);
    }
}



Measured memory_bytes: 33240
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
using namespace std;

ll n,a[200010],L[200010],R[200010];

int main()
{

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

    cin >> n;
    for(ll i=1; i<=n; i++){
        cin >> a[i];
        L[i]=a[i];
        if(i) L[i]=max( L[i], L[i-1] );
    }
    R[n]=a[n];
    for(ll i=n-1; i>=1; i--) R[i]=max(a[i],R[i+1]);

    for(ll i=1; i<=n; i++) cout << max( L[i-1] , R[i+1] ) << "\n";
    return 0;
}


Measured memory_bytes: 6272