akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
using namespace std;
#define getbit(n, i) (((n) & (1LL << (i))) != 0) 
#define setbit0(n, i) ((n) & (~(1LL << (i)))) 
#define setbit1(n, i) ((n) | (1LL << (i))) 
#define togglebit(n, i) ((n) ^ (1LL << (i))) 
#define lastone(n) ((n) & (-(n))) 
char gap = 32;
template<typename T> 
ostream& operator<<(ostream &os, const vector<T> &v) { 
    os << '{'; 
    for (const auto &x : v) os << gap << x;
        return os << '}'; 
}
template<typename A, typename B> 
ostream& operator<<(ostream &os, const pair<A, B> &p) {
        return os << '(' << p.first << gap << p.second << ')';
}

template <class T>
void read(T &x) {
    char c;
    for (c = getchar(); c < '0' || c > '9'; c = getchar())
        ;
    for (x = 0; c <= '9' && c >= '0'; c = getchar()) x = x * 10 + (c & 15);
}
#define ll long long 
#define lll __int128_t
#define pb push_back
#define mp make_pair
typedef pair < int,int> ii;
typedef vector<ii> vii;
typedef vector<ll>vl;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll hashPrime = 1610612741;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    ll sum = 0;
    sum += (min(k, a));
    k -= min(k, a);
    k -= (min(b, k));
    sum -= (min(k, c));
    cout << sum << "\n";
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
#define FI(i,a,b) for(int i=(a);i<=(b);++i)
#define FD(i,b,a) for(int i=(b);i>=(a);--i)
#define DEBUG(x) cerr << #x << ": " << (x) << endl;
constexpr LL inv(LL x, LL m) { return x > m ? inv(x % m, m) : x > 1 ? inv(m % x, m) * (m - m / x) % m : x; }
constexpr LL mpow(LL a, LL k, LL m) { LL r(1); for (a %= m; k; k >>= 1, a = a * a % m) if (k & 1)r = r * a % m; return r; }


const int N = 1e6 + 5;
int n, q;
char S[N];


int main() {
    scanf("%d%s%d", &n, S + 1, &q);
    while (q--) {
        int k;
        scanf("%d", &k);
        LL ans = 0, cur = 0;
        int cd = 0, cm = 0;
        FI(i, 1, n) {
            if (i > k) {
                int j = i - k;
                if (S[j] == 'M') cm--;
                else if (S[j] == 'D') cur -= cm, cd--;
            }
            if (S[i] == 'M') cm++, cur += cd;
            else if (S[i] == 'D') cd++;
            else if (S[i] == 'C') ans += cur;
        }
        printf("%lld\n", ans);
    }
}


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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }
template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	os << v[0];
	for (int i = 1; i < v.size(); i++) os << " " << v[i];
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u; return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	int N; cin >> N;
	vll S(N); cin >> S;

	vvll suml(N), sumr(N);
	for (int i = 1; i < N; i++) {
		suml[i].push_back(0);
		for (int j = i; j < N; j += i) {
			suml[i].push_back(S[j] + suml[i].back());
		}
		sumr[i].push_back(0);
		for (int j = N-i-1; j >= 0; j -= i) {
			sumr[i].push_back(S[j] + sumr[i].back());
		}
	}
	
	ll maxv = 0;
	for (ll A = 2; A < N-1; A++) {
		ll iA = N-1-A;
		//divの約数列挙
		vll divisor;
		for (ll i = 1; i*i <= iA; i++) {
			if (iA % i == 0) {
				divisor.push_back(i);
				if (i != iA/i) divisor.push_back(iA/i);
			}
		}

		for (auto &d : divisor) {
			if (d < A && (iA < A || A%d != 0)) {
				//cout << A << " " << d << endl;
				chmax(maxv, suml[d][iA/d] + sumr[d][iA/d]);
			}
		}
	}

	cout << maxv << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


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

