akhauriyash/Code-Regression huggingface dataset:
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/*
 * AtCoder Beginner Contest 102 A "Multiple of 2 and N"
 */
public class Main {

	public static void main(String[] args) {

		InputScanner in = new InputScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		int N = in.nextInt();

		int ans = 0;
		if (N % 2 == 0) {
			ans = N;
		} else {
			ans = N * 2;
		}

		out.println(ans);

		in.close();
		out.close();

	}

	/*
	 * extends java.util.Scanner
	 */
	static class InputScanner{

		Scanner scanner;

		public InputScanner(InputStream inputStream) {
			this.scanner = new Scanner(inputStream);
		}

		public int nextInt() {
			return scanner.nextInt();
		}

		public long nextLong() {
			return scanner.nextLong();
		}

		public double nextDouble() {
			return scanner.nextDouble();
		}
		public String next() {
			return scanner.next();
		}

		public int[] nextIntArray(int n) {
			int[] ret = new int[n];
			for (int i = 0; i < n; i++) {
				ret[i] = scanner.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) {
			long[] ret = new long[n];
			for (int i = 0; i < n; i++) {
				ret[i] = scanner.nextLong();
			}
			return ret;
		}

		public String[] nextStringArray(int n) {
			String[] ret = new String[n];
			for (int i = 0; i < n; i++) {
				ret[i] = scanner.next();
			}
			return ret;
		}

		public String[] nextStringArray(String splitStr) {
			String[] ret = scanner.next().split(splitStr);
			return ret;
		}

		public void close() {
			scanner.close();
		}
	}

}


Measured memory_bytes: 21844
#include<stdio.h>

int main(){
    int n,l,m,i;
    int s[100];
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&s[i]);
    }
    l=0;
    m=101;
    for(i=0;i<n;i++){
        l+=s[i];
        if(s[i]%10 != 0 && m > s[i]){
            m = s[i];
        }
    }
    if(l%10 != 0){
        printf("%d\n",l);
    }else if(m != 101){
        printf("%d\n",l-m);
    }else{
        printf("0\n");
    }
}


Measured memory_bytes: 128
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))

from collections import defaultdict, deque
from sys import exit
import math
import copy
from bisect import bisect_left, bisect_right
from heapq import *
import sys
# sys.setrecursionlimit(1000000)
INF = 10 ** 17
MOD = 1000000007

from fractions import *
def inverse(f):
    # return Fraction(f.denominator,f.numerator)
    return 1/f


def combmod(n, k, mod=MOD):
    ret = 1
    for i in range(n - k + 1, n + 1):
        ret *= i
        ret %= mod

    for i in range(1, k + 1):
        ret *= pow(i, mod - 2, mod)
        ret %= mod

    return ret
def bunsu(n):
    ret = []
    for i in range(2, int(math.sqrt(n)) + 1):
        if n % i == 0:
            tmp = 0
            while(True):
                if n % i == 0:
                    tmp += 1
                    n //= i
                else:
                    break
            ret.append((i, tmp))

    ret.append((n, 1))
    return ret

def solve():
    n = getN()
    bun = bunsu(n)
    # print(bun)
    acc = []
    tmp = 0
    for i in range(10000):
        tmp += i
        acc.append(tmp)
    ans = 0
    for b, cnt in bun:
        if b == 1:
            continue
        ans += bisect_right(acc, cnt) - 1
    print(ans)
def main():
    # n = getN()
    # for _ in range(n):
    solve()
if __name__ == "__main__":
    solve()


Measured memory_bytes: 72780
#include<iostream>
using namespace std;
int main()
{
	
	int x, y;
	
	while (true)
	{	

		cin >> x >> y;

		if (x == 0 && y == 0) break;
		if (x < y) cout << x << " " << y << endl;
		if (x > y) cout << y << " " << x << endl;
		if (x == y) cout << x << " " << y << endl;
	
	}

}

Measured memory_bytes: 1160
#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
#define _GLIBCXX_DEBUG // check []
#define DIVISOR 1000000007

using namespace std;
typedef pair<int,int> pii;
typedef pair<int64_t, int64_t> pII;

template<typename T>
void cins(vector<T>& arr) { for(T& e: arr) cin >> e; }

#ifdef DEBUG
#define debug(fmt, ...) \
    printf("[debug: %s] " fmt, __func__, __VA_ARGS__)
#define ps(arr) \
    debug("size %ld: ", arr.size()); \
    for(auto e: arr) cout << e << " "; \
    cout << endl;
#else
#define debug(fmt, ...)
#define ps(arr)
#endif

#define ANS_MAX 10000

