akhauriyash/Code-Regression huggingface dataset:
import numpy as np
import itertools

N, K = map(int, input().split())
a = list(map(int, input().split()))
a.sort()

def check(i): #i番目のカードを使わなかった時
    dp = np.zeros(K, dtype = np.bool) #配列の初期化 
    #本来dp[x][y]の配列を用意すべきだけど、一回見たらそれ以降は見ないから上書きしていく
    #xが何であろうか、作れるかどうかだけが大切
    #dp: kが作れるかどうかだけを記録している
    dp[0] = True
    # print (dp)
    for j in itertools.chain(a[:i], a[i+1:]): #i番目を除いたリストを走査
        dp[j:] = np.logical_or(dp[j:], dp[:-j]) #ある数jを使うと、j以降のもの(N-j)個と前から(N-j)個のどちらかがTrueのものは作れる
    return not dp[-a[i]:].any() #dpのK-a[i]からKの範囲どれかにTrueがあるとFalseを返す

#詳しくはノート参照


# aを昇順並べた後の走査で、
# a_iが必要な時、a_(i+1)も必要
# -->二分探索によりlog Nで探索

la = -1
ua = N
while ua - la > 1:
    mid = (ua + la)//2
    if check(mid):
        la = mid
    else:
        ua = mid

print (ua)