int main(){
    int n, k, r = 0;
    cin >> n >> k;
    vector<int> p(n);
    rep(i, n) cin >> p[i];
    sort(p.begin(), p.end());
    rep(i, k) r += p[i];
    cout(r);
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=100000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


int main() {

	int a,b,c;

	cin>>a>>b>>c;

	if(a+b==c){
		cout<<"Yes"<<endl;
	}else if(a+c==b){
		cout<<"Yes"<<endl;
	}else if(b+c==a){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}






	return 0;
}


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

int main()
{
	int n;
	cin >> n;
	vector<ll> a(n),b(n);
	for(int i = 0;i<n;i++)
	{
		cin >> a[i] >> b[i];
	}
	ll ans = 0;
	for(int i = n-1;i>=0;i--)
	{
		a[i]+=ans;
		ans += b[i]-a[i]%b[i]==b[i]?0:b[i]-a[i]%b[i];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する
int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    map<int,int> p;
    rep(i,n-1){
        cin>>a[i];
        a[i]--;
        p[a[i]]++;
    }
    rep(i,n){
        cout<<p[i]<<endl;
    }
}

Measured memory_bytes: 13556
//============================================================================
//Everyone has a different way of thinking, so God Created us
//   Hope You Respect My Way..,Thank You ):
// Author      : Murad
// Name        : Codeforces.cpp & Atcoder.cpp
// Description : Problem name
//============================================================================
#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
using namespace std;
#define pi 3.1415926536
#define forn(i,a,b)for(int i=a;i<b;i++)
#define LL long long
#define ULL unsigned long long
#define MP make_pair
#define ff first
#define ss second
#define endl '\n'
#define INF 1e9 + 1
#define _INF INT32_MIN
#define PQ priority_queue
#define MM multimap
#define PB push_back
#define vii vector<int>
#define ipair pair<int,int>
#define lpair pair<LL,LL>
#define MAXN 100004
#define El3zba ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define modd 1000000007
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1,v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1,v2,v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
//std::transform(s1.begin(), s1.end(), s1.begin(),::tolower);
char alphz[27] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };
float Euclidean(LL x1, LL x2, LL y1, LL y2) {
	return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
}
LL gcd(LL a,LL b) {
	return !b ? a : gcd(b, a % b);
}
LL LCM(LL a, LL b) {
	return (a*b) / gcd(a, b);
}
void PrimeFactor(LL n)
{
	while (n % 2 == 0) {
		printf("%d ", 2);
		//aa.insert(2);
		n /= 2;
	}
	for (int i = 3; i <= sqrt(n); i += 2)
	{
		if (n%i == 0) {
			printf("%d ", i);
	//		aa.insert(i);
			n /= i;
		}
	}
	if (n > 2){
		printf("%d ", n);
		//aa.insert(n);
	};
}
bool is_square(LL x) {
	LL l = 0, r = x;
	while (l <= r) {
		LL mid = l + (r - l) / 2;
		if (mid*mid == x)return true;
		if (mid*mid > x)r = mid - 1;
		else l = mid + 1;
	}
	return false;
}
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;
}
bool is_Prime(int x) {
	if (x == 2)return 1;
	else if (x % 2 == 0 || x < 2)return 0;
	for (int i = 3; i*i <= x; i += 2)
		if (x%i == 0)return 0;
	return 1;
}
int main()
{
	El3zba;
	/***  بسم الله الرحمن الرحيم   ***/
	int n, t;
	cin >> n >> t;
	int ans = INF;
	MM<int, int>mpp;
	for (int i = 0; i < n; i++)
	{
		int c, tt;
		cin >> c >> tt;
		mpp.insert({ c,tt });
	}
	for (auto&x : mpp)
	{
		if (x.ss <= t)
		{
			if (x.ff < ans)
			{
				ans = x.ff;
			}
		}
	}
	if (ans != INF)
		cout << ans << endl;
	else cout << "TLE\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,r,no,sum=0;
    cin>>n>>r;
    while(r--)
    {
        cin>>no;
        sum+=no;
    }
    if(sum>=n) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	} 
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	m := scanInt()
	k := scanInt()

	x := n*m
	facInit(x)

	ans := 0
	for i := 0; i < n; i++ {
		ans += comb(x-2,k-2)*i%mod*(n-i)%mod*m%mod*m%mod
		ans %= mod
	}
	for i := 0; i < m; i++ {
		ans += comb(x-2,k-2)*i%mod*(m-i)%mod*n%mod*n%mod
		ans %= mod
	}

	fmt.Fprintln(wr, ans)
}

const mod = 1000000007

var fac, ifac []int

func facInit(n int) {
	fac = make([]int,n+1)
	ifac = make([]int,n+1)
	inv := make([]int, n+1)

	fac[0] = 1; fac[1] = 1
	ifac[0] = 1; ifac[1] = 1
	inv[1] = 1

	for i := 1; i < n; i++ {
		fac[i+1] = fac[i]*(i+1)%mod
		inv[i+1] = mod-inv[mod%(i+1)]*(mod/(i+1))%mod
		ifac[i+1] = ifac[i]*inv[i+1]%mod
	}
}

func comb(a,b int) int { return (fac[a]*ifac[b]%mod)*ifac[a-b]%mod }
func perm(a,b int) int { return fac[a]*ifac[a-b]%mod }


Measured memory_bytes: 5504
#include<stdio.h>

int main(){

    int i,j,n,v,k;

    scanf("%d",&n);

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

    for(i=0;i<n-1;i++) printf("%d ",A[i]);

    printf("%d\n",A[n-1]);

    for(i=1;i<=n-1;i++){

        v = A[i];

        j = i-1;

        while(j>=0 && A[j]>v){

            A[j+1] = A[j];
            j--;
 
            A[j+1] = v;

        }

        for(k=0;k<n-1;k++) printf("%d ",A[k]);

            printf("%d\n",A[n-1]);

    }

    return 0;

}




Measured memory_bytes: 2056
#include <iostream>
using namespace std;
using llong = long long;

llong n, k;
llong a[200005];
llong min_cost[200005];
bool used[200005];
bool las[200005];
llong m;

int main() {
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[i]--;
    }

    llong pos = 0;
    while (1) {
        used[pos] = true;
        llong npos = a[pos];

        if (used[npos]) {
            las[npos] = true;
            m = min_cost[pos] - min_cost[npos] + 1;
            break;
        }
        else {
            min_cost[npos] = min_cost[pos] + 1;
            pos = npos;
        }
    }

    pos = 0;
    while (k) {
        if (las[pos]) {
            las[pos] = false;
            k %= m;
        }
        else {
            pos = a[pos];
            k--;
        }
    }

    cout << pos + 1 << endl;
    
    return 0;
}


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

typedef unsigned uint;
typedef long long INT;
typedef unsigned long long UINT;
const int INF = 1001001001;
const INT INFLL = 1001001001001001001LL;

 int in() { int x; scanf("%d", &x); return x; }
double fin() { double x; scanf("%lf", &x); return x; }
INT lin() { INT x; scanf("%lld", &x); return x; }
UINT luin() { UINT x; scanf("%llu", &x); return x;}


int main(){
    int a, b, c;
    double fa, fb, fc;
    char S[128], sa[128], sb[128], sc[128];
    // int N = in();
    // int K = in();
    // scanf("%s", S);

    int N = in();
    int M = in();
    
    std::vector<INT> vecH;

    for (int i = 0; i < N; ++i) {
        vecH.push_back(lin());
    }

    bool* aOK = new bool[N];

    for (int i = 0; i < N; ++i) {
        aOK[i] = true;
    }

    for (int i = 0; i < M; ++i) {
        INT aL = lin() - 1;
        INT aR = lin() - 1;
        if (vecH[aL] <= vecH[aR]) {
            aOK[aL] = false;
        }

        if (vecH[aL] >= vecH[aR]) {
            aOK[aR] = false;
        }

    }

    int nCnt = 0;
    for (int i = 0; i < N; ++i) {
        nCnt += aOK[i] ? 1 : 0;
    }

    printf("%d", nCnt);


    delete[](aOK);

    return 0;
}