int main(void) {
    int num;
    cin >> num;
    vector<int> cum(ANS_MAX+1);
    for(int i = 1; i <= ANS_MAX; i++) {
        cum[i] = i;
        cum[i] += cum[i-1];
    }

    vector<int> arr;
    while(num) {
        auto pos = lower_bound(cum.begin(), cum.end(), num);
        int idx = pos-cum.begin();
        debug("%d\n", idx);
        arr.push_back(idx);
        num -= idx;
    }

    for(auto e: arr) cout << e << endl;
    return 0;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
#define rep(i,x,y) for(register int i = x;i <= y; ++ i)
#define repd(i,x,y) for(register int i = x;i >= y; -- i)
using namespace std;
typedef long long ll;
template<typename T>inline void read(T&x)
{
	char c;int sign = 1; x = 0;
	do { c = getchar(); if(c == '-') sign = -1; }while(!isdigit(c));
	do { x =  x * 10 + c - '0'; c = getchar(); }while(isdigit(c));
	x *= sign;
}

const int M = 4e5 + 50;
int n,m,cnt;

struct EDGE { int u,v;ll w; }e[M];

const bool cmp(EDGE a,EDGE b) { return a.w < b.w; }
ll v[M];int p[M];
ll ans;

int get_fa(int x) { return p[x] == x ? x : p[x] = get_fa(p[x]); }

int main()
{
	read(n); read(m);
	rep(i,0,2 * n) v[i] = INT_MAX;
	rep(i,1,m)
	{
		int a,b,c;
		read(a); read(b); read(c);
		e[++cnt].u = a+1;e[cnt].v = b+1;e[cnt].w = c;
		v[a] = min(v[a],c+1LL);	
		v[b] = min(v[b],c+2LL);
	}

	rep(i,1,2*n)
	{
		v[i] = min(v[i],v[i-1]+2);
		v[i%n] = min(v[i%n],v[i]);
	}

	rep(i,0,n-1)
		e[++cnt].u = i + 1,
		e[cnt].v = (i+1)%n + 1,
		e[cnt].w = v[i];

	sort(e + 1,e + 1 + cnt,cmp);
	rep(i,1,n) p[i] = i;
	rep(i,1,cnt)
	{
		int u = get_fa(e[i].u),v = get_fa(e[i].v);
		if(u != v)
		{
			p[u] = v;
			ans += e[i].w;
		}
	}
	
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 13568
#include <algorithm>
#include <functional>
#include <iostream>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = long long;
using ull = unsigned long long;

using vll = vector<ll>;

void solve();

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

  solve();

  return 0;
}

#define ini(...)   \
  int __VA_ARGS__; \
  in(__VA_ARGS__)

#define inl(...)  \
  ll __VA_ARGS__; \
  in(__VA_ARGS__)

#define ins(...)      \
  string __VA_ARGS__; \
  in(__VA_ARGS__);

void in() {}
template <typename T, class... U>
void in(T& t, U&... u) {
  cin >> t;
  in(u...);
}

void out() {
  cout << endl;
}
template <typename T, class... U>
void out(const T& t, const U&... u) {
  cout << t;
  if (sizeof...(u))
    cout << " ";
  out(u...);
}

#define rep(i, n) for (long long i = 0; i < n; i++)

void solve();
#ifndef ONLINE_JUDGE
#include "./lib.hpp"
#endif

void solve2(int tx) {
    rep(i, tx) cout << "R";
    
    cout << "U";
    rep(i, tx) cout << "L";
    cout << "D";

    cout << "D";
    rep(i, tx) cout << "R";
    cout << "U";

    cout << "R" << "D" << "D";
    rep(i, tx + 2) cout << "L";
    cout << "U" << "U" << "R";
}

void solve3(int ty) {
    rep(i, ty) cout << "U";
    
    cout << "R";
    rep(i, ty) cout << "D";
    cout << "L";

    cout << "L";
    rep(i, ty) cout << "U";
    cout << "R";

    cout << "U" << "R" << "R";
    rep(i, ty + 2) cout << "D";
    cout << "L" << "L" << "U";
}

void solve1(int tx, int ty) {
    rep(i, ty) cout << "U";
    rep(i, tx) cout << "R";

    rep(i, ty) cout << "D";
    rep(i, tx) cout << "L";

    cout << "L";
    rep(i, ty + 1) cout << "U";
    rep(i, tx + 1) cout << "R";
    cout << "D";

    cout << "R";
    rep(i, ty + 1) cout << "D";
    rep(i, tx + 1) cout << "L";
    cout << "U";
}

void solve() {
    ini(sx, sy, tx, ty);
    tx -= sx;
    ty -= sy;

    if (ty == 0) {
        solve2(tx);
    } else if (tx == 0) {
        solve3(ty);
    } else {
        solve1(tx, ty);
    }
    out();
}


Measured memory_bytes: 3652
n = int(input())
l = list(map(int,input().split()))
i = 0
c = 0
l2 = []
while i < n-1:
    if l[i] >= l[i+1]:
        c = c+1
        i = i+1
    else :
        l2.append(c)
        c = 0
        i = i+1
l2.append(c)
print(max(l2))

Measured memory_bytes: 14224
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>
#include <cstdint>



#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rrep(i, n) for(ll i = (ll)(n-1); i >= 0; i--)
#define repi(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rrepi(i,a,b) for(ll i=(ll)(b-1);i>=(ll)(a);i--)

#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll h,n;cin>>h>>n;
  vector<ll>a(n),b(n);
  rep(i,n)cin>>a[i]>>b[i];
  ll hh=2e4+7;
  vector<ll>dp(hh,1e9+7);
  dp[0]=0;
  rep(i,hh){
    if(i==0)continue;
    rep(j,n){
      if(i-a[j]<0)continue;
      chmin(dp[i],dp[i-a[j]]+b[j]);
    }
  }
  ll res=1e9+7;
  repi(i,h,hh){
    chmin(res,dp[i]);
  }
  cout<<res<<endl;


  return 0;

}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define fore(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define rfore(i,a,b) for(ll i=(ll)(b);i>=(ll)(a);--i)
#define rrep(i,n) rfore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
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 solve(){
    ll n,k;cin>>n>>k;
    vl a(n),b(n);rep(i,n)cin>>a[i]>>b[i];

    vl cand;
    cand.push_back(k);
    rep(i,30){
        if(k>>i&1){
            ll t=k;
            t&=~(1<<i);
            t|=(1<<i)-1;
            cand.push_back(t);
        }
    }

    ll ans=0;
    for(ll c:cand){
        ll tmp=0;
        rep(i,n){
            if((c|a[i])==c)tmp+=b[i];
        }
        chmax(ans,tmp);
    }
    cout<<ans<<endl;
}

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


Measured memory_bytes: 1920
#include <stdio.h>

int main()
{
    int h1, h2, h3, ch;
    
    h1 = 0;
    h2 = 0;
    h3 = 0;
    
    while (scanf("%d", &ch) != EOF)
    {
         if (ch > h1) {
                h3 = h2;
                h2 = h1;
                h1 = ch;
         }
         else
         {
             if (ch>h2) {
                    h3 = h2;
                    h2 = ch;
             }
             else
             {
                 if (ch>h3) {
                     h3 = ch;
                 }
             }
         }
    }
    
    printf("%d\n", h1);
    printf("%d\n", h2);
    printf("%d\n", h3);
    
    return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<algorithm>


using namespace std;

int main()
{
	long long  A,B;
	string op;

	cin >> A >> op >> B;
	if(op =="+")     cout << A + B << endl;

	if (op == "-")     cout << A - B << endl;


	return 0;
}

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

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

int main() {
    string S, t = "ACGT";
    cin >> S;

    int now = 0, ans = 0;
    rep(i, S.size()) {
        bool f = false;
        rep(j, 4) {
            if (S[i] == t[j])
                f = true;
        }
        if (f)
            now++;
        else
            now = 0;
        ans = max(ans, now);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <bitset>
#include <math.h>
#include <iomanip>
#include <queue>
#define inp(X) cin >> X
#define out(X) cout << X << endl
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define MAX(A) *max_element(A.begin(),A.end())
#define MIN(A) *min_element(A.begin(),A.end())
#define SORT(A) sort(A.begin(),A.end())
using namespace std;

typedef long long int ll;
#define MOD 1000000007
#define INF 1000000001

ll gcd(ll x, ll y){
	if(y==0) return x;
	return gcd(y,x%y);
}

bool bfs(vector<vector<int>> g, vector<int> &dist, int sv)
{
	queue<int> q;
	q.push(sv);
	dist[sv]=0;
	while(!q.empty()){
		int now = q.front(); q.pop();
		for(auto v : g[now]){
			if(dist[v]!=-1) continue;
			dist[v] = dist[now]+1;
			q.push(v);
		}
	}
}

int main(void) {
	ll h,w; cin >> h >> w;
	vector<string> s(h); rep(i,h) cin >> s[i];
	vector<vector<ll>> dp(h,vector<ll>(w,0));
	dp[0][0] = 1;
	rep2(i,1,h) dp[i][0] = s[i][0]=='#' ? 0 : dp[i-1][0];
	rep2(j,1,w) dp[0][j] = s[0][j]=='#' ? 0 : dp[0][j-1];
	rep2(i,1,h)rep2(j,1,w) dp[i][j] = s[i][j]=='#' ? 0 : (dp[i-1][j]+dp[i][j-1])%MOD;
	
	out(dp[h-1][w-1]);
}




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

// repetition
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

// const value
// const ll MOD = 1e9 + 7;
// const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
// const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
inline ll toLL(string s) {
  ll v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
  return a < b && (a = b, true);
}

template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
  return a > b && (a = b, true);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll a, b, c;
  cin >> a >> b >> c;
  swap(a, b);
  swap(a, c);
  cout << a << " " << b << " " << c << endl;
  return 0;
}


Measured memory_bytes: 256
<?php
while(1) {
    list($h, $w) = explode(" ", fgets(STDIN));
    if($h==0 && $w==0) break;
    $ptn = str_repeat("#.", (int)$w);
    for($y=0; $y<$h; $y++) {
        echo(substr($ptn, $y%2, (int)$w) . "\n");
    }
    echo("\n");
}



Measured memory_bytes: 9252
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stdlib.h>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;

int main(){
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++){
		if(i)printf(" ");
		printf("%d",b*((i%2)||(a%2==0&&i==0)));
	}
	printf("\n");
}

Measured memory_bytes: 2748
#include <algorithm>
#include <cstdint>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using namespace std;

using lint=int64_t;
using uint=uint32_t;
using ulint=uint64_t;

template<class T>
using vector2d=vector<vector<T>>;

template<class T>
bool UpdateMax(T &a, const T &b){
  if(a<b){
    a=b;
    return true;
  }else{
    return false;
  }
}

template<class T>
bool UpdateMin(T &a, const T &b){
  if(a>b){
    a=b;
    return true;
  }else{
    return false;
  }
}

template <class T>
void OutVec(const vector<T>& vec){
  for(int i = 0; i < vec.size() - 1; ++i){
    cout<<vec[i]<<" ";
  }
  cout<<vec.back()<<endl;
}

template <class T>
void OutVec2d(const vector2d<T>& vec){
  for(auto v:vec){
    OutVec(v);
  }
}

bool CanAccess(int r, int c, int h, int w, vector2d<char>& field){
  if(0 <= r && r < h && 0 <= c && c < w){
    return field[r][c]!='#';
  }
  return false;
}

struct Info{
    int depth;
    int r;
    int c;

  };

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  int h,w,k;
  cin>>h>>w>>k;
  int sr,sc;
  vector2d<char> field(h, vector<char>(w));
  vector2d<bool> visited(h, vector<bool>(w,false));
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin>>field[i][j];
      if(field[i][j]=='S'){
        sr=i;
        sc=j;
      }
    }
  }

  Info origin;
  origin.depth=0;
  origin.c=sc;
  origin.r=sr;

  queue<Info> q;
  q.push(origin);
  int result=INT32_MAX;
  vector<int> vr{0,1,0,-1},vc{1,0,-1,0};
  while(!q.empty()){
    Info curr=q.front();
    q.pop();
    int len=min({curr.r,curr.c, h-1-curr.r, w-1-curr.c});
    int time=len/k;
    if(len%k!=0) time++;
    UpdateMin(result, time+1);

    if(curr.depth>=k) continue;
    for(int vi=0;vi<4;vi++){
      if(!CanAccess(curr.r+vr[vi], curr.c+vc[vi], h,w,field)) continue;
      if(visited[curr.r+vr[vi]][ curr.c+vc[vi]]) continue;
      Info next=curr;
      next.depth++;
      next.r+=vr[vi];
      next.c+=vc[vi];
      visited[next.r][next.c]=true;
      q.push(next);
    }
  }

  cout<<result<<endl;





  return 0;
}




Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >> s;
	for (int i = 2; i <= 3; i++) {
		for (int j = 0; j <= (int) s.length() - i; j++) {
			string t = s.substr(j, i);
			int c[26] = {};
			for (int k = 0; k < i; k++) {
				c[t[k] - 'a']++;
			}
			for (int k = 0; k < 26; k++) {
				if (c[k] >= 2) {
					cout << j + 1 << " " << j + i << endl;
					return 0;
				}
			}
		}
	}
	cout << -1 << " " <<  -1 << endl;
	return 0;	
}

