akhauriyash/Code-Regression huggingface dataset:
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>
#include <stack>
#include <bitset>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

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(a>b){a=b;return 1;}return 0;}

// T have +-*/ and 0
template<class T> class BIT {
public:
    vector<T> dat;
    ll N;

    BIT(){}
    BIT(ll N) : N(N) { dat.assign(N,0); }
    // sum [0,i)
    T sum(ll i){
        ll ret = 0;
        for(--i; i>=0; i=(i&(i+1))-1) ret += dat[i];
        return ret;
    }
    // sum [i,j)
    T sum(ll i, ll j) { return sum(j) - sum(i); }
    // add x to i
    void add(ll i, T x) { for(; i < N; i|=i+1) dat[i] += x; }
};


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

  ll n; cin >> n;
  vector<ll> a(n);
  REP(i,n) {
    cin >> a[i];
  }
  //転倒してるのが蓄積される

  multiset<ll> ms;
  ms.insert(-1);
  for(auto &e: a) {
    //for(auto &m: ms) cerr << m << " ";
    //cerr << endl;
    auto p = ms.lower_bound(e);
    p--;
    //cerr  << " *p:" << *p << endl;
    if(*p >= 0) ms.erase(p);
    ms.insert(e);
  }
  cout << ms.size()-1 << endl;
  
  return 0;
}


Measured memory_bytes: 5760
n = int(input())
A = [int(input()) for _ in range(n)]
used = {1}
pos = 1
count = 0
for _ in range(n):
  pos = A[pos - 1]
  count += 1
  if pos in used:
    print(-1)
    break
  used.add(pos)
  if pos == 2:
    print(count)
    break


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

using namespace std;

#define REP(i, n) for(int i = 0; i < (n); i++)
#define SORT(v, n) sort(v, v+n);
#define SSORT(v, n) sort(v, v+n, greater<int>())

int main(){
	int n,m,flag;
	cin >> n >> m;
	int l[m],r[m];
	REP(i,m){
		cin >> l[i] >> r[i];
	}
	SSORT(l,m);
	SORT(r,m);
	int ans = r[0]-l[0];
	if(ans<0) ans = 0;
	else ans++;
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define fi first
#define endl '\n'
#define se second
#define pb push_back
#define int long long
#define ve vector<int>
#define mod 1000000007
#define eb emplace_back
#define inf ((long long) 1e18 )
#define all(x) (x).begin(),(x).end()
#define debug(x) cout << '>' << #x << ':' << x << '\n';
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug2(x,y) cout << '>' << #x <<" = "<< x <<" & "<< #y <<" = "<< y << '\n';
#define fileIO freopen("input.txt", "r", stdin); freopen("output1.txt", "w", stdout);
using namespace std;
const int N = 1e3 + 7;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};

int32_t main() {
	IOS
#ifndef ONLINE_JUDGE
	fileIO
#endif
	auto start = std::chrono::high_resolution_clock::now();
	int test;
	test = 1;
	// cin >> test;
	while (test--) {
		int n, m;
		cin >> n >> m;
		int start_i, start_j;
		int end_i, end_j;
		cin >> start_i >> start_j;
		cin >> end_i >> end_j;
		start_i--;
		start_j--;
		end_i--;
		end_j--;
		vector<vector<int>> dp(n, vector<int> (m, -1));
		vector<string> a(n);
		for (auto &i : a)
			cin >> i;
		deque<pair<int, int>> q;
		q.push_front({start_i, start_j});
		dp[start_i][start_j] = 0;
		while (!q.empty()) {
			pair<int, int> temp = q.front();
			q.pop_front();
			int cur = dp[temp.first][temp.second];
			for (int i = 0 ; i < 4; i++) {
				int s = temp.fi + dx[i];
				int d = temp.se + dy[i];
				if (s >= 0 and d >= 0 and s < n and d < m and a[s][d] == '.') {
					if (dp[s][d] == -1 or dp[s][d] > cur) {
						dp[s][d] = cur;
						q.push_front({s, d});
					}
				}
			}
			for (int i = -2; i < 3; i++) {
				for (int j = -2; j < 3; j++) {
					if (i == 0 and j == 0)
						continue ;
					int s = temp.fi + i;
					int d = temp.se + j;
					if (s >= 0 and d >= 0 and s < n and d < m and a[s][d] == '.') {
						if (dp[s][d] == -1 or dp[s][d] > cur + 1) {
							dp[s][d] = cur + 1;
							q.push_back({s, d});
						}
					}
				}
			}
		}
		cout << dp[end_i][end_j] << endl;
	}

	auto stop = std::chrono::high_resolution_clock::now();
	auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(stop - start);

	cerr << "Time taken : " << ((long double)duration.count()) / ((long double) 1e9) << "s " << endl;

	return 0;
}

Measured memory_bytes: 12824
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

constexpr int mod = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    vector<char> S(N);
    rep(i, N) cin >> S[i];
    
    vector<int> alpha(26, 0);
    rep(i, N) ++alpha[S[i] - 'a'];
    long long ans = 1;
    rep(i, 26) ans = ans * (alpha[i] + 1) % mod;
    cout << ans - 1 << endl;
    return 0;
}


Measured memory_bytes: 384
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<stack>
#include<string.h>
#include<queue>
using namespace std;
typedef long long ll;

//const int maxn
int n,m,cnt;

ll read(){ ll s=0,f=1; char ch=getchar(); while(ch<'0' || ch>'9'){ if(ch=='-') f=-1; ch=getchar(); } while(ch>='0' && ch<='9'){ s=s*10+ch-'0'; ch=getchar(); } return s*f; }

int main(){
	cnt=0;
	string s,t;
	cin>>s;
	cin>>t;
	n=s.size();
	m=t.size();
	for(int i=0;i<n;i++){
		if(s[i]!=t[i]) ++cnt;
	}
	
	printf("%d\n",cnt);
	return 0;
}


