akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <utility>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <istream>
#include <ostream>

#include <cstdlib>
#include <cmath>
#include <cstdio>

using namespace std;

#define fi first
#define se second
#define mkp make_pair
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define rep(i,n) for(ll i=0; i < (n); ++i)
#define rrep(i,n) for(ll i=((n)-1); i >= 0; --i)

#define OPLT(T) bool operator<(const T & lop_, const T & rop_)
#define OPEQ(T) bool operator==(const T & lop_, const T & rop_)

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

istream& operator>>(istream& istr, __float128& obj) { double d; istr >> d; obj = d; return istr; };
ostream& operator<<(ostream& ostr, __float128& obj) { ostr << static_cast<double>(obj); return ostr; };

vector<vector<int> > E;
vector<int> X;

pii tab[1100];
bool dp[2][5100];

bool solve(int n) {
	//cout << "*" << n << endl;
	if(E[n].size() == 0) {
		tab[n] = pii(X[n], 0);
		return true;
	}
	rep(i,E[n].size()) {
		bool tmp;
		tmp = solve(E[n][i]);
		if(!tmp) return false;
	}

	rep(i,2) rep(j,5100) dp[i][j] = false;
	dp[1][0] = true;

	int sum = 0;
	rep(i,E[n].size()) {
		int u = E[n][i];
		rep(j,X[n]+1) {
			if(dp[!(i%2)][j] && j + tab[u].fi <= X[n]) {
				dp[i%2][j + tab[u].fi] = true;
			}
			if(dp[!(i%2)][j] && j + tab[u].se <= X[n]) {
				dp[i%2][j + tab[u].se] = true;
			}
			dp[!(i%2)][j] = false;
		}
		sum += tab[u].fi + tab[u].se;
	}

	int mn = -1;
	rep(i,X[n]+1) {
		if(dp[!(E[n].size()%2)][i]) {
			mn = X[n] -i;
		}
	}
	if(mn < 0) return false;
	sum += mn;
	tab[n] = pii(X[n],sum-X[n]);

	return true;
}

int main() {
	const string ok = "POSSIBLE", ng = "IMPOSSIBLE";
	int N;
	cin >> N;
	E.resize(N);
	X.resize(N);
	rep(i, N-1) {
		int P;
		cin >> P;
		E[P-1].push_back(i+1);
	}
	rep(i,N) cin >> X[i];
	if(solve(0)) {
		cout << ok << endl;
	}
	else {
		cout << ng << endl;
	}

	/*
	rep(i,N)
		cout << tab[i].fi << "," << tab[i].se << endl;
	// */
	return 0;
}


Measured memory_bytes: 384
def func(n):
    ans = 0
    while n > 0:
        cnt = 0
        for i in range(33):
            if (n & (1<<i)) != 0:
                cnt += 1
        ans += 1
        n %= cnt
    return ans

def main():
    n = int(input())
    s = input()
    ans = [0]*n
    cnt = 0
    for c in s:
        if c == "1":
            cnt += 1
    ad = cnt + 1
    df = cnt - 1
    start_ad = 0
    start_df = 0
    for i in range(n):
        if ad > 0:
            if s[n-1-i] == "1":
                start_ad += pow(2, i, ad)
                start_ad %= ad
        if df > 0:
            if s[n-1-i] == "1":
                start_df += pow(2, i, df)
                start_df %= df
    for i in range(n):
        if s[i] == "0":
            ans[i] = 1
            tmp = (start_ad + pow(2, n-1-i, ad)) % ad
            ans[i] += func(tmp)
        else:
            if cnt == 1:
                ans[i] = 0
            else:
                ans[i] = 1
                tmp = (start_df - pow(2, n-1-i, df)) % df
                ans[i] += func(tmp)
    for v in ans:
        print(v)

if __name__ == "__main__":
    main()

Measured memory_bytes: 75928
'use strict';