Measured memory_bytes: 21544
function Main(input){
    let num = Number(input);
    let result = '';
    const arphabet = 'abcdefghijklmnopqrstuvwxyz'.split('');
    while (0 < num) {
		var m = num % 26; // 1桁目を取得
		if (m === 0) { // z(26文字目)のときは割り切れたとき
			m = 26;
		}
		result = arphabet[m-1] + result;
		num = (num-m)/26; // 26で割って、次の桁に備える 例：10進数なら 335 -> (335 -5) / 30 = 33
    }
    console.log(result);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 29612
import math
x = int(input())


def is_prime(n):
    # 1は素数ではない
    if n == 1:
        return False
    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False
    return True


for i in range(x, 10 ** 6):
    if is_prime(i):
        print(i)
        exit()


Measured memory_bytes: 2940
#include <stdio.h>
int  main(void)
{
	int x,y,z,ans,i=0;
	scanf("%d%d%d",&x,&y,&z);
	for(i=0;y*i+z*(i+1)<=x;i++){
		ans=i;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
bool isP[1000001];
int N = 1000000;
void make_table(){
  for(int i=0;i<=N;i++)isP[i]=true;
  isP[0]=isP[1]=false;
  for(int i=2;i*i<=N;i++){
    if(isP[i]==false)continue;
    for(int j=i+i;j<=N;j+=i){
      isP[j]=false;
    }
  }
}
int main(){
  make_table();
  int n,sum;
  while(cin>>n&&n){
    sum=0;
    for(int i=0;i<=n/2;i++){
      if(isP[i]&&isP[n-i])sum++;
    }
    cout<<sum<<endl;
  }
  return 0;
}

Measured memory_bytes: 2136
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

void yes(int n){
    cout << "Yes" << endl;
}

void no (int n){
    cout << "No" << endl;
}

int main() {
    int a, b, n; cin >> a >> b >> n;
    cout << n / a * b << endl;
}

Measured memory_bytes: 3632
/*
    Author - Param Kothari
    Ah shit, here we go again
*/

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

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define mk make_pair

typedef long long ll;
typedef long double ld;

const ll MOD = 1e9 + 7;

ll modp(ll x, ll y, ll p){  
    ll res = 1;
    x = x % p;
    while(y > 0){  
        if (y & 1){ 
            res = (res * x) % p; 
        } 
        y = y >> 1;
        x = (x * x) % p;  
    }  
    return res % p;  
}

void solve(){
    ll n;
    cin >> n;
    ll res = 0;
    if(n == 1){
        cout << 0 << "\n";
        return;
    }
    res = modp(10, n, MOD) + modp(8, n, MOD);
    res %= MOD;
    res = (res - modp(9, n, MOD) + MOD) % MOD;
    res = (res - modp(9, n, MOD) + MOD) % MOD;
    cout << res % MOD << "\n";
    return;
}

int main(){
    IOS;
    int t = 1;
    // cin >> t;
    for(int i = 1; i <= t; i++){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#define int long long
using namespace std;
int n, k, q, p, a[123456];
signed main() {
	cin >> n >> k >> q;
	k -= q;
	for (int i = 1; i <= n; i++)a[i] = k;
	for (int i = 0; i < q; i++) { cin >> p; a[p]++; }
	for (int i = 1; i <= n; i++)cout << (a[i] > 0 ? "Yes\n" : "No\n");
}

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

int n, m;

int main(void){
    cin >> n >> m;
    vector<string> A(n);
    vector<string> B(m);
    for(int i = 0; i < n; i++) cin >> A[i];
    for(int i = 0; i < m; i++) cin >> B[i];
    bool matched = false;
    for(int i = 0; i <= n-m; i++){
        for(int j = 0; j <= n-m; j++){
            bool tmp = true;
            for(int s = 0; s < m; s++){
                for(int t = 0; t < m; t++){
                    if(A[i+s][j+t] != B[s][t]) tmp = false;
                }
            }
            if(tmp){
                matched = true;
                i = j = n-m+1;
            }
        }
    }
    if(matched) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pi 3.141592653589
 
ll power(ll b,ll e,ll m)
{
    if(e==0) return 1;
    if(e&1) return b*power(b*b%m,e/2,m)%m;
    return power(b*b%m,e/2,m);
}
ll power(ll b,ll e)
{
    if(e==0) return 1;
    if(e&1) return b*power(b*b,e/2);
    return power(b*b,e/2);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,M=1e9+7;
    cin>>n;
    ll ans1=power(10,n,M);
    ll ans2=(2*power(9,n,M)-power(8,n,M)+M)%M;
    cout<<(ans1-ans2+M)%M;
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    int t = n;

    int digisum = 0;
    while(n>0){
        digisum += n%10;
        n = n/10;
    }

    if(t%digisum == 0) cout << "Yes" << endl;
    else cout << "No" << endl;

    // cout << "Hello, World" << endl;
}


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


int N, K;

int main(){
    cin >> N >> K;
    double ans = 0;
    for(int i = 1; i <= N; i++){
        double p = 1. / N;
        int j = i;
        while(j < K){
            j *= 2;
            p /= 2;
        }
        ans += p;
    }
    cout << setprecision(15) << ans << endl;
}


Measured memory_bytes: 256
#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 <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>
#define rep(i,n) for(int i=0;i<(n); i++)

using namespace std;
typedef long long ll;
const int MAX_N = 100000;
const int MAX_W = 1000000000;
static const int INF = 1<<29;
string s,t,ans;
int dp[3001][3001];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0); //この2行はより速度を向上させる
    // 追加２, 以降 cin の入力元が 'input.txt' になる
    //提出時に消す！！

    int N,D,a,ans;
    cin >> N >> D;
    a = N%(2*D+1);
    ans = N/(2*D+1);
    if(a==0){
        cout << ans << endl;
        return 0;
    }
    ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <bitset>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#else
#define eprintf(...)
#endif

#define TIMESTAMP(x) eprintf("["#x"] Time : %.3lf s.\n", clock()*1.0/CLOCKS_PER_SEC)
#define TIMESTAMPf(x,...) eprintf("[" x "] Time : %.3lf s.\n", __VA_ARGS__, clock()*1.0/CLOCKS_PER_SEC)

using namespace std;

#ifdef LOCAL
static struct __timestamper {
  string what;
  __timestamper(const char* what) : what(what){};
  __timestamper(const string& what) : what(what){};
  ~__timestamper(){
    TIMESTAMPf("%s", what.data());
	}
} __TIMESTAMPER("end");
#else 
struct __timestamper {};
#endif

typedef long long ll;
typedef long double ld;

int g[20];
int dp[(1 << 15)];
int n;

const int MOD = 1000000007;

int add(int &a, int b) {
  if ((a += b) >= MOD) a -= MOD;
}

int mult(int a, int b) {
  return (a * 1LL * b) % MOD;
}


void solve(int mask) {
  int& ans = dp[mask];
  ans = 0;
  for (int submask = mask; submask != 0; submask = (submask - 1) & mask) {
    if ((submask & 1) != ((submask >> 1) & 1)) continue;
    int coef = 1;
    for (int j = 0; j < n; j++) {
      if (!(mask & (1 << j))) {
        int c = __builtin_popcount(g[j] & submask);
        coef = mult(coef, (1 << c) - 1);
      }
      if (submask & (1 << j)) {
        int c = __builtin_popcount(g[j] & ~mask);
        coef = mult(coef, (1 << c));
      }
    }
    add(ans, mult(coef, dp[mask ^ submask]));
  }
}

int main() {
#ifdef LOCAL
  freopen("f.in", "r", stdin);
  freopen("f.out", "w", stdout);
#endif

  int m;
  while (scanf("%d%d", &n, &m) == 2) {
    memset(g, 0, sizeof(g));
    memset(dp, -1, sizeof(dp));

    for (int i = 0; i < m; i++) {
      int a, b;
      scanf("%d%d", &a, &b);
      --a, --b;
      g[a] |= (1 << b);
    }

    dp[0] = 1;

    for (int mask = 1; mask < (1 << n); mask++) {
      solve(mask);
    }

    int ans = 1;
    for (int i = 0; i < m; i++) {
      ans = mult(ans, 2);
    }
    add(ans, MOD - dp[(1 << n) - 1]);

    printf("%d\n", ans);
  }

  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int w, h;
int mx[] = {0, 0, -1, 1};
int my[] = {-1, 1, 0, 0};

int dfs(int x, int y, vector<string> &v) {
    int cnt = 1;
    for ( int i = 0; i < 4; i++ ) {
        int nx = x + mx[i], ny = y + my[i];
        if ( 0 <= nx && nx < w && 0 <= ny && ny < h && v[ny][nx] == '.' ) {
            v[ny][nx] = '#';
            cnt += dfs(nx, ny, v);
        }
    }
    return cnt;
}

int main() {
    while ( true ) {
        int x, y;
        cin >> w >> h;
        if ( w == 0 && h == 0 ) break;

        vector<string> v(h);

        for ( int i = 0; i < h; i++ ) {
            cin >> v[i];

            for ( int j = 0; j < v[i].size(); j++ ) {
                if ( v[i][j] == '@' ) {
                    y = i;
                    x = j;
                }
            }
        }

        cout << dfs(x, y, v) << endl;
    }
    return 0;
}

Measured memory_bytes: 1236
import Control.Monad
import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)

main :: IO ()
main = do
    n <- fst . fromJust . B.readInt <$> B.getLine
    ss <- replicateM n $ fst . fromJust . B.readInt <$> B.getLine
    let t = sum ss
    if t `mod` 10 == 0
        then do
            let l = filter (\x -> x `mod` 10 /= 0) ss
            if null l
                then print (0 :: Int)
                else print $ t - minimum l
        else print t


Measured memory_bytes: 508
#include <iostream>
#include <numeric>

int main()
{
    int K;
    std::cin >> K;

    auto result = 0;

    for (auto a = 1; a <= K; a++) {
        for (auto b = 1; b <= K; b++) {
            auto tmp = std::gcd(a, b);

            for (auto c = 1; c <= K; c++) {
                result += std::gcd(tmp, c);
            }
        }
    }

    std::cout << result << std::endl;

    return 0;
}

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

using namespace std;

typedef long long ll;
const int N=1e5+100;
ll linf = 1e15+5;

ll n,k;
ll a[N];
ll mem[N];

ll solve(int idx)
{
    if(idx==n-1)
        return 0;
    /*if(idx>=n)
        return linf;*/
    if(mem[idx]!=-1)
        return mem[idx];
    ll mn=linf;
    for(int i=1;(i<=k);++i)
    {
        if(idx+i>=n)
            break;
        mn=min(mn,solve(idx+i)+abs(a[idx]-a[idx+i]));
    }
    return mem[idx] = mn;
}

int main(){

    cin>>n>>k;
    for(int i=0;i<n;++i)
    {
        cin>>a[i];
        mem[i]=-1;
    }
    cout<<solve(0);

    return 0;
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
\
int main(){
  int N, c;
  cin >> N;
  c = 0; //カウンタ変数
  for (int i=0; N>i; i++){
    string s;
    cin >> s;
    if (s=="Y"){
      c += 1;
    }
  }
  if (c > 0){
    cout << "Four" << endl;
  }
  else{
    cout << "Three" << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define SWAP(type, x, y) do { type tmp = x; x = y; y = tmp; } while (0)

#define MOD 1000000007 

int main(void){
    int N;
    long T;
    scanf("%d%ld",&N,&T);

    long* t;
    NEW(t,N);
    for(int i=0;i<N;i++){
        scanf("%ld",&t[i]);
    }

    long ans=0;
    long start=0;
    long end=T;
    for(int i=0;i<N;i++){
        if(t[i]>end){
            ans+=(end-start);
            start=t[i];
            end=t[i]+T;
        }
        else end=t[i]+T;
    }
    ans+=(end-start);
    printf("%ld\n",ans);

    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

int main() {
    int n;
    cin >> n;
    vector<int> a;
    a.push_back(1);
    int sixp = 6, ninep = 9;
    while(sixp<100000){
        a.push_back(sixp);
        sixp *= 6;
    }
    while(ninep<100000){
        a.push_back(ninep);
        ninep *= 9;
    }
    sort(a.begin(),a.end());

    vector<int> dp(n+1);
    dp[0] = 0; dp[1] = 1;
    for(int i = 2; i < n+1; i++){
        int minnum = 99999;
        for(int j = 0; j < a.size(); j++){
            if(i-a[j]>=0){
                minnum = min(minnum, dp[i-a[j]]+1);
            }
        }
        dp[i] = minnum;
    }

    cout << dp[n] << endl;

}

Measured memory_bytes: 640
#include <bits/stdc++.h>
 
#define ll long long
#define ld long double
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define for0(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define forr(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define forab(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define foriter(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define endl '\n'
#define INF (ll)(1e9)
#define EPS 1e-9
#define MOD (ll)(1e9+7)
#define PI 3.1415926535897932384626433832795
#define set set
#define mset multiset
#define uset unordered_set
#define umset unordered_multiset
#define map map
#define mmap multimap
#define umap unordered_map
#define ummap unordered_multimap

using namespace std;
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vll;
typedef vector<vll> vvll;
typedef pair<i64, i64> pll;

int inp(){
  int x; 
  cin>>x;
  return x;
}

//=============================================================================//

void solve() {
    int x; cin>>x;
    cout<<(x>29? "Yes":"No");
}

int main() {
    
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);

    int T=1;
    //cin >> T;
    while (T--) {
        solve();
        cout<<endl;
    }
    
    return 0;
}

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

int main(){

 int n;
 cin >> n;
 int a[n+1],total = 0;
 for(int i = 1; i <= n; i++){
  cin >> a[i];
  total += a[i]; 
 }	
 int m;
 cin >> m;
 int x,y;
 while(m--){
 cin >> x >> y;
 cout << total - a[x] + y << "\n";
 }
 return 0;	
}


Measured memory_bytes: 3616
#include <iostream>
#define int long long 
using namespace std;	

typedef long long ll;

int mod=1000003;

ll fac[1000010];
 
ll modinv(ll a){
    ll b=mod,u=1,v=0;
    while(b){
        ll t=a/b;
        a-=t*b; swap(a,b);
        u-=t*v; swap(u,v);
        }
        u%=mod;
        if(u<0) u+=mod;
    return u;
}
 
void modfac(){
    fac[0]=1;
    for(ll i=1;i<1000010;i++){
        fac[i]=(fac[i-1]*i)%mod;
    }
}
 
ll modperm(ll n,ll k){
    if(n<0||k<0||n<k) return 0;
    else return (fac[n]*modinv(fac[n-k]))%mod;
}
 
ll modcomb(ll n,ll k){
    if(n<0||k<0||n<k) return 0;
    else return ((fac[n]*modinv(fac[k]))%mod*modinv(fac[n-k]))%mod;
}

ll modfrac(ll n,ll m){
    return (n*modinv(m))%mod;
}

ll mod2x(ll n,ll k){
    ll ans=n;
    for(ll i=0;i<k;i++){
      ans=(ans*ans)%mod;
    }
    return ans;
}

string by_x(ll n,ll x){
    string ans="";
    while(n>0){
        char c=n%x+'0';
        ans=ans+c;
        n/=x;
    }
    return ans;
}

ll modpow(ll n,ll k){
    ll ans=1;
    string s=by_x(k,2);
    ll t=s.size();
    for(ll i=0;i<t;i++){
      if(s[i]=='1'){
        ans=(ans*mod2x(n,i))%mod;
      }
    }
  return ans;
}

signed main(){
  modfac();
  int q;
  cin >> q;
  int x[q],d[q],n[q];
  for(int i=0;i<q;i++) cin >> x[i] >> d[i] >> n[i];
  for(int i=0;i<q;i++){
    if(d[i]!=0){
      int start=(mod-((x[i]*modinv(d[i]))%mod))%mod;
      int t=modperm(start,n[i]);
      int z=(mod-d[i])%mod;
      int s=modpow(z,n[i]);
      cout << (t*s)%mod << endl;
    }
    else{
      cout << modpow(x[i],n[i]) << endl;
    }
  }
}

Measured memory_bytes: 11008
//
//  main.cpp
//  priority_queue
//
//  Created by ???????????? on 2017/10/17.
//  Copyright ?? 2017 ????????????. All rights reserved.
//

#include <iostream>
#include <stdio.h>
#define MAX 200000000

using namespace std;

int h, A[MAX];


void max_heepify(int ind){
    int left = ind*2;
    int right = ind*2+1;
    int largest;
    if (left <= h && A[left] > A[ind] ){
        largest = left;
    }
    else{
        largest = ind;
    }
    if(right <= h && A[right] > A[largest]){
        largest = right;
    }
    
    if(largest != ind){
        int temp = A[ind];
        A[ind] = A[largest];
        A[largest] = temp;
        
        max_heepify(largest);
    }
}

void heap_increasekey(int i, int key){
    if(key < A[i]) cout << "Error: New key is smaller than current key"<<endl;
    A[i] = key;
    while(i > 1 && A[i/2] < A[i]){
        int temp = A[i];
        A[i] = A[i/2];
        A[i/2] = temp;
        
        i = i/2;
    }
}

void insert(int key){
    h++;
    A[h] = -MAX;
    heap_increasekey(h, key);
}

int heap_extramax(){
    if (h < 1) {
        cout << "Heap underflow" <<endl;
        return 0;
    }
    int max = A[1];
    A[1] = A[h];
    h--;
    max_heepify(1);
    return max;
}


int main(int argc, const char * argv[]) {
    char command[10];
    int key;
    h = 0;
    while(true){
        scanf("%s", command);
        if(command[0] == 'i'){
            scanf("%d", &key);
            insert(key);
        }
        else if(command[0] == 'e' && command[1] == 'x'){
            cout << heap_extramax() << endl;
        }
        else{
            break;
        }
    }
    
//    std::cout << "Hello, World!\n";
    return 0;
}

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

int main()
{
	int x, y;
	bool flag = false;
	std::cin >> x >> y;
	for (int i = 0; i <= x; i++)
	{
		for (int j = 0; j <= x; j++)
		{
			if (2 * i + 4 * j == y && i + j == x)
				flag = true;
		}
	}
	if (flag)
		std::cout << "Yes\n";
	else
		std::cout << "No\n";
	return 0;
}

Measured memory_bytes: 3644
n,k=map(int,input().split())

a=list(map(int,input().split()))

l=[1]
di={}
di[1]=1

for i in a:
    b=a[l[-1]-1]
    if b in di:
        x=b
        break
    l.append(b)
    di[b]=1
aa=0
for j in l:
    if j==x:
        break
    else:
        aa+=1

bb=len(l)-aa
if k<=aa:
    print(l[k])

else:
    cc=(k-aa)%bb
    print(l[aa+cc])


Measured memory_bytes: 35540
#include<iostream>
#include<algorithm>
using namespace std;int t[1024],i,j,k,r,c,a[10000],m,z;main(){for(;i<1024;t[i++]=k)for(k=j=10;j--;i&1<<j||--k);for(;cin>>r>>c,i=r;cout<<m<<'\n'){for(fill(a,a+c,m=0);i--;)for(j=c;j--;k?a[j]|=1<<i:0)cin>>k;for(i=1<<r;i--;m=max(m,z),z=0)for(j=c;j--;z+=max(k,r-k))k=t[a[j]^i];}}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep1(i,n) for (int i = 1; i <= n; ++i)
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline T intceil(T a, T b) { return (a + (b - 1)) / b; }
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
const long long MOD = 1e9+7;
#define precout() cout << std::fixed << std::setprecision(20);
const string alphabet = "abcdefghijklmnopqrstuvwxyz";
const int dy[4] = { 0, 1, 0, -1 };
const int dx[4] = { 1, 0, -1, 0 };
typedef complex<double> cd;
static const double pi = 3.141592653589793;

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

  int n; cin >> n;
  int left = 0, right = n;

  cout << 0 << endl << flush;
  string leftT; cin >> leftT;
  if(leftT == "Vacant") {
    return 0;
  }

  while(true) {
    int mid = (left + right) / 2;
    cout << mid << endl << flush;
    string curT; cin >> curT;

    if(curT == "Vacant") {
      return 0;
    }

    if(((mid - left) % 2 == 0 && leftT == curT) || ((mid - left) % 2 == 1 && leftT != curT)) {
      left = mid;
      leftT = curT;
    } else {
      right = mid;
    }
  }
}


Measured memory_bytes: 852
#define SUBMIT

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_B
// Search - Binary Search

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int n, q;
    vector<int> s, t;
    cin >> n;
    s.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> s[i];
    }
    cin >> q;
    t.resize(q);
    for (int i = 0; i < q; ++i) {
        cin >> t[i];
    }

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

    auto ans = 0;
    for (const auto& t_i : t) {
        if (*lower_bound(s.begin(), s.end(), t_i) == t_i) {
            ans++;
        }
    }

    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3356
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a[3+1][3+1], s=0, f=0;
	for(int i=1;i<=3;i++)
	{
		for(int j=1;j<=3;j++)
		{
			cin >> a[i][j];
		}
	}
	for(int i=1;i<=2;i++)
	{	
		s=a[i][1]-a[i+1][1];
		for(int j=2;j<=3;j++)
		{
				if(a[i][j]-a[i+1][j]!=s)
				{
					f=1;
					break;
				}
		}
		if(f==1)
	    {
		 	break;
		}
	}
	if(f==1)
	{
		cout << "No"<<endl;
		return 0;
	}
	else
	{
		cout << "Yes"<<endl;
		return 0;
	}
}

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

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

    while (1) {
        int w, h, n;
        cin >> w >> h >> n;
        if (w == 0 && h == 0) break;
        vector<int> xs(2 * n + 4), ys(2 * n + 4);
        for (int i = 0; i < 2 * n; i++) cin >> xs[i] >> ys[i];
        xs[2 * n] = 0; ys[2 * n] = 0;
        xs[2 * n + 1] = w; ys[2 * n + 1] = 0;
        xs[2 * n + 2] = 0; ys[2 * n + 2] = h;
        xs[2 * n + 3] = w; ys[2 * n + 3] = h;
        int N = 2 * n + 4;

        set<pair<int, int>> grads;
        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                if (xs[i] == xs[j]) continue;
                int dx = xs[j] - xs[i];
                int dy = ys[j] - ys[i];
                int g = __gcd(dx, dy);
                dx /= g;
                dy /= g;
                if (dy < 0) {
                    dx = -dx;
                    dy = -dy;
                }
                grads.insert({dy, dx});
            }
        }
        set<double> gs;
        for (auto &g : grads) {
            gs.insert((double) g.first / g.second);
        }

        vector<double> ss;
        for (double g : gs) ss.push_back(g);


        double ans = 0;
        for (int i = 0; i < (int) ss.size() - 1; i++) {
            double a = (ss[i] + ss[i + 1]) / 2;
            vector<pair<double, int>> vs;
            for (int j = 0; j < 2 * n; j++) {
                vs.emplace_back(ys[j] - a * xs[j], j);
            }
            sort(vs.begin(), vs.end());
            int A = vs[n - 1].second, B = vs[n].second;
            double tn = vs[n - 1].first, tN = vs[n].first;

            tN=min(tN,double(h));
            tN=min(tN,h-a*w);
            tn=max(tn,double(0));
            tn=max(tn,-a*w);

            if(tN>tn) ans+=(ss[i+1]-ss[i])*(tN-tn);

        }

        ans /= (double) h * h / w;
        cout << setprecision(20) << fixed << ans << endl;
    }
}


Measured memory_bytes: 5408
#include <bits/stdc++.h>
#define N 8000000
using namespace std;

int prime[N] = {0};
int n, m, now = 0;

int sprime() {
  int i, j;
  for(i = n; i < N; ++i)
    if(prime[i] == 0) {
      if(now == m) return i;
      ++now;
      for(j = 1; i * j < min(N, m * 1000); ++j)
        prime[i * j] = 1;
    }
  return 0;
}

int main() {
  while(1) {
    memset(prime, 0, sizeof(prime));
    cin >> n >> m;
    now = 0;
    if(n + m == 0) break;
    cout << sprime() << endl;
  }
  return 0;
}



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

A = [[0 for i in range(n)] for j in range(m)]
for i in range(m):
    A[i] = [int(x) for x in input().split()]

b = []
for j in range(n):
    b.append(int(input()))

c = [0 for i in range(m)]
for i in range(m):
    for j in range(n):
        c[i] += A[i][j] * b[j]

for i in range(m):
    print(c[i])


Measured memory_bytes: 5788
#include<iostream>
using namespace std;
//int dp[100003],v[100003];
int main()
{
	int n;
	cin>>n;
	int dp[n],v[n],k;
	cin>>k;
	for(int i =0;i<n;i++)
	{
		dp[i] = (int)1e9+5;
	}
	for(int i=0;i<n;i++)
	{
		cin>>v[i];
	}
	//v[n] = 10000;
	//v[n+1] = 100000;
	//v[n+2] = 10000;
	dp[0]  =0;
	for(int i =0;i<n;i++)
	{
		for(int j = i+1;j<i+k+1;j++)
		{
			if(j<n)
			{
				dp[j] = min(dp[j],dp[i]+abs(v[i] - v[j]));
			}
		}
	}
	cout<<dp[n-1]<<"\n";
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define pc _putchar_nolock
#define mp make_pair
#define mt make_tuple
#define um unordered_map
#define inf (ll)9223372036854775807
#define sz(x) (int)x.size()
using namespace std;
using ll=long long int;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
void input(vector<int>&a,int n)
{
   rep(i,0,n-1)
   cin>>a[i];
}
void solve()
{
  int n; cin>>n; vector<int>p(n); input(p,n); int res=0;
  rep(i,0,n-1)
  {
  	if(i!=0 and i!=n-1)
  	{
  		vector<int>v; v.eb(p[i-1]); v.eb(p[i]); v.eb(p[i+1]); 
		  sort(all(v)); if(v[1]==p[i]) res++; 
	  }
  }
  cout<<res<<"\n"; return;
}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t=1;
  while(t--)
  {
	 solve();
  }
  return 0;
}


Measured memory_bytes: 3616
input()
inp = input().strip().split(' ')
inp = [int(v) for v in inp]
flg = 'Yes'
for i in reversed(range(len(inp) - 1)):
    if inp[i] - inp[i + 1] == 1:
        inp[i] -= 1
    elif inp[i + 1] >= inp[i]:
        a = 1
    else:
        flg = 'No'
        break
print(flg)


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

    int main()
    {
        int a,b,c,d,th,ah;
        cin>>a>>b>>c>>d;
        while(1)
        {

            ah = c - b;
            if(ah <= 0) {
                    cout<<"Yes"<<endl;
                    break;
            }

            th = a - d;
            if(th <= 0)
            {
                cout<<"No"<<endl;
                    break;
            }
            a = th;
            c = ah;
        }
    }



Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int n;
    cin>>n;
    vector<pair<int,int>>p(n);
    rep(i,n){
        int x,l; cin>>x>>l;
        p[i]=make_pair(x+l,x-l);
    }
    sort(p.begin(),p.end());
    ll cnt=p[0].first;
    int ans=n;
    for(int i=1; i<n; ++i){
        if(cnt>p[i].second)ans--;
        else cnt=p[i].first;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
#define debug(P) cout<<#P<<" = "<<P<<endl;
 
typedef long long ll;


const int MAXN = 200001;
int n;
int a[MAXN];
int ans[MAXN];

vector<int> d;

vector<int> adj[MAXN];

void dfs(int x, int p){
	int pos = lower_bound(d.begin(), d.end(), a[x]) - d.begin();

	bool pushed = 0;

	if(pos == d.size())d.push_back(a[x]), pushed = 1;

	ans[x] = d.size();

	int svi = pos, svv = d[pos];

	if(!pushed)d[pos] = a[x];

	for(int c : adj[x]){
		if(c!=p){
			dfs(c, x);
		}
	}

	if(!pushed)d[svi] = svv;
	else d.pop_back();
}
 
int main() {
	//freopen("input.txt","r",stdin);
	cin>>n;

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

	for(int i= 1; i < n; ++i){
		int u, v;
		cin>>u>>v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}

	d.clear();

 	dfs(1, 0);

 	for(int i= 1; i <= n; ++i)cout<<ans[i]<<'\n';
}

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

int main(){
  string a;
  string b;
  int count=0;
  cin>>a;
  cin>>b;
  for(int i=0; i<a.length();i++){
    if(a[i]!=b[i]){
      char c = b[i];
      b[i]=a[i];
      a[i]=c;
      count++;
    }
  }
  cout<<count;
  return 0;
}

Measured memory_bytes: 3916
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

int main() {
    int a,b;
    cin >> a >> b;
    int ans = 0;
    int outlet = 1;
    while(outlet < b){
        ans++;
        outlet += (a-1);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
D = int(input())
C = list(map(int, input().split()))
S = [0] * D
for i in range(D):
  S[i] = list(map(int, input().split()))
         
         
t = [0] * (D + 1)
#for i in range(D):
#  t[i] = int(input())
  
last = [0] * (26)
score = 0
for i in range(1, D + 1):
  score = -10000000
  for j in range(26):
    score2 = 0
    score2 += S[i - 1][j]
    score2 -= C[j] * (i - last[j])
    if score < score2:
      score = score2
      t[i] = j
      last[j] = i
    
#print(t)
for i in range(1, len(t)):
  print(t[i] + 1)
    
    
    

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

int main(){
    int n,k;
    cin >> n >> k;
    if(n>=k) {
    if(n%k==0) cout << 0 <<endl;
    else cout << 1 << endl;
    }
    else cout << 1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;cin>>n;
    bool flag=0;
    while(n){
        if(n%10==7){
            flag=1;
            break;
        }
        n/=10;
    }
    if(flag) puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 3596
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 998244353
#define INF (1<<30)
#define LINF (1LL<<60)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
typedef unsigned long long int ull;
typedef long long lint;

int main(void){
    int N;
    cin >> N;
    int even=0,odd=0;
    rep(i,N){
        int X;
        cin >> X;
        if(X%2==0) even++;
        else odd++;
    }
    if(odd%2==0) cout << "YES" << endl;
    else cout << "NO" << endl;
}

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

typedef long long int llint;

int main()
{
  string str;
  llint k;

  cin>> str >> k;

  for(int i = 0; i < str.size(); i++) {
    if(str[i] == '1' && i + 1 < k) continue;
    else {
      cout<< str[i] <<endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 200000 + 10;
long long a[N << 1];
int n, k;
int main() {
	scanf("%d %d", &k, &n);
	for (int i = 1; i <= n; i++)	scanf("%lld", a + i);
	sort(a + 1, a + 1 + n);
	for (int i = 1; i <= n; i++)	a[i + n] = a[i] + k;
	long long ans = k;
	for (int i = 1; i <= n; i++)	ans = min(ans, a[i + n - 1] - a[i]);
	cout << ans;
	// system("pause");
	return 0;
}

Measured memory_bytes: 3328
using System;
					
public class Program
{
	public static void Main()
	{
		var input = Console.ReadLine();
		var split = input.Split(' ');
		if(int.Parse(split[0]) < int.Parse(split[1])){
			Console.WriteLine("0");
		}else{
			Console.WriteLine("10");
		}
		//nsole.WriteLine("Hello World");
	}
}

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

int main() {
	int a, b, c;
	cin >> a;
	cin >> b;
	cin >> c;

	if ((a < b && a < c) && (b < c)) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 3072
import sys
sys.setrecursionlimit(10**6)

MOD = 998244353


def main(input, print):
    n, s = map(int, input().split())
    a = list(map(int, input().split()))
    dp = [[0 for _ in range(s+1)] for _ in range(n+1)]
    dp[0][0] = 1
    for i in range(n):
        for j in range(s+1):
            dp[i+1][j] += dp[i][j]*2
            dp[i+1][j] %= MOD
            if j+a[i] <= s:
                dp[i+1][j+a[i]] += dp[i][j]
                dp[i+1][j+a[i]] %= MOD
    print(dp[n][s])


if __name__ == '__main__':
    main(sys.stdin.readline, print)


Measured memory_bytes: 147024
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    n, k, q = map(int, input().split())
    qk = q - k
    l = [0] * (n+1)
    for _ in range(q):
        l[int(input())] += 1
    print('\n'.join(['Yes' if (i > qk) else 'No' for i in l][1:]))

if __name__ == '__main__':
    main()


Measured memory_bytes: 5528
N, W = map(int, input().split())
R = []
for i in range(N):
    v, w = map(int, input().split())
    R.append((v/w, v, w))
R.sort(reverse=1)
ans = 0
for _, v, w in R:
    c = min(w, W)
    W -= c
    ans += c * v / w
print(ans)


Measured memory_bytes: 22236
X,Y = map(int,input().split())
 
c1 = (2*Y-X)
rest = c1%3
c1 = c1//3
if (rest!=0)or((X-c1)<0)or((Y-2*c1)<0)or(c1<0):
  print(0)

else:
  c2 = Y-2*c1
  c3 = c1+c2+1
  mod = 10**9+7
  c4 = min(c1,c2)
  x = 1
  y = 1
  for i in range(1,c4+1):
    x = x * (c3-i) % mod
    y = y * i % mod
    
  result = x * pow(y,mod-2,mod) % mod
 
  print(result)

Measured memory_bytes: 3064
while True:
  a,op,b=map(str,input().split())
  a=int(a)
  b=int(b)
  if op == '?':
    break
  elif op == '+':
    print(a+b)
  elif op == '-':
    print(a-b)
  elif op == '*':
    print(a*b)
  elif op == '/':
    print(a//b)


Measured memory_bytes: 5592
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a),i##_end=(b);i<=i##_end;i++)
#define per(i,a,b) for(int i=(b),i##_st=(a);i>=i##_st;i--)
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define dbg(x) cerr<<#x" = "<<x<<endl
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define Es(x,i) for(Edge *i=G[x];i;i=i->nxt)
typedef long long ll;
typedef pair<int,int> pii;
const int inf=~0u>>1,MOD=1e9+7;
char *TT,*mo,but[(1<<15)+2];
#define getchar() ((TT==mo&&(mo=((TT=but)+fread(but,1,1<<15,stdin)),TT==mo))?-1:*TT++)
inline ll rd() {
    ll x;char c,f=1;while(!isdigit(c=getchar()))f=c!='-';x=c-'0';
    while(isdigit(c=getchar()))x=x*10+c-'0';return f?x:-x;
}
 
const int N=100000+19;
 
ll x[N],tmp;
int P[60][N],Q[N];
int A[N];
int n,m,u;
ll K;
 
int main(){
	n=rd();
	rep(i,1,n)i[x]=rd();
	m=rd(),K=rd();
	rep(i,1,n-1){
		i[0[P]]=i;
		i[Q]=i;
	}
	rep(i,1,m){
		u=rd();
		swap(u[0[P]],P[0][u-1]);
	}
	rep(t,1,59){
		rep(i,1,n-1) i[t[P]]=P[t-1][P[t-1][i]];
	}
	rep(t,0,59) if (K>>t&1){
		rep(i,1,n-1) i[Q]=i[Q][t[P]];
	}
	tmp=1[x];
	printf("%lld\n",tmp);
	rep(i,1,n-1){
		tmp+=x[Q[i]+1]-i[Q][x];
		printf("%lld\n",tmp);
		//printf("%.10lf\n",tmp);
	}
}

Measured memory_bytes: 25856
//
// Created by 陈基彤 on 2019-12-25.
//
#include<bits/stdc++.h>
using namespace std;
int n,u,v;
vector<int> tree[100005];
int deep[100005],fa[100005],dp[100005];
void dfs(int x,int f){
    fa[x] = f;
    for(auto v : tree[x]){
        if(v == f)continue;
        deep[v] = deep[x] + 1;
        dfs(v,x);
        dp[x] = max(dp[x],dp[v] + 1);
    }
}


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>u>>v;
    for(int i=1;i<n;i++){
        int x,y;
        cin>>x>>y;
        tree[x].push_back(y);
        tree[y].push_back(x);
    }
    dfs(v,0);
    int dis = (deep[u] - deep[v])/2;
    int now = u,ans = 0;
    while(dis >= 0){
        ans = max(ans,deep[now] + dp[now] - 1);
//        printf("%d %d %d %d %d %d\n",now,deep[now],dp[now],fa[now],dis,ans);
        now = fa[now];
        dis -= 1;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 12032
#include"bits/stdc++.h"
using namespace std;
int main()
{
  int a,b;
  cin>>a>>b;
  if(a>=1 && a<10 && b>=1 && b<10) {
    cout<<a*b<<"\n";
  }
  else {
    cout<<"-1\n";
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll, ll> pll;
//int dx[4] = { 1,0,0,-1 };
//int dy[4] = { 0,1,-1,0 };
#define MOD 1000000007
#define ARRAY_MAX 55

const int INF = 1e9 + 7;


int main() {


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

	int n;

	while (cin >> n, n) {

		vector<int> vec[ARRAY_MAX];//vec[i]:=i日目までに持てる地図
		bool check[ARRAY_MAX][ARRAY_MAX];

		memset(check, false, sizeof(check));

		

		for (int i = 1; i <= n; i++)
		{
			//i人目の子孫
			int tm;
			cin >> tm;

			for (int j = 0; j < tm; j++)
			{
				//空いている日
				int tmp;
				cin >> tmp;
				vec[tmp].push_back(i);
			}
			check[i][i] = true;
		}

		bool flag = false;

		int ans = -1;
		for (int day = 1; day <= 30; day++)
		{
			//i日目を調べて
			for (int j = 0; j < vec[day].size(); j++)
			{
				for (int k = j + 1; k < vec[day].size(); k++)
				{
					int cnt = 0;
					for (int a = 1; a <= n; a++)
					{
						if (check[vec[day][j]][a] == true || check[vec[day][k]][a] == true)
						{
							check[vec[day][j]][a] = true;
							check[vec[day][k]][a] = true;
							cnt++;
						}
					}
					if (cnt == n)
					{
						ans = day;
						break;
					}
				}
				if (ans != -1)
				{
					break;
				}
			}
			if (ans != -1)
			{
				break;
			}
		}
		cout << ans << endl;
		for (int i = 0; i < ARRAY_MAX; i++)
		{
			vec[i].shrink_to_fit();
		}
	}
	return 0;
}


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

#define ll long long
const int MOD = 1e9 + 7;
#define INF 2e9

#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

#define MATCH(_str, _ptn) regex_match(_str, regex(_ptn))
#define REPLACE(_str, _ptn, _replacement) regex_replace(_str, regex(_ptn), _replacement)

# define pb push_back

# define INIT() cin.tie(0); ios::sync_with_stdio(false); cout << fixed << std::setprecision(20)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

ll n,m,k;
string s;
int main() {
    INIT();

    cin >> n >> k;
    vector<ll> a(n);
    for(ll i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    ll r = 0;
    for(ll i = 0; i < k; i++) {
        r += a[i];
    }
    cout << fixed << std::setprecision(20) << r;
}

Measured memory_bytes: 3660
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <tuple>
#include <functional>

using namespace std;

#define ll long long

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

int main() {
	ll n, a, b;
	ll sum = 0;
	cin >> n;

	vector<pair<ll, ll>> pairs(n);

	for (ll i = 0; i < n; i++) {
		cin >> a >> b;
		pairs[i] = make_pair(-a, b);
	}

	sort(pairs.begin(), pairs.end(), compare_by_b);


	for (ll i = 0; i < n; i++) {
		sum += pairs[i].first * -1;
		if (sum > pairs[i].second) {
			cout << "No" << endl;
			return 0;
		}
	//	cout << sum << endl;
	}

	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 3328
import sys

readline=sys.stdin.readline

s=list(readline().strip())
n=len(s)
f=n%2
mid=s[n//2]

for i in range(n//2):
  if s[n//2-i-1]!=mid or s[(n+1)//2+i]!=mid:
    print((n+1)//2+i)
    break
else:
  print(n)
  


Measured memory_bytes: 9860
#include<iostream>
using namespace std;
int main(){
	int n, a[128],b[128];
	cin >> n;
	for (int i=0;i<n;i++){
		cin >> a[i];
	}
	for (int i = 0; i < n; i++){
		b[n - i] = a[i];
	}
	for (int i = 0; i < n; i++){
		if (i != 0)cout << " ";
		cout << b[i+1];
	}
	cout << endl;
	return 0;
}

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

typedef long long ll;

#define pb push_back
#define mp make_pair
#define f first
#define s second
#define all(a) a.begin(), a.end()

const int maxn = 200010;
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;
int n, m, a[maxn];
string s, ss;

void solve()
{
    cin >> s >> ss;
    int ans=INF;
    for(int i = 0; i <= s.size()-ss.size(); i++)
    {
        int cnt=0;
        for(int j = 0; j < ss.size(); j++)
            if(s[i+j]!=ss[j])cnt++;
        ans = min(ans, cnt);
    }
    cout << ans << "\n";
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int t=1;
    //cin >> t;
    while(t--) solve();
}


Measured memory_bytes: 3652
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

const P: i64 = 1_000_000_007;

fn solve() {
    let N = read!(usize);
    let mut C = read![usize; N];

    for i in 0..N {
        C[i] -= 1;
    }
    let M = C.iter().cloned().max().unwrap();

    let mut last = vec![N; M + 1];
    let mut next = vec![N + 1; N + 1];
    let mut i = 0;
    while i < N {
        while i + 1 < N && C[i] == C[i + 1] {
            i += 1;
        }

        next[last[C[i]]] = i;
        last[C[i]] = i;
        i += 1
    }
    debug!(next);

    // dp[r]: 0..r の塗り方が決まって、r.. に操作が及んでないときの場合の数

    let mut dp = vec![P; N + 2];
    dp[N] = 1;
    dp[N + 1] = 0; // 位置 i より後に同色の石がないとき dp[next[i]] == 0 にしておけば next[i] が存在するかどうかの場合分けを潰せる

    let mut i = N - 1;
    loop {
        dp[i] = dp[i + 1];
        dp[i] += dp[next[i]];
        dp[i] %= P;

        if i == 0 {
            break;
        }
        i -= 1;
    }
    debug!(dp);

    println!("{}", dp[0]);
}

fn main() {
    solve();
}


Measured memory_bytes: 12540
#include <string>
#include <iostream>

using namespace std;

int main()
{

	string S;
	int first, last;
	bool fYY = 0, fMM = 0;
	bool lYY = 0, lMM = 0;

	cin >> S;

	last = first = atoi(S.c_str());

	last = first % 100;
	first = first / 100;

	// is first YY? 
	if (first >= 0 && first < 100) {

		fYY = true;

		// is first MM?
		if (first > 0 && first < 13) {

			fMM = true;

		}
	}

	// is last YY? 
	if (last >= 0 && last < 100) {
		lYY= true;

		// is first MM?
		if (last > 0 && last < 13) {

			lMM = true;

		}
	}

string output;

if (fYY && lYY) {

	if (fMM) {

		if (lMM) {
			output = "AMBIGUOUS";
		}
		else {
			output = "MMYY";
		}
	}
	else if(lMM) {
		output = "YYMM";
	}
else
{
	output = "NA";
}


}
else {
	// neither first and last Year or month

	output = "NA";
}

cout << output << endl;

return 0;

}

Measured memory_bytes: 256