akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    int H,W,A,B;
    cin >> H >> W >> A >> B;
    vector<vector<char>> G(H,vector<char>(W,'0'));
    for(int i=0;i<B;i++){
        for(int j=0;j<A;j++){
            G[i][j] = '1';
        }
    }
    for(int i=B;i<H;i++){
        for(int j=A;j<W;j++){
            G[i][j] = '1';
        }
    }
    rep(i,H){
        rep(j,W){
            cout << G[i][j];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 4600
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <climits>
typedef long long ll;
using namespace std;

int main(void){
  ll i,j,n,m,sum=0;
  static pair<ll,ll> a[100010]; //b,a
  
  cin>>n>>m;

  vector<ll> sch(m+2,-1);

  for(i=0;i<n;i++){
    cin>>a[i].second>>a[i].first;
  }

  sort(a,a+n);

  int day,tmp;
  vector<int> skip;
  for(i=0;i<n;i++){
    day=a[n-i-1].second;
    if(day<=m){
      skip.clear();
      while(sch[day]!=-1){
        skip.push_back(day);
        day=sch[day];
      }
      
      if(day<=m){
        for(j=0;j<skip.size();j++){
          sch[skip[j]]=day+1;
        }
        sch[day]=day+1;

        sum+=a[n-i-1].first;
      }
    }
  }

  cout<<sum<<endl;

  return 0;
}



Measured memory_bytes: 2560
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

int n, use;
string cur, p, q;
vector<string> vec;

void recurse(){
	if((int)cur.length() < n){
		for(int i = 1; i <= n; i++)
			if((1 << i) & use){
				cur += i + '0';
				use = use ^ (1 << i);
				recurse();
				cur.pop_back();
				use = use ^ (1 << i);
			}
	}else vec.push_back(cur);
}

int main(){
	//IO("input.txt", "output.txt");
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n;
	for(int i = 0; i < n; i++){
		char num;
		cin >> num;
		p += num;
	}
	for(int i = 0; i < n; i++){
		char num;
		cin >> num;
		q += num;
	}
	use = (1 << (n + 1)) - 1;
	recurse();
	sort(vec.begin(), vec.end());
	int a = -1, b = -1;
	for(int i = 0; i < (int)vec.size(); i++){
		if(vec[i] == p) a = i;
		if(vec[i] == q) b = i;
	}
	cout << abs(a - b) << "\n";
	return 0;
}

Measured memory_bytes: 2424
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL


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

    int N, M;
    cin >> N >> M;

    vector< priority_queue<int> > vpq(N);
    vector< pair<int, int> > key(M);
    map< pair<int, int>, int > m;
    int p, y;
    rep (i, M)
    {
        cin >> p >> y;
        --p;
        vpq[p].push(-y);
        key[i] = make_pair(p, y);
    }

    rep (i, N)
    {
        int cnt = 1;
        while (!vpq[i].empty())
        {
            y = vpq[i].top(); vpq[i].pop();
            m[make_pair(i, -y)] = cnt;
            ++cnt;
        }
    }

    rep (i, M)
    {
        cout << setw(6) << setfill('0') << key[i].first + 1 << setw(6) << setfill('0') << m[key[i]] << "\n";
    }

    return 0;
}



Measured memory_bytes: 14848
from collections import deque

tokens = input().split()
dq = deque()
operators = "+-*"
for token in tokens:
    if token in operators:
        a = dq.pop()
        b = dq.pop()
        if token == "+":
            dq.append(b + a)
        elif token == "-":
            dq.append(b - a)
        else:
            dq.append(b * a)
    else:
        dq.append(int(token))
print(dq.pop())



Measured memory_bytes: 5996
N = int(input())
l = list(map(int, input().split()))
import itertools

total = sum(l)
cumsum = list(itertools.accumulate(l))

i = 0
sig = 0
for cus in cumsum:
    rest = (total - cus)
    
    sig += (l[i] * rest)
    i +=1
    
    
print(sig % (10**9 + 7))

Measured memory_bytes: 31624
/*╔═══╗──╔╗╔╗───────────────────╔╗────────╔═══╦═══╗
  ║║─║╠╗╠╗╔╣╚═╦══╦═╗╔╦╗╔═╗╔══╦══╣╚═╦╦══╦══╣║─║║║─╚╝
  ║╔═╗║╚╝║╚╣║║║╚╝║║─╔╦╗║║║║╚╝║╚╝║╚╝║║║═╬══║╔═╗║╚╩═║
  ╚╝─╚╩══╩═╩╝╚╩══╩╝─╚╩╝╚╝╚╩══╩══╩══╩╩══╩══╩╝─╚╩═══╝*/

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

#define f(i,k,n) for(i=k;i<n;i++)
#define fd(i,k,n) for(i=k;i>n;i--)
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define vvll vector<vll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define all(c) c.begin(),c.end()
#define sz(c) (int)c.size()
#define lb lower_bound
#define ub upper_bound
#define gi greater<int>
#define rev reverse
#define ff first
#define ss second
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define imp cout << "IMPOSSIBLE" << endl;
#define nl cout << endl
#define hello cout << "hello" << endl;
#define sp(x) fixed << setprecision(x)
#define re return

void dbg_out(){cerr << endl;}
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)

const double pi = 3.14159265359;
const ll mod = 1000000007;
const ll modc = 998244353;

ll inline power(ll a, ll b, ll p){
    a %= p;
    ll ans = 1;
    while(b>0){
        if(b & 1)
            ans = (ans*a)%p;
        a = (a*a)%p;
        b >>= 1;
    }
    return ans;
}

ll mod_inv(ll n, ll p){
    return power(n,p-2, p);
}

