akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int n, k;
string aux = "";

int main()
{
	cin >> n >> k;
	while(n>=k)
	{
		aux+=(n%k)-'0';
		n/=k;
	}
	
	cout << aux.size()+1 << '\n';
}


Measured memory_bytes: 256
module IntMap = Map.Make (struct
  type t = int
  let compare = compare
end)

let () = Scanf.scanf "%d %d\n" @@ fun n m ->
  let elts = Array.make (n + m) (0, 0) in
  for i = 0 to n - 1 do
    Scanf.scanf "%d " @@ fun a ->
      elts.(i) <- (a, 1)
  done;
  for i = 0 to m - 1 do
    Scanf.scanf "%d %d\n" @@ fun b c ->
      elts.(i + n) <- (c, b)
  done;
  Printf.printf "%d\n" @@ fst @@
  List.fold_left (fun (acc, n) (c, b) ->
    acc + c * min n b, n - min n b) (0, n) @@
  List.rev @@
  IntMap.bindings @@
  Array.fold_left (fun m (c, b) ->
    IntMap.add c (b + try IntMap.find c m with Not_found -> 0) m) IntMap.empty elts

Measured memory_bytes: 35968
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  string S;
  int K;
  cin>>S>>K;
  char C=S[0];
  bool b=true;
  for(char c:S)
    if(c!=C){
      b=false;
      break;
    }
  if(b){
    cout<<S.size()*K/2<<endl;
    return 0;
  }
  int j=1,ans1=0,k;
  bool bo=true;
  for(int i=1;i<S.size();i++){
    if(S[i]!=S[i-1]){
      if(bo){
        k=j;
        bo=false;
      }
      else
        ans1+=j/2;
      j=1;
    }else
      j++;
  }
  if(S[0]!=S[S.size()-1])
    cout<<(k/2+ans1+j/2)*K<<endl;
  else
    cout<<ans1*K+(k+j)/2*(K-1)+k/2+j/2<<endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
int MAX_N = 100000;
int MAX_W = 100000;

int main(){
  int P,Q,R;
  cin >> P >> Q >> R;
  priority_queue<
    int,                // 要素の型はint
    vector<int>,   // 内部コンテナはstd::vector (デフォルトのまま)
    greater<int>   // 昇順 (デフォルトはstd::less<T>)
  > que;

  que.push(P);
  que.push(Q);
  que.push(R);
  int x = que.top(); que.pop();
  x +=  que.top();
  cout << x <<endl;
}


Measured memory_bytes: 256
N = int(input())

# 初期化
G = [[] for i in range(10 ** 6 + 1)]  # グラフ
U = [None] * (10 ** 6 + 1)  # 入次数
D = [0] * (10 ** 6 + 1)  # 根からの距離


# 変換用
def x(i, j):
    return j + 1000 * i


# グラフを構築
for i in range(1, N + 1):
    A = list(map(int, input().split()))
    for j in range(N - 2):
        fv1, fv2 = min(i, A[j]), max(i, A[j])
        tv1, tv2 = min(i, A[j + 1]), max(i, A[j + 1])
        G[x(fv1, fv2)].append(x(tv1, tv2))
        U[x(fv1, fv2)] = 0
        U[x(tv1, tv2)] = 0


# 入次数をカウント
for i in range(10 ** 6 + 1):
    for v in G[i]:
        U[v] += 1

# トポロジカルソート
U_zero_nodes = []
for i in range(10 ** 6 + 1):
    if U[i] is None:
        continue

    if U[i] == 0:
        U_zero_nodes.append(i)


topological_order = []
while U_zero_nodes:
    n = U_zero_nodes.pop()
    topological_order.append(n)

    for v in G[n]:
        U[v] -= 1
        if U[v] == 0:
            U_zero_nodes.append(v)


# 不可能判定
if len(topological_order) != N * (N - 1) // 2:
    print(-1)
    exit()


# 最長経路を計算
for t_n in topological_order:
    for v in G[t_n]:
        D[v] = max(D[v], D[t_n] + 1)
print(max(D) + 1)


Measured memory_bytes: 168676
#include<stdio.h>

#define MAX_DIR_SIZE      (101)
#define MAX_SURFACE_COUNT (6)

typedef union _dice{
        int number[MAX_SURFACE_COUNT];
        struct {
                int front;
                int south;
                int east;
                int west;
                int north;
                int back;
        } pos;
} DICE;

void roll_dice(DICE * dice, char direction);

int main(void)
{
        DICE dice;
        char direction[MAX_DIR_SIZE];
        int index;

        for(index=0; index < MAX_SURFACE_COUNT; index++){
                scanf("%d", &dice.number[index]);
        }

        scanf("%s", direction);

        for(index=0; index < MAX_DIR_SIZE; index++){

                if(direction[index] == '\0'){
                        break;
                }

                roll_dice(&dice, direction[index]);
        }

        printf("%d\n", dice.pos.front);

        return 0;
}

