akhauriyash/Code-Regression huggingface dataset:
import functools
N, A, B = map(int, input().split())
MOD = 10 ** 9 + 7

def modpow(x, n):
    ret = 1
    while n:
        if n & 1:
            ret = ret * x % MOD
        x = x * x % MOD
        n >>= 1
    return ret

@functools.lru_cache(maxsize=None)
def modinv(x):
    return modpow(x, MOD - 2)

def modcomb(n, r):
    ret = 1
    for i in range(n, n - r, -1):
        ret *= i
        ret %= MOD
    for i in range(r, 1, -1):
        ret *= modinv(i)
        ret %= MOD
    return ret

total = modpow(2, N) - 1
ans = total - (modcomb(N, A) + modcomb(N, B))
ans %= MOD
print(ans)


Measured memory_bytes: 35768
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int Q=200;
int f[Q][Q][Q],g[Q][Q][Q];
char a[Q][Q];
inline void Gmax(int &a,int b)
{a<b?a=b:1;}
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        scanf("%s",a[i]+1);
    for(int st=m;st;--st){
        for(int len=1;len<=n;len++)
            for(int i=1,j;(j=i+len-1)<=n;i++){
                if(len==1)f[st][i][j]=(st<m&&a[i][st]==a[i][st+1])?f[st+1][i][j]:(st+1);
                else f[st][i][j]=a[i][st]==a[i+1][st]?min(f[st][i][i],f[st][i+1][j]):st;
            }
    }
    for(int st=n;st;--st){
        for(int len=1;len<=m;len++)
            for(int i=1,j;(j=i+len-1)<=m;i++){
                if(len==1)g[st][i][j]=(st<n&&a[st][i]==a[st+1][i])?g[st+1][i][j]:(st+1);
                else g[st][i][j]=a[st][i]==a[st][i+1]?min(g[st][i][i],g[st][i+1][j]):st;
            }
    }
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            f[m+1][i][j]=m+1;
    for(int i=1;i<=m;i++)
        for(int j=1;j<=m;j++)
            g[n+1][i][j]=n+1;
    for(int p=0;;p++){
        // printf("%d \n",f[1][1][n]);
        if(f[1][1][n]>m){
            printf("%d\n",p);
            return 0;
        }
        for(int st=1;st<=m;st++)
            for(int i=1;i<=n;i++)
                for(int j=i;j<=n;j++)
                    f[st][i][j]=f[f[st][i][j]][i][j];
        for(int st=1;st<=n;st++)
            for(int i=1;i<=m;i++)
                for(int j=i;j<=m;j++)
                    g[st][i][j]=g[g[st][i][j]][i][j];
        //
        for(int st=1;st<=m;st++)
            for(int i=1;i<=n;i++)
                for(int j=i;j<=n;j++)
                    Gmax(g[i][st][f[st][i][j]-1],j+1);
        for(int st=1;st<=n;st++)
            for(int i=1;i<=m;i++)
                for(int j=i;j<=m;j++)
                    Gmax(f[i][st][g[st][i][j]-1],j+1);
        //
        for(int st=1;st<=m;st++)
            for(int i=1;i<=n;i++)
                for(int j=n;j>=i;--j){
                    Gmax(f[st][i][j],f[st][i][j+1]);
                    Gmax(f[st][i][j],f[st][i-1][j]);
                }
        for(int st=1;st<=n;st++)
            for(int i=1;i<=m;i++)
                for(int j=m;j>=i;--j){
                    Gmax(g[st][i][j],g[st][i][j+1]);
                    Gmax(g[st][i][j],g[st][i-1][j]);
                }
    }
    return 0;
}

Measured memory_bytes: 61440
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0 ; i<(n) ; ++i)
typedef long long ll;
using namespace std;
const ll MAX = 2500LL;
typedef pair <ll, ll> P;

int main(){
  ll a;
  double b;
  cin >> a >> b;
  ll ib = b*100+0.3;
  a *= ib;
  a /= 100;
  //double c = a*b;
  //int d = c;
  cout << a << endl;
  return 0;
}


Measured memory_bytes: 3700
n , a , b = gets.split.map(&:to_i)
s = gets
check = 0
b_chk = 0
for i in 1..n do
	i = i - 1
	ch = s[i..i]
	
	if "#{ch}" == "a" then
		if check.to_i < a + b then
			puts "Yes"
			check = check + 1
		else
			puts "No"
		end
	elsif "#{ch}" == "b" then
		if check.to_i < a + b then
			if b_chk.to_i < b then
				puts "Yes"
				check = check + 1
				b_chk = b_chk + 1
			else
				puts "No"
			end
		else
			puts "No"
		end
		;;
	elsif "#{ch}" == "c" then
		puts "No"
	end
end


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e16+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);

    ll n;
    cin>>n;
    Vec a(n);
    rep(i,n)cin>>a[i];
    sort(ALL(a));
    reverse(ALL(a));
    ll ans=0;

    rep(i,n){
        if(i==0){
            ans += a[i]/2;
        }else{
            ans += a[i];
        }
    }
    cout<<ans<<endl;
    return  0;
}


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

#define int long long

