akhauriyash/Code-Regression huggingface dataset:
n, m, k = [int(i) for i in input().split()]

flag = False
for y in range((n+1)//2+1):
    for x in range((m+1)//2+1):
        a = x*y + (m-x)*(n-y)
        b = n*m - a
        if k in [a, b]:
            flag = True
            break
    if flag:
        break

if flag:
    print("Yes")
else:
    print("No")

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

int main()
{
	int A, B;
	cin >> A >> B;
	int resmax = -1000000;
	if(A+B > resmax){
		resmax = A+B;
	}
	if(A-B > resmax){
		resmax = A-B;
	}
	if(A*B > resmax){
		resmax = A*B;
	}
	cout << resmax;
	return 0;
}


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

int main(){
	string s;
	cin>>s;
	
	int ans=0;
	if(s[0]=='1')
		ans++;
	if(s[1]=='1')
		ans++;
	if(s[2]=='1')
		ans++;
	
	cout<<ans<<endl;
	return 0;
}

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

int main()
{
	int r;
	cin >> r;
	if (r < 1200) cout << "ABC" << endl;
	else if (r < 2800) cout << "ARC" << endl;
	else cout << "AGC" << endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> H(N);
  for (int i = 0; i < N; i++) {
    cin >> H.at(i);
  }
  
  int ans = 0;
  int test = 0;
  for (int i = 0; i < N-1; i++) {
    if (H.at(i) >= H.at(i+1)) {
      test++;
    }
    else {
      ans = max(ans,test);
      test = 0;
    }
  }
  ans = max(test,ans);
  cout << ans << endl;
}

Measured memory_bytes: 640
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) FOR(i, n, 0, 1)

// functions
int ceil(int a, int b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    int X;
    cin >> X;
    if (X == 1) {
        cout << 1 << endl;
        return 0;
    }
    int e = sqrt(1000);
    int res = 0;
    FOR(b, 2, e + 1, 1) {
        int bp = b * b;
        if (bp > X) {
            break;
        }
        while (bp * b <= X) {
            bp *= b;
        }
        amax(res, bp);
    }
    cout << res << endl;
    return 0;
}


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

typedef long long ll;

int h, w, cnt, b[55][55];
char a[55][55];
queue<int> qr, qc;

void f(int p, int q, int r) {
	if(a[p][q]=='.') {
		qr.push(p);
		qc.push(q);
		a[p][q] = 'x';
		b[p][q] = r;
	}
}

int main() {
	int i, j;
	scanf("%d%d", &h, &w);
	for(i=1; i<=h; i++) {
		scanf("%s", &a[i][1]);
		for(j=1; j<=w; j++) cnt += a[i][j]=='.';
	}
	f(1, 1, 1);
	while(!qr.empty()) {
		i = qr.front(), qr.pop();
		j = qc.front(), qc.pop();
		if(i==h && j==w) {printf("%d", cnt-b[h][w]); return 0;}
		f(i+1, j, b[i][j]+1);
		f(i-1, j, b[i][j]+1);
		f(i, j+1, b[i][j]+1);
		f(i, j-1, b[i][j]+1);
	}
	puts("-1");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 20;
const int INF = 0x3f3f3f3f;
#define DEBUG(x) cout << x << '\n'

int n, m, k, c[MAXN][MAXN], a[MAXN], b[MAXN];
int main(){
#ifdef Irene
    freopen("in.txt", "r", stdin);
#endif // Irene
    ios::sync_with_stdio(false);

    cin >> n >> m >> k;
    for(int i = 0; i < n; i++){
        cin >> b[i];
        for(int j = 0; j < m; j++)
            cin >> c[i][j];
    }
    int bit = 1 << n, f, sum, mi = INF;
    for(int s = 1; s < bit; s++){
        fill(a, a + m, 0); f = 1, sum = 0;
        for(int i = 0; i < n; i++){
            if(!(s & (1<<i))) continue;
            sum += b[i];
            for(int j = 0; j < m; j++) a[j] += c[i][j];
        }
        for(int j = 0; j < m; j++) f &= a[j] >= k;
        if(f && sum < mi) mi = sum;
    }
    cout << (mi == INF ? -1 : mi);
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define int long long
#define double long double
#define F first
#define S second
using namespace std;

int mod=1e9+7;
const int mx=3005;
int dp[mx][mx], a[mx];
int n;

int fun(int i, int j){
    if(abs(i-j)<2){
        dp[i][j]=max(a[i],a[j]);
        return dp[i][j];
    }
    if(dp[i][j]){
        return dp[i][j];
    }
    int x=1e15, y=1e15;
    if(i+2<n){
        x= fun(i+2,j);
    }
    if(i+1<n && j-1>=0){
        x= min(x, fun(i+1,j-1));
    }
    if(i+1<n && j-1>=0){
        y=fun(i+1,j-1);
    }
    if(j-2>=0){
        y=min(y, fun(i, j-2));
    }
    dp[i][j]=max(x+a[i], y+a[j]);
    return dp[i][j];
}

int32_t main() {
    int T;
    T=1;
    //cin>>T;
    while(T--){
        cin>>n;
        int sum=0;
        for(int i=0;i<n;i++){
            cin>>a[i];
            sum+=a[i];
        }
        
        int x= fun(0,n-1);
        // for(int i=0;i<n;i++){
        //     for(int j=0;j<n;j++){
        //         cout<<dp[i][j]<<" ";
        //     }cout<<endl;
        // }
        // cout<<x<<endl;
        cout<<x-(sum-x);
        cout<<'\n';
    }
	return 0;
}

Measured memory_bytes: 70144
class Cmb:
    def __init__(self, N, mod=10**9+7):
        self.fact = [1,1]
        self.fact_inv = [1,1]
        self.inv = [0,1]
        
        """ 階乗を保存する配列を作成 """
        for i in range(2, N+1):
            self.fact.append((self.fact[-1]*i) % mod)
            self.inv.append((-self.inv[mod%i] * (mod//i))%mod)
            self.fact_inv.append((self.fact_inv[-1]*self.inv[i])%mod)
    
    """ 関数として使えるように、callで定義 """
    def __call__(self, n, r, mod=10**9+7):
        if (r<0) or (n<r):
            return 0
        r = min(r, n-r)
        return self.fact[n] * self.fact_inv[r] * self.fact_inv[n-r] % mod

n,k = map(int,input().split())
mod = 10**9+7
c = Cmb(N=n)
ans = 0
for l in range(min(k+1, n)):
    tmp = c(n,l)*c(n-1, n-l-1)
    ans += tmp%mod
print(ans%mod)

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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef tuple<int, int> duo;

#define TT template<typename T>
#define ET(T) typename T::value_type
TT inline T sq(T x){return x*x;}
TT inline T In(){T x;cin>>x;return x;}
TT inline int ubnd(T&v,ET(T) x){return upper_bound(begin(v),end(v),x)-begin(v);}
TT inline int lbnd(T&v,ET(T) x){return lower_bound(begin(v),end(v),x)-begin(v);}
TT inline void sort(T&v){sort(begin(v),end(v));}
TT inline void revs(T&v){reverse(begin(v),end(v));}
TT inline void uniq(T&v){sort(v);v.erase(unique(begin(v),end(v)),end(v));}
TT inline void inpt(T&v,int n,function<ET(T)()>f=In<ET(T)>){for(v.reserve(n);n--;v.emplace_back(f()));}
TT inline void show(T&v,string d=" ",string e="\n"){int i=0;for(auto&x:v)i++&&(cout<<d),cout<<x;cout<<e;}
#undef TT
#undef ET

inline void fast_io(){ios::sync_with_stdio(0); cin.tie(0);}
inline int in(){int x;scanf("%d",&x);return x;}
inline string instr(){string x;cin>>x;return x;}
inline ll pow_mod(ll a, ll k, ll m){ll r=1;for(;k>0;a=a*a%m,k>>=1)if(k&1)r=r*a%m;return r;}
inline ll mod_inv(ll a, ll p){return pow_mod(a,p-2,p);}

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

struct Sweets {
  int id, p, q, r, c;
  Sweets(int id, int p, int q, int r) : id(id), p(p), q(q), r(r), c((p + r) * 4 + q * 9) {}
};

int main()
{
  int n;
  while (n = in()){
    vector<Sweets> v;
    v.reserve(n);
    for (int i = 0; i < n; i++){
      int id, p, q, r;
      cin >> id >> p >> q >> r;
      v.emplace_back(Sweets(id, p, q, r));
    }
    int P, Q, R, C;
    cin >> P >> Q >> R >> C;
    bool na = true;
    for (const auto& vi : v){
      if (vi.p <= P && vi.q <= Q && vi.r <= R && vi.c <= C){
        cout << vi.id << "\n";
        na = false;
      }
    }
    if (na) cout << "NA\n";
  }
  return (0);
}

// priority_queue queue deque front top push pop map set stringstream max_element min_element insert count find get tie make_tuple

Measured memory_bytes: 1256
#include <iostream>

using namespace std;

int dsum(int n) {
    int res = 0;
    while(n != 0) {
        res += n % 10;
        n /= 10;
    }
    return res;
}

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

    int ans = 0;
    for (int i=1; i<=n; i++) {
        int _dsum = dsum(i);
        if (a <= _dsum && _dsum <= b) ans+= i;
    }
    cout << ans << endl;
}

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

int main(void){
  int a, b, c, i=1, se;
  cin >> a >> b >> c;
  while(true){
    se = a*i;
    if(se >= a*b) break;
    if(se%b==c){
      cout << "YES" << endl;
      return 0;
    }
    ++i;
  }
  cout << "NO" << endl;
}

Measured memory_bytes: 256
/*suri_kumkaran*/

#include <bits/stdc++.h>

using namespace std;

#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define MP make_pair
#define EB emplace_back
#define endl "\n"
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long

typedef long long int64;
typedef vector<int> VI64;
typedef vector<pair<int,int>> VII64;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;

int32_t main()
{
	IOS;
	int T=1;
	//cin>>T;
	while(T--)
	{
		int a,b,i;
		cin>>a>>b;
		for(i=1;i<1000000;i++)
		{
 			int x=i*0.08;
 			int y=i*0.1;
 			if(x==a&&y==b)
 			{
 				cout<<i;
 				return 0;
 			}
		}
		cout<<-1;
	}

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
const int mod = 1000000007;

struct mint {
  ll x;  // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }

  mint RepeatSquaring(mint N, ll P) {
    if (P == 0) return 1;
    if (P % 2 == 0) {
      mint t = RepeatSquaring(N, P / 2);
      return t * t;
    }
    return RepeatSquaring(N, P - 1) * N;
  }
};

struct combination {
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};

istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

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

  ll ans = 0;
  for (int i = 1; i <= K; i += 1) {
    // まずは赤を並べ、そこに青を入れるi個の場所を考える
    // 赤がN-K個なので隙間は端を含めてN-K+1個

    // 次に、i個の場所に対する青の入れ方を考える
    // これはK個の青の隙間（K-1）個に
    // i-1個のしきりを入れるのと同様なので

    cout << c(N - K + 1, i) * c(K - 1, i - 1) << endl;
  }
  return 0;
}

Measured memory_bytes: 256
//Codes by: Umar Bin Qamar

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

bool compare(int a,int b){
    return a>b;
}
int arr[10010];
int32_t main(){

//int count=0;
  int n,m;
  cin>>n>>m;
  //cin>>p;
  
  for(int i=0;i<m;i++){
    cin>>arr[i];
  }
  int count=0;
  for(int i=0;i<m;i++){
   count=count +arr[i];
 //   count=count-n;
  }
  if(count>n){
    printf("-1\n");
  }
  else{
    printf("%d\n",n-count);
  }


    return 0;
}



Measured memory_bytes: 3748
using System;

namespace UnionFind_Csharp{
    class Program{
        static void Main(string[] args){
            var line = System.Console.ReadLine().Split(' ');
            var n = int.Parse(line[0]);
            var q = int.Parse(line[1]);
            var uft = new UnionFindTree(n);
            for(int i=0; i<q; i++){
                var l = System.Console.ReadLine().Split(' ');
                var c = int.Parse(l[0]);
                var x = int.Parse(l[1]);
                var y = int.Parse(l[2]);
                if(c==0){
                    uft.unite(x,y);
                }else{
                    Console.WriteLine( uft.is_same_set(x,y)? 1: 0 );
                }
                
            }
        }
    }
    
    class UnionFindTree{
        private int[] tree;
        private int[] rank;
        public UnionFindTree(int n){
            tree = new int[n];
            rank = new int[n];
            for(int i=0; i<n; i++){
                tree[i] = i;
                rank[i] = 1;
            }
        }
        public int root(int a){
            if(tree[a] == a) return a;
            return (tree[a]=root(tree[a]));
        }
        public bool is_same_set(int a, int b) => tree[root(a)] == root(b);
        public void unite(int a, int b){
            var ra = root(a);
            var rb = root(b);
            if(ra == rb) return;
            if(rank[ra] < rank[rb]){
                tree[ra] = rb;
            }else{
                tree[rb] = ra;
                if(rank[ra] == rank[rb]) rank[ra]++;
            }
        } 
    }
}



Measured memory_bytes: 22072
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    int n; cin >> n;
    deque<string> v;
    bool b = n % 2 == 0 ? true : false;

    REP(i,n) {
        string x; cin >> x;
        if (b) v.push_back(x);
        else v.push_front(x);
        b = !b;
    }

    string ans = "";
    REP(i,n-1) {
        ans += v[i] + " ";
    }
    ans += v[n-1];

    cout << ans << endl;

    return 0;
}

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

#define ll long long
#define INF_LL 1LL << 60
#define INF 99999999
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }


int main()
{
    int A,B,C;
    cin >> A >> B >> C;
    
    if( A <= C && C <= B ) cout << "Yes" << endl;
    else cout << "No" << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

struct UnionFind {
  vector<int> parent;
  UnionFind (int n) : parent(n, -1) {}
  int root(int x) { return parent[x] < 0 ? x : parent[x] = root(parent[x]); }
  bool merge(int x, int y) {
    x = root(x); y = root(y);
    if (x == y) return false;
    if (parent[y] < parent[x]) swap(x, y);
    if (parent[x] == parent[y]) --parent[x];
    parent[y] = x;
    return true;
  }
};

int main()
{
  int n,m,k;
  cin>>n>>m>>k;
  vector<vecint> g1(n), g2(n);
  UnionFind uf(n);
  for(auto&& i:irange(0,m)) {
    int a,b;
    cin>>a>>b;
    --a;--b;
    g1[a].push_back(b);
    g1[b].push_back(a);
    uf.merge(a,b);
  }
  for(auto&& i:irange(0,k)) {
    int a,b;
    cin>>a>>b;
    --a;--b;
    g2[a].push_back(b);
    g2[b].push_back(a);
  }
  vecint cnt(n);
  for(auto&& i:irange(0,n)) {
    ++cnt[uf.root(i)];
  }
  for(auto&& i:irange(0,n)) {
    if(i) cout<<' ';
    int ans = cnt[uf.root(i)] - g1[i].size() - 1;
    for(auto&& to:g2[i]) {
      if (uf.root(i) == uf.root(to)) --ans;
    }
    cout<<ans;
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 12664
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;
#define ll int64_t
const long mod = 1e9 + 7;


const long LINF = 1e13;
const long LLINF = 1e18;
const long ALPHABET = 26;

template <class T>
void Swap(T& r, T& l) {
  T tmp = r;
  r = l;
  l = tmp;
}

template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
  for (T& x : vec) is >> x; //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいい
  return is;
}




int main() {

  long n,m;

  cin >> n >> m;

  vector<long> x(m);
  cin >> x;

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

  long ans = 0;

  vector<long> interval_x(m-1);

  for (int i = 1; i < m; ++i){
    interval_x[i-1] = x[i] - x[i-1];
  }

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


  // mに対してnおく


  for(int i=1;i<=m-n;i++){
    ans += interval_x[i-1];
    cerr << interval_x[i-1] <<endl;
  }





  cout << ans;


}




















Measured memory_bytes: 1792
#include <stdio.h>
#define SENTINEL 1000000000;
int A[500000];
int L[500000],R[500000];
int count=0;
void merge(int left,int mid,int right){
  int n1,n2,i,j,k;
  n1=mid-left;
  n2=right-mid;
  
  for(i=0;i<n1;i++)
    {
      L[i]=A[left+i];
    }
  for(i=0;i<n2;i++)
    {
      R[i]=A[mid+i];
    }
  L[n1]=SENTINEL;
  R[n2]=SENTINEL;
  i=0;
  j=0;
  for(k=left;k<right;k++)
    {
      count++;
      if(L[i]<=R[j])
	{
	  A[k]=L[i];
	  i++;
	}
      else 
	{
	  A[k]=R[j];
	  j++;
	}
    }
}

void mergesort(int left,int right){
  int mid;
  if(left+1<right)
    {
      mid=(left+right)/2;
      mergesort(left,mid);
      mergesort(mid,right);
      merge(left,mid,right);
    }
}

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

  mergesort(0,n);

  for(i=0;i<n;i++)
    {
      printf("%d",A[i]);
      if(i<n-1)
	{
	  printf(" ");
	}
    }
  printf("\n");
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 5488
class Array
  def cumsum!(s = 0); map!{|t| s += t } end
end

n, k = gets.to_s.split.map{|t| t.to_i }
a    = gets.to_s.split.map{|t| t.to_i }

ans = []
[k, 50].min.times do |i|
  ans = [0] * n
  a.each_with_index do |t, i|
    
    j = i - t
    if 0 <= j
      ans[j] += 1
    else
      ans[0] += 1
    end
    
    j = i + t + 1
    ans[j] += -1 if j < n
  end
  ans.cumsum!
  a = ans.dup
end

puts ans * ' '

Measured memory_bytes: 83432
#include<stdlib.h>
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<cstring>
#include<time.h>
#include<queue>
using namespace std;
#define INF 10000000
struct set{
	int a;
	int b;
};
int n,m,f[501];
set s[10002];
int main(){
	while(1){
		int c=0;
		cin>>n;
		cin>>m;
		if(n==0&&m==0)break;
		for(int i=0;i<=n;i++){
			f[i]=0;
		}
		for(int i=0;i<m;i++){
			cin>>s[i].a>>s[i].b;
			if(s[i].a==1){
				f[s[i].b]=1;
			}	
		}
		for(int i=0;i<m;i++){
			if(f[s[i].a]==1){
				if(f[s[i].b]==0){
					f[s[i].b]=2;
				}
			}else if(f[s[i].b]==1){
				if(f[s[i].a]==0){
					f[s[i].a]=2;
				}
			}
		}
		for(int i=2;i<=n;i++){
			if(f[i]!=0)c++;
		}
		cout<<c<<endl;
	}
	return 0;
}	

Measured memory_bytes: 1240
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
int main(){
  int n;
  while(cin >> n, n){
    int sum = 1;
    int l = 1,r = 2;//(l,r]
    while(sum!=n){
      if(sum<n){
        sum += r++;
      }else{
        sum -= l++;
      }
    }
    cout << l << " " << r-l << endl;
  }
}



Measured memory_bytes: 3096
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>

#define ABS(x) ( (x)>0 ? x : -(x) )
#define MIN(x,y) ( (x) < (y) ? (x) : (y) )
#define MAX(x,y) ( (x) > (y) ? (x) : (y) )
#define INF 1000000000

long long int sum_digit(long long int x)
{
	long long int sum = 0;

	while (x > 0)
	{
		sum += x % 10;
		x /= 10;
	}
	return sum;
}

int main()
{
	char x[1000][1001];

	int i, j;
	int count = 0;

	for (i = 0;; i++)
	{
		scanf("%s", x[i]);
		if (x[i][0] == '0')
			break;

		count++;
	}

	int sum = 0;
	for (i = 0; i < count; i++)
	{
		sum = 0;
		for (j = 0; j < strlen(x[i]); j++)
		{
			sum += x[i][j] - '0';
		}
		printf("%d\n", sum);
	}

	return 0;
}



Measured memory_bytes: 2112
/* ITP1_11_C: Dice III */
/* 20181128 AOJ */

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

enum Direction {top, front, right, left, back, bottom};

void RotateWE(int* Dice);
void RotateSN(int* Dice);

int main(void) {
	int Dice[2][6];
	int i, j, k, flag;

	for(i = 0; i < 2; i++) {
		for(j = 0; j < 6; j++) scanf("%d", Dice[i] + j);
	}

	flag = 0;
	for(k = 0; k < 2; k ++)
	{
		for(i = 0; i < 4; i++)
		{
			for(j = 0; j < 4; j++)
			{
				if(Dice[0][top] == Dice[1][top] &&
				   Dice[0][bottom] == Dice[1][bottom] &&
				   Dice[0][left] == Dice[1][left] &&
				   Dice[0][right] == Dice[1][right] &&
				   Dice[0][front] == Dice[1][front] &&
				   Dice[0][back] == Dice[1][back])
				{
					flag = 1;
					break;
				} 
				RotateWE(Dice[0]);
			}
			if(flag) break;		
			RotateSN(Dice[0]);
		}
		if(flag) break;
		RotateWE(Dice[0]);
	}

	if(flag) puts("Yes");
	else puts("No");
	
	return 0;
}

void RotateWE(int* Dice) {
	int temp = temp = Dice[top];	
	Dice[top] = Dice[left];
	Dice[left] = Dice[bottom]; 
	Dice[bottom] = Dice[right];
	Dice[right] = temp;
}

void RotateSN(int* Dice){
	int temp = Dice[top];
	Dice[top] = Dice[back];
	Dice[back] = Dice[bottom]; 
	Dice[bottom] = Dice[front];
	Dice[front] = temp;
}


Measured memory_bytes: 2144
package main

import (
	"fmt"
)

// 挿入ソート
func main() {

	var num int
	// fmt.Scanは自動で空白区切で読み込む
	fmt.Scan(&num)
	nums := make([]int, num)
	for i := range nums {
		fmt.Scan(&nums[i])
	}

	insertSort(nums)
}

func insertSort(nums []int) {
	output(nums)
	for i := 1; i < len(nums); i++ {
		for j := i - 1; j >= 0; j-- {
			if nums[j+1] < nums[j] {
				tmp := nums[j+1]
				nums[j+1] = nums[j]
				nums[j] = tmp
			} else {
				break
			}
		}
		output(nums)
	}
}

func output(nums []int) {
	for k := 0; k < len(nums); k++ {
		if k != len(nums)-1 {
			fmt.Print(nums[k], " ")
		} else {
			fmt.Println(nums[k])
		}
	}
}



Measured memory_bytes: 1180
N=int(input())
h=list(map(int,input().split()))
node=[0]
for i in range(1,N):
    if i==1:
        node.append(abs(h[1]-h[0]))
    else:
        a=abs(h[i]-h[i-1])+node[-1]
        b=abs(h[i]-h[i-2])+node[-2]
        node.append(min(a,b))
print(node[-1])

Measured memory_bytes: 13908
#![allow(non_snake_case, unused_imports)]

// Input
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} };}
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,HashMap,BTreeMap,VecDeque};

// Functions

// Main
fn main(){
    input!{
        H: usize,
        W: usize,
    }
    let mut ans = 999999999;
    let (mut s1, mut s2, mut s3) = (1,1,1);
    // 高さで分割するのを全探索、一方を更に高さor幅で分割
    for h in 1..H{
        s1 = h*W;
        // 高さで分割
        s2 = ((H-h)/2)*W;
        s3 = (H-h-(H-h)/2)*W;
        ans = min(ans, max(s1,max(s2,s3))-min(s1,min(s2,s3)));
        // 幅で分割
        s2 = (H-h)*(W/2);
        s3 = (H-h)*(W-W/2);
        ans = min(ans, max(s1,max(s2,s3))-min(s1,min(s2,s3)));
    }
    // 高さと幅を入れ替えて再実行
    let (H,W) = (W,H);
    for h in 1..H{
        s1 = h*W;
        // 高さで分割
        s2 = ((H-h)/2)*W;
        s3 = (H-h-(H-h)/2)*W;
        ans = min(ans, max(s1,max(s2,s3))-min(s1,min(s2,s3)));
        // 幅で分割
        s2 = (H-h)*(W/2);
        s3 = (H-h)*(W-W/2);
        ans = min(ans, max(s1,max(s2,s3))-min(s1,min(s2,s3)));
    }
    println!("{}",ans);
}

Measured memory_bytes: 4476
#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define test ll t; cin>>t; while(t--)
#define ll long long 
#define pb push_back
int main(){    
    fast;
    	string s; cin>>s;
    	if(s[2]==s[3] && s[4]==s[5]) cout<<"Yes\n";
    	else cout<<"No\n";
    	}

    

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

n,m=map(int, input().split())
es=[[] for _ in range(n)]
for i in range(m):
    a,b=map(int, input().split())
    es[a-1].append(b-1)
    es[b-1].append(a-1)

ans=0
from collections import deque
used=[0 for _ in range(n)]
for i in range(n):
    if used[i]==0:
        d=deque([i])
        cnt=0
        while d:
            now=d.popleft()
            cnt+=1
            used[now]=1
            for e in es[now]:
                if used[e]==0:
                    used[e]=1
                    d.append(e)
        ans=max(cnt,ans)
print(ans)

Measured memory_bytes: 113192
#include<iostream>
using namespace std;
int main(){
	long long a,b;
	cin>>a>>b;
	long long sum=a*b/2;
	if(a*b%2!=0)
		++sum;
	if(a==1||b==1)
		cout<<1;
	else
		cout<<sum<<endl;
	return 0;
}

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

using namespace std;

struct tort {long long x, y, z; int poz;} a[1002], b[1002];
long long n, sol, m, nr;
int semn[2] = {1, -1};
int v[9][3];

bool cmp (tort p, tort q) {
  return p.x + p.y + p.z > q.x + q.y + q.z;
}

int main()
{
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> a[i].x >> a[i].y >> a[i].z;
  }
  for (int i = 0; i < 2; i++)
    for (int j = 0; j < 2; j++)
      for (int k = 0; k < 2; k++) {
        nr++;
        v[nr][0] = semn[i], v[nr][1] = semn[j], v[nr][2] = semn[k];
      }
  for (int k = 1; k <= 8; k++) {
    for (int i = 1; i <= n; i++) {
      b[i].x = v[k][0] * a[i].x;
      b[i].y = v[k][1] * a[i].y;
      b[i].z = v[k][2] * a[i].z;
      b[i].poz = i;
    }
    sort (b + 1, b + n + 1, cmp);
    long long sumx = 0, sumy = 0, sumz = 0;
    for (int i = 1; i <= m; i++)
      {sumx += a[b[i].poz].x; sumy += a[b[i].poz].y; sumz += a[b[i].poz].z;}
    sol = max(sol, abs(sumx) + abs(sumy) + abs(sumz));
  }
  cout << sol;
  return 0;
}