Measured memory_bytes: 4336
#include<bits/stdc++.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>
using namespace std;

int main(){
  int a, b;
  cin >> a >> b;

  if(a <= b){
    cout << a << endl;
  }
  else{
    cout << (a-1) << endl;
  }

  return 0;
}


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)
    break;
    else{ for(i=1;i<=H;i++){

    for(j=1;j<=W;j++){
        printf("#");
}printf("\n");}
    }
printf("\n");
}
return 0;}





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

using namespace std;
using ll=long long;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, a, n) for(int i = (a); i < (n); i++)

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  string s_1,s_2;cin>>s_1;
  //753-111=642
  int ans=999;
  //s_1 $B$+$iO"B3$9$k(B 3 $B8D$N?t;z$r<h$j=P$7!"(B
  //1 $B$D$N@0?t(B s_2 $B$H$7$F$4<g?MMM$N85$K;}$C$F$$$-$^$9!#(B
  //$B$4<g?MMM$,Bg9%$-$J?t$O(B 753 $B$G!"(B
  //$B$3$l$K6a$$?t$[$I9%$-$G$9!#(B 
  //X$B$H(B753 $B$N:9!J$N@dBPCM!K$O:G>.$G$$$/$D$K$J$k$G$7$g$&$+!)(B
  s_2+=s_1[0];
  s_2+=s_1[1];
  rep2(i,2,s_1.size()){
    s_2+=s_1[i];
    rep(i,3){
      ans=min(abs(753-stoi(s_2)),ans);
    }
    s_2.erase(0,1);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
h,w = map(int, input().split())
s = [list(input()) for _ in range(h)]

for i in range(h):
  for j in range(w):
    if s[i][j] == "#":
      if i != 0: # 上
        if s[i-1][j] == "#": continue
      if i != h-1: #下
        if s[i+1][j] == "#": continue
      if j != 0: #左
        if s[i][j-1] == "#": continue
      if j != w-1: #右
        if s[i][j+1] == "#": continue
      print("No")
      exit()
print("Yes")

Measured memory_bytes: 9136
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;
long long INF = (1LL<<62);
typedef long long LL;

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

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

	int H, W; cin >> H >> W;
	vector<vector<int>> V;
	V.assign(H, vector<int>(W, 0));
	for(int i=0; i<H; i++){
		string s; cin >> s;
		for(int j=0; j<W; j++){
			char c = s[j];
			if(c == '.'){
				V[i][j] = 0;
			}
			else{
				V[i][j] = 1;
			}
		}
	}

	int impossilbe = 0;
	for(int i=0; i<H; i++){
		for(int j=0; j<W; j++){
			if(V[i][j] == 1){
				int c = 0;
				for(int k=0; k<4; k++){
					int nx = j+dx[k];
					int ny = i+dy[k];
					if(0 <= ny && ny < H && 0 <= nx && nx <= W){
						if(V[ny][nx] == 1){
							c++;
						}
					}
				}
				if(c < 1){
					impossilbe = 1;
					break;
				}
			}
		}
		if(impossilbe == 1){
			break;
		}
	}
	if(impossilbe == 1){
		printf("No\n");
	}
	else{
		printf("Yes\n");
	}
	return 0;
}


Measured memory_bytes: 3608
#include<iostream>
#include<vector>
#include<algorithm>
#define rep(i,n) for(int i=0; i<(n); i++)
typedef long long ll;
using namespace std;

vector<int> A;
vector<int> B;

int main(){
    int N;
    int saves;
    cin >> N;
    A.resize(N);
    rep(i,N) cin >> A[i];
    reverse(A.begin(), A.end());

    B.push_back(A[0]);
    for(int i=1; i<N; i++){
        auto insrt = upper_bound(B.begin(), B.end(), A[i]);
        auto tmp = insrt-B.begin();
        //cout << tmp << endl;
        if(tmp==B.size()){
            B.push_back(A[i]);
        }else{
            B[tmp] = A[i];
            if(tmp>0){
                if(B[tmp-1] > B[tmp]){
                    saves = B[tmp-1];
                    B[tmp-1] = B[tmp];
                    B[tmp] = saves;
                }
            }
        }
    }
    cout << B.size() << endl;
    return 0;
}

Measured memory_bytes: 1276
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{   
    string s,t; cin>>s>>t;
    int N=s.size();
    int M=t.size();

    for(int i=N-M;i>=0;i--){
        bool ok=true;
        REP(j,M){
            ok&=(s[i+j]=='?' or s[i+j]==t[j]);
        }
        if(ok){
            string ans;
            for(int j=0;j<i;j++)
                ans+=(s[j]=='?'? 'a':s[j]);
            ans+=t;
            for(int j=i+M;j<N;j++)
                ans+=(s[j]=='?'? 'a':s[j]);
            cout<<ans<<endl;
            return 0;
        }
    }
    cout<<"UNRESTORABLE"<<endl;

}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func solve() {
	n := getInt()
	a, b := getInt(), getInt()

	ans := mod(modPow(2, n) - 1)
	ans = mod(ans - f(n, a))
	ans = mod(ans - f(n, b))
	fmt.Fprintln(wr, ans)
}

func f(n, k int) int {
	ret := 1
	for i := n; i > n-k; i-- {
		ret = mod(ret * i)
	}
	for i := k; i > 0; i-- {
		ret = mod(ret * modInv(i))
	}
	return ret
}

var (
	modulus = 1000000007
)

func mod(a int) int {
	ret := a % modulus
	if ret < 0 {
		ret += modulus
	}
	return ret
}

func modPow(a, b int) int {
	ret := 1
	for b > 0 {
		if b&1 > 0 {
			ret = mod(ret * a)
		}
		a = mod(a * a)
		b >>= 1
	}
	return ret
}