typedef pair<int, int> P;
typedef pair<int, P> Pp;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N;
  cin >> N;

  vector<Pp> C;
  vector<int> A(N), B(N);  
  for ( int i = 0; i < N; i++ ) {
    cin >> A[i] >> B[i];
    C.emplace_back(Pp(A[i], P(i, 0)));
    C.emplace_back(Pp(B[i], P(i, 1)));
  }

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

  int ca = 0, cb = 0;
  int sum = 0;
  bool flg = false;
  bool used[N][2];
  fill_n(*used, N*2, false);
  for ( int i = 0; i < N; i++ ) {
    int c = C[i].first;
    int id = C[i].second.first;
    int ab = C[i].second.second;
    if ( used[id][!ab] ) flg = true;
    used[id][ab] = true;    
    if ( ab == 0 ) ca++;
    else cb++;    
    sum += c;    
  }

  if ( ca == N || cb == N || flg ) {
    cout << sum << endl;
    return 0;
  }

  int ans = 1e15;  
  for ( int i = 0; i < N; i++ ) {
    int c;
    if ( used[i][0] ) {
      if ( C[N-1].second.first == i ) {
	c = sum-C[N-2].first+B[i];	
      } else {
	c = sum-C[N-1].first+B[i];	
      }
    }
    if ( used[i][1] ) {
      if ( C[N-1].second.first == i ) {
	c = sum-C[N-2].first+A[i];	
      } else {
	c = sum-C[N-1].first+A[i];	
      }
    }
    ans = min(ans, c);
  }

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


Measured memory_bytes: 10096
def Partition(A, p, r):
    x = A[r]
    i = p - 1

    for j in range(p, r):
        if A[j] <= x:
            i += 1
            A[i], A[j] = A[j], A[i]

    A[i + 1], A[r] = A[r], A[i + 1]
    return i + 1

n = int(input())
input_list = list(map(int, input().split(' ')))

q = Partition(input_list, 0, n - 1)

print(*input_list[:q], "[{}]".format(input_list[q]), *input_list[q + 1:])



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

int main(int, char**) {
        std::vector<int> bingo(9, 0);
        for (int i=0; i<9; i++) {
                std::cin >> bingo.at(i);
        }

        int N;
        std::cin >> N;
        int b;
        for (int i=0; i<N; i++) {
                std::cin >> b;
                auto itr = std::find(bingo.begin(), bingo.end(), b);
                if (itr != bingo.end()){
                        *itr = 0;
                }
        }
        for (int i=0; i<3; i++) {
                if (bingo.at(3*i+0) + bingo.at(3*i+1) + bingo.at(3*i+2) == 0) {
                        std::cout << "Yes" <<std::endl;
                        return 0;
                } else if (bingo.at(i+0) + bingo.at(i+3) + bingo.at(i+6) == 0) {
                        std::cout << "Yes" <<std::endl;
                        return 0;
                }
        }
        if (bingo.at(0) + bingo.at(4) + bingo.at(8) == 0 || bingo.at(2) + bingo.at(4) + bingo.at(6) == 0){
                        std::cout << "Yes" <<std::endl;
                        return 0;
        }

        std::cout << "No" <<std::endl;
        return 0;
}


Measured memory_bytes: 256
#ifndef __cplusplus
    cat << EOF
#endif
#include <bits/stdc++.h>
using namespace std;

#define rep(...) overload_rep(__VA_ARGS__, rep_1, rep_0)(__VA_ARGS__)
#define rep_0(i, end) for(int i = 0; i < (end); ++i)
#define rep_1(i, fr, ba) for(int i = (fr); i <= (ba); ++i)
#define overload_rep(arg0, arg1, arg2, name, ...) name
#define all(box) box.begin(), box.end()

template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if(lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if(lhs > rhs) { lhs = rhs; return 1; } return 0; }

int main() {

    long long a, b;
    cin >> a >> b;
    cout << a * b / __gcd(a, b) << '\n';

}


Measured memory_bytes: 256
import fractions

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

A, B, C, D = map(int, input().split())
print(
  (B - B // C - B // D + B // lcm(C, D)) - 
  ((A - 1) - (A - 1) // C - (A - 1) // D + (A - 1) // lcm(C, D))
)

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

const ll infll=9223372036854775806;
const int inf=2147483646;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	int n,k,i;
	string a;
	cin>>n>>a>>k;
	for (i=0;i<a.size();i++){
		if (a[i]!=a[k-1]){
			cout<<"*";
		}
		else {
			cout<<a[i];
		}
	}
	return 0;
}

Measured memory_bytes: 384
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import Data.Bool (bool)

main :: IO ()
main = do
  (n : m : _) <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  as <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  let
    s = sum as :: Int
    k = length . filter ((s <=) . (* (4 * m))) $ as :: Int
  putStrLn . bool "No" "Yes" $ m <= k

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n


Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define INFF 9223372036854775807
#define ll long long
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,m,n) for(int i=m;i<n;i++)
#define ALL(N) (N.begin(),N.end())
#define de cout << "debug" << endl;
#define pb push_back
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {
    cin.tie(0);    
	ios::sync_with_stdio(false);
    int N,M;
    cin >> N >> M;
    int a[100010] = {};
    REP(i,M) cin >> a[i];
    ll dp[100100] = {};

    dp[0] = 0;
    dp[1] = 1;
    dp[2] = 2;
    REP(i,M){
     if(a[i] == 1){
       dp[1] = 0;
       dp[2] = 1;
     }
     if(a[i] == 2){
       dp[2] = 0;      
     }
    }
    int O = 0;
    REPP(i,3,N+1){
        dp[i] = dp[i-1] + dp[i-2];
        dp[i] %= 1000000007;
        REPP(j,O,M){
            if(i == a[j]){
              dp[i] = 0;
              O++;
              break;
            }
        }
    }

      cout << dp[N] << endl;
}

Measured memory_bytes: 1408
# -*- coding: utf-8 -*-
import sys
# sys.setrecursionlimit(10**6)
buff_readline = sys.stdin.buffer.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


