akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
using namespace std;

string s[1000];
int cnt=0;

void dfs(string str,int a,int b,int j,int y){
  if(a==j && b==y){
    bool flag=0;
    for(int i=0; i<cnt; i++){
      if(s[i]==str){
        flag++;
      }
    }
    if(flag==0){
      s[cnt]=str;
      cnt++;
    }
  }

  string str1=str;
  string str2=str;

  if(a>=4 && b>=4){
    if(a<j){
      str1.push_back('A');
      dfs(str1,a+1,b,j,y);
    }
    if(b<y){
      str2.push_back('B');
      dfs(str2,a,b+1,j,y);
    }
  }else{
    if(a==4 && b<y){
      str1.push_back('B');
      dfs(str1,a,b+1,j,y);
    }else if(a<j){
      str1.push_back('A');
      dfs(str1,a+1,b,j,y);
    }
    if(b==4 && a<j){
      str2.push_back('A');
      dfs(str2,a+1,b,j,y);
    }else if(b<y){
      str2.push_back('B');
      dfs(str2,a,b+1,j,y);
    }
  }
}

int main(){
  int j,y;
  cin >> j >> y;

  string str;

  dfs(str,0,0,j,y);

  for(int i=0; i<cnt; i++){
    cout << s[i] << '\n';
  }

  return 0;
}



Measured memory_bytes: 3216
n=int(input())
t=tuple(map(int,input().split()))
while True:
  if t[0]!=0:
    print(0)
    break
  m=max(t)
  a=[0]*(m+1)
  for i in range(n):
    a[t[i]]+=1
  a=tuple(a)
  if a[0]!=1:
    print(0)
    break
  s=1
  for i in range(m):
    s=(s*(a[i]**a[i+1]))%998244353
  print(s)
  break

Measured memory_bytes: 14148
#include <cstdio>
#include <algorithm>

const int MN = 100005;

int N, A[MN];

int main() {
	scanf("%d", &N);
	for (int i = 1; i <= N; ++i) scanf("%d", &A[i]);
	int mx = *std::max_element(A + 1, A + N + 1);
	int mn = *std::min_element(A + 1, A + N + 1);
	if (mx == mn) {
		if (mx == N - 1) puts("Yes");
		else if (mx > N / 2) puts("No");
		else puts("Yes");
		return 0;
	}
	if (mx - mn >= 2) return puts("No"), 0;
	int cnt = 0;
	for (int i = 1; i <= N; ++i) if (A[i] == mn) ++cnt;
	puts(mx <= cnt || mx > cnt + (N - cnt) / 2 ? "No" : "Yes");
	return 0;
}

Measured memory_bytes: 2016
#include<iostream>
#include<stdio.h>
#include<vector>//s1.erase(n)=文字列s1の、n文字目以降削除
#include<algorithm>//辞書順=next_permutation
#include<set>
#include<string>//char 小文字のほうが32大きい
#include<sstream>
#include<string.h>
#include<complex>
#include<time.h>
#include<random>
#include<cmath>
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swap=数値交換
#define rt "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(s,n) rep(i,n)cin>>s[i];//vcin(配列名),(繰り返し回数)
#define sort(s) sort(s.begin(),s.end())//標準=昇順
#define reve(s) reverse(s.begin(),s.end())
#define asas int ans=0
#define llcncn llint cnt=0
#define llasas llint ans=0
#define str string
#define please return
#define AC 0
#define ic_a int a;cin>>a;
#define ic_b int b;cin>>b;
#define ic_s string s;cin>>s;
#define Rapid_pleaseAC_fast cin.tie(0);ios::sync_with_stdio(false)
#define Pi 3.1415926535897932384626
#define nine 1000000000

using namespace std;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<double> vdou;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<bool>> vvbool;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;
typedef long double ld;
const ld eps = 1.0e-10; // 許容される誤差
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

unsigned GetDigit(unsigned num) {
	return std::to_string(num).length();
}

int tow(int n) {//2のn乗
	if (n == 0)return 1;
	int x = tow(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;//@domino
}

int keta(int n) {
	int sum = 0;
	while (n != 0) {
		sum += n % 10; n /= 10;
	}
	return sum;//Nanashi,tRue,wai
}

/*

 (char)toupper(a[n])=文字列のn文字目を大文字で出力

  pow(a,b)=aのb乗

  */
ld mysqrtl(ld x)
{
	ld a = sqrtl((double)x); // 近似値
	do {
		a = (a + x / a) / 2.0L;
	} while (fabsl(x - a * a) > eps);
	return a;
}

//平方根を求める。sqrtより精度が高い。
//epsを変えて誤差を調整する。
int main(void) {
	Rapid_pleaseAC_fast;
	llint ans = 0, n = 0, m, count, sum = 0, ch = 0;
	llint s, a, aa, aaa, rr = 0, gg = 0, bb = 0;
	bool check = false;

	vector<llint> r, g, b;
	char c;
	cin >> a>>aa;
	if (a + aa >= 10)cout << "error" << endl;
	else cout << a+aa << endl;
	please AC;
}


Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as BS

uo=1000000007
h l k |k==1   =mod l uo
      |even k =h(mod(l*l)uo)(quot k 2)
      |odd k  =mod((h l (k-1))*l)uo

main=do
 n<-readLn;a<-map (read.BS.unpack).BS.words<$>BS.getLine
 print(f n a (g n a 1) 0)
  where g 0 _ l = mod l uo
        g n (k:a) l = g (n-1) a (lcm k l)
        f 0 _ _ i = i
        f n (k:a) l i = f (n-1) a l (mod(i+l*(h k (uo-2)))uo)

Measured memory_bytes: 6524
mod = 998244353

A, B, C, D = map(int, input().split())

dp = [0] * B + [pow(A, i, mod) for i in range(D + 1 - B)]
for a in range(A + 1, C + 1):
    T = [0] * (D + 1)
    for b in range(B, D + 1):
        T[b] = (a * T[b - 1] + b * dp[b] - (a - 1) * (b - 1) * dp[b - 1]) % mod
    dp = T

print(dp[D])

Measured memory_bytes: 73772
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        private static bool AKB(string S)
        {
            return Regex.IsMatch(S, "^A?KIHA?BA?RA?$");
        }

        static void Main(string[] args)
        {
            Console.WriteLine(AKB(Read()) ? "YES" : "NO");
        }
    }
}


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

