akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
const int MN = 305;
ll dp[MN][MN][MN];
const ll M = 1e9+7;
vii q[MN];
int main() {
	ll n,m;
	scanf("%lld %lld ",&n,&m);
	for(int i=0;i<m;i++) {
		ll a,b,c;
		scanf("%lld %lld %lld ",&a,&b,&c);
		q[b].push_back({a,c});
	}
	memset(dp,0,sizeof(dp));
	dp[1][0][0] = dp[0][1][0] = dp[0][0][1] = 1;
	for(int i=0;i<=n;i++) {
		for(int j=0;j<i;j++) {
			for(int k=0;k<i;k++) {
				for(int l=0;l<q[i].size();l++) {
					int ct = 1;
					int st = q[i][l].first;
					if(j >= st) {ct++;}
					if(k >= st) {ct++;}
					if(q[i][l].second != ct) {
						dp[i][j][k] = dp[j][i][k] = dp[j][k][i] = 0;
					}
				}
			}
		}
		for(int j=0;j<i;j++) {
			for(int k=0;k<i;k++) {
				dp[i+1][j][k] += dp[i][j][k];
				dp[i][i+1][k] += dp[i][j][k];
				dp[i][j][i+1] += dp[i][j][k];
				dp[i+1][i][k] += dp[j][i][k];
				dp[j][i+1][k] += dp[j][i][k];
				dp[j][i][i+1] += dp[j][i][k];
				dp[i+1][k][i] += dp[j][k][i];
				dp[j][i+1][i] += dp[j][k][i];
				dp[j][k][i+1] += dp[j][k][i];
			}
		}
		for(int j=0;j<=i;j++) {
			for(int k=0;k<=i;k++) {
				dp[i+1][j][k] %= M;
				dp[j][i+1][k] %= M;
				dp[j][k][i+1] %= M;
			}
		}
	}
	ll tot = 0;
	for(int i=0;i<n;i++) {
		for(int j=0;j<n;j++) {
			//printf("%lld %d %d\n",dp[i][j][n],i,j);
			tot += dp[n][i][j];
			tot += dp[i][j][n];
			tot += dp[i][n][j];
		}
	}
	tot %= M;
	printf("%lld\n",tot);
}

Measured memory_bytes: 221952
#include <bits/stdc++.h>
using i64 = int_fast64_t;
#define repeat(i, a, b) for(int i = (a); (i) < (b); ++(i))
#define rep(i, n) repeat(i, 0, n)

void solve() {
    int a, b, c, d, e, k;
    scanf("%d%d%d%d%d", &a, &b, &c, &d, &e);
    scanf("%d", &k);
    if(e - a <= k) {
        std::cout << "Yay!" << std::endl;
    } else {
        std::cout << ":(" << std::endl;
    }
}

int main() {
    // std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    solve();
    return 0;
}

Measured memory_bytes: 256
getX = do
  x <- getLine
  if x == "0"
    then
      return []
    else do
      xs <- getX
      return (x:xs)

putX (x:xs) i = do
  if x == []
    then
      return []
    else do
      putStrLn $ "Case " ++ show(i) ++ ": " ++ x
      if xs == []
        then
          return []
        else do
          putX xs (i + 1)
          return []

main = do
  l <- getX
  putX l 1

Measured memory_bytes: 7444
#include<iostream>
using namespace std;
int n,k;
int a[100000000];

int check(long long p){
	int i=0;
	for(int j=0;j<k;j++){
		long long s=0;
		while(s+a[i]<=p){
			s+=a[i];
			i++;
			if(i==n)return n;
		}
	} 
	return i;
}

int solve(){
	long long left=0;
	long long right=100000*10000;
	long long mid;
	while(right-left>1){
		mid=(left+right)/2;
		int v=check(mid);
		if(v>=n)right=mid;
		else left=mid;
	} 
	return right;
}

int main(){
    cin>>n>>k;
    for(int i=0;i<n;i++)cin>>a[i];
    long long ans=solve();
    cout<<ans<<endl;
} 


Measured memory_bytes: 3476
//=================================
// Created on: 2018/07/07 21:03:01
//=================================
#include <bits/stdc++.h>
#define show(x) cerr << #x << " = " << x << endl
using namespace std;
using ll = long long;
using ld = long double;
constexpr ll MOD = 1000000007LL;
template <typename T>
constexpr T INF = numeric_limits<T>::max() / 10;
mt19937 mt{random_device{}()};
int main()
{
    ll D, N, M;
    cin >> N >> M >> D;
    const ld d = (D == 0 ? N : 2 * N - 2 * D) * 1.0 / (N * N);
    cout << fixed << setprecision(15) << d * (M - 1) << endl;
    return 0;
}


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

using namespace std;

#define foru(i, l, r) for(register int i = l; i <= r; i++)
#define ford(i, r, l) for(register int i = r; i >= l; i--)

const int maxn = 2e6 + 5;
int N, K, H[maxn];
long long Ans = 0;

int main() {
  //  freopen("c.in", "r", stdin);
  //  freopen("c.out", "w", stdout);
  scanf("%d%d", &N, &K);
  if(K >= N) { puts("0"); return 0; }
  for(int i = 1; i <= N; i++) scanf("%d", &H[i]);
  sort(H + 1, H + N + 1);
  for(int i = 1; i <= N - K; i++) Ans += H[i];
  printf("%lld\n", Ans);
  return 0;
}


Measured memory_bytes: 1024
/**
*	  Name: Ajay Subhash Jadhav
*	  Institute: International Institute of Technology Hyderabad 
*/

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <deque>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <ctime>
#include <string.h>
#define LL long long
#define inf 0x7fffffff
#define mod 1000000007
#define pb push_back
#define ppi pair<int,int>
#define vi vector<int>
#define vii vector<ppi>
#define vll vector<LL>
#define mp make_pair
using namespace std;