class SegmentTree:
    def __init__(self, array, operator, identity_element):
        _len = len(array)
        self.__op = operator
        self.__size = 1 << (_len - 1).bit_length()
        self.__tree = [identity_element] * self.__size + \
            array + [identity_element] * (self.__size - _len)
        self.__ie = identity_element

        for i in range(self.__size - 1, 0, -1):
            self.__tree[i] = operator(
                self.__tree[i * 2], self.__tree[i * 2 + 1])

    def update(self, i, v):
        i += self.__size
        self.__tree[i] = v
        while i:
            i //= 2
            self.__tree[i] = self.__op(
                self.__tree[i * 2], self.__tree[i * 2 + 1])

    def query(self, l, r):
        """[l, r)
        """
        l += self.__size
        r += self.__size
        ret = self.__ie
        while l < r:
            if l & 1:
                ret = self.__op(ret, self.__tree[l])
                l += 1
            if r & 1:
                r -= 1
                ret = self.__op(ret, self.__tree[r])
            l //= 2
            r //= 2
        return ret


def slv(N, P):

    lst = SegmentTree([0] * (N+1), max, 0)
    rst = SegmentTree([N+1] * (N+1), min, N+1)
    pi = [(p, i+1) for i, p in enumerate(P)]
    pi.sort(reverse=True)

    lst.update(pi[0][1], pi[0][1])
    rst.update(pi[0][1], pi[0][1])
    ans = 0
    for p, i in pi[1:]:
        l = lst.query(0, i+1)
        ll = lst.query(0, l)
        r = rst.query(i, N+1)
        rr = rst.query(r+1, N+1)

        lst.update(i, i)
        rst.update(i, i)
        c = 0
        c += (l - ll) * (r-i)
        c += (rr - r) * (i-l)
        ans += c*p
    return ans


def main():
    N = read_int()
    P = read_int_n()
    print(slv(N, P))


if __name__ == '__main__':
    main()


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

int main(){
  vector<int> v(4,0);
  for (int i=0; i<3; i++){
    int a, b; cin >> a >> b;
    a--; b--;
    v[a]++; v[b]++;
  }
  int c1=0, c2=0;
  for (int i=0; i<4; i++){
    if (v[i]==1) c1++;
    else if (v[i]==2) c2++;
  }
  if (c1==2&&c2==2) cout << "YES" << endl;
  else cout << "NO" << endl;
}


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

using namespace std;
using namespace __gnu_pbds;

#define ll long long

typedef tree< pair<int,int>, null_type, less< pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update>Order_Set;

Order_Set X;

const int mxn = 1e7+100;
const int Mod = 1e9+7;

int arr[mxn], qs[mxn];
int bitOn[55];
map<int,int>Mp, cnt, op;
vector< pair<int, pair<int,int> > >Pi, Ans;
vector<int>G[mxn];
set<int>seet[mxn];

int main()
{
     ios::sync_with_stdio(false);

     long long n;
     cin>>n;

     if(n&1) return cout<<0<<endl, 0;
     n/=2;
     long long Ans = 0;
     while(n){
        Ans+=(n/5);
        n/=5;
     }

     cout<<Ans<<endl;

     return 0;
}




Measured memory_bytes: 704768
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
int a[3][3],n;
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

const int MOD = 1000000007;
typedef pair<int,int> P;