func modInv(a int) int {
	return modPow(a, modulus-2)
}

// -----------------------------------------

const (
	inf = 1 << 60
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func main() {
	maxBufSize := int(1e8)
	sc.Buffer(make([]byte, 4096), maxBufSize)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}

func getInt() (ret int) {
	sc.Scan()
	ret, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return
}

func getIntSlice(n int) (ret []int) {
	ret = make([]int, n)
	for i := range ret {
		ret[i] = getInt()
	}
	return
}

func getString() (ret string) {
	sc.Scan()
	ret = sc.Text()
	return
}

func getRunes() (ret []rune) {
	ret = []rune(getString())
	return
}


Measured memory_bytes: 1800
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define ALL(v) (v).begin(), (v).end()
#define ios() ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
constexpr ll MOD = 10e9+7;
constexpr ll INF = 1LL << 60;
constexpr int Inf = 1e9;
inline int in() {int x; cin >> x; return x;}
template <typename T> inline void out(const T& x) {cout << x << endl;}
template <class T> inline bool chmin(T &a, T b){if (a > b){a = b;return 1;}return 0;}
template <class T> inline bool chmax(T &a, T b){if (a < b){a = b;return 1;}return 0;}
//UP = 0;RIGHT = 1; DOWN = 2; LEFT =3;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b)
{
  if (a < b)
    gcd(b, a);
  int r;
  while ((r = a % b))
  {
    a = b;
    b = r;
  }
  return b;
}
void eratos(bool * isPrime,int max){
  fill(isPrime,isPrime + max,true);
  isPrime[0] = false; 
  isPrime[1] = false; 
  for(int i=2; i<=max/i; ++i) 
      if(isPrime[i]) 
          for(int j=2; j<=max/i; ++j) 
              isPrime[i*j] = false;    
}
//
//UnionFind隴幢ｽｨ
//陷ｷ蠕個ｧ郢ｧ・ｰ郢晢ｽｫ郢晢ｽｼ郢晏干竊楢椽讒ｭ・邵ｺ・ｦ邵ｺ繝ｻ・狗ｸｺ荵昶・邵ｺ繝ｻﾂｰ郢ｧ蜻域Β邵ｺ・ｧ髯ｦ・ｨ邵ｺ蜷ｶﾂ繝ｻ
//隴幢ｽｨ邵ｺ・ｮ陷ｷ蝓溘・邵ｺ・ｯ驍・ｽ｡陷雁･竊鍋ｸｺ・ｧ邵ｺ髦ｪ・狗ｸｺ蠕個竏ｵ・ｰ蜉ｱ繝ｻ陋ｻ繝ｻ迚｡邵ｺ・ｯ邵ｺ・ｧ邵ｺ髦ｪ竊醍ｸｺ繝ｻ

struct UnionFind
{
  vi par;
  vi rank;
  vi sizes;
  //par[i] parent
  UnionFind(int N) : par(N) , rank(N),sizes(N,1)
  {
    //par[i] == i 邵ｺ・ｪ郢ｧ逕ｻ・ｰ・ｹ
    rep(i,N) par[i] = i,rank[i] = 0;
  }
  int root(int x)
  {
    return par[x] == x ? x : par[x] = root(par[x]);
  }
  //蜷後§繧ｰ繝ｫ繝ｼ繝励↓蜷ｫ縺ｾ繧後※縺・ｋ縺九←縺・°
  bool same(int x,int y)
  {
    return root(x) == root(y);
  }
  //x縺ｨy縺悟性縺ｾ繧後ｋ髮・粋繧貞粋謌舌る嚴謨ｰrank縺ｮ鬮倥＞縺ｻ縺・↓蟆上＆縺・⊇縺・′蜷域・縺輔ｌ繧・
  void unite(int x,int y)
  {
    x = root(x);
    y = root(y);
    if(x==y) return ;
    if(rank[x] < rank[y])
    {
      par[x] = y;
      sizes[y] += sizes[x];
    } else {
      par[y] = x;
      sizes[x] += sizes[y];
      if(rank[x]==rank[y])rank[x] ++;
    }

  }
  int size(int x)
  {
    return sizes[root(x)];
  }
};

int A[100010],B[100010],ans[100010];
signed main()
{
  ios();
  int N,M;
  cin >> N >> M ;
  rep(i,M) cin >> A[i] >> B[i],A[i]--,B[i]--;
  ans[M-1] = (N * (N-1))/2;
  UnionFind uf(N);
  for(int i = M-1;i >= 1; i--)
  {
    if(uf.same(A[i],B[i])) {ans[i-1] = ans[i];continue;}
    ans[i-1] = ans[i] - uf.size(A[i]) * uf.size(B[i]);
    uf.unite(A[i],B[i]);
  }
  rep(i,M)
  {
    cout << ans[i] << endl;
  }



}


Measured memory_bytes: 6016
#include<stdio.h>

int main()
{
    int n,m,a,b,ch[100100];
    long int h[100100];

    scanf("%d %d",&n,&m);

    int i;

    for(i=1;i <= n;i++)
    {
        scanf("%ld",&h[i]);
        ch[i]  = 1;
    }

    for(i=1;i <= m;i++)
    {
        scanf("%d %d",&a,&b);

        if(h[a] >= h[b])
            ch[b] = 0;

        if(h[a] <= h[b])
            ch[a] = 0;
    }

    int ans = 0;

    for(i=1;i <= n;i++)
    {
        ans += ch[i];
    }

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


    return 0;
}

Measured memory_bytes: 2872
#include <iostream>
#include <sstream>
#include <algorithm>
#include <functional>
#include <iterator>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

typedef   signed long long int slli;
typedef unsigned long long int ulli;
const slli MAX_SLLI = 0x7FFFFFFFFFFFFFFF;
const slli MIN_SLLI = 0x8000000000000000;
const ulli MAX_ULLI = 0xFFFFFFFFFFFFFFFF;
const ulli MIN_ULLI = 0x0000000000000000;

#define N_TIMES(i, n)     for (ulli i = 0;     i <  n; ++i)
#define N_TIMES_REV(i, n) for (slli i = n - 1; i >= 0; --i)

#ifdef __DEBUG__
template<typename T>
std::ostream& operator<<(std::ostream &os, const std::list<T> &list)
{
  const std::string delim = ", ";
  typename std::list<T>::const_iterator itr = list.begin();
  while (itr != list.end()) {
    os << *itr;
    ++itr;
    if(itr != list.end()) os << delim;
  }
  return os;
}

template<typename T>
std::ostream& operator<<(std::ostream &os, const std::vector<T> &v)
{
  const std::string delim = ", ";
  for (unsigned n = 0; n < v.size(); ++n) {
    os << v[n];
    if((n + 1) < v.size()) os << delim;
  }
  return os;
}
#endif

int main()
{
  std::string O, E;
  std::cin >> O >> E;
  
  for(unsigned i = 0; i < std::min(O.size(), E.size()); ++i) {
    std::cout << O[i] << E[i];
  }
  
  if (O.size() > E.size()) {
    std::cout << O[O.size() - 1];
  }
  
  std::cout << std::endl;
  
  return 0;
}

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

bool compare(const pair<int, int> &a, const pair<int, int> &b) {
    return a.second > b.second;
}

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

    int N;
    cin >> N;
    vector<pair<int, int>> edges(N - 1);
    vector<vector<int>> G(N + 1);
    map<pair<int, int>, int> c;
    for (int i = 0; i < N - 1; i++) {
        cin >> edges[i].first >> edges[i].second;
        G[edges[i].first].push_back(edges[i].second);
        G[edges[i].second].push_back(edges[i].first);
        c[{edges[i].first, edges[i].second}] = 0;
        c[{edges[i].second, edges[i].first}] = 0;
    }

    int K = 0;
    for (int i = 0; i < G.size(); i++) {
        vector<bool> used(N, false);
        for (int j : G[i]) {
            map<pair<int, int>, int>::iterator it = c.find({i, j});
            if (it->second != 0)
                used[it->second] = true;
        }

        int ci = 1;
        for (int j : G[i]) {
            map<pair<int, int>, int>::iterator it = c.find({i, j});
            if (it->second == 0) {
                while (used[ci]) ci++;
                it->second = ci;
                c.find({j, i})->second = ci;
                used[ci] = true;
            }
        }
        K = max(K, ci);
    }

    cout << K << '\n';
    for (pair<int, int> e : edges)
        cout << c.find(e)->second << '\n';

    return 0;
}

