akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
class Main{
    int a,b;
    public void solve(){
        int d, r;
        double f;
        Scanner sc = new Scanner(System.in);
        a = sc.nextInt();
        b = sc.nextInt();
        d = a / b;
        r = a % b;
        f = 1.0 * a / b;
        System.out.printf("%2d %2d %2.5f",d,r,f);
    }
    public static void main(String[] args){
        new Main().solve();
    }
}

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

int main()
{
    int n, m;
    cin >> n >> m;
    cout << (n-1)*(m-1) << "\n";
    return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        a solver = new a();
        solver.solve(1, in, out);
        out.close();
    }

    static class a {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            long A = in.nextLong();
            String op = in.next();
            long B = in.nextLong();

            if (op.equals("+")) {
                out.println(A + B);
            } else {
                out.println(A - B);
            }
        }

    }
}



Measured memory_bytes: 21716
formula = input().split(' ')
stack = []
for target in formula:
    if target == '+':
        operand1 = stack.pop()
        operand2 = stack.pop()
        result = int(operand2) + int(operand1)
        stack.append(result)
    elif target == '-':
        operand1 = stack.pop()
        operand2 = stack.pop()
        result = int(operand2) - int(operand1)
        stack.append(result)
    elif target == '*':
        operand1 = stack.pop()
        operand2 = stack.pop()
        result = int(operand2) * int(operand1)
        stack.append(result)
    else:
        stack.append(target)
print(stack[0])


Measured memory_bytes: 5600
#include <bits/stdc++.h>
using namespace std;
#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 ALL(v) v.begin(), v.end()
#define downque(que)  priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;
typedef long long ll;
const int MOD = 1e9+7;



int main(){
 int n; cin>>n;
 priority_queue<double, vector<double>, greater<double>> que;
 REP(i,n){
     double v; cin>>v; que.push(v);
 }
  
double res=0;
while(1){
     double a=que.top();  que.pop();
     double b=que.top();  que.pop();
     res=(a+b)/2; 
     if(!que.empty())que.push(res);
     else break;
     //cout<<a<<' '<<b<<' '<<res<<endl;
}

std::cout << std::fixed;
std::cout << std::setprecision(5)<<res<<endl;
}

Measured memory_bytes: 256
local x,y,a,b,c=io.read("n","n","n","n","n")
local A,B={},{}
local t={}

for i=1,a do
    A[i]=io.read("n")
end
table.sort(A,function(a,b)
    return a>b
end)
for i=1,x do
    table.insert(t,A[i])
end

for i=1,b do
    B[i]=io.read("n")
end
table.sort(B,function(a,b)
    return a>b
end)
for i=1,y do
    table.insert(t,B[i])
end

for i=1,c do
    table.insert(t,io.read("n"))
end
table.sort(t,function(a,b)
    return a>b
end)

local max=0
for i=1,x+y do
    max=max+t[i]
end
print(max)

Measured memory_bytes: 14576
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int[] len = new int[3];

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

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

		Arrays.sort(len);

		System.out.println((len[0] == 5 && len[1] == 5 && len[2] == 7) ? "YES" : "NO");
	}
}

Measured memory_bytes: 35632
#include <iostream>
#include <limits>
#include <numeric>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <utility>
using namespace std;
#define INF 100000000
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define rep(i, n) for(int (i)=1; (i)<=(n); (i)++)
typedef pair<int, int> P;
typedef long long ll;
int main(){
    int x;
    cin >> x;
    if(x == 0) cout << 1 << endl;
    else if (x == 1) cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 3516
#include <iostream>
#define llint long long

using namespace std;

llint n;
llint a[405];
llint sum[405];
llint dp[405][405];

int main(void)
{
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	for(int i = 1; i <= n; i++) sum[i] = sum[i-1] + a[i];
	
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			dp[i][j] = 1e18;
			if(i == j) dp[i][i] = 0;
		}
	}
	
	for(int i = 1; i <= n; i++){
		for(int l = 1; l+i-1 <= n; l++){
			int r = l+i-1;
			for(int k = l; k < r; k++){
				dp[l][r] = min(dp[l][r], dp[l][k] + dp[k+1][r] + sum[r] - sum[l-1]);
			}
		}
	}
	cout << dp[1][n] << endl;
	
	return 0;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;

ll dp[110][4][2] = {};

int main(void){
  string n;
  int k;
  cin >> n;
  cin >> k;
  int len = (int)n.size();
  dp[0][0][0] = 1LL;
  for(int i = 0;i < len;++i){
    ll c = n[i] - '0';
    for(int j = 0;j < 4;++j){
      if(c != 0) {
        dp[i+1][j][1] += dp[i][j][0]; // 0
        if (j + 1 < 4) {
          dp[i+1][j+1][1] += dp[i][j][0] * (c - 1); // c - 1
          dp[i+1][j+1][0] += dp[i][j][0]; // c
        }
      } else {
        dp[i+1][j][0] += dp[i][j][0];
      }
      dp[i+1][j][1] += dp[i][j][1]; // 0
      if (j + 1 < 4) {
        dp[i+1][j + 1][1] += dp[i][j][1] * 9;
      }
    }
  }
  cout << dp[len][k][0] + dp[len][k][1] << endl;
  return 0;
}


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

using namespace std;
using Graph = vector<vector<int>>;
using Grid= vector<vector<char>>;
using vin= vector<int>;
using ll=long long;
using vll= vector<ll>;
using vbl=vector<bool>;
using vch=vector<char>;
using pnn=pair<int ,int>;

#define ft first
#define sd second
#define fn front
#define pb push_back
#define it insert
#define si(v) int((v).size())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rell(i,n) for (ll i=0; i< (ll)(n); i++)
#define sot(x) sort(x.begin(), x.end())
#define rese(x) reverse(x.begin(), x.end())
#define vnn(x,y,s,name) vector<vector<int>> name(x, vector<int>(y,s))
#define mse(x) memset(x, 0, sizeof(x))
#define mii(x,y,z) min(x,min(y,z))
#define maa(x,y,z) max(x,max(y,z))

string yes="Yes",no="No";