Measured memory_bytes: 256
Scanf.scanf "%s" (fun s ->
    let k = "keyence" in
    let n = String.length s in
    let judge a =
        String.sub s 0           a       = String.sub k 0 a &&
        String.sub s (n - 7 + a) (7 - a) = String.sub k a (7 - a)
    in
    let rec loop i =
        if i < 0 then "NO" else
            if judge i then "YES" else
                loop (i - 1)
    in
    loop 7 |> print_endline
)


Measured memory_bytes: 384
n = int(input())
h = list(map(int,input().split()))
ans = [0,abs(h[1]-h[0])]
for i in range(2,n):
	ans.append(min((ans[i-1] + abs(h[i]-h[i-1])),(ans[i-2] + abs(h[i]-h[i-2]))))
print(ans[n-1])

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

int main(){
	long a, b, n;
	scanf("%ld%ld%ld", &a, &b, &n);
	long x = n;
	if(b - 1 < n) x = b - 1;
	printf("%ld\n", a * x / b - a * (x / b));
}


Measured memory_bytes: 3820
#include<iostream>
#include<cstdio>
#include<cstdlib>
#define ll long long
#define mod 1000000007
using namespace std;
ll f[50][1<<18],ans=1;
int main()
{
	int n,x,y,z;
	scanf("%d%d%d%d",&n,&x,&y,&z);
	for(int i=1;i<=n;i++) ans=ans*10%mod;
	int N=(1<<(x+y+z))-1,res=(1<<(x-1))|(1<<(x+y-1))|(1<<(x+y+z-1));
	f[0][0]=1;
	for(int i=1;i<=n;i++)
		for(int s=0;s<=N;s++)
			for(int j=1,o=0;j<=10;j++)
			if(((o=((s<<j)|((1<<j-1)))&N)&res)!=res)
			f[i][o]=(f[i][o]+f[i-1][s])%mod;
	for(int i=0;i<=N;i++) ans=(ans-f[n][i]+mod)%mod;
	printf("%lld",ans);
	return 0;
}


