akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const int INF=1<<30,MOD=1000000007;
const ll LINF=1ll<<60;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...) _overload3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define REPARR(i,v) for(int i=0;i<v.size();++i)
#define all(v) (v).begin(),(v).end()
#define uniq(v) sort(all(v));v.erase(unique(all(v)),v.end())
#define bit(n) (1ll<<(n))
template<class T>bool chmax(T&a,const T&b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T&a,const T&b){if(a>b){a=b;return true;}return false;}
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define yes(n) cout<<((n)?"yes":"no")<<endl
#define poss(n) cout<<((n)?"":"im")<<"possible"<<endl
#define Poss(n) cout<<((n)?"P":"Imp")<<"ossible"<<endl
template<typename T>ostream&operator<<(ostream&o,const vector<T>&v){for(T i:v)o<<i<<' ';return o;}
template<typename T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<typename T>ostream&operator<<(ostream&o,const set<T>&v){for(T i:v)o<<i<<' ';return o;}
template<typename T,typename U>ostream&operator<<(ostream&o,const pair<T,U>&v){o<<v.first<<' '<<v.second;return o;}

int main(){
    int n,h,w;
    cin>>n>>h>>w;
    cout<<(n-h+1)*(n-w+1)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MAX 5000005
using namespace std;

int n;
string s;
ll ans;

int main()
{
    cin >> n;
    for(int i = 1; i <= n; i++){
        if(i%3==0 || i%5==0) continue;
        ans += i;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3596
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <bitset>
#include <complex>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

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++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cout << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i : a)cout << i << " "; puts("");

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef complex<double> CD;

int main() {
	map<string, int> m;
	int q; cin >> q;
	rep(i, q) {
		int t, x;
		string key;
		cin >> t;

		switch (t) {
		case 0:
			cin >> key >> x;
			m.erase(key);
			m.insert(mp(key, x));
			break;
		case 1:
			cin >> key;
			Cout(m.at(key));
			break;
		}
	}
}


Measured memory_bytes: 27900
#include<iostream>
#include<string>
#include<map>
#include<algorithm>
using namespace std;
int main()
{
	long long a,b,c;
	cin>>a>>b>>c;
	if(a%2==0||b%2==0||c%2==0)
	{
		cout<<0<<endl;
	}
	else
	{
	long long ans=min(min(a*b,a*c),(b*c));
	cout<<ans<<endl;
	}
}

Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)

int main(){

    // 1. 入力情報.
    int N;
    LL T;
    scanf("%d %lld", &N, &T);
    
    // 2. お湯の出る合計時間は？
    LL ans = 0, s, t, e = 0;
    rep(i, N){
        scanf("%lld", &t);
        s = max(e, t); // 開始時刻.
        e = t + T;     // 終了時刻.
        ans += (e - s);
    }
    
    // 3. 出力.
    printf("%lld\n", ans);
    return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
void chmin(long long &a, long long b) { if (a > b) a = b; }
const long long INF = 1LL<<58;

// vector v において、x の前方と後方の index を求める
template<class T> int former(const vector<T> &v, T x) {
    return upper_bound(v.begin(), v.end(), x) - v.begin() - 1;
}
template<class T> int latter(const vector<T> &v, T x) {
    return lower_bound(v.begin(), v.end(), x) - v.begin();
}

int main() {
    int A, B, Q; cin >> A >> B >> Q;
    vector<long long> s(A), t(B);
    for (int i = 0; i < A; ++i) cin >> s[i];
    for (int i = 0; i < B; ++i) cin >> t[i];
    s.push_back(INF); s.push_back(-INF); sort(s.begin(), s.end());
    t.push_back(INF); t.push_back(-INF); sort(t.begin(), t.end());
    
    for (int _ = 0; _ < Q; ++_) {
        long long x; cin >> x;
        long long res = INF;
        
        // 最初に s (前方に行くか後方に行くか場合分け)
        for (int i = 0; i < 2; ++i) {
            long long first = (i ? s[former(s, x)] : s[latter(s, x)]);
            // 次に t (現在地の前後を見る)
            for (int j = 0; j < 2; ++j) {
                long long second = (j ? t[former(t, first)] : t[latter(t, first)]);
                chmin(res, abs(x - first) + abs(first - second));
            }
        }
        // 最初に t (前方に行くか後方に行くか場合分け)
        for (int i = 0; i < 2; ++i) {
            long long first = (i ? t[former(t, x)] : t[latter(t, x)]);
            // 次に t (現在地の前後を見る)
            for (int j = 0; j < 2; ++j) {
                long long second = (j ? s[former(s, first)] : s[latter(s, first)]);
                chmin(res, abs(x - first) + abs(first - second));
            }
        }
        cout << res << endl;
    }
}

Measured memory_bytes: 4832
def next_diverse_word(s):
    alphabets = set(chr(ord('a') + i) for i in range(26))
    if s == 'zyxwvutsrqponmlkjihgfedcba':
        return -1
    r = alphabets - set(s)
    if len(r) != 0:
        return s + sorted(r)[0]
    s = list(s)
    r = [s[-1]]
    s = s[:-1]
    while True:
        k = s[-1]
        r.append(s[-1])
        s = s[:-1]
        t = [c for c in r if c > k]
        if len(t) != 0:
            s.append(sorted(t)[0])
            return ''.join(s)


S = input()
print(next_diverse_word(S))


Measured memory_bytes: 3064
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<unordered_map>
#include<random>
#include<fstream>
#include<iterator>
#include <numeric>

using namespace std;

int main() {

	std::ios::sync_with_stdio(false);
	std::cin.tie(0);

	int ans = 0;
	int temp;

	vector<int>a(3);

	cin >> a[0] >> a[1] >> a[2];

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


	if ((a[2] - a[1]) % 2 == 0) {
		ans = (a[2] - a[1]) / 2;

		if ((a[2] - a[0]) % 2 == 0) {
			ans += (a[2] - a[0]) / 2;
		}
		else {
			ans += (a[2] - a[0]) / 2 + 2;
		}
	}
	else if((a[2]-a[0])%2==0){
		ans = (a[2] - a[0]) / 2;
		ans += (a[2] - a[1]) / 2 + 2;
	}
	else {
		ans = (a[1] - a[0]) / 2;
		ans += (a[2] - a[1]);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
use proconio::input;

fn main() {
    input! {
        x: i32,
        y: i32,
    }
    for n in 0..=x {
        if y == 2 * n + (x - n) * 4 {
            println!("Yes");
            return;
        }
    }
    println!("No");
}

Measured memory_bytes: 2136
#include<bits/stdc++.h>
using namespace std;
long long modexp(long long n)
{
    if(n==1)
        return 2;
    long long ans = modexp(n/2);
    if(n%2==0)
        return ans*ans;
    else
        return 2*ans*ans;
}
int main()
{
    long long H;
    cin>>H;
    long long n=1;
    long long ans=2;
    while(ans<=H)
    {
        ans*=2;
        n++;
    }
    cout<<modexp(n) - 1;

    return 0;

}


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

int main()  {
    string s;
    cin>>s;
    for(int i=1;i<s.length();i++)
        if(s[i]==s[i-1])
        {
            cout<<i<<" "<<i+1;
            return 0;
        }
    for(int i=2;i<s.length();i++)
        if(s[i-2]==s[i])
        {
            cout<<i-1<<" "<<i+1;
            return 0;
        }
    cout<<"-1 -1";
    return 0;
}


Measured memory_bytes: 3704
-- https://github.com/minoki/my-atcoder-solutions
{-# LANGUAGE BangPatterns #-}
import Data.Char (isSpace)
import Data.Int (Int64)
import Data.List (unfoldr, intersperse)
import Control.Monad
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed.Mutable as UM
import qualified Data.ByteString.Char8 as BS
import qualified Data.ByteString.Builder as BSB
import System.IO
import Data.Monoid

type Map = U.Vector Int

compose :: Int -> Map -> Map -> Map
compose !n xs ys = U.generate n (\i -> xs U.! (ys U.! i))

powMap :: Int -> Map -> Integer -> Map
powMap !n xs 0 = U.generate n id
powMap !n xs m = loop xs xs (m-1)
  where
    loop !acc !ys 0 = acc
    loop !acc !ys 1 = compose n acc ys
    loop !acc !ys m = case m `quotRem` 2 of
                        (m',0) -> loop acc (compose n ys ys) m'
                        (m',_) -> loop (compose n acc ys) (compose n ys ys) m'

main = do
  s <- BS.getLine
  let n = BS.length s
  let xs = U.generate n (\i -> if BS.index s i == 'R' then i + 1 else i - 1)
  let zs = powMap n xs (10^100)
  let result = U.create $ do
        vec <- UM.replicate n 0
        U.forM_ zs $ \i -> UM.modify vec (+1) i
        return vec
  BSB.hPutBuilder stdout $ (mconcat $ intersperse (BSB.char7 ' ') $ map BSB.intDec $ U.toList result) <> BSB.char7 '\n'


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

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


#define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++)
#define frep(i,m,n) for(ll (i)=(m); (i)<=(ll)(n); (i)++)
#define rrep(i,n) for(ll (i)=(n)-1; (i)>-1; (i)--)
#define frrep(i,m,n) for(ll (i)=(n); (i)>(ll)(m); (i)--)
#define ALL(x) (x).begin(), (x).end()

const ll INF = 1000000000;
const ll MOD = 1000000007;

// get abs
ll my_abs(ll a);
// a^n
ll a_n(ll a, ll n);
// get gcd
ll my_gcd(ll a, ll b);
// a^(-1) % MOD 
ll inv(ll a);
// (a+b+c)%MOD
ll madd(ll a, ll b, ll c);
// (a-b)%MOD
ll msub(ll a, ll b);
// (a*b*c)%MOD
ll mtime(ll a, ll b, ll c);

// map of result of factorization
void factorization(ll n, map<ll, ll> &a) {
    while((n%2) == 0) {
        n /= 2;
        if(a.count(2)) a.at(2)++;
        else a[2] = 1;
    }
    for(ll i = 3; i*i <= n; i+=2) {
        while((n%i) == 0) {
            n /= i;
            if(a.count(i)) a.at(i)++;
            else a[i] = 1;
        }
    }
    if(n != 1) a[n] = 1;
}

int main() {
    ll s, x, y; cin >> s;
    y = (INF - (s%INF))%INF;
    x = (s+y)/INF;

    cout << 0 << ' ' << 0 << ' ';
    cout << 1 << ' ' << INF << ' ';
    cout << x << ' ' << y << endl;
    return 0;
}

ll my_abs(ll a) {
    if(a >= 0) return a;
    else return -1 *a;
}

ll a_n(ll a, ll n) { 
    if(n == 0) return 1;
    
    ll ret = a, count = 1;
    while(count * 2 < n) {
        ret *= ret;
        count *= 2;
    }
    if(count == n) return ret;
    else return (ret * a_n(a, n-count));
}

ll my_gcd(ll a, ll b) {
    if(b == 0) return a;
    return my_gcd(b, a%b);
}

ll inv(ll a) {
    return a_n(a, MOD-2);
}

ll madd(ll a, ll b, ll c) {
    ll ret = (a+b) % MOD;
    return (ret+c) % MOD;
}

ll msub(ll a, ll b) {
    if(a < b) return (a-b+MOD) % MOD;
    else return (a-b) % MOD;
}

ll mtime(ll a, ll b, ll c) {
    ll ret = (a*b) % MOD;
    return (ret*c) % MOD;
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define INF 1000000000
#define MOD 1000000007
#define PI acos(-1)
#define M 998244353
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ll long long
#define endl "\n"
#define fori(i, a, b) for(i=a; i<b; i++)
#define ford(i, a, b) for(i=a; i>b; i--)
using namespace std;
const ll N = 500043;
ll fact[N];
ll add(ll x, ll y)
{
	x += y;
	while(x >= MOD) x -= MOD;
	while(x < 0) x += MOD;
	return x;
}
ll mul(ll x, ll y)
{
	return (x * 1ll * y) % MOD;
}
ll mulmod(ll a, ll b)
{
    ll res = 0;
    a = a % MOD;
    while (b>0)
    {
        if (b % 2 == 1)
            res = (res + a) % MOD;
        a = (a * 2) % MOD;
        b /= 2;
    }
    return res % MOD; 
}
ll binpow(ll x, ll y)
{
	ll z = 1;
	while(y > 0)
	{
		if(y % 2 == 1)
			z = mul(z, x);
		x = mul(x, x);
		y /= 2;
	}
	return z;
}
ll inv(ll x)
{
	return binpow(x, MOD - 2);
}
ll divide(ll x, ll y)
{
	return mul(x, inv(y));
}
void precalc()
{
	fact[0] = 1;
	ll i;
	fori(i, 1, N)
		fact[i] = mul(i, fact[i - 1]);
}
ll C(ll n, ll k)
{
	if(k > n)
	    return 0;
	return divide(fact[n], mul(fact[n-k], fact[k]));
}



void solve()
{
    char ch;
    cin >> ch;
    if(ch>='A' && ch<='Z')
        cout << "A" << endl;
    else
        cout << "a" << endl;
    
}
signed main()
{
    io
    int t;
    t=1;
    // cin >> t;
    while(t--)
        // cout << solve() << endl;
        solve();
    return 0;
}

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

typedef long long ll;
int p[10],q[10];
int t[10];
int n;
bool check(int s[]){
	for(int i=0;i<n;i++){
		if(s[i]!=t[i]) return false;
	}
	return true;
}
int main(){
	//int n;
	while(~scanf("%d", &n)){
		for(int i=0;i<n;i++){
			t[i]=i+1;
		}
		for(int i=0;i<n;i++){
			scanf("%d", &p[i]);
		}
		for(int i=0;i<n;i++){
			scanf("%d", &q[i]);
		}
		int a,b;
		int cnt=0;
		do{
			cnt++;
			if(check(p)) a=cnt;
			if(check(q)) b=cnt;

		}while(next_permutation(t,t+n));
		cout<<abs(a-b)<<"\n";
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>



int main(){
	int i,j,k;
	int n;
	int y,m,d;
	int ans;
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++){
		ans=0;
		
		scanf("%d%d%d",&y,&m,&d);
		
		for(j=y;j<1000;j++){
			if(j%3==0){
				ans+=20*10;
			}else{
				ans+=20*5+19*5;
			}
			if(j==y){
				for(k=1;k<m;k++){
					if(k%2!=0 || j%3==0) ans-=20;
					else ans -=19;
				}
				ans-=d;
			}
		}
		ans++;
		printf("%d\n",ans);
		
		
	}
	return 0;
}

Measured memory_bytes: 596
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 1000000000
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

int main(){
  int a, b;
  cin >> a >> b;
  ll ans = 0;
  if(a < b){
    rep(i, b){
      ans *= 10;
      ans += a;
    }
    cout << ans << endl;
  }
  else{
    rep(i, a){
      ans *= 10;
      ans += b;
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <set>
#include <string>
#include <utility>

using namespace std;

int main() {
  int x, n;

  cin >> x >> n;

  deque<int> vals(n);

  for (int i = 0; i < n; i++) {
    cin >> vals[i];
  }

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

  for (int diff = 0; true; diff++) {
    int target_l = x + diff;
    int target_s = x - diff;
    bool is_l_exist = false;
    bool is_s_exist = false;

    for (int i = 0; i < n; i++) {
      if (vals[i] == target_l) {
        is_l_exist = true;
      }
      if (vals[i] == target_s) {
        is_s_exist = true;
      }
    }

    if (!is_s_exist) {
      cout << target_s << endl;
      return 0;
    } else if (!is_l_exist) {
      cout << target_l << endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 3212
n, m = map(int, input().split())
ks_list = [list(map(int, input().split())) for _ in range(m)]
p_list = list(map(int, input().split()))
odd_list = []
even_list = []
for i in range(m):
    k = ks_list[i][0]
    s_list = ks_list[i][1:]
    p = p_list[i]

ans = 0
for i in range(2 ** n):
    on_list = [False] * n
    for j in range(n):
        if ((i >> j) & 1):
            on_list[j] = True
    ok = True
    for j in range(m):
        k = ks_list[j][0]
        s_list = ks_list[j][1:]
        p = p_list[j]
        count = 0
        for s in s_list:
            if on_list[s-1]:
                count += 1
        if count % 2 != p:
            ok = False
            break
    if ok:
        ans += 1
print(ans)


Measured memory_bytes: 3064
#include<iostream>
#include<cmath>
#include<bits/stdc++.h>
#include<string.h>
using namespace std;
typedef long long int ll;
const ll mod=1e9+7;
long double mm=1e9+7;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    ll i,a[n],s=0,ans=0;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        s=s+a[i];
    }
    for(i=0;i<n;i++)
    {
        s=s-a[i];
        ans=(ans+((a[i]%mod)*(s%mod))%mod)%mod;
    }
    cout<<ans<<"\n";
    cerr<<"\nTime elapsed:"<< 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}


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

using namespace std ;

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	int n ;
	cin>>n ;
	int arr[n] , arr1[n];
	for(int i = 0 ; i < n ; ++i)
	{
		cin>>arr[i] ;
		arr1[i] = arr[i] ;
	}
	sort(arr , arr + n) ;
	for(int i = 0 ; i < n ; ++i)
	{
		if(arr1[i] == arr[n-1])
			cout<<arr[n-2]<<"\n";
		else
			cout<<arr[n-1]<<"\n";
	}
	return 0 ;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        std::cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
    }
} fast;

/* define */
#define FOR(I, X, Y) for (long long(I) = (X); (I) < (Y); (I)++)
#define REP(I, X, Y) for (long long(I) = (Y)-1; (I) >= (X); (I)--)
#define ALL(X) (X).begin(), (X).end()
#define pb push_back
#define COUNT(V, X)                           \
    (upper_bound((V).begin(), (V).end(), X) - \
     lower_bound((V).begin(), (V).end(), X))
#define debug(x) cerr << #x << ':' << x << endl;
#define DEBUG(v)                             \
    {                                        \
        cerr << #v << ':';                   \
        for (auto xv : v) cerr << xv << ' '; \
        cerr << endl;                        \
    }
#define Yes(X) cout << (X ? "Yes" : "No") << endl;
#define YES(X) cout << (X ? "YES" : "NO") << endl;
#define ctoi(C) (C - '0')
#define pow2(x) ((long long)((long long)1 << x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int, int>;
using pl = pair<long long, long long>;
template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1, 0, -1, 0};
const long long dy[] = {0, 1, 0, -1};
const long long dx8[] = {1, 1, 0, -1, -1, -1, 0, 1};
const long long dy8[] = {0, 1, 1, 1, 0, -1, -1, -1};
const long long dx9[] = {1, 1, 0, -1, -1, -1, 0, 1, 0};
const long long dy9[] = {0, 1, 1, 1, 0, -1, -1, -1, 0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T1, typename T2>
inline bool chmin(T1 &a, const T2 &b) {
    if (a > b) a = b;
    return a > b;
}
template <typename T1, typename T2>
inline bool chmax(T1 &a, const T2 &b) {
    if (a < b) a = b;
    return a < b;
}
long long max(long long x, int y) {
    return max(x, (long long)y);
}
long long max(int x, long long y) {
    return max((long long)x, y);
}
long long min(long long x, int y) {
    return min(x, (long long)y);
}
long long min(int x, long long y) {
    return min((long long)x, y);
}

/* library */

/* main */

signed main() {
    ll N;
    cin >> N;
    vl A(N + 1);
    FOR(i, 1, N + 1) {
        cin >> A[i];
    }
    bool ball[N + 1] = {};
    REP(i, 1, N + 1) {
        ll sum = 0;
        for(int j = i + i;j <= N;j += i){
            sum += ball[j];
        }
        ball[i] = ((sum % (ll)2) != A[i]);
    }
    vl ans;
    REP(i, 1, N + 1) {
        ll sum = 0;
        for(int j = i;j <= N;j += i){
            sum += ball[j];
        }
        if(sum%2 != A[i]){
            cout << -1 << endl;
            return 0;
        }
        if(ball[i]){
            ans.push_back(i);
        }
    }
    cout << ans.size() << endl;
    FOR(i,0,ans.size()){
        cout << ans[i] << (i == ans.size()-1 ? "\n" : " ");
    }
}

Measured memory_bytes: 3828
K, N = map(int, input().split())
loc = list(map(int, input().split()))
distances = []
total = []

for i in range(N-1):
    distances.append(loc[i+1] - loc[i])

distances.append(loc[0] + K - loc[N-1])
max_dis = max(distances)

print(K - max_dis)


Measured memory_bytes: 26444
#include<bits/stdc++.h>
using namespace std;
string s1,s2;
vector<vector<int>>dp;
int solve(int i,int j){
    if(i==s1.size()||j==s2.size()) return 0;
    
    if(dp[i][j]!=-1) return dp[i][j];
    else{
        
        if(s1[i]==s2[j]){
            dp[i][j]=1+solve(i+1,j+1);
        }
        else{
            dp[i][j]=max(solve(i+1,j),solve(i,j+1));
        }
        return dp[i][j];
    }
}
int main(){
    
    cin>>s1>>s2;
    dp.resize(s1.size()+1,vector<int>(s2.size()+1,-1));
    int ans=solve(0,0);
    // cout<<ans;
    // int flag=0;
    if(ans==0) cout<<"";
    
    else {for(int i=0,j=0;i<s1.size()&&j<s2.size();){
        if(s1[i]==s2[j]){
            cout<<s1[i];
            // flag++;
            i++;j++;
        }
        else if(dp[i+1][j]>dp[i][j+1])
            i++;
        else j++;
    }
    }
    return 0;
}

Measured memory_bytes: 35968
#include<stdio.h>

int main() {
	int n,i;
	int loan = 100000;
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		loan = loan*1.05;
		if (loan % 1000 != 0) {
			loan = (loan / 1000 + 1) * 1000;
		}
	}
	printf("%d\n",loan);
	return 0;
}

Measured memory_bytes: 592
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
using namespace std;

int main(){
	cin.sync_with_stdio(false); cin.tie(nullptr);
	int n; cin >> n;
	cout << n + n*n + n * n*n << endl;
	return 0;
}

Measured memory_bytes: 3648
#include<iostream>
#include<queue>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
using namespace std;
/****************************/
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define qi queue<int>
#define mii map<int,int>
#define msi map<string,int>
/****************************/
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define rep3(i,a,n) for(ll i=(a);i<(n);i++)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define pi 3.1415926535897932384626433832795
#define zero(n) memset(n,0,sizeof(n));
#define SZ(n) n.size()
#define ss st.st
#define sn st.nd
#define mod 100000007
#define INF 1e9
/****************************/
int n;
int b[100010];
int c[100010];
int main()
{
	cin>>n;
	memset(b,0,sizeof(b));
	memset(c,0,sizeof(c));
	rep(i,n)
	{
		int a;
		cin>>a;
		b[a]++;
	}
	rep3(i,1,100005)
	{
		c[i]=b[i-1]+b[i]+b[i+1];
	}
	int max=-1;
	rep(i,100005)
	{
		if(c[i]>max)
		{
			max=c[i];
		}
	}
	cout<<max;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <map>

using namespace std;

int main() {
  long long n, m;
  cin >> n >> m; //n問、m回提出

  map<long long, long long> ok;
  map<long long, long long> ms;
  for(long long i = 0; i < m; i++){
    long long p;
    string s;
    cin >> p >> s;

    if(s == "WA" && ok[p] == 0){
      ms[p]++;
    } else if(s == "AC"){
      ok[p] = 1;
    }
  }

  long long sum = 0;
  for(auto p : ok)  sum += p.second;
  cout << sum << " ";

  sum = 0;
  for(auto p : ms){
    if(ok[p.first] == 1){
      sum += p.second;
    }
  }
  cout << sum << endl;

  return 0;
}

Measured memory_bytes: 8064
#include<bits/stdc++.h>
 
using namespace std;
 
#define D(x) cout << (#x) << " is " << x << endl;
#define Q int t; scanf("%d", &t); for(int q=1; q<=t; q++)
typedef long long int lli;
typedef pair<int, int> pi;
typedef pair<lli, lli> pii;


int main()
{
    int n;
    cin >> n;
    lli a, b;
    lli mx1=-1e10, mx2=-1e10, mn1=1e10, mn2=1e10;
	for(int i=0; i<n; i++){
		cin >> a >> b;
		mx1 = max(mx1, a+b);
		mx2 = max(mx2, a-b);
		mn2 = min(mn2, a-b);
		mn1 = min(mn1, a+b);
	}
	cout << max(mx1-mn1, mx2-mn2) << endl;
	
 
    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
int MAX = 10000;
int main() {
  int n;
  cin >> n;
  vector<int> A(n), B(n, 0), C(MAX, 0);
  for (size_t i = 0; i < n; i++) {
    cin >> A[i];
    C[A[i]] += 1;
  }

  int sum = 0;
  for (int i = 0; i < MAX - 1; i++) {
    C[i + 1] += C[i];
  }
  reverse(A.begin(), A.end());
  for (auto &&e : A) {
    B[C[e] - 1] = e;
    C[e]--;
  }

  for (size_t i = 0; i < n; i++) {
    if (i == n - 1) {
      cout << B[i] << endl;
    } else {
      cout << B[i] << ' ';
    }
  }
}


Measured memory_bytes: 18332
import sys
h,w = map(int,input().split())
s = [list(input()) for i in range(h)]
dx = [0,-1,1,0]
dy = [-1,0,0,1]

for i in range(h):
    for j in range(w):
        cnt = 0
        if  s[i][j] == "#":
            for k in range(4):
                nx = j + dx[k]
                ny = i + dy[k]
                if nx>=0 and ny>=0 and ny<h and nx<w:
                    if s[ny][nx] == "#":
                        cnt += 1
            if cnt == 0:
                print("No")
                sys.exit()
print("Yes")

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
 
int gcd(int x, int y){
  int a,b,temp;
  a = max(x,y);
  b = min(x,y);
  
  while(1){
    if(a%b == 0){
      return b;
    }else{
      temp = a%b;
      a = b;
      b = temp;
    }
  }
}
 
 
int main(){
  int a,b,k;
  cin>>a>>b>>k;
  
  int g;
  g = gcd(a,b);
  int count=0;
  while(1){
    if(a%g == 0 && b%g == 0){
      count++;
      if(count==k){
        break;
      }
      g--;
    }else{
      g--;
    }
  }
  
  cout<<g<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
#ifndef ONLINE_JUDGE
#define dbg(x...) do{cout << "\033[32;1m" << #x << "->" ; err(x);} while(0)
void err(){cout << "\033[39;0m" << endl;}
template<template<typename...> class T,typename t,typename... A>
void err(T<t> a,A... x){for (auto v:a) cout << v << ' '; err(x...);}
template<typename T,typename... A>
void err(T a,A... x){cout << a << ' '; err(x...);}
#else
#define dbg(...)
#endif
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
ll quick(ll a,ll b)
{
	ll ret=1;
	while(b)
	{
		if(b&1)
			ret=ret*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ret;
}
ll inv(ll a){return quick(a,mod-2);}
ll dp[42][1<<18];
int n,x,y,z;
inline int Merge(int cur,int num)
{
	cur<<=num;
	num=1<<(num-1);
	cur|=num;
	cur&=(1<<(x+y+z))-1;
	return cur;
}
bool check(int cur)
{
	return !((cur&(1<<(x+y+z-1)))&&(cur&(1<<(y+z-1)))&&(cur&(1<<(z-1))));
}
ll dfs(int p,int st)
{
	if(p==n)
		return 1;
	if(dp[p][st]!=-1) return dp[p][st];
	ll ret=0;
	for(int i=1;i<=10;i++)
	{
		int nxt=Merge(st,i);
		if(check(nxt)) ret=(ret+dfs(p+1,nxt))%mod;
	}
	return dp[p][st]=ret;
}
int main()
{
	memset(dp,-1,sizeof(dp));
	cin>>n>>x>>y>>z;
	cout<<(quick(10,n)-dfs(0,0)+mod)%mod<<endl;
}


Measured memory_bytes: 86400
import java.util.Scanner;

public class Main{
    void euc(int n, int m){
	int x, y, z, t = 0;
	if(n < m){
	    x = m;
	    y = n;
	} else {
	    x = n;
	    y = m;
	}

	while(y > 0){
	    x %= y;
	    z = y;
	    y = x;
	    x = z;
	    t++;
	}
	System.out.println(String.valueOf(x)+ " " + String.valueOf(t));

	return ;
    }

    Main(){
	Scanner sc = new Scanner(System.in);

	while(sc.hasNext()){
	    int n = sc.nextInt(), m = sc.nextInt();
	    if(n+m == 0) break;

	    euc(n, m);
	}
    }

    public static void main(String[] args){
	new Main();
    }
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    int A, B, C, X, Y; cin >> A >> B >> C >> X >> Y;
    int cntA = 0, cntB = 0, cntC = 0;
    if (2 * C < A + B) cntC = min(X, Y) * 2;

    X -= cntC / 2;
    Y -= cntC / 2;
    if (2 * C < A) cntC += 2 * X;
    else cntA = X;

    if (2 * C < B) cntC += 2 * Y;
    else cntB = Y;
    
    cout << A * cntA + B * cntB + C * cntC << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 998244353
using namespace std;
int main() {
    ll h, w;
    cin >> h >> w;
    if(h == 1 || w == 1) {
        cout << 1 << endl;
        return 0;
    }
    if(h % 2 == 0) {
        cout << (h / 2) * w << endl;
    } else {
        cout << (h / 2) * w + (w + 1) / 2 << endl;
    }
}

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

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

int main()
{
 int a,b;
 cin>>a>>b;
 a--;
 b--;
 cout<<(a*b)<<endl;
 return 0;
}

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

class Program
{
    static void Main()
    {
        var N = int.Parse(ReadLine());
        var A = ReadLine().Split(' ').Select(int.Parse).ToArray();

        var n = A.Max();
        var r = A.OrderBy(a => Abs(a - n / 2.0)).ThenBy(a => a).First();

        WriteLine($"{n} {r}");
    }
}

static class ArrayDeconstructExtensions
{
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2) => (i1, i2) = (a[0], a[1]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3) => (i1, i2, i3) = (a[0], a[1], a[2]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3, out T i4) => (i1, i2, i3, i4) = (a[0], a[1], a[2], a[3]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3, out T i4, out T i5) => (i1, i2, i3, i4, i5) = (a[0], a[1], a[2], a[3], a[4]);
}


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

int main() {
  int N;
  cin >> N;
  
  for (int i = 0; i < N; i++){
    char S;
    cin >> S;
    if (S == 'P' || S == 'W' || S == 'G'){
      continue;
    }
    else if (S == 'Y'){
      cout << "Four" << endl;
      return 0;
    }
  }
  cout << "Three" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c,k;
  cin >> a>>b>>c>>k;
  int ma = max({a,b,c});
  int ans = a+b+c -ma;
  for(int i =0;i<k;i++){
    ma *=2;
  }
  cout << ans+ma;
}

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

int main()
{
    int n;
    cin >> n;
    vector<vector<int>> in(n, vector<int> (3, 0));
    bool res = true;

    for(int i = 0; i < n; ++i)
    {
        for(int j = 0; j < 3; ++j)
        {
            cin >> in[i][j];
        }
    }

    if(n == 1)
    {
        cout << (in[0][1] + in[0][2] <= in[0][0] && 
            in[0][1] + in[0][2] % 2 == in[0][0] % 2 ? "Yes" : "No") << "\n";
    } else
    {
        for(int i = 0; i < n - 1; ++i)
        {
            if(abs(in[i+1][0] - in[i][0]) < 
                abs(in[i+1][1] - in[i][1]) + abs(in[i+1][2] - in[i][2])
                ||  (in[i][1] + in[i][2]) % 2 != in[i][0] % 2)
            {
                res = false;
            }
        }
        cout << (res ? "Yes" : "No") << "\n";
    }

    return 0;
}


Measured memory_bytes: 8724
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))
a,b,c = iim()
count = 0
if a == b == c and a%2 == 0:
    print(-1)
    exit()

while a%2 == 0 and b%2 == 0 and c%2 == 0:
    ta = a
    tb = b
    tc = c
    a = (tb+tc)//2
    b = (tc+ta)//2
    c = (ta+tb)//2
    count += 1

print(count)

Measured memory_bytes: 3064
#include<stdio.h>

int main(void){
    int n;
    long m;
    scanf("%d %ld",&n,&m);
    long max = (m / n) + 1;
    for(long i = max;i >= 1;i--){
        if(!(m % i) && (m / i) >= n || i == 1){
            printf("%d",i);
            return 0;
        }
    }
}

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

#define LL long long

const int maxN = 1e5 + 100;

int n;
int q[maxN + 1];
LL x[maxN + 1], T, E, f[maxN + 1], ans;

int main()
{
	scanf("%d %lld %lld", &n, &E, &T);
	for(int i = 1; i <= n; i++) scanf("%lld", &x[i]), ans += x[i] - x[i - 1];
	ans += E - x[n];

	int now = 0, head = 1, tail = 0;
	LL minT = 1e18; q[++ tail] = 0;
	for(int i = 1; i <= n; i++)
	{
		while(head <= tail && 2 * (x[i] - x[ q[head] + 1 ]) >= T) head ++;
		while(now < i && 2 * (x[i] - x[now + 1]) >= T) 
			minT = min(minT, f[now] - 2 * x[now + 1]), now ++;
		f[i] = minT + 2 * x[i];
		if(head <= tail) f[i] = min(f[i], f[ q[head] ] + T);
		while(head <= tail && f[i] <= f[ q[tail] ]) tail --;
		q[++ tail] = i;
	}

	printf("%lld", ans + f[n]);
	return 0;
}

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

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

using namespace std;

using LL = long long int;
using LD = long double;

using pii = pair<int, int>;
using pll = pair<LL, LL>;
using pdd = pair<double, double>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<LL>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;

const int INF = (1 << 30) - 1;
const LL INF64 = ((LL)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
LL gcd(LL x, LL y) { return y ? gcd(y, x % y) : x; }

int main() {

	vvi m(14, vi(14));

	char ch;
	int x, y, s;
	while (cin >> x >> ch >> y >> ch >> s){
		y += 2;
		x += 2;

		m[y][x]++;
		m[y + 1][x]++;
		m[y - 1][x]++;
		m[y][x + 1]++;
		m[y][x - 1]++;

		if (s == 1) {
			continue;
		}

		m[y + 1][x + 1]++;
		m[y + 1][x - 1]++;
		m[y - 1][x + 1]++;
		m[y - 1][x - 1]++;

		if (s == 2) {
			continue;
		}

		m[y + 2][x]++;
		m[y - 2][x]++;
		m[y][x + 2]++;
		m[y][x - 2]++;
	}

	int noInkGrid = 0;
	int maxInc = 0;
	for (int i = 2; i < 12; i++) {
		for (int j = 2; j < 12; j++) {
			if (m[i][j] == 0) {
				noInkGrid++;
			}
			maxInc = max(maxInc, m[i][j]);
		}
	}

	cout << noInkGrid << endl;
	cout << maxInc << endl;
	return 0;
}

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

typedef long long ll;

using namespace std;
int main() {
	int N,res=0,A=0,B=0;
	string S;
	cin >> S;
	for (int i = 0; i < S.size(); i++)
	{
		if (S.at(i) == '1') { A++; }
		if (S.at(i) == '0') { B++; }
	}
	res = 2 * min(A, B);
	cout << res << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int A, B, C;
    scanf("%d%d%d", &A, &B, &C);
    int ans;
    if(B > C) ans = B + C;
    else if(A >= C - B)
    {
        ans = B + C;
    }
    else if(C - B - A >= 1)
    {
        ans = B + B + A + 1;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int Y[]={0,1,0,-1};
int X[]={1,0,-1,0};
int main(){
  int n,ny,nx,t,r,i,j,k,c,f,e,y[200],x[200];
  char s[20][10]={0};
  scanf("%d",&n);
  while(n--){
    for(i=0;i<12;i++)scanf("%s",s[i+1]+1);
    for(c=0;f=1;c++){
      int d[20][10]={0};
      for(i=1;i<13;i++){
	for(j=1;j<7;j++){
	  if(d[i][j]||s[i][j]=='.'||s[i][j]=='O')continue;
	  d[y[t=0]=i][x[0]=j]=1;
	  for(r=1;r-t;t++){
	    for(k=0;k<4;k++){
	      ny=y[t]+Y[k];
	      nx=x[t]+X[k];
	      if(s[ny][nx]-s[y[0]][x[0]]||d[ny][nx])continue;
	      d[y[r]=ny][x[r]=nx]=1;
	      r++;
	    }
	  }
	  if(r<4)continue;
	  for(t=f=0;t<r;t++){
	    d[y[t]][x[t]]=2;
	    for(k=0;k<4;k++){
	      ny=y[t]+Y[k];
	      nx=x[t]+X[k];
	      if(s[ny][nx]=='O')d[ny][nx]=2;
	    }
	  }
	}
      }
      if(f)break;
      for(j=1;j<7;j++){
	e=0;
	for(i=13;i;i--){
	  s[i+e][j]=s[i][j];
	  if(d[i][j]==2)e++;//,printf("%d %d\n",i,j);
	}
	for(i=e;i;i--)s[i][j]='.';
      }
      //for(i=0;i<12;i++)printf("%s\n",s[i+1]+1);//break;
    }
    //for(i=0;i<12;i++)printf("%s\n",s[i+1]+1);//break;
    printf("%d\n",c);
  }
  return 0;
}

Measured memory_bytes: 596
#include<cstdio>
#include<iostream>
#define fi(s) freopen(s,"r",stdin);
#define fo(s) freopen(s,"w",stdout);
using namespace std;
typedef long long ll;
const int N = 1000000 + 5;
ll read() {
	ll x = 0,f = 1;char c = getchar();
	while(c < '0' || c > '9') {
		if(c == '-') f = -1;
		c = getchar();
	}
	while(c >= '0' && c <= '9') {
		x = x * 10 + c - '0';
		c = getchar();
	}
	return x * f;
}
int a[N];
int Min,Max,Minjs,Maxjs;
int main() {
//	freopen("hat.in","r",stdin);
//	freopen("hat.out","w",stdout);
//	int T =  read();
//	while(T--) {
		int n = read();
		Min = N; Max = -1;
		Minjs = Maxjs = 0;
		for(int i = 1;i <= n;++i) {
			a[i] = read();
			Min = min(Min,a[i]); Max = max(Max,a[i]);
		}
		if(Max - Min > 1) {
			puts("No");//continue; ret
			return 0;
		}
		if(Min == Max) {
			if(Min + 1 == n || Min <= (n>>1)) puts("Yes");
			else puts("No");
//			continue;
			return 0;
		}
		for(int i = 1;i <= n;++i) {
			if(a[i] == Min) Minjs++;
			if(a[i] == Max) Maxjs++;
		}
		if(Max <= Minjs) {
			puts("No");
			return 0;
		}
		Max -= Minjs;
		if(Max > (Maxjs >> 1) ) {
			puts("No"); 
						return 0;

		}
		puts("Yes");
//	}
//	fclose(stdin);
//	fclose(stdout);
	return 0;
}




Measured memory_bytes: 640
#include "bits/stdc++.h"
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define all(V) (V).begin(), (V).end() 
#define x first
#define y second

using namespace std;

typedef long long ll;
template <typename T> using V = vector <T>;

int main() {fio;
	string s, t;
	cin >> s >> t;
	V <V <int> > DP(s.size(), V <int> (t.size(), 0));
	V <V <pair <int, int> > > prev(s.size(), V <pair <int, int>> (t.size()));

	for(int si = 0; si < s.size(); si++) {
		for(int ti = 0; ti < t.size(); ti++) {
			if(s[si] == t[ti]) {
				if(si == 0 || ti == 0) {
					DP[si][ti] = 1;
					prev[si][ti] = {-1, -1};
				} else {
					DP[si][ti] = 1 + DP[si - 1][ti - 1];
					prev[si][ti] = {si - 1, ti - 1};
				}
			} else {
				prev[si][ti] = {-1, -1};
				if(si) {
					DP[si][ti] = max(DP[si][ti], DP[si - 1][ti]);
					if(DP[si][ti] == DP[si - 1][ti]) {
						prev[si][ti] = {si - 1, ti};
					}
				}
				if(ti) {
					DP[si][ti] = max(DP[si][ti], DP[si][ti - 1]);
					if(DP[si][ti] == DP[si][ti - 1]) {
						prev[si][ti] = {si, ti - 1};
					}
				}
			}
		}
	}
	string ans;
	pair <int, int> cur = {s.size() - 1, t.size() - 1};
	while(cur.first != -1) {
		if(s[cur.x] == t[cur.y]) {
			ans.push_back(s[cur.x]); 
		}
		cur = prev[cur.x][cur.y];
	}	
	reverse(all(ans));
	cout << ans;
    return 0;
}

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

//macro-----------------------------------------------------------------------------------------
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i=a;i>b;i--)
#define int long long

//constant--------------------------------------------------------------------------------------
const int inf = 100100100100000;
const int mod = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//general_method--------------------------------------------------------------------------------
vector<int> cs(vector<int> arr){vector<int> ret = arr;rep(i,1,arr.size()){ret[i] += ret[i-1];}return ret;}
int ceil(int a, int b){if(a%b == 0) return a/b;else return a/b + 1;}
int digitlen(int i){int t = i;int count = 0;while(t){count += 1;t /= 10;}return count;}
int gcd(int m, int n){if((0== m)||(0 == n))return 0;while(m != n){if(m > n)m = m - n;else n = n - m;}return m;}
int lcm(int n, int m){return n*m/gcd(n,m);}

//io_method-------------------------------------------------------------------------------------
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
string readline(){string s;getline(cin, s);return s;}
void print(int n){cout << n << endl;}
void print(vector<int> arr){cout << arr[0];rep(i,1,arr.size()) cout << " " << arr[i];cout << endl;}
void print(string s){cout << s << endl;}
void print(pair<int, int> p){cout << p.first << " " << p.second;}
void print(vector<vector<int>> arr){rep(i,0,arr.size()){print(arr[i]);}}
void print(double n){cout << n << endl;}

//main------------------------------------------------------------------------------------------


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

    int n = input();
    int k = input();

    vector<int> arr; rep(i,0,n) arr.push_back(input());

    sort(arr.begin(), arr.end(), greater<int>());
    int ans = 0;
    rep(i,0,k){
        ans += arr[i];
    }
    print(ans);
    
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>

int main(void)
{
  double x1,x2,y1,y2,defx,defy,squx,squy,sum,z;

  scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);

  defx=fabs(x1-x2);
  defy=fabs(y1-y2);
  squx=defx*defx;
  squy=defy*defy;
  sum=squx+squy;
  z=sqrt(sum);

  printf("%f\n", z);

  return 0;
}


Measured memory_bytes: 1080
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define MOD 1000000007
#define ALL(a) begin((a)),end((a))
#define MS(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef long long ll;
struct edge
{
	int from, to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator >(const edge& e) const { return cost > e.cost; }
};
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///

int main()
{
	int n, q;
	cin >> n;
	vi s(n);
	REP(i, n) cin >> s[i];
	cin >> q;
	vi t(q);
	REP(i, q) cin >> t[i];
	int cnt = 0;
	REP(i, q)
	{
		REP(j, n)
		{
			if (t[i] == s[j])
			{
				cnt++;
				goto next;
			}
		}
	next:;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 1232
# G[v]: 頂点vに隣接する頂点list
# N: 頂点数
N = int(input())
from collections import defaultdict
G = defaultdict(list)
for _ in range(N-1):
    a,b = map(int,input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)

from collections import deque
dist = [-1]*N
que = deque([0])
dist[0] = 0
while que:
    v = que.popleft()
    d = dist[v]
    for w in G[v]:
        if dist[w] > -1:
            continue
        dist[w] = d + 1
        que.append(w)


dist2 = [-1]*N
que = deque([N-1])
dist2[N-1] = 0
while que:
    v = que.popleft()
    d = dist2[v]
    for w in G[v]:
        if dist2[w] > -1:
            continue
        dist2[w] = d + 1
        que.append(w)

ans = [0, 0]
for a,b in zip(dist, dist2):
    if a <= b:
        ans[0] += 1
    else:
        ans[1] += 1



if ans[0] > ans[1]:
    print("Fennec")
else:
    print("Snuke")




Measured memory_bytes: 74072
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define mp make_pair
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef long double ld;
const int N = 100006;

int main() {
 
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    ll x, k, d;

    cin >> x >> k >> d;
    x = abs(x);
    
    ll need = x / d;

    if(need >= k) {
        cout << x - k * d << '\n';
        return 0;
    }

    k -= need;
    x -= need * d;

    ll y = x, kk = k;

    y -= d;
    kk--;

    ll ans = 2e18;

    if(k % 2 == 0) ans = min(ans, x);
    if(kk % 2 == 0) ans = min(ans, abs(y));

    cout << ans << '\n';
    return 0;
}

// 


Measured memory_bytes: 3600
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>

using namespace std;

int main(void) {
	int N, K;
	cin >> N >> K;
	if (N % 2 == 0) {
		if (N / 2 >= K) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}
	else {
		if (N / 2 + 1 >= K) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 256
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from functools import reduce


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007



from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n, k = LI()
graph = [[] for _ in range(n)]
for a, b in LIR(n-1):
    graph[a - 1] += [b - 1]
    graph[b - 1] += [a - 1]


L = [-1] * n
check = [0] * n
L[0] = k
que = deque([0])
while que:
    cur = que.popleft()
    for nxt in graph[cur]:
        if L[nxt] == -1:
            if check[cur]:
                ret -= 1
                L[nxt] = ret % mod
                que += [nxt]
                continue
            elif cur == 0:
                ret = k - 1
            else:
                ret = k - 2
            L[nxt] = ret % mod
            que += [nxt]
            check[cur] = 1
            que += [nxt]



print(reduce(lambda x, y: x * y % mod, L))

Measured memory_bytes: 75440