int main() {
   int h,n;
   cin>>h>>n;
   int sum=0;
   rep(i,n){
       int a;
       cin>>a;
       sum+=a;
   }
   if(sum>=h) cout<<yes<<endl;
   else cout<<no<<endl;
   
}


Measured memory_bytes: 3648
#include <stdio.h>
#include <string.h>

char change(char c){
	if(c>='a'&&c<='z'){
		return c-('a'-'A');
	}
	else return c;
}

int main(){
	char c;
	while(scanf("%c",&c)!=EOF){
		printf("%c",change(c));
	}
	//printf("\n");

	return 0;
}

Measured memory_bytes: 524
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	ans := 0
	for i := 1; i <= n; i++ {
		if i >= 1 && i <= 9 {
			ans++
		}
		if i >= 100 && i <= 999 {
			ans++
		}
		if i >= 10000 && i <= 99999 {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main(){
	int buildings[4][3][10] = { 0 }, n, b, f, r, v;
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> b >> f >> r >> v;
		if (b > 0 && b < 5 && f>0 && f < 4 && r>0 && r < 11){
			buildings[b - 1][f - 1][r - 1] += v;
			if (buildings[b - 1][f - 1][r - 1] < 0){
				buildings[b - 1][f - 1][r - 1] = 0;
			}
			else if (buildings[b - 1][f - 1][r - 1] >9){
				buildings[b - 1][f - 1][r - 1] = 9;
			}
			//buildings[b - 1][f - 1][r - 1] = (buildings[b - 1][f - 1][r - 1] < 0) ? 0 : (buildings[b - 1][f - 1][r - 1]>9) ? 9 : buildings[b - 1][f - 1][r - 1];
		}
	}
	for (int i = 0; i < 4; i++){
		for (int j = 0; j < 3; j++){
			for (int k = 0; k < 10; k++){
				cout << " " << buildings[i][j][k];
			}
			cout << endl;
		}
		if (i < 3){
			cout << "####################" << endl;
		}
	}
}


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

int main() {
  int a, b, c;

  scanf("%d %d %d", &a, &b, &c);

  int divisors_count;

  for(int num = a; (num <= c && num <= b); num++) {
    int remainder = c % num;

    if (remainder == 0) {
      divisors_count++;
    }
  }

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



Measured memory_bytes: 2756
#include <iostream>
#include <cstdio>
#include <string>

using namespace std;

int main() {
	string s1, s2;
	cin >> s1;
	cin >> s2;
	if (s1.length() > s2.length()) {
		printf("GREATER\n");
	}
	else if (s1.length() < s2.length()) {
		printf("LESS\n");
	}
	else {
			if (s1>s2) {
				printf("GREATER\n");
			}
			else if (s1<s2){
				printf("LESS\n");
			}
			else {
				printf("EQUAL\n");
			}
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007;
using ll = long long;
using namespace std;

int main(){
	int n, d; cin >> n >> d;
	cout << (n+(2*d+1)-1)/(2*d+1) << endl;
	return 0;
}

Measured memory_bytes: 256
while 1:
 n, x = map(int, input().split())
 counter = 0
 if n == 0 and x == 0:
  break
 # y + (y-1) + (y-2) = x 
 y = (x+3) // 3
 for a in range(y, n+1):
  for b in range(2, a):
   if (x-a-b) > 0 and (x-a-b) < b:
    counter += 1
 print(counter)
  

Measured memory_bytes: 7648
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        
        // 障害物のマスをキューに入れる
        char[][] board = new char[h][w];
        Queue<int[]> que = new ArrayDeque<int[]>();
        for (int i = 0; i < h; i++) {
            String str = sc.next();
            for (int j = 0; j < w; j++) {
                board[i][j] = str.charAt(j);
                if (board[i][j] == '#') {
                    que.add(new int[]{i, j, 0});
                }
            }
        }
        
        // visited[i][j]: 当該マスを既に通ったか否か
        boolean[][] visited = new boolean[h][w];
        
        // 上下左右
        int[] dx = new int[]{1, 0, -1, 0};
        int[] dy = new int[]{0, 1, 0, -1};
        
        // max = 障害物からの最短距離の最大値
        int max = 0;
        // 障害物から上下左右に1ずつ配り障害物にする
        while (!que.isEmpty()) {
            int[] cur = que.poll();
            int x = cur[0];
            int y = cur[1];
            int depth = cur[2];
            
            max = Math.max(max, depth);
            
            // 上下左右のマスに深さ+1を配ってキューに入れる
            for (int k = 0; k < 4; k++) {
                int nx = x + dx[k];
                int ny = y + dy[k];
                int ndepth = depth + 1;
                
                if (0 <= nx && nx < h && 0 <= ny && ny < w &&
                    board[nx][ny] == '.' && !visited[nx][ny]) {
                    que.add(new int[]{nx, ny, ndepth});
                    visited[nx][ny] = true;
                }
            }
        }
        System.out.println(max);
    }
}


Measured memory_bytes: 68528
import Foundation
let input = readLine()!.split(separator: " ").map { Int($0)! }

let M = input[0]
let K = input[1]

let N = 1 << M

if N <= K {
  print("-1")
} else if M == 1 && K != 0 {
  print("-1")
} else if M == 1 && K == 0 {
  print("0 0 1 1")
} else {
	var list = (0..<N).map { $0 }
	list.remove(at: K)
	list = list + [K] + list.reversed() + [K]
  	print(list.map { String($0) }.joined(separator: " "))
}

Measured memory_bytes: 20108
#include <bits/stdc++.h>
using namespace std;
const int N = 10000010;
bool pd[N];
int prime[N],tot;
void find_prime(){
	memset(pd,true,sizeof(pd));
	for(int i=2;i<N;i++){
		if(pd[i]) prime[++tot]=i;
		for(int j=1;j<=tot;j++){
			if(prime[j]*i>=N) break;
			pd[prime[j]*i]=false;
			if(i%prime[j]==0) break;
		}
	}
	pd[0] = pd[1]=pd[2]=false;
}
bool pd2[N];
int n,a[110];
vector<int> v[2];
vector<int> g[300];
bool flag[300];
int last[300];
bool find(int x){
	int t;
	for(int i = 0;i<g[x].size();i++) if(flag[t=g[x][i]]){
		flag[t] = false;
		if(last[t]==0) {
			last[t] = x+1;
			return true;
		} else if(find(last[t]-1)){
			last[t] = x+1;
			return true;
		}
	}
	return false;
}
int main(){
	find_prime();
	scanf("%d",&n);
	for(int i = 1;i<=n;i++)scanf("%d",a+i),pd2[a[i]]=true;
	for(int i = 1;i<N;i++) if(pd2[i]!=pd2[i-1]) v[i&1].push_back(i);
	for(int i = 0;i<v[0].size();i++){
		for(int j = 0;j<v[1].size();j++){
			if(pd[abs(v[0][i]-v[1][j])]) g[i].push_back(j);//puts("YYY");
		}
	}
	int tot = 0;
	//for(int i = 0;i<v[1].size();i++) cout<<v[1][i]<<endl;
	for(int i = 0;i<v[0].size();i++) {
		memset(flag,true,sizeof(flag));	
		if(find(i)) tot++;
	}
	//cout<<tot<<endl;
	printf("%d\n",tot+(v[0].size()-tot)/2*2+(v[1].size()-tot)/2*2+(v[0].size()-tot)%2*3);
	return 0;
}

Measured memory_bytes: 24192
import java.util.Arrays;
import java.util.Scanner;

public class Main{

	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int N;
		N = sc.nextInt();
		long[] A=new long[N];
		long[] B=new long[N];
		long[] C=new long[N];
		long sum=0;
		int ans=0;
		

		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
		}
		for (int i = 0; i < N; i++) {
			B[i] = sc.nextInt();
		}
		for (int i = 0; i < N; i++) {
			C[i] = A[i]-B[i];
		}
		for (int i = 0; i < N; i++) {
			sum=sum+C[i];
		}
		
		if(sum<0) {
			System.out.print("-1"); 
			}else {
				Arrays.sort(C);
long tar=0;
				for(int k=0;k<C.length;k++) {
					if(C[k]>=0)break;
					tar=tar+C[k];
					ans++;
				}
				for(int k=0;k<C.length;k++) {
					if(tar>=0)break;
					tar=tar+C[C.length-k-1];
					ans++;
		}
				System.out.print(ans); 
		
	}

	
	}
}