bool inline isPrime(ll n) {
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    for (ll i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;
    return true;
}
template<typename... T>
void W(T&&... args)
{
	((cout << sp(9) <<  args << " "), ...);
	nl;
}
template<typename... T>
void R(T&&... args)
{
	((cin >> args), ...);
}
ll ston(string s) 
{
	ll a = 0;
	reverse(s.begin(),s.end());
	ll pow = 1;
	for(int i=0;i<s.size();i++)
	{
		a += pow*(s[i]-'0');
		pow*=10;
	}
	return a;
}
template <class T>
string to_binary(T n) 
{
	string binaryNum;
	int i = 0;
	while (n > 0) {
		binaryNum.pb((n % 2)+'0');
		n = n / 2;
		i++;
	}
	reverse(binaryNum.begin(),binaryNum.end());
	return binaryNum;
}
template<class T>
void wv(T &v)
{
	for(auto x : v)
		cout << x << " " ;
	nl;
}
template<class T>
void rv(T &v)
{
	for(int i=0;i<sz(v);i++)
		cin >> v[i];
}
void solve()
{
	int i,j;ll sum = 0,prod = 1;ll maxl = LONG_MIN,minl = LONG_MAX;int maxi = INT_MIN,mini = INT_MAX;
	int n;
	cin >> n;
	vll a(n);
	rv(a);
	ll xorr = a[0];
	for(i=1;i<n;i++)
		xorr ^= a[i];
	for(i=0;i<n;i++)
		a[i] ^= xorr;
	wv(a);
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t = 1;
	while(t--)
	{
		solve();
	}
}


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

class union_find {
public:
  vector<ll> data;

  union_find(){};
  union_find(ll size) { data.assign(size, -1); }

  bool unite(ll x, ll y) {
    x = root(x);
    y = root(y);
    if (x == y) {
      return false;
    }
    if (data[x] > data[y]) {
      swap(x, y);
    }
    data[x] += data[y];
    data[y] = x;
    return true;
  }

  ll root(ll x) {
    if (data[x] < 0) {
      return x;
    }
    else {
      return data[x] = root(data[x]);
    }
  }

  ll size(ll x) { return (-data[root(x)]); }
};

ll n, m;
vector<ll> a, b;

void abc120d() {
  union_find uf = union_find(n + 1);
  vector<ll> ans(m + 1);
  ans[m] = n * (n - 1) / 2;
  for (ll i = m - 1; i >= 1; i--) {
    ll tmp = uf.size(a[i]) * uf.size(b[i]);
    if (uf.unite(a[i], b[i])) {
      ans[i] = ans[i + 1] - tmp;
    }
    else {
      ans[i] = ans[i + 1];
    }
  }

  for (ll i = 1; i <= m; i++) {
    cout << ans[i] << '\n';
  }
  return;
}

int main() {
  cin >> n >> m;
  a.resize(m);
  b.resize(m);
  for (ll i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
  }
  abc120d();
  return 0;
}


Measured memory_bytes: 4480
from math import *
n = int(input())
ps = set(range(2, 55556))
for i in range(2, floor(sqrt(55555) + 1)):
    if i in ps:
        k = 2
        while(i*k <= 55555):
            if i*k in ps:
                ps.remove(i*k)
            k += 1
ans = []
i = max(ps)
while len(ans) < n and i <= 55555:
    if i in ps:
        ans.append(i)
    i -= 25
print(*ans)

Measured memory_bytes: 43504
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
int h, w;
int main() {
	cin>>h>>w;
	ll ans = (ll)h*(ll)w;
	if (h >= 3) {
		if (h%3 == 0) ans = min(ans, 0LL);
		else {
			ans = min(ans, (ll)w);
		}
	}
	if (w >= 3) {
		if (w%3 == 0) ans = min(ans, 0LL);
		else {
			ans = min(ans, (ll)h);
		}
	}
	for (int j = 1; j < w; ++j) {
		vector<ll> xs;
		xs.clear();
		xs.push_back((ll)j * (ll)h);
		if (h % 2 == 0) {
			xs.push_back((ll)(w-j) * (ll)h / 2);
		} else {
			xs.push_back((ll)(w-j) * (ll)(h / 2));
			xs.push_back((ll)(w-j) * (ll)((h+1)/2));
		}
		sort(xs.begin(), xs.end());
		ans =min(ans, (ll)(xs.back()-xs[0]));
	//	cout<<j<<" "<<ans<<endl;
	}
	for (int i = 1; i < h; ++i) {
		vector<ll> xs;
		xs.clear();
		xs.push_back((ll)i * (ll)w);
		if (w % 2 == 0) {
			xs.push_back((ll)(h-i) * (ll)w / 2);
		} else {
			xs.push_back((ll)(h-i) * (ll)(w / 2));
			xs.push_back((ll)(h-i) * (ll)((w+1)/2));
		}
		sort(xs.begin(), xs.end());
		ans = min(ans, (ll)(xs.back()-xs[0]));
	//	cout<<i<<" "<<ans<<endl;
	}
	cout<<ans<<endl;
	return 0;
}

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

int main() {
  int N,Q,a,b;
  int count=0;
  int c=0;
  string S;
  cin >> N >> Q >> S;
  vector<int> mozi(N);
  for (int i=0; i<N-1 ; i++){
    if (S.at(i)=='A'){
      if (S.at(i+1)=='C'){
        c=c+1;
        mozi.at(i+1)=c;
      }
      else{
        mozi.at(i+1)=c;
      }
      
    }
    else{
      mozi.at(i+1)=c;
    }
  }
  for (int i=0; i<Q; i++){
    cin >> a >> b;
    cout << mozi.at(b-1)-mozi.at(a-1) <<endl;
    count=0;
  }
}

Measured memory_bytes: 1408
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
using namespace std;

#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

#define int ll
#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(int i=(a),i##_cond=(b);i<i##_cond;++i)
#define ROF(i,a,b) for(int i=(a)-1,i##_cond=(b);i>=i##_cond;--i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define sz(x) ((int)(x).size())
#define pb push_back
#define fst first
#define snd second
#define mp make_pair
using ll  = long long;
using vi  = vector<int>;
using vvi = vector<vi>;
using vs  = vector<string>;
using pii = pair<int,int>;
// constexpr ll inf = 1ll<<61;
// constexpr ll mod = 1e9+7;

signed main(){
  int n,m; cin >> n >> m;
  vi x(m); rep(i,m) cin >> x[i];
  sort(all(x));

  priority_queue<int> q;
  rep(i,m-1) q.push(x[i]-x[i+1]);

  int ans = 0;
  rep(i,m-n){
    ans -= q.top();
    q.pop();
  }
  cout << ans << endl;
}


Measured memory_bytes: 2168
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for (int i=a; i<b; ++i)
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin >> s;
    int A=0, B=0;
    loop(i,0,s.length()){
        if (s[i]=='A') A=1;
        if (s[i]=='B') B=1;
    }
    if (A&&B) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}