Measured memory_bytes: 512
//Created Time:2019年10月27日 星期日 20时09分40秒
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#define db double
#define N 602

using namespace std;

int n, m;
db mat[N][N], deg[N], ans[N], tmp[N];
bool mp[N][N];

int main(){
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= m; ++i){
		int u, v; scanf("%d%d", &u, &v);
		mp[u][v] = true; deg[u] += 1.0;
	}
	for(int i = 1; i <= n; ++i){
		for(int j = 1; j <= n; ++j)
			if(mp[i][j])
				mat[i][j] = -1.0 / deg[i];
		mat[i][i] = 1.0; mat[i][n + 1] = 1.0;
	}
	mat[n][n + 1] = 0;
	for(int i = 1; i <= n; ++i){
		int mx = i;
		for(int j = i + 1; j <= n; ++j)
			if(fabs(mat[j][i]) > fabs(mat[mx][i])) mx = i;
		if(i != mx) swap(mat[i], mat[mx]);
		db div = mat[i][i];
		for(int j = i; j <= n + 1; ++j) mat[i][j] /= div;
		for(int j = i + 1; j <= n; ++j){
			div = mat[j][i];
			for(int k = i; k <= n + 1; ++k) mat[j][k] -= mat[i][k] * div;
		}
	}	
	for(int i = n; i; --i){
		ans[i] = mat[i][n + 1];
		for(int j = n; j > i; --j) ans[i] -= ans[j] * mat[i][j];
	}
	
	memcpy(tmp, ans, sizeof tmp);
	db res = ans[1];
	for(int i = 1; i <= n; ++i)
		if(deg[i] > 1.0){
			double mx = 0.0, sum = 0.0;
			for(int j = i + 1; j <= n; ++j)
				if(mp[i][j]) sum += ans[j], mx = max(mx, ans[j]);
			ans[i] = (sum - mx) / (deg[i] - 1) + 1;
			for(int j = i - 1; j; --j){
				ans[j] = 0.0;
				for(int k = j + 1; k <= n; ++k)
					if(mp[j][k]) ans[j] += ans[k];
				ans[j] /= deg[j]; ans[j] += 1.0;
			}
			res = min(res, ans[1]); memcpy(ans, tmp, sizeof ans);
		}
	printf("%.10lf", res);
	return 0;
}