#define int long long
// typedef __int128_t Int;
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

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

  int a, b, c, k;
  cin >> a >> b >> c >> k;
  cout << (a - b) * (k & 1 ? -1 : 1) << endl;

  return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair 
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<n;i++)

int main(){
	//input
	string s; cin>>s;

	//solve
	if(sz(s)<4) cout<<"No";
	else{
		string t="";
		rep(i,4){
			t+=s[i];
		}
		if(t=="YAKI") cout<<"Yes";
		else cout<<"No";
	}
}

Measured memory_bytes: 256
Ss = input()
Ts = input()

Ass = [[0] * 26 for _ in range(26)]

ordA = ord('a')
for S, T in zip(Ss, Ts):
    ordS = ord(S) - ordA
    ordT = ord(T) - ordA
    Ass[ordS][ordT] = 1

if max(map(sum, Ass)) > 1:
    print('No')
elif max(map(sum, list(zip(*Ass)))) > 1:
    print('No')
else:
    print('Yes')


Measured memory_bytes: 3632
#include <stdio.h>
#define MAX_N 40
#define MAX_A 10
#define MAX_B 10
#define INF 1000000007

int min(int x, int y) {
    return (x < y) ? x : y;
}

int main() {
    int n, ma, mb;
    scanf("%d %d %d", &n, &ma, &mb);

    int dp[MAX_N * MAX_A + 1][MAX_N * MAX_B + 1];
    for (int i = 0; i <= MAX_N * MAX_A; i++) {
        for (int j = 0; j <= MAX_N * MAX_B; j++) {
            dp[i][j] = INF;
        }
    }
    dp[0][0] = 0;
    for (int k = 0; k < n; k++) {
        int a, b, c;
        scanf("%d %d %d", &a, &b, &c);
        for (int i = MAX_N * MAX_A; i >= a; i--) {
            for (int j = MAX_N * MAX_B; j >= b; j--) {
                dp[i][j] = min(dp[i][j], dp[i - a][j - b] + c);
            }
        }
    }
    int ans = INF;
    for (int ia = ma, ib = mb; ia <= MAX_N * MAX_A && ib <= MAX_N * MAX_B; ia += ma, ib += mb) {
        ans = min(dp[ia][ib], ans);
    }
    printf("%d\n", (ans == INF) ? -1 : ans);
    return 0;
}


Measured memory_bytes: 768
#include<stdio.h>
    int main()
    {
        int N,i,j,k;
        j = 1001;
        k = -1;
        int data[1001];
        scanf("%d",&N);
        for(i = 0;i < N;i++){
        scanf("%d",&data[i]);
        if(data[i] < j) j = data[i];
        if(data[i] > k) k = data[i];
        }
        printf("%d\n",k-j);
        return 0;
    }

Measured memory_bytes: 128
today = input()

if today == 'SUN' :
	ans = 7
if today == 'MON' :
	ans = 6
if today == 'TUE' :
	ans = 5
if today == 'WED' :
	ans = 4
if today == 'THU':
	ans = 3
if today == 'FRI' :
	ans = 2
if today == 'SAT' :
	ans = 1

print(ans)

Measured memory_bytes: 3060
import java.util.Scanner;

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

    long N = scanner.nextLong();
    if (N % 2 == 1) {
      System.out.println(0);
      return;
    }
    long res = 0;
    long a = 1;
    for (int i = 0; i < 25; i++) {
      a *= 5;
      res += N / a / 2;
    }
    System.out.println(res);
  }
}


Measured memory_bytes: 23764
from itertools import product
N = int(input())
F = [list(map(int,input().split())) for _ in range(N)]
P = [list(map(int,input().split())) for _ in range(N)]

x = list(product(range(2), repeat = 10))
x.remove(tuple([0]*10))

ans = float('-inf')
for i in range(len(x)):
  p = 0
  for j in range(N):
    c = 0
    for k in range(10):
      if x[i][k] == 1 and F[j][k]== 1:
        c += 1
    p += P[j][c]
  if ans < p:
    ans = p
print(ans)

Measured memory_bytes: 3188
#include <iostream>
#include <cstdlib>