Measured memory_bytes: 384
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE TypeFamilies #-}
import           Data.Maybe
import           Data.Int
import           Data.List
import           Data.Char
-- import qualified Data.Vector.Unboxing as VU
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as BS
import           Data.List (scanl')
import           Data.IORef
import           Control.Monad
import           Control.Monad.ST
import           Control.Monad.State.Strict
import           Control.Applicative
import           Debug.Trace
import           Text.Printf


readInt = BS.readInt . BS.dropWhile isSpace
getVector f = VU.unfoldr f <$> BS.getLine
getIntVector = getVector readInt
getBSVector = getVector BS.uncons
getInt = readLn :: IO Int
getInt2Tuple = (\vec -> (vec VU.! 0, vec VU.! 1)) <$> getIntVector
getInt3Tuple = (\vec -> (vec VU.! 0, vec VU.! 1, vec VU.! 2)) <$> getIntVector


main = do
  n <- getInt
  as <- getIntVector
  bs <- getIntVector
  print . VU.sum $ solve n as bs
  -- print 1

solve :: Int -> VU.Vector Int -> VU.Vector Int -> VU.Vector Int
solve n as bs = VU.create $ do
  dp <- VUM.replicate (n+1) (0 :: Int)

  forM_ [0..n-1] $ \i -> do
    nowToubatu <- VUM.read dp i
    let nowA = as VU.! i
        nextA = as VU.! (i+1)
        nowB = bs VU.! i
        nowMonster = nowA - nowToubatu
    if (nowB <= nowMonster)
      then do
      VUM.modify dp (\n -> n + nowB) i
      else do
      VUM.modify dp (\n -> n+nowMonster) i
      VUM.modify dp (\n -> n + min nextA (nowB - nowMonster)) (i+1)


  return dp

-- solve n as bs = undefined
--   where
--     go res carry (m:ms) (y:ys)
--       | m <= carry = go (res+y) m ms ys
--       | z <- min y (m + carry) = go (res + z) (m - (z -carry)) ms ys


Measured memory_bytes: 11132
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma warning(disable : 4996)
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>
#include<array>


using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), (n))
#define ub(v,n) upper_bound(v.begin(), v.end(), (n))
#define int long long
//#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
typedef array<int, 3> arr3;
std::random_device rd;
std::mt19937 mt(rd());
constexpr ll MOD = 1e9+7; constexpr int MAX = 2000020;
const double pi = acos(-1); constexpr double EPS = 1e-8;
constexpr ll INF = 1e18;
void y(bool cond) {
	if (cond)print("Yes");
	else print("No");
}
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll add(ll x, ll y) {
	x += y;
	if (x >= MOD) return x - MOD;
	return x;
}
ll sub(ll x, ll y) {
	x -= y;
	if (x < 0) return x + MOD;
	return x;
}
ll mult(ll x, ll y) {
	return (x * y) % MOD;
}
ll bin_pow(ll x, ll p) {
	if (p == 0) return 1;
	if (p & 1) return mult(x, bin_pow(x, p - 1));
	return bin_pow(mult(x, x), p / 2);
}
int cnt[26];
void solve() {
	int N; cin >> N;
	vector<int>A(N), B(N), C(N);
	REP(i, N) {
		cin >> A[i];
	}
	REP(i, N)cin >> B[i];
	REP(i, N)cin >> C[i];
	VSORT(A); VSORT(B); VSORT(C);
	vector<int>cumB(N + 1);
	REP(i, N) {
		int cnt = C.end() - ub(C, B[i]);
		cumB[i] = cnt;
	}
	REPR(i, N) {
		cumB[i] += cumB[i + 1];
	}
	ll ans = 0;
	REP(i, N) {
		int id = ub(B, A[i])-B.begin();
		ans += cumB[id];
	}
	print(ans);
}


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q; cin >> q;
	//while (q--)
	solve();
}