Measured memory_bytes: 3912
N, K = map(int,input().split())
ans = float('inf')
for i in range(N,K):
    for j in range(i+1,K+1):
        mod = (i*j)%2019
        ans = min(mod, ans)
        if mod==0:
            break
    else:
        continue
    break
print(ans)

Measured memory_bytes: 9092
from bisect import bisect_left, bisect_right
from itertools import product

n = int(input())
s = input()

A = [[] for _ in range(10)]
for i in range(n):
    x = int(s[i])
    A[x].append(i)

use = set((i for i in range(10) if len(A[i]) > 0))
ans = 0
for a, b, c in product(use, repeat=3):
    ai = A[a][0]
    ci = A[c][-1]
    k = bisect_right(A[b], ci - 1) - bisect_left(A[b], ai + 1)
    if k > 0:
        ans += 1
print(ans)


Measured memory_bytes: 74152
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;


#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define PSET(x,y) fixed<<setprecision(y)<<x
#define pb push_back
#define pii pair<int,int>
#define pf push_front
#define mp make_pair
#define vi vector<int>
#define vip vector<pair<int,int> >
#define ff first
#define ss second
#define int long long
#define mod 1000000007
#define BIG 998244353
#define s(t) scanf("%lld",&t)
#define p(t) printf("%lld\n",t)
#define mii map<int,int>
#define MSET(table,i) memset(table, i, sizeof(table))
#define endl '\n'
#define tc int t;cin>>t;while(t--)
#define pi  3.1415926358
#define bits(x) __builtin_popcount(x)
#define minimum(a,n) min_element(a,a+n)-a
#define maximum(a,n) max_element(a,a+n)-a
#define pqbig priority_queue<pii>
#define pqsmall priority_queue<pair<int,pii>,vector<pair<int,pii> >,greater<pair<int,pii> > >
#define all(v) v.begin(),v.end()
#define sitr set<int>:: iterator
#define spitr set<pii>:: iterator
#define mitr map<string,int>:: iterator

int toint(const string &s) {stringstream ss; ss << s; int x; ss >> x; return x;}
string tostring ( int number ) {stringstream ss; ss << number; return ss.str();}

typedef tree<pii, null_type, less<pii>, rb_tree_tag,
        tree_order_statistics_node_update>
        new_data_set;

#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

const int N=2e5+5;
int freq[N];
int arr[N];
int val[N];
int n;

int32_t main()
{
    fast;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        int x;cin>>x;
        arr[i]=x;
        freq[x]++;
    }

    for(int i=1;i<=n;i++)
        val[i]=val[i-1]+(freq[i]*(freq[i]-1))/2;

    for(int i=1;i<=n;i++)
    {
        int right_sum=val[n]-val[arr[i]];
        int left_sum=val[arr[i]-1];

        int cur=(freq[arr[i]]-1)*(freq[arr[i]]-2)/2;
        cout<<right_sum+left_sum+cur<<endl;
    }

}

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

#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << ": " << x << '\n'

typedef long long int ll;
typedef pair<int, int> P;

const long long INF = 3e18 + 12;
const int inf = 1e9;

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

  ll a, b, k;
  cin >> a >> b >> k;

  if ((b - a + 1) <= k * 2) {
    repi(i, a, b + 1) {
      cout << i << endl;
    }
    return 0;
  }

  repi(i, a, a + k) {
    cout << i << endl;
  }

  repi(i, b - k + 1, b + 1) {
    cout << i << endl;
  }

  return 0;
}

Measured memory_bytes: 256
(defun main ()
  (let ((a (read))
	(b (read))
	(c (read))
	(k (read))
	(ans "No"))
    (dotimes (i k)
      (cond ((< a b c) (setf c (* c 2)))
	    ((>= a c) (setf c (* c 2)))
	    ((>= a b) (setf b (* b 2)))
	    ((>= b c) (setf c (* c 2)))))
    (if (< a b c )
	(setf ans "Yes"))
    (format t "~a~%" ans)))
(main)


Measured memory_bytes: 23412
void main() {
  import std.stdio, std.string, std.conv, std.algorithm;
  import std.range;

  int n, m, q;
  rd(n, m, q);
  auto a = new int[][](n);
  foreach (_; 0 .. m) {
    int l, r;
    rd(l, r);
    a[l - 1] ~= r - 1;
  }
  foreach (i; 0 .. n)
    sort(a[i]);
  while (q--) {
    int l, r;
    rd(l, r);
    int s = 0;
    for (int i = l - 1; i < r; i++) {
      auto tri = a[i].assumeSorted.trisect(r - 1);
      s += tri[0].length + tri[1].length;
    }
    writeln(s);
  }

}

void rd(T...)(ref T x) {
  import std.stdio : readln;
  import std.string : split;
  import std.conv : to;

  auto l = readln.split;
  assert(l.length == x.length);
  foreach (i, ref e; x)
    e = l[i].to!(typeof(e));
}


Measured memory_bytes: 11772
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long r = 0;
		long g = 0;
		long b = 0;
		long result;
		char[] c = sc.next().toCharArray();

		for(char var : c) {
			switch (var) {
			case 'R':
				r++;
				break;
			case 'G':
				g++;
				break;
			case 'B':
				b++;
				break;
			}
		}

		result = r * g * b;

		for(int i = 0; i < n - 2; i++) {
			for(int j = i + 1; j < n; j++) {
				int k = j + (j - i);
				if(k >= n) break;
				if(c[i] != c[j] && c[j] != c[k] && c[k] != c[i]) result--;
			}
		}

		System.out.println(result);

		sc.close();
	}
}

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