Measured memory_bytes: 82176
#include<bits/stdc++.h>
using namespace std;
int n,d,f[2005][2005],x,y,i,j,l,r,s1[3005][3005],s2[3005][3005];
bool check(int m)
{
	++m;
	int l=m%d,i,j,t=m/d+1;
	memset(s1,0,sizeof(s1));
	memset(s2,0,sizeof(s2));
	for(i=0;i<2*d;i++)
		for(j=0;j<2*d;j++)
		{
			if(f[i][j]>1ll*(t-1)*(t-1))
				s1[i][j]++;
			if(f[i][j]>1ll*t*(t-1))
				s2[i][j]++;
			if(f[i][j]>1ll*t*t)
				return false;
		}
	for(i=0;i<2*d;++i)
		for(j=0;j<2*d;++j)
			if(j!=0)
			{
				s1[i][j]+=s1[i][j-1];
				s2[i][j]+=s2[i][j-1];
			}
	for(i=0;i<2*d;++i)
		for(j=0;j<2*d;++j)
			if(j!=0)
			{
				s1[j][i]+=s1[j-1][i];
				s2[j][i]+=s2[j-1][i];
			}
	for(i=d;i<2*d;++i)
		for(j=d;j<2*d;++j)
			if(s1[i-l][j-l]-s1[i-d][j-l]-s1[i-l][j-d]+s1[i-d][j-d]==0&&s2[i][j-l]-s2[i-l][j-l]-s2[i][j-d]+s2[i-l][j-d]==0&&s2[i-l][j]-s2[i-l][j-l]-s2[i-d][j]+s2[i-d][j-l]==0)
				return true;
	return false;
}
int main()
{
	scanf("%d %d",&n,&d);
	for(i=1;i<=n;++i)
	{
		scanf("%d %d",&x,&y);
		++f[(x%d+d)%d][(y%d+d)%d];
	}
	for(i=0;i<2*d;++i)
		for(j=0;j<2*d;++j)
			f[i][j]=f[i%d][j%d];
	l=0;
	r=10000000;
	while(l<r)
	{
		int mid=l+r>>1;
		if(check(mid))
			r=mid;
		else
			l=mid+1;
	}
	cout<<l;
}


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