void fastio()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
void inputread()
{
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif
}

int main(){
      
  fastio();
  int n,i;
  string s,t;
  cin>>s>>t;
  vi x,y;
  map<char,int> a,b;
  
  for(i=0;i<s.size();i++)
  	a[s[i]]++;
  for(i=0;i<s.size();i++)
  	b[t[i]]++;

  for(char i='a';i<='z';i++)
  	x.pb(a[i]);
  
  for(char i='a';i<='z';i++)
  	y.pb(b[i]);
  sort(x.begin(),x.end());
  sort(y.begin(),y.end());
  for(i=0;i<x.size();i++)
  {
  	if(x[i]!=y[i])
  	{
  		cout<<"No"<<"\n";
  		return 0;
  	}
  }
  cout<<"Yes";
  return 0;
}

Measured memory_bytes: 916
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define deb(x) cout<<#x<<" " <<x<<"\n";
#define pi 3.1415926535897932384626433832795
#define mod 1000000007
#define all(x) x.begin(), x.end()
#define cr7 ios_base::sync_with_stdio(false);cin.tie(NULL);
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (((a)*(b))/gcd((a),(b)))
/*
1
0
2
*/
int main()
{
    cr7
#ifndef ONLINE_JUDGE
    freopen("input1.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
#endif
    ll n, m;
    cin >> n >> m;
    ll h[n + 1] = {0};
    for (ll i = 1; i <= n; ++i) cin >> h[i];
    map<ll, vector<ll> > mp;
    for (ll i = 0; i < m; ++i) {
        ll arr1, arr2;
        cin >> arr1 >> arr2;
        mp[arr1].eb(arr2);
        mp[arr2].eb(arr1);
    }
    ll cnt = n;
    for (auto it : mp) {
        for (ll i = 0; i < (ll)it.second.size(); ++i) {
            if (h[it.first] <= h[it.second[i]]) {
                cnt--;
                break;
            }
        }
    }
    cout << cnt << "\n";
    return 0;
}

Measured memory_bytes: 14704
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;


namespace AtCoder_Beginner_Contest_132
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static void Main(string[] args)
        {
            var LR=Sarray();
            var L = LR[0];
            var R = LR[1];
            if(L/2019<R/2019)
            {
                WriteLine(0);
                return;
            }
            var l = L % 2019;
            var r = R % 2019;
            long min = long.MaxValue;
            for(var i=L;i<R;++i)
            {
                for(var j=i+1;j<=R;++j)
                {
                    min = Math.Min(min, (i * j) % 2019);
                }
            }
            WriteLine(min);
        }
    }
}


Measured memory_bytes: 13396
// http://arc058.contest.atcoder.jp/tasks/arc058_b
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int H, W, A, B;
const int K = 1E9 + 7 + 1E-5;
ll fact[200000 + 10];

pair<ll, ll> extgcd(ll n, ll m) {
  if (m == 0) return {1, 0};
  auto p = extgcd(m, n % m);
  return {p.second, p.first - n / m * p.second};
}