Measured memory_bytes: 3456
#include<iostream>
#include<string>
#include<vector>
#include<unordered_map>
#include<algorithm>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)

int main() {
	int n;
	cin >> n;
	vector<int> a;
	int tmp;
	int max=0;//Aの最大値
	int max2 = 0;//Aの2番目に大きい値(maxと同じでもよい）

	FOR(i, 0, n) {
		cin >> tmp;
		a.push_back(tmp);
		if (tmp >= max && tmp >= max2) {//tmpがmaxよりも大きい
			max2 = max;
			max = tmp;
		}
		else if (tmp >= max2) {//tmpがmax以下だがmax2よりも大きい
			max2 = tmp;
		}
	}

	FOR(i, 0, n) {
		if (a[i] == max) {
			cout << max2 << endl;
		}
		else {
			cout << max << endl;
		}
	}


	return 0;
}

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

int main() {
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    int ans = 1000000000;
    for (int i = 0; i <= 100000; i++) {
        ans = min(ans, i*2*c + max(0, x-i)*a + max(0, y-i)*b);
    }
    cout << ans << endl;
}

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

int main() {
  int n;
  cin >> n;
  for (int i = 1; i < 10; i++)
    for (int j = 1; j < 10; j++)
      if (i * j == n) {
        cout << "Yes" << endl;
        return 0;
      }

  cout << "No" << endl;
}

Measured memory_bytes: 3640
import java.util.*

fun main(args: Array<String>) {
    val values = mutableListOf<Int>()
    val scanner = Scanner(System.`in`)

    val n = scanner.nextLine().toInt()
    repeat(n) { values.add(scanner.nextInt()) }

    var v: Int
    var j: Int
    (1 until n).forEach { i ->
        println(values.joinToString(" "))
        v = values[i]
        j = i - 1
        while (j >= 0 && values[j] > v) {
            values[j + 1] = values[j]
            j--
        }
        values[j + 1] = v
    }
    println(values.joinToString(" "))
}


Measured memory_bytes: 30756
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC
{
    class A043
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            Console.WriteLine(Enumerable.Range(1, N).Sum());
        }
    }
}

Measured memory_bytes: 2776
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

/*
// 最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

// 最小公倍数
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}*/