int main()
{
  int a,b,c;
  int res=0;
  cin >> a >> b>>c;

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

}


Measured memory_bytes: 256
#include <cmath>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int N, K; long long dp[109][2]; bool vis[109][2];
long long solve(int pos, int col) {
	if (vis[pos][col]) return dp[pos][col];
	long long ret = (col == 1 ? 1 : 0);
	if (pos < N) ret += solve(pos + 1, col ^ 1);
	if (pos <= N - K && col == 0) ret += solve(pos + K, col ^ 1);
	vis[pos][col] = true;
	dp[pos][col] = ret;
	return ret;
}
int main() {
	cin >> N >> K;
	cout << solve(0, 0) << endl;
	return 0;
}

Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rfor(i, a, b) for (int i=a; i<(b); i++)
#define zfor(i, a) for (int i=0; i<(a); i++)
#define brfor(i,a,b) for (int i = (b)-1; i >= a; i--)
#define bzfor(i,a) for (int i = (a)-1; i >= 0; i--)

int main(){
    int n;
    cin>>n;
    int arr[n];
    zfor(i,n){
        cin>>arr[i];
    }
    vector<int> xro;
    zfor(i,n-1){
        xro.emplace_back(arr[i]^arr[i+1]);
        ++i;
    }
    int totalXor = xro[0];
    rfor(i,1,xro.size()){
        totalXor = totalXor ^ xro[i];
    }
    zfor(i,n){
        int cx = totalXor^arr[i];
        cout<<cx<<" ";
    }
}

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