Measured memory_bytes: 3456
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int n,ans=0;
    cin>>n;
    map<int,int> s;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        s[a-1]++;
    }
    for(auto x:s){
        if(x.second%2==1)ans++;
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

int main(int argc,char const* argv[])
{
  long long n,m;
  long long ans=0;
  int p;
  long long down;
  cin >> n >> m;
  down=min(n,m/2);
  ans+=down;
  n-=down;
  m-=down*2;
  ans+=m/4;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import collections as c
ip = lambda : map(int, input().split())

# ##############
N,M = ip()
L,R = ip()
for i in range(1,M):
    l,r = ip()
    if R<l or r<L:
        print(0)
        exit()
    L = max(L,l)
    R = min(R,r)
print(R-L+1)

Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define LL long long

const int mod = 1e9 + 7;
const int N = 1e6 + 5;
const int M = 2e6 + 5;

int n, k;
int m, fac[M] = {1}, inv[M];
char str[N];

LL tot, mis;

int mul(int ta, int tb) {
	int ret;
	__asm__ __volatile__ ("\tmull %%ebx\n\tdivl %%ecx\n":"=d"(ret):"a"(ta), "b"(tb), "c"(mod));
	return ret;
}

int qpow(int bas, int po) {
	int res = 1;
	while(po) {
		if(po & 1)
			res = mul(res, bas);
		bas = mul(bas, bas);
		po >>= 1;
	}
	return res;
}

int C(int tn, int tm) {
	return mul(fac[tn], mul(inv[tm], inv[tn - tm]));
}

int32_t main() {
	
	scanf("%d %s", &k, str + 1);
	
	n = strlen(str + 1);
	m = n + k;

	tot = qpow(26, m);
	
	for(int i = 1; i <= m; ++i)
		fac[i] = mul(fac[i - 1], i);
	for(int i = 0; i <= m; ++i)
		inv[i] = qpow(fac[i], mod - 2);

	for(int i = 0; i <= n - 1; ++i) {
		mis = (mis + mul(C(m, i), qpow(25, m - i))) % mod;
	}
	
	tot = ((tot - mis) % mod + mod) % mod;
	
	printf("%d", tot);

	return 0;
}

Measured memory_bytes: 20352
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include <cmath>
using namespace std;

#define mod 1000000007
#define ten5 100005
#define ten52 200005
#define ten53 300005
#define ten6 1000005
#define PI 3.1415926
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()
#define mkpr(x1,x2) make_pair(x1,x2)
typedef long long int ll;

//stack<char> stk;
//set<ll> sll;
//set<pair<ll,ll>> spll;
//map<string,ll> mp;
//map<ll,ll> mp;
//deque<ll> deq;
vector<ll> vll;
ll num[ten52],num2[ten52];
//priority_queue<pair<ll,ll>> pq;          //decreasing

int main(void)
{
    ll m,n,i,j,k=0,k1=0;
    string s;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>m;
        num[i-1]=m-i;
    }
    sort(num,num+n);
    m=n/2;
    if(n&1==1)
    {
        for(i=0;i<n;i++)
            k+=abs(num[i]-num[m]);
    }
    else
    {
        for(i=0;i<n;i++)
        {
            k+=abs(num[i]-num[m]);
            k1+=abs(num[i]-num[m-1]);
        }
        k=min(k,k1);
    }
    cout<<k;
    return 0;
}





Measured memory_bytes: 5200
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);

	ll n;
	cin >> n;

	vector<vector<ll>> abc(n, vector<ll> (3, 0)), dp(n, vector<ll> (3, 0));

	for (ll i = 0; i < n; i++)	cin >> abc[i][0] >> abc[i][1] >> abc[i][2];

	dp[0][0] = abc[0][0];
	dp[0][1] = abc[0][1];
	dp[0][2] = abc[0][2];

	for (ll i = 1; i < n; i++) {
		dp[i][0] =  max(dp[i - 1][1] + abc[i][0], dp[i - 1][2] + abc[i][0]);
		dp[i][1] =  max(dp[i - 1][0] + abc[i][1], dp[i - 1][2] + abc[i][1]);
		dp[i][2] =  max(dp[i - 1][0] + abc[i][2], dp[i - 1][1] + abc[i][2]);
	}

	cout << *max_element(dp[n - 1].begin(), dp[n - 1].end())  << endl;
	return 0;
}

Measured memory_bytes: 11264
s = input()
s = s[::-1]
mod = 10 ** 9 + 7
table = [[0] * 13 for _ in range(len(s) + 2)]
table[0][0] = 1
dd = 1
for c in range(len(s)):
    if s[c] == "?":
        for n in range(10):
            for i in range(13):
                table[c + 1][(i + n * dd) % 13] += table[c][i]
                table[c + 1][(i + n * dd) % 13] %= mod
    else:
        num = int(s[c])
        for i in range(13):
            table[c + 1][(i + num * dd) % 13] += table[c][i]
            table[c + 1][(i + num * dd) % 13] %= mod
    dd = (dd * 10) % 13
print(table[c + 1][5])

Measured memory_bytes: 61916
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <random>
#include <queue>

using namespace std;

using Graph = vector<vector<int> >;

vector<int> seen;

int main()
{
	int N;

	cin >> N;

	if (N == 1) {
		cout << 1;
		return 0;
	}

	int v;
	int max_v = 0;
	for (int ni = 2; ni < 34; ni++) {
		v = ni * ni;
		while (v <= N) {
			max_v = max(max_v, v);
			v *= ni;
		}
	}

	int ans = max_v;
	//printf("%.9f", ans);
	std::cout << ans;

	return 0;
}



Measured memory_bytes: 256
x = gets.chomp.to_i
s = x.to_s

if x < 100
  puts 0
  exit
end

head = s[0...-2].to_i
tail = s[-2..-1].to_i

cnt = (tail / 5.0).ceil

if head >= cnt
  puts 1
else
  puts 0
end


Measured memory_bytes: 1788
#include<iostream>
using namespace std;
int N,p[51],s=0;
int main(void){
	cin>>N;
	for(int i=1;i<=N;i++){
		cin>>p[i];
		if(p[i]!=i)s++;
	}
	if(s>2)cout<<"NO";
	else cout<<"YES";
	return 0;
}

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

using namespace std;

using ll = long long;

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

vector<int> koho;

void dfs(int n, const string& nums, string s) {
    if (n == 0) {
        if (s.size() > 0) koho.push_back(stoi(s));
        return;
    }
    dfs(n - 1, nums, s);
    for (char c : nums) dfs(n - 1, nums, s + c);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    vector<bool> num(10, true);
    for (int i = 0; i < K; ++i) {
        int d;
        cin >> d;
        num[d] = false;
    }
    string nums;
    for (int i = 0; i < 10; ++i) {
        if (num[i]) nums += to_string(i);
    }
    dfs(6, nums, "");
    int ans = 0;
    sort(koho.begin(), koho.end());
    for (int i : koho) {
        if (i >= N) {
            ans = i;
            break;
        }
    }
    cout << ans << endl;
}

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