void roll_dice(DICE * dice, char direction){

        int index;
        DICE d;

        switch(direction){
        case 'N':
                d.pos.front = dice->pos.south;
                d.pos.south = dice->pos.back;
                d.pos.east  = dice->pos.east;
                d.pos.west  = dice->pos.west;
                d.pos.north = dice->pos.front;
                d.pos.back  = dice->pos.north;
                break;
        case 'S':
                d.pos.front = dice->pos.north;
                d.pos.south = dice->pos.front;
                d.pos.east  = dice->pos.east;
                d.pos.west  = dice->pos.west;
                d.pos.north = dice->pos.back;
                d.pos.back  = dice->pos.south;
                break;
        case 'W':
                d.pos.front = dice->pos.east;
                d.pos.south = dice->pos.south;
                d.pos.east  = dice->pos.back;
                d.pos.west  = dice->pos.front;
                d.pos.north = dice->pos.north;
                d.pos.back  = dice->pos.west;
                break;
        case 'E':
                d.pos.front = dice->pos.west;
                d.pos.south = dice->pos.south;
                d.pos.east  = dice->pos.front;
                d.pos.west  = dice->pos.back;
                d.pos.north = dice->pos.north;
                d.pos.back  = dice->pos.east;
                break;
        default:
                break;
        }

        for(index=0; index < MAX_SURFACE_COUNT; index++){
                dice->number[index] = d.number[index];
        }

}


Measured memory_bytes: 2100
#include<iostream>
#include<string>
#include<cstdlib>
#include<algorithm>
#include<cctype>
#include<cmath>


using namespace std;


int main(){
	double n,t,a;
	double h;
	double p;
	int count=0;
	double place=10000.0;
	
	cin>>n>>t>>a;
	for(int i=0;i<n;i++){
		cin>>h;
		p =abs( a -(t-h*0.006));
			
		if(place>p){
			place=p;
			count=i+1;
		}
	p=0;
	}
	cout<<count<<endl;
	


}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<int>>;
#define MOD 1000000007
#define MAX 1000000

int main(){
  int n;
  cin>>n;
  vector<int> v(n);
  map<int,int> odd,even;
  for(int i=0;i<n;i++){
    cin>>v.at(i);
    if(i%2==0){
      if(odd.count(v.at(i))==0){
        odd[v.at(i)]=0;
      }
      odd[v.at(i)]++;
    }else{
      if(even.count(v.at(i))==0){
        even[v.at(i)]=0;
      }
      even[v.at(i)]++;
    }
  }

  pair<int,int> largest1=make_pair(0,-1);
  pair<int,int>largest2=make_pair(0,-1);
  for(auto m: odd){
    if(largest1.second<m.second){
      largest1=m;
    }
  }
  for(auto m: even){
    if(largest2.second<m.second){
      largest2=m;
    }
  }
  if(largest1.first==largest2.first){
    pair<int,int> large1=make_pair(0,0);
    pair<int,int> large2=make_pair(0,0);
    for(auto m: odd){
      if(m.first==largest1.first){
        continue;
      }
      if(large1.second<m.second){
        large1=m;
      }
    }
    for(auto m: even){
      if(m.first==largest2.first){
        continue;
      }
      if(large2.second<m.second){
        large2=m;
      }
    }
    cout<<min(n-largest1.second-large2.second,n-large1.second-largest2.second)<<endl;
  }else{
    cout<<n-largest1.second-largest2.second<<endl;;
  }
}


Measured memory_bytes: 5376
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime> 
#include <memory.h>
#include <assert.h>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
const int INF = 1e9 + 1;
const ll LLINF = 1e18 + 1;

int main() {
    vector<int> a(5);
    for(int i = 0; i < 5; i++) cin >> a[i];
    int k;
    cin >> k;

    bool ans = true;
    for(int i = 0; i < 5; i++) {
        for(int j = 0; j < 5; j++) {
            if(i == j) continue;
            if(abs(a[i]-a[j]) > k) ans = false;
        }
    }

    if(ans) cout << "Yay!" << endl;
    else cout << ":(" << endl;

    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<cmath>
#include <iomanip>
using namespace std;

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

    double theta;

    double totalMin = h * 60 + m;
    theta = abs(totalMin / (60 * 12) - (double)m / 60) * 2 * M_PI;
    double ans = a * a + b * b - 2 * a * b * cos(theta);


    cout << fixed << setprecision(20) << sqrt(ans) << endl;

    return 0;
}

Measured memory_bytes: 4256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <utility>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
typedef long long int ll;