Measured memory_bytes: 19328
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<numeric>
using namespace std;
#define INF (1 << 30) - 1
#define LINF 1LL << 60
const int MOD = 1000000007;
using ll = long long;
using P = pair<int, int>;

int main(){
  int h, a;
  cin >> h >> a;

  int ans = h / a;
  if(h % a != 0)++ans;

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


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

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a,b) ((a)>(0)?(a):-(a))

void run(void){
  int s[3]={0};
  int i;
  for(i=0;i<3;i++){
    char c;
    scanf("%c",&c);
    s[c-'a']++;
  }
  for(i=0;i<3;i++){
    if(s[i]!=1){
      printf("No\n");
      return;
    }
  }
  printf("Yes\n");
  return;
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
                String str = scanner.nextLine();
                int counter = 0;
                for(int i =0; i < str.length() / 2; i ++){
                    if(str.charAt(i) != str.charAt(str.length() - 1 - i)){
                        counter++;
                    }
                }
                System.out.println(counter);
    }
}


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

int main() {
  bool flag = false;
  char tmp;
  while(cin >> tmp) {
    if (flag && tmp == 'F') {
      cout << "Yes" << endl;
      return 0;
    }
    else if (!flag && tmp == 'C') {
      flag = true;
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int n,l;
int a[100010];
int ind;
int main()
{
	scanf("%d%d",&n,&l);
	for(int i=1;i<=n;i++)scanf("%d",a+i);
	for(int i=1;i<n;i++)
	{
		if(a[i]+a[i+1]>=l)
		{
			ind=i;
			break;
		}
	}
	if(!ind)
	{
		printf("Impossible");
		return 0;
	}
	puts("Possible");
	for(int i=1;i<ind;i++)printf("%d\n",i);
	for(int i=n-1;i>ind;i--)printf("%d\n",i);
	printf("%d",ind);
	return 0;
}

Measured memory_bytes: 1152
#include<iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>

using namespace std;

int main()
{
    // 整数の入力
    string S,T, returnS;
    long i,j;
    cin >> S >> T;
    returnS = "";
    i = 0;
    j = T.length() -1;

    if (S.find(T)!= string::npos){
        replace(S.begin(), S.end(), '?', 'a');
        cout << S << endl;
    }else{
        bool found = false;
        for (i= S.length() - T.length();i>=0;i--){
            for (j = 0;j< T.length();j++){
                if (S[i+j] == '?' || S[i+j] == T[j]){
                    if (j == T.length() - 1){
                        found = true;
                        break;
                    }
                }else{
                    break;
                }
            }
            if (found){
                break;
            }
        }

        if (found){
            long matchEnd = i + T.length() - 1;
            long matchStart = i;
            for (i= S.length() - 1;i>=0;i--){
                if (S[i] == '?' ){
                    if (matchStart <= i && i <= matchEnd){
                        returnS = T[i - matchStart ] + returnS;
                    }else{
                        returnS = "a" + returnS;
                    }
                }else{
                    returnS = S[i] + returnS;
                }
            }
            cout << returnS << endl;
        }else{
            cout << "UNRESTORABLE" << endl;
        }
    }
    return 0;
}

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

using namespace std;

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


template<class V> class MaxFlow_dinic{
public:
	struct edge{int to,reve;V cap;};
	static const int MV = 10100;
	vector<edge> E[MV];
	int itr[MV],lev[MV];

	void add_edge(int x,int y,V cap,bool undir=false){
		E[x].push_back((edge){y,(int)E[y].size(),cap});
		E[y].push_back((edge){x,(int)E[x].size()-1,undir?cap:0});
	}
	void bfs(int cur){
		memset(lev,0xff,sizeof(lev));
		queue<int> q;
		lev[cur] = 0;
		q.push(cur);
		while(q.size()){
			int v=q.front();
			q.pop();
			for(edge &e:E[v]){
				if(e.cap>0&&lev[e.to]<0){
					lev[e.to]=lev[v]+1,q.push(e.to);
				}
			}
		}
	}	

	V dfs(int from,int to,V cf){
		if(from==to) return cf;
		for(;itr[from]<E[from].size();itr[from]++){
			edge &e = E[from][itr[from]];
			if(e.cap>0&&lev[from]<lev[e.to]){
				V f=dfs(e.to,to,min(cf,e.cap));
				if(f>0){
					e.cap-=f;
					E[e.to][e.reve].cap+=f;
					return f;
				}
			}
		}
		return 0;
	}
	V maxflow(int from,int to){
		V fl = 0,tf;
		while(1){
			bfs(from);
			if(lev[to]<0) return fl;
			memset(itr,0,sizeof(itr));
			while((tf=dfs(from,to,numeric_limits<V>::max()))>0) fl+=tf;
		}
	}
};



int n,m;


int main(){
	while(cin>>n>>m,n||m){
		pair<int,int> ans;
		int l,r;
		l=0,r=m+1;
		vector<int> a(m),b(m);
		rep(i,m) cin>>a[i]>>b[i],a[i]--,b[i]--;
		while(r-l>1){
			int mid = (r+l)/2;
			// cout<<"a "<<mid<<endl;
			MaxFlow_dinic<int> mf;
			int source = n+m;
			int sink = n+m+1;
			rep(i,m){
				// int a,b;
				// cin>>a>>b;
				// a--,b--;
				mf.add_edge(i,m+a[i],1);
				mf.add_edge(i,m+b[i],1);
				mf.add_edge(source,i,1);
			}
			rep(i,n){
				mf.add_edge(m+i,sink,mid);
			}
			int t = mf.maxflow(source,sink);
			// cout<<"t "<<t<<endl;
			if(t==mid*n){
				l=mid;
			}
			else{
				r=mid;
			}
		}
		ans.first = l;
		l=0,r=m+1;
		while(r-l>1){
			int mid = (r+l)/2;
			MaxFlow_dinic<int> mf;
			int source = n+m;
			int sink = n+m+1;
			rep(i,m){
				mf.add_edge(i,m+a[i],1);
				mf.add_edge(i,m+b[i],1);
				mf.add_edge(source,i,1);
			}
			rep(i,n){
				mf.add_edge(m+i,sink,mid);
			}
			int t = mf.maxflow(source,sink);
			if(t==m){
				r=mid;
			}
			else{
				l=mid;
			}
		}
		ans.second = r;
		cout<<ans.first <<" "<< ans.second <<endl;
	}
}

Measured memory_bytes: 3660
/*
    Author: Anthony Ngene
    Created: 19/09/2020 - 13:00
*/

import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String word = in.next();
        char ch = word.charAt(word.length() - 1);
        word = word + ((ch == 's') ? "es" : "s");
        System.out.println(word);
    }
}


Measured memory_bytes: 39336
import sys
import itertools
# import numpy as np
import time
import math
from heapq import heappop, heappush
from collections import defaultdict
from collections import Counter
from collections import deque
from itertools import permutations
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())
S = input()
if S[-1] == 's':
    print(S + 'es')