int main()
{
    int N;
    cin >> N;
    string S[100000];
    int A = 0, W = 0, T = 0, R = 0;
    for (int i = 0; i < N; i++) {
        cin >> S[i];
    }
    for (int i = 0; i < N; i++) {
        if (S[i] == "AC") {
            A ++;
        }
    }
    for (int i = 0; i < N; i++) {
        if (S[i] == "WA") {
            W ++;
        }
    }
    for (int i = 0; i < N; i++) {
        if (S[i] == "TLE") {
            T ++;
        }
    }
    for (int i = 0; i < N; i++) {
        if (S[i] == "RE") {
            R ++;
        }
    }
    cout << "AC x " << A<<endl;
    cout << "WA x " << W<<endl;
    cout << "TLE x " << T<<endl;
    cout << "RE x " << R <<endl;
    return 0;
}

Measured memory_bytes: 6756
/*
    https://onlinejudge.u-aizu.ac.jp/courses/lesson/2/ITP1/9/ITP1_9_B
*/
#include <bits/stdc++.h>
using namespace std;

string shuffle(string str, int number) {
    string answer = "";
    int len = str.size();

    for (int i = number; i < len; i++)
        answer += str[i];

    for (int i = 0; i < number; i++)
        answer += str[i];

    return answer;
}

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

    string str;
    int loop, number;

    while (true) {
        cin >> str;

        // end if str is -
        if (str == "-")
            break;

        // shuffle
        cin >> loop;
        for (int i = 0; i < loop; i++) {
            cin >> number;
            str = shuffle(str, number);
        }
        cout << str << endl;
    }
}


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

using namespace std;
typedef long long int ll;
typedef pair <ll,ll> P;
#define REP(i, n) for(ll i = 0LL; i < (ll)(n); i++)
#define REPR(i, n) for(ll i = n-1; i >= 0LL; i--)
#define FOR(i, n, m) for(ll i = n; i < (ll)(m); i++)
#define PRINT(x) cout << x << endl
#define ALL(v) v.begin(), v.end()
#define INF (ll)1e18
#define INFD 1e18
#define PI 3.14159265358979
#define MOD 1000000007
#define vl vector<ll>

vector<ll> dx = {-1, 1, 0, 0};
vector<ll> dy = {0, 0, 1, -1};

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

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

	vector<ll> P(N);
	REP(i, N) cin >> P[i];
	vl dp(N);
	REP(i,N) {
		dp[P[i]-1] = i;
	}
	ll cnt = 1;
	ll ma = 1;
	REP(i,N-1){
		if(dp[i] < dp[i+1]) {
			cnt++;
		} else {
			ma = max(ma, cnt);
			cnt = 1;
		}
	}
	ma = max(ma, cnt);
	PRINT(N - ma);
	return 0;
}


Measured memory_bytes: 3328
def move(dice, order):
  if order == "E":
    temp = dice[0]
    dice[0] = dice[3]
    dice[3] = dice[5]
    dice[5] = dice[2]
    dice[2] = temp
  elif order == "N":
    temp = dice[0]
    dice[0] = dice[1]
    dice[1] = dice[5]
    dice[5] = dice[4]
    dice[4] = temp
  elif order == "S":
    temp = dice[0]
    dice[0] = dice[4]
    dice[4] = dice[5]
    dice[5] = dice[1]
    dice[1] = temp
  elif order == "W":
    temp = dice[0]
    dice[0] = dice[2]
    dice[2] = dice[5]
    dice[5] = dice[3]
    dice[3] = temp
  else:
    pass
  return dice

def roll(dice):
  temp = dice[1]
  dice[1] = dice[2]
  dice[2] = dice[4]
  dice[4] = dice[3]
  dice[3] = temp
  return dice

def judge(dice1, dice2):
  flag = True
  for i in range(6):
    if dice1[i] != dice2[i]:
      flag = False
      break
  return flag

import sys

dice1 = list(map(int, input().split()))
dice2 = list(map(int, input().split()))

mvdice = dice2
cnt = 0

while True:
  mvdice = move(mvdice, "E")
  cnt += 1
  if dice1[0] == mvdice[0]:
    rolldice = mvdice
    cntroll = 0
    while True:
      rolldice = roll(rolldice)
      cntroll += 1
      if judge(dice1, rolldice) == True:
        print("Yes")
        sys.exit()
      if cntroll == 4:
        break
  if cnt == 4:
    break

mvdice = dice2
cnt = 0
    
while True:
  mvdice = move(mvdice, "N")
  cnt += 1
  if dice1[0] == mvdice[0]:
    rolldice = mvdice
    cntroll = 0
    while True:
      rolldice = roll(rolldice)
      cntroll += 1
      if judge(dice1, rolldice) == True:
        print("Yes")
        sys.exit()
      if cntroll == 4:
        break
  if cnt == 4:
    break

print("No")


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

ll N, K;
string S;
vector<ll> A;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    cin >> N >> K >> S;
    ll cur = 1;
    for (ll i = 1; i < S.length(); i++) {
        if (S[i] != S[i-1]) {
            if (S[i-1] == '0') {
                A.push_back(-cur);
                cur = 1;
            }
            else {
                A.push_back(cur);
                cur = 1;
            }
        }
        else cur++;
    }
    if (S[S.length()-1] == '0') {
        A.push_back(-cur);
        cur = 1;
    }
    else {
        A.push_back(cur);
        cur = 0;
    }
    
    ll i = 0, j = 0, cnt = 0, ans = 0;
    cur = 0;
    while (i <= j && j < A.size()) {
        //cout << i << " " << j << "\n";
        while (j < A.size() && (A[j] > 0 || A[j] < 0 && cnt < K)) {
            cur += abs(A[j]);
            if (A[j] < 0) cnt++;
            j++;
        }
        ans = max(ans, cur);
        while (i < j && cnt == K) {
            cur -= abs(A[i]);
            if (A[i] < 0) cnt--;
            i++;
        }
        ans = max(ans, cur);
    }
    
    cout << ans << "\n";
    
}

Measured memory_bytes: 1528
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
a1,a2,a3=parseMap(split(readline()))
f(a,b,c)=min(abs(a-b)+abs(b-c),abs(a-c)+abs(c-b))
ans=min(f(a1,a2,a3),f(a2,a1,a3),f(a3,a1,a2))
print(ans)

Measured memory_bytes: 162728
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)

