akhauriyash/Code-Regression huggingface dataset:
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
count = 0
for i in range(N):
  for j in range(2):
    tmp = min(A[i+j],B[i])
    count += tmp
    A[i+j] -= tmp
    B[i] -= tmp
print(count)

Measured memory_bytes: 18624
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <cassert>

using namespace std;
using ll = long long;

int main()
{
    int n, x, t;
    cin >> n >> x >> t;
    int num = n / x;
    if(n % x == 0){
        cout << num * t << endl;;
    }else{
        cout << (num + 1) * t << endl;
    }
    return 0;
}

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

using namespace std; 

int A, B, C, X, Y;

int main(void) {

	cin >> A >> B >> C >> X >> Y;

	long long int ans = (long long int)5000 * 10000000;

	

	//========
	ans = min(ans,(long long int) A*X + B*Y);

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

	long long int tmp;
	tmp = C * 2 * X; if (Y > X) { tmp += (Y - X)*B; }

	ans = min(ans, tmp);

	//===========
	tmp = C * 2 * Y; if (X > Y) { tmp += (X - Y)*A; }
	ans = min(ans, tmp);


	cout << ans << endl;

	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.answer"

int dp[4001][4001];
int main() {
	string a, b;
	while (cin >> a >> b) {
		for (int i = 0; i < 4001; ++i) {
			for (int j = 0; j < 4001; ++j) {
				dp[i][j] = -1e9;
			}
		}
		int ans = 0;
		for (int i = 0; i < a.size(); ++i) {
			for (int j = 0; j < b.size(); ++j) {
				if (a[i] == b[j]) {
					if (i > 0 && j > 0) {
						dp[i][j] = max(1,dp[i - 1][j - 1] + 1);
					}
					else {
						dp[i][j] = 1;
					}

				}
				ans = max(ans, dp[i][j]);
			}
		}
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 65652
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  string ns;
  getline(cin, ns);
  const int N = ns.size();
  i64 bills = 0;
  i64 carry = 0;
  bool five = false;
  REP(i, N) {
    int j = N - 1 - i;
    int d = ns[j] - '0' + carry;
    if (five && d <= 5) {
      d--;
    }
    carry = d / 10;
    d %= 10;
    five = d == 5;
    if (d < 5) {
      bills += d;
    } else if (d > 5) {
      bills += 10 - d;
      assert(carry == 0);
      carry = 1;
    } else {
      bills += 5;
      carry = 1;
    }
  }
  if (!five) {
    bills += carry;
  }
  cout << bills << '\n';
}


Measured memory_bytes: 1948
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>


using namespace std;

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

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

        cin>>P[i];
    }

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

        X[i]=i+1;
    }
    int D;
    D=0;
    for(int i=0;i<N;i++){
        if(P[i]!=X[i]){
            D=D+1;

        }
        else{
            D=D+0;

        }

    }

    if(D<=2){
        cout<<"YES"<<endl;

    }
    else{
        cout<<"NO"<<endl;
    }
}





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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int N,K; cin>>N>>K;
  int cnt=0,X=1;
  while(N>=X){
    X*=K;
    cnt++;
  }
  cout<<cnt<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int a, b, c, d, e, k;
  scanf("%d %d %d %d %d %d", &a, &b, &c, &d, &e, &k);
  if ((e - a) > k)
    puts(":(");
  else
    puts("Yay!");
  return 0;
}

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

#define int long long int 


signed main()
{
    int n;
    cin>>n;
    vector<string> s;
    for(int i=0;i<n;i++)
    {
        string str;
        cin>>str;
        s.push_back(str);
    }
   string march="MARCH";
    map<char,int> m;
    for(auto i:s)
    {
       if(string::npos!=march.find(i[0],0))
       m[i[0]]++;
    }
    int ans=0;
    for(int i=0;i<march.size()-2;i++)
    for(int j=i+1;j<march.size()-1;j++)
    for(int k=j+1;k<march.size();k++)
    ans+=m[march[i]]*m[march[j]]*m[march[k]];
    cout<<ans<<endl;
}

Measured memory_bytes: 7400
#include <algorithm>
#include <iostream>
#include <set>
#include <vector>

using namespace std;

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

    int d;
    while (cin >> d && d) {
        int n, m;
        cin >> n >> m;
        vector<int> S;
        S.push_back(0);
        S.push_back(-d);
        S.push_back(d);
        int di;
        for (int i=2; i<=n; ++i) {
            cin >> di;
            S.push_back(di);
            S.push_back(di - d);
            S.push_back(di + d);
        }
        sort(S.begin(), S.end());
        long long sum = 0;
        int ki;
        for (int i=1; i<=m; ++i) {
            cin >> ki;
            auto it = lower_bound(S.begin(), S.end(), ki);
            int add = abs(ki - *it);
            if (it != S.begin()) {
                -- it;
                add = min(add, abs(ki - *it));
            }
            sum += add;
        }
        cout << sum << endl;
    }

    return 0;
}

Measured memory_bytes: 3176
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<utility>


#define rep(i,x) for(int i=0;i<(int)(x);i++)
#define reps(i,x) for(int i=1;i<=(int)(x);i++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(int i=((int)(x));i>0;i--)

#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define INF 2e9

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; }
typedef long long ll;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

using namespace std;

vector<ll> S, T;

bool binary_search(ll d)
{
    int l = 0;
    int h = S.size()-1;
    if(S[l]==d || S[h]==d) return true;

    int flag = 0;
    while(1){
        int m = (l + h)/2;
        if(d==S[m]) return true;
        if(d>S[m]){
            l = m;
        }
        if(d<S[m]){
            h = m;
        }
        if(h-1<=l) break;
    }
    return false;  
}