Measured memory_bytes: 88876
//Author: Fuadul Hasan(fuadul202@gmail.com)
//BSMRSTU,Gopalganj
#include<bits/stdc++.h>
using namespace std;int tc = 1;
#define happy ios::sync_with_stdio(false);
#define coding  cin.tie(0);
#define mp make_pair
#define ll long long
#define Pi atan(1)*4
#define pb  push_back
#define vpr vector<pr> 
#define pr pair<int, int> 
#define vi std::vector<int>
#define vll std::vector<ll>
#define YES printf("YES\n");
#define NO printf("NO\n");
#define Yes printf("Yes\n");
#define No printf("No\n");
#define all(n) n.begin(),n.end()
#define point(x) setprecision(x)
#define Test printf("Case %d: ",tc++);
#define Unique(c) (c).resize(unique(all(c))-(c).begin())
#define vout(v) for (auto z: v) cout << z << " "; cout << endl;

const int M = 1e9 + 7;
const ll  Inf = (ll)2e18 + 5;
const int N   = 2e5 + 5;

int solve() 
{
	//happy coding

	ll n,m,total;
	cin>>n>>m>>total;
	ll  v[n][m];
	ll cst[n+1];
	for(ll i=0;i<n;i++){
		cin>>cst[i];
		for(ll j=0;j<m;j++){
			cin>>v[i][j];
		}
	}
	ll mn = INT_MAX;
	for(ll i=0;i<(1<<n);i++){
		ll sumx = 0,sumcst = 0,sumarr[m];
		memset(sumarr,0,sizeof sumarr);
		for(ll j=0;j<n;j++){
			if(i&(1<<j)){
				sumcst += cst[j];
				for(ll k = 0;k<m;k++){
					sumarr[k] += v[j][k];
				}
			}
		}
		bool f = true;
		//vout(sumarr);
		for(int k = 0;k<m;k++){
			if(sumarr[k]<total){
				f = false;
			}
		}
		if(f){
			mn = min(mn,sumcst);
		}
	}

	cout<<((mn==INT_MAX)?(-1):(mn))<<endl;
	return 0;
}
int main(){
	int test = 1;
	//scanf("%d", &test);
	while (test--)solve();return 0;
}

Measured memory_bytes: 3624
#!usr/bin/env python3
import sys
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LIR(n):
    return [[i,LI()] for i in range(n)]

def solve():
    def add(i,x):
        while i < len(bit):
            bit[i] += x
            i += i&-i
    def sum_(i):
        res = 0
        while i > 0:
            res += bit[i]
            i -= i&-i
        return res
    n,Q = LI()
    c = LI()
    c = [0]+c
    q = LIR(Q)
    q.sort(key = lambda x:x[1][1])
    bit = [0]*(n+2)
    i = 1
    p = [None]*(n+1)
    ans = [0]*Q
    s = 0
    for ind,(l, r) in q:
        l -= 1
        while i <= r:
            ci = c[i]
            j = p[ci]
            if j is not None:
                add(j,1)
            else:
                s += 1
            p[ci] = i
            i += 1
        ans[ind] = s-l+sum_(l)
    for i in ans:
        print(i)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 236144
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

struct BIT{
private:
    vector<ll> a;
    int n;
public:
    BIT(int sz){
        n=sz;
        a.resize(sz+1);
    }
    ll sum(int i){
        ll res=0;
        while(i>0){
            res+=a[i];
            i-=i&-i;
        }
        return res;
    }
    ll sum(int i,int j){
        return sum(j)-sum(i-1);
    }
    void add(int i,ll x){
        while(i<=n){
            a[i]+=x;
            i+=i&-i;
        }
    }
};