int main(){
	int N,X; cin>>N>>X;
	vi M(N);
	int all_m = 0;
	rpz(i,N){
		cin>>M[i];
		all_m += M[i];
	}
	X -= all_m;
	sort(all(M));
	int ans = N + X/M[0];
	ote(ans);
}


Measured memory_bytes: 256
n = int(input())
b = list(map(int, input().split()))
a = []
while b != []:
  best_match = -1
  for i in range(1, len(b)+1):
    if b[i-1] == i:
      best_match = i
  if best_match == -1:
    print(-1)
    exit(0)
  else:
    a.append(best_match)
    del b[best_match-1]
for num in a[::-1]:
  print(num)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
#define P(a,b) make_pair(a,b);
ll MOD = 1000000007;
//ll INF = 21474836470000000;
ll INF = 1001001001001001001;
long double EPS = 1e-11;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<pair<ll,ll>>>;

int main(){
    ll A,B,K;
    cin >> A >>B >> K;
    rep(i,K){
        if(i % 2 == 0){
            A /= 2;
            B += A;
        }else{
            B /= 2;
            A += B;
        }
    }
    cout << A << ' ' << B << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repp(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)
#define p(a,b) printf(a,b);
#define o(s) cout<< s << endl;
typedef long long LL;
template <class T>
bool contain(const std::string &s, const T &v)
{
    return s.find(v) != std::string::npos;
}

int main()
{
   string s; int h,w; cin>>h>>w;
   rep(i,h){
       rep(j,w){
           cin>>s;
           if(s=="snuke"){
               cout << char(int('A')+j) << i+1 << endl;
               return 0;
           }
       }
   }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<int,int> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define FILL(i,n) memset(i,n,sizeof(i));
#define X first
#define Y second
#define pb push_back
#ifdef brian
#define  debug(...) do{\
    fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename t> void _do(t &&x){cerr<<x<<endl;}
template<typename t,typename ...T> void _do(t &&x,T &&...tail){cerr<<x<<", ";_do(tail...);}
#else
#define debug(...)
#endif // brian


ll sx,sy,tx,ty;
bool d[2010][2010];
string s;
void it(ii f,ii t)
{
    debug(f.X,f.Y,t.X,t.Y);
    d[f.X][f.Y]=1;
    if(f==t)return;
    if(f.X>t.X)
    {
        ll dx[4]={-1,0,0,1};
        ll dy[4]={0,1,-1,0};

        string ds[4]={"L","U","D","R"};
        if(f.Y>t.Y){swap(dy[1],dy[2]);swap(ds[1],ds[2]);}
        REP(k,4)
        {
            if(!d[f.X+dx[k]][f.Y+dy[k]])
            {
                it(ii(f.X+dx[k],f.Y+dy[k]),t);
                s+=ds[k];
                break;

            }
        }
    }
    else if(f.X<t.X)
    {
        ll dx[4]={1,0,0,-1};
        ll dy[4]={0,1,-1,0};

        string ds[4]={"R","U","D","L"};
        if(f.Y>t.Y){swap(dy[1],dy[2]);swap(ds[1],ds[2]);}
        REP(k,4)
        {
            if(!d[f.X+dx[k]][f.Y+dy[k]])
            {
                it(ii(f.X+dx[k],f.Y+dy[k]),t);
                s+=ds[k];
                break;

            }
        }
    }
    else if(f.Y<t.Y)
    {
        ll dx[4]={0,1,-1,0};
        ll dy[4]={1,0,0,-1};

        string ds[4]={"U","R","L","D"};
        if(f.X>t.X){swap(dx[1],dx[2]);swap(ds[1],ds[2]);};
        REP(k,4)
        {
            if(!d[f.X+dx[k]][f.Y+dy[k]])
            {
                it(ii(f.X+dx[k],f.Y+dy[k]),t);
                s+=ds[k];
                break;
            }
        }
    }
    else
    {
        ll dx[4]={0,1,-1,0};
        ll dy[4]={-1,0,0,1};

        string ds[4]={"D","R","L","U"};
        if(f.X>t.X){swap(dx[1],dx[2]);swap(ds[1],ds[2]);}
        REP(k,4)
        {
            if(!d[f.X+dx[k]][f.Y+dy[k]])
            {
                it(ii(f.X+dx[k],f.Y+dy[k]),t);
                s+=ds[k];
                break;
            }
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin>>sx>>sy>>tx>>ty;
    sx+=1005;sy+=1005;tx+=1005;ty+=1005;
    FILL(d,0);
    d[sx][sy]=0;
    d[tx][ty]=0;
    it(ii(sx,sy),ii(tx,ty));
    d[sx][sy]=0;
    d[tx][ty]=0;
    it(ii(tx,ty),ii(sx,sy));
    d[sx][sy]=0;
    d[tx][ty]=0;
    it(ii(sx,sy),ii(tx,ty));
    d[sx][sy]=0;
    d[tx][ty]=0;
    it(ii(tx,ty),ii(sx,sy));
    cout<<s<<endl;
}


Measured memory_bytes: 5768
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
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;
}
int main() {
  cout << fixed << setprecision(10);
  string s,t;
  cin >> s >> t;
  if(s==t.substr(0,s.size())){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3632
A = [0]*3
for i in range(3):
    A[i] = [int(a) for a in input().split()]

N = int(input())
B = [int(input()) for _ in range(N)]

for b in B:
    for i in range(3):
        for j in range(3):
            if A[i][j] == b:
                A[i][j] = 0

f = 0
for i in range(3):
    if sum(A[i][:]) == 0:
        f = 1


for i in range(3):
    x = 0
    for j in range(3):
        x += A[j][i]
    if x == 0:
        f = 1
x = 0
for i in range(3):
    x += A[i][i]
if x == 0:
    f = 1

x = 0
x = A[0][2]+A[1][1]+A[2][0]
if x == 0:
    f = 1

if f == 1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 38384
#include <iostream>
#include <string>
#include <cctype>
using namespace std;

int main(){
    string n;
    string w;
    int c, l, i;
    c = 0;
    
    cin >> w;
    
    while(true){
        cin >> n;
        if(n == "END_OF_TEXT") break;
        l = n.size();
        for(i = 0; i < l; i++){
            n[i] = tolower(n[i]);
        }
        if(n == w) c = c + 1;
    }
    
    cout << c << endl;
}



Measured memory_bytes: 3220
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
#define rep(i,n) for (int i=0; i<n;++i)
using namespace std;
int N;
string s, t; 
int DP[3002][3002]; // sのi文字目までとtのj文字目まで探索し、その最大共通個数

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

  cin >> s >> t;
  rep(i, s.size()) {
    rep(j, t.size()) {
      if (s[i] == t[j]) {
        DP[i+1][j+1] = max(DP[i][j]+1, DP[i+1][j+1]);
      }
      DP[i+1][j+1] = max(DP[i+1][j+1], DP[i][j+1]);
      DP[i+1][j+1] = max(DP[i+1][j+1], DP[i+1][j]);
    }
  }

  string ans = "";
  int s_idx = (int)s.size();
  int t_idx = (int)t.size();
  while (s_idx > 0 && t_idx > 0) {
    if (DP[s_idx][t_idx] == DP[s_idx-1][t_idx]) s_idx--;
    else if (DP[s_idx][t_idx] == DP[s_idx][t_idx-1]) t_idx--;
    else {
      ans = s[s_idx-1]+ans;
      s_idx--;
      t_idx--;
    }
  }
  cout << ans << "\n";
  return 0;
}

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

using namespace std;

const int MAX_SIZE = 2e5+10;
const int inf = 1e8;
vector<int> graph[MAX_SIZE];
vector<bool> visited(MAX_SIZE, false);
std::vector<int> dist(MAX_SIZE, inf);

void bfs(int s) {
	visited[s] = true;
	dist[s] = 0;
	queue<int> q;
	q.push(s);
	while(!q.empty()) {
		int u = q.front();
		q.pop();
		for(auto &v: graph[u]) {
			if(!visited[v]) {
				visited[v] = true;
				dist[v] = dist[u] + 1;
				q.push(v);
			}
		}
	}
}

int main() {
	int n, m;
	cin >> n >> m;
	int a, b;
	while(m--) {
		cin >> a >> b;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}
	bfs(1);
	if(dist[n] <= 2) {
		cout << "POSSIBLE" << endl;
	}
	else
	{
		cout << "IMPOSSIBLE" << endl;
	}
}

Measured memory_bytes: 13168
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


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

  int n;
  cin >> n;
  map<string,int> smap;
  rep(i,n){
    string s;
    cin >> s;
    smap[s]++;
  }
  int mn=0;
  for(auto i:smap){
    mn = max(mn,i.second);
  }
  set<string> ans;
  for(auto i:smap){
    if(mn==i.second) ans.insert(i.first);
  }
  for(auto i:ans) cout << i<< endl;
  
  return 0;
    

}


Measured memory_bytes: 33280
H,W=map(int,input().split())
N=int(input())
A=list(map(int,input().split()))

ans=[[0]*W for _ in range(H)]
x=0
y=0
dir=1
for a in range(1,N+1):
  for _ in range(A[a-1]):
    ans[y][x]=a
    if dir==1 and x==W-1:
      y+=1
      dir=-1
    elif dir==1:
      x+=1
    elif dir==-1 and x==0:
      y+=1
      dir=1
    elif dir==-1:
      x-=1
      
for i in ans:
  print(*i)

Measured memory_bytes: 3916
#include "bits/stdc++.h"

using namespace std;

string com = "LRUD";

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

    int h, w, n;
    cin >> h >> w >> n;
    int sx, sy;
    cin >> sx >> sy;
    string s, t;
    cin >> s >> t;
    s = "$" + s;
    t = "$" + t;
    int L = 0, R = 1, U = 2, D = 3;
    vector<vector<int>> ssum(n + 1, vector<int>(4, 0)), tsum(n + 1, vector<int>(4, 0));
    for (int i = 1; i <= n; i++)
    {
        for (int j = 0; j < 4; j++)
        {
            ssum[i][j] = ssum[i - 1][j];
            tsum[i][j] = tsum[i - 1][j];

            if (s[i] == com[j])
                ssum[i][j]++;
            if (t[i] == com[j])
                tsum[i][j]++;
        }
        tsum[i][L] = min(tsum[i][L], sy + ssum[i][R] - 1);
        tsum[i][R] = min(tsum[i][R], w - (sy - ssum[i][L]));
        tsum[i][U] = min(tsum[i][U], sx + ssum[i][D] - 1);
        tsum[i][D] = min(tsum[i][D], h - (sx - ssum[i][U]));
    }
    bool f = false;
    for (int i = 1; i <= n; i++)
    {
        // L
        if (sy - ssum[i][0] + tsum[i - 1][1] <= 0)
            f = true;
        // R
        if (sy + ssum[i][1] - tsum[i - 1][0] > w)
            f = true;
        // U
        if (sx - ssum[i][2] + tsum[i - 1][3] <= 0)
            f = true;
        // D
        if (sx + ssum[i][3] - tsum[i - 1][2] > h)
            f = true;
    }
    cout << (f ? "NO" : "YES") << endl;
}


Measured memory_bytes: 22544
(defun calc-scores (sorted-lst turn-alice alice bob)
  (if (null sorted-lst)
      (- alice bob)
      (if turn-alice
	  (calc-scores (cdr sorted-lst)
		       (not turn-alice)
		       (+ alice (car sorted-lst))
		       bob)
	  (calc-scores (cdr sorted-lst)
		       (not turn-alice)
		       alice
		       (+ bob (car sorted-lst))))))
      
(let ((n (read)))
  (princ
   (calc-scores
    (sort (loop for x from 1 to n collect (read)) #'>=)
    t 0 0))
  (fresh-line))


Measured memory_bytes: 12128
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s,t;
	cin>>s;
	cin>>t;
	int count=0;
	for(int i=0;i<3;i++)
	{
		if(s[i]==t[i])
			count++;
	}	
	cout<<count;
}

Measured memory_bytes: 256
function main(arg) {
	arg = arg.trim().split("\n")
	var N = arg.shift()
	arg = arg.map(e => Number(e))
	var sum = 0
	var max = 0
	for (var i = 0; i < arg.length; i++) {
		if (arg[i] > max) {
			max = arg[i]
		}
		sum += arg[i]
	}
	console.log(parseInt(sum - (max / 2), 10))
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 7372
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int a, b;
  cin >> a >> b;
  cout << a * b - (a + b - 1) << endl;
}


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

bool isEvenString(string s, int size){
	for(int i = 0; i < size/2; i++){
		if(s[i] != s[i + size/2]) return false;
	}
	return true;
}

int main(){
	string s;
	int i;
	cin >> s;
	for(i=s.size()-1; i > 1; i--){
		if(i%2==0 && isEvenString(s, i)) break;
	}
	cout << i;
	return 0;
}



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

#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nyan "(=^･ω･^=)"
#define mkp make_pair
#define lP pair<ll, ll>
#define iP pair<int,int>

using namespace std;
typedef long long ll;

int X, K, A[100002], Q, t, a, p, q, l, r, L, R;

int main() {
	cin >> X >> K;
	for (int i = 1; i != K + 1; ++i)
		cin >> A[i];
	A[K + 1] = intmax;
	cin >> Q;
	r = X;
	R = X;
	while (Q--) {
		cin >> t >> a;
		for (; p != K + 1; ++p) {
			if (A[p + 1] >= t) {
				int res;
				if (p & 1) {
					if (a < l) {
						res = L + t - A[p];
					}
					else if (a <= r)
						res = a + q + t - A[p];
					else
						res = R + t - A[p];
					res = min(res, X);
				}
				else {
					if (a < l) {
						res = L - t + A[p];
					}
					else if (a <= r)
						res = a + q - t + A[p];
					else
						res = R - t + A[p];
					res = max(res, 0);
				}
				cout << res << endl;
				break;
			}
			if (p & 1) {
				L += A[p + 1] - A[p];
				q += A[p + 1] - A[p];
				R += A[p + 1] - A[p];
				L = min(L, X);
				R = min(R, X);
				r = min(r, X - q);

			}
			else {
				L -= A[p + 1] - A[p];
				q -= A[p + 1] - A[p];
				R -= A[p + 1] - A[p];
				L = max(L, 0);
				R = max(R, 0);
				l = max(l, -q);
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1536
r,g,b,n=map(int,input().split())
ans=0
r,g,b=sorted([r,g,b])[::-1]
for i in range(n//r+1):
    for j in range(n//g+1):
        k=n-i*r-j*g
        if(k<0):
            break
        if(k>=0 and k%b==0):
            ans+=1
print(ans)

Measured memory_bytes: 40428
using System;
class AOJ{
public static void Main(){
int[, ,] k=new int[4,3,10];
int a=int.Parse(Console.ReadLine());
for(int i=0;i<a;i++){
string[] st=Console.ReadLine().Split(' ');
k[int.Parse(st[0])-1,int .Parse(st[1])-1,int.Parse(st[2])-1]+=int.Parse(st[3]);

}
for(int i=0;i<4;i++){
for(int j=0;j<3;j++){
for(int n=0;n<10;n++){
Console.Write(" "+k[i,j,n]);
if(n==9)
Console.WriteLine();
}


}
if(i!=3)
Console.WriteLine("####################");

}
}

}

Measured memory_bytes: 9076
N, K = map(int, input().split())

mod = 10 ** 9 + 7

memo = [0] * (K + 1)
ans = 0
for i in range(K, 0, -1):#大きいほうから順に考える
    memo[i] = pow(K // i, N, mod)#最大公約数がiの倍数となる数列の個数
    j = 2#最初は２から
    while i * j <= K:#そのうち最大公約数がi以外のやつを引いていく
        memo[i] -= memo[i * j]
        j += 1
    ans += memo[i] * i#gcdの値*個数を足していく
    ans %= mod

print(ans)

Measured memory_bytes: 68948
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    bool inc[n-1];
    for(int i=0;i<n;i++){
        if(a[i]<a[i+1])inc[i]=true;
        else inc[i]=false;
    }
    int cnt[n],t=1;
    cnt[0]=1;
    for(int i=0;i<n-1;i++){
        if(inc[i])t++;
        else t=1;
        cnt[i+1]=t;
    }
    int ans=n-k+1;
    for(int i=k-1;i<n;i++){
        if(cnt[i]>=k){
            ans++;
            break;
        }
    }
    bool flag=false;
    for(int i=k-1;i<n;i++){
        if(cnt[i]>=k){
            if(!flag){
                flag=true;
                ans--;
            }
        }
        else flag=false;
    }
    set<int> st;
    for(int i=0;i<k;i++){
        st.insert(a[i]);
    }
    for(int i=1;i<n-k+1;i++){
        auto it=st.lower_bound(a[i+k-1]);
        if(it==st.end()&&*st.begin()==a[i-1]){
            ans--;
        }
        st.erase(a[i-1]);
        st.insert(a[i+k-1]);
    }
    cout<<ans<<endl;
}


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

int N;
int H[1000000];
int C[1000000];

void solve()
{
    int sum = 0;
    for(int i = 0; i < N; i++) {
        if (i==0)
        {
            C[i] = 0;
        } else if (i==1)
        {
            C[i] = abs(H[1] - H[0]);
        } else {
            C[i] += min(C[i-1] + abs(H[i]-H[i-1]), C[i-2] + abs(H[i]-H[i-2]));
        }
    }
    cout << C[N-1] << endl;
}

int main()
{
    cin >> N;
    for(int i = 0; i < N; i++) {
        cin >> H[i];
    }

    solve();

    return 0;
}

Measured memory_bytes: 4736