ll inverse_mod(ll n, ll m) {
  auto p = extgcd(n, m);
  ll x = p.first;
  ll y = p.second;
  assert(n * x + m * y == 1);
  if (x < 0) x += m;
  return x;
}
inline ll factorial(const ll n) {
  return fact[n];
}
ll choose_mod(ll n, ll k) {
  ll a1 = fact[n];

  ll a20 = (fact[k] * fact[n - k]) % K;

  ll ra2 = inverse_mod(a20, K);
  return (a1 * ra2) % K;
}
int ct(int h, int w) {
  if (h == 0 || w == 0) return 0;
  return choose_mod(h + w - 2, min(h, w) - 1);
}
int main() {
  // prepare factorial
  fact[0] = 1;
  fact[1] = 1;
  for(ll i = 2; i <= 200005; ++i) {
    fact[i] = (i * fact[i - 1]) % K;
  }


  cin >> H >> W >> A >> B;
  if (A == H || B == W) {
    cout << 0 << endl;
    return 0;
  }
  long long ret = ct(H, W);
 
  int n1 = H - 1 + B - 1;
  const int k1 = B - 1;
  int n2 = W - 1 - B + 1 - 1;
  const int k2 = W - 1 - B;

  for(int i = 0; i < A; ++i) {
    ll d1 = choose_mod(n1--, k1);
    ll d2 = choose_mod(n2++, k2);
    ret -= (d1 * d2) % K;
    ret += K;
    ret %= K;
  }
  cout << ret << endl;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int main() {
  int a,b; cin>>a>>b;
  if (!(a&1) || !(b&1)) {
    cout << "Even" << endl;

  } else {
    cout << "Odd" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#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;

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

template <class T>
class BIT {
  vector<T> data[2];
  T ZERO = 0;

 public:
  BIT(int n) { init(n); }
  void init(int n) {
    for (int i = 0; i < 2; ++i) {
      data[i].assign(n + 1, ZERO);
    }
  }

  void sub_add(int p, int a, T x) {
    for (int i = a; i < (int)data[p].size(); i += (i & -i)) {
      data[p][i] = data[p][i] + x;
    }
  }

  void add(int a, int b, T x) {
    sub_add(0, a, x * -(a - 1));
    sub_add(1, a, x);
    sub_add(0, b, x * (b - 1));
    sub_add(1, b, x * (-1));
  }

  T sub_sum(int p, int a) {
    T res = 0;
    for (int i = a; i > 0; i -= (i & -i)) {
      res += data[p][i];
    }
    return res;
  }

  T sum(int a, int b) {
    return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) -
           sub_sum(1, a - 1) * (a - 1);
  }
};

int N, Q;

int main() {
  cin >> N >> Q;
  vector<int> c(N + 1);
  repe(i, 1, N) { cin >> c[i]; }
  vector<int> left(Q), right(Q), ids(Q);
  rep(i, 0, Q) {
    cin >> left[i] >> right[i];
    ids[i] = i;
  }

  sort(ids.begin(), ids.end(),
       [&](int a, int b) { return right[a] < right[b]; });

  BIT<int> bit(N);
  vector<int> prev(N + 10, 0);
  vector<int> res(Q);
  int r = 1;
  for (auto q : ids) {
    for (; r <= right[q]; ++r) {
      bit.add(prev[c[r]] + 1, r + 1, 1);
      prev[c[r]] = r;
    }
    res[q] = bit.sum(left[q], left[q] + 1);
  }
  for (auto e : res) {
    cout << e << "\n";
  }
}


Measured memory_bytes: 19424
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

class UnionFind{
  int n;
  vector<int> data;
public:
  UnionFind(int _n):n(_n),data(_n,-1){}
  bool link(int a, int b){ //if new link, then true.
    int ra=find_root(a);
    int rb=find_root(b);
    if(ra!=rb){
      if(data[rb]<data[ra]) swap(ra,rb);
      data[ra]+=data[rb];
      data[rb]=ra;
    }
    return (ra!=rb);
  }
  bool check(int a, int b){ //if same set, then true.
    return (find_root(a)==find_root(b));
  }
  int find_root(int a){
    return ((data[a]<0)?a:(data[a]=find_root(data[a])));
  }
};


int main(){
  int N, M;
  cin >> N >> M;
  UnionFind uf(N);
  rep(i,M){
    int x, y, z;
    cin >> x >> y >> z;
    x--;
    y--;
    uf.link(x,y);
  }

  map<int,int> memo;
  rep(i,N){
    memo[uf.find_root(i)] = 1;
  }

  cout << memo.size() << endl;
  
  
  return 0;
}


Measured memory_bytes: 5376
from bisect import bisect_left
from collections import deque

n = int(input())
max_color = deque([int(input())])
for _ in range(n-1):
  a = int(input())
  if a <= max_color[0]:
    max_color.appendleft(a)
  else:
    index = bisect_left(max_color, a) - 1
    max_color[index] = a
print(len(max_color))

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

#define PI 3.141592653589
#define ll long long int
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define ii pair<int,int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pll pair<ll,ll>
#define vv vector
#define all(v) (v).begin(),(v).end()
int MOD=1e9+7;
ll power(ll a, ll b){//a^b
    ll res=1;
    a=a%MOD;
    while(b>0){
        if(b&1){res=(res*a)%MOD;b--;}
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
ll fermat_inv(ll y){return power(y,MOD-2);}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
ll min(ll a,ll b){return (a>b)?b:a;}
ll max(ll a,ll b){return (a>b)?a:b;}
bool prime[1000001];
vi primes;
void SieveOfEratosthenes(int n) 
{ 
    memset(prime, true, sizeof(prime)); 
    for (int p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
    for(int p=2;p<1000001;p++)
        if(prime[p])
            primes.pb(p);
}
ll fact[100010];
ll finv[100010];
void factorial(int n){
    fact[0]=1;
    finv[0]=1;
    for(int i=1;i<=n;i++)
        fact[i]=fact[i-1]*i,fact[i]%=MOD,finv[i]=fermat_inv(fact[i]);
}
ll ncr(ll n,ll r)
{
    if(n<r)
        return 0;
    else{
        ll x=finv[r]*finv[n-r]%MOD;
        return fact[n]*x%MOD;
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    int te=1;
    //cin>>te;
    //SieveOfEratosthenes(1000000);
    //factorial(100005);
    while(te--){
        string s;
        cin>>s;
        int n=s.size();
        if(s[n-1]=='s')
            s+="es";
        else
            s+='s';
        cout<<s;
    }
}

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


int f(string s){
    if(s.size()%2) return 0;
    int p = s.size()/2;
    string sb = s.substr(0,p);
    if(sb+sb == s){
        return sb.size()*2;
    }
    return 0;
}

int main() {
    string s;
    cin >> s;
    int ans;
    for(int i = 1;i<s.size();i++){
        ans=f(s.substr(0,s.size()-i));
        if(ans) break;
    }
    cout << ans << endl;

}

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

using namespace std;

int main(void){
  int N, Q;
  cin >> N >> Q;
  vector<vector<int>> tree(N+1, vector<int>(1, 0));
  int i;

  //木の作成
  int s, g;
  for(i=1; i<=N-1; i++){
    cin >> s >> g; 
    tree[s].push_back(g);
    tree[g].push_back(s);
  }

  //カウンターの初期化
  int p, x;
  vector<int> counter(N+1, 0);
  for(i=1; i<=Q; i++){
    cin >> p >> x;
    counter[p] += x;
  }

  //頂点iを探索済みかどうかを格納するvector
  vector<bool> visit(N+1, false);
  visit[0] = true;

  //次に探索する頂点を入れていくキュー
  queue<int> q;
  q.push(1);

  int now, next;
  while(q.empty() == 0){
    //今訪れている頂点を保持
    now  = q.front();
    //頂点nowを探索済みにする
    visit[now] = true;
    q.pop();
    
    //頂点nowに接続されている頂点を全て見る
    for(i=1; i<tree[now].size(); i++){
      next = tree[now][i];
      //次に訪れる頂点nextが未探索であれば処理をする
      if(visit[next] == false){
	counter[next] += counter[now];
	//未探索の頂点をキューに追加
	q.push(next);
      }
    }
  }

  for(i=1; i<=N; i++)
    cout << counter[i] << " ";
  cout << endl;
  
  return 0;
}


Measured memory_bytes: 15608
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class Program
{
    static void Main()
    {
        var ND = ReadLine().Split().Select(int.Parse).ToArray();
        var N = ND[0];
        var D = ND[1];
        var X = new long[N][];

        for (int i = 0; i < N; i++)
        {
            X[i] = ReadLine().Split().Select(long.Parse).ToArray();
        }

        var ans = 0;
        for (int i = 0; i < N; i++)
        {
            for (int j = i + 1; j < N; j++)
            {
                var d = dist(X[i], X[j]);
                var k = (long)Sqrt(d);
                if (k * k == d) ans++;
            }
        }
        WriteLine(ans);
    }

    static long dist(long[] x, long[] y)
    {
        var ans = 0L;
        for (int i = 0; i < x.Length; i++)
        {
            var k = x[i] - y[i];
            ans += k * k;
        }

        return ans;
    }
}


Measured memory_bytes: 13396
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
#![macro_use]

use std::cmp::*;
use std::collections::*;
use std::io::prelude::*;
use std::mem::*;
use std::num::*;
use std::slice::*;

const MOD: isize = 1_000_000_007;

fn main() {
    let mut x: isize = read();

    let amari: isize = x % 500;
    let mut ans: isize = 0;
    ans += x / 500 * 1000;
    ans += amari / 5 * 5;
    println!("{}", ans);
}
fn read<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let next: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    next.parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int solve(int n, vector<int> &coins, vector<int> &memo) {
  if (n == 0) {
    return 0;
  }

  if (memo[n] != -1) {
    return memo[n];
  }

  int min_cnt = n + 1;
  for (auto coin : coins) {
    if (n < coin) {
      continue;
    }

    min_cnt = min(min_cnt, 1 + solve(n - coin, coins, memo));
  }

  return memo[n] = min_cnt;
}

int main(int argc, const char *argv[])
{
  int n, m;
  cin >> n >> m;

  vector<int> coins(m);
  vector<int> memo(n + 1, -1);
  for (int i = 0; i < m; i++) {
    cin >> coins[i];
  }

  cout << solve(n, coins, memo) << "\n";
  return 0;
}


Measured memory_bytes: 7008
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <cstring>
#include <cmath>
#include <iomanip>
#include <sstream>

#define fi first
#define se second
#define pb push_back
#define fore(i, a, b) for (int i = (a), _b = (b); i < (_b); ++i)
#define fort(i, a, b) for (int i = (a), _b = (b); i <= (_b); ++i)
#define ford(i, a, b) for (int i = (a), _b = (b); i >= (_b); --i)

using namespace std;

typedef long long LL;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;

const int INF = 1e9 + 3;
const int MOD = 1e9 + 7;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n, m; cin >> n >> m;
    priority_queue<int> pq;
    int x; fort(i, 1, n) {
        cin >> x;
        pq.push(x);
    }
    fort(i, 1, m) {
        int u = pq.top(); pq.pop();
        pq.push(u /= 2);
    }
    LL sum = 0;
    while (!pq.empty()) {
        sum += pq.top(); pq.pop();
    }
    cout << sum << '\n';
    return 0;
}


Measured memory_bytes: 892
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>

using namespace std;

const int INF = 1 << 29;

vector<int> a;
vector<int> memo1(1000005, -1);
vector<int> memo2(1000005, -1);

int dfs1(int s)
{
	if(s == 0) return 0;

	if(memo1[s] != -1) {
		return memo1[s];
	}

	int res = INF;

	for(int i = a.size() - 1; i >= 0; --i) {
		if(s - a[i] >= 0) {
			res = min(res, dfs1(s - a[i]) + 1);
		}
	}

	return memo1[s] = res;
}

int dfs2(int s)
{
	if(s == 0) return 0;

	if(memo2[s] != -1) {
		return memo2[s];
	}

	int res = INF;

	for(int i = a.size() - 1; i >= 0; --i) {
		if(s - a[i] >= 0 && (a[i] & 1)) {
			res = min(res, dfs2(s - a[i]) + 1);
		}
	}

	return memo2[s] = res;
}

int main()
{
	int n;

	for(int i = 1; i * (i + 1) * (i + 2) / 6 < 1000004; ++i) {
		a.push_back(i * (i + 1) * (i + 2) / 6);
	}

	//cout << a.size() << endl;

	while(cin >> n, n) {
		cout << dfs1(n) << ' ' << dfs2(n) << endl;
	}
}

Measured memory_bytes: 10480
#!/usr/bin/env python3
import sys


def solve(x: int):
    return 1 if x == 0 else 0


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    x = int(next(tokens))  # type: int
    print(solve(x))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()


Measured memory_bytes: 9160
#include<stdio.h>
#include<cstdio>
#include<algorithm>
using namespace std;

long gcd(long a, long b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}

int main() {
  int N;
  scanf("%d", &N);
  long T[N];
  for (int i=0 ; i<N ; i++) {
    scanf("%ld", &T[i]);
  }
  long res=T[0];
  long max_num, min_num, gcd_num;
  for (int i=1 ; i<N ; i++) {
    max_num = max(T[i], res);
    min_num = min(T[i], res);
    gcd_num = gcd(max_num, min_num);
    res = max_num/gcd_num;
    res *= min_num;
  }
  printf("%ld\n", res);
}

Measured memory_bytes: 128
//2020-08-30, Sun

#include<iostream>
using namespace std;

int main(){
    int a, b, c, x, ans = 0;
    cin >> a >> b >> c >> x;
    
    for (int i = 0; i <= a; i++) {
        for (int j = 0; j <= b; j++) {
            for (int k = 0; k <= c; k++) {
                if (i * 500 + j * 100 + k * 50 == x) ans++;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3600
$n=<>;
@h=glob<>;
print+&f(@h);

sub f{
    my @a = @_;
    my $i=0;
    my $div=0;
    my @l;
    my @r;
    shift(@a) while($a[0]==0&&$#a>0);
    pop(@a) while($a[$#a]==0&&$#a>0);
    return $a[0] if ($#a==0);
    foreach(@a){
        if ($_==0){
            @l=@a[0..$i-1];
            @r=@a[$i+1..$#a];
            $div=1;
            last;
        }
        $i++;
    }
    if ($div==0){
        $_-- for(@a);
        return 1+&f(@a);
    }else{
        return &f(@l)+&f(@r);
    }
}

Measured memory_bytes: 1280
S = input()
Q = int(input())

rev = False
head = []
tail = []
for _ in range(Q):
    q = input()
    if q[0] == '1':
        rev = not rev

    else:
        _, f, c = q.split()
        if (f == '1') ^ rev:
            head.append(c)
        else:
            tail.append(c)
ans = ''.join(reversed(head)) + S + ''.join(tail)
if rev:
    ans = ans[::-1]
print(ans)

Measured memory_bytes: 6252
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<bitset>
#define ld long double
#define ll long long int
#define ull unsigned long long int
#define rep(i,n) for(i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define INF INT_MAX
#define vi vector<int>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define vvc vector<vector<char> >
#define vvs vector<vector<string> >
#define P 1000000007
using namespace std;
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 long long LLINF=1LL<<60;
//set<int>::iterator it;
//|\_
//g++ -std=c++1z temp.cpp
//./a.out



int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
    
    string s,t,u;
    int sn,tn,un;
    int i,n,ans,N;
    vector<int> v;
    set<int> st;
    while(1){
        cin>>s>>N;
        if(s=="0"&&N==0)break;
        rep(i,s.length()-N)s='0'+s;
        st.clear();
        v.clear();
        ans=0;
        n=atoi(s.c_str());
        st.insert(n);
        v.push_back(n);
        while(1){
            while(s.length()<N)s='0'+s;
            t=s;
            u=s;
            sort(t.begin(),t.end());
            sort(u.rbegin(),u.rend());
            n=atoi(u.c_str())-atoi(t.c_str());
            if(st.find(n)!=st.end()){
                rep(i,v.size()){
                    if(v[i]==n){
                        cout<<i<<" ";
                        cout<<n<<" ";
                        cout<<v.size()-i<<endl;
                        break;
                    }
                }
                break;
            }
            else {
                st.insert(n);
                v.push_back(n);
            }
            s="";
            while(n>0){
                s+=n%10+'0';
                n/=10;
            }
            s.reserve();
            ans++;
        }
        // rep(i,v.size())cout<<v[i]<<" ";
    }
    
//////////////////////////////////////////////////////
return 0;}








Measured memory_bytes: 3204
#include<bits/stdc++.h>
#define mp make_pair
#define fi first
#define se second
#define VAL 100000
#define ll long long
#define INF 10000000000000000LL
#define pll pair<long long , long long>
const int MAX=1e5+10;
const int MOD=1e9+7;
const int TOT_PRIMES=19;
const int MAX_A=70;
using namespace std;
ll dp[200][MAX];
int main() 
{ 
	//ios_base::sync_with_stdio(false);
  //  cin.tie(NULL);	
//	#ifndef ONLINE_JUDGE
//	freopen("inp.txt" ,"r", stdin );
//	freopen("out.txt", "w", stdout);
//	#endif
	ll n ,w ;
	cin>>n>>w;
	ll cost[n+1] , wt[n+1];
	memset(dp ,  0 , sizeof(dp));
	for(int i=1;i<=n;i++)
		cin>>wt[i]>>cost[i];
	for(int i=1;i<=n;i++){
		for(int j=1;j<=w;j++){
			if(j-wt[i]>=0){
			dp[i][j]=max(dp[i-1][j] , dp[i-1][j-wt[i]]+cost[i]);}
			else
				dp[i][j]=dp[i-1][j];
		
		}
	}
	cout<<dp[n][w];
	
}

Measured memory_bytes: 156544
import math
def num():
    return map(int , input().split())
def nu():
    return int(input())
def li():
    return input().split()
def sli():
    return list(map(str, input().split()))
def lli ():
    return list (map(int, input ().split ()))
def fli():
    return [float(x) for x in input().split()]

n = nu()
a = lli()

a.sort()
if(a[0] == 0):
    print(0)
else:
    ans = 1
    xx = 1000000000000000000
    for i in range (n):
        ans = ans * a[i]
        if(ans > xx):
            ans = -1;
            break
    print(ans)


Measured memory_bytes: 22548
#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0; i<n; i++)
#define Rep(i,n) for(long long i=1; i<n; i++)
#define ll long long
#include <math.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <vector>


using namespace std;
#define PI acos(-1)
using P =pair<int,int>;

ll ketasu(ll a){
   ll num=1;
   while(a/10){
       num++;
       a/=10;
   }
   return num;
}

ll gcd(ll a,ll b){return b ? gcd(b,a%b) :a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

ll kosuu(ll a){
    ll sum=0;
    for(ll i=1;i*i<=a;i++){
        if(a%i==0){
            if(a!=1&&i*i!=a){
            sum+=2;
            }else{
             sum++;   
            }
        }
    }
    return sum;
}

ll sum(ll l,ll r){
    return(l+r)*(r-l+1)/2;
}

int main(){

ll n;cin>>n;
vector<P>p(n);
rep(i,n)cin>>p[i].second>>p[i].first;
sort(p.begin(),p.end());
ll sum=0;
bool ok=true;
for(auto x:p){
    sum+=x.second;
    if(x.first<sum){
    ok =false;
    break;
    }
}
cout<<(ok ? "Yes":"No")<<endl;

}



Measured memory_bytes: 4828
//Jai Shree Krishna
#include <bits/stdc++.h>
using namespace std;
#define PI acos(-1)
#define MOD (ll)1000000007
#define pii pair<long long ,long long >
#define ll  long long int
#define loop(i,n) for(ll i=0;i<n;i++)
#define loop2(i,n) for(ll i = 1;i<=n;i+=1)
#define pb push_back
#define mp make_pair
#define EPS 1e-8
void display(vector<int> v1){loop(i,v1.size()){cout<<v1[i]<<" ";}cout<<endl;}
ll dx[8] = {0,1,0,-1,1,1,-1,-1};
ll dy[8] = {1,0,-1,0,1,-1,1,-1};


long long int n,A,B,C,D;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>A>>B>>C>>D;
    for(long long int m = 0 ;m<=n-1;m+=1)
    {
        if(B-A>=C*(n-1-m) - D*m && -C*m +(n-1-m)*D>=(B-A))
        {
            cout<<"YES";
            return 0;
        }
    }
    cout<<"NO";
    return 0;
}

Measured memory_bytes: 256
n=int(input())
A=list(map(int,input().split()))
for i in range(n):
    A[i]-=(i+1)
# print(A)
A.sort()
if len(A)%2==1:
    num = A[len(A)//2]
else:
    num = (A[len(A)//2] + A[len(A)//2-1]) // 2
for i in range(n):
    A[i]-=num
for i in range(n):
    A[i]=abs(A[i])

print(sum(A))



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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    int N, K; cin >> N >> K;
    vec a(N); rep(i, N) cin >> a[i];

    cout << (N-1 + K-2)/(K-1) << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,29)-1;


int main() {
  string S; cin >> S;
  int result = 0;
  rep(i, S.length()) if (S[i]=='1') result++;
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <limits.h>
#include <cmath>
#include <queue>
#include <map>
#include <iomanip>
#include <random>
#include <fstream>
#define rep(i, n) for (int i = 0; i < n; i++)
#define pi 3.14159265358979323846
using namespace std;
typedef long long ll;

ll gcd(ll a, ll b)
{
  ll r;
  while ((r = a % b))
  {
    a = b;
    b = r;
  }
  return b;
}

int main()
{

  int a,b,c; cin >> a >> b >> c;
  if (a*b%2!=0){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


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

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define ALL(a) (a).begin(),(a).end()
#define DEBUG(a) "(" << #a << ": " << (a) << ")"

template<typename T>
void chmin(T &x, T y) { x = min(x, y); }

template<typename T>
void chmax(T &x, T y) { x = max(x, y); }

typedef long long int lli;
typedef long double ld;
typedef tuple<int,string,int> Tr;

const int INF = INT_MAX/2 - 1;
const double EPS = 1e-14;
const int dx[4] = {0, 1, 0, -1}; // {-1,  0,  1, -1, 1, -1, 0, 1};
const int dy[4] = {1, 0, -1, 0}; // {-1, -1, -1,  0, 0,  1, 1, 1};

string solve(vector<Tr> table, int wy) {
  auto iter = lower_bound(ALL(table), make_tuple(wy, "ZZZZZZ", INF), greater<Tr>());
  if (iter == table.end()) { return "Unknown"; }
  string name; int start, limit;
  tie(start, name,limit) = *iter;
  int ey = wy - start;
  if (wy > limit) return "Unknown";
  return name + " " + to_string(ey);
}

int main() {
  cout << fixed << setprecision(10);
  int N, Q;
  while (cin >> N >> Q and N) {
    vector<Tr> table;
    REP(i, N) {
      string name; int eyear, wyear;
      cin >> name >> eyear >> wyear;
      table.emplace_back(wyear - eyear, name, wyear);
    }
    sort(ALL(table), greater<Tr>());
    REP(i, Q) {
      int wyear;
      cin >> wyear;
      cout << solve(table, wyear) << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3216
N,K = (int(x) for x in input().split())
A = [int(x) for x in input().split()]

#print(N)
#print(K)
#print(A)

preX = 0
nowX = 1

for i in range(K+1,N+1):
#  print(str(i)+'学期')
#  if i == K:
#    for x in range(K):
#      nowX *= A[x]
#  else:
#    nowX = int(preX / A[i-K-1]) * A[i-1]
#    print(str(preX) +', '+ str(nowX))
#    if preX < nowX:
#      print('Yes')
#    else:
#      print('No')
#  preX = nowX

  if A[i-K-1] < A[i-1]:
    print('Yes')
  else:
    print('No')


Measured memory_bytes: 31572
// AOJ 2581 Derangement
// 2018.3.9 bal4u

#include <stdio.h>
#include <string.h>

#define QMAX 10000
typedef struct { int t, s; } QUE;
QUE que[QMAX]; int qsize;

#define PARENT(i) ((i)>>1)
#define LEFT(i)   ((i)<<1)
#define RIGHT(i)  (((i)<<1)+1)

void min_heapify(int i)
{
	int l, r, min;
	QUE qt;

	l = LEFT(i), r = RIGHT(i);
	if (l < qsize && que[l].t < que[i].t) min = l; else min = i;
	if (r < qsize && que[r].t < que[min].t) min = r;
	if (min != i) {
		qt = que[i], que[i] = que[min], que[min] = qt;
		min_heapify(min);
	}
}

void deq()
{
	que[0] = que[--qsize];
	min_heapify(0);
}

void enq(int s, int t)
{
	int i, min;
	QUE qt;

	i = qsize++;
	que[i].s = s, que[i].t = t;
	while (i > 0 && que[min = PARENT(i)].t > que[i].t) {
		qt = que[i], que[i] = que[min], que[min] = qt;
		i = min;
	}
}

#define INF 0x10101010
#define MAX 205
typedef struct { int to, rev; int cap, cost; } EDGE;
EDGE edge[MAX][MAX]; int hi[MAX];
int V;				// 頂点数
int potential[MAX], dist[MAX], prevv[MAX], preve[MAX];

void add_edge(int from, int to, int cap, int cost)
{
	int f, t;
	EDGE *ep;

	f = hi[from]++, t = hi[to]++;
	ep = &edge[from][f], ep->to = to, ep->cap = cap, ep->cost = cost, ep->rev = t; 
	ep = &edge[to][t], ep->to = from, ep->cap = 0, ep->cost = -cost, ep->rev = f;
}

int minCostFlow(int S, int T, int F)
{
	int i, v, nv, t, nt, ret;
	EDGE *ep;

	ret = 0;
//	memset(potential, 0, V << 2);
  
	while (F > 0) {
		memset(dist, INF, V << 2);
		qsize = 0;
		dist[S] = 0;
		enq(S, 0);
		while (qsize) {
			v = que[0].s, t = que[0].t, deq();
			if (dist[v] < t) continue;
			for (i = 0; i < hi[v]; i++) {
				ep = &edge[v][i];
				if (ep->cap <= 0) continue;
				nv = ep->to;
				nt = t + ep->cost - potential[nv] + potential[v];
				if(dist[nv] > nt) {
					dist[nv] = nt;
					prevv[nv] = v, preve[nv] = i;
					enq(nv, nt);
				}
			}
		}
		if (dist[T] == INF) return -1;
		for (v = 0; v < V; v++) potential[v] += dist[v];

		t = F;
		for (v = T; v != S; v = prevv[v]) {
			ep = &edge[prevv[v]][preve[v]];
			if (t > ep->cap) t = ep->cap;
		}
		F -= t;

		ret += t * potential[T];
		for (v = T; v != S; v = prevv[v]) {
			ep = &edge[prevv[v]][preve[v]];
			ep->cap -= t;
			edge[v][ep->rev].cap += t;
		}
	}
	return ret;
}

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = 10*n + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

#define ABS(a)    ((a)>=0?(a):-(a))
int p[102];

int main()
{
	int n, i, j;
	int source, sink;

	n = in();
	source = n << 1, sink = source+1, V = sink+1;

	for (i = 0; i < n; i++) p[i] = in();

	for (i = 0; i < n; i++) add_edge(source, i, 1, 0);
	for (i = 0; i < n; i++) for (j = 0; j < n; j++) if (p[i] != j+1)
		add_edge(i, n+j, 1, ABS(i-j)*p[i]);
	for (i = 0; i < n; i++) add_edge(n+i, sink, 1, 0);

	printf("%d\n", minCostFlow(source, sink, n));
	return 0;
}


Measured memory_bytes: 2512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n,i,ans = 0;scanf("%lld",&n);
  pair<ll,ll> p[n];
  for(i=0;i<n;i++) scanf("%lld%lld",&p[i].first,&p[i].second);
  for(i=n-1;i>=0;i--){
    p[i].first += ans;
    ans += ((p[i].first%p[i].second) ? p[i].second-p[i].first%p[i].second:0);
  }
  printf("%lld\n",ans);
}

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

int main(){
	int k, n;
	cin >> k >> n;
	
	//距離配列作成	
	int tmp;
	int dis[n]={0};
	cin >> dis[0];
  int pre=dis[0];
	for(int i=1; i<n; i++){
		cin >> tmp;
		dis[i]=tmp-pre;
    pre = tmp;  
	}  
	dis[n]=k-pre;
	
 	//距離計算
	int ans;
	int now=k;
	for(int i=1; i<n; i++){
		ans=k-dis[i];
		if(ans<now) now=ans; 
	}
	ans=k-dis[0]-dis[n];
	
	//解を出力
	cout << min(ans, now) << endl;
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main()
{
    int n;
    while (~scanf("%d", &n))
    {
        int cnte = 0, cnt4 = 0, cnt2 = 0;
        for (int i = 1; i <= n; i++)
        {
            int num;
            scanf("%d", &num);
            if (num % 2) cnte++;
            else if (num % 4) cnt2++;
            else cnt4++;
        }
        if (cnt2 == 0)
        {
            if (cnt4 >= cnte - 1)printf("Yes\n");
            else printf("No\n");
        }
        else if(cnt4>=cnte)printf("Yes\n");
        else printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;

int m,n;
int map[100][100];
int dp[100][100];

int inf = 10000000;

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

int solve(int y,int x,int d){
  map[y][x] = 0;
  int ret = 0;
  for(int i = 0;i<4;i++){
    int nx = x + dx[i];
    int ny = y + dy[i];
    if(nx >= 0 && nx < m && ny >= 0 && ny < n && map[ny][nx] == 1)
      ret = max(ret,solve(ny,nx,d+1));
  }
  map[y][x] = 1;

  return max(ret,d);
}

int main(){
  while(cin>>m){
    cin>>n;
    if(n==0&&m==0)
      break;
    for(int i = 0;i<n;i++){
      for(int j = 0;j<m;j++){
	cin>>map[i][j];
      }
    }
    int ans = -1;
    for(int i = 0;i<n;i++){
      for(int j = 0;j<m;j++){
	if(map[i][j] == 1){
	  //cout<<"a"<<endl;]
	  //cout<<i<<"\t"<<j<<endl;
	  ans = max(ans,solve(i,j,0)+1);
	  // cout<<ans<<endl;
	  //	  memset(dp,-1,sizeof(dp));
	}
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for(int i = a; i <b; i++)
using pii = pair<int,int>;
#define all(a) a.begin(), a.end()

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 MOD = 1e9 + 7;

map<long long, int> prime_factor(long long n){
    map< long long, int> ret;

    for(long long i = 2; i * i <= n; i++){
        while(n % i == 0){
            ret[i]++;
            n /= i;
        }
    }

    if( n != 1) ret[n] = 1;
    return ret;
}

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main(){
    int N; cin >> N;
    vector<int> A(N);
    map<ll,int> mp;
    rep(i, 0, N) cin >> A[i];

    //ll lis = A[0];
    rep(i, 0, N){
        map<ll,int> tmp = prime_factor(A[i]);
        for(auto e: tmp){
            if(mp[e.first] < e.second) mp[e.first] = e.second;
        }
    }
    ll lis = 1, ans = 0;
    for(auto e: mp){
        lis *= modpow(e.first, e.second, MOD);
        lis %= MOD;
    }

    rep(i, 0, N){
        ans += lis * modinv(A[i], MOD);
        ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 896
#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);
    }
    vector<int> costs(n);
    costs.at(0) = 0;
    for (int i = 1; i < n; i++) {
        if (i == 1) {
            costs.at(1) = abs(h.at(1) - h.at(0));
        } else {
            costs.at(i) = min(abs(h.at(i) - h.at(i-1)) + costs.at(i-1), abs(h.at(i) - h.at(i-2)) + costs.at(i-2));
        }
    }
    cout << costs.at(n-1) << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N;
int A[MAX_N];

void solve() {
	cin >> N;
	rep(i, 0, N) {
		cin >> A[i];
	}
	sort(A, A + N);
	int m1 = A[N - 1];
	int m2 = -1, val = inf;
	
	if(N % 2 == 0) {
		rep(i, 0, N - 1) {
			int tmp = abs(A[i] - m1 / 2);
			if(val > tmp) {
				val = tmp;
				m2 = A[i];
			}
		}
	}
	else {
		rep(i, 0, N - 1) {
			int tmp = min(abs(A[i] - m1 / 2), abs(A[i] - m1 / 2 - 1));
			if(val > tmp) {
				val = tmp;
				m2 = A[i];
			}
		}
	}

	cout << m1 << " " << m2 << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
string s;
long long k;
long long a[10];
int main()
{
    cin>>s;
    scanf("%lld",&k);
    string tmp=s+s+s;
    for(int i=1;i<tmp.size();i++){
        if(tmp[i]==tmp[i-1]){
            tmp[i]='.';
            a[(i/s.size())]++;
        }
    }
    k--;
    long long ans=a[0];
    ans+=(k+1)/2*a[1];
    ans+=k/2*a[2];
    printf("%lld",ans);
    return 0;
}


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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    string s,t;
    cin >> s >> t;
    ll ans = 1e9;
    ll n = t.size();
    for(i = 0;i < s.size();++i){
        if(i + n - 1 >= s.size()) continue;
        else{
            ll tmp = 0;
            for(j = i;j < i + n;++j){
                if(s.at(j) != t.at(j - i)) ++tmp;
            }
            ans = min(ans, tmp);
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3632
count = 0

def merge(A, left, mid, right):
    global count
    L = A[left: mid]
    R = A[mid: right]
    L.append(10e9 + 1)
    R.append(10e9 + 1)
    i, j = 0, 0
    for k in range(left, right):
        count += 1
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1

def merge_sort(A, left, right):
    if left + 1 < right:
        mid = int((left + right)/2)
        merge_sort(A, left, mid)
        merge_sort(A, mid, right)
        merge(A, left, mid, right)

n = int(input())
S = list(map(int, input().split(' ')))

merge_sort(S, 0, n)
print(' '.join(list(map(str, S))))
print(count)


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

#define watch(x) cout<<#x<<" -> "<<x<<endl
#define ALL(x) x.begin() , x.end()
#define INF 100000

typedef long long ll;

using namespace std;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s;
    long long n , arr[200001] ,sum = 0 ;
        cin>>n;
        for (int i = 1; i<=n ;i++)
            cin>>arr[i];
        for (int i = 1;i<n ;i ++){
            if (arr[i]>arr[i + 1]){
                sum = sum +(arr[i] - arr[i + 1]);
                arr[i+1] = arr[i];
            }
        }
    cout<<sum<<endl;

}



Measured memory_bytes: 5140
#include <iostream>
#include <algorithm>
#ifdef _MSC_VER
#include <conio.h>
#else
#define getch()
#endif

using namespace std;

int main(){
	int n=0;
	bool ans[8]={};
	int res=0;
	int sp=0;
	int st[8]={399,799,1199,1599,1999,2399,2799,3199};
	cin >> n;
	for(int i=0;i<n;i++){
		int temp=0;
		cin >> temp;
		if(temp>=3200){
			sp++;
			continue;
		}
		for(int j=0;j<8;j++){
			if(temp<=st[j]){
				if(ans[j]==false){
					res++;
					ans[j]=true;
				}
				break;
			}
		}
	}
	cout << max(res,1) << " " << res+sp << endl;
	getch();
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
	int a,b;
	scanf("%d %d",&a,&b);
	if(a>=13)
		printf("%d\n",b);
	else if(a>=6)
		printf("%d\n",b/2);
	else if(a>=0)
		printf("0\n");
	return 0;

}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n;
    scanf("%lld",&n);
    ll *a = new ll[n];
    for(ll i=0;i<n;i++)
    {
        scanf("%lld",&a[i]);
    }
    ll *dp =new ll[n];
    dp[0] = 0;
    dp[1] = abs(a[1]-a[0]);
    for(ll i=2;i<=n;i++)
    {
        dp[i] = min(dp[i-2]+abs(a[i]-a[i-2]),dp[i-1]+abs(a[i]-a[i-1]));
    }
    printf("%lld\n",dp[n-1]);
}


Measured memory_bytes: 1792