int main(){
    int n;
    cin>>n;
    int a[n],b[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        cin>>b[i];
    }
    ll ans=LINF;
    using pa=pair<int,int>;
    for(int s=0;s<1<<n;s++){
        bool flag=true;
        vector<pa> ev;
        vector<pa> od;
        for(int i=0;i<n;i+=2){
            if((s>>i)&1)ev.push_back({a[i],i});
            else od.push_back({b[i],i});
        }
        for(int i=1;i<n;i+=2){
            if((s>>i)&1)od.push_back({a[i],i});
            else ev.push_back({b[i],i});
        }
        if(n%2==0&&ev.size()!=od.size()){
            continue;
        }
        if(n%2==1&&ev.size()!=od.size()+1){
            continue;
        }
        sort(ev.begin(),ev.end());
        sort(od.begin(),od.end());
        int t=-1;
        ll sum=0;
        BIT bit(n);
        for(int i=0;i<(n/2)*2;i++){
            if(i%2==0){
                if(t>ev[i/2].first){
                    flag=false;
                }
                t=ev[i/2].first;
                sum+=abs(ev[i/2].second+bit.sum(ev[i/2].second+1,n)-i);
                bit.add(ev[i/2].second+1,1);
            }
            else{
                if(t>od[i/2].first){
                    flag=false;
                }
                t=od[i/2].first;
                sum+=abs(od[i/2].second+bit.sum(od[i/2].second+1,n)-i);
                bit.add(od[i/2].second+1,1);
            }
        }
        if(n&1){
            if(t>ev.back().first){
                flag=false;
            }
        }
        if(flag){
            ans=min(ans,sum);
        }
    }
    if(ans==LINF)cout<<-1<<endl;
    else cout<<ans<<endl;
}

Measured memory_bytes: 384
package main

import (
	"bufio"
	"fmt"
	"io/ioutil"
	"log"
	"os"
	"strconv"
	"strings"
)

const debug = false

func (p *problem) solve() {
	l := p.NextInts()
	a, b, c := l[0], l[1], l[2]
	var opeN int
	for {
		log.Printf("ope=%v: a=%v, b=%v, c=%v\n", opeN, a, b, c)
		switch {
		case a == b && b == c:
			p.PrintInt(opeN)
			return
		case a < b && a < c:
			a += 2
		case b < a && b < c:
			b += 2
		case c < a && c < b:
			c += 2
		case a == b && a < c:
			a++
			b++
		case a == c && a < b:
			a++
			c++
		case c == b && c < a:
			c++
			b++
		default:
			panic(fmt.Errorf("a=%v, b=%v, c=%v is invalid numbers", a, b, c))
		}
		opeN++
	}
}

func main() {
	if debug {
		log.SetOutput(os.Stdout)
	} else {
		log.SetOutput(ioutil.Discard)
	}

	p := problem{
		in:  bufio.NewReader(os.Stdin),
		out: bufio.NewWriter(os.Stdout),
	}
	p.solve()

	if err := p.out.Flush(); err != nil {
		panic(err)
	}
}

type problem struct {
	in  *bufio.Reader
	out *bufio.Writer
}

func (p *problem) PrintInt(d int) {
	p.Printf("%d", d)
}

func (p *problem) Printf(format string, a ...interface{}) {
	if _, err := fmt.Fprintf(p.out, format, a...); err != nil {
		panic(err)
	}
}

func (p *problem) NextInt() int {
	return stoi(p.Next())
}

func (p *problem) NextInts() []int {
	line := p.NextSSLine()
	ds := make([]int, len(line))
	for i, s := range line {
		ds[i] = stoi(s)
	}
	return ds
}

func (p *problem) NextSSLine() []string {
	return strings.Split(p.Next(), " ")
}

// Next reads line and return string.
func (p *problem) Next() string {
	var b []byte
	for {
		l, pre, err := p.in.ReadLine()
		if err != nil {
			panic(err)
		}
		b = append(b, l...)
		if !pre {
			break
		}
	}
	return string(b)
}

func stoi(s string) int {
	i, err := strconv.Atoi(s)
	if err != nil {
		fmt.Println(i)
		fmt.Println(err)
	}
	return i
}


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

import numpy as np
a = np.array(a)
a1 = np.where(a == 1)[0][0]
ar = len(a) - a1 - 1
al = a1

if ar > al:
    while True:
        if ar % (k-1) == 0 or al % (k-1) == 0:
            break            
        ar -= 1
        al += 1

if ar <= al:
    while True:
        if ar % (k-1) == 0 or al % (k-1) == 0:
            break            
        ar += 1
        al -= 1


nr = int(np.ceil(ar / (k-1)))
nl = int(np.ceil(al / (k-1)))

ans = nr + nl

print(ans)