int main() {
  long N;
  std::cin >> N;

  long prev=0;
  long step=0;

  for (size_t i=0; i<N; i++) {
    long a;
    std::cin >> a;

    if (a > i || a > prev+1) {
      std::cout << -1 << std::endl;
      std::exit(EXIT_SUCCESS);
    }

    if (a == prev+1) {
      step+=1;
    } else {
      step+=a;
    }

    prev=a;
  }

  std::cout << step << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define fi first
#define se second
#define int long long
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;

int h, w, n;
int t[500 * 500];
int u[500 * 500][50];
int sp[500 * 500];

bool check(int m){
    set<int> st;
    rep(i, 0, n){
        int p = sp[i];
        rep(j, 0, 50){
            if(m & ((int)1 << j)) p = u[p][j];
        }
        if(st.count(p) > 0) return true;
        st.insert(p);
    } 
    return false;
}

signed main(){
    cin >> h >> w >> n;
    rep(i, 0, h){
        rep(j, 0, w){
            int y, x;
            cin >> y >> x;
            t[i * w + j] = y * w + x;
        }
    }
    rep(i, 0, n){
        int y, x;
        cin >> y >> x;
        sp[i] = y * w + x;
    }
    rep(i, 0, h * w){
        u[i][0] = t[i];
    }
    rep(k, 1, 50){
        rep(i, 0, h * w){
            u[i][k] = u[u[i][k - 1]][k - 1];
        }
    }
    int l = 0, r = ((int)1<<45), m;
    if(check(r) == false){
        cout << -1 << endl;
        return 0;
    }
    while(l < r){
        m = (l + r) / 2;
        if(check(m)) r = m;
        else l = m + 1;
    }
    cout << l << endl;
}

Measured memory_bytes: 116356
package main

import (
	"bufio"
	"container/list"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

const (
	BUFSIZE   = 10000000
	MOD       = 1000000007
	INF_INT   = math.MaxInt32
	INF_INT64 = math.MaxInt64
)

var rdr *bufio.Reader

func main() {
	rdr = bufio.NewReaderSize(os.Stdin, BUFSIZE)
	solve()
}

func solve() {
	N := readint()
	var S, T string
	fmt.Scanf("%s %s", &S, &T)
	row := strings.Split(readline(), " ")
	S = row[0]
	T = row[1]
	ans := list.New()

	for i := 0; i < N; i++ {
		ans.PushBack(string(S[i]))
		ans.PushBack(string(T[i]))
	}

	for e := ans.Front(); e != nil; e = e.Next() {
		fmt.Print(e.Value)
	}
	fmt.Println()
}

func readline() string {
	buf := make([]byte, 0, BUFSIZE)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			fmt.Println(e.Error())
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func readIntSlice(size int) []int {
	slice := make([]int, size)
	lines := strings.Split(readline(), " ")
	for i, v := range lines {
		slice[i] = s2i(v)
	}
	return slice
}

func readInt64Slice(size int) []int64 {
	slice := make([]int64, size)
	lines := strings.Split(readline(), " ")
	for i, v := range lines {
		slice[i] = s2i64(v)
	}
	return slice
}

func readint() int {
	return s2i(readline())
}

func readint64() int64 {
	return s2i64(readline())
}

// For int64
func b2i64(b bool) int64 {
	if b {
		return 1
	}
	return 0
}

func abs64(v int64) int64 {
	if v < 0 {
		return -v
	}
	return v
}

func min64(values ...int64) int64 {
	ret := int64(INF_INT64)
	for _, v := range values {
		if ret > v {
			ret = v
		}
	}
	return ret
}

func max64(values ...int64) int64 {
	ret := -int64(INF_INT64)
	for _, v := range values {
		if ret < v {
			ret = v
		}
	}
	return ret
}

func s2i64(s string) int64 {
	v, ok := strconv.ParseInt(s, 10, 64)
	if ok != nil {
		panic("Faild : " + s + " can't convert to int64")
	}
	return v
}

// For int
func b2i(b bool) int {
	if b {
		return 1
	}
	return 0
}

func abs(v int) int {
	if v < 0 {
		return -v
	}
	return v
}

func min(values ...int) int {
	ret := INF_INT
	for _, v := range values {
		if ret > v {
			ret = v
		}
	}
	return ret
}

func max(values ...int) int {
	ret := -INF_INT
	for _, v := range values {
		if ret < v {
			ret = v
		}
	}
	return ret
}

func s2i(s string) int {
	v, ok := strconv.Atoi(s)
	if ok != nil {
		panic("Faild : " + s + " can't convert to int")
	}
	return v
}

/* ------------------------------------------------ */
/* Data stracture                                   */
/* ------------------------------------------------ */
type IntHeap []int

func (h *IntHeap) Push(x interface{}) {
	*h = append(*h, x.(int))
}

func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

func (h IntHeap) Len() int           { return len(h) }
func (h IntHeap) Less(i, j int) bool { return h[i] < h[j] }
func (h IntHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }


Measured memory_bytes: 12432
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines

# rstrip().decode('utf-8')
# map(int,input().split())
# import numpy as np

from collections import defaultdict

def main():
	d=defaultdict(int)
	
	n=int(input())
	A=list(map(int,input().split()))
	for x in A:
		d[x]+=1
	
	li=[]
	li2=[]
	for k,v in d.items():
		if v>=2:
			li.append(k)
		if v>=4:
			li2.append(k)

	li.sort(reverse=True)
	li2.sort(reverse=True)
	
	if len(li)<=1 and len(li2)==0:
		print(0)
	elif len(li)>=2 and len(li2)>=1:
		print(max(li[0]*li[1],li2[0]**2))
	elif len(li)>=2:
		print(li[0] * li[1])
	else:
		print(li2[0]**2)
	

if __name__ == "__main__":
	main()


Measured memory_bytes: 18360
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		int N=in.nextInt();
		int A[]=new int[N];
		for(int i=0;i<N;i++)A[i]=in.nextInt();
		Arrays.sort(A);
		if(A[0]!=0&&N%2==1){
			System.out.println(0);
			System.exit(0);
		}
		for(int i=N-1;i>0;i-=2){
			if(A[i]!=A[i-1]){
				System.out.println(0);
				System.exit(0);
			}
		}
		long ans=1;
		for(int i=0; i<N/2; i++)ans = 2*ans%1000000007;
		System.out.println(ans);

		in.close();
	}

}


Measured memory_bytes: 32140
N, W = map(int, input().split())
INF = float('inf')
MAX_V = 100100

dp = [[INF for _ in range(MAX_V+1)] for _ in range(N+1)]
dp[0][0] = 0
weight = []
value = []
for i in range(N):
    w, v = map(int, input().split())
    weight.append(w)
    value.append(v)

for i in range(N):
    for sum_v in range(MAX_V + 1):
        # i 番目の品物を選ぶ場合
        if sum_v - value[i] >= 0:
            dp[i+1][sum_v] = min(dp[i+1][sum_v], dp[i][sum_v - value[i]] + weight[i])
        # i 番目の品物を選ばない場合
        dp[i+1][sum_v] = min(dp[i+1][sum_v], dp[i][sum_v])

ans = 0
for sum_v in range(MAX_V + 1):
    if dp[N][sum_v] <= W:
        ans = sum_v

print(ans)


Measured memory_bytes: 332220
use std::io::{stdout, BufWriter, Write};
use std::str::FromStr;
use std::thread;

fn run() {
    let stdin = std::io::stdin();
    let mut input = String::new();
    stdin.read_line(&mut input).ok();

    let in_n: i64 = input.trim().parse().unwrap();

    let mut input = String::new();
    stdin.read_line(&mut input).ok();
    let in_x: Vec<u64> = input
        .split_whitespace()
        .map(|s| u64::from_str(s).unwrap())
        .collect();

    let mut y = in_x.clone();
    y.sort();
    let x1 = y[in_n as usize / 2 - 1];
    let x2 = y[in_n as usize / 2];

    let mut out = stdout();
    let mut out = BufWriter::new(out.lock());
    for x in in_x {
        writeln!(out, "{}", if x <= x1 { x2 } else { x1 }).unwrap();
    }
}

fn main() {
    thread::Builder::new()
        .stack_size(32 * 1024 * 1024) // 32MB
        .spawn(run)
        .unwrap()
        .join()
        .unwrap();
}

/// ローカル環境なら _in.txt から入力を受ける
fn read_input() -> String {
    use std::fs::File;
    use std::io::Read;
    let mut s = String::new();
    match option_env!("LOCAL") {
        Some(_) => File::open("src/_in.txt")
            .expect("File not found")
            .read_to_string(&mut s)
            .unwrap(),
        None => std::io::stdin().read_to_string(&mut s).unwrap(),
    };
    s
}


Measured memory_bytes: 17656
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cassert>
#define InfL 1000000000
#define InfLL 1000000000000000000LL
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=(n-1);(i)>=(0);(i)--)
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<db> vd;

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

	ll ans = 0;
	ll A = 100;
	while (1) {
		if (A >= X)
			break;
		A *= 1.01;
		ans++;
	}

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