function Main(input) {
    const tmp = input.split('\n');
    const N = tmp[0];
    const K = tmp[1];
    const X = parseInt(tmp[2], 10);
    const Y = parseInt(tmp[3], 10);

    let sum = 0;

    for (let i = 1; i <= N; i++) {
        if (i <= K) {
            sum += X;
        } else {
            sum += Y;
        }
    }
    console.log(sum);
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 17864
import java.util.*;
import java.util.stream.Collectors;
//import java.io.*;
import java.util.stream.IntStream;


public class Main{
    static int sum=0;
    public static void main (String args[]){
        //初期処理
        Scanner sc=new Scanner(System.in);
        // BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        // try{
            // int n = Integer.parseInt(br.readLine());
            int N= sc.nextInt();
            int M=sc.nextInt();
            Bulb[] bulbs = new Bulb[M];
            int[] swArr = new int[N];
            Set<int[]> swSet = new HashSet<>();

            setSwPattern(swSet, swArr, 0);


            IntStream.range(0,M).forEach(i->{
                int n=sc.nextInt();
                bulbs[i]=new Bulb();
                for(int j=0;j<n;j++){
                    int m=sc.nextInt();
                    bulbs[i].sw.add(m);
                }
            });

            IntStream.range(0,M).forEach(i->bulbs[i].p=sc.nextInt());

            swSet.forEach(s->check(s,bulbs));
            System.out.println(sum);

    }

    static void check(int[] swArr, Bulb[] bulbs){

            Arrays.asList(bulbs).stream().forEach(s->{
                int swSum=0;
                for(int i=0;i<s.sw.size();i++){
                    swSum+=swArr[s.sw.get(i)-1];
                }
                if(s.p==(swSum%2)){
                    s.on=true;
                }else{
                    s.on=false;
                }
            });
            if(Arrays.asList(bulbs).stream().allMatch(s->s.on==true)){
                sum++;
            }
        
    }
    static void setSwPattern(Set<int[]> set,int[] swArr,int n){
        set.add(swArr);
        if(n<swArr.length){
        int cloneSwArr[]= swArr.clone();
        swArr[n]=0;
        setSwPattern(set,swArr,n+1);
        cloneSwArr[n]=1;
        setSwPattern(set,cloneSwArr,n+1);
        }
    }

    
}


class Bulb{
    Bulb(){};
    int p;
    Boolean on=false;
    List<Integer> sw = new ArrayList<>();

    void turn(){
        this.on=(this.sw.stream().reduce(0,Integer::sum)/2)==this.p;
    }

}

Measured memory_bytes: 27220
#include<bits/stdc++.h>
using namespace std;
const long long MOD = 1e9+7;
#define rep(i,n) for(int i=0;i<n;++i)
typedef long long int ll;
typedef unsigned long long ull;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
typedef pair<ll,ll> P;

int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    int k;
    cin>>k;
    bool ok=true;
    rep(i,k){
        if(a<b)ok=false;
        if(!ok&&b<c)break;
        if(ok){
            b*=2;
        }
        if(!ok)c*=2;  
    }
    
    if(a<b&&b<c)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3580
#include <iostream>
using namespace std;
int main()
{
int s,h,m;
    cin>>s;
    h=s/3600;
    s-=s/3600*3600;
    m=s/60;
    s-=s/60*60;
    cout<<h<<":"<<m<<":"<<s<<endl;
    return 0;
}


Measured memory_bytes: 3108
import java.util.*;

public class Main{
	public static void main(String[] args){
		int S = new Scanner(System.in).nextInt();
		int h = S / (60 * 60);
		int m = S % (60 * 60) / 60;
		int s = (S % (60 * 60)) % 60;
		System.out.println(h + ":" + m + ":" + s);
	}
}

Measured memory_bytes: 26348
#include <iostream>
#include <cmath>

using std::cin;
using std::cout;
using std::endl;

int dfs(int n, int sum, int k, int sn) {
	int ret = 0;
	if ( k < 0 ) {
		return 0;
	}
	else {
		if (sn == sum) {
			return 1;
		}
	}
	if (sn > sum || n == 0) {
		return 0;
	}
	if ( sn + (k * pow(n,2)) < sum ) {
		return 0;
	}

	ret += dfs(n, sum, k-1, sn+pow(n,2));
	ret += dfs(n-1, sum, k, sn);
	
	return ret;
}

int main(void) {
	int n;
	cin >> n;

	int lim,ret;
	bool find = false;
	while ( n != 0 ) {
		find = false;
		for (int i = 1; !(find); i++) {
			if ( !(pow(i,2) < n) ) {
				lim = i;
				find = true;
			}
		}
		ret = dfs(lim, n, 4, 0);
		cout << ret << endl;
		cin >> n;
	}
	return 0;
}

Measured memory_bytes: 2928
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
random_device rnd;
mt19937 mt(rnd());

const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7;

ll n, m, x;
ll check(VVL &book, VL &cost, int order)
{
    VL skill(m, 0);
    ll ret = 0;
    rep(i, n)
    {
        if (((order >> i) & 1) == 1)
        {
            ret += cost[i];
            rep(j, m)
            {
                skill[j] += book[i][j];
            }
        }
    }
    rep(i, m)
    {
        if (skill[i] < x)
        {
            return -1;
        }
    }
    return ret;
}

int main()
{
    cin >> n >> m >> x;
    VVL book(n, VL(m, 0));
    VL cost(n);
    rep(i, n)
    {
        cin >> cost[i];
        rep(j, m) cin >> book[i][j];
    }
    ll ans = INF;
    rep(i, (1 << n))
    {
        auto ret = check(book, cost, i);
        if (ret != -1)
            chmin(ans, ret);
    }
    if (ans == INF)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
 
using namespace std;
 
int N, M, K, v[600009];
const int mod = 1e9 + 7;
 
int add (int x, int y) {int ans = x + y; if (ans >= mod) ans -= mod; return ans;}
int subtract (int x, int y) {if (x >= y) return x - y; return x - y + mod;}
int mul (int x, int y) {return 1LL * x * y % mod;}
void adto (int &x, int y) {x += y; if (x >= mod) x -= mod;}
 
int power (int a, int b)
{
    int p = 1;
    for (int i=0; (1<<i) <= b; i++)
    {
        if (b & (1 << i)) p = mul (p, a);
        a = mul (a, a);
    }
    return p;
}
 
int fac[1000009], inv[1000009], p3[1000009];
void Prec (int lim){fac[0] = inv[0] = 1;for (int i=1; i<=lim; i++)fac[i] = mul (fac[i - 1], i);
inv[lim] = power (fac[lim], mod - 2);for (int i=lim - 1; i>=1; i--)inv[i] = mul (inv[i + 1], i + 1);}
int comb (int N, int K){int ans = mul (fac[N], inv[N - K]);ans = mul (ans, inv[K]);return ans;}
 
int main ()
{
scanf ("%d %d %d", &N, &M, &K), Prec (900003), p3[0] = 1;
for (int i=1; i<=900000; i++)
    p3[i] = add (add (p3[i - 1], p3[i - 1]), p3[i - 1]);

v[0] = 1;
if (M > K) swap (M, K); ///M <= K
for (int i=1; i<=M + K; i++)
{
    v[i] = add (v[i - 1], v[i - 1]);
    if (i > M) v[i] = subtract (v[i], comb (i - 1, M));
    if (i > K) v[i] = subtract (v[i], comb (i - 1, K));
}
int ans = 0;
for (int i=0; i<=M + K; i++)
{
    v[i] = mul (v[i], p3[M + K - i]);
    adto (ans, mul (v[i], comb (i + N - 1, N - 1)));
}
printf ("%d\n", ans);
return 0;
}

Measured memory_bytes: 14336
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define pvec(v) rep(i,v.size()){cout << v[i] << " ";};cout<<endl;
#define pb push_back
#define pf push_front
#define mod 1e9+7
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;

const double pi = acos(-1.0);
 
ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

int main()
{
	ll n,tmp,ans=10000000000,a,b;
	cin >> n;
	for(ll i=1;i<=sqrt(n);i++){
		if(n%i!=0) continue;
		ll ca=0,cb=0;
		a=i;
		b=n/i;
		while(a>0){
			a/=10;
			ca++;
		}
		while(b>0){
			b/=10;
			cb++;
		}
		tmp=max(ca,cb);
		ans=min(ans,tmp);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <string.h>
#include <string>
#include <cmath>
#include <cstdio>
#include <functional>
#include <map>
#include <typeinfo>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<double, double> pd;

stack<int> s;

int main()
{
  int n;
  scanf("%d", &n);
  
  int res = 0;
  
  for(int i = 0; i < n; i++)
  {
    int num;
    scanf("%d", &num);
    
    if(s.empty() || s.top() >= num)
    {
      s.push(num);
      res++;
    }
  }
  
  printf("%d\n", res);
  
  return 0;
}


Measured memory_bytes: 1024
n = int(input())
li = list(map(int,input().split()))

M = max(li)
li.remove(M)

N = int(M//2)
li_sa = [abs(li[i] - N) for i in range(n-1)]
m = min(li_sa)
k = li_sa.index(m)

N = li[k]

print(str(M)+" "+str(N))


Measured memory_bytes: 14060
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath> 
using namespace std;

int main(){
    int N;
    cin >> N;
    if(N%2==0)
        cout << N << endl;
    else
        cout << N*2 <<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int a,p;
	cin >> a >> p;
	p+=a*3;
	cout << p/2;
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
#AGC38 A

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

h,w,a,b = LI()
lst = [[0]*w for _ in range(h)]
for i in range(h):
    if i < b:
        for j in range(w):
            if j < a:
                lst[i][j] = 1
    else:
        for j in range(w):
            if j >= a:
                lst[i][j] = 1
for i in range(h):
    lst[i] = ''.join(map(str,lst[i]))
    print(lst[i])
            

Measured memory_bytes: 55516
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <cmath>

#define MAX_N 100

using namespace std;

int inf = 1000000000;
int N, M;
int a[MAX_N], b[MAX_N];
int suma, sumb;

void solve() {
	int min = inf;
	int ansa, ansb;
	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j < M; j++)
		{
			if(suma-a[i]+b[j] == sumb+a[i]-b[j]){
				if(min > a[i] + b[j]){
					min = a[i]+b[j];
					ansa = i;
					ansb = j;
				}
			}
		}
	}
	if(min == inf) cout << -1 << endl;
	else cout << a[ansa] << " " << b[ansb] << endl;
}

int main(){
	while(1){
		cin >> N >> M;
		if(N == 0 && M == 0) break;
		suma = 0;
		for(int i = 0; i < N; i++){
			cin >> a[i];
			suma += a[i];
		}
		sumb = 0;
		for (int i = 0; i < M; i++)
		{
			cin >> b[i];
			sumb += b[i];
		}
		solve();
	}
	return 0;
}

Measured memory_bytes: 1160
N = int(input())
cnt = 0
list1 = []
for i in range(2, 55555):
    for j in range(2, i+1):
        if i % j == 0 and i % 5 == 1:
            if i == j:
                cnt += 1
                list1.append(str(i))
            else:
                break
    if(cnt >= N):
        break

anslist = []
#print(list1)

str = ' '.join(list1)
print(str)


Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main(void)
{
    int a,b;
    cin >> a >> b;
    
    if(a > b)
        cout << "a > b" << endl;
        
    else if(a < b)
        cout << "a < b" << endl;
    
    else
        cout << "a == b" << endl;
        
    return 0;
}


Measured memory_bytes: 3072
;; C - Next Prime

(defun next-prime (X)
  (loop for n from X
    when (primep n) return n))

(defun primep (n)
  (loop for d from 2
    while (<= (* d d) n)
    never (zerop (mod n d))))

(format t "~a~%" (next-prime (read)))


Measured memory_bytes: 8936
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

void dfs(vector<int> &visit, int E[][50], int v) {
    visit[v] = 1;
    for (int i = 0; i < 50; i++) {
        if (E[v][i] && !visit[i]) {
            dfs(visit, E, i);
        }
    }
}

int main() {
    int N, M;
    cin >> N >> M;
    int E[50][50] = {{0}};
    vector<int> A, B;
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        E[a][b] = E[b][a] = 1;
        A.push_back(a);
        B.push_back(b);
    }

    int ans = 0;
    for (int i = 0; i < M; i++) {
        E[A[i]][B[i]] = E[B[i]][A[i]] = 0;

        vector<int> visit(50);
        dfs(visit, E, 0);
        bool flag = true;
        for (int i = 0; i < N; i++) {
            if (!visit[i]) flag = false;
        }
        if (!flag) {
            ans++;
        }
        E[A[i]][B[i]] = E[B[i]][A[i]] = 1;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iterator>
#include <string>
#include <map>
#include <vector>
using namespace std;

int main() {
	int n,i;
	scanf("%d",&n);
	vector<vector<int>> dice(n);
	for(i=0;i<n;i++){
		int d1,d2;
		scanf("%d%d",&d1,&d2);
		dice[i].push_back(d1);
		dice[i].push_back(d2);
	}
	for(i=0;i<=n-3;++i){
		int flag=0;
		for(int j=i;j<i+3;j++){
			if(dice[j][0]!=dice[j][1]){
				flag=1;
				break;
			}
		}
		if(flag==0){
			printf("Yes");
			return 0;
		}
	}
	printf("No");
	
	return 0;
}

Measured memory_bytes: 3728
n,m,c=map(int,input().split())
b=list(map(int,input ().split()))
num=0
for _ in range(n):
  a=list(map(int,input().split()))
  hoge=0
  for i in range(m):
    hoge+=a[i]*b[i]
  if hoge+c>0:
    num+=1
print(num)

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

namespace ConsoleApp95 {
    class Program {
        static void Main(string[] args) {
            string S = Console.ReadLine();
            string T = Console.ReadLine();

            int len = S.Length;
            int len_hint = T.Length;

            int ans_ind = 0;

            bool flg = false;

            //後ろから調べていくことに注意
            for (int i = len - len_hint; i >= 0; i--) {
                for (int j = 0; j < len_hint; j++) {
                    if (S[i + j] == '?') {
                        continue;
                    }

                    if (S[i + j] != T[j]) {
                        goto skip;
                    }
                }

                flg = true;
                ans_ind = i;
                break;

                skip:;
            }

            if (flg == false) {
                Console.WriteLine("UNRESTORABLE");
                return;
            }

            for (int i = 0; i < len; i++) {
                if (i <= ans_ind - 1 || i >= ans_ind + len_hint) {
                    if (S[i] == '?') {
                        Console.Write('a');
                    } else {
                        Console.Write(S[i]);
                    }

                } else {
                    Console.Write(T[i - ans_ind]);

                }

            }
            Console.WriteLine();


        }
    }
}


Measured memory_bytes: 13140
#include <iostream>
using namespace std;
int main(void){
   int n,a[11]={},max=0,cnt=0;
   cin>>n;
   for(int i=0;i<n;i++){
       cin>>a[i];
       if(max<a[i]) max=a[i];
       cnt+=a[i];
   }
   
   int ans=cnt-max;
   if(max<ans) cout<<"Yes"<<endl;
   else cout<<"No"<<endl;
   
   return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
lst = list(map(int, input().split()))

ans = 0
A = 0
while A <= min(K, N):
    B = 0
    lst2 = []
    while B <= min(K, N) - A:
        lst2 = lst[:A]+lst[N-B:]
        lst2.sort()
        count = 0
        for i in range(len(lst2)):
            if lst2[i] <= 0 and i+1 <= K - A - B:
                pass
            else:
                count += lst2[i]
        ans = max(ans, count)
        B += 1
    A += 1

print (ans)


Measured memory_bytes: 3064
A = int(input())
B = int(input())
C = int(input())
X = int(input())

ans = 0
for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if 500*i+100*j+50*k == X:
                ans += 1

print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <numeric>

using namespace std; 

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)


int main() {
    
  int N,K;
  int ans;

  cin >> N >> K;

  if( K == 1 ){
	  ans = 0;
  } else {
	  ans = N - K;
  }
 
  cout << ans << endl;

  return 0;
}

/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep for(int i = 0;i<n;i++)
#define ll long long
 
//const int INF = 1e8;
const int MOD = 1000000007;
typedef pair<int,int>P;
int dx[4] = {1,0,-1,0};int dy[4] = {0,1,0,-1};
queue<P> que;
 
int main(){
    ll n,m;cin >> n >> m;
    //Sがn個、cがm個
    if(n>=m/2){
        cout << m/2 << endl;
    }else{
        //使えるcの数
        ll a = m - 2*n;
        cout << n +  a/4 << endl;
    }
}

Measured memory_bytes: 256
// HTTF.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include "bits/stdc++.h"
#define YES "YES"
#define NO "NO"
#define YESNO OUT(three(solve(),YES,NO))
#define ECHO OUT(solve())
#define three(A,B,C) ((A)?(B):(C))
#define FOR(i,a,b)  for(LL i=(a);i< (LL)(b);i++)
#define EFOR(i,a,b) for(LL i=(a);i<=(LL)(b);i++)
#define RFOR(i,a,b) for(LL i=(a);i>=(LL)(b);i--)
#define REP(i,b) FOR(i,zero,b)
#define EREP(i,b) EFOR(i,zero,b)
#define RREP(i,b) RFOR(i,b,zero)
#define ALL(c) c.begin(),c.end()
#define UNIQUE(c) sort(ALL(c));c.erase(unique(ALL(c)),c.end())
#define MAX(c) (*max_element(ALL(c)))
#define MIN(c) (*min_element(ALL(c)))
#define MP make_pair
#define FI first
#define SE second
#define SI(x) (LL(x.size()))
#define PB push_back
#define DEBUG(a) OUT(a)
#define DEBUG2(a,b) OUT2(a,b)
#define cat cout << __LINE__ << endl
#define OUT(a) cout << (a) << endl
#define OUT2(a,b) cout << (a) <<" "<<(b) << endl
#define zero 0LL
#define int LL
#define pb emplace_back
#define eb pb

using namespace std;
template<typename T> inline void maximize(T &a, T b) { a = max(a, b); }
template<typename T> inline void minimize(T &a, T b) { a = min(a, b); }
template<typename T> inline bool middle(T a, T b, T c) { return b <= a && a <= c; }
template<class T> inline bool MX(T &l, const T &r) { return l < r ? l = r, 1 : 0; }
template<class T> inline bool MN(T &l, const T &r) { return l > r ? l = r, 1 : 0; }
typedef long long LL;
typedef double ld;
typedef int ut;
typedef vector<ut> VI;
typedef vector<VI> VII;
typedef pair<ut, ut> pr;
typedef pair<ut, pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef priority_queue<pr, Vpr, greater<pr> > PQ;
inline void outputVI(VI x) { REP(i, SI(x)) { cout << three(i, " ", "") << x[i]; }OUT(""); }
const int SIZE1 = 5e5 + 1000;
const int SIZE2 = 2010;
const int SIZE3 = 400;
const int SIZE = SIZE1;
const int MAPSIZE = 40;
const LL p = 998244353;
const LL INF = 1LL << 60;
const long double EPS = 1e-7;
typedef pair<ld, ut> pld;

#define endl "\n" //インタラクティブでは消す
ut N, M, K, L, Q, D, H, W;
// ut A,B,C,D,E,F,G,H,I,J,O,P,Q,R,T,U;
VI edges[SIZE];
LL vals[SIZE], maps2[SIZE2][SIZE2], answer = zero;
LL maps[SIZE2][SIZE2];
VI v;
LL solve() {

	cin >> N;
	LL MSIZE = 100;

	EFOR(i, 1,MSIZE) vals[i] = (1LL<<i)-1;
	LL nokori = N;
	EFOR(i,1, 100) {
		int ans = 0;
		REP(j,i) {
			if (vals[j+1]-vals[j] <= nokori) ans = j;
			else break;
		}
		nokori -= vals[ans+1]-vals[ans];
		v.insert(v.begin() + ans, i);
		if (nokori == 0) break;
	}
	cout << v.size() + 100 << endl;
	EFOR(i, 1, 100) {
		if (i == 1) cout << i;
		else cout << " " << i;
	}
	REP(i, v.size()) {
		cout << " " << v[i];
	}
	cout << endl;
//	cout << nokori << endl;
	return	0;
}





//!!!!!!!!!!!!!!!!!!!実装を詰める!!!!!!!!!!!!!!!!!!!!!!!!!
signed main() {

	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(0);
	solve();
	cin >> N;
	return 0;

}

Measured memory_bytes: 15616
#include<iostream>
#include<stack>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

int main() {
    stack<int> s1;
    stack<pair<int, int> > s2;
    char ch;
    int sum = 0;
    for (int i = 0; cin >> ch; i++) {
        if (ch == '\\') s1.push(i);
        else if (ch == '/' && s1.size() > 0) {
            int j = s1.top(); s1.pop();
            sum += i - j;
            int a =i - j;
            while (s2.size() > 0 && s2.top().first > j) {
                a += s2.top().second; s2.pop();
            }
            s2.push(make_pair(j, a));
        }
    }
    vector<int> ans;
    while (s2.size() > 0) { 
        ans.push_back(s2.top().second);
        s2.pop();
    }
    reverse(ans.begin(), ans.end() );
    cout << sum << endl;
    cout << ans.size();
    for (int i = 0; i < ans.size(); i++) {
        cout << " ";
        cout << ans[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3240
#ifndef _WIN32
#include<iostream>
#endif
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<string>
#include<stdlib.h>

using namespace std;

bool func(int w1, int h1, int w2, int h2){
	int l1 = w1*w1 + h1*h1;
	int l2 = w2*w2 + h2*h2;
	if (l1 < l2)return true;
	if (l1 == l2 && h1 < h2)return true;
	return false;
}

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

	cout << fixed << setprecision(30);
	int h, w;
	while (cin >> h >> w){
		if (h == 0 && w == 0)return 0;
		int rw = w + 1;
		int rh = h + 1;
		for (int i = 1; i <20001; i++){ //w
			for (int j = 1; j<101; j++){//h
				if (i <= j)continue;
				if (func(w, h, i, j)){
					if (func(i, j, rw, rh)){
						rw = i;
						rh = j;
					}
				}
			}
		}
		cout << rh << " " << rw << endl;
	}

	return 0;
}

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

int main(){
    long long a, b, x; cin >> a >> b >> x;
 
    long long ans = (b / x) - (a / x);
    if (a % x == 0LL)
	ans++;
 
    cout << ans << endl; 
    return 0;
}


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

template <typename T>
class BIT {
    using u32 = uint_fast32_t;
    // bit : 1-indexed,各要素の値を持つ
    vector<T> bit;
    u32 n;

   public:
    BIT(u32 N) {
        n = N;
        bit.assign(N + 1, 0);
    }

    // i番目の値にxを加える
    void add(u32 i, T x) {
        while (i <= n) {
            bit[i] += x;
            // i&-i : iの最右1bit
            i += i & -i;
        }
    }

    // a1～aiの総和を返す
    T sum(u32 i) {
        T s = 0;
        while (i > 0) {
            s += bit[i];
            i -= i & -i;
        }
        return s;
    }

    // ai～ajの総和を返す
    T range_sum(u32 i, u32 j) { return sum(j) - sum(i - 1); }
};

template <typename T>
ll inversion_number(vector<T> &v) {
    int n = v.size(), cnt = 1;
    set<T> st;
    unordered_map<T, int> f;
    for (int i = 0; i < n; i++) st.insert(v[i]);
    for (auto ite = st.begin(); ite != st.end(); ++ite) f[*ite] = cnt++;

    BIT<ll> tree(cnt - 1);
    ll res = 0;
    for (int j = 0; j < n; j++) {
        res += j - tree.sum(f[v[j]]);
        tree.add(f[v[j]], 1);
    }
    return res;
}

int main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> a(N + 1, 0), s(N + 1, 0), x(N + 1, 0);
    for (int i = 1; i <= N; i++) {
        cin >> a[i];
        s[i] = s[i - 1] + a[i];
        x[i] = s[i] - i * K;
    }
    cout << N * (N + 1) / 2 - inversion_number(x) << endl;
    return 0;
}

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

int main() {
  int s;
  cin >> s;
  set<int> st;
  int x = s;
  while(st.count(x) == 0) {
    st.insert(x);
    if(x % 2 == 0) {
      x /= 2;
    }
    else {
      x = 3 * x + 1;
    }
  }
  cout << st.size() + 1 << endl;
  return 0;
}

Measured memory_bytes: 3564
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <random>
#include <iterator>

using namespace std;

#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(v) reverse((v).begin(),(v).end())
#define ANS(ans) cout<<(ans)<<endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  for (int i = 0; i < (n); ++i)


int main() {
	int n;
	cin >> n;
	VI v(n);
	REP(i, n) {
		cin >> v[i];
	}

	int a, b;
	b = accumulate(v.begin(), v.end(), 0);
	a = 0;
	int ans = abs(a - b);
	REP(i, n) {
		a += v[i];
		b -= v[i];
		ans = min(ans, abs(a - b));
	}
	ANS(ans)


	return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val s = readLine()!!
    if (n%2 == 1) {
        println("No")
        return
    }
    val len = n/2
    var ans = true
    repeat(len) {
        if(s[it] != s[it+len]) ans = false
    }
    if(ans) println("Yes")
    else println("No")
}


Measured memory_bytes: 34452
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
  int n;
  long long ans = 0;
  vector<int> a;
  cin >> n;
  for (int i=0;i<3*n;i++) {
    int tmp;
    cin >> tmp;
    a.push_back(tmp);
  }
  sort(a.begin(), a.end(), greater<int>());
  for (int i=0;i<n;i++) {
    ans += a[i*2+1];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2420
//#include "SaveFuncs.cpp"

#include <iostream>
#include <array>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <iomanip>	//cout << fixed << setprecision(桁数);
#include <stdexcept>

using namespace std;
using ll = long long;

#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; i++)
#define rep1(i, n) for(int i=1, i##_len=(n); i<i##_len; i++)
#define rrep(i, n) for(int i=(n)-1; i >= 0; i--)
#define rrep1(i, n) for(int i=(n); i > 0; i--)
#define all(x) (x).begin(), (x).end()
#define pair(a, b) make_pair(a, b);
//#define int long long
constexpr int INF = 2000000100;
constexpr int DIV = 1000000007;	// 10e9+7
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> T divUp(T a, T b) { if (a % b == 0) { return a / b; } return a / b + 1; }
std::string strMulti(std::string t, int n) { std::string out = ""; for (int i = 0; i < n; i++) { out += t; } return out; }
template<class T> T mathP(T m, T n) { T ret = 1; for (T i = m; i > m - n; i--) { ret *= i; } return ret; }
template<class T> T mathC(T m, T n) { T ret = mathP(m, n); for (T i = 2; i <= n; i++) { ret /= i; } return ret; }

/*****/

int Main()
{
	int N;
	cin >> N;
	vector<string> S(N);
	rep(i, N)
	{
		string txt;
		cin >> txt;
		sort(all(txt));
		S.at(i) = txt;
	}

	sort(all(S));

	ll ret = 0;
	int end = 0;
	for (int i = 0; i < N; i++)
	{
		if (S.at(end) != S.at(i))
		{
			ret += mathC((ll)i - (ll)end, 2ll);
			end = i;
		}
	}
	ret += mathC((ll)N - (ll)end, 2ll);

	cout << ret;

	return 0;
}

/*****/

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

	Main();

	return 0;
}


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

int main(){
    string S;
    cin >> S;
    
    if(S[2] == S[3] && S[4] == S[5]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

}

Measured memory_bytes: 256
#include <iostream>                                        
using namespace std;                                       
                                                           
int main(){                                                
                                                           
  int x,y,tmp;                                             
                                                           
  while(1){                                                
    cin >> x >> y;                                         
    if(x == 0 && y == 0) break;                            
    if(x > y){                                             
      tmp = x;                                             
      x = y;                                               
      y = tmp;                                             
    }                                                      
                                                           
    cout << x << " " <<  y << endl;;                       
                                                           
  }                                                        
                                                           
  return 0;                                                
                                                           
}

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

int main(){
  long long  N ; 
  cin >> N ;
  map<long long , int> mp;
  for(int i = 0 ; i < N ; i++){
    int P ; 
    cin >> P ; 
    mp[P]++ ; 
  }
  int ans = 0 ; 
  for(auto a : mp){
    if(a.second%2 == 1 ) ans++ ; 
    else continue ;
  }
  cout << ans << endl ; 
}

Measured memory_bytes: 9868
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;

using namespace std;
#define N 100010
int n,m;
pair<int,int> p[N];
int main(){
    cin>>n>>m;
    lol(i,m)cin>>p[i].first>>p[i].second;
    sort(p,p+m);
    int ans=1,mini=mod;
    lol(i,m){
	int a=p[i].first,b=p[i].second;
	if(mini<=a){
	    ans++;
	    mini=mod;
	}
	mini=min(mini,b);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1152
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define MAXN 8
char M[MAXN+5][MAXN+5];
int cnt,x=1,y=1;
int main(){
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        getchar();
        for(int j=1;j<=m;j++){
            cin>>M[i][j];
            if(M[i][j]=='#') cnt++;
        }
    }
    for(int i=1;i<cnt;i++){
        if(M[x+1][y]=='#') x++;
        else if(M[x][y+1]=='#') y++;
        else {
            cout<<"Impossible"<<endl;
            return 0;
        }
    }
    cout<<"Possible"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F(i,n) for (int i=1; i<=(int)n; i++)
#define FF(i,n) for (int i=0; i<(int)n; i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pi pair < int , int >
#define re(x) (int)x.size()
#define y1 u228
#define vi vector<int>
using namespace std;
typedef long long ll;
const int N = 100010;
const int big = 2e9;
const int md = 1e9 + 7;
int n,k,ans,tex,d1[N],d2[N];
vi p[N];
void dfs(int v,int pr,int kol){
    if (kol>k/2) tex++;
    FF(j,re(p[v])){
        int u=p[v][j];
        if (u==pr) continue;
        dfs(u,v,kol+1);
    }
}
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);
//    freopen("input.txt","r",stdin);
    cin>>n>>k;
    F(i,n-1){
        int a,b;
        cin>>a>>b;
        p[a].pb(b);
        p[b].pb(a);
        d1[i]=a; d2[i]=b;
    }
    ans=big;
    if (k%2==0){
        F(i,n){
            tex=0;
            dfs(i,-1,0);
            ans=min(ans,tex);
        }
        cout<<ans;
        return 0;
    }
    F(i,n-1){
        tex=0;
        dfs(d1[i],d2[i],0);
        dfs(d2[i],d1[i],0);
        ans=min(ans,tex);
    }
    cout<<ans;
    return 0;
}







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


using namespace std;

int main(void)
{
	int n;
	int i1,i2;

	vector<int> v;
	v.push_back(6);

	for(i1=8;i1<300001;i1++){
		if(i1%7==1 || i1%7==6){
			for(i2=0;(v[i2]*v[i2])<=i1;i2++){
				if(i1%v[i2]==0) break;
			}
			//if(i2>=v.size()) v.push_back(i1);
			if(v[i2]*v[i2]>i1) v.push_back(i1);

		}
	}

	while(1){
		cin >> n;
		if(n==1) break;

		cout << n << ":";

		for(i1=0;v[i1]<=n;i1++){
			if(i1==v.size()) break;
			if(n%v[i1]==0) cout << " " << v[i1] ;
		}

		cout << endl;

	}
	return 0;
}

Measured memory_bytes: 1348
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String s=sc.next();
		long mod=1000000007;
		long[][] dp=new long[s.length()+1][13];
		dp[0][0]=1;
		int rt=1;
		for(int i=1; i<=s.length(); i++){
			if(i!=1){
				rt*=10;
				rt%=13;
			}
			if(s.charAt(s.length()-i)=='?'){
				for(int j=0; j<10; j++){
					for(int u=0; u<13; u++){
						int c=(j*rt)%13;
						dp[i][(c+u)%13]=(dp[i][(c+u)%13]+dp[i-1][u])%mod;
					}
				}
			}else{
				int k=s.charAt(s.length()-i)-'0';
				k*=rt;
				k%=13;
				for(int j=0; j<13; j++){
					dp[i][(j+k)%13]=(dp[i-1][j])%mod;
				}
			}
		}
		System.out.println(dp[s.length()][5]);
	}
}


Measured memory_bytes: 37104
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm> // sort
#include <map>

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 998244353;
static const ll INF = 1000000000000000000LL;
using namespace std;

struct Node {
    int l;
    int r;
    ll  c;
};

bool cmp(const Node &a, const Node &b)
{
    if(a.l == b.l)
    {
        return a.r < b.r;
    }

    return a.l < b.l;
}

Node make_Node(int l, int r, ll c) {
    Node mynode = {l, r, c};
    return mynode;
}

int main(){
    ll N,M;
	cin >> N >> M;

    ll dp[N+1];
    REP(i,N+1)
    {
        dp[i] = INF;
    }

    dp[0] = 0;

    vector <Node> v(M);
    REP(i,M)
    {
        ll l,r,c;
        cin >> l >> r >> c;
        --l;--r;
        v[i] = make_Node(l, r, c);
    }

    sort(v.begin(),v.end(),cmp);

    REP(i,M)
    {
        ll l = v[i].l;
        ll r = v[i].r;

        if(dp[r] <= dp[l] + v[i].c)continue;

        //cout << l << " " << r << endl;
        for(ll j = l; j <= r; ++j)
        {
            dp[j] = min(dp[j],dp[l] + v[i].c);
        }
    }

    ll res = dp[N-1];

    if(res >= INF)res = -1;
	cout << res << endl;
    return 0;    
}

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

using namespace std;

const int M = 50;
int n, a[M], b[M], c[M];

int main () {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) cin >> b[i];
  for (int i = 1; i <  n; i++) cin >> c[i];
  int ans = 0; 
  a[0] = 2e9;
  for (int i = 1; i <= n; i++) {
    ans += b[a[i]];
    if (a[i] == a[i-1]+1) ans += c[a[i]-1];
  }
  cout << ans << endl;
}

Measured memory_bytes: 384
# include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m, temp;
  	cin >> n >> m;
  	int broken[n+1] = {0};
	for (int i =0; i < m; i++){
    	cin >> temp;
      	broken[temp] = 1;
    }
  	long int dp[n+1] = {0};
  	dp[0] = 1;
  	(broken[1]==0)? dp[1] = 1 : dp[1] = 0;
  	for (int i = 2; i < n+1; i++){
    	if(!broken[i]) dp[i] = (dp[i-1]%1000000007 + dp[i-2]%1000000007)%1000000007;
    }
  
  cout << dp[n]<<'\n';
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#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--)

int main(){
    int N; cin >> N;
    vector<int> p(N), rf(N), Sum(N, -1), rSum(N, -1);
    rep(i, 0, N){
        cin >> p[i]; p[i]--;
        rf[p[i]] = i;
    }
    Sum[0] = 0;
    rep(i, 1, N){
        if(rf[i-1] < rf[i] )Sum[i] = Sum[i-1] + 1;
        else Sum[i] = 0;
    }
    rSum[N - 1] = 0; 
    rrep(i, 0, N - 1){
        if(rf[i] < rf[i + 1]) rSum[i] = rSum[i+1] + 1;
        else rSum[i] = 0;
    }
    int ans = 1e9;
    rep(i, 0, N){
        ans = min(ans, i - Sum[i] + (N - 1 - i) - rSum[i]);
    }
    cout << ans << endl;


}

Measured memory_bytes: 3328
#include <iostream>
#include <algorithm>

using namespace std;

const int INF = 99999;
const int MAXN = 41;
int N, M_a, M_b;
int a[MAXN], b[MAXN], c[MAXN];
int dp[44][444][444];
int maxa,maxb;

int main() {
  cin >> N >> M_a >> M_b;

  for(int i = 0; i < N; i++) {
    cin >> a[i] >> b[i] >> c[i];
    maxa = max(maxa,a[i]);
    maxb = max(maxb,b[i]);
  }

  for(int i = 0; i < N; i++)
    for(int j = 0; j < maxa * N; j++) fill(dp[i][j],dp[i][j]+(maxb * N),INF);

  dp[0][0][0] = 0;
  dp[0][a[0]][b[0]] = c[0];

  for(int i = 1; i < N; i++) {
    for(int j = 0; j < maxa*N; j++) {
      for(int k = 0; k < maxb*N; k++) {
	dp[i][j][k] = min(dp[i][j][k],dp[i-1][j][k]);
	if(j - a[i] >= 0 && k -b[i] >= 0)
	dp[i][j][k] = min(dp[i-1][j][k],dp[i-1][j-a[i]][k-b[i]]+c[i]);
      }
    }
  }

  int ans = INF;
  for(int i = 1; i < maxa*N; i++) {
    for(int j = 1; j < maxb*N; j++) {
      if(M_a * j == M_b * i) {
	ans = min(ans,dp[N-1][i][j]);
      }
    }
  }
  if(ans == INF) cout << "-1"<<endl;
  else  cout << ans <<endl;
}
	
      


Measured memory_bytes: 32896
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int m(int a) {
    return ((a%MOD)+MOD)%MOD;
}

int main() {
    int n;
    scanf("%d ", &n);
    string s;
    cin>>s;
    vector<vector<int>> dp(n+5, vector<int>(n+5, 0));
    vector<int> sm(n+5, 1);
    dp[1][1] = 1;
    sm[0] = 0;
    for (int i=2; i<=n; i++) {
        vector<int> ns(n+5, 0);
        for (int j=1; j<=i; j++) {
            if (s[i-2]=='>') {
                dp[i][j] = m(sm[i-1]-sm[j-1]);
                ns[j] += dp[i][j];
                // ns[i] -= dp[i][j];
                // for (int k=j; k<i; k++) {
                //     dp[i][j] += dp[i-1][k];
                //     if (dp[i][j]>=MOD) dp[i][j] -= MOD;
                // }
            } else {
                dp[i][j] = m(sm[j-1]-sm[0]);
                ns[j] += dp[i][j];
                // ns[i] -= dp[i][j];
                // for (int k=1; k<j; k++) {
                //     dp[i][j] += dp[i-1][k];
                //     if (dp[i][j]>=MOD) dp[i][j] -= MOD;
                // }
            }
        }
        sm[0] = 0;
        for (int j=1; j<=n; j++) {
            sm[j] = m(sm[j-1]+ns[j]);
        }
    }

    int ans = 0;
    for (int i=1; i<=n; i++) {
        ans += dp[n][i];
        if (ans>=MOD) ans -= MOD;
    }

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


Measured memory_bytes: 35712
N,*as=$<.read.split.map(&:to_i)

n = as[0]
ls = as.map {|a| n = n.gcd(a) }
n = as[-1]
rs = as.reverse_each.map {|a| n = n.gcd(a) }

max = [ls[-2],rs[-2]].max
(N-2).times do |i|
    n = ls[i].gcd(rs[-3-i])
    max = n if max < n
end

puts max

Measured memory_bytes: 23248
import java.io.*;
import java.math.BigInteger;
import java.util.*;

/**
 * @author Tran Anh Tai
 * @template for CP codes
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }
    // main solver
    static class Task{
        static int MOD = 998244353;
        public void solve(InputReader in, PrintWriter out){
            int n = in.nextInt();
            int[] a =  new int[n];
            int t = 0;
            for (int i = 0; i < n; i++){
                a[i] = in.nextInt();
                t ^=a[i];
            }
            for (int i = 0; i < n; i++){
                out.print((t ^ a[i])+ " ");
            }
        }
    }
    // fast input reader class;
    static class InputReader {
        BufferedReader br;
        StringTokenizer st;

        public InputReader(InputStream stream) {
            br = new BufferedReader(new InputStreamReader(stream));
        }

        public String nextToken() {
            while (st == null || !st.hasMoreTokens()) {
                String line = null;
                try {
                    line = br.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
                if (line == null) {
                    return null;
                }
                st = new StringTokenizer(line);
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextToken());
        }
        public long nextLong(){
            return Long.parseLong(nextToken());
        }
    }
}

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

using namespace std;

#define MAXN 100010
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define eps (1e-6)
typedef long long LL;

int n, k, a[MAXN];

int GCD(int a, int b)
{
    for(int t; b; t = a % b, a = b, b = t);
    return a;
}


int main()
{
    int i, j;
    scanf("%d %d", &n, &k);
    for(i = 1; i <= n; ++i){
        scanf("%d", a + i);
    }
    for(i = 2, j = a[1]; i <= n; ++i){
        j = GCD(j, a[i]);
    }
    for(i = 1; i <= n; ++i){
        if(k > a[i]) continue;
        if((a[i] - k) % j == 0){
            printf("POSSIBLE\n");
            return 0;
        }
    }
    printf("IMPOSSIBLE\n");
	return 0;
}


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

template <class T>
struct UnionFind {
    vector<T> parents;
    UnionFind(int N) : parents(N) {
        for (int i = 0; i < N; i++) parents[i] = i;
    }
    T root(int x) {
        if (parents[x] == x) return x;
        return parents[x] = root(parents[x]);
    }
    bool unite(int x, int y) {
        int rx = root(x), ry = root(y);
        if (rx == ry) return false;
        parents[rx] = ry;
        return true;
    }
    bool same(int x, int y) {
        int rx = root(x), ry = root(y);
        return rx == ry;
    }
};

int main() {
    ll N, M;
    cin >> N >> M;
    vector<ll> X(M), Y(M), Z(M);
    rep(i, M) cin >> X[i] >> Y[i] >> Z[i];

    UnionFind<int> uf(N);
    ll ans = N;
    rep(i, M) if (uf.unite(X[i] - 1, Y[i] - 1)) ans--;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2944