Measured memory_bytes: 23308
#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;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    ll a[n],ans=0;
    for(int i=0;i<n;i++){
    	cin>>a[i];
    }
    ll num,index;
    bool maki=1;
    while(maki){
    	maki=0;
    	for(int i=0;i<n;i++){
    	    if(a[i]>=n){
    	    	maki=true;
    	    	num=a[i]/n;
    	    	index=i;
    	    	a[i]%=n;
    	    	for(int i=0;i<n;i++){
        	        if(i==index)continue;
        	        a[i]+=num;
                }
                ans+=num;
    	    }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
A = list(map(int,input().split()))
l = []

m = 1000
k = 0

for i in range(n):
    if i == n-1: # 最後ながら全部売る
        m = m + A[i]*k
    elif A[i] <= m and A[i] < A[i+1]: #お金あって明日上がるなら買う
        k = m//A[i]
        m = m - A[i]*k
    elif 0 < k and A[i+1] < A[i]: #株があって明日下がるなら売る
        m = m + A[i]*k
        k = 0
    else:
        pass

print (m)


Measured memory_bytes: 9172
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from itertools import *
import random

S = input()
T = "gp" * len(S)
ans = 0
for s,t in zip(S,T):
    if t == 'g' and s == 'p':
        ans -= 1
    elif t == 'p' and s == 'g':
        ans += 1
print(ans)


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

static const int MAXN = 1e+3;
static const int MAXV = MAXN * (MAXN-1) / 2;
int mat[MAXN][MAXN], dp[MAXV];
vector<int> adj[MAXV];
bool visited[MAXV], calculated[MAXV];

// max length of path from s
int dfs(int u){
    if(visited[u]){
        if(!calculated[u]) return -1;
        return dp[u];
    }
    visited[u] = true;
    dp[u] = 1;
    for(int v : adj[u]){
        int res = dfs(v);
        if(res == -1) return -1;
        dp[u] = max(dp[u], res + 1);
    }
    calculated[u] = true;
    return dp[u];
}

int main(){
    int n;
    cin >> n;
    int cnt = 0, v = n * (n-1) / 2;
    rep(i, n) for(int j = i+1; j < n; j++){
        mat[i][j] = mat[j][i] = cnt;
        cnt++;
    }
    int a, prev_a;
    rep(i, n){
        scanf("%d", &prev_a);
        prev_a--;
        rep(_, n-2){
            scanf("%d", &a);
            a--;
            adj[mat[i][prev_a]].push_back(mat[i][a]);
            prev_a = a;
        }
    }
    rep(i, v){
        visited[i] = calculated[i] = false;
        dp[i] = 0;
    }
    int ans = 0;
    rep(i, v){
        int res = dfs(i);
        if(res == -1){
            ans = -1;
            break;
        }
        ans = max(ans, res);
    }
    cout << ans << "\n";
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int K,N; cin >> K >> N;
    vector<int> A(N);
    for (int i=0;i<N;++i) cin >> A[i];
    int M=0;
    for (int i=0;i<N;++i) M=max(M,(i!=N-1?A[(i+1)%N]-A[i]:A[(i+1)%N]+K-A[i]));
    cout << K-M << '\n';
}

Measured memory_bytes: 1024
import math

mod = 1000000007
n = int(input())
zero = 0
dic = {}
dic[(0, 1.5)] = 0
dic[(1.5, 0)] = 0
for i in range(n):
    ai, bi = map(int, input().split())
    idx = (ai, bi)
    if ai < 0:
        ai, bi = -ai, -bi
    if idx == (0, 0):
        zero += 1
    elif idx[0] == 0:
        dic[(0, 1.5)] += 1
    elif idx[1] == 0:
        dic[(1.5, 0)] += 1
    else:
        g = math.gcd(abs(ai), abs(bi))
        ai = ai // g
        bi = bi // g
        idx = (ai, bi)
        if idx in dic:
            dic[idx] += 1
        else:
            dic[idx] = 1

ans = 1
already = set([])
for key, value in dic.items():
    if key in already: continue
    a, b = key
    if a == 1.5 or b == 1.5:
        pair1 = dic[(0, 1.5)]
        pair2 = dic[(1.5, 0)]
        ans = (ans * (pow(2, pair1, mod)+pow(2, pair2, mod)-1)) % mod
        already.add((0, 1.5))
        already.add((1.5, 0))
    else:
        if b > 0: idx = (b, -a)
        else: idx = (-b, a)
        if idx in dic:
            pair1 = dic[key]
            pair2 = dic[idx]
            ans = (ans * (pow(2, pair1, mod)+pow(2, pair2, mod)-1)) % mod
            already.add(key)
            already.add(idx)
        else:
            pair1 = dic[key]
            ans = (ans * pow(2, pair1, mod)) % mod
            already.add(key)

ans = (ans + zero - 1) % mod
print(ans)

Measured memory_bytes: 59192
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long  long b){
    if(b == 0) return a;
    return gcd(b, a%b);
}

int main(){
    long long sum = 0;
    int K;
    cin >> K;
    for(int i =1; i <= K; i++){
        for(int j =1; j <= K; j++){
            for(int l = 1; l <= K; l++){
                sum += gcd(gcd(i, j), l);
            }
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 3664
#include<iostream>
#include<string>
#include<algorithm>
#include <string.h>
#include <stdio.h>
using namespace std;
int o=0;
int main()
{
    string s;
    cin>>s;
    if(s[0]=='A'&&s[1]>=97&&s[s.size()-1]>=97)
    {
        for(int i=2;i<s.size()-1;i++)
        {
            if(s[i]<97)
            {
                if(o==0&&s[i]=='C')
                    o++;
                else
                {
                    printf("WA\n");
                    return 0;
                }
            }
        }
        if(o==1)
        printf("AC\n");
        else
            printf("WA\n");
   }
   else
    printf("WA\n");
    return 0;

}


Measured memory_bytes: 256
n = gets.to_i
a = gets.split(" ").map(&:to_i)
puts a.join(" ")

(1...n).each {|i|
  v = a[i]
  j = i - 1
  while j >= 0 && a[j] > v
    a[j+1] = a[j]
    j -= 1
  end
  a[j+1] = v
  puts a.join(" ")
}

Measured memory_bytes: 8716
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}

int main()
{
    int H, W, K; cin >> H>>W>>K;
    vector<string> S(H); cin >> S;

    vector<vector<int>> acc(H, vector<int>(W, 0));
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            acc[i][j] = S[i][j]-'0';
            if (i != 0)
                acc[i][j] += acc[i-1][j];
            if (j != 0) {
                acc[i][j] += acc[i][j-1];
                if (i != 0) {
                    acc[i][j] -= acc[i-1][j-1];
                }
            }
        }
    }

    int ans = INT_MAX;

    for (int b = 0; b < (1<<(H-1)); b++) {
        bool next_b = false;
        int cut_cnt = __builtin_popcount(b);
        vector<int> hdiv;
        for (int i = 0; i < H; i++) {
            if ((b & (1 << i)) || i == H - 1) {
                hdiv.push_back(i);
            }
        }
        int prev_w = -1;
        for (int j = 0; j < W; j++) {
            for (int i = 0; i < hdiv.size(); i++) {
                
                int c = acc[hdiv[i]][j];
                if (prev_w >= 0) c -= acc[hdiv[i]][prev_w];
                if (i > 0) {
                    c -= acc[hdiv[i-1]][j];
                    if (prev_w >= 0) {
                        c += acc[hdiv[i-1]][prev_w];
                    }
                }
                
                if (c > K) {
                    if (j > 0 && prev_w != j - 1) {
                        cut_cnt++;
                        prev_w = j-1;
                        break;
                    } else {
                        next_b = true;
                    }
                }
            }
            if (next_b) { break; }
        }
        if (!next_b) ans = min(ans, cut_cnt);
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
A = list(map(int, input()))
while A[-1] == 0:
  A.pop()
n = len(A)
dp = [[0]*2 for _ in range(n)]
dp[0][1] = 1
for i, a in enumerate(A[:-1]):
  if i < n-1:
    dp[i+1][0] = min(dp[i][0]+a, dp[i][1]+10-a)
    dp[i+1][1] = min(dp[i][0]+a+1, dp[i][1]+9-a)
ans = min(dp[-1][0]+A[-1], dp[-1][1]+10-A[-1])
print(ans)

Measured memory_bytes: 176992
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

class dice {
  int dice[6];
  string state;
public:
  void input(void) {
    for (int i=0; i<6; i++) {
      cin >> dice[i];
    }
  }
  void move(void) {
    cin >> state;
    for (int i=0; i<state.length(); i++) {
      switch (state[i]) {
      case 'N':
        swap(dice[0],dice[1]);
        swap(dice[1],dice[5]);
        swap(dice[5],dice[4]);
        break;
      case 'S':
        swap(dice[0], dice[4]);
        swap(dice[4], dice[5]);
        swap(dice[5], dice[1]);
        break;
      case 'E':
        swap(dice[0], dice[3]);
        swap(dice[3], dice[5]);
        swap(dice[5], dice[2]);
        break;
      case 'W':
        swap(dice[0], dice[2]);
        swap(dice[2], dice[5]);
        swap(dice[5], dice[3]);
        break;
      default:
        break;
      }
    }
  }
  void output(void) {
    cout << dice[0] << endl;
  }
};

int main(void) {
  dice d;
  d.input();
  d.move();
  d.output();
  return 0;
}

Measured memory_bytes: 3140
N,M=map(int, input().split())

B=[]
for i in range(M):
    a,b=map(int, input().split())
    B.append((a,b))


B=sorted(B)
now=-1
pre=1
ans=0
for i in range(M):
    
    left,right=B[i]
    if i==0:
        now=left
        pre=right
        if i==M-1:
            ans+=1
        continue
    if i==M-1:
        ans+=1
    if now!=left and pre<=left:
        now=left
        ans+=1
        pre=right
    elif now!=left and pre>left:
        pre=min(pre,right)
        continue
    elif now==left:
        pre=min(pre,right)
    

print(ans)
#print(B)

Measured memory_bytes: 17804
def input_int_list():
    return [int(thing) for thing in input().split(" ")]
def No():
    print(-1)
    exit()
def eight(x):
    return int(x*0.08//1)
def ten(x):
    return int(x*0.1//1)

A,B=input_int_list()

for i in range(1,1009):
    if eight(i)==A and ten(i)==B:
        print(i)
        exit()
No()



Measured memory_bytes: 3064
import java.util.Scanner;

public class Main
{

	public static void main(String[] args)
	{
		Scanner in =new Scanner(System.in);
		
		int x=1;
		int i=1;
		while((x=in.nextInt())!=0)
		{
			
			System.out.println("Case "+ i + ": "+x);
			i++;
		}

	}
}

Measured memory_bytes: 41336
N=gets.to_i
ba=[]
N.times do
  a,b = gets.chomp.split.map(&:to_i)
  ba << [b,a]
end
ba.sort!

t = 0
ba.each do |b,a|
  t += a
  if b < t
    puts "No"
    exit
  end
end
puts "Yes"

Measured memory_bytes: 18552
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	char c; cin >> c;
	cout << char(c + 1) << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    //template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
    //template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

    class Node{
    public:
        int location;
        int p, l, r;
        Node() {};
    };

    class Point{
    public:
        int id, x, y;
        Point(){}
        Point(int id, int x, int y): id(id), x(x), y(y){}
        bool operator < (const Point &p) const {
            return id < p.id;
        }

        void print() {
            printf("%d\n", id);
        }
    };

    static const int MAX = 10000000;
    static const int NIL = -1;

    int N;
    Point P[MAX];
    Node T[MAX];
    int np;

    bool lessX(const Point &p1, const Point &p2) {return p1.x < p2.x;}
    bool lessY(const Point &p1, const Point &p2) {return p1.y < p2.y;}

    int makeKDTree(int l, int r, int depth){
        if(!(l < r)) return NIL;
        int mid = (l + r)/2;
        int t = np++;
        if(depth%2 == 0){
            sort(P+l, P+r, lessX);
        }
        else{
            sort(P+l, P+r, lessY);
        }

        T[t].location = mid;
        T[t].l = makeKDTree(l, mid, depth+1);
        T[t].r = makeKDTree(mid+1, r, depth+1);

        return t;
    }

    void find(int v, int sx, int tx, int sy, int ty, int depth, vector<Point> &ans){
        int x = P[T[v].location].x;
        int y = P[T[v].location].y;

        if(sx <= x && x <= tx && sy <= y && y<= ty){
            ans.push_back(P[T[v].location]);
        }

        if(depth%2 == 0){
            if(T[v].l != NIL){
                if(sx <= x) find(T[v].l, sx, tx, sy, ty, depth+1, ans);
            }
            if(T[v].r != NIL){
                if(x <= tx) find(T[v].r, sx, tx, sy, ty, depth+1, ans);
            }
        }
        else{
            if(T[v].l != NIL){
                if(sy <= y) find(T[v].l, sx, tx, sy, ty, depth+1, ans);
            }
            if(T[v].r != NIL){
                if(y <= ty) find(T[v].r, sx, tx, sy, ty, depth+1, ans);
            }
        }
    }

    int main(){
        int x, y;
        scanf("%d", &N);
        for(int i=0; i<N; i++){
            scanf("%d %d", &x, &y);
            P[i] = Point(i, x, y);
            T[i].l = T[i].r = T[i].p = NIL;
        }

        np = 0;

        int root = makeKDTree(0, N, 0);

        int q;
        scanf("%d", &q);
        int sx, tx, sy, ty;
        vector<Point> ans;
        for(int i=0; i<q; i++){
            scanf("%d %d %d %d", &sx, &tx, &sy, &ty);
            ans.clear();
            find(root, sx, tx, sy, ty, 0, ans);
            sort(ans.begin(), ans.end());
            for(int j=0; j<ans.size(); j++){
                ans[j].print();
            }
            printf("\n");
        }
    }


Measured memory_bytes: 16420
/// @file
/// @copyright 2018 thousand
/// @version Accepted.
#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
using std::max_element;
using std::string;
using std::stringstream;
using std::vector;

namespace {
class Ints : public vector<int> {
 public:
  string str();
};
class Intss : public vector<Ints> {
 public:
  string str(string delimiter);
};
class Intsss : public vector<Intss> {
 public:
  string str();
};
string Ints::str() {
  stringstream ss;
  for (auto it = this->begin(); it != this->end(); ++it) {
    ss << *it;
    if (it != this->end() - 1) ss << " ";
  }
  return ss.str();
}
string Intss::str(string delimiter="\n") {
  stringstream ss;
  for (auto it = this->begin(); it != this->end(); ++it) {
    ss << it->str();
    if (it != this->end() - 1) ss << delimiter;
  }
  return ss.str();
}
string Intsss::str() {
  stringstream ss;
  for (auto it = this->begin(); it != this->end(); ++it) {
    ss << it->str(" ");
    if (it != this->end() - 1) ss << endl;
  }
  return ss.str();
}
void GetInput(int* N, Intsss* F, Intss* P) {
  cin >> *N;
  for (int i = 1; i <= *N; ++i) {
    Intss intss;
    for (int j = 1; j <= 5; ++j) {
      Ints ints;
      for (int k = 1; k <= 2; ++k) {
        ints.push_back(-1);
        cin >> *--ints.end();
      }
      intss.push_back(ints);
    }
    (*F).push_back(intss);
  }
//  cout << F->str() << endl;
  for (int i = 1; i <= *N; ++i) {
    Ints ints;
    for (int j = 0; j <= 10; ++j) {
      ints.push_back(-1);
      cin >> *--ints.end();
    }
    (*P).push_back(ints);
  }
//  cout << P->str() << endl;
}
void Solve(int N, Intsss& F, Intss& P) {
  Ints profits;
  for (int b = 1; b <= 1023; ++b) {  // for each case.
    int P_sum = 0;
    for (int i = 0; i < N; ++i) {
      // "Let c_i be the number of periods during which both Shop i"
      // "and Joisino's shop are open."
      int c_i = 0;
      for (int j = 0; j < 5; ++j) {
        for (int k = 0; k < 2; ++k) {
          bool open_shop_i = F[i][j][k];
          bool open_Joisino = (b >> (2 * j + k) & 1);
          if (open_shop_i && open_Joisino) ++c_i;
        }
      }
      P_sum += P[i][c_i];
    }
    profits.push_back(P_sum);
  }
  cout << *max_element(profits.begin(), profits.end()) << endl;
}
}  // namespace

int main() {
  int N;
  Intsss F;
  Intss P;
  GetInput(&N, &F, &P);
  Solve(N, F, P);
}


Measured memory_bytes: 256
#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 reps(i,a,b) for(int i= a; i < b; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int n, k, r, s, p;
  string t;
  cin >> n >> k >> r >> s >> p >> t;
  vector<int> vec(n);
  vector<int> pts = {r, s, p};
  rep(i, n) {
    if (t.at(i) == 'r') vec.at(i) = 2;
    if (t.at(i) == 's') vec.at(i) = 0;
    if (t.at(i) == 'p') vec.at(i) = 1;
  }
  vector<vector<int>> dp(n, vector<int>(3));
  rep(i,k) {
    dp.at(i).at(vec.at(i)) = pts.at(vec.at(i));
    for (int j = i + k; j < n; j += k) {
      for (int m = 0; m < 3; m++) {
        if (vec.at(j) == m) {
          dp.at(j).at(m) = max(dp.at(j-k).at((m+1)%3), dp.at(j-k).at((m+2)%3)) + pts.at(m);
        } else {
          dp.at(j).at(m) = max(dp.at(j-k).at((m+1)%3), dp.at(j-k).at((m+2)%3));
        }
      }
    }
  }
  ll ans = 0;
  for (int i = n-1; i > n-k-1; i--) {
    ans += max(dp.at(i).at(0), max(dp.at(i).at(1), dp.at(i).at(2)));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 9304
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
#define sz size()
#define bgn begin()
#define en end()
#define pb push_back
#define pp() pop_back()
#define V vector
#define P pair
#define yuko(a) setprecision(a)
#define uni(a) a.erase(unique(a.begin(),a.end()),a.end())
#define Q queue
#define pri priority_queue
#define Pri priority_queue<int,vector<int>,greater<int>>
#define PriP priority_queue<P<int,int>,vector<P<int,int>>,greater<P<int,int>>>
#define ff first.first
#define fs first.second
#define sf second.first
#define ss second.second
#define all(a)  (a).begin(),(a).end()
#define elif else if


int low(V<int> a,int b){
  decltype(a)::iterator c=lower_bound(a.begin(),a.end(),b);
  int d=c-a.bgn;
  return d;
}
int upp(V<int> a,int b){
  decltype(a)::iterator c=upper_bound(a.begin(),a.end(),b);
  int d=c-a.bgn;
  return d;
}
int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
}
int gcd(int a,int b){
  if(a%b==0)
    return b;
  return gcd(b,a%b);
}
int ketas(int a){
  string b=to_string(a);
  int c=0;
  fo(i,keta(a)){
    c+=b[i]-'0';
  }
  return c;
}
int INF=1000000007;
int kaijou(int a){
  int b=1;
  fo(i,a)
    b*=i+1;
  return b;
}

V<P<int,int>> factorize(int n){
  V<P<int,int>> res;
  for(int i=2; i*i<=n; i++){
    if(n%i)
      continue;
    res.emplace_back(i,0);
    while(n%i==0){
      n/=i;
      res.back().second++;
    }
  }
  if(n!=1)
    res.emplace_back(n,1);
  return res;
}
int pow_kai(int a, int b){
  int c=1;
  while(b>0){//bit全部捨てるまで
    if(b%2){//一番右のbitが1
      c=c*a;
    }
    a=a*a;
    b>>=1;//全体右に1つシフト
  }
  return c;
}

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


signed main(){
  int n,p;
  cin>>n>>p;
  V<int> a(n);
  fo(i,n){
    cin>>a[i];
  }
  int b=1;//全部2で割れたらtrue 1つでも奇数があったらfalse
  fo(i,n){
    if(a[i]%2){
      b=0;
      break;
    }
  }
  if(p==0&&b==1){
    cout<<pow_kai(2,n)<<endl;
    return 0;
  }
  if(p==1&&b==1){
    cout<<0<<endl;
    return 0;
  }
  int c=pow_kai(2,n-1);
  cout<<c<<endl;
}

Measured memory_bytes: 256
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define _LIBCPP_DEBUG 0
using namespace std;
int64_t MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int x_1, y_1, x_2, y_2;
  cin >> x_1 >> y_1 >> x_2 >> y_2;

  int x_3 = x_2 - (y_2 - y_1);
  int y_3 = y_2 + (x_2 - x_1);
  int x_4 = x_1 - (y_2 - y_1);
  int y_4 = y_1 + (x_2 - x_1);

  cout << x_3 << " " << y_3 << " " << x_4 << " " << y_4 << endl;
  return 0;
}
//templete by private_yusuke

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin>>n;
  bool judge=true;
  rep(i,n){
    int a=0; cin>>a;
    if(a%2==0) if(!((a%3==0)||(a%5==0))) judge=false;
  }
  (judge)?cout<<"APPROVED"<<endl:cout<<"DENIED"<<endl;
}


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

typedef long long ll;
typedef pair<int,int> P;
int dx[] = {-1, 1, 0,  0};
int dy[] = { 0, 0, 1, -1};
 
int main(){
  int h, w;
  cin >> h >> w;
  vector<vector<int>> a(50, vector<int>(50, 0));
  for(int i=0; i<h; i++){
    for(int j=0; j<w; j++){
      char b;
      cin >> b;
      if(b=='#'){
        a[i][j] = 1;
      }
    }
  }
  int cnt = 0;
  for(int i=0; i<h; i++){
    for(int j=0; j<w; j++){
      if(a[i][j]){
        bool ok = false;
        for(int k=0; k<4; k++){
          int nx = i + dx[k];
          int ny = j + dy[k];
          if(nx<0 || nx>=h || ny<0 || ny>=w) continue;
          if(a[nx][ny]) ok = true;
        }
        if(!ok){
          cout << "No" << endl;
          return 0;
        }
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
/**
 * A - 9x9
 * https://atcoder.jp/contests/abc144/tasks/abc144_a
 */
#include <bits/stdc++.h>
using namespace std;

int main() {
  int A, B;
  cin >> A >> B;
  if (A < 10 && B < 10) {
    cout << A * B << endl;
  } else {
    cout << "-1" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
  string h,s="CODEFESTIVAL2016";
  cin>>h;
  int count=0;
  for(int i=0;i<h.length();++i){
    if(h[i]!=s[i]) count++;
  }
  cout<<count<<endl;
}

Measured memory_bytes: 256
n, f = map(int, input().split())
a = {}
for _ in range(n):
    m, *c = input().split()
    m = int(m)
    for i in range(m - 1):
        for j in range(i + 1, m):
            p = (min(c[i], c[j]), max(c[i], c[j]))
            if p in a:a[p] += 1
            else:a[p] = 1
b = []
for k in a:
    if a[k] >= f:b.append((k,a[k]))
b.sort(key = lambda x:x[0][1])
b.sort(key = lambda x:x[0][0])
print(len(b))
for i in b:print(*i[0])


Measured memory_bytes: 6392
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i, n) for (int i=0; i<n; ++i)
#define all(obj) (obj).begin(),(obj).end()
using namespace std;
typedef long long ll;
long long GCD(long long x, long long y) { return y ? GCD(y, x%y) : x; }

int main(){
    string s;
    cin >> s;
    int cnt = 0;
    string kaibun = s;
    reverse(kaibun.begin(), kaibun.end());
    rep(i, s.length()){
        if(s[i]!=kaibun[i]) cnt++;
    }
    cout << cnt/2 << endl;
    return 0;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll read(){
	ll a=0,b=getchar(),c=1;
	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();
	while(isdigit(b))a=a*10+b-'0',b=getchar();
	return a*c;
}
ll n,k,j,mod=1e9+7,a[2000005]={1};
string s;
ll jj(ll x,ll y){
	ll res=1;
	while(y){
		if(y%2)res=(res*x)%mod;
		x=x*x%mod,y/=2;
	}
	return res;
}
ll gg(ll n,ll r){
	ll n1=a[n],n2=a[n-r],n3=a[r];
	n2=n2*n3%mod;
	n3=jj(n2,mod-2);
	n1=n1*n3%mod;
	return n1;
}
int main(){
	for(int i=1;i<2e6+5;i++)
		a[i]=i*a[i-1]%mod;
	k=read();
	cin >> s;
	n=s.size(),j=jj(26,k+n);
	ll xx=n+k,j1=0;
	for(int i=0;i<n;i++){
		ll x=gg(xx,i),y=jj(25,xx-i);
		x*=y,x%=mod;
		j1+=x,j1%=mod;
	}
	j=(j-j1+mod)%mod;
	cout << j;
	return 0;
}

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

int main(){
    char s[100];
    cin>>s;
    int max=0;
    int ans=0;
    int len=strlen(s);
    for(int i=0;i<len;i++){
        if(s[i]=='A'||s[i]=='T'||s[i]=='G'||s[i]=='C') {
            int j = i + 1;
            ans=1;
            while (s[j] == 'A' || s[j] == 'T' || s[j] == 'G' || s[j] == 'C') {
                ans++;
                j++;
            }
        }
        if(ans>max) max=ans;
    }
    cout<<max<<endl;
}

Measured memory_bytes: 256