else:
    print(S + 's')

Measured memory_bytes: 65072
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
sumA = sum(A)

for i in range(N):
    if A[i] >= B[i]:
        A[i] = A[i] - B[i]
    else:
        c = B[i]-A[i]
        A[i] = 0
        if A[i+1]>=c:
            A[i+1] = A[i+1]-c
        else:
            A[i+1] =0

new_sumA = sum(A)

print(sumA - new_sumA)


Measured memory_bytes: 18476
#include <vector>
#include <queue>
#include <iostream>
#include <set>
#include <algorithm>
#define ii pair<int, int>
#define iii pair<ii, int>
#define pq priority_queue

using namespace std;

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

    int n;
    cin >> n;
    vector<iii> points(2 * n);

    for (int i = 0; i < n; i++) {
        //red
        int a, b;
        cin >> a >> b;
        points[i] = make_pair(make_pair(a, b), 0);
    }

    for (int i = 0; i < n; i++) {
        //blue
        int a, b;
        cin >> a >> b;
        points[i + n] = make_pair(make_pair(a, b), 1);
    }
    sort(points.begin(), points.end());
    set<int> ycoords;
    int no_pair = 0;
    for (int i = 0; i < 2 * n; i++) {
        int rb = points[i].second;
        if (rb == 0) {
            ycoords.insert(points[i].first.second);
        }
        else {
            set<int>::iterator bef = lower_bound(ycoords.begin(), ycoords.end(), points[i].first.second);
            if (bef != ycoords.begin()) {
                //remove it; add pair
                ycoords.erase(prev(bef));
                no_pair++;
            }
        }
    }
    cout << no_pair;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<int, int>
using namespace std;
int dp[1000005][2];

int main(){
    string s; cin >> s;
    int sl=s.length();
    dp[0][0]=0;
    dp[0][1]=0;
    rep(i,sl){
        int now=s[sl-i-1]-'0';
    // i桁目はぴったり
        dp[i+1][0]=min(dp[i][0]+now,dp[i][1]+now+1);
    // i桁目は繰り上がり
        if(i==0) dp[i+1][1]=10-now;
        else dp[i+1][1]=min(dp[i][0]+10-now,dp[i][1]+9-now);
    }
  cout << min(dp[sl][0],dp[sl][1]+1) << endl;
return 0;
}

