akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

int const N = 1e5 + 100;
long long a[N], b[N], A, B, Q;

long long dist1(long x,long y){
    long long d = abs(x - y);
    
    int z = lower_bound(b, b + B + 1, y) - b;
    
    return min(abs(y - b[z]) + d, abs(y - b[z - 1]) + d);
}

long long dist2(long x,long y){
    long long d = abs(x - y);
    
    int z = lower_bound(a, a + A + 1, y) - a;
    
    return min(abs(y - a[z]) + d, abs(y - a[z - 1]) + d);
}

int main() {
    
    cin >> A >> B >> Q;
    for(int i = 1;i <= A;++i)
        cin >> a[i];
    
    for(int i = 1;i <= B;++i)
        cin >> b[i];
    
    a[0] = b[0] = -1e18;
    a[A + 1] = b[B + 1] = 1e18;
    
    for(int i = 1;i <= Q;++i){
        int y, z;
        long long x;
        cin >> x;
        y = lower_bound(a, a + A + 1, x) - a;
        z = lower_bound(b, b + B + 1, x) - b;
        
        long long mn = 8e18;
        
        mn = min(mn, dist1(x, a[y]));
        mn = min(mn, dist1(x, a[y-1]));
        mn = min(mn, dist2(x, b[z]));
        mn = min(mn, dist2(x, b[z-1]));
        
        cout << mn << endl;
    }
    return 0;
}

Measured memory_bytes: 2944
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <set>
#include <queue>
#include <stack>
using namespace std;
typedef long long int ll;

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

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define drep(i, n) for(int i = n - 1; i >= 0; i--)

const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

int main() {
  ll x;
  cin >> x;
  ll now = 100;

  rep (i, 100000) {
    now = now + now / 100;
    if (now >= x) {
      P(i + 1);
      return 0;
    }
  }
  return 0;
}

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

#define pb push_back

typedef long long ll;

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

	int k;
	string s;
	cin >> k >> s;
	
	if (s.length() <= k) {
		cout << s << endl;
	} else {
		cout << s.substr(0, k) << "..." << endl;
	}
	
    return 0;
}

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

using namespace std;