Measured memory_bytes: 3596
from collections import Counter

N, M = map(int, input().split())
Ass = [tuple(map(lambda x: int(x)-1, input().split())) for _ in range(N)]

def isOK(k):
    iAs = [0] * N
    isAvailables = [True] * M
    numSport = M
    while numSport > 0:
        sports = []
        for i in range(N):
            while iAs[i] < M and not isAvailables[Ass[i][iAs[i]]]:
                iAs[i] += 1
            sports.append(Ass[i][iAs[i]])
        cnt = Counter(sports)
        isOK = True
        for sp, num in cnt.items():
            if num > k:
                isAvailables[sp] = False
                numSport -= 1
                isOK = False
        if isOK:
            return True
    return False

ng, ok = 0, N
while abs(ok-ng) > 1:
    mid = (ng+ok) // 2
    if isOK(mid):
        ok = mid
    else:
        ng = mid

print(ok)


Measured memory_bytes: 4588
import java.util.Scanner;

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

        while(true) {
            int n = sc.nextInt();
            int x = sc.nextInt();
            if(n == 0 && x == 0) {
                break;
            }

            int cnt = 0;
            for(int i=1; i<=n-2; i++) {
                for(int j=i+1; j<=n-1; j++) {
                    for(int k=j+1; k<=n; k++) {
                        if(x == i + j + k) {
                            cnt++;
                        }
                    }
                }
            }
            System.out.println(cnt);
        }
    }
}



Measured memory_bytes: 26420
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;

public class Main {

	static int h, w;
	static char[][] board;
	
	public static void main(String[] args) {
		FastScanner fs=new FastScanner();
		h=fs.nextInt(); w=fs.nextInt();
		int sy=fs.nextInt()-1, sx=fs.nextInt()-1;
		int ey=fs.nextInt()-1, ex=fs.nextInt()-1;
		ArrayDeque<Integer> xs=new ArrayDeque<>(), ys=new ArrayDeque<>();
		board=new char[w][h];
		for (int y=0; y<h; y++) {
			char[] line=fs.next().toCharArray();
			for (int x=0; x<w; x++) {
				board[x][y]=line[x];
			}
		}
		xs.add(sx);
		ys.add(sy);
		int[][] dist=new int[w][h];
		for (int x=0; x<w; x++) Arrays.fill(dist[x], 1_000_000_000);
		dist[sx][sy]=0;
		int[] dx= {-1, 1, 0, 0};
		int[] dy= {0, 0, -1, 1};
		while (!xs.isEmpty()) {
			int curX=xs.removeFirst(), curY=ys.removeFirst();
			for (int d=0; d<4; d++) {
				int nx=curX+dx[d], ny=curY+dy[d];
				if (!legal(nx, ny)) continue;
				if (dist[nx][ny]>dist[curX][curY]) {
					dist[nx][ny]=dist[curX][curY];
					xs.addFirst(nx);
					ys.addFirst(ny);
				}
			}
			for (int x=curX-2; x<=curX+2; x++) {
				for (int y=curY-2; y<=curY+2; y++) {
					if (!legal(x, y)) continue;
					if (dist[x][y]>dist[curX][curY]+1) {
						dist[x][y]=dist[curX][curY]+1;
						xs.addLast(x);
						ys.addLast(y);
					}
				}
			}
		}
		System.out.println(dist[ex][ey]>1e7?-1:dist[ex][ey]);
	}