Measured memory_bytes: 9220
#include <iostream>
#include <algorithm>
using namespace std;
using ll = long long;

constexpr int lim = 1e5;
constexpr int mod = 1e9+7;

ll fac[2*(lim+1)];

ll h, w, a, b;

ll pow(ll x, ll n){
  if(n == 0) return 1;
  
  ll tmp = pow(x * x % mod, n / 2);
  return tmp * ((n % 2)? x: 1) % mod;
}

ll mul(ll a, ll b){
  return (a % mod) * (b % mod) % mod;
}

ll comb(ll n, ll r){
  return mul(fac[n], mul(pow(fac[n-r], mod-2), pow(fac[r], mod-2)));
}

int main(){
  cin >> h >> w >> a >> b;

  fac[0] = 1;
  for(int i=1; i<=2*lim; i++) (fac[i] = fac[i-1] * i) %= mod;

  ll ans = 0;
  for(int y=1; y<=h-a; y++){
    ans += (comb(b+y-2, y-1) * comb(h-y+w-b-1, h-y) % mod);
    ans %= mod;
  }

  cout << ans << endl;

  return 0;
}


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

int main() {
    int h,w;
    cin >> h >> w;
    string x[h];

    for (int i = 0; i < h; i++)
    {
        cin >> x[i];
        
    }

    for (int i = 0; i < w+2; i++)
    {
        cout << '#';
    }
    cout << endl;
    

    for (int i = 0; i < h; i++)
    {
        cout << '#' << x[i] << '#';
        cout << endl;
    }
   
    for (int i = 0; i < w+2; i++)
    {
        cout << '#';
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 3640
h,w,k = list(map(int,input().split())); arr = [[int(i) for i in input()] for _ in range(h)]

from itertools import product
ans = 2000

for cond in product([True,False],repeat=(h-1)):
    cut = sum(cond)
    splits = [arr[0][:]]
    for i in range(1,h):
        if cond[i-1]:
            splits.append(arr[i][:])
        else:
            splits[-1] = [splits[-1][j]+arr[i][j] for j in range(w)]
    
    check = [max(i) for i in splits]
    if max(check) > k:
        break
    count = [i[0] for i in splits]
    
    div = cut
    for j in range(1,w):
        addarr = [count[i]+splits[i][j] for i in range(cut+1)]
        if max(addarr) > k:
            div += 1
            count = [splits[i][j] for i in range(cut+1)]
        else:
            count = addarr[:]
    ans = min(ans,div)
        
print(ans)

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

int main() {
    string S;
    cin >> S;
    int len = S.length();
    int halflen = len / 2;
    string subS = S.substr(len - halflen);// ここの長さ以下
    string frontS = S.substr(0, halflen);

    int count = 0;
    int subsSize = subS.size();
    for (int i = 0; i < subS.size(); i++){
      if (subS[i] != frontS[subsSize - i - 1]) count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <numeric>




typedef long long ll;
#define PI 3.14159265359
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define mp make_pair
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define decp(n) cout<<fixed<<setprecision((int)n)
#define _GLIBCXX_DEBAC
#include <functional>
/*map<Keyの型, Valueの型> 変数名;
queue<型> 変数名;
priority_queue<型> 変数名;
priority_queue<型, vector<型>, greater<型>> 変数名;*/
//copy(v1.begin(), v1.end(), back_inserter(v2));
using namespace std;

ll gcd(ll a, ll b) {
	ll c;
	if (a < b) {
		c = a; a = b; b = c;
	}
	while (b != 0) {
		c = a % b; a = b; b = c;
	}
	return a;
}

ll lcm(ll a, ll b) {
	ll c;
	c = a * b / gcd(a, b);
	return c;
}

int sort_greater(int m, int n) {
	vector<int> a(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(), greater<int>());
	for (int i = 0; i < n; i++) {
		cout << a[i];
	}
	return 0;
}

int bubblesort(int a[], int n) {
	int sw = 0;
	bool flag = 1;
	for (int i = 0; flag; i++) {
		flag = 0;
		for (int j = n - 1; j >= i + 1; j--) {
			if (a[j] < a[j - 1]) {
				swap(a[j], a[j - 1]);
				flag = 1;
				sw += 1;
			}
		}
	}
	return sw;
}

int a_z()
{
	for (int i = 0; i <= ('Z' - 'A'); i++) {
		cout << (char)('A' + i);
	}
	return 0;
}

int selecttionsort(int a[], int n) {
	int t, sw = 0, minj;
	for (int i = 0; i < n - 1; i++) {
		minj = i;
		for (int j = 0; j < n - 1; j++) {
			if (a[j] < a[minj]) {
				minj = j;
			}
		}
		t = a[i]; a[i] = a[minj]; a[minj] = t;
		if (i != minj) sw += 1;

	}
	return sw;
}

bool is_prime(int x) {
	if (x <= 1) return false;
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0) return false;
	}
	return true;
}

const ll mod = 1000000007;

map<string, int> memo;

using P=pair<int, int>;
/*void dfs(int v, int p = -1) {
	for (int u : to[v]) {
		if (u == p) continue;
		ans[u] += ans[v];
		dfs(u, v);
	}
}*/
ll findIndex(int value, vector<ll> a)
{

	for (ll i = 0; i < (ll)a.size(); i++) {
		if (a[i] == value) {
			return i;
		}
	}
	return -1;
}

ll nCr(ll n, ll r) {
	ll a = 1;
	for (ll i = n; i > n - r; --i) {
		a = a * i;
	}
	for (ll i = 1; i < r + 1; ++i) {
		a = a / i;
	}
	return a;
}

void comb(vector<vector <long long int> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (ll j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);
		}
	}
}



int main() {
	int a, b;
	cin >> a >> b;
	cout << (a - 1) * (b - 1);
	return 0;
}













Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>