int main() {
  int L;
  cin>>L;
  
  double P=(double)L/3;
  double ans=P*P*P;
  cout<<fixed;
  cout<<setprecision(10)<<ans<<endl;
  
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

class Point {
public:
    int x, y;
    Point(int a = 0, int b = 0)
    {
        int x = a;
        int y = b;
    };
    bool operator <(const Point& p) const {
        return y < p.y || (y == p.y && x < p.x);
    }
};

inline bool direct(Point& base, Point& a, Point& b) {
    return (a.x - base.x)*(b.y - base.y) - (a.y - base.y)*(b.x - base.x) < 0;
}


int main() {
    int n, i;
    int k = 2;
    scanf("%d", &n);
    vector <Point> P(n), H(2 * n);
    for (i = 1; i <= n; ++i) {
        scanf("%d%d",&P[i - 1].x, &P[i - 1].y);
    }
    sort(P.begin(), P.end());
    H[0] = P[0];
    H[1] = P[1];
    for (i = 0; i < n - 2; ++i) {
        while (k >= 2 && direct(H[k - 2],H[k - 1],P[i + 2])) k--;
        H[k++] = P[i + 2];
    }
    H[k++] = P[n - 2];
    for (i = n; i > 2; i--) {
        while (k >= 2 && direct(H[k - 2],H[k - 1],P[i - 3])) k--;
        H[k++] = P[i - 3];
    }
    printf("%d\n", k - 1);
    for (i = 0; i < k - 1; ++i) {
        printf("%d %d\n", H[i].x, H[i].y);
    }
    return 0;
}

Measured memory_bytes: 4740
#include<bits/stdc++.h>
using namespace std;
int n,k;
int c[300005];
int main(){
	scanf("%d%d",&k,&n);
	if(k&1){
		for(int i=1;i<=n;++i)c[i]=k+1>>1;
		int f=n,g=n/2;
		while(g--)if(c[f]==1)c[f--]=k;else --c[f],f=n;
		for(int i=1;i<=f;++i)printf("%d ",c[i]);
	}else{
		printf("%d ",k/2);
		for(int i=1;i<n;++i)printf("%d ",k);
	}
	return 0;
}

Measured memory_bytes: 3584
program sample
	implicit none
    integer :: a,b
    read(*,*) a,b
    
    if (a<b) then
    	write(*,*) b+b-1
    else if (b<a) then
    	write(*,*) a+a-1
    else
    	write(*,*) a+b
    end if
    stop
end program sample



Measured memory_bytes: 2860
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
// #include <boost/multiprecision/cpp_int.hpp>
// #include <boost/multiprecision/cpp_dec_float.hpp>

using namespace std;
// using namespace boost::multiprecision;

typedef long long ll;
typedef long double ld;

#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mis map<int,string>
#define msi map<string,int>
#define mll map<ll,ll>
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep1(i,n) for(int i=1; i<=(int)(n); i++)
#define all(c) c.begin(),c.end()
#define srta(a) sort(all(a))
#define srtd(a) sort(all(a),greater<型>())
#define rvs(s) reverse(all(s))
#define psb push_back
#define ppb pop_back
#define ers erase
#define isu isupper
#define isl islower
#define lb(a,k) lower_bound(all(a),k)
#define ub(a,k) upper_bound(all(a),k)
#define bs(a,k) binary_search(all(a),k)
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

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 int I_INF = 1001001001;
const ll LL_INF = 1001001001001001001;
const ld EPS = 0.001;

void Main() {
    ll N;
    cin >> N;

    vl a(N);
    rep (i, N) cin >> a[i];

    ll ans = 0;
    rep (i, N) {
        if (i == 0) continue;
        ll s = a[i-1]-a[i];
        if (s > 0) {
            a[i] += s;
            ans += s;
        }
    }

    cout << ans << endl;
}

int main() {
    Main();
    return 0;
}


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

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/2;
    public static final int inf = Integer.MAX_VALUE/2;
    //arc59 d
    static void solve(InputReader in, PrintWriter out){
        char[] s = in.ns().toCharArray();
        int ans = -1;
        boolean flag = false;
        for (int i = 0; i < s.length-1; i++) {
            if(i<s.length-2){
                if(s[i]==s[i+1]||s[i]==s[i+2]){
                    out.printf("%d %d\n",i+1, i+3);
                    flag = true;
                    break;
                }
            }else{
                if(s[i]==s[i+1]){
                    out.printf("%d %d\n",i+1, i+2);
                    flag = true;
                    break;
                }
            }
        }
        if(!flag) out.println("-1 -1");
    }

    public static void main(String[] args){
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public double nd(){
            return Double.parseDouble(ns());
        }
        public char nc(){
            return ns().toCharArray()[0];
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

Measured memory_bytes: 22740
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
ll mod = 1000000007;

int main() {
    int n, W, ans = 0;
    cin >> n >> W;
    vector<int> w1, w2, w3, w4;
    int w0, v0;
    cin >> w0 >> v0;
    w1.push_back(v0);
    for(int i = 1; i < n; i++) {
        int w, v;
        cin >> w >> v;
        if(w == w0) {
            w1.push_back(v);
        }
        else if(w == w0+1) {
            w2.push_back(v);
        }
        else if(w == w0+2) {
            w3.push_back(v);
        }
        else if(w == w0+3) {
            w4.push_back(v);
        }
    }

    sort( w1.begin(), w1.end(), greater<int>() );
    sort( w2.begin(), w2.end(), greater<int>() );
    sort( w3.begin(), w3.end(), greater<int>() );
    sort( w4.begin(), w4.end(), greater<int>() );

    rep(i, w1.size()+1) {
        rep(j, w2.size()+1) {
            rep(k, w3.size()+1) {
                rep(l, w4.size()+1) {
                    ll sumWeight = (ll)(i+j+k+l)*w0 + (j+2*k+3*l);
                    
                    if(W < sumWeight) {
                        continue;
                    }

                    int sumValue = 0;
                    rep(h, i) {
                        sumValue += w1[h];
                    }
                    rep(h, j) {
                        sumValue += w2[h];
                    }
                    rep(h, k) {
                        sumValue += w3[h];
                    }
                    rep(h, l) {
                        sumValue += w4[h];
                    }

                    ans = max(ans, sumValue);
                }
            }
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i;
  char c;
  string s;
  while(cin>>s>>c&&c!='X'){
    if(s.find('_')!=string::npos){
      if(c=='U'){
	s[0]+='A'-'a';
	while(s.find('_')!=string::npos){
	  s[s.find('_')+1]+='A'-'a';
	  s.erase(s.find('_'),1);
	}
      }else if(c=='L'){
	while(s.find('_')!=string::npos){
	  s[s.find('_')+1]+='A'-'a';
	  s.erase(s.find('_'),1);
	}
      }
    }else if('a'<=s[0]&&s[0]<='z'){
      if(c=='U'){
	s[0]+='A'-'a';
      }else if(c=='D'){
	for(i=0;i<(int)s.length();i++){
	  for(;i<(int)s.length()&&'a'<=s[i]&&s[i]<='z';i++);
	  if(i!=(int)s.length()){
	    s[i]+='a'-'A';
	    s.insert(i,1,'_');
	  }
	}
      }
    }else if('A'<=s[0]&&s[0]<='Z'){
      if(c=='L'){
	s[0]+='a'-'A';
      }else if(c=='D'){
	s[0]+='a'-'A';
	for(i=0;i<(int)s.length();i++){
	  for(;i<(int)s.length()&&'a'<=s[i]&&s[i]<='z';i++);
	  if(i!=(int)s.length()){
	    s[i]+='a'-'A';
	    s.insert(i,1,'_');
	  }
	}
      }
    }
    cout<<s<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<iostream>

#define MAX_LEN 32
using namespace std;

int main(){
	while(true){
		int i;
		int now = 0;
		int yama = 32;
		int jiro[MAX_LEN]={0,};
		scanf("%d", &i);
		if(i==0)break;
		for(int t = 0; t < i; ++t){
			scanf("%d", &jiro[t]);
		}
		while( yama > 0 ){
			yama -= ( yama - 1 ) % 5;
			printf("%d\n", yama);
			yama -= std::min( yama, jiro[now] );
			printf("%d\n", yama);
			++now;
			if(now>=i)now=0;
		}
	}
	return 0;
}

Measured memory_bytes: 0
S=str(input())
maru_count=0
#注文書に書かれた文字列Sに含まれるoの数だけ、１００円加算する。

for i in S:
    if i=='o':
        maru_count=maru_count+1
    elif i=='x':
        maru_count=maru_count+0
        
    
ramen_price=700+100*maru_count

print(ramen_price)

Measured memory_bytes: 9040
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MOD	1000000007
#define int	long long
#define pii pair<int,int> 
#define vi vector<int>
using namespace std;

int32_t main(){
	int n;
	cin >> n;
	int a[n];
	for(int i = 0; i < n; i++)
		cin >> a[i];
	double ans = 1.0, temp = 0;
	for(int i = 0; i < n; i++){
		temp += 1.0/(double)a[i];
	}
	cout <<  fixed << setprecision(10) << 1.0 / temp << endl;

	return 0;
}



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

using namespace std;

int main()
{
	int n, k;
	cin >> n >> k;
	vector<int> h(n);
	for (int i = 0; i < n; i++)
		cin >> h[i];
	sort(h.begin(), h.end());
	int ans = 1e9;
	for (int i = 0; i < n - k + 1; i++)
		ans = min(ans, h[i + k - 1] - h[i]);
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;
const int mod = 1e9+7;

int main() {
    string s; cin >> s;
    rep(i,s.size()) {
        if (s[i] == ',') cout << " ";
        else cout << s[i];
    }
    cout << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main(void) {
    int n;
    cin >> n;
    vi a(n),b(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    vector<bool> ans(51,true);
    for(int i = 50; i > 0; i--){
        int dp[51][51];
        rep(x,51)rep(y,51){
            if(x==y)dp[x][y] = 0;
            else dp[x][y] = INF;
        }
        for(int j = 50; j > 0; j--)if(ans[j] && i!=j){
            rep(k,51){
                dp[k][k%j]=min(dp[k][k%j],1);
            }
        }
        rep(z,51)rep(x,51)rep(y,51)
            dp[x][y] = min(dp[x][y], dp[x][z]+dp[z][y]);

        bool c = true;
        rep(k,n)if(dp[a[k]][b[k]]==INF) c = false;

        if(c) ans[i] = false;
    }
    if(ans[50]){
        cout << -1 << endl;
    }else{
        ll ret = 0;
        loop(i,1,51)if(ans[i]) ret += 1LL<<i;
        cout << ret << endl;
    }
}


Measured memory_bytes: 256
# ABC133C - Remainder Minimization 2019
def main():
    L, R = map(int, input().split())
    MOD = 2019
    if R - L + 1 >= MOD:  # L <= 2019n <= R
        print(0)
    else:  # max: 2018 * 2017 patterns
        L, R = L % MOD, R % MOD
        if L <= 3 and R >= 673:  # 2019 = 3 * 673
            print(0)
            return
        # 3 < L < R < 673
        ans = min((i * j) % MOD for i in range(L, R) for j in range(i + 1, R + 1))
        print(ans)


if __name__ == "__main__":
    main()

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

int main(){
    ll n, a, b;
    cin >> n >> a >> b;
    if(a + b > n + 1 || a * b < n) {
        cout << -1 << endl;
        return 0;
    }
    vector<ll> ans;
    ll s = n - a;
    ll cur = n;
    rep(i, 0, a){
        ll num = min(b-1, s) + 1;
        s -= num-1;
        rep(j, 0, num) ans.push_back(cur - (num-1) + j);
        cur -= num;
    }
    reverse(ans.begin(), ans.end());
    rep(i, 0, n) cout << ans[i] << (i == n-1 ? "\n" : " ");
    return 0;
}

Measured memory_bytes: 7436
import java.util.*; 

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

  	int[] p=new int[n];
   for(int c=0;c<n;c++){
    		p[c]=sc.nextInt();
    	}
    int[] q=new int[n];
   for(int c=0;c<n;c++){
    		q[c]=sc.nextInt();
    	}
    int pans=0;
  	int qans=0;
  
 	for(int c=0;c<n-1;c++){
      int pans2 =p[c]-1;
      for(int d=1;d<n-c;d++){
        pans2*=d; 
     }
      pans+=pans2;
      pans2=0;
      
      for(int e=0;e<=c;e++){
       if(p[e]<p[c+1]){
         p[c+1]-=1;
        }
      }
      
      }
      
    
  
   for(int c=0;c<n-1;c++){
      int qans2 =q[c]-1;
      for(int d=1;d<n-c;d++){
        qans2*=d;
     }
      qans+=qans2;
      qans2=0;
     
     for(int e=0;e<=c;e++){
       if(q[e]<q[c+1]){
         q[c+1]-=1;
        }
      }
    }
   
    int max=Math.max(pans,qans);
  	int min=Math.min(pans,qans);
  
    	System.out.println(max-min);
    }
}



Measured memory_bytes: 23124
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

"""
両端の位置が不変。x,y,z -> x,x+z-y,zを繰り返すが、階差数列で見るとswapに相当する。
"""

import numpy as np

N = int(input())
X = [int(x) for x in input().split()]
M,K = map(int,input().split())
A = [int(x) for x in input().split()]

P = list(range(N))
for a in A:
    P[a-1],P[a] = P[a],P[a-1]

P = np.array(P,dtype=np.int32)

def power(P,n):
    if n == 1:
        return P
    Q = power(P,n//2)
    Q = Q[Q]
    return P[Q] if n&1 else Q

Q = power(P,K)

diff = np.diff([0] + X)
answer = diff[Q].cumsum()
print('\n'.join(answer.astype(str)))

Measured memory_bytes: 44388
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


#define in(x) cin >> x
#define out(x) cout << x
#define outn(x) cout << x << '\n'
#define outs(x) cout << x << ' '
#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)

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

	vll num(t.size() + 1, 0);
	vector<string> str(t.size() + 1, "");
	rep(i, 0, s.size()) {
		vll tmp_num(t.size() + 1, 0);
		vector<string> tmp_str(t.size() + 1, "");

		rep(j, 0, t.size()) {
			if (s[i] == t[j]) {
				tmp_num[j + 1] = num[j] + 1;
				tmp_str[j+1] = str[j] + s[i];
			}
			else {
				if (num[j + 1] > tmp_num[j]) {
					tmp_num[j + 1] = num[j + 1];
					tmp_str[j + 1] = str[j + 1];
				}
				else {
					tmp_num[j + 1] = tmp_num[j];
					tmp_str[j + 1] = tmp_str[j];
				}
			}
		}
		num = tmp_num;
		str = tmp_str;
	}


	std::cout << str[t.size()] << endl;
	return 0;

}


Measured memory_bytes: 16788
#include<bits/stdc++.h>
#define M 500000
#define MAX 10000000000000010
#define mod 1000000007
#define ss second
#define ff first
#define ll long long int
#define pb push_back
#define ld double
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;

int main()
{
	int n,h,ans=0;
	cin>>h>>n;
	while(h>0)
	{
		h-=n;
		ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
main(c,t){double*p=t,v,atof();for(;t=c&2&&printf("%f\n",*p),~scanf("%s%c",&t,&c);)v=t<48?*--p=t&1?t&2?t&4?*p/v:*p+v:*p-v:*p*v:(*++p=atof(&t));}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N;
int ans[10101];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N;
	rep(x, 1, 101) rep(y, 1, 101) rep(z, 1, 101) {
		int tot = x * x + y * y + z * z + x * y + y * z + z * x;
		if (tot <= N) ans[tot]++;
	}
	rep(i, 1, N + 1) printf("%d\n", ans[i]);
}







Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
using ll = long long;
// using Graph = vector<vector<int>>;
const ll MOD = 1e9 + 7;
const ll INF = 1e9;
const ll LINF = 1LL << 60;

int main() {
  vector<int> cnt(4, 0);
  rep(i, 6) {
    int x;
    cin >> x;
    x--;
    cnt[x]++;
  }
  sort(ALL(cnt));
  if (cnt[0] == cnt[1] && cnt[2] == cnt[3])
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h> 
using namespace std;

typedef long long ll;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0) 
#define rep(pp,nn) for (int ii = pp; ii < nn; ++ii)
#define vi vector<int>
#define vll vector<ll>
#define vs vector<string>

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

string int_to_string(int x) {
    stringstream ss;
	ss << x;
	string ni = ss.str();
	return ni;
}
int string_to_int(string x) {
	int n;
	stringstream s(x);
	s >> n;
	return n;
}

int64_t power_mod(ll a, ll b, ll mo) {
	ll ans = 1;
	while (b) {
		if(b & 1) {
			ans = (ans % mo * a % mo) % mo;
		}
		a = (a % mo * a % mo) % mo;
		b /= 2;
	}
	return ans;
}
int64_t POW(ll a, ll b) {
	ll ans = 1;
	while (b) {
		if(b & 1) {
			ans = ans * a;
		}
		a = a * a;
		b /= 2;
	}
	return ans;
}

vector<int64_t> INVERSE(int64_t nn, int64_t mo) {
	vector<int64_t> inv(nn + 1);
	vector<int64_t> mul(nn + 1);
	inv[0] = 1;
    inv[1] = 1;
	for (ll i = 2; i <= nn; ++i) {
		inv[i] = (mo - (mo / i) * inv[mo % i] % mo) % mo; 
	}
	mul[0] = 1;
	for (int i = 1; i <= nn; ++i) {
		mul[i] = (mul[i - 1] * inv[i]) % mo;
	}
	return mul;
}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif



int main() {
	int n;
	cin  >> n;
	vector<int64_t> v(n);
	int64_t ans = 1000;
	for (int i = 0; i < n; ++i) {
		cin >> v[i];
		//if (i) {
			//if (v[i] > v[i - 1]) {
				//int64_t x = ans / v[i - 1];
				//ans = ans % v[i - 1];
				//ans += x * v[i];
			//}
		//}
	}
	for (int i = 1; i < n; ++i) {
		if (v[i] > v[i - 1]) {
			int64_t x = ans / v[i - 1];
			ans = ans % v[i - 1];
			ans += x * v[i];
		}
	}
	cout << ans;
}













Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
 
#define ll          long long int
#define ld          long double
#define pb          push_back
#define mp          make_pair
#define ff          first
#define se          second
#define endl        '\n'
#define fd(n)       fixed<<setprecision(n)
#define MAX         100000000000000000
#define MAXN        1000005
#define mod         1000000007  
#define pi          3.1415926535897932384626433
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,x,t;
    cin>>n>>x>>t;
    if(n%x==0){
        cout<<(n/x)*t;
    }
    else{
        cout<<(1+n/x)*t;
    }
}

Measured memory_bytes: 3580
import java.util.*;

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

		Scanner sc = new Scanner(System.in);
		String str = sc.nextLine();
		String[] data = str.split(" ");
		int num[] = new int[data.length];
		for(int i = 0; i < data.length; i++){
			num[i] = Integer.parseInt(data[i]);
		}
	
		int a = num[0];
		int b = num[1];
		int c = num[2];


		ArrayList<Integer> yaku = new ArrayList<Integer>();
		for(int i = a; i <= b; i++){
			if(c % i == 0){
				yaku.add(i);
			}
		}
		int x = yaku.size();
		System.out.println(x);
	}
}


Measured memory_bytes: 26304
#include<bits/stdc++.h>
#define int long long
#define ll long long
#define fi first
#define se second
#define  pb push_back
#define  pob pop_back
#define mp make_pair
#define db long double
#define pll pair<ll,ll>
#define vll vector<ll>
#define all(a) (a).begin(),(a).end()
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define sz(x) (int)x.size()
#define endl '\n'
#define mod 1000000007
#define MAX 100005
using namespace std;

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

    // freopen("in.txt","r",stdin);
    // freopen("out.txt","w",stdout);

    ll x;
    cin >> x;
    ll ans = (x/500)*1000;
    ans += ((x%500)/5)*5;
    cout << ans;
    return 0;

}


Measured memory_bytes: 256
x, y, z, k = gets.to_s.split.map{|i|i.to_i}

A = gets.to_s.split.map{|i|i.to_i}.sort.reverse[0,k]
B = gets.to_s.split.map{|i|i.to_i}.sort.reverse[0,k]
C = gets.to_s.split.map{|i|i.to_i}.sort.reverse[0,k]

t = []

i = 0
A.each_with_index do |a,i|
  B.each_with_index do |b,j|
    break if (i+1) * (j+1) > k
    t.push a + b
  end
end

t = t.sort.reverse[0,k]

v = []
C.each_with_index do |c,i|
  t.each_with_index do |u,j|
    break if (i+1) * (j+1) > k
    v.push( c + u )
  end
end

puts v.sort.reverse[0, k]

Measured memory_bytes: 4972
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=mod*mod*3LL;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

struct node{int y1, x1, y2, x2;};
int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll a, b;
    cin >> a >> b;
    if(abs(a-b) <= 1LL) cout << "Brown" << endl;
    else cout << "Alice" << endl;
    return 0;
}


Measured memory_bytes: 256
h, w = gets.split.map(&:to_i)
s = []
(0...h).each do
  s << gets.strip
end

oct = [[-1, 0], [-1, 1], [0, 1], [1, 1], [1, 0], [1, -1], [0, -1], [-1, -1]]

result = []
(0...h).each do |i|
  arr = []
  (0...w).each do |j|
    cnt = 0
    if s[i][j] == '#'
      arr << '#'
      next
    end
    oct.each do |dir|
      if (0 <= j + dir[1]) && (j + dir[1] <= w - 1) then x = j + dir[1] else next end
      if (0 <= i + dir[0]) && (i + dir[0] <= h - 1) then y = i + dir[0] else next end
      if s[y][x] == '#'
        cnt = cnt.succ
      end
    end
    arr << cnt
  end
  result << arr
end

(0...h).each do |i|
  (0...w).each do |j|
    print result[i][j]
  end
  puts ""
end


Measured memory_bytes: 14260
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<iostream>
using namespace std;

long long a[100];
int main ()
{
	long long n;
	a[0]=2;
	a[1]=1;
	for(long long i = 2; i <= 86; i++)
	{
		a[i] = a[i-1]+a[i-2];
	}
	scanf("%lld",&n);
	printf("%lld\n",a[n]);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define endl '\n'

#define si(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) 
#define rep2(i, n, m) for (ll i = n; i <= (ll)(m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (ll)(m); --i)

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

using ll = long long;
using ld = long double;
using namespace std;

constexpr ll MOD = 1000000007;

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);

  int h, w; cin >> h >> w;
  char c[h][w];

  rep(i, h) rep(j, w) cin >> c[i][j];

  vi row(w, 0), cul(h, 0);
  rep(i, h) {
    bool flag = true;

    rep(j, w) if (c[i][j] == '#') flag = false;
    if (flag) cul[i] = true;
  }

  rep(i, w) {
    bool flag = true;

    rep(j, h) if (c[j][i] == '#') flag = false;
    if (flag) row[i] = true;
  }

  rep(i, h) {
    if (!cul[i]) {
      rep(j, w) if (!row[j]) cout << c[i][j];
      cout << endl;
    }
  }

  return (0);
}


Measured memory_bytes: 3640
#121_D
def F(A):
    if A%2==0:
        if (A//2)%2==0:
            return A
        else:
            return 1^A
    else:
        if ((A+1)//2)%2==0:
            return 0
        else:
            return 1
def f(A,B):
    return F(A-1)^F(B)

A,B=map(int,input().split())
print(f(A,B))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main(void){
    string N;
    int a=0;
    cin >> N;
    for(int i=0; i <3; i++){
        if(N[i]=='7'){
            a=1;
        }
    }
    if (a==1){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

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

int main()
{
  string s;
  cin>>s;
  int n=s.size();
  int cnt=0;
  std::vector<string> vec;
  int before=0;
  for (int i = 1; i < n; ++i)
  {
    if(s[i-1]=='L'&&s[i]=='R'){
      vec.push_back(s.substr(before,i-before));
      before=i;
    }
  }
  vec.push_back(s.substr(before));
  
  std::vector<int> ans;
  for(auto &e: vec) {
    int pos;
    for (int i = 0; i < e.size()-1; ++i)
    {
      if(e[i]=='R'&&e[i+1]=='L'){
        pos=i;
        break;
      }
    }
    int r=0,l=0;
    for (int i = 0; i < e.size(); ++i)
    {
      if(i%2==pos%2) r++;
      else l++;
    }
    vector<int> tmp(e.size(),0);
    tmp[pos]=r;
    tmp[pos+1]=l;
    for(auto &g: tmp) {
      ans.push_back(g);
    }
  }
  for(auto &e: ans) {
    cout<<e<<" ";
  }

}

Measured memory_bytes: 3832
#include<iostream>
#include<cmath>
using namespace std;
int main(){
	int n,sum=0,m;
	cin>>n;
	for(int i=1;i<=n;i++){
		m=log10(i)+1;
		if(m%2==1){
			sum++;
		}
	}
	cout<<sum;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using st=string;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
#define mp make_pair
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
st abc="abcdefghijklmnopqrstuvwxyz";
st ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};

int main() {
  ll a,v,b,w,t;
  cin >> a >> v >> b >> w >> t;
  ll d=abs(a-b);
  if(d<=(v-w)*t){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
}

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

const int MOD = 1e9 + 7;

int main() {
    int N, K;
    cin >> N >> K;
    int64_t A[N], ans = 1;
    rep(i, N) cin >> A[i];
    sort(A, A + N);

    int l = 0, r = N - 1, sign = 1;
    if (K % 2) {
        ans = A[r];
        r--;
        K--;
        if (ans < 0) sign = -1;
    }

    while (K) {
        int64_t x = A[l] * A[l+1];
        int64_t y = A[r] * A[r-1];
        if (x * sign > y * sign) {
            ans *= x % MOD;
            l += 2;
        } else {
            ans *= y % MOD;
            r -= 2;
        }
        ans %= MOD;
        K -= 2;
    }
    cout << (ans + MOD) % MOD << endl;
}

Measured memory_bytes: 5100
import itertools

N, M, Q = list(map(int,input().split()))
numbers = [i for i in range(1, M+1)]
array = itertools.combinations_with_replacement(numbers, N)

input_data = [list(map(int,input().split())) for _ in range(Q)]

max_score = 0
for A in array:
    score = 0
    for _ in range(Q):
        a, b, c, d = input_data[_]
        a = a - 1
        b = b - 1
        if A[b] - A[a] == c:
            score += d
    if score > max_score:
        max_score = score
    
print(max_score)

Measured memory_bytes: 9216
#include <stdio.h>

int main()
{
    int k, s;
    scanf("%d %d", &k, &s);
    int x, y, z, ans;
    ans = 0;
    for (x=0; x<=k; x++)
    {
        for (y=0; y<=k; y++)
        {
            z = s - x - y;
            if (0 <= z && z <=k && x + y + z == s) {
                ans ++;
            }
        }
    }
    printf("%d\n", ans);
}


Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;

namespace a
{
    class Program
    {
        static void Main(string[] args)
        {
            var _ = Console.ReadLine().Split();
            var a = int.Parse(_[0]);
            var b = int.Parse(_[1]);

            var total = 0;
            for(var i = 0; i < 2; i++){
                if(a > b){
                    total += a;
                    a--;
                }else{
                    total += b;
                    b--;
                }
            }

            Console.WriteLine(total);
        }
    }
}


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


//wierd debugging stuff
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
//end of weird debugging stuff
using ll = long long;
using vi = vector<int>;
using ii = pair<int,int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define invec(v) for(auto& x : v)cin>>x;
#define Test int T;cin>>T;while(T--)
#define REP(i,j,k) for(int i=(j);(i)<(k);(i)++)
#define Time()	cerr <<'\n' << clock() * 1000 / CLOCKS_PER_SEC << "ms\n"
#define SZ(x) (int)x.size();
#define all(x) x.begin,x.end()
// no change 

//const int MxN = 1e9+5;

int main() {
	int n;
	cin >> n;
	vi v(2*n);
	invec(v);
	sort(v.rbegin(),v.rend());
	ll ans =0;
	for(int i=0;i<2*n;i++){
		if(i&1)ans +=v[i];
	}
	cout << ans;
	
	
	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
typedef long long ll;
#define ALL(v) v.begin(), v.end()
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define chmax(x, a) x = max(x, a)
#define chmin(x, a) x = min(x, a)

int main() {
    ll N, K; cin >> N >> K;
    ll round_sum = 0;
    vector<ll> P(N), C(N);
    rep(i, N) {
        cin >> P[i];
        P[i]--;
    }
    rep(i, N) {
        cin >> C[i];
    }
    ll ans = vmax(C);
    ll tmp, cnt, cnt2, mx, mx2, memo, now;
    bool flag;
    rep(i, N) {
        tmp = P[i]; cnt = C[tmp]; mx = cnt; memo = 1;
        flag = false;
        while (tmp != i) {
            tmp = P[tmp];
            cnt += C[tmp];
            chmax(mx, cnt);
            memo++;
            if (memo == K) {
                flag = true;
                break;
            }
        }
        if (flag || cnt < 0) {
            chmax(ans, mx);
        }
        else {
            tmp = P[i]; cnt2 = C[tmp]; mx2 = cnt2; now = 0;
            while (now < K%memo+memo-1) {
                tmp = P[tmp];
                cnt2 += C[tmp];
                chmax(mx2, cnt2);
                now++;
            }
            chmax(ans, cnt*(K/memo-1)+mx2);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3708
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<queue>
#include<map>
#include<stack>
#include<fstream>
#include<stdlib.h>
#include<set>
#include<climits>
#include<cmath>  
#include<memory.h> 
#include<sstream>
#include<time.h>
#include<iomanip>
using namespace std;
const unsigned long long BIGEST=1000000000000000000+1000000000000000000;
const long long BIGER=1000000000000000000;
const int BIG=1000000000;
const int MOD=1000000007;
const long long LMOD=1000000007;
#define F first
#define S second
#define p2 pair<int,int>
#define cb make_pair
int n;
int ar[200005];
vector<int>v[200005];
p2 p[200005];
struct seg
{
	int mnid[800005][2];
	int ch(int x,int l=1,int r=n,int k=1)
	{
		if(r<x||x<l)return 0;
		//cout<<"!"<<x<<" "<<l<<" "<<r<<" "<<k<<" ";
		if(ar[x]<ar[mnid[k][x%2]])mnid[k][x%2]=x;
		//cout<<mnid[k][0]<<" "<<mnid[k][1]<<endl;
		if(l!=r)
		{
			ch(x,l,(l+r)/2,k*2);
			ch(x,(l+r)/2+1,r,k*2+1);
		}
		//cout<<"!"<<x<<" "<<l<<" "<<r<<" "<<k<<" ";
		//cout<<mnid[k][0]<<" "<<mnid[k][1]<<endl;
		return 0;
	}
	int q(int a,int b,int v,int l=1,int r=n,int k=1)
	{
		//cout<<" "<<a<<" "<<b<<" "<<v<<" "<<l<<" "<<r<<" "<<k<<endl;
		if(r<a||b<l)return 0;
		//cout<<">"<<a<<" "<<b<<" "<<v<<" "<<l<<" "<<r<<" "<<k<<endl;
		if(a<=l&&r<=b)return mnid[k][v];
		if(l!=r)
		{
			int t1,t2;
			t1=q(a,b,v,l,(l+r)/2,k*2);
			t2=q(a,b,v,(l+r)/2+1,r,k*2+1);
			if(ar[t1]<ar[t2])return t1;
			else return t2;
		}
		return 0;
	}
}T;
int g=0;
int fu(int l,int r)
{
	//cout<<l<<" "<<r<<endl;
	int id=++g;
	p2 t;
	t.F=T.q(l,r,l%2);
	t.S=T.q(t.F,r,(l+1)%2);
	//cout<<"("<<t.F<<","<<t.S<<")";
	if(t.F>l)v[id].push_back(fu(l,t.F-1));
	if(t.S>t.F+1)v[id].push_back(fu(t.F+1,t.S-1));
	if(r>t.S)v[id].push_back(fu(t.S+1,r));
	p[id].F=ar[t.F];
	p[id].S=ar[t.S];
	return id;
}
int main()
{
	ar[0]=BIG;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&ar[i]);
		T.ch(i);
	}
	fu(1,n);
	set<pair<p2,int > >q;
	q.insert(cb(p[1],1));
	pair<p2,int> t;
	while(!q.empty())
	{
		t=*q.begin();
		q.erase(t);
		printf("%d %d ",t.F.F,t.F.S);
		//cout<<t.S<<" ";
		for(int i=0;i<v[t.S].size();i++)q.insert(cb(p[v[t.S][i]],v[t.S][i]));
	}
	return 0;
}

Measured memory_bytes: 35072
#include<bits/stdc++.h>
using namespace std;
char a[6];
int main(){
	int b=0;
	for(int i=0;i<6;i++){
		cin>>a[i];
	}
	if(a[0]==a[3]){
		b++;
	}
	if(a[1]==a[4]){
		b++;
	}
	if(a[2]==a[5]){
		b++;
	}
	cout<<b<<endl;
}


Measured memory_bytes: 256