	static boolean legal(int x, int y) {
		if (x<0||y<0||x>=w||y>=h || board[x][y]=='#') return false;
		return true;
	}
	
	static final Random random=new Random();
	
	static void ruffleSort(int[] a) {
		int n=a.length;//shuffle, then sort 
		for (int i=0; i<n; i++) {
			int oi=random.nextInt(n), temp=a[oi];
			a[oi]=a[i]; a[i]=temp;
		}
		Arrays.sort(a);
	}
	
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		long nextLong() {
			return Long.parseLong(next());
		}
	}

	
}


Measured memory_bytes: 65216
//package Beginner118;

import java.io.*;
import java.util.*;


public class Main {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int a = s.nextInt();
        int b = s.nextInt();
        if(b % a == 0) {
            System.out.println(a+b);
        } else {
            System.out.println(b-a);
        }
    }
}


Measured memory_bytes: 22996
#include<iostream>
#include<stdlib.h>
#include<math.h>
using namespace std;
typedef long long ll;
int main(){
	int n,a=0,b=0,p=0;
	char c[200001];
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>c[i];
		if(c[i]=='R') a++;
		else b++;
	}
	for(int i=0;i<a;i++)
	if(c[i]=='R') p++;
	a=a-p;
	cout<<min(a,b);
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    int target = 1;
    int cnt = 0;
    rep(i, N) {
        if (A[i] == target) {
            target++;
            cnt++;
        }
    }
    if (cnt == 0) {
        cout << -1 << '\n';
    } else {
        cout << N - cnt << '\n';
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


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

int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    a--;

    ll l = c*d/__gcd(c, d);
    ll ans = (b - b/c - b/d + b/l) - (a - a/c - a/d + a/l);

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


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

signed main(){
  int n;
  cin >>n;
  int a[n];
  int temp,flag;
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  int cash=1000;
  int share=0;
  temp=a[0];
  flag=0;
  for(int i=1;i<n-1;i++){
    if(flag==0 && a[i]<a[i-1]){
      temp=a[i];
      continue;
    }
    else if(flag==0 && a[i]>a[i-1]){
      flag=1;
      continue;
    }
    if(flag==1 && a[i]<a[i-1]){
      share+=(cash/temp);
      cash-=(temp*share);
      cash+=(share*a[i-1]);
      share=0;
      temp=a[i];
    }
  }
  
  if(a[n-1]>=a[n-2]){
    share+=(cash/temp);
    cash-=(temp*share);
    cash+=(share*a[n-1]);
  }
  else{
    share+=(cash/temp);
    cash-=(temp*share);    
    cash+=(share*a[n-2]);
  } 
  cout<<cash<<endl;
  return 0;
}

     
  
  

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using vll = vector<ll>;
using vvll = vector<vll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vb = vector<bool>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;

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

//pow(llpow,modpow)
template <class T>
ll llpow(ll x, T n)
{
    ll ans = 1;
    if (x == 0)
        ans = 0;
    while (n)
    {
        if (n & 1)
            ans *= x;
        x *= x;
        n >>= 1;
    }
    return ans;
}
long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
template <class T>
inline T gcd(T x, T y)
{
    if (y == 0)
        return x;
    else
    {
        return gcd(y, x % y);
    }
}
//最小公倍数
template <class T>
inline T lcm(T x, T y) { return x / gcd(x, y) * y; }
//逆元
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 rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i - 1; i >= (ll)end_i; i--)