using namespace std;

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


int main(){
    string s = "aeiou";
    char c;
    cin >> c;
    rep(i, 5){
        if(s[i] == c){
            cout << "vowel" << endl;
            return 0;
        }
    }
    cout << "consonant" << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
int N;
int a[200];

int main() {
  cin >> N;
  rep(i, 0, N) { cin >> a[i]; }
  sort(a, a + N, greater<int>());
  int alice = 0, bob = 0;
  rep(i, 0, N) {
    if (i % 2 == 0)
      alice += a[i];
    else
      bob += a[i];
  }
  cout << alice - bob << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>
#include <map>

#define INF 1000000000
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

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

  ll N, M; cin>>N>>M;
  vector<ll> xs(M);
  for(ll i = 0; i<M; i++) {
    cin >> xs[i];
  }
  sort(xs.begin(), xs.end());

  vector<ll> diffs;
  for(int i=1; i<M; i++) {
    diffs.push_back(xs[i] - xs[i-1]);
  }
  sort(diffs.begin(), diffs.end(), greater<ll>());

  ll ans = xs.back() - xs.front();
  for(int i=0; i < min((int)diffs.size(), (int)N-1); i++) {
    ans -= diffs[i];
  }

  cout << ans << endl;
}


Measured memory_bytes: 2168
S = input()

S1 = int(S[0]+S[1])
S2 = int(S[2]+S[3])

flag = 0
S1_flag = 0
 
if S1 >= 1 and S1 <= 12:
    flag = flag +1
    S1_flag = 1    
if S2 >= 1 and S2 <= 12:
    flag = flag +1
    
if flag == 0:
    print('NA')
elif flag == 2:
    print('AMBIGUOUS')
elif S1_flag == 1:
    print('MMYY')
else:
    print('YYMM')


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
struct tree{
	int l;
	int r;
	int p;
}T[100001];
void preorder(int u){
	if(u==-1)return;
	printf(" %d",u);
	preorder(T[u].l);
	preorder(T[u].r);
}

void inorder(int u){
	if(u==-1)return;
	inorder(T[u].l);
	printf(" %d",u);
	inorder(T[u].r);
}

void postorder(int u){
	if(u==-1)return;
	postorder(T[u].l);
	postorder(T[u].r);
	printf(" %d",u);
}


int main(){
	int n;scanf("%d",&n);
	int left,right,id;
	for(int i=0;i<n;i++)T[i].r=T[i].l=T[i].p=-1;
	for(int i=0;i<n;i++){
		scanf("%d%d%d",&id,&left,&right);
		T[id].l=left;T[id].r=right;
		if(left!=-1)T[left].p=id;
		if(right!=-1)T[right].p=id; 
	}
	int root; 
	for(int i=0;i<n;i++){
		if(T[i].p==-1)root=i;
	}
	printf("Preorder\n");
	preorder(root);printf("\n");
	
	printf("Inorder\n");
	inorder(root);printf("\n");
	
	printf("Postorder\n");
	postorder(root);printf("\n");
	return 0;
}


Measured memory_bytes: 3220
#!/mnt/c/Users/moiki/bash/env/bin/python
def gcd(a, b):
    while b:
        a, b = b, a%b
    return a

# N,M = map(int, input().split())
N = int(input())
from functools import reduce
A = list(map(int, input().split()))

a = reduce(gcd, A)
print(a)


Measured memory_bytes: 62704
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#ifdef TEST
#define getchar_unlocked _getchar_nolock
#endif
#define int long long
#define ins insert
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define pp pop
#define ppb pop_back
#define ppf pop_front
#define eb emplace_back
#define g0(a) get<0>(a)
#define g1(a) get<1>(a)
#define g2(a) get<2>(a)
#define g3(a) get<3>(a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef double db;
typedef long long ll;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int N, ans, P[505], dist[505][505], dr[] = {-1, 0, 0, 1}, dc[] = {0, -1, 1, 0};
bool grid[505][505];

main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> N;
	for (int i = 1; i <= N; i++)
		for (int j = 1; j <= N; j++) grid[i][j] = 1, dist[i][j] = min({i, j, N - i + 1, N - j + 1});
	for (int i = 1, d, r, c, P; i <= N * N; i++) {
		cin >> P;
		ans += dist[(P - 1) / N + 1][(P - 1) % N + 1] - grid[(P - 1) / N + 1][(P - 1) % N + 1];
		grid[(P - 1) / N + 1][(P - 1) % N + 1] = 0;
		deque<iii> D;
		
		D.emplace_front(--dist[(P - 1) / N + 1][(P - 1) % N + 1], (P - 1) / N + 1, (P - 1) % N + 1);
		while (!D.empty()) {
			tie(d, r, c) = D.front();
			D.ppf();
			if (dist[r][c] < d) continue;
			for (int k = 0; k < 4; k++)
				if (1 <= r + dr[k] && r + dr[k] <= N && 1 <= c + dc[k] && c + dc[k] <= N && dist[r + dr[k]][c + dc[k]] > d + grid[r + dr[k]][c + dc[k]]) {
					dist[r + dr[k]][c + dc[k]] = d + grid[r + dr[k]][c + dc[k]];
					if (grid[r + dr[k]][c + dc[k]]) D.emplace_back(dist[r + dr[k]][c + dc[k]], r + dr[k], c + dc[k]);
					else D.emplace_front(dist[r + dr[k]][c + dc[k]], r + dr[k], c + dc[k]);
				}
		}
	}
	cout << ans << '\n';
}


Measured memory_bytes: 8808
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

const int M = 1e9+7;

using namespace std;

main()
{
    fast;
    ll n,m;
    cin>>n>>m;
    if (n==m/2)
        cout<<n<<endl;
    else if (n<m/2)
    {
        m-=2*n;
        cout<<n+m/4<<endl;
    }
    else
        cout<<min(n,m/2)<<endl;
}

Measured memory_bytes: 256