int main() {
	int n, d;
	cin >> n >> d;
	vector<vector<int>> x(n, vector<int>(d));
	rep(i, n)rep(j, d) cin >> x[i][j];

	int ans = 0;

	rep(i, n) {
		Rep(j,i + 1, n) {
			if (i == j) continue;
			int distance = 0;
			rep(k, d) {
				distance += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
			}
			//cout << distance << endl;
			for (int cnt = 1; cnt * cnt <= distance; cnt++) {
				if (cnt * cnt == distance) {
					ans++;
					break;
				}
			}
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<cmath>
#define N 100005
#define A 1000005
#define MOD 1000000007 // //100000000 998244353 //
#define inf 1000000000000000000
#define ll long long
//#define M_PI 3.141592653589793238463

using namespace std;

#define pii pair<ll, ll>
#define piii pair<ll, pii>
#define ft first
#define sd second
#define pb push_back
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n-1; i >= 0; i--)
#define itr(it, x) for(auto it = x.begin(); it != x.end(); it++)
#define mem(a, b) memset(a, (ll)b, sizeof(a))
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define edge(v, x, y) v[x].pb(y); v[y].pb(x);
#define popcount __builtin_popcount
#define ANS(s) {cout << s << "\n"; return;}

//~~~~~~fancy print~~~~~~~//
#define printpii(a) cout << a.ft << " " << a.sd << endl;
#define printpiii(a) cout << a.ft << " " << a.sd.ft << " " << a.sd.sd << endl;
#define print(a, n) rep(i, n) cout << a[i] << " "; cout << endl;
#define printv(v) for(auto x: v)cout << x << " "; cout << endl;
#define printm(a, n, m) rep(i, n) { rep(j, m) cout << a[i][j] << "\t"; cout << endl;}

ll dx[4] = {0, 0, 1, -1};
ll dy[4] = {1, -1, 0, 0};

void fast(){ios_base::sync_with_stdio(false);cin.tie(0);cout << setprecision(12) << fixed;}


void solve(){
    ll n;
    cin >> n;
    ll a[n+1];
    rep(i, n) cin >> a[i+1];
    ll ans = 0, vis[n+1], x = 1; mem(vis, 0);
    while(vis[x] == 0){
        vis[x] = 1;
        x = a[x];
        ans++; 
        if(x == 2) break;
    }
    if(x != 2) ANS(-1);
    cout << ans;

}
main(){
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    fast();
    ll t = 1; //cin >> t;
    while(t--){
        solve();
    }
}


Measured memory_bytes: 1920
a=input()
b=list(a)
c=1
x=0
ans={"L":1,"R":0,"U":0,"D":0}
ans2={"L":0,"R":1,"U":0,"D":0}
for i in b:
	if int(c)%2==1:
		x=x+ans[i]
	elif int(c)%2==0:
		x=x+ans2[i]
	c=c+1
if x>=1:
	print("No")
else:
	print("Yes")
	
	


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

int main(){
  int n;
  int p[9][9];
  char map[9][9];
  int check[10];

  cin >> n;
  while(n){
    n--;

    for(int i=0;i<9;i++){
      for(int j=0;j<9;j++){
	cin >> p[i][j];
	map[i][j] = ' ';
      }
    }

    for(int i=0;i<9;i++){
      for(int j=1;j<10;j++)check[j] = 0;
      for(int j=0;j<9;j++)check[p[i][j]]++;
      for(int j=0;j<9;j++){
	if(check[p[i][j]]>1)map[i][j] = '*';
      }
    }

    for(int i=0;i<9;i++){
      for(int j=1;j<10;j++)check[j] = 0;
      for(int j=0;j<9;j++)check[p[j][i]]++;
      for(int j=0;j<9;j++){
	if(check[p[j][i]]>1)map[j][i] = '*';
      }
    }

    for(int i=0;i<9;i+=3){
      for(int j=0;j<9;j+=3){
	for(int k=1;k<10;k++)check[k] = 0;
	for(int k=i;k<i+3;k++){
	  for(int l=j;l<j+3;l++)check[p[k][l]]++;
	}
	for(int k=i;k<i+3;k++){
	  for(int l=j;l<j+3;l++){
	    if(check[p[k][l]]>1)map[k][l] = '*';
	  }
	}
      }
    }
 
    for(int i=0;i<9;i++){
      for(int j=0;j<9;j++){
	cout << map[i][j] << p[i][j];
      }
      cout << endl;
    }
    if(n)cout << endl;
  }
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cassert>
#include <functional>
#include <string>
#include <sstream>
#include <cctype>
using namespace std;

class xy{
public:
  int x, y;
  xy() {x = y = 0;}
};

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


Measured memory_bytes: 256
h, w = map(int, input().split())
table = []
for _ in range(h):
    k = [int(i) for i in input().split()]
    table.append(k)

temp = 0
ans = []
for i in range(h):
    for j in range(w):
        if (i != h - 1) | (j != w - 1):
            if i % 2 == 1:
                j = w - j - 1
            if (table[i][j] + temp) % 2 == 1:
                temp = 1
                if i % 2 == 0:
                    if 0 <= j < w - 1:
                        ans.append([i + 1, j + 1,  i + 1, j + 2])
                    else:
                        ans.append([i + 1, j + 1,  i + 2, j + 1])
                else:
                    if 0 < j <= w - 1:
                        ans.append([i + 1, j + 1, i + 1, j])
                    else:
                        ans.append([i + 1, j + 1, i + 2, j + 1])
            else:
                temp = 0
print(len(ans))
for i in ans:
    print(*i)

Measured memory_bytes: 30144
#include <bits/stdc++.h>
 
using namespace std;
 
#define FOE(i, s, t) for (int i = s; i <= t; i++)
#define FOR(i, s, t) for (int i = s; i < t; i++)
#define LL long long
#define pb push_back
#define mp make_pair
#define M 1000000007
#define y1 fwfwkpoe
 
#define K 2001

int n, m, q;

int sum[K][K], ege[K][K];
int eu[K][K], el[K][K];
int a[K][K];

int sumRect(int sum[K][K], int x1, int y1, int x2, int y2) {
	return sum[x2][y2] - sum[x1 - 1][y2] - sum[x2][y1 - 1] + sum[x1 - 1][y1 - 1];	
}
 
int main() {
	scanf("%d%d%d", &n, &m, &q);
	
	FOE(i, 1, n) {
		string x; cin >> x;
		FOE(j, 1, m) a[i][j] = (x[j - 1] - '0');
	}
	
	FOE(i, 1, n) {
		FOE(j, 1, m) {
			sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + a[i][j];
			eu[i][j] = eu[i - 1][j] + eu[i][j - 1] - eu[i - 1][j - 1] + (a[i][j] & a[i - 1][j]);
			el[i][j] = el[i - 1][j] + el[i][j - 1] - el[i - 1][j - 1] + (a[i][j] & a[i][j - 1]);
			
			
			int tot = (a[i][j] & a[i - 1][j]) + (a[i][j] & a[i][j - 1]);
			
			ege[i][j] = ege[i - 1][j] + ege[i][j - 1] - ege[i - 1][j - 1] + tot;
		}
	}
	
	FOE(i, 1, q) {
		int x1, y1, x2, y2;	
		scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
		
		int tv = sumRect(sum, x1, y1, x2, y2);
		int te = sumRect(ege, x1, y1, x2, y2) - sumRect(eu, x1, y1, x1, y2) - sumRect(el, x1, y1, x2, y1);
		
//		printf("dafuq %d %d [%d]\n", tv, te, ege[x2][y2]);
		
		printf("%d\n", tv - te);
	}
}


Measured memory_bytes: 80000
n = int(input())
h = list(map(int,input().split()))

ans = "Yes"
for i in reversed(range(1, n)):
  if h[i]>=h[i-1]:
    continue
  elif h[i-1] - h[i] == 1:
    h[i-1] -= 1
  else:
    ans = "No"
    break

print(ans)

Measured memory_bytes: 14224
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <cstring>
#include <math.h>
#include <bitset>
#include <time.h>
#include <set>
#include <algorithm>
#define ll long long
#define Inf 123372036854775806ll
using namespace std;

ll dp[666][666];
int main() {
    int N,Ma,Mb;
    cin>>N>>Ma>>Mb;
    
    for(int i=0;i<=555;i++)
        for(int j=0;j<=555;j++)
            dp[i][j]=(i+j==0?0:Inf);
    
    for(int i=1;i<=N;i++) {
        int a,b,c;
        cin>>a>>b>>c;
        for(int x=555;x>=0;x--)
            for(int y=555;y>=0;y--) {
                if (x >= a && y >= b)
                    dp[x][y]=min(dp[x][y],c+dp[x-a][y-b]);
            }
    }
    ll ans=Inf;
    for(int t=1;max(t*Ma,t*Mb)<=555;t++)
        ans=min(ans,dp[t*Ma][t*Mb]);
    if (ans == Inf) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }
    
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);



int main(){
  string a, t;
  cin >> a >> t;

  int n =  a.size() - t.size() + 1;
  //cout << n << endl;
  if( a.size() < t.size() ){
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  // if(n == 1){
  //   REP(i,t.size()){
  //     if (a[i] == t[i] ||　a[i] == '?') continue;
  //     else ok = false;
  //   }
  //
  // }

  //init
  vector<string> vec_s;
  string firstS;
  REP(i,a.size()) firstS += 'z';


  REP(k,n){
    bool ok = true;
    string s = firstS;

    REP2(i,0,k){
      if (a[i] == '?') s[i] = 'a';
      else s[i] = a[i];
    }
    REP2(i,k,k + t.size()){
      if (a[i] == t[i-k] || a[i] == '?' ){
        s[i] = t[i-k];
      }
      else {
        ok = false;
        break;
      }
    }
    REP2(i,k+t.size(),a.size()) {
        if (a[i] == '?') s[i] = 'a';
        else s[i] = a[i];
      }

    //cout << s << " " << ok <<endl;
    if(ok) vec_s.push_back(s);
  }

  if(vec_s.empty()){
    cout << "UNRESTORABLE" << endl;
    return 0;
  }

  sort(ALL(vec_s));

  cout << vec_s[0] << endl;

  return 0;
}


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

#define MOD 1000000007

long long extGCD(long long a,long long b,long long &x,long long &y){
  if(b==0){
    x=1;
    y=0;
    return a;
  }
  long long d=extGCD(b,a%b,y,x);
  y=y-(a/b)*x;
  return d;
}

long long modinv(long long a, long long p){
  long long d,x,y;
  d=extGCD(a,p,x,y);
  x%=p;
  if(x<0) x+=p;
  return x;
}

long long modcomb(long long n,long long r,long long p,long long F[]){
  long long c;
  c=(F[n]*((modinv(F[r],p)*modinv(F[n-r],p))%p))%p;
  return c;
}

int main(){
  long long H,W,A,B;
  cin >> H >> W >> A >> B;
  long long F[H+W-1];
  F[0]=1;
  for(int i=1;i<=H+W-2;i++){
    F[i]=(i*F[i-1])%MOD;
  }
  long long X[W-B];
  for(int i=0;i<W-B;i++){
    X[i]=(modcomb(H-A+B+i-1,H-A-1,MOD,F)*modcomb(A+W-B-i-2,A-1,MOD,F))%MOD;
  }
  long long S=0;
  for(int i=0;i<W-B;i++){
    S=(S+X[i])%MOD;
  }
  cout << S << endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> pint;
typedef vector<int> vint;
#define MSG(a) cout << #a << " " << a << "\n";

int main(){
    int N,L; cin >> N >> L;
    vint apple(N+1);
    int res=100000,ans=0,t;
    FOR(i,1,N+1){
        int x = L + i - 1;
        // cout << abs(x) << endl;
        apple.at(i) = x;
        if(abs(x) < res){
            t = i;
            res = abs(x);
        }
        ans += x;
    }
    // cout << t << endl;
    cout << ans - apple.at(t) << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define MOD 1000000007
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; }
#define ALL(v) v.begin(), v.end()
typedef long long ll;
const ll mod=1000000007;

ll powmod(ll x,ll y){
    ll res=1;
    for(ll i=0;i<y;i++){
        res=res*x%mod;
    }
    return res;
}

int main(){
    ll n;cin >> n;
    ll ans = powmod(10,n)-powmod(9,n)-powmod(9,n)+powmod(8,n);

    ans%=mod;
    ans=(ans+mod)%mod;
    cout << ans << endl;

   

}


Measured memory_bytes: 3628
#include<cstdio>
#include<algorithm>
int main(){
    int a,b;
    scanf("%d%d",&a,&b);
    int ans[3]={a+a-1,a+b,b+b-1};
    std::sort(ans,ans+3);
    printf("%d\n",ans[2]);
    return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <cstdio>
const int MAXN = 305;
const int S = 3;
double dp[MAXN][MAXN][MAXN]{ };
int cnt[S]{ };
int A, N;

void init() {
  int a = cnt[0];
  int b = cnt[1];
  int c = cnt[2];
  for (int i = a+b+c; i >= 0; --i) {
    for (int j = b+c; j >= 0; --j) {
      for (int k = c; k >= 0; --k) {
        dp[i][j][k] = -1.0;
      }
    }
  }
  dp[0][0][0] = 0.0;
}

// 1. Geometric expectation
//    Re-roll on empty sushi plates - "failure".
// 2. Traverse an edge of the DFA
//    Weighted summation of expectations of simpler states,
//    given a "success" of non-empty plate.

double dfs(int i, int j, int k) {
  if (dp[i][j][k] >= 0.0) {
    return dp[i][j][k];
  }
  int sum = i + j + k;
  double p  = 1.0 * N / sum;
  if (k) p += 1.0 * k / sum * dfs(i, j+1, k-1);
  if (j) p += 1.0 * j / sum * dfs(i+1, j-1, k);
  if (i) p += 1.0 * i / sum * dfs(i-1, j, k);
  return dp[i][j][k] = p;
}

int main() {
  scanf("%d", &N);
  for (int i = 0; i < S; ++i) {
    cnt[i] = 0;
  }
  for (int i = 1; i <= N; ++i) {
    scanf("%d", &A);
    ++cnt[A-1];
  }
  init();
  printf("%.12f\n", dfs(cnt[0], cnt[1], cnt[2]));
  return 0;
}

Measured memory_bytes: 219392
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=100000000000000000;

int main() {
    string s;
    cin >> s;
    if (s=="SUN") cout << 7 << endl;
    if (s=="MON") cout << 6 << endl;
    if (s=="TUE") cout << 5 << endl;
    if (s=="WED") cout << 4 << endl;
    if (s=="THU") cout << 3 << endl;
    if (s=="FRI") cout << 2 << endl;
    if (s=="SAT") cout << 1 << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	final int MOD = 1000000007;
	final int MAX = Integer.MAX_VALUE;
	final long LMAX = Long.MAX_VALUE;


	void doIt() {
		int a = sc.nextInt();
		int b = sc.nextInt();
		System.out.println(Math.max(0, a - 2 * b));
		
	}
		
	
	

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


Measured memory_bytes: 23124
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = 1'000'000'007;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

using Weight = int;
struct Edge {
	int s, d; Weight w;
	Edge() {};
	Edge(int s, int d, Weight w) : s(s), d(d), w(w) {};
};
bool operator<(const Edge &e1, const Edge &e2) { return e1.w < e2.w; }
bool operator>(const Edge &e1, const Edge &e2) { return e2 < e1; }
inline ostream &operator<<(ostream &os, const Edge &e) { return (os << '(' << e.s << ", " << e.d << ", " << e.w << ')'); }

using Edges = vector<Edge>;
using Graph = vector<Edges>;
using Array = vector<Weight>;
using Matrix = vector<Array>;

void addArc(Graph &g, int s, int d, Weight w = 1) {
	g[s].emplace_back(s, d, w);
}
void addEdge(Graph &g, int a, int b, Weight w = 1) {
	addArc(g, a, b, w);
	addArc(g, b, a, w);
}

// 有効グラフでの閉路検出
bool detectCycle(const Graph &g) {
	int n = g.size();
	vector<bool> path(n);
	vector<bool> vis(n);
	function<int(int)> dfs = [&](int u) {
		bool ret = false;
		path[u] = true;
		for (auto e : g[u]) {
			if (vis[e.d])continue;
			if (path[e.d]) {
				ret = true;
				break;
			}
			ret |= dfs(e.d);
			if (ret)break;
		}
		vis[u] = true;
		path[u] = false;
		return ret;
	};
	for (int i = 0; i < n; i++)
		if (!vis[i])
			if (dfs(i))
				return true;
	return false;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int V, E; cin >> V >> E;
	Graph g(V);
	rep(i, 0, E) {
		int s, t; cin >> s >> t;
		addArc(g, s, t);
	}
	cout << (detectCycle(g) ? 1 : 0) << endl;
	return 0;
}


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

int main() {
  int N, X; cin >> N >> X;
  int cnt = 1;
  int length = 0;
  for (int i = 0; i < N; i++) {
    int L; cin >> L;
    length += L;
    if (length <= X) {
      cnt++;
    }
    else break;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
using namespace std;
 
int H, W;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> H >> W;
  char c[H+10][W+10];
  memset(c, '.', sizeof(c));
  for(int i=0; i<H; ++i)
    for(int j=0; j<W; ++j){
      char x; cin >> x;
      c[i][j] = x;
    }
  for(int i=0; i<H; ++i){
    for(int j=0; j<W; ++j){
      if(c[i][j] == '#'){
          if(c[i-1][j] == '#' || c[i+1][j] == '#' || c[i][j-1] == '#' || c[i][j+1] == '#')
           continue;
         else{
            cout << "No\n";
            return 0;
         }
      }
    }
  }
  cout << "Yes\n";
  return 0;
}



Measured memory_bytes: 256
n, k = map(int, input().split())
a = list(map(int, input().split()))

# bottom...最小0ずつ切る(不可能な方)、top...最大max(a)ずつ切る（可能な方）
bottom, top = 0, max(a)


while top - bottom > 1:
    mid = (top+bottom) // 2
    cnt = 0
    for i in a:
        cnt += i//mid
        if i%mid == 0:
            cnt -= 1
    if cnt <= k:
        top = mid
    else:
        bottom = mid

print(top)


Measured memory_bytes: 103960
#include<bits/stdc++.h>
using namespace std;
char s[5],s1[5];int ans;
int main(){
	scanf("%s%s",s,s1);
	for(int i=0;i<3;i++)if(s[i]==s1[i])ans++;
	printf("%d\n",ans);
	return 0;
} 


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

int main() {
    string s, t;
    cin >> s >> t;

    int n = s.size();
    int sum = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] != t[i]) {
            sum++;
        }
    }
    cout << sum << endl;
    return 0;
}

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


int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<char>> A(H, vector<char>(W));
    
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> A.at(i).at(j);
        }
    }
    
    for (int i = 0; i < H; i++) {
        bool B = false;
        for (int j = 0; j < W; j++) {
            if (A.at(i).at(j) == '#') {
                B = true;
            }
        }
        if (B == false)
        for (int j = 0; j < W; j++) {
            A.at(i).at(j) = 'x';
        }
    }
    
     for (int i = 0; i < W; i++) {
        bool B = false;
        for (int j = 0; j < H; j++) {
            if (A.at(j).at(i) == '#') {
                B = true;
            }
        }
        if (B == false)
        for (int j = 0; j < H; j++) {
            A.at(j).at(i) = 'x';
        }
    }
    
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (A.at(i).at(j) != 'x') {
                cout << A.at(i).at(j);
            }
        }
        bool C = false;
        for (int j = 0; j < W; j++) {
            if (A.at(i).at(j) != 'x') {
                C = true;
            }
        }
        if (C)
        cout << endl;
    }
}

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