int main()
{
    int n, q;
    cin >> n;
    S.resize(n);
    rep(i, n) cin >> S[i];
    cin >> q;
    T.resize(q);
    rep(i, q) cin >> T[i];
    ll cnt = 0;
    rep(i, T.size()){
        ll d = T[i];
        if(binary_search(d)) cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 3788
import copy
n,m=map(int,input().split())
a=[[0 for _ in range(m+3)] for _ in range(n+2)]
a[0][0]=1
a[1][2]=1
for i in range(1,n):
  b=copy.deepcopy(a)
  for j in range(0,i+2):
    for k in range(0,m+1):
      if k>=2*j:
        a[j][k]=(2*j+1)*b[j][k-2*j]+(j+1)**2*b[j+1][k-2*j]
        if j>0:
          a[j][k]+=b[j-1][k-2*j]
        a[j][k]%=(10**9+7)
      else:
        a[j][k]=0
print(a[0][m])

Measured memory_bytes: 121308
#include <iostream>

using namespace std;

int main() {
	long long int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;
	for (int i = sx; i < tx; i++) {
		cout << 'R';
	}
	for (int i = sy; i <= ty; i++) {
		cout << 'U';
	}
	for (int i = tx; i >= sx; i--) {
		cout << 'L';
	}
	for (int i = ty; i >= sy; i--) {
		cout << 'D';
	}
	cout << 'R';
	cout << 'D';
	for (int i = sx; i <= tx; i++) {
		cout << 'R';
	}
	for (int i = sy; i <= ty; i++) {
		cout << 'U';
	}
	for (int i = tx; i >= sx; i--) {
		cout << 'L';
	}
	for (int i = ty; i > sy; i--) {
		cout << 'D';
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<map>
#include<utility>
#include<string>
#include<unordered_map>
#include<queue>

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

using namespace std;

#define min_3(a, b, c) min(a, min(b, c))
#define max_3(a, b, c) max(a, max(b, c))
typedef long long ll;
typedef pair<int, int> P;

int main(){
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        int a; cin >> a;
        if(a % 2 == 0){
            if(a % 3 != 0 && a % 5 != 0){
                cout << "DENIED" << endl;
                return 0;
            }
        }
    }

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


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

using i32 = int_fast32_t;
using i64 = int_fast64_t;

int main() {
    i32 x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector<i32> p(a), q(b), r(c);
    for (auto& e : p) cin >> e;
    for (auto& e : q) cin >> e;
    for (auto& e : r) cin >> e;
    sort(begin(p), end(p), greater<>());
    sort(begin(q), end(q), greater<>());
    sort(begin(r), end(r), greater<>());
    
    vector<i32> apple;
    for (i32 i = 0; i < x; i++) apple.push_back(p[i]);
    for (i32 i = 0; i < y; i++) apple.push_back(q[i]);
    for (i32 i = 0; i < min(x+y, c); i++) apple.push_back(r[i]);
    sort(begin(apple), end(apple), greater<>());

    cout << accumulate(begin(apple), begin(apple) + x + y, 0l) << endl;
}


Measured memory_bytes: 8560
import sys
from io import StringIO
import unittest


def resolve():
    # 整数 1 つ
    # n = int(input())
    # 整数複数個
    n, k = list(map(int, input().split()))
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    L = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    # A = [list(map(int, input().split())) for i in range(H)]

    Lsort = sorted(L, reverse=True)
    re = 0
    for i in range(k):
        re += Lsort[i]

    print(re)
resolve()

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

int main(void){
  int n, d;
  cin >> n >> d;
  if(n%(2*d+1) == 0){
    cout << n/(2*d+1) << endl;
  } else{
    cout << n/(2*d+1)+1 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
#define debug(x) std::cerr << #x << " = " << (x) << std::endl
typedef long long LL;
const int MAXN = 1e5+17;
vector<int > G[MAXN];
bool in[MAXN];
int main(int argc ,char const *argv[])
{
    #ifdef noob
    freopen("Input.txt","r",stdin);freopen("Output.txt","w",stdout);
    #endif
    int a,b,c,ans=0;
    cin>>a>>b>>c;
    while(a%2==0&&b%2==0&&c%2==0)
    {
    	int x = a,y=b,z=c;
    	a = (y+z)/2;
    	b = (x+z)/2;
    	c = (x+y)/2;
    	// debug(a);
    	// debug(b);
    	// debug(c);
    	ans++;
    	if(ans>1e6)
    	{
    		ans = -1;
    		break;
    	}
    }
    cout<<ans<<endl;
    return 0;        
}

Measured memory_bytes: 2560
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE RankNTypes #-}
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
-- import Data.List
-- import qualified Data.Vector.Unboxed as VU
-- import qualified Data.Vector.Unboxed.Mutable as VUM
-- import Control.Monad
-- import Control.Monad.ST
-- import Debug.Trace
-- trace _ = id

solve :: Int -> Int -> String
solve n k = if n >= 2*k-1 then "YES" else "NO"

readBInt :: B.ByteString -> Int
readBInt = fst . fromJust . B.readInt

tmain :: B.ByteString -> String
tmain cont =
  let remLines0 = map B.words (B.lines cont)
      [bs_n,bs_k]:remLines1 = remLines0
      n = readBInt bs_n
      k = readBInt bs_k
  in solve n k

outAnswer :: String -> IO ()
outAnswer = putStrLn

main :: IO ()
main = outAnswer . tmain =<< B.getContents


-------------------------------------------------------------------------------

inp1 = "3 2\n"
inp2 = "5 5\n"
inp3 = "31 10\n"
inp4 = "10 90\n"
tv1 = tmain $ B.pack inp1
tv2 = tmain $ B.pack inp2
tv3 = tmain $ B.pack inp3
tv4 = tmain $ B.pack inp4
test1 = tv1 == "YES"
test2 = tv2 == "NO"
test3 = tv3 == "YES"
test4 = tv4 == "NO"
alltest = test1 && test2 && test3 && test4



Measured memory_bytes: 380
from sys import stdin
def solve():
    import collections
    readline = stdin.readline
    h,w = map(int,readline().split())
    si,sj = map(int,readline().split())
    gi,gj = map(int,readline().split())
    si,sj,gi,gj = si-1,sj-1,gi-1,gj-1
    grid = []
    for _ in [0]*h:
        grid.append(readline()[:-1])
    INF = float("inf")
    dist = [[INF]*w for _ in range(h)]
    q = collections.deque([(si,sj)])
    dist[si][sj] = 0
    while q:
        i,j = q.popleft()
        if (i,j) == (gi,gj):
            return dist[i][j]
        for ni,nj in [(i+1,j),(i-1,j),(i,j+1),(i,j-1)]:
            if 0 <= ni and ni < h and 0 <= nj and nj < w and grid[ni][nj] == ".":
                if dist[ni][nj] > dist[i][j]:
                    dist[ni][nj] = dist[i][j]
                    q.appendleft((ni,nj))
        listj = range(j-2,j+3)
        for ni in range(i-2,i+3):
            if not (0 <= ni and ni < h): continue
            for nj in listj:
                if not (0 <= nj and nj < w): continue
                if grid[ni][nj] == "." and dist[ni][nj] > dist[i][j] + 1:
                    dist[ni][nj] = dist[i][j] + 1
                    q.append((ni,nj))

    return -1

print(solve())

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

using namespace std;

/*
	UNITY_NODE sumの単位元
	UNITY_LAZY updateの単位元
	nodeの初期値に注意(init)
	addの呼び出し元に注意(区間の長さに比例する)
	上の関係でUNITY_LAZY / 2も単位元とみなしている
*/
template <class NODE, class LAZY, NODE UNITY_NODE, LAZY UNITY_LAZY>
struct LazySegTree {
// edit start
	void add(LAZY &a, LAZY b) {
		if (b == UNITY_LAZY || b == UNITY_LAZY / 2) return;
		a = b;
	}
	void reflect(NODE& a, LAZY b, int l, int r) {
		if (b == UNITY_LAZY || b == UNITY_LAZY / 2) return;
		a = b;
	}
	NODE merge(NODE a, NODE b) {
		return a + b;
	}
// end
	int n;
	vector<NODE> node;
	vector<LAZY> lazy;
	LazySegTree(int sz) {
		init(sz);
	}
	void init(int sz) {
		n = 1;
		while (n < sz) n *= 2;
		node.assign(2*n-1, 0);
		lazy.assign(2*n-1, UNITY_LAZY);
	}
	void eval(int l, int r, int k) {
		reflect(node[k], lazy[k], l, r);
		if (r - l > 1) {
			add(lazy[k*2+1], lazy[k] / 2);
			add(lazy[k*2+2], lazy[k] / 2);
		}
		lazy[k] = UNITY_LAZY;
	}
	void renode(int k) {
		node[k] = merge(node[k*2+1], node[k*2+2]);
	}
	void set(int a, int b, LAZY x, int k=0, int l=0, int r=-1) {
		if (r < 0) r = n;
		if (b <= l || r <= a) {
			eval(l, r, k);
		} else if (a <= l && r <= b) {
			add(lazy[k], x * (r - l));
			eval(l, r, k);
		} else {
			eval(l, r, k);
			set(a, b, x, k*2+1, l, (l+r) / 2);
			set(a, b, x, k*2+2, (l+r) / 2, r);
			renode(k);
		}
	}
	NODE get(int a, int b, int k=0, int l=0, int r=-1) {
		if (r < 0) r = n;
		eval(l, r, k);
		if (b <= l || r <= a) {
			return UNITY_NODE;
		} else if (a <= l && r <= b) {
			return node[k];
		} else {
			NODE t1 = get(a, b, 2*k+1, l, (l+r) / 2);
			NODE t2 = get(a, b, 2*k+2, (l+r) / 2, r);
			renode(k);
			return merge(t1, t2);
		}
	}
};

int main(){
	int n, q;
	cin >> n >> q;
	LazySegTree<long long, long long, 0, LLONG_MAX> L(n);
	while (q--) {
		int a, s, t, x;
		cin >> a >> s >> t;
		if (a == 0) {
			cin >> x;
			L.set(s, t+1, x);
		} else {
			cout << L.get(s, t+1) << endl;
		}
	}
}



Measured memory_bytes: 7084
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int P = 1e9 + 7;
inline void pp(int &x,int d){if((x+=d)>=P)x-=P;}

typedef vector<vi> MM;
MM operator * (const MM a,const MM b){
  int L = sz(a);MM r(L,vi(L,0));
  rep(i,0,L) rep(j,0,L) rep(k,0,L) pp(r[i][j] , ll(a[i][k]) * b[k][j] % P);
  return r;
}
MM operator ^ (MM a,ll t){
  int L = sz(a);MM r(L,vi(L,0));
  rep(i,0,L) r[i][i] = 1;
  for(;t;t>>=1,a=a*a) if(t&1) r=r*a;
  return r;
}
const int N = 1e5 + 10;
int n , m , x[N];

int main(){
  scanf("%d%d",&n,&m);
  rep(i,1,m+1) scanf("%d",x+i);
  MM limit{
    {1,2,1},
    {0,1,1},
    {0,0,1}
  };
  MM nolimit{
    {2,2,1},
    {1,1,1},
    {1,0,1}
  };
  MM A(3,vi(3,0));
  rep(i,0,3) A[i][i]=1;
  rep(i,1,m+1) {
    A = A * (nolimit ^ (x[i] - x[i-1] - 1));
    A = A * limit;
  }
  A = A * (nolimit ^ (n - x[m]));
  printf("%d\n",A[0][2]);
  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a),i##_end=(b);i<=i##_end;++i)
#define per(i,a,b) for(int i=(b),i##_end=(a);i>=i##_end;--i)
#define For(i,a,b) for(int i=(a),i##_end=(b);i<i##_end;++i)
#define foe(i,a) for(__typeof(a.begin())i=a.begin();i!=a.end();++i)
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
typedef double ld;
typedef long long L;
typedef vector<int> vi;
typedef pair<int,int> pa;
const int N=2e5+11,P=1e9+7;
int f[N],pr[N];
int n,a[N];

int main(){
	cin>>n;
	int x,m=0;
	rep(i,1,n){
		cin>>x;
		if(x!=a[m]){
			a[++m]=x;
			f[m]=(f[m-1]+f[pr[x]])%P;
			pr[x]=m;
		}
		f[1]=1;
	}
	cout<<f[m];
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e14;
const int ZERO = 0;
const int MOD = 1000000007;
const double PI = 3.1415926535897;

signed main() {
    int N;
    cin >> N;
    vector<int> vec(N);
    for(int i = 0;i < N;i++) {
        cin >> vec.at(i);
    }
    int cnt = 1;
    for(int i = 0;i < N;i++) {
        if(vec.at(i) == cnt) {
            cnt++;
        }
    }
    if(cnt == 1) {
        cout << -1 << endl;
    }
    else {
        cout << N - (cnt - 1) << endl;
    }
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 1e18;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

ll power(ll x, ll y) {
	if (y==0) return 1;
	else if (y==1) return x%MOD;
	else if (y%2==0) { ll pow=power(x,y/2); return (pow*pow)%MOD; } 
	else { ll pow=power(x,y/2); return ((pow*pow)%MOD)*x%MOD; }
}
ll divid(ll x, ll y) {
	return ((x%MOD)*power(y,MOD-2))%MOD;
}

int main(){
	int n, k; cin >> n >> k;
	VI a(n); REP(i,n) cin >> a[i];
	sort(ALL(a),[](auto const& l, auto const& r){return abs(l)>abs(r);});
	bool m=0; ll ans=1;
	ll lastp=0, lastm=0;
	REP(i,k){
		ans*=abs(a[i]);
		ans%=MOD;
		if(a[i]<0){
			m=!m;
			lastm=a[i];
		}
		else{
			lastp=a[i];
		}
	}
	if(!m||ans==0)
		cout << ans << endl;
	else{
		long double pp=0, mm=0;
		ll np=0, nm=0;
		if(lastp!=0){
			for(int i=k;i<n;i++){
				if(a[i]<0){
					pp=(long double)(-a[i])/lastp;
					np=-a[i];
					break;
				}
			}
		}
		if(lastm!=0){
			for(int i=k;i<n;i++){
				if(a[i]>0){
					mm=(long double)a[i]/(-lastm);
					nm=a[i];
					break;
				}
			}
		}
		if(nm==0&&np==0){
			ans=1;
			REP(i,k){
				ans*=abs(a[n-1-i]);
				ans%=MOD;
			}
			ans=MOD-ans;
			ans%=MOD;
		}
		else{
			if(pp<mm){
				ans=divid(ans,-lastm);
				ans*=nm;
			}
			else{
				ans=divid(ans,lastp);
				ans*=np;
			}
			ans%=MOD;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 4852
#include<bits/stdc++.h>
using namespace std;
#define inf 100000000000000000
#define ll long long 
#define pb push_back
#define f first
#define s second
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define test ll t ; cin>>t; while(t--)
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}
int main(){
	//mahakal(),fast;
	
	ll n , k ;
	cin>>n>>k ;
	string str;
	cin>>str;
	ll arr[k+1]={0};
	ll ans = 0 , ten=1; 
	ll a=0;
	if(k==2 || k==5){
		for(ll i=0;i<n ;i++){
			if((str[i]-'0')%k==0){
				ans += i+1;
			}
		}
		cout<<ans<<endl;
		return 0;
	}
	for(ll i=n-1;i>=0 ; i--){
		a+=((str[i]-'0')*ten);
		a=a%k ;
		arr[a%k]++;
		ten=(ten*10)%k;
	}
	for(ll i=0;i<k ; i++){
		if(arr[i]>1)
		ans+=(arr[i]*(arr[i]-1))/2;
	}
	ans += arr[0];
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 644
#include<stdio.h>
    int main()
    {
        char S[4],n[4];
        int i,j=0;
      
        scanf("%s%s",S,n);
      
        for(i=0;i<3;i++){
          if(S[i]==n[i]) j++;
        }
          
        printf("%d\n",j);}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define pii pair<int,int>
#define reset(x,n) memset((x),(n),sizeof(x))
#define all(n) (n).begin(),(n).end()
#define pb push_back
#define IOS ios::sync_with_stdio(0),cin.tie(0);
ll dp[3005][3005];
string ans;
string a,b;
void dfs(int x,int y){
	if(!x||!y)return;
	if(a[x]==b[y]){
		ans+=a[x];
		dfs(x-1,y-1);
	}
	else{
		if(dp[x-1][y]>dp[x][y-1]){
			dfs(x-1,y);
		}
		else dfs(x,y-1);
	}
}
int main(){
	cin>>a>>b;
	int siza=a.size(),sizb=b.size();
	a="%"+a;
	b="$"+b;
	for(int i=1;i<=siza;i++){
		for(int j=1;j<=sizb;j++){
			if(a[i]==b[j]){
				dp[i][j]=dp[i-1][j-1]+1;
			}
			else{
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
			}
		}
	}
	//cout<<dp[siza][sizb]<<'\n';
	dfs(siza,sizb);
	reverse(all(ans));
	cout<<ans<<'\n';
}


Measured memory_bytes: 70656
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

template<typename T> T minimum(T head, T tail) { return std::min(head, tail); }
template<typename Head, typename... Tail> Head minimum(Head head, Tail... tail) {
  return std::min(head, minimum(tail...));
}

template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  ll i = 0;
  for (auto x : v){os << " [" << i++ << "]" << x; if (i % 5 == 0) os << std::endl;}
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::vector< std::pair<T, S> > vp)
{
  ll i = 0;
  for (auto p : vp){os << " [" << i++ << "]" << p.first << " " << p.second; if (i % 5 == 0) os << std::endl;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

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

  //std::ostringstream oss;
  //oss << "ABC" << N;
  //std::string ans = oss.str();

  ll H = 2;
  ll W = 3;
  std::vector< std::string > grid (H, std::string(W, 'x'));
  std::vector< std::string > grid2(H, std::string(W, 'x'));
  for (ll y = 0; y < H; y++) {
    for (ll x = 0; x < W; x++) {
      std::cin >> grid[y][x];
    }
  }

  for (ll y = 0; y < H; y++) {
    grid2[y] = grid[H-y-1];
    std::reverse(grid2[y].begin(), grid2[y].end());
  }

  bool judge = true;
  for (ll y = 0; y < H; y++) {
    for (ll x = 0; x < W; x++) {
      if (grid[y][x] != grid2[y][x]) judge = false;
    }
  }

  if (judge == true) print("YES");
  else print("NO");

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int l = sc.nextInt() + sc.nextInt();
		int r = sc.nextInt() + sc.nextInt();
		if(l > r) {
			System.out.println("Left");
		}else if(l < r){
			System.out.println("Right");
		}else {
			System.out.println("Balanced");
		}
		sc.close();
	}
}

Measured memory_bytes: 21716
def main():
    n = int(input())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    move = sum(b)-sum(a)
    if move<0:
        print("No")
        return 0
    amove = 0
    bmove = 0
    for i in range(n):
        if a[i] < b[i]:
            amove += (b[i]-a[i]+1)//2
            bmove += (b[i]-a[i])%2
        elif a[i] > b[i]:
            bmove += a[i]-b[i]
    if max(amove,bmove) <= move:
        print("Yes")
    else:
        print("No")

main()


Measured memory_bytes: 4596
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, w, n) for(int i = w; i < n; i++)
#define all(a) a.begin(), a.end()
#define SORT(a) sort(all(a))

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;}
const long long INF = 1LL << 60;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout<<fixed<<setprecision(15);
    
    int a, b, c; cin >> a >> b >> c;
    int ans = 0;
    for(int i = a; i <= b; i++) {
        if(c % i == 0) ans++;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3212
#include <stdio.h>
int main()
{
  int n,f=0,s=0,t=0,i;
  for(i=0;i<3;i++){
    scanf("%d",&n);
    if(n>f){
      t=s;
      s=f;
      f=n;
    }
    else if(n>s){
      t=s;
      s=n;
    }
    else t=n;
  }
  printf("%d %d %d\n",t,s,f);
  return 0;
}

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

using namespace std;

int NumWin(const auto &you, const auto &me, size_t pass) {
    int res = 0;
    for (size_t i = 0, j = 0; i < you.size() && j < me.size(); ) {
        if (j != pass && you[i] < me[j]) { ++res; ++i; }
        ++j;
    }
    return res;
}

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

    int n;
    cin >> n;

    vector<int> you(n), me(n);
    for (auto &&x : you) cin >> x;
    for (auto &&x : me) cin >> x;

    vector<int> ord(you);
    sort(you.begin(), you.end());
    sort(me.begin(), me.end());

    int max_win = NumWin(you, me, n);

    vector<int> ans; ans.reserve(n);
    for (const int x : ord) {
        for (size_t i = 0; i + 1 < you.size(); ++i)
            if (you[i] == x) swap(you[i], you[i + 1]);
        you.pop_back();

        int lb = 0, ub = me.size();
        int idx = distance(me.begin(), lower_bound(me.begin(), me.end(), x + 1));
        if (idx == ub || (x < me[idx]) + NumWin(you, me, idx) != max_win) ub = idx;
        else lb = idx;

        while (1 < ub - lb) {
            int mid = (lb + ub) >> 1;
            if ((x < me[mid]) + NumWin(you, me, mid) == max_win) lb = mid;
            else ub = mid;
        }

        if (x < me[lb]) --max_win;
        ans.push_back(me[lb]);
        for (size_t i = 0; i + 1 < me.size(); ++i)
            if (me[i] == ans.back()) swap(me[i], me[i + 1]);
        me.pop_back();
    }

    for (int i = 0; i < n; ++i)
        cout << ans[i] << " \n"[i == n - 1];

    return 0;
}



Measured memory_bytes: 3264
from fractions import gcd

n, m = [int(i) for i in input().split()]
S = input()
T = input()

g = n * m // gcd(n, m)

SA = set()
SB = set()

for i in range(0, g, g//n):
    SA.add(i)

for i in range(0, g, g//m):
    SB.add(i)

SC = SA & SB

for s in SC:
    if S[s//(g//n)] != T[s//(g//m)]:
        print(-1)
        exit()

print(g)

Measured memory_bytes: 19164
n=input()
clear=0
if n[:1]=='A' and n.find('C',n.find('C')+1)==-1 and n.find('C') >1 and n.find('C') <len(n)-1:
    n=n.replace('A','')
    n=n.replace('C','')
    if n.islower()==True:
        clear=1
if clear==1:
    print('AC')
else:
    print('WA')

Measured memory_bytes: 3060
class UnionFind():
    # 作りたい要素数nで初期化
    def __init__(self, n):
        self.n = n
        self.root = [-1]*(n+1)
        self.rnk = [0]*(n+1)

    # ノードxのrootノードを見つける
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]
    
    # 木の併合、入力は併合したい各ノード
    def Unite(self, x, y):
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        if(x == y):
            return 
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    # ノードxが属する木のサイズ
    def Count(self, x):
        return -self.root[self.Find_Root(x)]


N, M = map(int, input().split())
uni = UnionFind(N)
for _ in range(M):
    a, b = map(int, input().split())
    uni.Unite(a-1, b-1)

ans = 0
for i in range(N):
    ans = max(ans, uni.Count(i))
print(ans)

Measured memory_bytes: 14556
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

ll MOD = 1000000007;

ll absdif(ll x, ll y){
  ll ret;

  if(x - y >= 0){
    ret = x - y;
  } else{
    ret = y - x;
  }

  return ret;
}

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

  ll A;
  map<ll, ll> cnt;
  rep(i, N){
    cin >> A;
    cnt[A]++;
  }

  ll ans = 1;

  rep(i, N){
    ans = (ans * cnt[absdif(N - 1 - i, i)]) % MOD;
    cnt[absdif(N - 1 - i, i)]--;
  }

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

Measured memory_bytes: 5376
#include <cstdio>
#include <algorithm>
#include <tr1/unordered_map>

std::tr1::unordered_map<int,int> f;
int n, ans, a[200005], b[35];

int read() {
	int x = 0; char c = getchar();
	while (c < '0' || c > '9') c = getchar();
	while (c >= '0' && c <= '9') {
		x = (x << 3) + (x << 1) + (c ^ 48);
		c = getchar();
	}
	return x;
}

int main() {
	n = read();
	for (int i = 1; i <= n; ++i) a[i] = read(), ++f[a[i]];
	std::sort(a + 1, a + n + 1);
	for (int i = 1, j = 0; j <= 30; ++j) {
		while (a[i] <= 1 << j && i < n) ++i;
		b[j] = i;
	}
	for (int j = 30, i = 1 << j; ~j; --j, i = 1 << j) {
		for (int k = b[j]; k >= 1; --k)
			if ((a[k] != i - a[k] && f[a[k]] && f[i-a[k]]) || (a[k] == i - a[k] && f[a[k]] > 1)) ++ans, --f[a[k]], --f[i-a[k]];
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 29556
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 998244353
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

// code credit : https://github.com/niklasb/contest-algos/
// blob/master/convex_hull/dynamic.cpp
using line_t = long double;
const line_t is_query = -1e100;

struct Line {
	line_t m, b;
	mutable function<const Line*()> succ;
	bool operator<(const Line& rhs) const {
		if (rhs.b != is_query) return m < rhs.m;
		const Line* s = succ();
		if (!s) return 0;
		line_t x = rhs.m;
		return b - s->b < (s->m - m) * x;
	}
};

struct HullDynamic : public multiset<Line> { // will maintain upper hull for maximum
	bool bad(iterator y) {
		auto z = next(y);
		if (y == begin()) {
			if (z == end()) return 0;
			return y->m == z->m && y->b <= z->b;
		}
		auto x = prev(y);
		if (z == end()) return y->m == x->m && y->b <= x->b;
		return (x->b - y->b)*(z->m - y->m) >= (y->b - z->b)*(y->m - x->m);
	}
	void insert_line(line_t m, line_t b) {
		auto y = insert({ m, b });
		y->succ = [=] { return next(y) == end() ? 0 : &*next(y); };
		if (bad(y)) { erase(y); return; }
		while (next(y) != end() && bad(next(y))) erase(next(y));
		while (y != begin() && bad(prev(y))) erase(prev(y));
	}
	line_t query(line_t x) {
		Line u = { x, is_query };
		auto l = *lower_bound(u);
		return l.m * x + l.b;
	}
}* solver;

long long a[200005];
long long dp[200005];
ll C;
int n;

int main(void) {

    scanf("%d%lld", &n,&C);
    for (int i = 1; i <= n; i++)
        scanf("%lld", &a[i]);
    dp[1] = 0;
    solver = new HullDynamic();
    solver->insert_line((long double)(2LL*a[1]),(long double)(dp[1]-a[1]*a[1]));
    for(int i=2;i<=n;i++){
    	dp[i] = floor(solver->query(a[i])+0.3)-C-a[i]*a[i];
    	solver->insert_line((long double)(2LL*a[i]),(long double)(dp[i]-a[i]*a[i]));
	}
	printf("%lld\n", -dp[n]);
    return 0;
}

Measured memory_bytes: 25216
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
using ll = long long;
using namespace std;
//LLONG_MAX = 90^18
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No"); }
void Yes() { cout << "Yes"; }
void No() { cout << "No"; }

int N, M, Q;
int A[100];
int B[100];
int C[100];
int D[100];

int ary[11];
int ans = 0;

void func(int depth, int n)
{
	if (depth == N)
	{
		int sum = 0;
		for (int i = 0; i < Q; i++)
		{
			if (ary[B[i] - 1] - ary[A[i] - 1] == C[i])
			{
				sum += D[i];
			}
		}
		ans = max(ans, sum);

		return;
	}

	for (int i = n; i <= M; i++)
	{
		ary[depth] = i;
		func(depth + 1, i);
	}
}

signed main()
{
	cin >> N >> M >> Q;
	REP(i, Q)
	{
		cin >> A[i] >> B[i] >> C[i] >> D[i];
	}

	func(0, 1);

	cout << ans << endl;
}





Measured memory_bytes: 3636
n = int(input())

fib = [0] * 45

for i in range(len(fib)):
    if i == 0 or i == 1:
        fib[i] = 1
    else:
        fib[i] = fib[i-1] + fib[i-2]

    if i == n:
        print(fib[i])
        break



Measured memory_bytes: 5600
n = int(input())
List = list(map(int, input().split()))
denied_point = 0
List_even = [i for i in List if i % 2 == 0]

# print(List_even)
for i in List_even:
    if (i % 3) != 0 and (i%5 != 0):
        denied_point = denied_point + 1


if denied_point ==0 :
    print('APPROVED')
else:
    print('DENIED')







Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <array>
#include <cstdint>
#include <functional>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <vector>

#define PD(x) printf("%d",x)
#define PL(x) printf("%lld",x)
#define PC(x) printf("%c",x)
#define PS(x) printf("%s",x)
#define PF(x) printf("%f",x)
#define SP printf(" ")
#define BR printf("\n")
#define INF 1000000000
#define MOD 1000000007
#define ll long long
#define rep(i,a,b) for(int i = (a); i < (b); ++i)
#define bitget(a,b) (((a) >> (b)) & 1)
#define vint vector<int>
#define ALL(x) (x).begin(),(x).end()
#define scanf scanf_s

using int32 = int_fast32_t;
using int64 = int_fast64_t;
using uint32 = uint_fast32_t;
using uint64 = uint_fast64_t;

using namespace std;
int main() {
	int h, w;
	cin >> h >> w;
	uint64 c[10][10];
	rep(i, 0, 10) {
		rep(j, 0, 10) {
			cin >> c[i][j];
		}
	}
	int a[200][200];
	rep(i, 0, h) {
		rep(j, 0, w) {
			cin >> a[i][j];
		}
	}
	rep(k, 0, 10) {
		rep(i, 0, 10) {
			rep(j, 0, 10) {
				if (c[i][j] > c[i][k] + c[k][j]) {
					c[i][j] = c[i][k] + c[k][j];
				}
			}
		}
	}
	uint64 ans = 0;
	rep(i, 0, h) {
		rep(j, 0, w) {
			if (a[i][j] != -1) {
				ans += c[a[i][j]][1];
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define MOD 1000000007
#define INF 1000000000
#define LLINF 1e18

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_abc_e() {
	ll n, m, l;
	cin >> n >> m;

	V a(m), b(m), c(m);
	rep(i, m) {
		cin >> a[i] >> b[i];
		ll tmp = 0;
		rep(j, b[i]) {
			cin >> tmp;
			c[i] |= 1 << (tmp - 1);
		}
	}

	V dp(1 << n, LLINF);
	dp[0] = 0;

	rep(i, 1 << n) {
		rep(j, m) {
			ll t = i | c[j];
			ll cost = dp[i] + a[j];
			chmin(dp[t], cost);
		}
	}

	if (dp[(1 << n) - 1] != LLINF) {
		cout << dp[(1 << n) - 1] << "\n";
	}
	else {
		cout << -1 << "\n";
	}
}

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

	solve_abc_e();

	return 0;
}

Measured memory_bytes: 3680
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
 
MAXN = 1005
MAXV = MAXN*(MAXN-1)//2
 
to = [[] for _ in range(MAXV)]
id = [[[] for _ in range(MAXN)] for _ in range(MAXN)]
 
def toId(i, j):
    if i > j:
        i, j = j, i
    return id[i][j]
visited = [False] * MAXV
calculated = [False] * MAXV
dp = [1] * MAXV
 
def dfs(v):
    if visited[v]:
        if not calculated[v]:
            return -1
        return dp[v]
    visited[v] = True
    dp[v] = 1
 
    for u in to[v]:
        res = dfs(u)
        if res == -1: return -1
        dp[v] = max(dp[v], res+1)
    calculated[v] = True
    return dp[v]
 
def main():
    n = int(input())
    a = [[int(i) for i in readline().split()] for _ in range(n)]
    
    for i in range(n):
        for j in range(n-1):
            a[i][j] -= 1
    V = 0
    for i in range(n):
        for j in range(n):
            if i < j:
                id[i][j] = V
                V += 1
    
    for i in range(n):
        for j in range(n-1):
            a[i][j] = toId(i, a[i][j])
        for j in range(n-2):
            to[a[i][j+1]].append(a[i][j])
    
    ans = 0
    
    for i in range(V):
        res = dfs(i)
        if res == -1:
            print('-1')
            return
        ans = max(ans, res)
    print(ans)
    return
  
if __name__ == '__main__':
    main()

Measured memory_bytes: 177520
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int[] a = new int[3];

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

			a[i] = sc.nextInt();
		}

		int temp = 0;

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

			for(int j=i;j<3;j++) {

				if(a[i]>a[j]) {

					temp = a[i];

					a[i] = a[j];

					a[j] = temp;
				}
			}
		}


		int ans = 0;

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

			ans += (a[i+1]-a[i]);

		}

		System.out.println(ans);

	}

}


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

using namespace std;


int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m, e;
  cin >> n >> m >> e;
  vector<string> g(n);
  for (int i = 0; i < n; i++) {
    cin >> g[i];
  }
  int ans = 0;
  for (int mask_r = 0; mask_r < (1 << n); mask_r++) {
    for (int mask_c = 0; mask_c < (1 << m); mask_c++) {
      int d = 0;
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
          if ((mask_r & (1 << i)) && (mask_c & (1 << j)) && g[i][j] == '#') {
            d += 1;
          }
        }
      }
      if (d == e) {
        ans += 1;
      }
    }
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h> 
int n,mod1=0,mod2,md1[200010],md2[200010],res1=0,res2=0,sa;
char s[200010];
void ru(int n)
{
	while (n>0)
	{
		int q=n,p=0;
		while (q>0)
		{
			q=q&(q-1);
			p++;
		}
		n=n%p;
		sa++;
	}
}
int main()
{
	scanf("%d",&n);
	scanf("%s",&s);
	for (int i=0;i<n;i++) if (s[i]=='1') mod1++;
	mod2=mod1-1,mod1++;
	if (mod2==0)
	{
		md1[n-1]=md2[n-1]=1;
		for (int i=n-2;i>=0;i--) md1[i]=md1[i+1]*2%mod1;
		for (int i=n-1;i>=0;i--) if (s[i]=='1') res1=(res1+md1[i])%mod1;
		for (int i=0;i<n;i++)
		{
			if (s[i]=='1') printf("0\n");
			if (s[i]=='0')
			{
				sa=1;
				int ss=(res1+md1[i])%mod1;
				//printf("%d\n",ss);
				ru(ss);
				printf("%d\n",sa);
			}
		}
		return 0;
	}
	md1[n-1]=md2[n-1]=1;
	for (int i=n-2;i>=0;i--) md1[i]=md1[i+1]*2%mod1,md2[i]=md2[i+1]*2%mod2;
	for (int i=n-1;i>=0;i--) if (s[i]=='1') res1=(res1+md1[i])%mod1,res2=(res2+md2[i])%mod2;
	for (int i=0;i<n;i++)
	{
		if (s[i]=='1')
		{
			sa=1;
			int ss=(res2-md2[i]+mod2)%mod2;
			//printf("%d\n",ss);
			ru(ss);
			printf("%d\n",sa);
		}
		if (s[i]=='0')
		{
			sa=1;
			int ss=(res1+md1[i])%mod1;
			//printf("%d\n",ss);
			ru(ss);
			printf("%d\n",sa);
		}
	}
	return 0;
}

Measured memory_bytes: 5464
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
using ll=long long;
using namespace std;
//const int INF = 7+(1e+9);
ll GCD(ll x, ll y)
{
    if (y == 0)
    {
        return x;
    }
    else
    {
        return GCD(y, x % y);
    }
}
ll LCM(ll x, ll y)
{
    return x / GCD(x, y) * y;
}
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

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

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

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

int dx[]={0,-1,0,1};
int dy[]={1,0,-1,0};
int dfs(int y,int x){
    vec[y][x]='5';
    for(int i=0;i<4;i++){
        if(x+dx[i]<12&&x+dx[i]>=0&&y+dy[i]<12&&y+dy[i]>=0&&vec[dy[i]+y][dx[i]+x]=='1'){
            dfs(y+dy[i],x+dx[i]);
        }
    }
    return 0;
}

int main(){
    while(1){
        ll n,k;
        cin>>n>>k;
        if(n==0&&k==0)break;
        vector<bool> vec(n+1,false);
        vector<ll> vec1(k);
        bool h=false;
        for(ll i=0;i<k;i++){
            ll x;cin>>x;
            if(x==0){
                h=true;
                continue;
            }
            vec[x]=true;
          //  cout<<x<<endl;
            vec1[i]=x;
        }
    //    sort(vec.begin(),vec.end());
        sort(vec1.begin(),vec1.end());
        vector<vector<ll>> dp(n+1,vector<ll>(2));
        if(!h){
            ll c=1;
            ll res=0;
            for(ll i=0;i<k;i++){
            //    cout<<vec1[i]<<" "<<vec1[i+1]<<endl;
                if(vec1[i]+1==vec1[i+1]){
                    c++;
                }else{
                    res = max(res,c);
                    c=1;
                }
            }
            res=max(res,c);
            cout<<res<<endl;
            continue;
        }
        ll MAX=0;
        for(ll i=1;i<=n;i++){
       //     cout<<i<<" "<<vec[i]<<endl;
            if(!vec[i]){
                dp[i][1]=dp[i-1][0]+1;
                dp[i][0]=0;
                
              //  cout<<i<<endl<<endl;
            }else{
                dp[i][0]=dp[i-1][0]+1;
                dp[i][1]=dp[i-1][1]+1;
            }
            MAX=max({dp[i][0],dp[i][1],MAX});
         //   cout<<dp[i][0]<<" "<<dp[i][1]<<endl;
        }
        cout<<max(MAX,dp[n][0]+1)<<endl;
    }
}


Measured memory_bytes: 8944
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e9
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

template <typename T, class F = function<T(const T&, const T&)>>
class SparseTable {
 public:
  int n;
  vector<vector<T>> mat;
  F func;
 
  SparseTable(const vector<T>& a, const F& f) : func(f) {
    n = static_cast<int>(a.size());
    int max_log = 32 - __builtin_clz(n);
    mat.resize(max_log);
    mat[0] = a;
    for (int j = 1; j < max_log; j++) {
      mat[j].resize(n - (1 << j) + 1);
      for (int i = 0; i <= n - (1 << j); i++) {
        mat[j][i] = func(mat[j - 1][i], mat[j - 1][i + (1 << (j - 1))]);
      }
    }
  }
 
  T get(int from, int to) const {
    assert(0 <= from && from <= to && to <= n - 1);
    int lg = 32 - __builtin_clz(to - from + 1) - 1;
    return func(mat[lg][from], mat[lg][to - (1 << lg) + 1]);
  }
};



bool ok[200010];
signed main(){
    int n,k;
    cin>>n>>k;
    vector<int>p(n);
    REP(i,n) cin>>p[i];
    int min_n=p[0];
    int max_n=p[0];
   set<int>st;
   vector<int>bad(n-1);
   if(n==k){
       cout<<1<<endl;
       return 0;
   }
    for (int i = 0; i < n-1; i++)
    {
        bad[i]=(p[i]>p[i+1]);
    }
    vector<int>pref(n);
    for (int i = 0; i < n-1; i++)
    {
        pref[i+1]=pref[i]+bad[i];
    }
    SparseTable<int>smin(p,[&](int i,int j) {
       return min(i,j);});
    SparseTable<int>smax(p,[&](int i,int j) {
       return max(i,j);});    
     
    int ans=0;
    int nosort=0;
    for (int i = 0; i <=n-k; i++)
    {
        if(pref[i+k-1]-pref[i] == 0) {
            nosort=1;
            continue;
        }
        if(i>0 && smin.get(i-1,i+k-1)==p[i-1] && smax.get(i-1,i+k-1)== p[i+k-1]) 
        continue;
        ans++;
    }
    cout<<ans+nosort<<endl;
    
   

    return 0;
}

Measured memory_bytes: 57216
x1, x2, x3, x4, x5 = (int(each) for each in input().split())

if x1 == 0:
    print(1)
elif x2 == 0:
    print(2)
elif x3 == 0:
    print(3)
elif x4 == 0:
    print(4)
else:
    print(5)

Measured memory_bytes: 9112