int main() {
  long long N;
  cin >> N;
  priority_queue<long long, vector<long long>, greater<long long>> que;
  long long tmp,ans=0;
  for(long long i = 0; i < N; i++){
    cin >> tmp;
    que.push(tmp);
    if(tmp==que.top()){
      ans++;
    }
  }
  cout << ans;
}


Measured memory_bytes: 2420
#include<stdio.h>
int main(){
   int sum=700;
   char s[4]={'\0'};
   scanf("%s",s);
   for(int i=0;i<3;i++){
      if(s[i]=='o'){
      sum+=100;
      }
    } 
  printf("%d\n",sum);
  return 0;
}


Measured memory_bytes: 128
n     = gets.to_i
size  = n.to_s.size
count = [0]
num   = []

def dp(n, num, count, size, dim)

  [3, 5, 7].each do |i|

    num[dim] = i

    x = num.uniq.sort.join.to_i
    if x == 357 && num.join.to_i <= n
      count[0] += 1
    end

    if dim + 1 < size
      dim += 1
      dp(n, num, count, size, dim)
      num.pop
      dim -= 1
    end
  end
end

dp(n, num, count, size, 0)

puts count[0]


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
int n,l,r,ans=0,A[55]={};

void solve(int x){
  for(int i=1;i<=n;i++){
    if(x%A[i]==0){
      if(i%2==0);
      else ans++;
      return;
    }
  }
  if(n%2==0) ans++;
  else;
  return;
}