int dp[505050];

int main() {
        int n; 
        scanf("%d", &n);
        string s; 
        cin >> s;
        s = "0" + s + "0";
        for (int i = 1; i < s.size() - 1; i ++) {
                dp[i + 1] = max(dp[i + 1], dp[i]);
                if (s[i - 1] == '1' && s[i] == '0' && s[i + 1] == '1') {
                        int prev = i - 1, next = i + 1;
                        while (s[prev] != '0') {
                                dp[i + 1] = max(dp[i + 1], dp[prev - 1] + (i - prev));
                                prev --;
                        }
                        while (s[next] != '0') {
                                dp[next] = max(dp[next], dp[i - 2] + (next - i));
                                next ++;
                        }
                }
        }
        printf("%d\n", dp[s.size() - 1]);
        return 0;
}


Measured memory_bytes: 2840
n = int(input())
dp = [10 ** 9] * (n + 5)
dp[0] = 0

idx = 0
while dp[n] == 10 ** 9:
    for i in range(n):
        if dp[i] == idx:
            for j in range(10):
                if i + 6 ** j > n: break
                dp[i + 6 ** j] = min(dp[i + 6 ** j], dp[i] + 1)
            for j in range(10):
                if i + 9 ** j > n: break
                dp[i + 9 ** j] = min(dp[i + 9 ** j], dp[i] + 1)
    idx += 1