int main(){
  int N, H;
  cin >> N >> H;
  vector<int> b(N);
  int amax = 0;
  for(int i=0;i<N;i++){
    int a;
    cin >> a >> b[i];
    amax = max(a, amax);
  }
  sort(b.begin(), b.end(), greater<int>());
  int ans = 0;
  for(auto&& x:b){
    if(H <= 0)break;
    if(x <= amax)break;
    H -= x;
    ans++;
  }
  if(H > 0)ans += (H + amax - 1) / amax;
  cout << ans << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstddef>
#include<queue>
#include<math.h>
#include<iomanip>
using namespace std;

int main()
{
    string s, ans = "AC";
    cin >> s;
    int cnt = 0;
    if(s.at(0) != 'A'){
        ans = "WA";
    }
    else{
        for(int i = 1; i < s.size(); ++i){
            if(isupper(s.at(i))){
                if(i == 1 || i == s.size() - 1 || s.at(i) != 'C'){
                    ans = "WA";
                }
                cnt++;
            } 
        }
        if(cnt != 1) ans = "WA";
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3564
#![allow(unused_mut, non_snake_case, unused_imports, dead_code)]

use std::iter;
use std::cmp::{max, min, Ordering};
use std::mem::swap;
use std::collections::{HashMap, BTreeMap, HashSet, BTreeSet, BinaryHeap, VecDeque};
use std::iter::FromIterator;

//　高速 EOF要
//macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();input_inner!{iter, $($r)*}};($($r:tt)*) => {let mut s = {use std::io::Read;let mut s = String::new();std::io::stdin().read_to_string(&mut s).unwrap();s};let mut iter = s.split_whitespace();input_inner!{iter, $($r)*}};}
//macro_rules! input_inner {($iter:expr) => {};($iter:expr, ) => {};($iter:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($iter, $t);input_inner!{$iter $($r)*}};}
//macro_rules! read_value {($iter:expr, ( $($t:tt),* )) => {( $(read_value!($iter, $t)),* )};($iter:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()};($iter:expr, chars) => {read_value!($iter, String).chars().collect::<Vec<char>>()};($iter:expr, usize1) => {read_value!($iter, usize) - 1};($iter:expr, $t:ty) => {$iter.next().unwrap().parse::<$t>().expect("Parse error")};}
// 低速 EOF不要
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, usize1) => {read_value!($next, usize) - 1};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

// 非常時
fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

fn main() {
    input!(A:i32,B:i32);
    println!("{}",if B%A==0{A+B}else{B-A});
}

Measured memory_bytes: 4352
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#define ALL(a)  (a).begin(),(a).end()
using namespace std;

int main(){
    int n, rn = 0, bn = 0;
    string s;

    cin >> n >> s;

    for(int i = 0; i < n; i++){
        if(s[i] == 'R'){
            rn++;
        }else{
            bn++;
        }
    }

    if(rn > bn){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
	int a[4];
	for(int i=0;i<3;i++)
		cin>>a[i];
	sort(a,a+3);
	int sum=a[2]*10+a[1]+a[0];
	cout<<sum;
	return 0;		
} 

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

int main() {
  int x, y, ans = 0;
  cin >> x >> y;
  if (x <= 3) ans += 100000 * (4 - x);
  if (y <= 3) ans += 100000 * (4 - y);
  if (ans == 600000) ans += 400000;
  cout << ans << endl;
}


Measured memory_bytes: 764
#include <iostream>
#include <cmath>
using namespace std;
int N,M,A[51],B[51],C[51],D[51];

int main(){
  cin >> N >> M;
  for(int i=1;i<=N;i++){
   	cin >> A[i] >> B[i];
  }
  for(int i=1;i<=M;i++){
    cin >> C[i] >> D[i];
  }
  for(int i=1;i<=N;i++){
    int ans = -1,dist = 1e9;
    for(int j=1;j<=M;j++){
      if(dist>abs(A[i]-C[j])+abs(B[i]-D[j])){
  		ans = j;
        dist = abs(A[i]-C[j])+abs(B[i]-D[j]);
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
inputs = gets.chomp.split
nums = Array.new
pos = 0

inputs.each do |input|
   pos += 1

   if input == "+" || input == "-" || input == "*"
      n = input
      a = nums.pop
      b = nums.pop
      case n
      when "+"
         sum = b + a
      when "-"
         sum = b - a
      when "*"
         sum = b * a
      end
      nums.push sum
      pos = nums.count
   else
      n = input.to_i
      nums.push n
   end

end

puts nums[0]

Measured memory_bytes: 8692
while True:
    a,b=map(int,input().split())
    if a==0 and b==0:
        break
    for i in range(a):
        for j in range(b):
            if (i+j)%2==0:
                print("#",end="")
            else:
                print(".",end="")
        print()
    print()


Measured memory_bytes: 7004
// 2019/06/25
// AtCoder Beginner Contest 050 - B

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

int main() {
    int n, m, tsum, p, x, ans;
    cin >> n;
    vector<int> t(n);
    tsum = 0;
    for(int i=0; i<n; i++){
        cin >> t.at(i);
        tsum += t.at(i);
    }
    cin >> m;
    for(int k=0; k<m; k++){
        cin >> p >> x;
        ans = tsum + x - t.at(p-1);
        cout << ans << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  long N,A,B;cin>>N>>A>>B;
  if((B-A)%2==0){cout<<(B-A)/2;return 0;}
  cout<<min((B+1-A)/2+N-B,(B-A+1)/2+A-1);
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,n) for (int i=(n-1);i >= 0;i--)
#define all(v) v.begin(),v.end()
#define sz(v) (int)((v).size())
#define MAX(v) *max_element(all(v))
#define MIN(v) *min_element(all(v))
using namespace std; using ll = long long; using P = pair<int,int>;
using vl = vector<ll>; using vvl = vector<vl>;
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
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;}
const ll INF = 1LL << 60;
const ll mod = 1000000007;
const int dx[8] = {1,0,-1,0,1,1,-1,-1}; const int dy[8] = {0,1,0,-1,1,1,-1,-1};

int main(){
  cin.tie(0); ios::sync_with_stdio(false);
  int r; cin >> r;
  printf("%lf",(double)2*r*3.1415926535);
}

Measured memory_bytes: 3784
#include <bits/stdc++.h>
#define int int64_t
#define rp(i, N) for(int i=0; i<N; i++);
using namespace std;
using pair = pair<int, int>;
using tup  = tuple<int, int, int>;
using vec  = vector<int>;
using vvec = vector<vec>;
const int INF = 100000000;
// " ", ' '

// プロトタイプ宣言
// int myfunc(int, vvec);

// グローバル変数
// int N, M;
// vvec data(N, vec(M));

// 関数：

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int N; cin >> N;
	vec H(N+1), ans(N+1);
	for(int i=0; i<N; i++) cin >> H.at(i);

	int mx = 0;
	ans.at(0) = 0;
	for(int i=1; i<N; i++) {
		if(H.at(i)<=H.at(i-1)) ans.at(i) = ans.at(i-1)+1;
		else ans.at(i) = 0;
	}

	for(int i=0; i<N; i++) {
		if(mx<ans.at(i)) mx = ans.at(i);
	}

	cout << mx << endl;
		
	
}


Measured memory_bytes: 1792
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9;
const ll INF=1e18;
using P=pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n,a[100005]={},ans=1,u=0,d=0;
  cin >> n;
  for(int i=0; i<n; i++) {
    cin >> a[i];
  }
  for(int i=0; i<n-1; i++) {
    if(a[i]<a[i+1]) {
      u=1;
    }
    else if(a[i]>a[i+1]) {
      d=1;
    }
    if(u&&d) {
      ans++;
      u=d=0;
    }
  }
  cout << ans << "\n";
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <memory>
#include <algorithm>
#include <cstring>

using namespace std;

typedef long long ll;

int main() {

    int N;
    ll W;
    cin>>N>>W;

    ll w[110];
    ll v[110];

    for(int i=0; i<N; ++i)
        cin>>w[i]>>v[i];

    vector<vector<ll>> dp;
    dp.resize(N+1);
    for(int i=0; i<=N; ++i)
        dp[i].resize(W+1);


    for(int i=0; i<=W; ++i)
        dp[0][i] = 0;

    for(int i=0; i<N; ++i)
    {
        for(int j=0; j<=W; ++j)
        {
            if(j-w[i]>=0)
            {
                dp[i+1][j] = max(dp[i][j-w[i]]+v[i], dp[i][j]);
            }
            else
            {
                dp[i+1][j] = dp[i][j];
            }
        }
    }

    cout<<dp[N][W]<<endl;


    return 0;
}


Measured memory_bytes: 79488
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
using namespace std;

using INT = long long;
using UINT = unsigned long long;

unsigned gcd(unsigned a, unsigned b) {
	while (1) {
		if (a < b) swap(a, b);
		if (!b) break;
		a %= b;
	}
	return a;
}

const UINT mod = 1000000007;

UINT PowMod(UINT x, UINT y)
{
	if (y == 0)
	{
		return 1;
	}
	else if (y == 1)
	{
		return x % mod;
	}
	else if (y % 2 == 0)
	{
		auto tmp = PowMod(x, y / 2);
		return tmp * tmp % mod;
	}
	else
	{
		auto tmp = PowMod(x, y / 2);
		return (tmp * tmp % mod) * x % mod;
	}
}

UINT getModInv(UINT N)
{
	return PowMod(N, mod - 2);
}

int main()
{
	INT N;
	cin >> N;

	vector<INT> a(N + 1);
	vector<INT> b(N);

	for (size_t i = 0; i < N +1; i++)
	{
		cin >> a[i];
	}
	for (size_t i = 0; i < N; i++)
	{
		cin >> b[i];
	}

	INT ans = 0;
	for (size_t i = 0; i < N; i++)
	{
		if (a[i] <= b[i])
		{
			b[i] -= a[i];
			ans += a[i];
			a[i] = 0;
			if (a[i + 1] <= b[i])
			{
				b[i] -= a[i + 1];
				ans += a[i + 1];
				a[i + 1] = 0;
			}
			else
			{
				a[i + 1] -= b[i];
				ans += b[i];
				b[i] = 0;
			}
		}
		else
		{
			ans += b[i];
		}
	}
	cout << ans << endl;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define For(i, l, r) for (int i = (l); i <= (r); ++i)

typedef long long LL;
typedef pair<int, int> Pii;

const int inf = 0x3f3f3f3f;
const LL infLL = 0x3f3f3f3f3f3f3f3fLL;

const int maxn = 100000 + 5;

int n;
char s[maxn];
int a[maxn];

int main() {
  scanf("%s", s);
  n = strlen(s);
  for (int i = 0; i < n; ++i) {
    int j = i;
    while (j < n && s[j] == 'R') ++j;
    int k = j;
    while (k < n && s[k] == 'L') ++k;
    a[j] += (j - i) / 2, a[j - 1] += (j - i + 1) / 2;
    a[j - 1] += (k - j) / 2, a[j] += (k - j + 1) / 2;
    i = k - 1;
  }
  rep(i, n) printf("%d%c", a[i], " \n"[i == n - 1]);

  return 0;
}

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

#define ll long long
const int maxn=1e5+10;

int main()
{
    ll n,m;
    cin>>n>>m;
    if(n==1&&m==1){cout<<1;return 0;}
    if(n==1){cout<<m-2;return 0;}
    if(m==1){cout<<n-2;return 0;}
    cout<<(n-2)*(m-2);
    return 0;
}

Measured memory_bytes: 256
fun main() {
  val MOD = 1000000007
  val S = readInt()

  val dp = Array(S + 1) { 0 }
  for (i in 3..S) {
    var sum = 0
    for (j in 0..(i - 3)) sum = (sum + dp[j]) % MOD
    dp[i] = sum + 1
  }
  println(dp[S])
}

fun readString() = readLine()!!
fun readStrings() = readString().split(" ")
fun readInt() = readString().toInt()
fun readLong() = readString().toLong()
fun readInts() = readStrings().map { it.toInt() }
fun readLongs() = readStrings().map { it.toLong() }


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

int main() {
	int k, n;
	cin >> k >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	int sum = 0;
	rep(i, n - 1) sum += a[i + 1] - a[i];
	int ans = k - a.back() + a.front();
	sum += ans;
	rep(i, n - 1) ans = max(ans, a[i + 1] - a[i]);
	cout << sum - ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
/* 
*    coder :: ATUL_PANDEY_2608
*        >>> INDIA <<<
*/
using namespace std;

// #define  part ..
#define pb(a) push_back(a)
#define all(a) a.begin(),a.end() 
#define mod 1000000007
#define maxx 200006
#define ll long long 
#define quick    ios_base::sync_with_stdio(NULL),cin.tie(0);
#define listll vector< long long > 
#define listi vector< int> 
#define pii   pair<int , int> 
#define pll pair<long long , long long > 
#define minheap priority_queue<long long , vector< long long >, greater<long long > >
#define rep(i,a,b) for(int i=a;i<b;i++)
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

// end of #define 

// define globals ...


//write function from here ...



int Main(){

   int a,b,d;
   cin>>a>>b>>d;

    int ans =0;

   ans-= a/d;
   ans+= b/d;
   if(a%d==0)
    ans++;

  cout<<ans;


  
  
  
  
  return 0;


}

















int main(){
 quick;

//      #ifndef ONLINE_JUDGE
//   freopen ("input.txt", "r", stdin);
//   freopen ("outt.txt", "w", stdout);
// #endif

 Main();

 return 0;


}

Measured memory_bytes: 3648
n=int(input())
t=0
a=''
al='abcdefghijklmnopqrstuvwxyz'
b=[1]
c=[1]
for i in range(10):
  c.append(c[-1]*26)
  b.append(sum(c))
b.sort(reverse=True)
b.append(1)
c.sort(reverse=True)
c.append(1)
flg=0
i=0
while n>0:
  if flg ==1:
    if n >= b[i]:
      tmp=0
      while n >= b[i] and tmp <26:
        n -= c[i]
        tmp+=1
      a+=al[tmp-1]
      i+=1
    else:
      a+='a'
      i+=1
  elif n >= b[i]:
    flg=1
    tmp=0
    while n >= b[i] and tmp <26:
      n -= c[i]
      tmp+=1
    a+=al[tmp-1]
    i+=1
  else:
    i+=1
print(a)

Measured memory_bytes: 9144
#include <bits/stdc++.h>
#define For(i, l, r) for(register int i = (l), _end_ = (int)(r); i <= _end_; ++i)
#define Fordown(i, r, l) for(register int i = (r), _end_ = (int)(l); i >= _end_; --i)
#define Set(a, v) memset(a, v, sizeof(a))
using namespace std;

bool chkmin(int &a, int b) {return b < a ? a = b, 1 : 0;}
bool chkmax(int &a, int b) {return b > a ? a = b, 1 : 0;}

inline int read() {
   int x = 0, fh = 1; char ch = getchar();
    for (; !isdigit(ch); ch = getchar() ) if (ch == '-') fh = -1;
    for (; isdigit(ch); ch = getchar() ) x = (x<<1) + (x<<3) + (ch ^ '0');
    return x * fh;
}

int n = 3;
int c[4][4];
int dx[4][4], dy[4][4];

int main () {
	For (i, 1, n)
		For (j, 1, n) {
			cin >> c[i][j];
			dx[i][j] = c[i][j] - c[i - 1][j];
			dy[i][j] = c[i][j] - c[i][j - 1];
		}
	For (j, 1, n - 1)
		For (i, 2, n)
			if (dx[i][j] != dx[i][j + 1]) return puts("No"), 0;
	For (j, 2, n)
		For (i, 1, n - 1)
			if (dy[i][j] != dy[i + 1][j]) return puts("No"), 0;
	puts("Yes");
    return 0;
}


Measured memory_bytes: 256
def inseration_sort(a,n)
    a.each_with_index do |val,key|
          if key != a.size-1
            print val; print " "
          else
            print val; print "\n"
          end
     end
    1.upto(n-1) do |i|
        v = a[i]
        j = i-1
        while j >= 0 && v <= a[j]
            a[j+1] = a[j]
            a[j] = v
            j -= 1
        end
        a.each_with_index do |val,key|
          if key != a.size-1
            print val; print " "
          else
            print val; print "\n"
          end
        end
    end
end


n=gets.chomp.to_i
a=gets.chomp.split(" ").map{|i|i.to_i}

inseration_sort(a,n)


Measured memory_bytes: 6868
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;

int main()
{
    VVI v(3, VI(3));
    VVI a(3, VI(3));
    for (int i = 0; i < 3; i++)
        for (int j = 0; j < 3; j++)
        {
            cin >> v[i][j];
            a[i][j] = 0;
        }

    int n;
    cin >> n;
    string ans = "No";

    for (int k = 0; k < n; k++)
    {
        int t;
        cin >> t;
        for (int i = 0; i < 3; i++)
            for (int j = 0; j < 3; j++)
            {
                if (v[i][j] == t)
                {
                    a[i][j] = 1;
                }
            }
    }

    for (int i = 0; i < 3; i++)
    {
        if (a[i][0] && a[i][1] && a[i][2])
            ans = "Yes";
    }
    for (int i = 0; i < 3; i++)
    {
        if (a[0][i] && a[1][i] && a[2][i])
            ans = "Yes";
    }
    if (a[0][0] && a[1][1] && a[2][2])
        ans = "Yes";
    if (a[0][2] && a[1][1] && a[2][0])
        ans = "Yes";
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() 
{
  int A,B,C,d;
  cin>>A>>B>>C;
  d=B/A;
  if (d>=C)
  {
     cout<<C<<endl;
  }
  else if (d<C)
  {
      cout<<d<<endl;
  }
  
  return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<pll> vpl;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define ZERO(a) memset(a,0,sizeof(a))

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};



bool ok[2510];
bool reachableToN[2510],reachableFromN[2510];
vll to[2510],from[2510];

void dfs(int x){
  if(reachableToN[x])
    return;
  reachableToN[x]=true;
  for(auto t:to[x])
    dfs(t);
  return;
}

void bdfs(int x){
  if(reachableFromN[x])
    return;
  reachableFromN[x]=true;
  for(auto t:from[x])
    bdfs(t);
  return;
}


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

  ll n,m,p;
  cin>>n>>m>>p;
  vector<tuple<ll,ll,ll>> edge;
  REP(i,m){
    ll a,b,c;
    cin>>a>>b>>c;
    a--;
    b--;
    c = -(c-p);
    edge.emplace_back(a,b,c);
    to[a].push_back(b);
    from[b].push_back(a);
  }

  dfs(0);
  bdfs(n-1);
  REP(i,n)ok[i]=reachableToN[i]&&reachableFromN[i];

  //berman
  ll dist[n];
  REP(i,n)dist[i]=INF;
  dist[0]=0;
  bool upd= true;
  ll ans=0;
  ll step=0;
  while(upd){
    upd = false;
    for(auto e:edge){
      ll a,b,c;
      tie(a,b,c)=e;

      if(!ok[a] || !ok[b])
        continue;

      if(dist[b]>dist[a]+c){
        dist[b] = dist[a]+c;
        upd=true;
      }
    }
    step++;
    if(step>n){
      ans=-1;
      cout<<ans<<endl;
      return 0;
    }
  }

  ans = max(-dist[n-1],0LL);
  cout<<ans<<endl;

}


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

string solve(string s,string t){
	int n=s.length(),m=t.length();
	int dp[n+1][m+1];
	
	//cout<<n<<" "<<m<<endl;
	
	for(int i=0;i<=n;i++){
		for(int j=0;j<=m;j++){
			if(i==0 || j==0)
			dp[i][j]=0;
			else if(s[i-1]==t[j-1])
				dp[i][j]=dp[i-1][j-1]+1;
			else
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
		}
	}
	
	/*for(int i=0;i<=n;i++){
		for(int j=0;j<=m;j++){
			cout<<dp[i][j]<<" ";
		}cout<<endl;
	}*/
	
	string lcs="";
	int i=n,j=m;
	while(i>0 && j>0){
		if(s[i-1]==t[j-1]){
			lcs=s[i-1]+lcs;
			i--,j--;
		}else{
			if(dp[i-1][j]>dp[i][j-1])
			i--;
			else
			j--;
		}
	}
//	cout<<lcs<<" "<<dp[n][m]<<endl;
	return lcs;
	
}

int main() {
	// your code goes here
	string s,t;
	cin>>s>>t;
	cout<<solve(s,t);
	return 0;
}

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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define show(x) cout << #x << " = " << x ln
#define dbg(x) cout<<#x"="<<x ln

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > mat;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

ll h, w, ans = linf;

void calch(ll hs) {
	ll sa, sb, sc;
	sa = hs * w;
	// タテ3分割
	sb = (h-hs)/2 * w;
	sc = ((h-hs)-(h-hs)/2) * w;
	if (sb>0 && sc>0) {
		chmin(ans, max(sa, max(sb, sc)) - min(sa, min(sb, sc)));
	}
	// ヨコ2分割
	sb = (h-hs) * (w/2);
	sc = (h-hs) * (w - (w/2));
	if (sb>0 && sc>0) {
		chmin(ans, max(sa, max(sb, sc)) - min(sa, min(sb, sc)));
	}
}

void calcw(ll ws) {
	ll sa, sb, sc;
	sa = h * ws;
	// ヨコ3分割
	sb = (w-ws)/2 * h;
	sc = ((w-ws)-(w-ws)/2) * h;
	if (sb>0 && sc>0) {
		chmin(ans, max(sa, max(sb, sc)) - min(sa, min(sb, sc)));
	}
	// タテ2分割
	sb = (w-ws) * (h/2);
	sc = (w-ws) * (h-(h/2));
	if (sb>0 && sc>0) {
		chmin(ans, max(sa, max(sb, sc)) - min(sa, min(sb, sc)));
	}
}

int main() {
	cin >> h >> w;
	repst(i,1,h-1) calch(i);
	repst(i,1,w-1) calcw(i);
	cout << ans << ln;
}

Measured memory_bytes: 256
import sys

t = set('dream, dreamer, erase, eraser'.split(', '))

def obtainable(s):
  while True:
    for i in range(5, 8):
      if s[-i:] in t:
        s = s[:-i]
        break
    else:
      return False
    if not s:
      return True
    
s = sys.stdin.readline().rstrip()

def main():
  print("YES" if obtainable(s) else "NO")

if __name__ ==  '__main__':
  main()

Measured memory_bytes: 3316
#include<cstdio>

int main(void){
	
	int n=0,s[21]={0};
	
	
	bool r[501][501];
	int h,w,i,j,k,l;
	char c[501][501];
	do{
	scanf("%d%d",&h,&w);
	
	for(i=0;i<h;i++){
			scanf("%s",c[i]);
			for(j=0;j<w;j++){
				if(c[i][j]=='*'){
					r[i][j]=false;
				}else{
					r[i][j]=true;
				}
			}
	}
	for(i=0;i<h;i++){
		r[i][w]=false;
	}
	for(j=0;j<w;j++){
		r[h][j]=false;
	}
	
	
	
	for(i=0;i<h;i++){
	//printf("iok\n");
		for(j=0;j<w;j++){
	//	printf("jok\n");
			if(r[i][j]==true){
	//		printf("kansoku\n");
				int a,b=0;
				while(r[i+b][j]==true){
					a=1;
					while(true){
						l=0;
						
						for(k=i;k<=i+b;k++){
							if(r[k][j+a]==false)l++;
							if(r[k][j+a]==false)break;
						}	
					//printf("i=%d,j=%d,b=%d,a=%d,l=%d\n",i,j,b,a,l);
						if(l!=0||a+j==w){
							if(s[n]<(a)*(b+1)){
							//	printf("i=%d,j=%d,a=%d,b+1=%d\n",i,j,a,b+1);
								s[n]=(a)*(b+1);
							}
						}else{
							a++;
						}
						if(l!=0)break;
					}
					b++;
				}
			}
		}
	}

	n++;
	
	} while(w!=0||h!=0);
	
	for( i=0;i<n-1;i++){
		printf("%d\n",s[i]);
		}
	return 0;
}					
					
					
				

Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(j, m) for (int j = 0; j < (int)(m); j++)
#define rep2(i, l, n) for (int i = l; i < (int)(n); i++)


int main() {
    int N,K;
    cin >> N >> K;
    vector<int> V(N);
    rep(i,N) {
        cin >> V[i];
    }
    sort(V.begin(),V.end());
    reverse(V.begin(),V.end());
    int ans = 0;
    rep(i,K) {
        ans += V[i];
    }
    cout << ans << endl;
}



Measured memory_bytes: 3592
t = input()

s = list(t)

for i in range(len(s)):
    if s[i] == '?':
        if i > 0 and s[i - 1] == 'P':
            s[i] = 'D'
        elif i < len(s) - 1 and s[i + 1] == 'D':
            s[i] = 'P'
        else:
            s[i] = 'D'

print(''.join(s))


Measured memory_bytes: 10824
# ABC 116: B – Collatz Problem
s = int(input())
the_sequence = []
m = 1

while s not in the_sequence:
    the_sequence.append(s)

    if s % 2 == 0:
        s //= 2
    else:
        s = 3 * s + 1
    
    m += 1
    
print(m)

Measured memory_bytes: 2940
#include <iostream>
using namespace std;
using ll = long long;
int main() {
  ll N, K, b, v[100001]{};
  cin >> N >> K;
  while (cin >> N >> b) v[N] += b;
  N = 0;
  while (K > 0) K -= v[++N];
  cout << N << endl;
}


Measured memory_bytes: 4400
#include <bits/stdc++.h>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
using ld = long double;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    ll N, M, i, A[101], sum=0, count=0;

    cin >> N >> M;

    for(i=1; i<=N; i++){
        cin >> A[i];
        sum += A[i];
    }

    for(i=1; i<=N; i++){
        if(A[i]*4*M >= sum) count++;
    }

    if(count>=M) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

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



int main()
{
	int a, b,c,d,e;

	cin >> a >> b;

	int x[40] = {0};

	for (int i = 0; i < a; ++i)
	{
		cin >> c;
		for (int j = 0; j < c; ++j)
		{
			cin >> d;
			x[d]++;
		}
	}
	
	int ans = 0;

	for (int i = 1; i <= b; i++)
	{
		if (x[i] == a )
		{
			ans++;
		}
	}

	cout << ans;


	
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <iterator>
#include <unordered_set>

int main() {
  std::int_fast64_t n;
  std::cin >> n;
  std::vector<std::int_fast64_t> a(n);
  std::copy_n(std::istream_iterator<std::int_fast64_t>(std::cin), n, a.begin());

  std::unordered_set<std::int_fast64_t> colors;
  std::int_fast64_t crowned_count = 0;
  for (const std::int_fast64_t& a_i : a) {
    if (a_i < 3200) {
      colors.insert(a_i / 400);
    } else {
      ++crowned_count;
    }
  }

  std::cout << std::max<std::int_fast64_t>(colors.size(), 1) << ' ' << colors.size() + crowned_count << std::endl;
  return 0;
}

Measured memory_bytes: 256
// 7/6 バーチャル参加
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<int>>;

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    if (A + B + C >= 22) cout << "bust" << endl;
    else cout << "win" << endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define MAX_N 10000
#define INF 1e9

using namespace std;

typedef int long long ll;
typedef int long l;
typedef pair<int, int> Pii;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    multiset<int> ans;
    int a, b, c;
    for (int i = 0; i < 3; i++) {
        cin >> a;
        ans.insert(a);
    }
    if (ans.count(7) == 1 && ans.count(5) == 2) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }


    return 0;
}

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

int main() {
  vector<int> retsu{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int K;
  cin >> K;
  cout << retsu[K-1] << endl;
  

}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
using ll = long long;
 
 
int main() {
	
	int n,k;
	cin >> n >> k;
	int res = n % k;
    
	if ( res == 0)
      	cout << res << endl;
  	else
      	cout << 1 << endl;
	
}


Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define rep(i,m,n) for(int (i)=(int)(m);(i)<(int)(n);(i)++)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;(i)>=(int)(m);(i)--)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;

typedef vector<ll> Array;
typedef vector<Array> Matrix;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

constexpr long long MOD = 998244353;

template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

struct Edge {
	int to, cap, rev;
	Edge(int _to, int _cap, int _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, int from, int to, int cap, bool revFlag, int revCap) {
	G[from].push_back(Edge(to, cap, G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, G[from].size() - 1));
}

void Dijkstra(Graph& G, ll s, Array& d) {//O(|E|log|V|)
	d.resize(G.size());
	REP(i, d.size())d[i] = INF;
	d[s] = 0;
	priority_queue<P, vector<P>, greater<P>> q;
	q.push(make_pair(0, s));
	while (!q.empty()) {
		P a = q.top();
		q.pop();
		if (d[a.second] < a.first)continue;
		REP(i, G[a.second].size()) {
			Edge e = G[a.second][i];
			if (d[e.to] > d[a.second] + e.cap) {
				d[e.to] = d[a.second] + e.cap;
				q.push(make_pair(d[e.to], e.to));
			}
		}
	}
}


void solve() {
	ll n, x, y;
	cin >> n >> x >> y;
	x--; y--;
	Graph g(n);
	REP(i, n - 1) add_edge(g, i, i + 1, 1, true, 1);
	add_edge(g, x, y, 1, true, 1);

	
	Array ans(n);
	REP(i, n) {
		Array d;
		Dijkstra(g, i, d);
		rep(j, i + 1, n) ans[d[j]]++;
	}
	
	rep(i, 1, n) cout << ans[i] << en;
}

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

	solve();
	//int t; cin >> t; REP(i, t) solve();

	return 0;
}


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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left!=NIL)
    x =x->left;
    return x;
}

Node treeMaximum(Node x){
  while(x->right != NIL)
    x = x->right;
    return x;
}

Node treeSearch(Node u, int k){
  while(u!=NIL && k!=u->key){

  if(k < u->key) u=u->left;

  else u=u->right;
  }
  return u;
  
}

Node treeSuccessor(Node x){
  Node y;
  if(x->right != NIL) return treeMinimum(x->right);
  y = x->parent;
  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;

}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  if(z->left==NIL || z->right==NIL) y = z;
  else y = treeSuccessor(z);

  if(y->left != NIL) x=y->left;
  else x = y->right;

  if(x!=NIL) x->parent = y->parent;
  if(y->parent==NIL) root = x;
  else if(y == y->parent->left) y->parent->left = x;
  else y->parent->right =x;
  
  if(y!= z) z->key = y->key;
  free(y);
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->parent = y;
  if(y==NIL) root = z;
  else if(z->key < y->key) y->left = z;
  else y->right = z;
}

void inorder(Node u){
  if(u == NIL)return;
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  
}
void preorder(Node u){
  if(u ==NIL)return;
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
  
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 20488
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;

template <typename T1, typename T2>
string print_iterable(T1 begin_iter, T2 end_iter, int counter) {
    bool done_something = false;
    stringstream res;
    res << "[";
    for (; begin_iter != end_iter and counter; ++begin_iter) {
        done_something = true;
        counter--;
        res << *begin_iter << ", ";
    }
    string str = res.str();
    if (done_something) {
        str.pop_back();
        str.pop_back();
    }
    str += "]";
    return str;
}

vector<int> SortIndex(int size, std::function<bool(int, int)> compare) {
    vector<int> ord(size);
    for (int i = 0; i < size; i++) ord[i] = i;
    sort(ord.begin(), ord.end(), compare);
    return ord;
}

template <typename T>
bool MinPlace(T& a, const T& b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
bool MaxPlace(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template <typename Container>
int SZ(const Container& S) { return S.size(); }

template <typename S, typename T>
ostream& operator <<(ostream& out, const pair<S, T>& p) {
    out << "{" << p.first << ", " << p.second << "}";
    return out;
}

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

#if DEBUG && !ONLINE_JUDGE
    ifstream input_from_file("input.txt");
    #define cin input_from_file

    #define dbg_var(x) clog << #x  << ": " << x << endl;
    #define dbg_array(x, len) clog << #x << ": " << print_iterable(x, x+len, -1) << endl;
#else
    #define dbg_var(x)
    #define dbg_array(x, len)
#endif

///////////////////////////////////////////////////////////////////////////
//////////////////// DO NOT TOUCH BEFORE THIS LINE ////////////////////////
///////////////////////////////////////////////////////////////////////////

const int MAXN = 310;
int din[MAXN][MAXN][MAXN];
int last[26][MAXN]; 

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); // Remove in problems with online queries!
    string s;
    cin >> s;
    int K;
    cin >> K;
    int N = s.size();
    for (int i = 0; i < N; i++) {
        for (int c = 0; c < 26; c++) last[c][i+1] = last[c][i];
        last[s[i]-'a'][i+1] = i;
    }
    // for (int l = 0; l <= N; l++) din[l][l] = 0;
    for (int l = 0; l < N; l++) for (int k = 0; k <= K; k++) din[l][l+1][k] = 1;
    for (int dd = 2; dd <= N; dd++) {
        for (int l = 0; l+dd <= N; l++) {
            int r = l+dd;
            for (int k = 0; k <= K; k++) {
                din[l][r][k] = din[l+1][r][k];
                if (k > 0) din[l][r][k] = max(din[l][r][k], 2 + din[l+1][r-1][k-1]);
                int index = last[s[l]-'a'][r];
                if (index > l) din[l][r][k] = max(din[l][r][k], 2 + din[l+1][index][k]);
            }
        }
    }
    cout << din[0][N][K] << "\n";
}



Measured memory_bytes: 114816
#include<cstdio>
using namespace std;
int main(void){
	int a,b;
	int x,ave;
	scanf("%d %d",&a,&b);
	x=a+b;
	ave=x/2;
	if(x%2!=0)	ave++;
	printf("%d\n",ave);
	return 0;
}

Measured memory_bytes: 128
/*
    Ujjawal Pabreja
*/
#include <bits/stdc++.h> 
#include <functional> 
using namespace std;
using ll = long long;
using ld = long double;
#define speed_cubing    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define rep(i,a)        for(ll i = 0 ; i < a ; i++)
#define repe(i,a,b)     for(ll i = a ; i < b ; i++)
#define bac(i,a)        for(ll i = a ; i >= 0 ; i--)
#define bace(i,a,b)     for(ll i = a ; i >= b ; i--)
#define pb              push_back
#define mp              make_pair
#define in              insert
#define ff              first
#define ss              second
#define vv              vector
#define vll             vector <ll>
#define pll             pair <ll,ll>
#define vpll            vector <pll>
#define umap            unordered_map
#define uset            unordered_set
#define mset            multiset
#define pqueue          priority_queue
#define setbit(x)       __builtin_popcountll(x)
#define init(c,a)       memset(c,a,sizeof(c))
#define all(c)          c.begin(),c.end()
#define sz(c)           (ll)c.size()
#define lb              lower_bound
#define ub              upper_bound
#define maxe            *max_element
#define mine            *min_element
#define gcd(a,b)        __gcd(a,b)
#define rev             reverse
#define Y               "YES"
#define N               "NO"
#define nl              "\n"
#define debug(x)        cout << #x << " : " << x << nl;
const ll inf = 1e18;  
const ll mod = 1e9 + 7;
const ll MOD = 998244353;
const ll MAX = 2e5 + 1;

// ====== int_1024t begins ======
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
// ====== int_1024t ends ======

// ====== pbds begins ======
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, 
//         tree_order_statistics_node_update> 
//         pbds; 
// ====== pbds ends ======

// ====== Useful functions begin ======
inline ll add(ll a,ll b) {return ((a%mod)+(b%mod))%mod;}
inline ll sub(ll a,ll b) {return ((a%mod)-(b%mod)+mod)%mod;}
inline ll mul(ll a,ll b) {return ((a%mod)*(b%mod))%mod;}
ll pwr(ll x,ll n){
    if(!n) return 1;
    if(n&1) return mul(x, pwr(mul(x,x),(n-1)/2));
    else return pwr(mul(x,x),n/2);
}
ll modinv(ll n){ 
    return pwr(n,mod - 2); 
}
// ====== Useful functions end ======
 
// ====== Variables begin ======

// ====== Variables end ======
void speed_solve(){
    ll n; ld m;
    cin >> n >> m;
    ld a[n], tot = 0;
    rep(i,n){
        cin >> a[i];
        tot += a[i];
    }
    tot /= (4 * m);
    ll cnt = 0;
    rep(i,n){
        if(a[i] >= tot){
            cnt++;
        }
    }
    if(cnt >= (ll)m){
        cout << "Yes";
    }
    else{
        cout << "No";
    }
}
int main()
{
    speed_cubing;
    ll test_cases = 1;
    // cin >> test_cases;
    rep(i,test_cases){
        // cout << "Case #" << i + 1 << ": ";
        speed_solve();
    }
    return 0;
}

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

#define ll long long
#define pb push_back
#define bit(a , b) (((a)>>(b))&1)

const int maxn = 1e5 + 20;

pair<vector<int> , int> solve(ll n)
{
	vector<int> ans;
	if(n == 1)
	{
		ans.pb(1);
		ans.pb(1);
		return {ans , 1};
	}

	if(n == 2)
	{
		ans.pb(1);
		ans.pb(50);
		ans.pb(50);
		ans.pb(1);

		return {ans , 2};
	}

	vector<int> tmp;
	int F = 0;

	if(n % 2 == 1)
	{
		auto shit = solve(n / 2);
		F = shit.second;
		tmp = shit.first;
	}
	else
	{
		auto shit = solve(n / 2 - 1);
		F = shit.second;
		tmp = shit.first;
	}

	int mx1 = 0 , mx = 0;
	for(auto x : tmp)
	{
		if(x < 50)
			mx1 = max(mx1 , x);
		mx = max(mx , x);
	}

	int ahhh = F;

	for(int i = 0; i < F; i++)
		ans.pb(tmp[i]);
	
	ans.pb(mx1 + 1);
	F++;

	if(mx < 50)
		mx = 49;

	if(n % 2 == 0)
	{
		F++;
		ans.pb(mx + 1);
		ans.pb(mx + 1);
	}

	for(int i = ahhh; i < (int)tmp.size(); i++)
		ans.pb(tmp[i]);

	ans.pb(mx1 + 1);

	return {ans , F};
}

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

	ll n;
	cin >> n;

	vector<int> ans = solve(n).first;

	cout << ans.size() << endl;
	for(auto x : ans)
		cout << x << " ";
	cout << endl;

}









Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int64_t DP[1010][1010][8]; // i番目までに、j個選んだ時、8パターンの最大値

int main()
{
  int64_t N, M, ans = 0;
  cin >> N >> M;
  vector<vector<int64_t>> A(N, vector<int64_t>(3));
  for (int i = 0; i < N; i++)
    cin >> A.at(i).at(0) >> A.at(i).at(1) >> A.at(i).at(2);
  for (int64_t i = 1; i <= N; i++)
  {
    for (int64_t j = 0; j <= min(M, i); j++)
    {
      int64_t a = -(1LL << 62), b = -(1LL << 62);
      for (int k = 0; k < 8; k++)
      {
        if (j <= i - 1)
        {
          a = DP[i - 1][j][k]; // 選ばない場合
        }
        if (j >= 1)
        {
          b = DP[i - 1][j - 1][k];
          for (int n = 0; n < 3; n++)
          {
            if (k & (1 << n))
              b += A.at(i - 1).at(n);
            else
              b -= A.at(i - 1).at(n);
          }
        }
        DP[i][j][k] = max(a, b);
      }
    }
  }
  for (int k = 0; k < 8; k++)
  {
    ans = max(ans, DP[N][M][k]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 38936
#include <stdio.h>
int main()
{
	int a,b=0,c;
	scanf("%d",&a);
	c=a;
	while(a>0)
	{
		b=a%10+b;
		a=a/10;
	}
	if(c%b==0)
	printf("Yes");
	else
	printf("No");
	return 0;
}


Measured memory_bytes: 128
max = 0
for i in range(1,10):
    max += i * (i + 1)

dp=[[[-1] * 1025 for i in range(max + 1)] for j in range(11)]

def solve(n,s,used):
    if n == 0 and s == 0:
        return 1;
    if n <= 0 or s < 0:
        return 0
    if dp[n][s][used] != -1:
        return dp[n][s][used]
        
    sum = 0
    for i in range(0,10):
        if (used >> i) % 2 == 0:
            used += 1 << i
            sum += solve(n - 1,s - i * n,used)
            used -= 1 << i
    dp[n][s][used] = sum        
    return sum

while(1):
    try:
        n,s = (int(x) for x in input().split())
        ans = 0
        if s >= 0 and s <= max:
            used = 0
            ans = solve(n,s,used)
        print(ans)
    except:
        break


Measured memory_bytes: 35060
#include<iostream>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
  	cin.tie(NULL);
  	cout.tie(NULL);
  	string s;
  	cin>>s;
  	for(int i=0;i<s.length();i++)if(s[i]=='?')s[i]='D';
  	cout<<s<<endl;
}

Measured memory_bytes: 3744
n = int(input())
nums = [int(i) for i in input().split()]
mod = 10 ** 9 + 7

def gcd(x, y): #GCD
    # greatest_common_divisor
    if x < y:
        x, y = y, x
    if y == 0:
        return 0
    if x % y == 0:
        return y
    return gcd(y, x % y)

def lcm(x, y): #LCM
    # lowest_common_multiple
    return x * y // gcd(x, y)

LCM = 1
for num in nums:
    LCM = lcm(num, LCM)
LCM %= mod
# ans = 0
# for num in nums:
#     ans += (LCM // num) % mod
# print(ans % mod)
ans = 0
for num in nums:
    ans += LCM * pow(num, mod - 2, mod)
    ans %= mod

print(ans % mod)

Measured memory_bytes: 71388