akhauriyash/Code-Regression huggingface dataset:
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
{-# LANGUAGE BangPatterns      #-}
{-# LANGUAGE CPP               #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TupleSections     #-}

import           Control.Applicative
import           Control.Monad
import           Control.Monad.Primitive
import           Control.Monad.ST
import           Control.Monad.State.Strict
import           Data.Bool
import qualified Data.ByteString             as B
import qualified Data.ByteString.Short       as B.Short
import qualified Data.ByteString.Unsafe      as B
import           Data.Char
import           Data.Function
-- import qualified Data.HashMap.Strict         as M
import qualified Data.IntMap.Strict          as M
import qualified Data.IntSet                 as IS
import           Data.List
import           Data.Monoid
import           Data.Ord
import           Data.Primitive.MutVar
import qualified Data.Set                    as S
import           Data.Tuple
import qualified Data.Vector                 as V
import qualified Data.Vector.Generic         as G
import qualified Data.Vector.Generic.Mutable as GM
import qualified Data.Vector.Unboxed         as U
import qualified Data.Vector.Unboxed.Mutable as UM
import           Debug.Trace
import           Foreign                     hiding (void)
import           Unsafe.Coerce

main :: IO ()
main = do
    !n <- readLn :: IO Int
    bs <- B.getLine
    print $ solve n bs

solve :: Int -> B.ByteString -> Int
solve n bs = sum [M.findWithDefault 0 pair rightFreq| pair<-lefts]
  where
    (left, right) = B.splitAt n bs
    lefts = pairs n left
    rights = pairs n $ B.reverse right
    !rightFreq = foldl' (\m pair -> M.insertWith (+) pair 1 m) M.empty rights

pairs n bs = [divide i bs|i<-[0..2^n-1]]
  where
    divide i bs = hash $ map (B.unsafeIndex bs) xis ++ 0:map (B.unsafeIndex bs) yis
      where
        (xis, yis) = partition (testBit (i :: Int)) [0..n-1]

hash :: [Word8] -> Int
hash ws = unsafeShiftL x 32 .|. y
  where
    x = foldl' (\acc w -> (1009 * acc + fromIntegral w) `rem` 1000000007) 0 ws
    y = foldl' (\acc w -> (1007 * acc + fromIntegral w) `rem` 1000000009) 0 ws
{-# INLINE hash #-}


Measured memory_bytes: 46460
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ll INF = 1e16;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

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

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll H, W;
    cin >> H >> W;
    vc<string> A(H);
    rep(i, H) cin >> A[i];

    ll cnt = 0;
    rep(i, H) rep(j, W) if (A[i][j] == '#') cnt++;
    cout << (cnt == H + W - 1 ? "Possible" : "Impossible") << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(void){
	int n;
	while(cin >> n && n){
		vector<pair<int,int> > p;
		int d1,d2, num;
		for(int i=0;i<n;i++){
			cin >> num >> d1 >> d2;
			p.push_back(make_pair(d1+d2,num));
		}
		sort(p.begin(), p.end());
		cout << p.back().second << " " << p.back().first << endl;
 	}
}

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

int c[5];

bool four_card(){
  if(c[0]==c[3] || c[1]==c[4]){
    cout<<"four card"<<endl;
    return true;
  }
  return false;
}

bool full_house(){
  if((c[0]==c[2] && c[3]==c[4]) || (c[0]==c[1] && c[2]==c[4])){
    cout<<"full house"<<endl;
    return true;
  }
  return false;
}

bool straight(){
  int i, n=c[0];
  for(i=1; i<5; i++){
    if(n==1&&c[i]==10){
      n=c[1];
      continue;
    }
    if(c[i]!=n+1)break;
    n=c[i];
  }
  if(i==5){
    cout<<"straight"<<endl;
    return true;
  }
  return false;
}

bool three_card(){
  if(c[0]==c[2] || c[1]==c[3] || c[2]==c[4]){
    cout<<"three card"<<endl;
    return true;
  }
  return false;
}

bool two_pair(){
  int n=0;
  for(int i=0; i<5; i++){
    if(c[i]==c[i+1])n++;
  }
  if(n==2){
    cout<<"two pair"<<endl;
    return true;
  }
  return false;
}

bool one_pair(){
  int n=0;
  for(int i=0; i<5; i++){
    if(c[i]==c[i+1])n++;
  }
  if(n==1){
    cout<<"one pair"<<endl;
    return true;
  }
  return false;
}

int main(){
  while(scanf("%d,%d,%d,%d,%d", &c[0], &c[1], &c[2], &c[3], &c[4])!=EOF){
    sort(c, c+5);
    if(four_card())continue;
    if(full_house())continue;
    if(straight())continue;
    if(three_card())continue;
    if(two_pair())continue;
    if(one_pair())continue;
    cout<<"null"<<endl;
  }
  return 0;
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
using namespace std;
         
#define fast { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define pb push_back
#define ll long long
#define ld long double
#define vll vector<ll>
#define infl LONG_LONG_MAX
#define infd LDBL_MAX
#define F first
#define S second
#define pll pair<ll,ll> 
#define G(a,b) get<a>(b)
#define ALL(v) v.begin(),v.end()
#define MP make_pair
#define MT make_tuple
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fi(i,a,b) for(ll i=(b-1);i>=a;i--)    
#define endl "\n"
#define nl cout<<"\n";
#define pr(x) cout<<x;
#define pr1(x) cout<<x<<" ";
#define pr2(x,y) cout<<x<<" "<<y;
#define sz(x) (ll)x.size() 
#define ara cout<<"ara-ara\n"; 
 
const ll N=2e5+5;
list<ll>adj[N];

void func()
{
   ll n;
   cin>>n;
   f(i,1,n)
   {
	   ll u,v;
	   cin>>u>>v;
	   adj[u].pb(v);
	   adj[v].pb(u);
   } 
   
   ll ans=0;
   f(i,1,n+1) ans+=( ( (n-i+1)*(n-i+2) )/2 );
   f(i,1,n+1)
   {
	   for(auto j:adj[i])
	   {
		   if(i<j) ans-=(i*(n-j+1));
	   }
   }
   
   cout<<ans<<endl;
}   
     
     
     
int main() 
{
    fast
    //#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //#endif // ONLINE_JUDGE
        
     
    ll ntc=1;
    //cin>>ntc;
     
    f(i,1,ntc+1)
    {
      //cout<<"Case #"<<i<<": ";
       func();
    }
     
    return 0;
}


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

const int mod = 1e5;

int main() {
    int N, M, S;
    while (true) {
        cin >> N >> M >> S;
        if (N == 0) break;
        long long dp[N * N + 1][S + 1];
        memset(dp, 0, sizeof(dp));
        dp[0][0] = 1;
        for (int i = 1; i <= N * N; ++i) {
            for (int j = 0; j <= S; ++j) {
                if (j >= i) (dp[i][j] += dp[i][j - i] + dp[i - 1][j - i]) %= mod;
                if (j >= M + 1) (dp[i][j] += mod - dp[i - 1][j - (M + 1)]) %= mod;
            }
        }
        cout << dp[N * N][S] << endl;
    }

    return 0;
}


Measured memory_bytes: 4184
// Crt. 2019-12-15  16:11:58
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <vector>
#define N 100005
using namespace std;

int n, m, a[N];
vector<int> pls[N], mns[N];

inline int Goto(int x, int y) {
    if (x < y) {
        pls[x].push_back(0);
        mns[y].push_back(x - y);
        return y - x;
    } else {
        pls[x].push_back(0);
        pls[1].push_back(m - x + 1);
        mns[y].push_back(-(y + m - x));
        return y + m - x;
    }
}

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

    cin >> n >> m;

    for (int i = 1; i <= n; ++i)
        scanf("%d", a + i);

    long long ans = 0;
    for (int i = 2; i <= n; ++i)
        ans += Goto(a[i - 1], a[i]);

    long long now = 0, num = 0, res = 0;
    for (int i = 1; i <= m; ++i) {
        now += num;
        for (int j = pls[i].size() - 1; ~j; --j)
            now += pls[i][j];
        num += pls[i].size();
        for (int j = mns[i].size() - 1; ~j; --j)
            now += mns[i][j];
        num -= mns[i].size();
        res = max(res, now);
    }

    cout << ans - res << endl;

    return 0;
}
// 215068256


Measured memory_bytes: 10360
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int main(void){
    char a;
    cin>>a;
    int b=a;
    if(b>=97){
        b=97;
        a=b;
    }else{
        b=65;
        a=b;
    }
    cout<<a<<endl;

}



Measured memory_bytes: 3632
# K - Stones
def main():
    N, K, *A = map(int, open(0).read().split())
    dp = [False] * (K + 1)
    for i in range(K):
        if dp[i]:
            continue
        for a in A:
            if i + a > K:
                break
            dp[i + a] = True
    print("First" if dp[-1] else "Second")


if __name__ == "__main__":
    main()


Measured memory_bytes: 3828
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int N; cin >> N;
    map<string,int> MAP;
    rep(i,N) {
        string s;
        cin >> s;
        sort(begin(s), end(s));
        MAP[s]++;
    }
    ll cnt = 0;
    for (auto &x : MAP) {
        if (x.second > 1) {
            cnt += ((ll)x.second * (x.second - 1)) / 2;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 11136
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<complex>
#include<unordered_map>
#define deg(x) cout<<#x<<"="<<x<<endl;
#define fd(x) for(int i=0;i<x;i++)
#define fdd(a,x) for(int i=a;i<x;i++)
#define fx(x,n) for(int i=n-1;i>=x;i--)
#define mst(x) memset(x,0,sizeof(x));
#define fi first
#define se second
#define TB ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define ok "ok"
#define HH puts("");
#define ls rt<<1
#define rs rt<<1|1
#define pb(a,b) a.push_back(b);
#define FIN  freopen("1.in","r",stdin);
#define FOUT freopen("1.out","w",stdout);
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<string,int> pss;
typedef unsigned long long ull;
const ll mod=1e9+7;
const ll inf=1e18;
const long double eps=1e-8;
ll qpow(ll a,ll b,ll m){ ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
const double pi=acos(-1);


int main(){
    TB
    ll n,k;
    cin>>n>>k;
    n=n%k;
    n=min(n,abs(n-k));
    cout<<n<<'\n';
    return 0;
}


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


Measured memory_bytes: 3604
import java.util.Scanner;
public class Main{
 public static void main(String[] args) {
   Scanner kbd = new Scanner(System.in);
   int n =kbd.nextInt();
   long c=0;
   for(int i=1;i<n+1;i++){
     if(i%3!=0&&i%5!=0){
       c=c+i;
     }
   }
   System.out.println(c);
 }
}


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

using namespace std;

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

#define each(i,a) for (auto&& i : a)
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    each(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    rep(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, const vector< vector<T> >& vec) {
    rep(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}

ll dx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
ll dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
ll normalize(ll n, ll L) {
    return (n % L + L) % L;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll h, w;
    while (cin >> h >> w, h || w) {
        vector<string> A(h); cin >> A;
        ll l = 0, r = w*h+1;
        auto f = [&](ll len) {
            string res = "0";
            if (len <= 1) return res;
            set<string> X;
            rep(y0, h) rep(x0, w) rep(d, 8) {
                vector<vector<bool>> used(h, vector<bool>(w, false));
                stack<P> S; S.push({x0, y0});
                string s = "";
                while ( !S.empty() ) {
                    P p = S.top(); S.pop();
                    ll x, y; tie(x, y) = p;
                    if (used[y][x]) break;
                    used[y][x] = true;
                    s += A[y][x];
                    if (s.size() == len) break;
                    S.push({normalize(x+dx[d], w), normalize(y+dy[d], h)});
                }
                if (s.size() != len) continue;
                if (X.count(s) > 0) {
                    if (res == "0" || s < res) res = s;
                }
                else {
                    X.insert(s);
                }
            }
            return res;
        };
        rep(t, 20) {
            ll m = (l + r) / 2;
            if (f(m) == "0") r = m;
            else l = m;
        }
        cout << f(l) << endl;
    }
}

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

int N, U[2], M, A[2][500][500];
int sum[2][2][500], f[2], g[2];
unordered_map< int, vector< tuple< int, int, int > > > memo;
int main()
{
  
  scanf("%d %d %d %d", &N, &U[0], &U[1], &M);

  for(int k = 0; k < 2; k++) {
    for(int i = 0; i < N; i++) {
      for(int j = 0; j < N; j++) {
        scanf("%d", &A[k][i][j]);
        memo[A[k][i][j]].emplace_back(k, i, j);
      }
      sum[k][0][i] = sum[k][1][i] = N; 
    }
    f[k] = g[k] = N;
  }
  
  while(M--) {
    int num;
    scanf("%d", &num);
    for(auto& d : memo[num]) {
      int k, i, j;
      tie(k, i, j) = d;
      U[k] -= --sum[k][0][i] == 0;
      if(N > 1) {
        U[k] -= --sum[k][1][j] == 0;
        if(i == j) U[k] -= --f[k] == 0;
        if(j == N - i - 1) U[k] -= --g[k] == 0;
      }
    }
    if(U[0] <= 0 || U[1] <= 0) {
      if(U[0] <= 0 && U[1] <= 0) break;
      puts(U[1] <= 0 ? "NEKO" : "USAGI");
      exit(0);
    }
  }
  puts("DRAW");
}

Measured memory_bytes: 30256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
  int p,q;
  while(cin >>p>>q){
    vector<int> ans,num;
    int r;
    bool ff = true;
    num.push_back(p);
    for(;;){
      if(p%q == 0){ff = false;break;}
      p*=10;
      vector<int>::iterator pos = find(num.begin(),num.end(),p%q);
      ans.push_back(p/q);
      if(pos != num.end()){r = p%q;break;}
      num.push_back(p%q);
      p%=q;
    }
    for(int i=0; i<ans.size(); i++){
      cout <<ans[i];
    }
    cout <<endl;
    if(ff){
      bool f = false;
      for(int i=0; i<num.size(); i++){
	if(num[i] == r){f = true;}
	if(f){cout <<"^";}
	else{cout <<" ";}
      }
      cout <<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1220
#include<bits/stdc++.h>
using namespace std;
#define INF 1<<30
struct edge{int to,cost;};
vector<edge> G[101];
int d[101];
bool visited[101];
void dijkstra(int n){
  fill(d+1,d+101,INF);
  memset(visited,false,sizeof(visited));
  for(int i=0;i<n;++i){
    int id=-1;
    for(int j=0;j<n;++j){
      if(!visited[j]){
        if(id==-1||d[id]>d[j]) id=j;
      }
    }
    visited[id]=true;
    for(int j=0;j<G[id].size();++j){
      edge e=G[id][j];
      d[e.to]=min(d[e.to],d[id]+e.cost);
    }
  }
}
int main(){
  int n; cin>>n;
  for(int i=0;i<n;++i){
    int u,k; cin>>u>>k;
    for(int j=0;j<101;++j) G[i].clear();
    for(int j=0;j<k;++j){
      int c,v; cin>>c>>v;
      edge e; e.to=c, e.cost=v;
      G[u].push_back(e);
    }
    dijkstra(n);
  }
  for(int i=0;i<n;++i) cout<<i<<" "<<d[i]<<endl;
  return 0;
}

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

using lli = long long int;

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

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

int main(void){
    string s, t;
    cin >> s >> t;
    cout << t << s << endl;
    return 0;
}


Measured memory_bytes: 256
def resolve():
    n = int(input())
    aaa = list(map(int, input().split()))
    bbb = list(map(int, input().split()))
    ccc = list(map(int, input().split()))
    ans = bbb[aaa[0]-1]
    for i in range(n-1):
        if aaa[i+1] == aaa[i] + 1:
            ans += ccc[aaa[i]-1]
        ans += bbb[aaa[i+1]-1]
    print(ans)
resolve()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MX = 1e5 + 100;
const int mo = 1e9 + 7;
int inverse(int v) {
	int p = mo - 2;
	int ans = 1;
	while(p) {
		if(p & 1) ans = ans * v % mo;
		v = v * v % mo;
		p >>= 1;
	}
	return ans;
}
int inv[MX];
main () {
	int n; cin >> n;
	int p = 1;
	for(int i = 1; i <= n; i ++) {
		p = p * i % mo;
		inv[i] = (inv[i - 1] + inverse(i)) % mo;
	}
	int ans = 0;
	for(int i = 1; i <= n; i ++) {
		int in; cin >> in;
		ans = (ans + in * p % mo * (inv[i] + inv[n - i + 1] - inv[1])) % mo;
	}
	cout << ans;
}

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

int main(){
  int A,B,C,X,Y;
  cin >> A >> B >> C >> X >> Y;
  int ans = A*X + B*Y;//最も単純な頼み方
  for(int i=1;i<=max(X,Y);i++){//AB pizzaを頼む数で探索
    ans = min(ans,A*max(X-i,0)+B*max(Y-i,0)+C*2*i);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import bisect
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
B_ans = [0]*N
A.sort()
B.sort()
C.sort()
ans = 0

for i, b in enumerate(B):
    bi = bisect.bisect_left(A, b)
    B_ans[i] = B_ans[i-1] + bi
for j, c in enumerate(C):
    ci = bisect.bisect_left(B, c)
    if ci == 0:
        continue

    ans += B_ans[ci-1]
print(ans)


Measured memory_bytes: 105572
#include <stdio.h>

/* prototype declaration */
void isInTriangle(double x0, double y0, double x1, double y1, double x2, double y2, double xp, double yp);
void calcCoeff(double a, double b, double c, double d, double e, double f);

double alpha, beta;

int main(int argc, const char *argv[])
{
	double x0, y0, x1, y1, x2, y2, xp, yp;
	while(scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &x0, &y0, &x1, &y1, &x2, &y2, &xp, &yp) != EOF) 
		isInTriangle(x0, y0, x1, y1, x2, y2, xp, yp);	
	return 0;
}

void isInTriangle(double x0, double y0, double x1, double y1, double x2, double y2, double xp, double yp)
{
	double a, b, c, d, e, f;
	a = x1 - x0; b = x2 - x0;
	c = y1 - y0; d = y2 - y0;
	
	e = xp - x0; f = yp - y0;
	
	calcCoeff(a, b, c, d, e, f);
	
	if(alpha >= 0 && beta >= 0 && alpha + beta < 1) printf("YES\n");
	else printf("NO\n");
}

void calcCoeff(double a, double b, double c, double d, double e, double f)
{
	double det = a*d - b*c;
	alpha = (d*e - b*f)/det;
	beta = (a*f - c*e)/det;	
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

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

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

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

signed main() {
  ll N;
  cin >> N;
  string S;
  cin >> S;
  if (S.size() % 2 == 0) {
    string sub1 = S.substr(0, S.size() / 2);
    string sub2 = S.substr(S.size() / 2, S.size() - 1);
    if (sub1 == sub2) {
      COUT("Yes");
    } else {
      COUT("No");
    }
  } else {
    COUT("No");
  }
  return 0;
}

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

#define RESIDUE(u,v) (capacity[u][v] - flow[u][v])
#define RCOST(u,v) (cost[u][v] + h[u] - h[v])
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define LL long long

LL dp[5001][5001];

void disp(int n){
  REP(i,n){
    REP(j,n){
      cerr<<dp[i][j]<<" ";
    }
    cerr<<endl;
  }
}

struct hp{
  LL h;
  LL p;
};

vector<hp> h_p;

bool h_plus_p(hp hp1,hp hp2){
  return (hp1.h + hp1.p) < (hp2.h + hp2.p);
}

int main(){
  int n;
  cin>>n;
  hp hpdata;
  REP(i,n){
    cin>>hpdata.h>>hpdata.p;
    h_p.push_back(hpdata);
  }
  sort(h_p.begin(),h_p.end(),h_plus_p);
  REP(i,n+1){
    REP(j,n+1){
      if(j==0)
	dp[i][j]=0;
      else
	dp[i][j]=LLONG_MAX;
    }
  }
  dp[0][0]=0;
  FOR(i,1,n+1){
    FOR(j,1,i+1){
      if(dp[i-1][j-1]<=h_p[i-1].h)
	dp[i][j]=min(dp[i-1][j],dp[i-1][j-1]+h_p[i-1].p);
      else
	dp[i][j]=dp[i-1][j];
      //disp(n+1);
    }
  }
  int ret;
  REP(i,n){
    if(dp[n][n-i] != LLONG_MAX){
      ret=n-i;
      break;
    }
  }
  cout << ret << endl;
  return 0;
}


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

int main(){
  int N, K;
  cin >> N >> K;
  int res = 1;
  
  for(int i = 0; i < N; i++){
    if(res <= K){
      res *= 2;
    }
    else{
      res += K;
    }
  }
  cout << res << endl;
}

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

int main() {
  string S;
  cin>>S;
  bool judge=0;
  
  if(S=="hi" || S=="hihi"){
    judge=1;
  }
  else if(S=="hihihi" || S=="hihihihi" ){
    judge=1;
  }
  else if(S=="hihihihihi"){
    judge=1;
  }
  
  if(judge==1){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef std::pair<int, int> ipair;
#define int long long
#define pb push_back
#define ff first
#define INF INT_MAX
#define ss second
#define fr(i, j, a) for (int i = j; i < a; i++)
#define cnt_ones(x) __builtin_popcount(x)
#define all(x) x.begin(), x.end()
#define sz size()
#define endl "\n"
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<ipair>
#define mod 1000000007
#define ar array
#define IOS                                                                    \
  std::ios::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);

void init() {
  int n, m;
  cin >> n >> m;
  vector<ar<int, 2>> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i][0] >> a[i][1];
  sort(all(a));
  int cans = 0, money = 0;
  int i = 0;
  while (cans < m) {
    int can = min(m - cans, a[i][1]);
    cans += can;
    money += a[i][0] * can;
    i++;
  }
  cout << money << endl;
}
int32_t main() {
  IOS;
  init();
  return 0;
}


Measured memory_bytes: 4792
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define dump(x) cerr<<#x<<": "<<(x)<<endl
using namespace std;
using vint = vector<int>;
using ll = long long;
using vll = vector<ll>;
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }
void yes() { cout << "Yes" << endl; exit(0); }
void no() { cout << "No" << endl; exit(0); }

int main() {
    int r; cin >> r;
    if(r < 1200) {
        cout << "ABC" << endl;
    } else if(r < 2800) {
        cout << "ARC" << endl;
    } else {
        cout << "AGC" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
using System;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            MainStream();
        }
        static void MainStream()
        {
            int n = int.Parse(Console.ReadLine());
            if(Judge(n))
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
        static bool Judge(int n)
        {
            for(int f = 0; f <= (n / 4); f++)
            {
                if((n-4*f)%7==0)
                {
                    return true;
                }
            }
            for (int s = 0; s <= (n / 7); s++)
            {
                if ((n - 7 * s) % 4 == 0)
                {
                    return true;
                }
            }

            return false;
        }

    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
int h[25];

int main(void){
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&h[i]);
    }
    int ans=0;
    for(int i=0;i<n;i++){
        bool flag=false;
        for(int j=0;j<i;j++){
            if(h[j]>h[i]){
                flag=true;
            }
        }
        if(!flag){
            ans++;
        }
    }
    printf("%d\n",ans);
    return 0;
}





Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

//AtCoder Beginner Contest 118
//D	Match Matching
public class Main {

	//                                  1, 2 ,3 ,4 ,5, 6 ,7 ,8 ,9
	static int[] NEEDS = new int[] { 2, 5, 5, 4, 5, 6, 3, 7, 6 };
	// matchNum, MaxFigure
	static Map<Integer, Integer> cache = new HashMap<Integer, Integer>();

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();

		List<Integer> inList = new ArrayList<>();
		for (int i = 0; i < M; i++) {
				inList.add(sc.nextInt());
		}
		sc.close();

		boolean[] isUsables = new boolean[] { false, false, false, false, false, false, false, false, false };
		for (Integer in : inList) {
			isUsables[in - 1] = true;
		}

		cache.put(0, 0);
		for (int i = 0; i < N; i++) {
			getMaxFigure(i, isUsables);
		}
		int maxFigure = getMaxFigure(N, isUsables);

		List<Integer> ret = new ArrayList<>();
		int restMatch = N;
		for (int i = maxFigure; i > 0; i--) {
			for (int j = NEEDS.length - 1; j >= 0; j--) {
				if (!isUsables[j]) {
					continue;
				}

				int need = NEEDS[j];
				if (!cache.containsKey(restMatch - need)) {
					continue;
				}

				if (cache.get(restMatch - need) == i - 1) {
					ret.add(j + 1);
					restMatch -= need;
					break;
				}
			}
		}

		for (Integer i : ret) {
			System.out.print(i);
		}
	}

	private static int getMaxFigure(int matchNum, boolean[] isUsables) {
		if (cache.containsKey(matchNum)) {
			return cache.get(matchNum);
		}
		if (matchNum < 0) {
			return Integer.MIN_VALUE;
		}
		if (matchNum == 0) {
			return 0;
		}
		int max = Integer.MIN_VALUE;
		for (int i = 0; i < isUsables.length; i++) {
			if (!isUsables[i]) {
				continue;
			}

			int need = NEEDS[i];
			int maxFigure = getMaxFigure(matchNum - need, isUsables);
			if (max < maxFigure + 1) {
				max = maxFigure + 1;
			}
		}
		if (max < 0) {
			max = Integer.MIN_VALUE;
		}
		cache.put(matchNum, max);
		return max;
	}
}


Measured memory_bytes: 30908
a, b, c, d= gets.chomp.split(" ").map(&:to_i)

can_devide_c = b / c - (a - 1)/ c
can_devide_d = b / d - (a - 1)/ d
can_devide_c_and_d = b / c.lcm(d) - (a - 1) / c.lcm(d)
can_devide_c_or_d = can_devide_c + can_devide_d - can_devide_c_and_d
count = b - a + 1 - can_devide_c_or_d

puts count

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int main(){
    int a,b;
    cin>>a>>b;
    cout<<max({a+b,a*b,a-b});
}

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

int check1(int i){
    if(i%3==0){
        cout << " " << i;
        return 1;
    }
    return 0;
}

int check2(int i){
    int x=i;
    while(1){
        if(x%10==3){
            cout << " " << i;
            return 1;
        }
        x /= 10;
        if(x==0)break;
    }
    return 0;
}

int main(){
    int n;
    cin >> n;
    for(int i=1;i<=n;i++){
        if(check1(i)==0){
            check2(i);
        }
    }
    cout << endl;
}


Measured memory_bytes: 3096
import java.io.*;
import java.util.*;

class FastReader 
{ 
    BufferedReader br; 
    StringTokenizer st; 
    
    public FastReader() 
    { 
        br = new BufferedReader(new InputStreamReader(System.in)); 
    } 
    
    String next() 
    { 
        while (st == null || !st.hasMoreElements()) 
        { 
            try
            { 
                st = new StringTokenizer(br.readLine()); 
            } 
            catch (IOException  e) 
            { 
                e.printStackTrace(); 
            } 
        } 
        return st.nextToken(); 
    } 
    
    int nextInt() 
    { 
        return Integer.parseInt(next()); 
    } 
    
    long nextLong() 
    { 
        return Long.parseLong(next()); 
    } 
    
    double nextDouble() 
    { 
        return Double.parseDouble(next()); 
    } 
    
    String nextLine() 
    { 
          String str = ""; 
        try
        { 
            str = br.readLine(); 
        } 
        catch (IOException e) 
        { 
            e.printStackTrace(); 
        } 
        return str; 
    } 
} 

class Solution
{
    void solve()
    {
        FastReader s = new FastReader();
        
        int N = s.nextInt(),count = 0;

        int arr[] = new int[N];

        for(int i = 0 ; i < N; i++)
            arr[i] = s.nextInt();

        for(int i = 0 ; i <= N - 3; i++)
        {
            int a = arr[i];
            int b = arr[i + 1];
            int c = arr[i + 2];

            //System.out.println(a + " " + b + " " + c);

            //we have to check if b is the second smallest element

            int second = Math.max(Math.min(a,b), Math.min(Math.max(a,b),c));

            if(b == second)
                count++;
        }

        System.out.println(count);
    }
}
  
public class Main 
{ 
    public static void main(String[] args) 
    { 
        Solution ob = new Solution();

        ob.solve();
    } 
} 

Measured memory_bytes: 32748
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> nums(n);
  bool ans = true;
  for(int i=0; i<n; ++i){
    cin >> nums[i];
    if (nums[i] % 2 == 0){
      if ((nums[i] % 3 == 0) || (nums[i] % 5 == 0))  {
        // ans = true;
      } else {
        ans = false;
      }
    }
  }
  if (ans) {
    cout << "APPROVED" << endl;
  } else {
    cout << "DENIED" << endl;
  }
}


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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n;
int h[252521];
int a[252521];

// BITでもよかったか
const int N = 1<<18;
ll seg[2*N];
void st(int p, ll v){
  p += N-1;
  CHMAX(seg[p], v);
  while(p>0){
    p = (p-1)/2;
    seg[p] = max(seg[2*p+1], seg[2*p+2]);
  }
}
ll query(int l, int r, int a, int b, int k){
  if(r<=a || b<=l)return -1ll<<60;
  if(l<=a && b<=r)return seg[k];
  int m = (a+b)/2;
  return max(query(l,r,a,m,2*k+1),query(l,r,m,b,2*k+2));
}

int main(){
  scanf("%d",&n);
  REP(i,n)scanf("%d",h+i);
  REP(i,n)scanf("%d",a+i);
  fill(seg,seg+2*N,0ll);
  REP(i,n){
    ll v = query(0,h[i],0,N,0);
    st(h[i],v+a[i]);
  }
  printf("%lld\n",seg[0]);
  return 0;
}


Measured memory_bytes: 5888
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String t = sc.next();
        if (t.substring(0,t.length()-1).equals(s))System.out.println("Yes");
        else System.out.println("No");
    }
}


Measured memory_bytes: 35716
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iterator>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>

using namespace std;

#define dump(n) cerr<<"# "<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

const int MOD=100000007;

int memo[200][200];
int combi(int n,int r)
{
	if(memo[n][r]!=-1) return memo[n][r];
	if(r==0 || r==n) return memo[n][r]=1;
	else return memo[n][r]=(combi(n-1,r-1)+combi(n-1,r))%MOD;
}

void solve(vd& ps,vi& ids,vd& ws)
{
	int n=ps.size();
	vi flg(n);
	vvi loops;
	rep(i,n){
		if(flg[i]) continue;
		flg[i]=1;
		loops.push_back(vi(1,i));
		for(int j=ids[i];j!=i;j=ids[j]){
			flg[j]=1;
			loops.back().push_back(j);
		}
	}
	
	vd es(loops.size(),INT_MAX);
	vi cands(loops.size());
	rep(i,loops.size()){
		double temp=0;
		rep(j,loops[i].size())
			temp+=1.0/ws[loops[i][j]];
		vd diffs(loops[i].size());
		rep(j,loops[i].size())
			diffs[j]=-1/ws[loops[i][j]]+1/ps[loops[i][j]];
		rep(j,loops[i].size())
			es[i]=min(es[i],temp+diffs[j]);
		
		sort(allof(diffs));
		rep(j,diffs.size())
			cands[i]+=abs(diffs[j]-diffs[0])<1e-10;
	}
	
	double rese=accumulate(allof(es),0.0);
	int resp=1;
	for(int i=n,j=0;j<loops.size();i-=loops[j].size(),j++)
		resp=((ll)resp*combi(i,loops[j].size())*cands[j])%MOD;
	printf("%.10f %d\n",rese,resp);
}

int main()
{
	memset(memo,-1,sizeof(memo));
	
	for(int n;cin>>n,n;){
		vi ids(n);
		vd ps(n),ws(n);
		rep(i,n)
			cin>>ps[i]>>ids[i]>>ws[i];
		solve(ps,ids,ws);
	}
	
	return 0;
}

Measured memory_bytes: 1148
/*　　　　　　　{:i:i:|i:i:/l/l--　 　 　--l/li:i:i|i:i:i:i}
　　　　　　 　 {:rx|:i:i ィi芥ミ 　 　 .ィi芥ミｉ:ｉ|ﾍ:i:i:}
.　　　 　 　 　 ｛ﾏ|ｉ:  {::’:} 　 　 　{:‘::} :ｉ:i:|〉｝:/
　　 　 　 　 　 乂|:i:| ｀¨¨¨¨´ 　 　　｀¨¨¨´  :i:ｉ:|ｼ/
　 　 　 　 　 　 ﾉ:|:i|　　　　　　′　　　 　   |:i:i:|ﾂ
　　　　　　　　/:/|:i:| ､　　　 　_ _ 　　　　  |:i:i:|
　 　 　　 　 /:/ .|:i:|/ ＼　　　 　 　     ｨ〔|:i:/
　　 　 　  　 〈;/ く刈＿ 个 　   -   　＜}　./|/_〉
　　     　　 r-っ'~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ|___
　　 　     /／ニつ　　　　　　 ､　　　　　　　ノﾆﾆ　＼
.　　　     |　　ニ⊃ 　./　/　 ──   /　/　　..⊆ﾆﾆ　　:|
.　　　     |　　丁´　 /|￣|￣  ─‐ /|￣|￣ 　 .￣|丁 　|
.　　　     |　　ﾉ.  　 |￣|￣  ─‐  |￣|￣ 　 　.|八 　|
.　　　     |　　||. 　 |￣|￣ |￣| |￣|￣ 　   .|　|
.　 　 　   |  　||   　￣￣￣　￣ 　￣￣￣　　  .|　|  |
.　 　 　  　    ||＿＿＿＿＿＿＿＿＿＿＿＿______|__　　 ',
　 　      ,′　 | ７ﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆ}  ,′
.　　     {　　　|/　}ﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆ{/ 　 　
*///讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐。
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <limits>

using namespace std;

#define rep(a) _rep(0,int(a))
#define repj(a) for(int j=0;j<int(a);j++)
#define repk(a) for(int k=0;k<int(a);k++)
#define _rep(a,b) for(int i=int(a);i<int(b);i++)
#define ll long long
#define fst first
#define snd second
#define pf(b) printf("%.12f\n",(double)b)
#define _GLIBCXX_DEBUG
const double pai = 3.1415926535897;
#define _cos(n) cos(n*pai/180)
#define l_b lower_bound
#define u_b upper_bound
#define b_s binary_search

//factorial(練習)　階乗
int fact(int n) {
	int a = 1;
	for (int i = 1;i <= n;i++) a *= i;
	return a;
}
int sa(int n, int m) {      //差！
	if (n < m)return m - n;
	else return n - m;
}
int keta(int num) {
	int n = 0;
	if (num == 0) {
		return 1;
	}
	while (num != 0) {
		num /= 10;
		n++;
	}
	return n;
}
int gcd(int n, int m) {
	
	int a = 0;
	return 0;
}

int x, y, n, m;
signed main() {
	cin >> x >> y;
	if (y % 2 != 0) {
		cout << "No" << endl;
		return 0;
	}
	else if (x * 4 < y) {
		cout << "No" << endl;
	}
	else if (x * 2 > y)cout << "No" << endl;
	else cout << "Yes" << endl;

}


Measured memory_bytes: 3620
x, n = map(int, input().split(' '))

if n == 0:
    print(x)
    exit()


p = set(map(int, input().split(" ")))

for i in range(100):
    if not x - i in p:
        print(x - i)
        exit()
    elif not x + i in p:
        print(x + i)
        exit()
        

Measured memory_bytes: 9180
#include <iostream>
#include <vector>

using namespace std;

struct UnionFind{
    vector<int> par;
    vector<int> rank;

    void init(int n) {
        par = vector<int>(n);
        rank = vector<int>(n);

        for (int i = 0; i < n; ++i) {
            par[i] = i;
            rank[i] = 0;
        }
    }

    int find(int x) {
        if (par[x] == x) return x;
        return par[x] = find(par[x]);
    }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (rank[x] > rank[y]) {
            par[y] = x;
        } else {
            par[x] = y;
            if (rank[x] == rank[y]) ++rank[x];
        }
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }
};

int p[100000];
int n;
int m;

int main(){
    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
        cin >> p[i];
        p[i]--;
    }
    UnionFind uf;
    uf.init(n);
    for (int i = 0; i < m; ++i) {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        uf.unite(x, y);
    }

    int ans = 0;
    for (int i = 0; i < n; ++i) {
        if (p[i] == i) {
            ans++;
            continue;
        }
        if (uf.same(p[i], i)) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1408
def calc(a):
    y = 0
    for xx in x:
        y += (a - xx) ** 2
    return y


n = int(input())
x = [int(i) for i in input().split()]
left = min(x)
right = max(x)
while (right - left > 1):
    l = calc(left)
    r = calc(right)
    if (l < r):
        right = (right + left) // 2
    else:
        left = (right + left) // 2
print(min(calc(left), calc(right)))

Measured memory_bytes: 3064
#include <iostream>
int main(void)
{
  while (1) {
    int a, b;
    std::cin >> a >> b;
    if (a == 0 && b == 0)
      break;
    if (a < b) {
      std::cout << a << " " << b << std::endl;
    }
    else {
      std::cout << b << " " << a << std::endl;
    }
  }
}

Measured memory_bytes: 1160
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#include<assert.h>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
#define SZ(x) ((int)x.size())
using namespace std;
inline int read()
{
	int f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
const int MAXN=2005;
const int mod=1e9+7;
int pow_mod(int a,int b)
{
	int ret=1;
	for(;b;b>>=1,a=1LL*a*a%mod)if(b&1)ret=1LL*ret*a%mod;
	return ret;	
}
void ad(int &x,int y){x+=y;if(x>=mod)x-=mod;}
int f[MAXN][MAXN],g[MAXN],n,K;
int pre[MAXN],inv[MAXN];
int C(int n,int m){return 1LL*pre[n]*inv[m]%mod*inv[n-m]%mod;}
int main()
{
	pre[0]=1;for(int i=1;i<MAXN;i++)pre[i]=1LL*pre[i-1]*i%mod;
	inv[MAXN-1]=pow_mod(pre[MAXN-1],mod-2);
	for(int i=MAXN-2;i>=0;i--)inv[i]=1LL*inv[i+1]*(i+1)%mod;
	n=read();K=read();
	if(K==1)
	{
		if(n>=2)return pr2(pow_mod(2,n-2)),0;
		return pr2(1),0;
	}
	for(int i=n;i>=2;i--)f[i][1]=1;
	for(int i=n;i>=1;i--)
	{
		for(int j=1;j<=(n-i+1);j++)if(f[i][j])
		{
			ad(f[i][j],g[j]);
			if((n-i+1)-j)ad(f[i][j+1],f[i][j]);
		}
		for(int j=1;j<=(n-i+1);j++)ad(g[j+1],f[i][j]);
	}int ans=0;
	for(int i=n;i>=1;i--)ad(ans,f[i][K-1]);
	if(K!=n)ans=1LL*ans*pow_mod(2,n-K-1)%mod;
	pr2(ans);
	return 0;
}


Measured memory_bytes: 15232
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  string S;
  cin >> S;
  ll N = S.length();
  vector<ll> accum_w(N + 1, 0);
  for (int i = N - 1; i >= 0; i--) {
    if (S[i] == 'W')
      accum_w[i] = accum_w[i + 1] + 1;
    else
      accum_w[i] = accum_w[i + 1];
  }
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    if (S[i] == 'B') {
      ans += accum_w[i];
    }
  }
  cout << ans << endl;
  return 0;
}

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

 using namespace std;

 int main() {
   int A, B, C, D, E;
   cin >> A >> B >> C >> D >> E;

   int a, b, c, d, e;
   if (A % 10 != 0) a = (A / 10 + 1) * 10;
   else a = A;

   if (B % 10 != 0) b = (B / 10 + 1) * 10;
   else b = B;

   if (C % 10 != 0) c = (C / 10 + 1) * 10;
   else c = C;

   if (D % 10 != 0) d = (D / 10 + 1) * 10;
   else d = D;

   if (E % 10 != 0) e = (E / 10 + 1) * 10;
   else e = E;

   int max_save;

   max_save = max(a - A, max(b - B, max(c - C, max(d - D, e - E))));

   cout << a + b + c + d + e - max_save << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

int main() {
    string s, t; cin >> s >> t;
    vector<int> check(26, 0);

    vector< vector<int> > pos(26, vector<int>(0));

    for (int i = 0; i < s.size();  i++) {
        int f = s[i] - 'a';
        check[f] = 1;
        pos[f].push_back(i + 1);
    }

    for (int i = 0; i < t.size(); i++) {
        int f = t[i] - 'a';
        if (check[f] != 1) {
            cout << -1 << endl;
            return 0;
        }
    }

    long long int cnt = 0;
    int p = 0;
    for (int i = 0; i < t.size(); ) {
        int f = t[i] - 'a';
        auto it = upper_bound(pos[f].begin(), pos[f].end(), p);
        if (it == pos[f].end()) {
            cnt += 1;
            p = 0;
        } else {
            i++;
            p = *it;
        }
    }
    cout << (long long int)p + (cnt * s.size()) << endl;

    return 0;
}

Measured memory_bytes: 1216
#include<stdio.h>
#include<stdlib.h>
typedef struct node {
	int bronum;
	int mo;
	int *bro;
}Node;
int main() {
	Node *n;
	int i, j, ndnum, mo, bronum,node,temp,dep;
	//一番始めに数が与えられる。それをこうぞうたいはいれつにいれる
	scanf("%d", &ndnum);
	n = malloc(sizeof(Node)*ndnum);
	for ( i = 0; i < ndnum; i++)
	{
		n[i].mo = -1;
	}
	for (i = 0; i < ndnum; i++)//この回数はただの何回回すかだけ。中に入るデータは関係ない
	{
		scanf("%d%d", &node, &bronum);
		n[node].bronum = bronum;
		/*n(node)で順番に入ってくれる。（データの数）
		bronumはbroと末端かを判別させる*/
		if (bronum != 0)
		{
			n[node].bro = malloc(sizeof(int)*bronum);
		}
		for ( j = 0; j < bronum; j++)
		{
			scanf("%d",&temp);
			n[node].bro[j] = temp;
			n[temp].mo = node;
			/*nの番号が入ってるデータと一緒になっている。
			兄弟のデータが入っているｎの数は兄弟の実際のデータの親に当たる*/
		}
	}
	for ( i = 0; i < ndnum; i++)
	{
		dep = 0;
		for ( j = i; n[j].mo != -1; j = n[j].mo)//下からたどっていっているイメージ
		{
			dep += 1;
		}
		printf("node %d: parent = %d, depth = %d, ", i, n[i].mo, dep);
		if (dep == 0)
		{
			printf("root, ");
		}
		else if (n[i].bronum != 0)
		{
			printf("internal node, ");
		}
		else
		{
			printf("leaf, ");
		}
		printf("[");
		for ( j = 0; j < n[i].bronum; j++)
		{
			if (j == 0)
			{
				printf("%d", n[i].bro[j]);
			}
			else
			{
				printf(", %d", n[i].bro[j]);
			}
		}
		printf("]\n");
		free(n[i].bro);
	}
	free(n);
	return 0;
}


Measured memory_bytes: 3336
#include<bits/stdc++.h>
using namespace std;
string s;
int n,k;
int main()
{
  	int ans=0, i;
	cin>>s;
  	n=s.size();
  	k=0;
  	for(i=0;i<n;i++)
    {
    	if(s[i]=='R')k++;
      	else{
            ans=max(ans, k);
            k=0;
        }
    }
    ans=max(ans, k);
  	cout<<ans<<endl;

}


Measured memory_bytes: 3620