int gcd(int a,int b){
	if (a%b == 0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}

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










int main() {

	ll n,X;
  cin >> n >> X;
  ll x[n+1];
  rep (i,n){
    cin >> x[i];
  }
  ll g = abs(X-x[0]);
  rep (i,n-1){
    g = gcd(g,abs(X-x[i+1]));
  }
  cout << g << endl;
}



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

int main() {
    int N,i,A,c=1;
    cin >> N;

    for(i=0; i<N; i++) {
        cin >> A;
        if(A == c)
            c++;
    }

    if(c == 1)
        cout << -1;
    else
        cout << N-c+1;
    cout << endl;
}

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

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef tuple<ll, ll, ll> ti;
 
#define REP(a,b,c) for(ll a=b;a<(c);a++)
#define PER(a,b,c) for(ll a=b;a>=(c);a--)
 
inline ll ii(){ ll x; cin >> x; return x; }
inline string is(){ string x; cin >> x; return x; }
inline ld id(){ ld x; cin >> x; return x; }
inline void oi(ll x){ cout << x; }
inline void od(ld x){ cout << fixed << setprecision(10) << x; }
inline void os(string x){ cout << x; }
inline void oe(){ cout << endl; }
inline void oie(ll x){ oi(x); oe(); }
inline void ode(ld x){ od(x); oe(); }
void ose(string x){ os(x); oe(); }

int main(){
    ll N=ii();
    ll lw=0,rr=0;
    string S=is();
    for(char c:S){
        if(c=='R'){
            rr++;
        }
    }

    ll r=rr;
    REP(i,0,N){
        if(S[i]=='R'){
            rr--;
        }else{
            lw++;
        }
        r=min(r,max(lw,rr));
    }
    oie(r);

    return 0;
}


Measured memory_bytes: 3780
//#include <cstdio>
#include <iostream>

#include <cstring>

#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
//#include <queue>
//#include <stack>
#include <cassert>

using namespace std;

#define SZ(a) int((a).size())
#define REP(i,n) for(int i=0,_n=(n);i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)

typedef long long llong;
typedef vector<int> VI;
typedef vector<VI> VVI;

#define MAXN 104
#define MAXW 100004
int N, C;
int W[MAXN], V[MAXN];

const llong INF = 1e18;
llong memo[MAXN][MAXW];
llong go(int n, int remC) {
   if (remC < 0) return -INF;
   if (remC == 0 || n >= N) return 0;
   llong& res = memo[n][remC];
   if (res < 0) {
      res = max( go(n+1, remC-W[n]) + V[n], go(n+1, remC) );
   }
   return res;
}

int main(int argc, char* argv[]) {
   ios_base::sync_with_stdio(false); 
   cin.tie(nullptr);

   cin >> N >> C;
   REP(i, N)
      cin >> W[i] >> V[i];

   memset(memo, -1, sizeof(memo));
   llong res = go(0, C);
   cout << res << '\n';

   return 0;
}


Measured memory_bytes: 81536
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

typedef long long ll;

void solve() {
  int a, b, c;
  cin >> a >> b >> c;
  if(a==b && b==c) cout << "Yes\n";
  else cout << "No\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
  /*
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
  */
}


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

using namespace std;

const int N = 11;

int n, m, q, res = 0;
int a[N];
vector<pair<int, pair<int, int>>> adj[N];

void Try(int x, int tot) {
    if (x == n + 1) {
        res = max(res, tot);
        return;
    }
    for (int i = a[x - 1]; i <= m; i++) {
        a[x] = i;
        for (auto v: adj[x])
            if (a[x] - a[v.first] == v.second.first)
                tot += v.second.second;
        Try(x + 1, tot);
        for (auto v: adj[x])
            if (a[x] - a[v.first] == v.second.first)
                tot -= v.second.second;
        a[x] = 0;
    }
}

int main() {
    if (fopen("A.inp", "r"))
    freopen("A.inp", "r", stdin),
    freopen("A.out", "w", stdout);
    cin >> n >> m >> q;
    while (q--) {
        int x, y, z1, z2;
        cin >> x >> y >> z1 >> z2;
        adj[y].push_back(make_pair(x, make_pair(z1, z2)));
    }
    a[0] = 1;
    Try(1, 0);
    cout << res;
}


Measured memory_bytes: 3608
//By TheOneYouWant
#pragma GCC optimize ("-O2")
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define memreset(a) memset(a,0,sizeof(a))
#define testcase(t) int t;cin>>t;while(t--)
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i=0;i<e;++i)
#define forsn(i,s,e) for(int i=s;i<e;++i)
#define rforn(i,s) for(int i=s;i>=0;--i)
#define rforsn(i,s,e) for(int i=s;i>=e;--i)
#define bitcount(a) __builtin_popcount(a) // set bits (add ll)
#define ln '\n'
#define getcurrtime() cerr<<"Time = "<<((double)clock()/CLOCKS_PER_SEC)<<endl
#define dbgarr(v,s,e) cerr<<#v<<" = "; forsn(i,s,e) cerr<<v[i]<<", "; cerr<<endl
#define inputfile freopen("input.txt", "r", stdin)
#define outputfile freopen("output.txt", "w", stdout)
#define dbg(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) { cerr<<endl; }
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << "\t"; err(++it, args...);
}
template<typename T1,typename T2>
ostream& operator <<(ostream& c,pair<T1,T2> &v){
	c<<"("<<v.fi<<","<<v.se<<")"; return c;
}
template <template <class...> class TT, class ...T>
ostream& operator<<(ostream& out,TT<T...>& c){
    out<<"{ ";
    forstl(x,c) out<<x<<" ";
    out<<"}"; return out;
}
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> p64;
typedef pair<int,int> p32;
typedef pair<int,p32> p96;
typedef vector<ll> v64;
typedef vector<int> v32; 
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<p64> vp64;
typedef vector<vp32> vvp32;
typedef map<int,int> m32;
const int LIM=1e5+5,MOD=1e9+7;
const ld EPS = 1e-9;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main(){
	fastio;

	int l,r,d; 
	cin>>l>>r>>d;
	cout<<r/d - (l-1)/d<<ln;

	return 0;
}

Measured memory_bytes: 3604
#define _DEBUG 1
#define _GLIBCXX_DEBUG

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

using ll = long long;

#ifdef _DEBUG
#define dump(x) cerr << #x << "=" << x << endl
#define dump2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define dump3(x, y, z)                                                         \
  cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z     \
       << endl
#define check(s) cerr << s << endl
#else
#define dump(x)
#define dump2(x, y)
#define dump3(x, y, z)
#define check(s)
#endif

#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

void showMap(map<tuple<ll, ll>, vector<ll>> mp) {
  for (const auto kv : mp) {
    auto l = get<0>(get<0>(kv));
    auto d = get<1>(get<0>(kv));
    auto vs = get<1>(kv);
    cerr << "(" << l << "," << d << "): ";
    for (auto v : vs) {
      cerr << v << " ";
    }
    cerr << endl;
  }
}

void solve(ll N, ll X, ll Y) {
  vector<ll> a(N, 0);

  for (ll i = 1; i <= N; i++) {
    for (ll j = i + 1; j <= N; j++) {
      if (i != j) {
        ll d = min(abs(j - i), min(abs(X - i) + 1 + abs(j - Y),
                                   abs(Y - i) + 1 + abs(j - X)));
        a.at(d)++;
      }
    }
  }
  for (ll k = 1; k < N; k++) {
    cout << a.at(k) << endl;
  }
}

int main() {
  ll N;
  scanf("%lld", &N);
  ll X;
  scanf("%lld", &X);
  ll Y;
  scanf("%lld", &Y);
  solve(N, X, Y);
  return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val s = readLine()!!

    val x = mutableSetOf<Char>()
    val y = mutableSetOf<Char>()

    for (v in s) {
        when (v) {
            'N', 'S' ->
                y.add(v)
            'W', 'E' ->
                x.add(v)
        }
    }
    println(if (x.size % 2 == 0 && y.size % 2 == 0) "Yes" else "No")
}