int main(){
  while(1){
    cin >> n >> l >> r;
    ans=0;
    if(n==0 && l==0 && r==0) break;
    for(int i=1;i<=n;i++) cin >> A[i];
    for(int x=l;x<=r;x++) solve(x);
    cout << ans << endl;
  }
  return 0;
}



Measured memory_bytes: 3020
from collections import Counter
N = int(input())
S = list(input())
cnt = Counter(S)
ans = 1
for s in list('RGB'):
    ans *= cnt[s]

for i in range(N):
    for j in range(i + 1, N):
        K = 2*j - i
        if K >= N:
            break
        if (S[i] != S[j]) & (S[j] != S[K]) & (S[i] != S[K]):
            ans -= 1
print(ans)


Measured memory_bytes: 9404
#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+5;
const int mod=1e9+7;
#define pb push_back
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef vector<int> vi;
ll qpow(ll a,ll b){ll ans=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)ans=ans*a%mod;a=a*a%mod;}return ans;}
ll gcd(ll a,ll b){return b>0?gcd(b,a%b):a;}

int a[maxn];
int dp[maxn][2];
vi g[maxn];
int vis[maxn];
ll ans,k;
int fac[maxn];
int inv[maxn];
void dfs(int u,int fa,int dep){
	ll sz=g[u].size()-(dep>1),temp;
	if(dep==1) temp=k-1;
	else temp=k-2;
//	cout<<u<<"========="<<sz<<" "<<g[u].size()<<endl;
	for(int i=0;i<sz;i++){
		ans=1ll*ans*(temp-i)%mod;
//		cout<<(temp-i)<<" ";
	}
//	cout<<endl;
//	cout<<u<<"-------------"<<ans<<endl;
	for(auto v:g[u]){
		if(v==fa)continue;
		dfs(v,u,dep+1);
	}
}
int main(){
	fac[0]=1;
	ll n,m;
	for(int i=1;i<=10005;i++)fac[i]=1ll*fac[i-1]*i%mod;
	
	cin>>n>>m;
	k=m;
	int u,v;
	for(int i=1;i<n;i++){
		cin>>u>>v;
		g[u].pb(v);
		g[v].pb(u);
	}
	ans=k;
	dfs(1,0,1);
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 17152
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m;i>n;i--)
#define pb(n) push_back(n)
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(20) << S << endl
#define Vecpr(K,L1,L2,N) vector<pair<L1,L2>> K(N)
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M) vector<vector<L>> K(N, vector<L>(M))
#define mod 1000000007
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
lli gcd(lli num1, lli num2){
    return num2 != 0 ? gcd(num2, num1 % num2) : num1;
}
lli lcm(lli num1, lli num2){
    return num1 / gcd(num1, num2) * num2;
}
int main(){
  lli B,C,D,E,F,N,M,K,sum=0,num=0,ans=0;
  cin >> N >> K;
  Vec(A,lli,N,0);
  rep(i,0,N)cin >> A[i];
  rep(i,0,N-1)rep(j,i+1,N)if(A[i]>A[j])sum++;
  rep(i,1,N)rrep(j,i-1,-1)if(A[i]>A[j])num++;
  ans+=sum*K%mod;
  ans%=mod;
  num+=sum;
  ans+=K*(K-1)/2%mod*num%mod;
  ans%=mod;
  Out(ans);
}