print(dp[n])



Measured memory_bytes: 43628
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define U(v) cerr << #v << ": " << (v) << endl

int main() {
    int N;
    while (cin >> N) {
        vector<int> a(N);
        int mx = 1 << 30;
        int bi;
        for (int i = 0; i < N; ++i) {
            int& p = a[i];
            cin >> p;
            if (mx == (1 << 30) || abs(mx) < abs(p)) {
                mx = p;
                bi = i;
            }
        }
        if (mx > 0) {
            cout << 2 * N << endl;
            cout << bi + 1 << ' ' << 1 << endl;
            cout << bi + 1 << ' ' << 1 << endl;
            a[0] += a[bi];
            a[0] += a[bi];
            for (int i = 1; i < N; ++i) {
                cout << i << ' ' << i + 1 << endl;
                cout << i << ' ' << i + 1 << endl;
                a[i] += a[i - 1];
                a[i] += a[i - 1];
            }
        } else if (mx < 0) {
            cout << 2 * N << endl;
            cout << bi + 1 << ' ' << N << endl;
            cout << bi + 1 << ' ' << N << endl;
            a[N - 1] += a[bi];
            a[N - 1] += a[bi];
            for (int i = N - 1; i; --i) {
                cout << i + 1 << ' ' << i << endl;
                cout << i + 1 << ' ' << i << endl;
                a[i - 1] += a[i];
                a[i - 1] += a[i];
            }
        } else {
            cout << 0 << endl;
        }
        for (int i = 1; i < N; ++i)
            if (a[i - 1] > a[i]) U("G");
    }
    return 0;
}