Measured memory_bytes: 35636
#include<bits/stdc++.h>
using namespace std;
int main(){
  int S,s1,s2,s3;
  cin>>S;
  s1=S/100;
  S=S%100;
  s2=S/10;
  s3=S%10;
  cout<<s1+s2+s3<<endl;
}
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long int
#define vi vector<int>
#define vl vector<ll>
#define ppi pair<int,int>
#define ppl pair<ll,ll>
#define all(x) x.begin(),x.end()
#define ii int,int 
#define mm map<ii>
#define ff first    
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define imx INT_MAX
#define imn INT_MIN
#define inf LONG_MAX
#define minf LONG_MIN
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse 
#define itr iterator 

/*
#define MODM(a,b,md) ((a%md)*(b%md))%md
#define MODA(a,b,md) ((a%md)+(b%md))%md
#define ull unsigned long long int
#define si short int
*/

/*
bool compare(int a,int b) {return a > b;}
bool compare1(ppi a,ppi b) {return a.ff > b.ff;}
bool compare2(ppi a,ppi b) {return a.ss < b.ss;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/


int main()
{
	fast

	int n,d;
	cin>>n>>d;


	int val = (n-(d+1))/(2*d+1) + 1;
	int last = (d+1) + (val-1)*(2*d+1);

	if((last + d)  < n)
	{
		val++;
	}

	cout<<val;

	return 0;
}

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

using namespace std ;

int main()
{
    cin.tie(nullptr) ;
    ios_base :: sync_with_stdio(false) ;
    int n , k ;
    cin >> n >> k ;
    int a[n] ;
    for(int &x : a)
        cin >> x ;
    sort(a , a + n) ;
    int ans = 0 ;
    for(int i = 0 ; i < k ; i ++)
        ans += a[i] ;
    cout << ans << '\n' ;
    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define rep(i,x,n) for(int i=x; i<(int)(n); i++)
#define rep_eq(i,x,n) for(int i=x; i<=(int)(n); i++)
using namespace std;

int main() {
  int X,N; cin >>X >>N;
  if (N==0) {cout <<X <<endl; return 0;}
  vector<int> p(N);
  rep(i,0,N) cin >>p[i];
  int ans=0;
  int check=INT_MAX;
  rep_eq(i,0,101) {
    bool check_flag=true;
    rep(j,0,N) {
      if (i==p[j]) {check_flag=false; break;}
    }
    if (check_flag) {
      if (abs(X-i)<check) {check=abs(X-i); ans=i;}
    }
  }
  cout <<ans <<endl;
  return 0;
}


Measured memory_bytes: 3620
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		ArrayList<Integer> H = new ArrayList<>();
		for(int i=0;i<N;++i){
			H.add(sc.nextInt());
		}
		sc.close();
		int c = 0;
		int s;
		int e;
		int min = 101;
		for (int i = 0; i < N; ++i)
			min = Math.min(H.get(i), min);
		for (int i = 0; i < N; ++i)
			H.set(i, H.get(i)-min);
		c += min;
		while(Collections.frequency(H, 0) != H.size()){
			for (s = 0; H.get(s) == 0; ++s)
				continue;
			for (e = s + 1; H.size() > e && H.get(e) != 0; ++e)
				continue;
			for (int i = s; i < e; ++i) {
				H.set(i, H.get(i)-1);
			}
			++c;
		}
		System.out.println(c);
	}
}


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

int main(void) {
    int n, m, c;
    
    cin >> n >> m >> c;
    
    int c_ary[m];
    int temp_m = m;
    
    for (int i = 0; temp_m; i++,temp_m--) {
        cin >> c_ary[i];
    }
    int data_ary[n][m];
    for (int k = 0; k < n; k++) {
        for (int j = 0; j < m; j++) {
            cin >> data_ary[k][j];
        }
    }
    
    int total = 0;
    int correct_counter = 0;
    for (int k = 0; k < n; k++) {
        total = 0;
        for (int j = 0; j < m; j++) {
            total += data_ary[k][j] * c_ary[j];
        }
        if (total + c > 0) {
            correct_counter++;
        }
    }
    
    cout << correct_counter << endl;
    
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define eb(k,v) emplace_back(k,v)
#define ct(res) cout << res << "\n";
#define vi vector<int>
#define vl vector<ll>
using namespace std;
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; }
const int INF = 1e9;
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n; cin >> n;
    ll sum = 0;
    for(int i=1; i<=n; ++i) {
        if (i%3==0) {
            continue;
        } else if (i%5 ==0 ) {
            continue;
        } else if (i%3==0 && i%5 == 0) {
            continue;
        } else {
            sum+=i;
        }
    }
    ct(sum);
}



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

#define rep(l, r) for (int i = (l); i < (r); i++)

typedef long long ll;
 
using namespace std;

void solve() {
    int n, k;
    cin >> n >> k;

    int num = 1;
    rep(0, n) {
        if (num < k) {
            num *= 2;
        } else {
            num += k;
        }
    }

    cout << num << endl;
}

int main() {
    solve();

    return 0;
}


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

using namespace std;

main() {
	long long k;
	cin >> k;
	int n = 50;
	long long cnt = k / n;
	long long r = k % n;
	cout << n << endl;
	for (int i = 0; i < r; i++)
		cout << n - 1 + n + cnt - r + 1 << ' ';
	for (int i = 0; i < n - r; i++)
		cout << n - 1 + cnt - r << ' ';
	cout << endl;
}

Measured memory_bytes: 256
n = int(input())
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
max_sum = 0
for i in range(0,n):
  x = sum(a1[0:i+1]) + sum(a2[i:n+1])
  if max_sum  <= x:
    max_sum = x
print(max_sum)

Measured memory_bytes: 3060
package main
  
import (
    "fmt"
)

func main() {
    var a, b int
    fmt.Scan(&a, &b)
    if a <= 5 {
        fmt.Println(0)
    } else if a <= 12 {
        fmt.Println(b / 2)
    } else {
        fmt.Println(b)
    }
}


Measured memory_bytes: 512
n = int(input())
a = [int(i) for i in input().split()]


def devide(k, l=0):
    if k % 2 == 1:
        return l
    return devide(k/2, l+1)

sum = 0

for i in range(n):
    sum += devide(a[i])

print(sum)


Measured memory_bytes: 4148
if __name__ == '__main__':
    N = int(input())
    S = str(input())
    K = int(input())

    replace_str = S[K-1]
    list_S = list(S)

    for i in range(0, N):
        if list_S[i] == replace_str:
            continue
        else:
            list_S[i] = "*"

    answer = "".join(list_S)
    print(answer)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using llong = long long;

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

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

    int M_1, D_1, M_2, D_2;
    cin >> M_1 >> D_1 >> M_2 >> D_2;

    if (M_1 != M_2) {
        cout << 1 << endl;
        return 0;
    } else {
        cout << 0 << endl;
        return 0;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int i[11111111];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b,c,d=0;
  string s;
  cin >>a;
  if(a>=1000) cout <<"ABD\n";
  else cout <<"ABC\n";
  return (0);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;

    int x=a*b;
    int y=a-b;
    int z=a+b;

    int ans= max(x,max(y,z));

    cout<<ans<<endl;


    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>


int main () {

	int dataset=0;
	int dataset_num=0;
	int input=0;
	int count=0;

	int point[1000]={};
	int max=0;
	int sma=0;
	int cul=0;


	


	while(1){

		scanf("%d",&dataset);

		if(dataset ==0){
			break;
		}

		
		count=0;
		for ( count=0; count < dataset; count++){
				scanf("%d",&point[count]);
				if(count==0){
					max = point[count];
					sma = point[count];
				}
				if(max < point[count]){
					max = point[count];
				}
				if(sma > point[count]){
					sma = point[count];
				}
				cul += point[count];


		}		
		cul -= max;
		cul -= sma;
		cul = cul/(dataset-2);
		printf("%d\n",cul );
		max=0;
		sma=0;
		cul=0;

		
	}
		


	return 0;
}

Measured memory_bytes: 600
import sys
input = sys.stdin.readline


def read():
    A = int(input().strip())
    return A,


def solve(a):
    return a + a * a + a * a * a


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))


Measured memory_bytes: 9160
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int Y = sc.nextInt()/1000;		// 1000の倍数が保証されている。
		int sub;
		int bill;
		boolean flag = false;

		int se = -1;
		int go = -1;
		int iti = -1;

//		long start = System.currentTimeMillis();

		// 全列挙
		for (int i = 0; i <= N; i++) {
			for (int j = 0; j <= N; j++) {
				for (int k = 0; k <= N; k++) {
					// 処理
					bill = i+j+k;
					sub = addBill(i, j, k);

					// 超えたらループを抜ける。
					if (bill >N) {
						break;
					}
					if (sub > Y) {
						break;
					}

					if (sub == Y && bill == N) {
						se = i;
						go = j;
						iti = k;
						flag = true;
					}

				} // end for k
				if (flag) break;
			} // end for j
			if (flag) break;
		} // end for i

//		long end = System.currentTimeMillis();

		System.out.println(iti + " " + go + " " + se);
//		System.out.println((end - start) + "ms");
	}

	public static int addBill(int se, int go, int iti) {
		return se + 5*go + 10*iti;
	}

}

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

int main()
{
    int N, H[100000];
    cin >> N;

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

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

    int mx = 0;

    for (int i = 0; i < N; i++)
    {

        mx = max(mx, H[i]);
        if (mx - H[i] >= 2)
        {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

#define REP(k, n) for (ll k = 0; k < (ll)(n); ++k)
#define REPREV(k, n) for (ll k = (ll)(n)-1; k >= 0; --k)
#define FOR(k, a, b) for (ll k = (ll)(a); k < (ll)(b); ++k)
#define FORREV(k, a, b) for (ll k = (ll)(b)-1; k >= (ll)(a); --k)
#define FOREACH(e, v) for (auto& e : v)

#define TGET(t, i) get<i>(t)
#define TSET(t, i, a) get<i>(t) = a
// MinHeap - priority_queue<ll, vll, greater<ll>> pq;

#define EVEN(n) ((n)&1) == 0
#define ODD(n) ((n)&1) == 1

#define SORT(v) sort(v.begin(), v.end())
#define SORTREV(v) sort(v.rbegin(), v.rend())
#define SHUFFLE(v) random_shuffle(v.begin(), v.end())
//srand(unsigned(time(0)));

#define REMOVEAT(v, i) v.erase(v.begin() + i)
#define REVERSE(v) reverse(v.begin(), v.end())
#define UNIQUE(v) \
    SORT(v);      \
    v.resize(distance(v.begin(), unique(v.begin(), v.end())))

ostream& operator<<(ostream& str, const pll& p) {
    str << p.first << " " << p.second;
    return str;
}

template <typename T>
void join(T& arr, string sep) {
    bool first = true;
    for (auto t : arr) {
        if (first) {
            first = false;
            cout << t;
        } else {
            cout << sep << t;
        }
    }
    cout << "\n";
}

const ll md = 1e9 + 7;
ll MOD(ll x) {
    ll r = x % md;
    if (r < 0) {
        r += md;
    }
    return r;
}

#define POS "POSSIBLE"
#define IMPOS "IMPOSSIBLE"

// #define INF DBL_MAX
// #define INF LLONG_MAX
// #define MINF LLONG_MIN
#define INF 1e18
#define MINF -INF

void add_self(ll& x, ll d) {
    x = MOD(x + d);
}

void mul_self(ll &x, ll d) {
    x = MOD(x * d);
}

void solve() {
    ll n;
    cin >> n;
    ll res = 0;

    vll dp(n+1);
    dp[0] = 1;
    FOR(i, 3, n+1) {
        FOR(j, 3, i+1) {
            add_self(dp[i], dp[i-j]);
        }
    }

    // cout << fixed << setprecision(6);
    cout << dp[n] << "\n";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int tt = 1;
    // cin >> tt;
    for (int t = 1; t <= tt; t++) {
        // cout << "Case #" << t << ": ";
        solve();
    }
    //cin.rdbuf()->in_avail()
    return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,m,yellow,k,blue,red,fuel,cap,d,y,b,r,price,sum=0,t,i,j,ans=0,dif,array[100000+10],f,p,minx=INT_MAX,maxx=INT_MIN,a,c,flag;
    char pixel [110][110];
    vector<long long int>v,vec;
    bool prime[1000007];
    string str,ptr;
    char ch;
    cin>>k;
    cin>>a>>b;
    for(i=a;i<=b;i++)
    {
        if(i%k==0)
        {
            cout<<"OK"<<endl;
            return 0;
        }
    }
    cout<<"NG"<<endl;




    return 0;


}


Measured memory_bytes: 3628
from bisect import bisect
from operator import itemgetter

n, a, b = map(int, input().split())
ppp = map(int, input().split())
qqq = [i for i, p in sorted(enumerate(ppp, start=1), key=itemgetter(1))]
INF = 10 ** 15

dp = [(0, 0)]
for i in qqq:
    ndp = []
    s = bisect(dp, (i,))
    tmp_min = INF
    for j, cost in dp[:s]:
        cost += b
        ndp.append((j, cost))
        tmp_min = cost
    stay_cost = dp[s - 1][1]
    if tmp_min > stay_cost:
        ndp.append((i, stay_cost))
        tmp_min = stay_cost
    for j, cost in dp[s:]:
        cost += a
        if tmp_min > cost:
            ndp.append((j, cost))
            tmp_min = cost
    dp = ndp

print(dp[-1][1])


Measured memory_bytes: 75228
package main

import "fmt"

func main() {
	var k, a, b int64
	fmt.Scanf("%d %d %d\n", &k, &a, &b)

	if k <= a || b <= a+2 {
		// ひたすら割るのが良いケース
		fmt.Println(k + 1)
		return
	}

	m := k - (a - 1)
	ans := a + (b-a)*(m/2) + m%2

	fmt.Println(ans)
}


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

// 最大公約数
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

// 最小公倍数
ll lcm(int x, int y) { return (ll)x * (ll)y / gcd(x, y); }

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

  ll ans = lcm(a, b);
  cout << ans << endl;
  return 0;
}

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

int main(){
	int n;	cin>>n;
	vector<int> a(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
		a[i]-=(i+1);
	}
	sort(a.begin(), a.end());

	long long ans=0;
	if(n%2){
		int b=a[n/2];
		for(int i=0;i<n;i++){
			ans+=abs(a[i]-b);
		}

	}else{
		int b1=a[n/2], b2=a[n/2 -1];
		long long ans1=0, ans2=0;
		for(int i=0;i<n;i++){
			ans1+=abs(a[i]-b1);
			ans2+=abs(a[i]-b2);
		}

		ans=min(ans1,ans2);
	}

	cout<<ans<<endl;


	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath> // 変数名にy1が使えなくなるかも…。
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <limits>
#include <functional>
#include <string>

typedef __int128_t int128_t;
std::istream &operator>>(std::istream& input, int128_t& value) { // int128_tの入力。入力が64bitに収まる前提。
    long long tmp; input >> tmp; value = tmp;
    return input;
}
std::ostream &operator<<(std::ostream& output, const int128_t value) { // int128_tの出力。出力が64bitに収まる前提。
    output << (long long)value;
    return output;
}

#define rep(i, begin, end) for(int64_t i = (begin); i <= (end); i++)
#define rev(i, begin, end) for(int64_t i = (begin); (end) <= i; i--)

void printvec(const std::vector<int>& vec) {
    for (int i = 0; i < vec.size(); i++) { std::cout << vec[i] << " "; } std::cout << std::endl;
}

std::string s;

int main(int argc, char **argv) {
    std::cin >> s;

    int begin, end;

    rep (i, 0, s.size()-1) {
        if (s[i] == 'A') {
            begin = i;
            break;
        }
    }

    rev (i, s.size()-1, 0) {
        if (s[i] == 'Z') {
            end = i;
            break;
        }
    }

    std::cout << end - begin + 1 << std::endl;
    
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#define MOD (long long)1000000007
#define INF (long long)998244353
using namespace std;

int main(void){
    long long a,b;
    cin >> a >> b;
    int count=1;
    if(a<b){
        long long temp=b;
        b=a;a=temp;
    }
    long long temp=b;
    for(long long i=2; i*i<=temp; i++){
        if(a%i==0 && b%i==0){
            count++;
        }
        while(a%i==0)a/=i;
        while(b%i==0)b/=i;
    }
    if(a!=1 && b!=1 && a%b==0)count++;
    cout << count << endl;
    return 0;
}

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

int main() {
    int i, c=1, next, n;
    cin >> n;
    vector<int> d(n+1);

    for (i=1; i<=n; i++) {
        cin >> d[i];
    }

    next = d[1];
    while(next != 2) {
        next = d[next];
        c++;
        if (c == n) {
            c = -1;
            break;
        }
    }
    cout << c << endl;
}


Measured memory_bytes: 3740
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <cctype>
#include <unordered_map>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<long, long>;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
#define rep(i, n) for(int i = 0; i<n; i++)
#define rep_s(i, start, n) for(int i= start;  i<n; i++)
#define rep_down(i, n) for(int i = n-1; i>=0; i--)
#define rep_down_s(i, n, start) for(int i = n-1; i>=start; i--)
#define ALL(a) (a).begin(), (a).end()
#define ALL_str(a) (a).cbegin(), (a).cend()

string alphabet_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alphabet_lower  = "abcdefghijklmnopqrstuvwxyz";
string numbers = "0123456789";
/*
for (iterator = hash.begin(); iterator != hash.end(); iterator++)
{
// ここで、要素毎の操作を行います。
std::pair<std::string, CMyClass> element = *iterator;

}
*/
/*
using edge = struct {int to; ll cost;};
vector<edge> tree[limit];
ll depth[limit];

void dfs(int v, int p, ll d){
  depth[v] = d;
  //cout <<"v: " << v << endl;
  for (auto &e: tree[v]){
    //cout << "e.to: " << e.to << endl;
    if (e.to == p) continue;
    dfs(e.to, v, d+e.cost);
  }
}
*/
int keta_sum(int num){
  int dig, sum = 0;
  while(num){
    dig = num % 10;
    sum = sum + dig;
    num = num / 10;
  }
  return sum;
}