template <class T>
bool is_prime(T IN)
{
    if (IN <= 1)
        return false;
    for (long long i = 2; i * i <= IN; i++)
    {
        if (IN % i == 0)
        {
            return false;
        }
    }
    return true;
}
template <class T>
vector<pair<long long, long long>> primefact(T x)
{
    vector<pair<long long, long long>> ret;
    ll cpyx=x;
    for (long long i = 1; i * i <= x; i++)
    {
        if (x % i == 0)
        {
            vector<long long> alt = {i, x / i};
            if (alt[0] == alt[1])
                alt[1] = 1;
            for (long long j = 0; j < alt.size(); j++)
            {
                if (is_prime(alt[j]))
                {
                    pair<long long, long long> t = make_pair(alt[j], 0);
                    while (cpyx % alt[j] == 0)
                    {
                        cpyx /= alt[j];
                        t.second++;
                    }
                    ret.push_back(t);
                }
            }
        }
    }
    return ret;
}
long long INF = 1LL << 60;
int main()
{
    ll A, B;
    cin >> A >> B;
    ll GCD = gcd(A, B);
    //1の分
    ll cnt = 1;
    vector<pair<ll, ll>> pf = primefact(GCD);
    cnt += pf.size();
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <ctime>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <bitset>
#include <list>
#include <cstdio>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <cmath>
#include <tuple>
#include <cassert>
#include <array>
#include <iomanip>

using namespace std;
using pii = pair<int, int>;
using ti = tuple<int, int, int>;

const double eps=1e-14;
const int mod = 1e9 + 7;
const int inf = ((1<<30));
const long long linf = (1LL<<60);

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, w;
    cin >> h >> w;
    char board[h][w];
    int ans[h][w];
    for(int i=0; i<h; i++)
    {
        for(int j=0; j<w; j++)
        {
            cin >> board[i][j];
            ans[i][j] = 0;
        }
    }
    for(int i=0; i<h; i++)
    {
        for(int j=0; j<w; j++)
        {
            if(board[i][j] == '#')
            {
                ans[i][j] = -1;
                for(int m=-1; m<=1; m++)
                {
                    for(int n=-1; n<=1; n++)
                    {
                        if(i+m<h && j+n<w && i+m>=0 && j+n>=0)
                        {
                            if(ans[i+m][j+n] != -1) ans[i+m][j+n]++;
                        }
                    }
                }
            }
        }
    }
    for(int i=0; i<h; i++)
    {
        for(int j=0; j<w; j++)
        {
            if(ans[i][j] >= 0) cout << ans[i][j];
            else cout << '#';
        }
        cout << endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  float m;
  cin>>n>>m;
  float arr[n];
  float sum=0;
  for(int i=0;i<n;i++){ cin>>arr[i];sum=sum+arr[i];}
    sum=sum/(float)4;
    sum=sum/m;
    vector<float>vec;
  sort(arr,arr+n,greater<float>());
  int i=0;
  for(int i=0;i<n;i++)
  {
    if(arr[i]>=sum)vec.push_back(arr[i]);
  }
  m = (int)m;
  if(vec.size()>=m)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N;
    while(cin>>N) {
        set<string> S;
        for(int i=0;i<N;i++) {
            string U;
            cin>>U;
            S.insert(U);
        }
        bool close=1;
        int M;
        cin>>M;
        for(int i=0;i<M;i++) {
            string T;
            cin>>T;
            if(S.find(T)!=S.end()) {
                if(close) cout<<"Opened by "<<T<<endl;
                else cout<<"Closed by "<<T<<endl;
                close^=1;
            }else {
                cout<<"Unknown "<<T<<endl;
            }
        }
    }
}

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

const int  N = (int) 1e5 + 5;

long long a, b;

int main() {
//	freopen("test.inp", "r", stdin);
	cin >> a >> b;
	long long d = __gcd(a, b);
	int cnt = 0;
	for (int i = 2; i <= sqrtl(d); i++)
		if (d % i == 0) {
			cnt++;
			while (d % i == 0) d/=i;
		}
	if (d != 1) cnt++;
	cout << cnt + 1;
	return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
typedef long long ll;

void Main()
{
  	int N;
  	cin >> N;
  	//vector<int> a(N);
  	vector<int> count(N,0);
  
  	int j = 1;
	rep(i,N) {
      int a;
      cin >> a;
      if(a == j){
      	count[j] = i;
        j++;
      }
    }	
  	if(j==1){
    	cout << -1 << endl;
    }
  	else{
      cout << N - j + 1 << endl;
    }
  	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

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

lli cnt[10010];

void func(long long N){

    for(lli x=1;x*x <= N;x++){
        for(lli y=1;y*y<=N;y++){
            for(lli z=1;z*z<=N;z++){
                lli ans = x*x+y*y+z*z+x*y+y*z+z*x;
                if(ans>N)continue;
                cnt[ans]++;
            }
        }
    }

    for(lli i=1;i<=N;i++){
        cout<<cnt[i]<<endl;
    }

}

int main(){
    // cout << fixed << setprecision(5);

    long long N;
    scanf("%lld",&N);
    func(N);
    return 0;
}


Measured memory_bytes: 3648
#include<iostream>
#include<vector>
#include<string>
#include<set>
#include<algorithm>
#include<cstring>

using namespace std;


int main() {
	int n;
	cin >> n;
	vector<int> ok(n+1,0);
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		if (ok[a - 1]) {
			ok[a] = 1;
		}
		else {
			ok[a] = -1;
		}
	}
	int tmp = 0;
	int mx = 0;
	for (int i = 0; i < n + 1; i++) {
		if (ok[i] != 1) { tmp = 0; }
		else {
			tmp += 1;
			mx = max(mx, tmp);
		}
	}
	cout << n-mx-1 << endl;

	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int64_t INF = 1LL << 60;

int main() {
 	int X,N;
   cin>>X>>N;
   vector<int>p(N);
   for(int i=0;i<N;i++){
     cin>>p[i];
   }
   sort(p.begin(),p.end());
   int ans=1000000;int m=0;
   for(int i=-1000;i<1000;i++){
     bool ok=true;
     for(int j=0;j<N;j++){
     if(i==p[j]){ok=false;}
   }
     if(ok){if(ans>abs(i-X)){ans=abs(i-X);m=i;}}
   }
   cout<<m<<endl;
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<char>> A(H, vector<char>(W));
    queue<P> que;
    vector<vector<int>> dist(H, vector<int>(W, -1));
    for(int i=0; i<H; ++i) {
        for(int j=0; j<W; ++j) {
            cin >> A[i][j];
            if(A[i][j] == '#') {
                dist[i][j] = 0;
                que.push({i, j});
            }
        }
    }

    
    while(!que.empty()) {
        P cur = que.front();
        que.pop();
        int x = cur.first, y = cur.second;
        for(int i=0; i<4; ++i) {
            int nx = x + dx[i], ny = y + dy[i];
            if(nx >= 0 && nx < H && ny >= 0 && ny < W && dist[nx][ny] == -1) {
                dist[nx][ny] = dist[x][y] + 1;
                que.push({nx, ny});
            }
        }
    }

    int res = -1;
    for(int i=0; i<H; ++i) {
        for(int j=0; j<W; ++j) {
            res = max(res, dist[i][j]);
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 13328
import java.util.Scanner;

public class Main {

    private static Scanner scan = new Scanner(System.in);

    public static void main(String[] args) {
	int N = Integer.parseInt(scan.next());
	int M = Integer.parseInt(scan.next());

	int[] a = new int[N];
	int[] b = new int[N];
	int[] min = new int[N];
	for (int i = 0; i < N; i++) {
	    a[i] = Integer.parseInt(scan.next());
	    b[i] = Integer.parseInt(scan.next());
	    min[i] = Integer.MAX_VALUE;
	}

	int[] dest = new int[N];
	for (int j = 0; j < M; j++) {
	    int c = Integer.parseInt(scan.next());
	    int d = Integer.parseInt(scan.next());
	    for (int i = 0; i < N; i++) {
		int dis = distance(a[i], b[i], c, d);
		if(dis < min[i]) {
		    min[i] = dis;
		    dest[i] = j+1;
		}
	    }
	}

	for (int i = 0; i < N; i++) {
	    System.out.println(dest[i]);
	}
	scan.close();
    }

    private static int distance(int x1, int y1, int x2, int y2) {
	return Math.abs(x1-x2) + Math.abs(y1-y2);
    }
}


Measured memory_bytes: 21844
def xgcd(a, b)
  x=xx=yy=q = 1
  y = 0
  x = a = 0  if b == 0
  while b > 0
    xx -= q*x; yy -= q*y
    q,a = a.divmod b
    return [b,xx,yy]  if a == 0
    x -= q*xx; y -= q*yy
    q,b = b.divmod a
  end
  [a,x,y]
end
N,A,B = gets.split.map &:to_i
P = 10**9+7
n,s,PP = 1,2,P<<2
30.times {|i| n*=s if N[i]>0; s*=s; s%=P if s>P;n%=P if n>PP}
a,b = [A,B].map{|r| N < r+r ? N-r : r}.sort
s=t=u = 1
f = proc {|i| t,u = [t*(N+1-i), u*i].map!{|x| x>P ? x%P : x} }
[[1,a],[a+1,b]].each {|x,y| x.upto(y ,&f); s += t*xgcd(u,P)[1]%P }
p (n-s) % P

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
using ll = long long;
using namespace std;
template <typename T>
using vec = std::vector<T>;

int main() {
    int N;
    cin >> N;
    vec<ll> A(N + 1), S(N + 1), M(N + 1);
    rep(i, N + 1) cin >> A[i];

    S[N] = A[N];
    for (int i = N - 1; i >= 0; --i)
        S[i] = S[i + 1] + A[i];

    rep(i, N + 1) {
        if (i == 0)
            M[i] = 1;
        else
            M[i] = min(M[i - 1] * 2, S[i]);
    }

    vec<ll> ans(N + 1);
    ll a = 0;
    rep(i, N + 1) {
        if (i == 0)
            ans[i] = M[i];
        else {
            ans[i] = min(M[i], (ans[i - 1] - A[i - 1]) * 2LL);
            ;
        }
        if (ans[i] < A[i]) {
            cout << -1 << endl;
            return 0;
        }
        a+=ans[i];
    }
    cout << a << endl;
}


Measured memory_bytes: 6424
import math

n = int(input())

x = list(map(float, input().split()))
y = list(map(float, input().split()))

#p=1
p_1 = 0
for i in range(n):
    p_1 += math.fabs(x[i] - y[i])

#p=2
p_2 = 0
for i in range(n):
    p_2 += math.fabs(x[i] - y[i]) ** 2
p_2 = math.sqrt(p_2)

#p=3
p_3 = 0
for i in range(n):
    p_3 += math.fabs(x[i] - y[i]) ** 3
p_3 = pow(p_3, (1/3))

#p is inf
prep = []
for i in range(n):
    prep.append(math.fabs(x[i] - y[i]))
p_inf = max(prep)

print('{:.6f}'.format(p_1))
print('{:.6f}'.format(p_2))
print('{:.6f}'.format(p_3))
print('{:.6f}'.format(p_inf))


Measured memory_bytes: 5736
#include<stdio.h>
int main(){
  int i,j,v,n,k;
  int A[1000];
  scanf("%d",&n);
  for(i=0;i<=n-1;i++){
    scanf("%d",&A[i]);
  }
  for(i=0;i<n-1;i++){
    printf("%d",A[i]);
     printf(" ");
  }
  printf("%d\n",A[n-1]);
  for(i=1;i<=n-1;i++){
    v=A[i];
    j=i-1;
    while(j>=0 && A[j]>v){
      A[j+1]=A[j];
      j--;
    }
    A[j+1]=v;
    for(k=0;k<n-1;k++){
      printf("%d",A[k]);
      printf(" ");
    }
    printf("%d\n",A[n-1]);
  }
  return 0;
}

Measured memory_bytes: 608
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;



class Program
{
    static void Main(string[] args)
    {
        string str1;
        str1 = Console.ReadLine(); //標準入力
        string[] str1s = str1.Split(' ');

        int a = int.Parse(str1s[0]);
        int b = int.Parse(str1s[1]);
        int c = b - a;

        int count = 2;
        int takasa = 1;
        while(true)
        {
            int tmp = takasa + count;

            if ((tmp - takasa) == c)
            {
                Console.WriteLine(takasa - a);
                break;
            }
            takasa = tmp;
            count++;
        }

    }


}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e18;
const ll mod = 1000000007;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}

int main() {
  ll n, m, l;
  cin >> n >> m >> l;
  vector <vector <ll>> a(n, vector <ll> (m));
  vector <vector <ll>> b(m, vector <ll> (l));
  rep(i, n) {
    rep(j, m) {
      cin >> a.at(i).at(j);
    }
  }
  rep(i, m) {
    rep(j, l) {
      cin >> b.at(i).at(j);
    }
  }
  rep(i, n) {
    rep(j, l) {
      ll ans = 0;
      rep(k, m) {
        ans += a.at(i).at(k)*b.at(k).at(j);
      }
      if (j) {
        cout << ' ' << ans;
      } else {
        cout << ans;
      }
    }
    cout << endl;
  }
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define rep(i, l, r) for(register int i = l; i < r; i++)
#define hrp(i, l, r) for(register int i = l; i <= r; i++)
#define rev(i, r, l) for(register int i = r; i >= l; i--)
#define ms(n, t) memset(n, 0, sizeof(n))
#define U 10050
#define pb push_back
#define int ll
#ifndef JOEON
#define D(...)
#define R(x, l)
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
template<typename tn> inline tn next(void);
template<typename tn> inline ostream& operator << (ostream& os, const vector<tn>& v);
bool visited[U][U];
int w[U][U], n;
const int bx[] = {1, 0}, by[] = {0, 1};
inline int dfs(int ex, int ey)
{
	int maxx = w[ex][ey];
	if (ex == 1 && ey == n-1) return maxx;
	visited[ex][ey] = 1;
	rep(i, 0, 2)
	{
		int nx = ex+bx[i], ny = ey+by[i];
		if (0 <= nx && nx < 2 && 0 <= ny && ny < n && !visited[nx][ny]) maxx = max(maxx, w[ex][ey]+dfs(nx, ny));
	}
	visited[ex][ey] = 0;
	D(ex, ey, maxx);
	return maxx;
}
signed main(void)
{
	#ifdef JOEON
//		freopen("C:\\Users\\Joeon\\Desktop\\IN.txt", "r", stdin);
//		freopen("C:\\Users\\Joeon\\Desktop\\OUT.txt", "w", stdout);
	#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	rep(i, 0, n) cin>>w[0][i];
	rep(i, 0, n) cin>>w[1][i];
	cout<<dfs(0, 0)<<endl;
	return 0;
}
template<typename tn> inline tn next(void)
{
	tn k;
	cin>>k;
	return k;
}
template<typename tn> inline ostream& operator << (ostream& os, const vector<tn>& v)
{
	rep(i, 0, v.size()) os<<v[i]<<' ';
	return os;
}

Measured memory_bytes: 2304
from itertools import product
H, W, K = map(int, input().split())
c = []
r = [0]* W
S = [input() for _ in range(H)]
for i in range(H):
    c.append(S[i].count('#'))
for i in range(W):
    for j in range(H):
        if S[j][i] == '#': r[i] += 1

nall = sum(c)
ans = 0
for hh in product([0, 1], repeat=H):
    for ww in product([0, 1], repeat=W):
        dl = 0
        for ih, ihh in enumerate(hh):
            dl += c[ih] * ihh
            for iw, iww in enumerate(ww):
                if S[ih][iw] == '#':
                    dl -= ihh * iww
        for iw, iww in enumerate(ww):
            dl += r[iw] * iww
        
        if nall - dl == K: ans += 1
print(ans)

Measured memory_bytes: 9212
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
using namespace std;

int main() {
  string str;
  vector<int> card;
  while(getline(cin,str)) {
    if(str == "0") break;
    int score=0,ace=0;
    stringstream ss;
    int s;
    ss << str;
    while(ss >> s) {
      card.push_back(s);
    }
    ss.str("");
    ss.clear(stringstream::goodbit);



    for(unsigned int i=0;i<card.size();i++) {
      if(2 <= card[i] && card[i] <= 9) {
        score += card[i];
      }
      else if(10 <= card[i] && card[i] <= 13) {
        score += 10;
      }
      else { //card[i]==1
        ace++;
      }
    }

    if(score > 21) {
      cout << 0 << endl;
      card.clear();
      continue;
    }

    while(ace>0) {
      if(score + ace <= score + 11 + ace - 1 && score + 11 + ace - 1 <= 21) {
        score += 11;
      }
      else {
        score += 1;
      }
      ace--;
    }

    if(score > 21) {
      cout << 0 << endl;
    }
    else cout << score << endl;
    card.clear();
  }
}

Measured memory_bytes: 0
import sys
import time
import random
import math
from collections import deque
import heapq
import itertools
from decimal import Decimal
import bisect
from operator import itemgetter
MAX_INT = int(10e18)
MIN_INT = -MAX_INT
mod = 1000000000+7
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

def tami(ans):
  res = 0
  LastDay = [0]*26
  for i in range(D):
    res += s[i][ans[i]]
    for j in range(26):
      if ans[i] == j:
        continue
      res -= (i+1 - LastDay[j]) * c[j]
    LastDay[ans[i]] = i+1
  return res

def nasu():
  res = []
  LastDay = [0]*26
  for d in range(1,D+1):
    tmp = ["", 0]
    for i in range(26):
      if tmp[1] < s[d-1][i] + (d - LastDay[i]) * c[i]:
        tmp = [i, s[d-1][i] + (d - LastDay[i]) * c[i]]
    res.append(tmp[0])
    LastDay[tmp[0]] = d
  return res

def nbo(ans, score, num):
  tmp_ans = ans[:]
  for _ in range(num):
    random_date = random.randint(0,D-1)
    random_val = random.randint(0,25)
    tmp_ans[random_date] = random_val
  scoscore = tami(tmp_ans)
  if scoscore > score:
    return (True, tmp_ans, scoscore)
  else:
    return (False, tmp_ans, scoscore)

start = time.time()
D = I()
c = IL()
s = [IL() for i in range(D)]

ans = nasu()
#print(ans)

score = tami(ans)
#print(score)

end = time.time()
num = 10
cnt = 0
while (time.time() - start) < 1.8:
  judge, anans, scoscore = nbo(ans, score, num)
  if judge == True:
    ans, score = anans, scoscore
    #print(ans)
    #print(tami(ans))
  cnt += 1
  if cnt == 1000:
    cnt = 0
    num = max(2, num-1)
for i in ans:
  print(i+1)

Measured memory_bytes: 90648
def Min(a,b):
    if a<b:
        return a
    return b

n=0
n=int(input())

alphabet=[[0 for i in range(26)]for i in range(n)]
for i in range(n):
    test=input()
    length=len(test)
    for j in range(length):
        k=ord(test[j])-ord('a')
        alphabet[i][k]=alphabet[i][k]+1
for i in range(26):
    minimum=50
    for j in range(n):
        minimum=Min(alphabet[j][i],minimum)
    for j in range(minimum):
        print(chr(i+ord('a')),end='')
print()


Measured memory_bytes: 3064