int main() {
  int X,Y;
  cin >> X >> Y;
  
  bool I = false;
  
  for(int i=0;i<X+1;i++){
    if(2*i + 2*X == Y){
      I = true;
    }
  }
  
  if(I == true){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  
  
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define pb push_back
#define FOR(i, a, b) for (long long i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define MOD 1000000007
#define INF 93193111451418101
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

struct graph {
  int L, R;
  vector<vector<int>> adj;
  graph(int L, int R) : L(L), R(R), adj(L + R) {}
  void add_edge(int u, int v) {
    adj[u].push_back(v + L);
    adj[v + L].push_back(u);
  }
  int maximum_matching() {
    vector<int> visited(L), mate(L + R, -1);
    function<bool(int)> augment = [&](int u) { // DFS
      if (visited[u])
        return false;
      visited[u] = true;
      for (int w : adj[u]) {
        int v = mate[w];
        if (v < 0 || augment(v)) {
          mate[u] = w;
          mate[w] = u;
          return true;
        }
      }
      return false;
    };
    int match = 0;
    for (int u = 0; u < L; ++u) {
      fill(visited.begin(), visited.end(), 0);
      if (augment(u))
        ++match;
    }
    return match;
  }
};
int main() {
  ll n;
  cin >> n;
  vector<P> red, blue;
  graph g(n, n);
  REP(i, n) {
    ll a, b;
    cin >> a >> b;
    red.pb({a, b});
  }
  REP(i, n) {
    ll a, b;
    cin >> a >> b;
    blue.pb({a, b});
  }

  REP(i, n) {
    REP(j, n) {
      if (blue[j].first > red[i].first && blue[j].second > red[i].second) {
        g.add_edge(i, j);
      }
    }
  }
  cout << g.maximum_matching() << endl;
}


Measured memory_bytes: 256
use std::collections::HashMap;

fn main() {
    let n = read::<i32>();
    let mut map = HashMap::new();
    for _ in 0..n {
        let insert = read_vec::<String>();
        match &*insert[0] {
            "insert" => { map.insert(insert[1].clone(), 0); },
            "find" => {
                if map.contains_key(&insert[1]) {
                    println!("yes");
                } else {
                    println!("no");
                }
            },
            _ => unreachable!(),
        }
    }
}

fn str_to_hash(s: &str) -> usize {
    let mut hash = 0;
    for ch in s.bytes() {
        hash <<= 2;
        hash |= match ch {
            b'A' => 0,
            b'C' => 1,
            b'G' => 2,
            b'T' => 3,
            _ => unreachable!(),
        };
    }
    hash
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line)
        .ok()
        .expect("Faild to read Vec");
    line.trim().split_whitespace()
        .map(|i| i.parse().ok().unwrap()).collect()
}

/// 標準入力から一行を読み取り、指定の型に変換する関数
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}