ll binary_search(ll left_key, ll border, ll low, ll high) {
     // 配列 a の左端と右端
    ll mid = (low+high)/2;
    while (high > low+1) {
       mid = (low+high)/2;
        if (left_key*mid>border) high = mid;
        else if (left_key*mid<border) low = mid;
        else {
          mid =mid-1;
          break;
        }
    }
    return mid;
}

bool IsPrime(ll a){
  ll b = sqrt(a);
  b++;
  while(b-->=2){
    if (a%b==0) return false;
  }
  return true;
}

ll gcd(ll a, ll b){
  ll tmp;
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }

  ll r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(void){
  ll N, M, A, B, C, D, E, F, K,W, H, Q, X, Y;
  ll ans;
  string S, T;
  cin >> A >> B;
  if (A>=13) cout << B << endl;
  else if(A >=6) cout << B/2 << endl;
  else cout << 0 << endl;
  


}


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

set<int> s;
map<int, int> mp;

int main() {
  int N; cin >> N;
  vector<int> a(N); 
  rep(i, N) {
    cin >> a[i];
    a[i]--;
  }
  vector<int> ans;

  rep(i, N) s.insert(i);
  rep(i, N) mp[a[i]]++;

  int ng = -1;
  rep(i, N) {
    int top = -1;
    for (int x : s) {
      if (x == ng) continue;
      int tmp = a[x];
      if (s.count(tmp) == 1 and mp[tmp] == N - i - 1) continue;
      if (s.size() == 3) {
        vector<int> test;
        for (auto y : s) {
          if (x == y) continue;
          test.push_back(y);
        }
        if (a[test[0]] == test[1] and a[test[1]] == test[0]) continue;
      }
      top = x;
      break;
    }
    if (top == -1) {
      cout << -1 << endl;
      return 0;
    }
    ans.push_back(top);
    s.erase(top);
    mp[a[top]]--;
    ng = a[top];
  }

  rep(i, N) {
    cout << ans[i] + 1 << " ";
  }
  cout << endl;
}