Measured memory_bytes: 256
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

struct N {
  long long v, w;
  bool swapped;
};

bool operator<(const N &lhs, const N &rhs) { return lhs.v < rhs.v; }

int main() {
  int n;
  cin >> n;
  vector<pair<long long, long long>> ps(n);
  for (int i = 0; i < n; i++)
    cin >> ps[i].first >> ps[i].second;
  long long mi = ps[0].first;
  long long ma = ps[0].first;
  for (int i = 0; i < n; i++) {
    mi = min(mi, ps[i].first);
    mi = min(mi, ps[i].second);
    ma = max(ma, ps[i].first);
    ma = max(ma, ps[i].second);
  }
  long long smi = ma;
  long long sma = mi;
  for (int i = 0; i < n; i++) {
    long long a = min(ps[i].first, ps[i].second);
    long long b = max(ps[i].first, ps[i].second);
    smi = min(smi, b);
    sma = max(sma, a);
  }
  long long ans = (ma - smi) * (sma - mi);
  multiset<N> q;
  sma = 0;
  for (int i = 0; i < n; i++) {
    q.insert(N{min(ps[i].first, ps[i].second), max(ps[i].first, ps[i].second),
               false});
    sma = max(sma, min(ps[i].first, ps[i].second));
  }
  for (int i = 0; i < 2 * n; i++) {
    N now = *q.begin();
    q.erase(q.begin());
    ans = min(ans, (ma - mi) * (sma - now.v));
    if (now.swapped) {
      break;
    }
    q.insert(N{now.w, now.v, true});
    sma = max(sma, now.w);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 17920
#include <stdio.h>

int n;

int makeNumber(int, int, int *);

int main()
{
  int a[20], q, m[200];
  int i, status;

  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[i]);
  }
  
  for(i = 0; i < q; i++){
    status = 0;
    status = makeNumber(0, m[i], a);
    if(status == 1) printf("yes\n");
    else printf("no\n");
  }
  return 0;
}


int makeNumber(int start, int key, int *a){
  int i, status;
  
  for(i = start; i < n; i++){
    if(key == a[i]) return 1;
    if(key < 0) break;
    if(key == 0) return 1;
    if((status = makeNumber(i + 1, key - a[i], a)) == 1) break;
  }
  if(status == 1) return 1;
  else return 0;
}



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

using ll=long long;
const ll MOD=1e9+7;

int main(){
  int A,B,C;
  cin >> A >> B >> C;
  bool flag=false;
  for (int i=1;i<B;i++){
    if(A*i%B==C)
      flag=1;
  }
  if (flag)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>
#include<random>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, -1, 0, 1};
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

struct edge {
    int v;
    ll w;
    edge() {}
    edge(int v, ll w) : v(v), w(w) {};
};

vector<ll> dijkstra(int n, vector<vector<edge> >& G, int s) {
    vector<ll> d(n, LLONG_MAX/10); d[s] = 0;
    priority_queue<pair<ll, int> > que;
    que.push(make_pair(0ll, s));
    while (!que.empty()) {
        auto p = que.top(); que.pop();
        int u = p.second;
        ll dist = -p.first;
        if (dist > d[u]) continue;
        for (edge e : G[u]) {
            if (d[e.v] > d[u]+e.w) {
                d[e.v] = d[u] + e.w;
                que.push(make_pair(-d[e.v], e.v));
            }
        }
    }
    return d;
}

void dfs(int v, int p, vi& vs, const vector<vector<edge> >& G) {
    vs.push_back(v);
    for (auto e : G[v]) if (e.v != p) {
        dfs(e.v, v, vs, G);
    }
}

ll dist[2222][2222];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    vector<vector<edge> > G(N);
    for (int i = 0; i < N-1; i++) {
        int u, v;
        cin >> u >> v;
        u--; v--;
        G[u].emplace_back(v, 1);
        G[v].emplace_back(u, 1);
    }
    for (int i = 0; i < N; i++) {
        auto d = dijkstra(N, G, i);
        for (int j = 0; j < N; j++)
            dist[i][j] = d[j];
    }
    int ans = N;
    for (int i = 0; i < N; i++) {
        int leaf = -1, maxi = 0;
        for (auto e : G[i]) {
            int ch = e.v;
            vi vs;
            dfs(ch, i, vs, G);
            int sz = vs.size();
            int cnt = N-sz-1;
            vi exist;
            for (int v : vs) {
                if (dist[i][v] > K) cnt++;
                else {
                    exist.push_back(v);
                    if (maxi < dist[i][v]) {
                        maxi = dist[i][v];
                        leaf = v;
                    }
                }
            }
            for (int v : exist) {
                if (dist[leaf][v] > K) cnt++;
            }
            ans = min(ans, cnt);
        }
    }
    cout << ans << endl;
    return 0;
}


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