Measured memory_bytes: 37540
#include<stdio.h>
int main(void)
{
	char s;
	scanf("%c",&s);
	if(s=='a' || s=='e'	|| s=='i' || s=='o' || s=='u')
	{   
			printf("vowel\n");
	}
	else{
		printf("consonant\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll n;
    cin>>n;
    vector<LP> ps(n);
    rep(i, n) {
        ll p;
        cin>>p;
        ps[i] = LP(p, i);
    }
    sort(rng(ps));

    rep(i, n) {
        cout<<(i + 1) * 30000 - (n - ps[i].se)<<" ";
    }
    cout<<endl;
    rep(i, n) {
        cout<<30000 * (n - i)<<" ";
    }
    cout<<endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define f first
#define s second
#define inf 999999999999
#define N  500009
#define M  (L+R)/2
#define ll long long
#define pb push_back
using namespace std;
ll n,ans,a[N],b[N];
int main()
{

	ios::sync_with_stdio(0);
	
	cin>>n;
	for(int i=1;i<n;i++){
		cin>>a[i];
	
	}
	b[0]=a[1];
	for(int i=1;i<n;i++){
		b[i]=min(a[i],a[i+1]);
	}
	b[n-1]=a[n-1];
	for(int i=0;i<n;i++){
	//	cout<<b[i]<<" ";
		ans+=b[i];
	}
	
	cout<<ans<<endl;
return 0;
}




Measured memory_bytes: 2304
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
#include<bitset>
#include<cstdlib>
// #include<deque>
// #include<multiset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

ll n, k;

int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  cin >> n >> k;
  vector<ll> a(n), b(n);
  for(int i = 0; i < n; i++) cin >> a[i];
  for(int i = 0; i < n; i++) cin >> b[i];
  ll ok = 1e12, ng = -1;
  sort(begin(a), end(a));
  sort(rbegin(b), rend(b));
  while(ok - ng > 1) {
    ll mid = (ok + ng) / 2;
    ll k2 = k;
    for(int i = 0; i < n; i++) {
      k2 -= max<ll>(0, a[i] - mid / b[i]);
    }
    if(k2 >= 0) ok = mid; else ng = mid;
  }
  cout << ok << endl;
  return 0;
}


Measured memory_bytes: 3456
#include<stdio.h>

int main(void)
{
    char word[256];
    scanf("%s",&word);

    char *s1 = "SUN";
    char *s2 = "MON";
    char *s3 = "TUE";
    char *s4 = "WED";
    char *s5 = "THU";
    char *s6 = "FRI";
    char *s7 = "SAT";

    if(strcmp(word,s1)==0)
    {
        printf("7\n");
    }
    else if(strcmp(word,s2)==0)
    {
        printf("6\n");
    }
    else if(strcmp(word,s3)==0)
    {
        printf("5\n");
    }
    else if(strcmp(word,s4)==0)
    {
        printf("4\n");
    }
    else if(strcmp(word,s5)==0)
    {
        printf("3\n");
    }
    else if(strcmp(word,s6)==0)
    {
        printf("2\n");
    }
    else if(strcmp(word,s7)==0)
    {
        printf("1\n");
    }
    
    return 0;

}

Measured memory_bytes: 128
// 前やったのを覚えていたので虚無

package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main() {
	var H, W, N int
	fmt.Scan(&H, &W, &N)
	A := make([]int, N)
	T := make([][]string, H)
	for i := 0; i < N; i++ {
		fmt.Scan(&A[i])
	}
	for i := 0; i < H; i++ {
		T[i] = make([]string, W)
	}
	idx := 0
	for i := 0; i < H; i++ {
		for j := 0; j < W; j++ {
			k := j
			if i%2 == 1 {
				k = W - j - 1
			}
			T[i][k] = strconv.Itoa(idx + 1)
			A[idx]--
			if A[idx] == 0 {
				idx++
			}
		}
	}
	for _, t := range T {
		fmt.Println(strings.Join(t, " "))
	}
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define ll long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    vector<string> a(n), b(m);
    bool res;
    rep(i, 0, n)
        cin >> a[i];
    rep(j, 0, m)
        cin >> b[j];
    rep(i, 0, n - m + 1)
    {
        rep(j, 0, n - m + 1)
        {
            res = true;
            rep(k, 0, m)
            {
                string s2 = a[i+k].substr(j, m);
                if (s2 != b[k])
                {
                    res = false;
                    break;
                }
            }
            if (res == true)
                break;
        }
        if (res == true)
            break;
    }
    cout << (res?"Yes":"No");
    return 0;
}

Measured memory_bytes: 256
class PriorityQueue
  attr_reader :values

  def initialize
    @values = [nil]
    @pos = 0
  end

  def push(value)
    @pos += 1
    @values[@pos] = value

    i = @pos

    while 2 <= i && @values[i] < @values[i / 2]
      @values[i], @values[i / 2] = @values[i / 2], @values[i]
      i /= 2
    end
  end

  def pop
    return nil if empty?

    ret = @values[1]
    @values[1] = @values[@pos]
    @pos -= 1

    i = 1

    loop do
      l = i * 2
      r = l + 1

      smallest = l <= @pos && @values[l] < @values[i] ? l : i
      smallest = r <= @pos && @values[r] < @values[smallest] ? r : smallest

      break if smallest == i

      @values[i], @values[smallest] = @values[smallest], @values[i]

      i = smallest
    end

    ret
  end

  def empty?
    @pos <= 0
  end
end

class Node
  attr_reader :id, :siblings
  attr_accessor :state

  def initialize(id)
    @id = id
    @siblings = []
    @distances = {}
    @state = :white
  end

  def add(sibling, distance)
    @siblings << sibling
    @distances[sibling.id] = distance
  end

  def distance_to(sibling)
    @distances[sibling.id]
  end
end

Pair = Struct.new(:distance, :id) do
  include Comparable

  def <=>(other)
    distance <=> other.distance
  end
end

if $PROGRAM_NAME == __FILE__
  n = gets.to_i

  nodes = []

  n.times do
    id, _, *rest = gets.chomp.split.map(&:to_i)

    nodes[id] ||= Node.new(id)
    node = nodes[id]

    rest.each_slice(2) do |sibling_id, distance|
      nodes[sibling_id] ||= Node.new(sibling_id)
      sibling = nodes[sibling_id]
      node.add(sibling, distance)
    end
  end

  distances = Array.new(n, Float::INFINITY)

  distances[0] = 0
  nodes[0].state = :gray

  queue = PriorityQueue.new
  queue.push(Pair.new(0, 0))

  until queue.empty?
    pair = queue.pop
    current = nodes[pair.id]
    current.state = :black

    next if distances[current.id] < pair.distance

    current.siblings.each do |sibling|
      next if sibling.state == :black

      distance = distances[current.id] + current.distance_to(sibling)

      if distance < distances[sibling.id]
        distances[sibling.id] = distance
        sibling.state = :gray
        queue.push(Pair.new(distance, sibling.id))
      end
    end
  end

  puts distances.map.with_index {|distance, id| [id, distance].join(' ') }.join("\n")
end

Measured memory_bytes: 46868
using System;

namespace b
{
    class Program
    {
        static void Main(string[] args)
        {
            var a = int.Parse(Console.ReadLine());
            var b = int.Parse(Console.ReadLine());
            var c = int.Parse(Console.ReadLine());
            var x = int.Parse(Console.ReadLine());

            var count = 0;
            for(var i = 0; i <= a; i++){
                for(var j = 0; j <= b; j++){
                    for(var k = 0; k <= c; k++){
                        var t = (500 * i) + (100 * j) + (50 * k);
                        count += t == x ? 1 : 0;
                    }                
                }
            }

            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 11092
#include <stdio.h>

int main(){
  int n;
  scanf("%d",&n);
  int i=9;
  int k;
  while(0<i){
    if(n%i==0){
      k=n/i;
      if(k>=10){
        printf("No\n");
        return 0;
      }else{
        printf("Yes\n");
        return 0;
      }
    }else{
      i--;
      if(i==0){
        printf("No\n");
        return 0;
      }
    }
  }
  return 0;
}


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

#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    int a, b;
    cin >> a >> b;
    if(a+b>=10) cout << "error" << endl;
    else cout << a+b << endl;
    return 0;
}

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


int main() {
    int j, n, v;
    cin >> n;
    int L[n];
    for (int i = 0; i < n; ++i) {
        cin >> L[i];
    }
    for (int i = 0; i < n; ++i) {
        v = L[i];
        j = i - 1;
        while ( j >= 0 && L[j] > v) {
            L[j + 1] = L[j];
            j--;
        }
        L[j+1] = v;
        for (int k = 0; k < n-1; ++k) {
            cout << L[k] << " ";
        }
        cout << L[n-1] << "\n";

    }
    return 0;
}


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

const int mxn = 1e5+1;
vector<int> st(1e5+1);

int fs(int x){
	if(x == st[x]) return x;
	return st[x] = fs(st[x]);
}

void us(int x,int y){
	int px = fs(x);
	int py = fs(y);
	if(px!=py) st[py] = px;
}

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

	vector<int> p(n+1);

	for(int i = 1; i <= n; i++) cin>>p[i];
	for(int i = 1; i <= n; i++) st[i] = i;

	for(int i = 0; i < m; i++){
		int x,y;
		cin>>x>>y;
		us(x,y);
	}
	int res = 0;
	for(int i = 1; i <= n; i++) if(fs(p[i]) == fs(i)) res++;
	cout<<res;
}



Measured memory_bytes: 1024
n,m=map(int,input().split())

class UnionFind():
  def __init__(self, n):
    self.n = n
    self.parents = [-1]*n
  
  def find(self, x):
    if self.parents[x] < 0:
      return x
    else:
      self.parents[x] = self.find(self.parents[x])
      return self.parents[x]
    
  def union(self, x, y):
    x=self.find(x)
    y=self.find(y)
    
    if x== y:
      return
    
    if self.parents[x] > self.parents[y]:
      x, y = y, x
      
    self.parents[x] += self.parents[y]
    self.parents[y] = x
    
  def size(self, x):
    return -self.parents[self.find(x)]
  
uf = UnionFind(n)
ans=0

for i in range(m):
  a, b = map(int,input().split())
  a -= 1
  b -= 1
  uf.union(a, b)
  
for i in range(n):
  ans = max(ans, uf.size(i))

print(ans)

Measured memory_bytes: 14756
// https://atcoder.jp/contests/dp/tasks/dp_f
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
typedef vector<ll> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<vs> vss;
#define rep(i, k, n) for (int i = k; i < (int)(n); i++)

int main()
{
    string a, b;
    cin >> a >> b;
    vii dp(a.length() + 1, vi(b.length() + 1));

    rep(i, 0, a.length() + 1)
    {
        rep(j, 0, b.length() + 1)
        {
            if (i == 0 || j == 0)
                dp[i][j] = 0;
            else if (a[i - 1] == b[j - 1])
                dp[i][j] = 1 + dp[i - 1][j - 1];
            else
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
        }
    }

    string ans;
    int i = a.length();
    int j = b.length();
    while (i != 0 && j != 0)
    {
        if (dp[i][j] == dp[i - 1][j])
            i--;
        else if (dp[i][j] == dp[i][j - 1])
            j--;
        else
        {
            //when a[i - 1] == b[j-1]
            ans = a[i - 1] + ans;
            i--;
            j--;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 74164
#include<iostream>
#include<cstring>
#include<cassert>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
#include<vector>
#include<time.h>
#include<algorithm>
using namespace std;
#define REP(i,x,y) for(ll i=x;i<=y;i++)
#define rep(i,n) REP(i,1,n)
#define rep0(i,n) REP(i,0,n-1)
#define repG(i,x) for(ll i=pos[x];~i;i=e[i].next)
#define ll long long
#define db double
const ll N=407;
const ll INF=1e9+7;
const ll mod=998244353;
ll Pow(ll x,ll y){
	ll ans=1,now=x;
	while(y){
		if(y&1)ans=ans*now%mod;
		now=now*now%mod;
		y>>=1;
	}
	return ans;
}
ll n,S=0,Sb=0;
ll a[N],b[N],p[N],g[N][N],fac[N],inv[N],pw[N],d[N],w[N][N];

int main(){
	scanf("%lld",&n);
	rep(i,n)scanf("%lld%lld",&a[i],&b[i]);
	rep(i,n)S+=a[i];
	rep(i,n)Sb+=b[i];
	fac[0]=1;
	rep(i,Sb)fac[i]=fac[i-1]*i%mod;
	inv[Sb]=Pow(fac[Sb],mod-2);
	for(ll i=Sb;i;i--)inv[i-1]=inv[i]*i%mod;
	ll iv=Pow(S,mod-2);
	rep(i,n)p[i]=a[i]*iv%mod;
	memset(g,0,sizeof(g));
	rep(i,Sb){
		g[i][0]=1;
		rep(j,n){
			ll t=0;
			pw[0]=1;
			rep(k,b[j])pw[k]=pw[k-1]*p[j]%mod;
			for(ll k=b[j]-1;~k;k--)t=(t*i+pw[k]*inv[k])%mod;
			memset(d,0,sizeof(d));
			rep0(k,S){
				if(!g[i][k])continue;
				d[k+a[j]]=(d[k+a[j]]+g[i][k])%mod;
				d[k]=(d[k]-g[i][k]*t)%mod;
			}
			rep0(k,S)g[i][k]=d[k];
		}
	}
	memset(w,0,sizeof(w));
	rep(i,Sb){
		ll o=1;
		w[i][0]=1;
		rep(j,Sb){
			if(i==j)continue;
			o=o*(i-j+mod)%mod;
			for(ll k=Sb;k;k--)w[i][k]=(w[i][k-1]-j*w[i][k]%mod+mod)%mod;
			w[i][0]=(mod-w[i][0]*j%mod+mod)%mod;
		}
		int vo=Pow(o,mod-2);
		rep0(k,Sb)w[i][k]=w[i][k]*vo%mod;
	}
	ll ans=0;
	rep0(i,S){
		memset(d,0,sizeof(d));
		rep(j,Sb)rep0(k,Sb)d[k]=(d[k]+g[j][i]*w[j][k])%mod;
		rep0(k,Sb)ans=(ans+Pow(Pow((1-i*iv%mod+mod)%mod,k+1),mod-2)*fac[k]%mod*d[k])%mod;
	}
	printf("%lld\n",(mod-ans)%mod);
	return 0;
}


Measured memory_bytes: 2816
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String c = sc.next();
        char d = c.charAt(0);
        if(d=='a'||d=='i'||d=='u'||d=='e'||d=='o'){
            System.out.println("vowel");
        }else{
            System.out.println("consonant");
        }
    }
}


Measured memory_bytes: 9552
import sys
c=lambda w,n:reduce(lambda a,b:a+b,[chr((ord(x)-97+n)%26+97)if x.isalpha() else x for x in w])
for i in sys.stdin:
	n=0
	for s in i.replace(".","").split():
		r=c(s,116-ord(s[0]))
		m=len(s)
		if m==3 and"the"==r or m==4 and r in["this","that"]:n=116-ord(s[0])
	print c(i,n).replace("\n","")

Measured memory_bytes: 4328
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = (int)1e9;

// graph template
template<typename T>
class edge{
    public:
        int src, to; T cost;

        edge(){}
        edge(int to, T cost): src(-1), to(to), cost(cost){}
        edge(int src, int to, T cost): src(src), to(to), cost(cost){}
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using AdjacencyList = vector<Edges<T>>;
template<typename T>
using Matrix = vector<vector<T>>;

#ifndef UNION_FIND_TREE
#define UNION_FIND_TREE
class UnionFindTree{
	private:
		int N;
		unique_ptr<int[]> parent;
		unique_ptr<int[]> rank;
		unique_ptr<int[]> size;
	public:
		UnionFindTree(int N){
			this -> N = N;
			this -> parent = make_unique<int[]>(N);
			this -> rank = make_unique<int[]>(N);
			this -> size = make_unique<int[]>(N);
			for(int i = 0; i < (int) N; i++){
				parent[i] = i; rank[i] = 0; size[i] = 1;
			}
		}
		void init(){
			for(int i = 0; i < (int) N; i++){
				parent[i] = i; rank[i] = 0; size[i] = 1;
			}
		}
		int find(int x){
			if(parent[x] == x) return x;
			else return parent[x] = find(parent[x]);
		}
		void unite(int x, int y){
			x = find(x); y = find(y);
			if(x == y) return;

			if(rank[x] < rank[y]){
				parent[x] = y;
				size[y] += size[x];
			}else{
				parent[y] = x;
				size[x] += size[y];
				if(rank[x] == rank[y]) rank[x]++;
			}
		}
		bool isSame(int x, int y){
			return find(x) == find(y);
		}
		int count(int x){
			return size[find(x)];
		}
};
#endif

template<typename T>
T kruskal(Edges<T> &edges, int V){
    sort(edges.begin(), edges.end(), [](const edge<T> &a, const edge<T> &b){return a.cost < b.cost;});
    UnionFindTree tree(V);
    
    T ret = 0;
    for(auto &e: edges){
        if(not tree.isSame(e.src, e.to)){
            ret += e.cost;
            tree.unite(e.src, e.to);
        }
    }

    return ret;
}

int main(void){
    int V, E;
    cin >> V >> E;

    Edges<int> edges(V);
    for(int i = 0; i < E; i++){
        int s, t, w;
        cin >> s >> t >> w;
        edges.emplace_back(edge<int>(s, t, w));
    }

    cout << kruskal(edges, V) << '\n';

    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++)
#define all(x) (x).begin(),(x).end()
const double PI = acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;

int main() {
  int X,Y,Z,K; cin >> X >> Y >> Z >> K;
  vector<ll> A(X),B(Y),C(Z);
  rep(i,X) cin >> A[i];
  rep(i,Y) cin >> B[i];
  rep(i,Z) cin >> C[i];

  sort(all(A)); sort(all(B)); sort(all(C));
  reverse(all(A)); reverse(all(B)); reverse(all(C));

  priority_queue<tuple<ll, int, int, int>> pq;
  pq.push(make_tuple(A[0]+B[0]+C[0],0,0,0));
  set<tuple<int, int, int>> s;
  s.insert(make_tuple(0,0,0));

  
  vector<ll> ans(K);
  rep(i,K) {
    ll num;
    int a,b,c;
    tie(num,a,b,c) = pq.top(); pq.pop();
    ans[i] = num;
    if (a != X-1 && !s.count(make_tuple(a+1,b,c))) {
      pq.push(make_tuple(A[a+1]+B[b]+C[c],a+1,b,c));
      s.insert(make_tuple(a+1,b,c));
    }
    if (b != Y-1 && !s.count(make_tuple(a,b+1,c))) {
      pq.push(make_tuple(A[a]+B[b+1]+C[c],a,b+1,c));
      s.insert(make_tuple(a,b+1,c));
    }
    if (c != Z-1 && !s.count(make_tuple(a,b,c+1))) {
      pq.push(make_tuple(A[a]+B[b]+C[c+1],a,b,c+1));
      s.insert(make_tuple(a,b,c+1));
    }
  }

  rep(i,K) cout << ans[i] << endl;
}

Measured memory_bytes: 896
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include<queue>
using namespace std;
int gcd(int a,int b)
{
    if(b == 0)
        return a;
    return gcd(b,a%b);
}
int main() {
    char a,b;
    while(cin>>a>>b)
    {
        if(a=='H')
        {
            if(b=='H')
                cout<<"H"<<endl;
            else
                cout<<'D'<<endl;
        }
        if(a=='D')
        {
            if(b=='H')
                cout<<"D"<<endl;
            else
                cout<<'H'<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
input = readlines()

meta = input.shift.chomp.split("\s").map{|x| x.to_i}

target_num = meta[0]

forbid_list = input.shift.split("\s").map{|x| x.to_i}

nearlest = nil
n_abs = nil
(-100..200).each do |x|
  next if forbid_list.include?(x)
  c_abs = (target_num - x).abs
  if n_abs.nil? || c_abs <= n_abs
    if n_abs.nil? || c_abs < n_abs
      nearlest = x
      n_abs = c_abs
      next
    end
    if c_abs == n_abs && nearlest > x
      nearlest = x
      n_abs = c_abs
    end
  end
end

puts nearlest


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

void solve(int d,int e){
    vector<double> v;
    for(int i=0;i<=d/2;i++){
        v.push_back(fabs(sqrt(i*i+(d-i)*(d-i))-e));
    }
    sort(v.begin(),v.end());
    cout<<setprecision(5)<<v.front()<<endl;
}

int main(void){
    int a,b;
    while(cin>>a>>b,a){
        solve(a,b);
    }
    
    
    
}

Measured memory_bytes: 3208
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

#define pv(val) cerr << #val << '=' << (val) << endl
#define pvn(name, val) cerr << name << '=' << (val) << endl
#define pl cerr << '@' << __LINE__ << endl

using namespace std;

using ll = int64_t;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

template <class T>
ostream &operator<<(ostream &os, vector<T> const &vec) {
    if (vec.empty()) {
        os << "{}";
    } else {
        os << '{';
        for (size_t i = 0; i < vec.size() - 1; i++) os << vec[i] << ", ";
        os << vec.back() << '}';
    }
    return os;
}

template <class T, size_t S>
ostream &operator<<(ostream &os, array<T, S> const &arr) {
    if (arr.empty()) {
        os << "{}";
    } else {
        os << '{';
        for (size_t i = 0; i < arr.size() - 1; i++) os << arr[i] << ", ";
        os << arr.back() << '}';
    }
    return os;
}

template <class T, class U>
ostream &operator<<(ostream &os, pair<T, U> const &p) {
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

namespace math {
ll gcd(ll u, ll v) {
    while (v != 0) {
        ll r = u % v;
        u = v;
        v = r;
    }
    return u;
}
ll lcm(ll m, ll n) {
    if ((0 == m) || (0 == n)) return 0;

    return ((m / math::gcd(m, n)) * n);
}
}  // namespace math

struct UnionFind {
    vector<ll> data;
    UnionFind(ll size) : data(size, -1) {}
    bool unionSet(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x != y) {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y];
            data[y] = x;
        }
        return x != y;
    }
    bool findSet(ll x, ll y) { return root(x) == root(y); }
    ll root(ll x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
    ll size(ll x) { return -data[root(x)]; }
};

template <class T, class U>
pair<T, U> operator+(pair<T, U> const &a, pair<T, U> const &b) {
    return pair<T, U>(a.first + b.first, a.second + b.second);
}

template <class T, class U>
pair<T, U> operator-(pair<T, U> const &a, pair<T, U> const &b) {
    return pair<T, U>(a.first - b.first, a.second - b.second);
}

ll bound(function<bool(ll)> f, ll ng, ll ok) {
    while (abs(ng - ok) > 1) {
        ll mid = (ng + ok) / 2;
        if (f(mid))
            ok = mid;
        else
            ng = mid;
    }

    return ok;
}

int main(void) {
    ll A, P;
    cin >> A >> P;
    ll const T = 3 * A + P;

    cout << T / 2 << endl;

    return 0;
}


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

int main(){
  string pd;
  cin >> pd;
  
  if(pd[0] == '?'){
    pd[0] = 'D';
  }
  
  for(int i=1; i < pd.size(); i++){
    if(pd[i] == '?' && pd[i-1] == 'P'){
      pd[i] = 'D';
    }
    else if(pd[i] == '?' && pd[i-1] == 'D'){
      pd[i] = 'D';
    }
  }
  
  
  cout << pd << endl;
  
}

Measured memory_bytes: 3760
#include<stdio.h>
int main()
{
	int k,a,b,x,z;
	scanf("%d %d %d",&k,&a,&b);
	x=1;
	z=0;
	while(1){
		if(z>=a) break;
		z=k*x;
		x++;
	}
	if(z>=a&&z<=b) printf("OK\n");
	else printf("NG\n");
	return 0;
}


Measured memory_bytes: 1656
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;

int main(int argc, char *argv[]){

  int N;
  cin>>N;
  vector<int> A(N);
  int a;
  int mcount=0;
  int zerocount=0;
  for(int i=0; i<N; i++){
    cin>>a;
    A[i]=a;
    if(a<0) mcount++;
    if(a==0) zerocount++;
  }
  if(mcount%2==0 || zerocount!=0){
   
    long long sum=0;
    for(int i=0; i<N; i++){
      sum+=abs(A[i]);
    }
    cout<<sum<<endl;
    return 0;
  }
  else{
    vector<int> tmp(N);
    for(int i=0; i<N; i++){
      tmp[i]=abs(A[i]);
    }
    int min = *std::min_element(tmp.begin(), tmp.end());
    long long sum=0;
    for(int i=0; i<N; i++){
      sum+=abs(A[i]);
    }
    sum=sum-(2*min);
    cout<<sum<<endl;
  }
}
  



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int x=n%10;
	if (x==3)
	{
		cout<<"bon"<<endl;
	}
	else if (x==0||x==1||x==6||x==8)
	{
		cout<<"pon"<<endl;
	}
	else
		cout<<"hon"<<endl;
}


Measured memory_bytes: 3620
#include<iostream>
using namespace std;
int main()
{
  long int i,n,m;
  cin>>n;
  cin>>m;
  long long int count=0,a;
  for(i=0;i<m;i++)
  {
    cin>>a;
    count+=a;
  }
  if((n-count)>=0)
	cout<<(n-count);
  else
	cout<<"-1";
  return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<algorithm>
#include<set>
#include<queue>
#include<stack>
#include<list>
#include<iostream>
#include<fstream>
#include<numeric>
#include<string>
#include<vector>
#include<cstring>
#include<map>
#include<iterator>

using namespace std;
#define EPS 1e-9
#define MAX 505
#define pb push_back
#define mp make_pair
#define ins insert
#define fi first
#define se second
#define pi acos(-1.0)
#define mod 100000007
#define inf 2147483647
#define ll long long int
#define sss stringstream
#define oss ostringstream
#define iss istringstream
#define llu long long unsigned

#define _sq(a) (a)*(a)
#define sz(a) ((int)a.size())
#define gcd(a,b)    __gcd(a,b)
#define lcm(a,b) ((a)*((b)/gcd(a,b)))
#define _max3(a,b,c) max(a, max(b,c))
#define _min3(a,b,c) min(a, min(b,c))
#define FOR(i, n) for(i=0; i<(int)n; i++)
#define FOR1(i, n) for(i=1; i<=(int)n; i++)
#define mem(a) memset(a, 0, sizeof(a))
#define _set(a) memset(a,-1,sizeof(a))
#define FORI(i, a, b) for(i=a; i>=(int)b; i--)
#define FORab(i, a, b) for(i=a; i<=(int)b; i++)
#define popcount(n) __builtin_popcount(n)
#define popcountl(n) __builtin_popcountll(n)
#define sort_rev(a) sort(a.rbegin(), a.rend())
#define sort_all(a) sort(a.begin(), a.end())
#define dis_twopoints(x1,y1,x2,y2) sqrt(_sq(x1-x2) + _sq(y1-y2))
#define foreach(i,n) for(__typeof((n).begin())i =(n).begin();i!=(n).end();i++)

//If Long Long (mask & (1LL << k))
#define check(mask, k) (mask & (1 << k))
#define set1(mask, k) (mask | (1 << k))
#define set0(mask ,k) (mask & (~(1<<k)))

#define SD(a) scanf("%d",&a)
#define SLF(a) scanf("%lf",&a)
#define SC(a) scanf("%c",&a)
#define SS(a) scanf("%s",a)
#define SLLD(a) scanf("%lld", &a)
#define Si64(a) scanf("%I64d", &a)

#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)

int main()
{
     int i,j;
     for(i=1;i<=9;i++)
     {
         for(j=1;j<=9;j++)
         {
             cout<<i<<"x"<<j<<"="<<i*j<<endl;
         }
     }
    return 0;
}

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

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

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


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    int x[105],y[105],h[105];
    int exx=0,exy=0,exh=0;
    cin >> n;
    rep(i,n){
        cin >> x[i] >> y[i] >> h[i];
        if(h[i]>0){
            exx=x[i];
            exy=y[i];
            exh=h[i];
        }
    }

    for(int cx =0;cx<=100;cx++){
        for(int cy=0;cy<=100;cy++){
            int ch = exh + abs(exx-cx) + abs(exy-cy);
            bool isPyra = true;
            for(int i=0;i<n;i++){
                if(max(ch-abs(x[i]-cx)-abs(y[i]-cy),0)!=h[i]){
                    isPyra = false;
                }
            }
            if(isPyra){
                cout << cx << ' ' << cy << ' ' << ch << endl;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
S = input()
a, b = int(S[:2]), int(S[2:])
if (a == 0 or 12 < a) and 1 <= b <= 12:
  print('YYMM')
elif 1 <= a <= 12 and (b == 0 or 12 < b):
  print('MMYY')
elif 1 <= a <= 12 and 1 <= b <= 12:
  print('AMBIGUOUS')
else:
  print('NA')

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main() {
    int N;
    string S;
    cin >> N >> S;
    int l = S.size();
    if (l%2 == 1) {
        cout << "No" << endl;
    } else {
        l /= 2;
        string T1 = S.substr(0,l);
        string T2 = S.substr(l,l);
        if (T1 == T2) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
    return 0;
}


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

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
using edge = struct {
  int to;
  int cost;
};
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define BITS(n, num) std::bitset<(n)>((num)).to_string()
#define REV <T> greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N, Q;
  string S;
  cin >> N >> Q >> S;
  vl l(Q, 0), r(Q, 0), DP(N + 1, 0);
  REP(i, Q) cin >> l[i] >> r[i];
  bool ok = false;
  FOR(i, 1, N + 1) {
    DP[i] = DP[i - 1];
    if (S[i - 1] == 'A')
      ok = true;
    else if (ok && S[i - 1] == 'C') {
      ok = false;
      DP[i]++;
    } else {
      ok = false;
    }
  }
  REP(i, Q) { cout << DP[r[i]] - DP[l[i]] << endl; }

  return 0;
}


Measured memory_bytes: 3392
import math

N, K = list(map(lambda k: int(k), input().split(" ")))

# dice -> n
# n * 2^x >= K
# 2^x >= K / n
# x >= log2 (K / n)

p = [1 * (1/2) ** max([math.ceil(math.log2(K/(i + 1))), 0]) for i in range(N)]
print(sum(p)/N)

Measured memory_bytes: 13012
#include <cstdio>
#include <algorithm>
using namespace std;
int ans[100001];
int dp(int x) {
	if (x < 0) return false;
	if (ans[x] != -1) return ans[x];
	if (x == 0) return ans[x] = true;
	return ans[x] = dp(x - 100) | dp(x - 101) | dp(x - 102) | dp(x - 103) | dp(x - 104) | dp(x - 105);
}
int main() {
	fill_n(ans, 100001, -1);
	int X;
	scanf("%d", &X);
	printf("%d", dp(X));
	return 0;
}

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

int main() {
  int64_t N, A, B;
  cin >> N >> A >> B;
  int64_t x, y, z, a;
  x = A + B;
  y = N / x;
  z = N % x;
  if(z > A) {
    a = A * (y + 1);
  }
  else {
    a = A * y + z;
  }
  cout << a << endl;
}

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

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

#define show(x) cout << #x << " = " << x << endl

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz=" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}

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


constexpr ll MOD = 1e9 + 7;

template <typename T>
constexpr T INF = numeric_limits<T>::max() / 100;

int main()
{
    ll N, M;
    cin >> N >> M;
    if (M <= 2 * N) {
        cout << M / 2 << endl;
        return 0;
    }
    cout << N + (M - 2 * N) / 4 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

int main() {
	ll n,k;
	cin>>n>>k;
	ll v[50];
	for(ll i=0;i<n;i++){
		cin>>v[i];
	}
	ll ans=0;
	for(ll i=0;i<=min(n,k);i++){
		for(ll j=0;j<=i;j++){
			vector<ll>g;
			for(ll l=0;l<j;l++){
				g.push_back(v[l]);
			}
			for(ll l=0;l<i-j;l++){
				g.push_back(v[n-1-l]);
			}
			sort(g.begin(),g.end());
			reverse(g.begin(),g.end());
			for(ll l=0;l<k-i;l++){
				if(g.size()!=0&&g[g.size()-1]<0){
					g.pop_back();
				}
			}
			ll cnt=0;
			for(auto itr=g.begin();itr!=g.end();itr++){
				cnt+=*itr;
			}
			ans=max(ans,cnt);
		}
	}
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 256