Measured memory_bytes: 10624
h,w=map(int,input().split())
if h%3==0 or w%3==0:
    print(0)
elif h==2 and w==2:
    print(1)
else:
    s=[h,w]
    for i in range(max(1,h//3-2),min(h//3+3,h-1)):
        s.append(max(w*i,((h-i)*(w//2+1)if w%2==1 else (h-i)*(w//2)))-min(w*i,(h-i)*(w//2)))
    for i in range(max(1,w//3-2),min(w//3+3,w-1)):
        s.append(max(h*i,((w-i)*(h//2+1)if h%2==1 else (w-i)*(h//2)))-min(h*i,(w-i)*(h//2)))
    print(min(s))  

Measured memory_bytes: 3064
#define _GLIBCXX_DEBUG
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<string>
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rep2(i,s,n) for(int i=s;i< (int)n; i++)
#define ll long long 
#define all(v) v.begin(),v.end()
using namespace std;
using Graph = vector<vector<int>>;
// 深さ優先探索
vector<bool> seen;
void dfs(const Graph &G, int v) {
    seen[v] = true;
    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue;
        dfs(G, next_v); // 再帰的に探索
    }
}

int main() {
    ll ans=0;
    // 頂点数と辺数
    int N, M; cin >> N >> M; 
    vector<pair<int,int>> P(M);
    // グラフ入力受取
    for (int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        P[i]={a-1,b-1};
    }
   rep(j,M){
     Graph G(N);
     rep(k,M){
       if(k!=j){
         G[P[k].first].push_back(P[k].second);
         G[P[k].second].push_back(P[k].first);
       }
     }
     //Graph G2(N)=G;
     //G[P[i].first].erase(G.begin()+P[i].second);
     //G[P[i].second].erase(G.begin()+P[i].first);
    // 全頂点が訪問済みになるまで探索
    int count = 0;
    seen.assign(N, false);
    for (int v = 0; v < N; ++v) {
        if (seen[v]) continue; // v が探索済みだったらスルー
        dfs(G, v); // v が未探索なら v を始点とした DFS を行う
        ++count;
    }
    if(count==2)ans++;
   }
  cout <<ans<<endl;
}



Measured memory_bytes: 3624