int N ;

int main() {
    cin>>N ;
    int h=N/100 ;
    int d=(N-100*h)/10 ;
    int s=N%10 ;
    if (h==7 or d==7 or s==7){
        cout<<"Yes";
    }
    else {
        cout<<"No";
    }

	return 0;
}

Measured memory_bytes: 3544
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
template<class Type>
class Stack
{
    struct Node
    {
        Type num;
        Node *forward;
    };
    int sz;
    Node *head;
    public:
        Stack() {sz = 0; head = new Node;}
        void push(Type x)
        {
            Node *n = new Node;
            n->num = x, n->forward = head;
            head = n, sz++;
        }
        Type pop()
        {
            if(size() == 0) return -1;
            Type res = head->num;
            Node *n = head;
            head = n->forward;
            delete n, sz--;
            return res;
        }
        Type top() { if (size() != 0) return head->num; }
        Type size() { return sz; }
};
int to_int(string s)
{
    int res = 0;
    int n = s.size(), x = 1;
    for(int i = n - 1; i >= 0; i--)
    {
        res += x * (s[i] - '0');
        x *= 10;
    }
    return res;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    Stack<int> st;
    while(cin >> s)
    {
        int a, b;
        if(s == "+") 
        {
            a = st.pop(), b = st.pop();
            st.push(a + b);
        }
        else if(s == "-")
        {
            a = st.pop(), b = st.pop();
            st.push(b - a);
        }
        else if(s == "*")
        {
            a = st.pop(), b = st.pop();
            st.push(a * b);
        }
        else
        {
            st.push(to_int(s));
        }
    }
    while(st.size() != 0)
    {
        cout << st.pop() << endl;
    }
    return 0;
}




Measured memory_bytes: 3228
import sys
import math

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MATINT(h): return [list(map(int, input().split())) for _ in range(h)]
def MATSTR(h): return [input() for _ in range(h)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7

def main():
    N = INT()
    minv = inf
    for i in range(5):
        minv = min(minv, INT())
    print(5 + math.ceil(N/minv) - 1)

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
import java.util.*;

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

    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int d = sc.nextInt();

    if (Math.abs(c-a) <= d) {
      System.out.println("Yes");
    } else if (Math.abs(b-c) <= d && Math.abs(b-a) <= d) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}


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

int main() {
  int H,W;
  cin >> H >> W;
  
  string picture;
  string sharp="#";
  vector<string>A(H+1);
  
  for(int i=0; i<H; i++){
    cin >> picture;
    string new_picture = sharp;
    for(int j=0; j<W; j++){
      new_picture += picture.at(j); 
    }
    new_picture += sharp;
    A.at(i+1)=new_picture;
  }
  
  string All_sharp;
  for(int k=0; k<A.at(1).size(); k++){
    All_sharp += sharp;
  }
  
  A.at(0)=All_sharp;
  A.push_back(All_sharp);
  for(int k=0; k<A.size();k++){
    cout << A.at(k) << endl;
  }
}


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

namespace ConsoleApp_ITP1_6_D
{
    class Program
    {
        static void Main(string[] args)
        {
            {
                //配列次元の読み込み
                int[] matrixDimension = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
                int n = matrixDimension[0];
                int m = matrixDimension[1];

                //配列の定義
                int[,] matrixA = new int[n, m];
                int[] matrixB = new int[m];
                int[] matrixC = new int[n];

                //配列aの要素に読み込んだ値を代入
                for (int i = 0; i < n; i++)
                {
                    int[] matrixALaine = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

                    for (int j = 0; j < m; j++)
                    {
                        matrixA[i, j] = matrixALaine[j];
                    }
                }

                //配列bの要素に読み込んだ値を代入
                for (int i = 0; i < m; i++)
                {
                    matrixB[i] = Int32.Parse(Console.ReadLine());
                }

                //配列の積(c=A*b)を計算し結果を出力
                for (int i = 0; i < n; i++)
                {
                    for (int j = 0; j < m; j++)
                    {
                        matrixC[i] += matrixA[i, j] * matrixB[j];
                    }

                    Console.WriteLine(matrixC[i]);
                }
            }
        }
    }
}


Measured memory_bytes: 9604
#include<iostream>
using namespace std;
int main(){
	for (int i = 0; i < 9; i++){
		for (int j = 0; j < 9; j++){
			cout << i + 1 << "x" << j + 1 << "=" << (i+1)*(j+1)<<endl;
		}
	}

	return 0;
}


Measured memory_bytes: 3080
N,M = map(int, input().split())
p = [0]*M
S = [0]*M
for i in range(M):
    p[i],S[i] = input().split()
q = [int(s)-1 for s in p]
X = [0]*N
Y = [0]*N
A = 0
B = 0
for i in range(M):
    if S[i] == "AC":
        if Y[q[i]]==0:
            Y[q[i]]+=1
            A += 1
            B += X[q[i]]
    else:
        if Y[q[i]]==0:
            X[q[i]] += 1
print(str(A)+" "+str(B))      

Measured memory_bytes: 21276