Measured memory_bytes: 888
class FenwickTree
    def initialize(n)
        @size = n 
        @ary = [0] * (n + 1)
    end 

    def add(i, x)
        return if i > @size
        @ary[i] += x
        add(i + (i & -i), x)
    end 

    def sum(i)
        return 0 if i == 0
        @ary[i] + sum(i - (i & -i))
    end 

    attr_reader :size
end

loop do
    a, b, mod = gets.split.map(&:to_i)
    break if a == 0
    tree = FenwickTree.new(b - a + 1)
    (a..b).map(&:to_s).sort.each do |s| 
        i = s.to_i - a + 1 
        tree.add(i, (1 + tree.sum(i - 1)) % mod)
    end 
    p tree.sum(b - a + 1) % mod 
end

Measured memory_bytes: 28612
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>

using namespace std;

int main(){
   int N,M;
   cin >> N >> M;
   int L=0;
   int R=N+1;
   for(int i=0;i<M;i++){
      int l,r;
      cin >> l >> r;
      L=max(L,l);
      R=min(R,r);
   }
   cout << max((R-L)+1,0)<< endl;
   
   return 0;
}


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

int main() {
  int N, A, B;
  string S;
  int t = 0;
  int f = 0;

  cin >> N >> A >> B >> S;

  for (int i = 0; i < S.size(); i++)
  {
    char c = S[i];
    if (c == 'a') {
      if (t < A + B) {
        cout << "Yes" << endl;
        t++;
      }
      else {
        cout << "No" << endl;
      }
    }
    if (c == 'b') {
      if (t < A + B && f < B) {
        cout << "Yes" << endl;
        t++;
        f++;
      }
      else {
        cout << "No" << endl;
      }
    }
    if (c == 'c') {
      cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 3744
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>

using namespace std;
 
#define fastio ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define t_times int t; cin >> t; while(t--)
#define fr(i, st, n) for(int i = (int )st; i < (int )n; i++)
#define rfr(i, en, st) for(int i = (int )en; i >= (int )st; i--)
#define all(c) (c).begin(), (c).end()
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)(a).size()
 
typedef long long int LL;
typedef pair< int, int> ii;
typedef vector< int> vi;
typedef vector< ii> vii;
typedef vector< vi> vvi;
 
const int mod = 1e9 + 7;
const LL INF = 9e18 + 2e17;
const int inf = 2e9;
const double eps = 1e-10;
 // START FROM HERE

int main(int argc, char const *argv[])
{
	fastio;

	int n; cin >> n;
	vi h(n); fr(i,0,n) cin >> h[i];

	vi dp(n);

	fr(i,1,n) {
		dp[i] = dp[i-1] + abs(h[i-1]-h[i]);
		if(i > 1) dp[i] = min(dp[i], dp[i-2] + abs(h[i-2]-h[i]));
	}
	cout<<dp[n-1]<<endl;



	return 0;
}

Measured memory_bytes: 3972
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long k = sc.nextLong();
		long a = Math.max(Math.abs(n - 2), 0);
		long b = Math.max(Math.abs(k - 2), 0);
		System.out.println(a * b);
	}
}


Measured memory_bytes: 23764