akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_macros)]
macro_rules! parse_line {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            iter.next().unwrap().parse::<$t>().unwrap()
        }
    );

    ( $( $t:ty), +) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ( $(iter.next().unwrap().parse::<$t>().unwrap()),* )
        }
    );
}

#[allow(unused_macros)]
macro_rules! read_line {
    () => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            line.pop();
            line
        }
    )
}

#[allow(unused_macros)]
macro_rules! parse_vec {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let iter = line.split_whitespace();
            iter.map(|v| v.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    )
}

fn solve(x: i64, xs: Vec<i64>) -> i64 {

    let n = xs.len();

    let mut acc = vec![0; n + 1];
    for i in 1..(n + 1) {
        acc[i] = acc[i - 1] + xs[i - 1];
    }

    let mut ans = std::i64::MAX;
    for k in 1..(n + 1) {
        let mut i = 1;
        let mut r = n;
        let mut e: i64 = 0;
        while r > 0 {
            let new_r = if r < k {0} else {r-k};
            let a = if i == 1 {5} else { 2*i + 1 };
            let w = acc[r] - acc[new_r];
            let new_e = w.checked_mul(a).and_then(|v| v.checked_add(e));

            r = new_r;
            i += 1;

            if let Some(new_e) = new_e {
                e = new_e;
            } else {
                continue
            }
        }

        if let Some(e) = e.checked_add(((n+k) as i64)*x) {
            ans = std::cmp::min(ans, e);
        }
    }
    ans
}

fn main() {
    let (n, x) = parse_line!(usize, i64);
    let xs = parse_vec!(i64);

    println!("{}", solve(x, xs));
}

#[test]
fn solve_test() {
    assert_eq!(solve(100, vec![1,10]), 355);
    assert_eq!(solve(1, vec![1, 999999997, 999999998, 999999999, 1000000000]), 19999999983);
}


Measured memory_bytes: 10492
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int x,y,n;
    int i=1;
    while (1) {
        scanf("%d %d",&x,&y);
        if(x==0 && y==0)break;
        if(x > y) {
            n = x;
            x = y;
            y = n;
        }
        printf("%d %d\n",x,y);
        i++;
    }
    return 0;
}


Measured memory_bytes: 1992
#include <stdio.h>;
//#include "Main.h"
int main(void)
{
	// Your code here!
	int n;
	long int a[101];
	long int b[101];
	long long int ans=0;
	long int min_num = 100001;
	int index;
	scanf("%d", &n);

	for (int i = 0; i<n-1; i++)
	{
		scanf("%ld", &b[i]);

	}
	for (int i = 0; i<n; i++)
	{
		a[i]=-1;
	}
	for (int i = 0; i<n-1; i++)
	{
		min_num = 100001;
		for (int j = 0; j < n-1; j++)
		{
			if (b[j]<=min_num)
			{
				index = j;
				min_num = b[j];
			}
		}
		
		if (a[index] == -1)
		{
			a[index] = b[index];
		}

		if (a[index+1] == -1)
		{
			a[index+1] = b[index];
		}
		b[index] = 100001;
	}
	for (int i = 0; i<n; i++)
	{
		//printf("%d", a[i]);
		ans = ans + a[i];
	}
	printf("%lld", ans);
	//system("pause");
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <queue>
#include <climits>
#include <set>
#include <complex>
#include <cmath>
#include <cstring>
#include <map>
using namespace std;
using ll = long long;
#define MOD 1000000007
#define INF 1LL << 59
using ld = long double;

int arr[310];

int sum;
int dp[90010];
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    //cout << fixed << setprecision(5);

    int N, K;
    cin >> N >> K;

    if (N % K == 0)
        cout << 0 << endl;
    else
        cout << 1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using VI = vector<int>;
using VB = vector<bool>;
using Graph = vector<vector<int>>;
using ll = long long;
using P = pair<int, int>;

int main(){
  ll n;
  cin >> n;
  ll a[n];
  rep(i, n) cin >> a[i];

  set<ll> s;
  rep(i, n){
    s.insert(a[i]);
  }

  if (s.size() == n) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 11136
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <time.h>
#include <cctype>
#include <deque>
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FFOR(i,a,b) for(int i=(a);i<=(b);i++)
#define REP(i,b) FOR(i,0,b)
#define RREP(i,b) FFOR(i,1,b)
#define PB push_back
#define F first
#define S second
#define BE(c) c.begin(),c.end()
using namespace std;
typedef long long LL;
typedef LL ut;
typedef long double ld;
typedef pair<ut,ut> pr;
typedef vector<pr> Vpr;
typedef vector<ut> VI;
typedef pair<ut,pr> ppr;
typedef priority_queue<pr,Vpr, greater<pr> > PQ;
const int SIZE=1e+4+10;
const ut INF=1<<30;
const ld eps=1e-6;
const LL mod=1e+9 + 7;

int N, M, L;
vector<pr> data[SIZE];

int main() {
	cin >> N >> M;
	int s, t, e;
	while(1){
		scanf("%d%d%d", &s, &t, &e);
		if(!s && !t && !e)
			break;
		t--; s--;
		data[t].PB(pr(s, e));
	}
	cin >> L;
	int b;
	REP(i,L){
		int ans[SIZE] = {0};
		REP(j,M){
			scanf("%d", &b);
			REP(k,data[j].size()){
				ans[data[j][k].F] += b * data[j][k].S;
			}
		}
		REP(j,N){
			if(j)
				printf(" ");
			printf("%d", ans[j]);
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 2784
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)n; i++)
#define PI 3.14159265358979323846
#define vll vector<long long>
#define vvll vector<vector<long long>>
#define pll pair<long long, long long>
using namespace std;
using ll = long long;
using ld = long double;

// グローバル変数（入力）
ll n,k;
vll p;

void input() { 
  cin >> n >> k;
  rep(i,n){
    ll a; cin >> a;
    p.push_back(a);
  }
}

void solve() {
  sort(p.begin(),p.end());
  ll ans=0;
  rep(i,k){
    ans += p[i];
  }
  cout << ans << endl;
}

int main() {
  input();
  solve();
  return 0;
}


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

int main() {
    long long N;
    cin >> N;
    if (N % 2 == 1) { cout << 0 << endl; return 0; }
    long long cnt = 0;
    for (long long i = 5LL; i*2 <= N; i *= 5LL) {
        cnt += (N/(i*2));
        //cout << i << " " << cnt << endl;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 384
n=int(input())
X=[]*n
A=[]*n

for i in range(n):
	a=int(input())
	A.append(a)
	xy = [list(map(int,input().split())) for _ in range(a)]
	X.append(xy)

ans=0
for i in range(2**n):
	cnt=0
	for j in range(n):
		if (i>>j)&1:
			for k,l in X[j]:
				if not ((i>>(k-1))&1)==l:
					cnt=1
					break

	if cnt==0:
		ans = max(ans,bin(i).count("1"))

print(ans)

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

int main() {
	static int N, P[200000], Q[200010], ans = 0, count = 1;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> P[i];
		Q[P[i] - 1] = i;
	}
	Q[N] = -1;
	for (int i = 0; i < N; i++) {
		if (Q[i] > Q[i + 1]) {
			ans = max(ans, count);
			count = 1;
		}
		else count++;
	}
	cout << N - ans;
}

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

long long n, kk, dp[51][51][65], ans[51][51], temp[51][51], res;

int main() {
	cin>>n>>kk;
	for (int i=0; i<n; i++) {
		ans[i][i]=1;
		for (int j=0; j<n; j++) cin>>dp[i][j][0];
	}

	for (int k=1; k<64; k++) {
		for (int i=0; i<n; i++) {
			for (int j=0; j<n; j++) {
				for (int l=0; l<n; l++) {
					dp[i][j][k]+=(dp[i][l][k-1]*dp[l][j][k-1])%M;
					dp[i][j][k]%=M;
				}
			}
		}
	}

	for (int k=0; k<64; k++) if (kk&(1ll<<k)) {
		for (int i=0; i<n; i++)  {
			for (int j=0; j<n; j++) {
				temp[i][j]=0;
				for (int l=0; l<n; l++) {
					temp[i][j]+=(ans[i][l]*dp[l][j][k])%M;
					temp[i][j]%=M;
				}
			}
		}
		for (int i=0; i<n; i++) {
			for (int j=0; j<n; j++) {
				ans[i][j]=temp[i][j];
			}
		}
	}

	for (int i=0; i<n; i++) {
		for (int j=0; j<n; j++) {
			res+=ans[i][j];
			res%=M;
		}
	}
	cout<<res<<endl;
	return 0;
}

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

#define rep(i,z) for(int i = 0; i<(int)(z); i++)
#define rep1(i,z) for(int i = 1; i<=(int)(z); i++)
 
using namespace std;

typedef long long ll;
const ll MOD=1e9+7;
using pear = pair<int,int>; 

int main(){
    ll a,b,k; cin>>a>>b>>k;
    if(k>a){
        cout<<0<<" ";
        if(k>a+b) cout<<0<<endl;
        else cout<<a+b-k<<endl;
    }else cout<<a-k<<" "<<b<<endl;
}

Measured memory_bytes: 256
fun main(){
    val n = readLine()!!.toLong()
    var tmpMax = 1L
    readLine()!!.split(" ").map(String::toLong).fold(0L){ accum, value ->
        val diff = tmpMax - value
        if(diff < 0){
            tmpMax = value
            accum
        } else {
            accum + diff
        }
    }.let { print(it) }
}

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

namespace ABC122_B
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();

            int maxCount = 0;

            for (int i = 0; i < str.Length; ++i)
            {
                int count = 0;

                for(int j = i; j < str.Length; ++j)
                {
                    if (str[j] == 'A' || str[j] == 'C' || str[j] == 'G' || str[j] == 'T')
                    {
                        ++count;
                    }
                    else
                    {
                        break;
                    }
                }

                if (maxCount < count)
                {
                    maxCount = count;
                }
            }

            Console.WriteLine("{0}", maxCount);
        }
    }
}


Measured memory_bytes: 13140
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
		if len(os.Args) > 2 {
			wfp, _ = os.Create(os.Args[2])
		}
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	n := getNextInt64(scanner)

	h, i, m := solve(n)
	fmt.Fprint(writer, h)
	fmt.Fprint(writer, " ")
	fmt.Fprint(writer, i)
	fmt.Fprint(writer, " ")
	fmt.Fprintln(writer, m)
	writer.Flush()
}

func solve(n int64) (int, int, int) {
	for h := 1; h < 3501; h++ {
		for i := h; i < 3501; i++ {
			l := i
			r := 3501
			for l < r {
				m := (l + r) >> 1
				if int64(4*h*i*m) == n*int64(h*i+i*m+h*m) {
					return h, i, m
				}
				if int64(4*h*i*m) < n*int64(h*i+i*m+h*m) {
					l = m + 1
					continue
				}
				r = m
			}
		}
	}
	return -1, -1, -1
}


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

class Program
{
    static void Main(string[] args)
    {
        var ab = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        var a = ab[0];
        var b = ab[1];

        Console.WriteLine(a * b);
    }
}

Measured memory_bytes: 28232
N = int(input())
a = list(map(int,input().split()))

mx = max(a)
mn = min(a)

proc = []
if mx >= (-1) * mn:
    i = a.index(mx)
    for j in range(len(a)):
        if a[j] < 0:
            proc.append([i+1,j+1])
            a[j] += a[i]

    for j in range(len(a)-1):
        if a[j] > a[j+1]:
            proc.append([j+1,j+2])
            a[j+1] += a[j]

else:
    
    i = a.index(mn)
    for j in range(len(a)):
        if a[j] > 0:
            proc.append([i+1,j+1])
            a[j] += a[i]

    for j in reversed(range(len(a)-1)):
        if a[j] > a[j+1]:
            proc.append([j+2,j+1])
            a[j] += a[j+1]



print(len(proc))
for k in proc:
    print(k[0], k[1])


Measured memory_bytes: 3064
N = int(input())
List1 = [int(i) for i in input().split(" ")]
List2 = [int(j) for j in input().split(" ")]
List3 = [int(k) for k in input().split(" ")]

baf = 0
last_m = 21

for i in range(N):
    p = List1[i]
    baf += List2[p-1]
    if last_m == p-1:
        baf += List3[last_m-1]
    last_m = p
print(baf)

Measured memory_bytes: 3064
class findroop:
    def __init__(self, n, nex):
        self.n = n
        self.next = nex

    #遷移start回でループに入る、end回でループする
    #A->B->C->D->B: return=(1, 4)
    #C->D->B->C   : return=(0, 3)
    #O(n)
    def findroop(self, start):
        roopstart = -1
        roopend = -1
        visited = [False for i in range(self.n)]
        visitlist = []
        now = start
        for i in range(self.n):
            if visited[now]:
                roopend = i
                break
            else:
                visited[now] = True
                visitlist.append(now)
                now = self.next(now)
        
        for i in range(len(visitlist)):
            if visitlist[i] == now:
                roopstart = i

        return (roopstart, roopend)


N,X,M = list(map(int, input().split()))

fr = findroop(M, lambda x: x**2 % M)

roopstart, roopend = fr.findroop(X)

ans = 0
if N <= roopstart:
    for i in range(N):
        ans += X
        X = (X**2)%M
else:
    for i in range(roopstart):
        ans += X
        X = (X**2)%M

    N -= roopstart
    roopsum = 0
    for i in range(roopend-roopstart):
        roopsum += X
        X = (X**2) % M
    ans += (N // (roopend-roopstart)) * roopsum

    N = N % (roopend-roopstart)

    for i in range(N):
        ans += X
        X = (X**2) % M

print(ans)

Measured memory_bytes: 11624
#include<cstdio>
#include<iostream>
#include<cmath>

using namespace std;
 
int main(void){
 
    int N,S,f,cnt;
 
    while(1){
        S=0;
		cnt=0;
        cin>>N;
        if(N==0) break;
        if(N%2==0) f=1;
        else f=2;
        for(int i=1;i*i<N;i+=f){
            if(N%i==0){
				S+=i+(N/i);
			}
        }
		S-=N;
		if(sqrt((double)N)==(double)(int)sqrt((double)N)) S-=(int)sqrt((double)N);
        if(N==S) cout<<"perfect number"<<endl;
        if(N>S)  cout<<"deficient number"<<endl;
        if(N<S)  cout<<"abundant number"<<endl;
    }
     
    return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
int main(){
  int A,B;
  cin>>A>>B;
  if(A==1&&B==2)cout<<"3"<<endl;
  if(A==1&&B==3)cout<<"2"<<endl;
  if(A==2&&B==1)cout<<"3"<<endl;
  if(A==2&&B==3)cout<<"1"<<endl;
  if(A==3&&B==1)cout<<"2"<<endl;
  if(A==3&&B==2)cout<<"1"<<endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;

int main()
{
    long long a, b, k;
    cin >> a >> b >> k;
    if (a >= k)
    {
        a -= k;
    }
    else
    {
        if (b >= k - a)
        {
            b = b - (k - a);
        }
        else
        {
            b = 0;
        }
        a = 0;
    }
    cout << a << " " << b << endl;
}


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

public class Main {
	static final int INFTY = 1000000001;
	public static int MAX = 500000;
	public static Card[] L = new Card[MAX / 2 + 2];
	public static Card[] R = new Card[MAX / 2 + 2];
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Card[] originalCards = new Card[n];
		for(int i = 0; i < n; i++) {
			originalCards[i] = new Card(sc.next(), sc.nextInt());
		}
		sc.close();
		Card[] quickSortCards = Arrays.copyOf(originalCards, n);
		Card[] mergeSortCards = new Card[MAX];
		for(int i = 0; i < n; i++) {
			mergeSortCards[i] = originalCards[i];
		}
		quickSort(quickSortCards, 0, n - 1);
		mergeSort(mergeSortCards, 0, n);
		System.out.println(anteiCheck(quickSortCards, mergeSortCards));
		for(int i = 0; i < n; i++) {
			Card card = quickSortCards[i];
			System.out.println(card.mark + " " + card.num);
		}
	}
	public static void quickSort(Card[] A, int p, int r) {
		int q;
		if(p < r) {
			q = partition(A, p, r);
			quickSort(A, p, q - 1);
			quickSort(A, q + 1, r);
		}
	}
	public static int partition(Card[] A, int p, int r) {
		int x = A[r].num;
		int i = p - 1;
		for(int j = p; j <= r- 1; j++) {
			if(A[j].num <= x) {
				i++;
				swap(A, i, j);
			}
		}
		swap(A, i + 1, r);
		return i + 1;
	}
	public static void swap(Card [] A, int index1, int index2) {
		Card work = A[index1];
		A[index1] = A[index2];
		A[index2] = work;
	}
	public static void merge(Card[] A, int left, int mid, int right) {
		int n1 = mid -left;
		int n2 = right - mid;
		for(int i = 0; i < n1; i++) {
			L[i] = A[left + i];
		}
		for(int i = 0; i < n2; i++) {
			R[i] = A[mid + i];
		}
		L[n1] = new Card(null, INFTY);
		R[n2] = new Card(null, INFTY);
		int i = 0;
		int j = 0;
		for(int k = left; k < right; k++) {
			if(L[i].num <= R[j].num) {
				A[k] = L[i];
				i++;
			} else {
				A[k] = R[j];
				j++;
			}
		}
	}
	public static void mergeSort(Card[] A, int left, int right) {
		if(left + 1 < right) {
			int mid = (left + right) / 2;
			mergeSort(A, left, mid);
			mergeSort(A, mid, right);
			merge(A, left, mid, right);
		}
	}
	public static String anteiCheck(Card[] arrayA, Card[] arrayB) {
		for(int i = 0; i < arrayA.length; i++) {
			if(!arrayA[i].mark.equals(arrayB[i].mark)) {
				return "Not stable";
			}
		}
		return "Stable";
	}


}

class Card {
	String mark;
	int num;
	public Card(String mark, int num) {
		this.mark = mark;
		this.num = num;
	}

}

Measured memory_bytes: 105724
#include <iostream>
#include <map>
using namespace std;

int main() {
	int N;
	char Heads[5] = { 'M','A','R','C','H' };
	cin >> N;
	map<char, int>Nums;
	for (int i = 0; i < N; i++) {
		string s;
		cin >> s;
		Nums[s[0]]++;
	}
	long long ans = 0;
	for (int i = 0; i < 5; i++) {
		for (int j = i + 1; j < 5; j++) {
			for (int k = j + 1; k < 5; k++) {
				ans += (long long)Nums[Heads[i]] * Nums[Heads[j]] * Nums[Heads[k]];
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
from itertools import permutations
from math import sqrt

def readinput():
    n=int(input())
    xyList=[]
    for _ in range(n):
        x,y=list(map(int,input().split()))
        xyList.append((x,y))
    return n,xyList

def main(n,xyList):
    sum=0.0
    factn=0
    for tup in permutations(range(n)):
        #print(tup)
        factn+=1
        x0=xyList[tup[0]][0]
        y0=xyList[tup[0]][1]
        for i in tup:
            x=xyList[i][0]
            y=xyList[i][1]
            sum+=sqrt((x-x0)**2+(y-y0)**2)
            x0=x
            y0=y
    ans=sum/factn
    return ans

if __name__=='__main__':
    n,xyList=readinput()
    #print(xyList)
    ans=main(n,xyList)
    print(ans)



Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define int int64_t
#define rep(i, N) for(int i=0; i<N; i++)
using namespace std;
using pair = pair<int, int>;
using tup  = tuple<int, int, int>;
using vec  = vector<int>;
using vvec = vector<vec>;
// " ", ' '
// std::string str;
// str = std::to_string(int i);

// プロトタイプ宣言
// int myfunc(int, vvec);

// グローバル変数
// int N, M;
// vvec data(N, vec(M));

// 関数：

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int N; cin >> N;
	vec A(N+1, 0), B(N+1, 0), C(N+1, 0);
	rep(i, N) {
		cin >> A.at(i);
		A.at(i) -= 1;
	}
	rep(i, N) cin >> B.at(i);
	rep(i, N-1) cin >> C.at(i);

	int ans = B.at(A.at(0));
	for(int i=1; i<N; i++) {
		if(A.at(i) == A.at(i-1)+1) {
		ans += B.at(A.at(i))+C.at(A.at(i-1));
		}
		else {
		ans += B.at(A.at(i));
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
using namespace std;
int k, v[100005];
struct st{int x, y;} a;
deque<st> dq;
int main() {
	cin>>k;
	dq.push_back({1, 1});
	while(1) {
		a = dq.front(); dq.pop_front();
		if(v[a.y]) continue;
		v[a.y] = 1;
		if(!a.y) {cout<<a.x; return 0;}
		dq.push_front({a.x, a.y*10 % k});
		dq.push_back({a.x+1, (a.y+1) % k});
	}
}

Measured memory_bytes: 1408
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                Solve.Answer();
            }
            catch (Exception ex)
            {
                WriteLine(ex.ToString());
            }
        }
    }

    public class Solve
    {
        public static void Answer()
        {
            var NM = IO_ShortCut.ReadSplitInt;
            var N = NM[0];
            var M = NM[1];

            WriteLine((N * (N - 1) + M * (M - 1)) / 2);
        }
    }

    public class IO_ShortCut
    {
        #region Input
        public static string ReadString => ReadLine();
        public static int ReadInt => int.Parse(ReadLine());
        public static long ReadLong => long.Parse(ReadLine());
        public static double ReadDouble => double.Parse(ReadLine());

        public static List<string> ReadSplitString => ReadLine().Split().ToList();
        public static List<int> ReadSplitInt => ReadLine().Split().Select(s => int.Parse(s)).ToList();
        public static List<long> ReadSplitLong => ReadLine().Split().Select(s => long.Parse(s)).ToList();
        public static List<double> ReadSplitdouble => ReadLine().Split().Select(s => double.Parse(s)).ToList();
        #endregion

        #region Output
        public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
        public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No");

        #endregion
    }

    /// <summary>
    /// 正の数の四則演算のみ対応
    /// </summary>
    public class Mod
    {
        // 割る数の定義
        private readonly static long M = 1000000007;

        // 足し算
        public static long Add(long a, long b) => (a * b) % M;
        // 引き算
        public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M;
        // 掛け算
        public static long Multi(long a, long b) => (a * b) % M;
    }

}

Measured memory_bytes: 11220
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x,n;
    cin>>n;
    int t=n;
    vector<int>v;
    vector<int>::iterator y;
    while(t--)
    {
      cin>>x;
      v.push_back(x);
    }
    int m=*max_element(v.begin(),v.end());
    int p=accumulate(v.begin(),v.end(),0)-m;
    if(p>m)
      cout<<"Yes"<<endl;
    else
      cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <list>
#include <algorithm>
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin >> n;
    list<int> li;

    for (int i=0; i<n; ++i) {
        string op; cin >> op;
        if (op[0] == 'i') {
            int key; cin >> key;
            li.push_front(key);
        } else if (op == "deleteFirst") {
            li.pop_front();
        } else if (op == "deleteLast") {
            li.pop_back();
        } else {
            int key; cin >> key;
            list<int>::iterator pos = find(li.begin(), li.end(), key);
            if (pos != li.end()) {
                li.erase(pos);
            }
        }
    }

    for (list<int>::iterator it = li.begin(); it != li.end(); ++it) {
        cout << ((it == li.begin()) ? "" : " ") << *it;
    }
    cout << endl;
    return 0;
}

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

int main(){
  long long int   N;
  string S, T;
  cin >> S >> T;
  
  long long int ans = 0;
  for(long long int i = 0; i < S.size(); i++){
    if (S.at(i) != T.at(i)) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3908
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

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

    int N = scanner.nextInt();
    int M = scanner.nextInt();
    Node[] nodes = new Node[N];
    for (int i = 0; i < N; i++) nodes[i] = new Node();
    for (int i = 0; i < M; i++) {
      int x = scanner.nextInt() - 1;
      int y = scanner.nextInt() - 1;
      int z = scanner.nextInt();
      nodes[x].adjacent.add(nodes[y]);
      nodes[y].adjacent.add(nodes[x]);
    }

    int count = 0;
    for (int i = 0; i < N; i++) {
      if (!nodes[i].visited) {
        count++;
        dfs(nodes[i]);
      }
    }
    System.out.println(count);
  }

  private static void dfs(Node node) {
    node.visited = true;
    for (Node n : node.adjacent) {
      if (!n.visited) dfs(n);
    }
  }

  private static class Node {
    List<Node> adjacent = new ArrayList<>();
    boolean visited;
  }
}


Measured memory_bytes: 109248
n = int(input())
xlst = list(map(int,input().split()))
lst2 = [i for i in xlst]
xlst.sort()
l = xlst[n//2 - 1]
r = xlst[n//2]
for i in range(n):
  if lst2[i] <= l:
    print(r)
  else:
    print(l)

Measured memory_bytes: 25472
def check(pat):
  honest = [1 if i in pat else 0 for i in range(N)]
  li = pat + [i for i in range(N) if i not in pat]
    
  for i in li:
    if honest[i] == 1:
      n = len(x[i])
      for j in range(n):
        y = x[i][j]
        if honest[y[0]] != y[1]:
          return -1
    
  return len(pat)

N = int(input())
x = [0]*N
for i in range(N):
  A = int(input())
  x[i] = []
  for j in range(A):
    y1,y2 = map(int,input().split())
    x[i].append((y1-1,y2))
max_honest = 0
l = [i for i in range(N)]
n = len(l)
for i in range(2 ** N):
    pat = []
    for j in range(n):  # このループが一番のポイント
        if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
            pat.append(l[j])  # フラグが立っていたら bag に果物を詰める
    max_honest = max(max_honest,check(pat))
print(max_honest)

Measured memory_bytes: 3064
#include "bits/stdc++.h"

using namespace std;

#define int long long
#define ll long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

bool twelve(int n) {
	if (n >= 1 && n <= 12)
		return true;
	return false;
}


signed main() {

	string S;
	cin >> S;

	int f = (S[0] - '0') * 10 + (S[1] - '0');
	int s = (S[2] - '0') * 10 + (S[3] - '0');

	if (twelve(f) && !twelve(s)) {
		cout << "MMYY" << endl;
	}
	else if (!twelve(f) && twelve(s)) {
		cout << "YYMM" << endl;
	}
	else if (twelve(f) && twelve(s)) {
		cout << "AMBIGUOUS" << endl;
	}
	else
		cout << "NA" << endl;


	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;

int main(void) {
	int count[4][3][10] = {0};
	int N, i, j, k;

	cin >> N;
	for (i = 0; i < N; i++) {
		int b, f, r, v;
		cin >> b >> f >> r >> v;
		count[b - 1][f - 1][r - 1] += v;
	}
	for (i = 0; i < 4; i++) {
		if (i > 0) cout << "####################" << endl;
		for (j = 0; j < 3; j++) {
			for (k = 0; k < 10; k++) {
				cout << " " << count[i][j][k];
			}
			cout << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3092
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
using namespace std;

typedef long long ll;
typedef pair<int, int> p;
#define modulo 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9



int main() {
	ll N, M;
	cin >> N >> M;
	if (2 * N >= M) cout << M/2 << endl;
	else cout << N + (M - 2 * N) / 4 << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll readll(){
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int readint(){
    int x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
    return f*x;
}
int main(){
    ll n,m;n=readll();m=readll();
    if(n==1&&m==1){
        printf("%d\n",1);
        return 0;
    }
    if(n==1||m==1){
        printf("%lld\n",max(n,m)-2);
        return 0;
    }
    if(n==2||m==2){
        printf("%d\n",0);
        return 0;
    }
    n-=2;m-=2;
    printf("%lld\n",n*m);
    return 0;
}

Measured memory_bytes: 256
INF = 10**9+7
s = input()
dp = [[0,0,0,0] for _ in range(len(s) + 10)]

dp[0][0] = 1

for i in range(len(s)):
    for j in range(4):
        if s[i] != '?':
            dp[i+1][j] = (dp[i+1][j]+dp[i][j]) % INF
        else:
            dp[i+1][j] = (dp[i+1][j]+dp[i][j] * 3) % INF
    if s[i] == 'A' or s[i] == '?':
        dp[i+1][1] = (dp[i+1][1]+dp[i][0]) % INF
    if s[i] == 'B' or s[i] == '?':
        dp[i+1][2] = (dp[i+1][2]+dp[i][1]) % INF
    if s[i] == 'C' or s[i] == '?':
        dp[i+1][3] = (dp[i+1][3]+dp[i][2]) % INF

print(dp[len(s)][3])        

Measured memory_bytes: 27624
#include <bits/stdc++.h>
#include <numeric>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;

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

    int N, K; cin >> N >> K;
    vector<ll> x(N);
    rep(i, 0, N) cin >> x[i];

    ll res = LLONG_MAX;
    for(int L = 0, R = K-1; R < N; ++L, ++R) {
        if (L == R) {
            res = min(res, abs(x[L]));
        }
        else if (x[L] <= 0 and x[R] <= 0) {
            if (R+1 < N and x[R+1] <= 0) continue;
            else res = min(res, -x[L]);            
        }
        else if (x[L] >= 0 and x[R] >= 0) {
            res = min(res, x[R]);
        }
        else {
            ll newRes = -x[L] + x[R] + min(-x[L], x[R]);
            res = min(res, newRes);
        }
    }
    
    cout << res << endl;
}

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

cnt = 0
for i in range(n):
    if a[i] < 0:
        cnt+=1

b = list(map(abs, a))

if cnt % 2 == 0:
    print(sum(b))
else:
    print(sum(b) - 2*min(b))
    



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

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

 
        int r;
        cin >> r;
		double Pi = 22.0 / 7.0;
        double ans = 2 * Pi * (double)(r);
        cout << ans;
    

    return 0;
}


Measured memory_bytes: 3796
#include <stdio.h>
#include<string>
#include<iostream>
using namespace std;
int tenki(string a, string b){
    int count=0;
    
    for(int i=0; i<3; i++){
        if(a[i]==b[i])
        count+=1;
        else
        count=count;
    }
    return count;
}
int main()
{
    string str1,str2;
    
    cin>>str1;
    cin>>str2;
    
    cout<<tenki(str1,str2);

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define P pair<ll,ll>
#define Graph vector<vector<P>>
#define fi first
#define se second
constexpr ll mod=1000000007;
constexpr ll INF=(1ll<<60);
constexpr double pi=3.14159265358979323846;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<typename T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}

int main(){
    ll n;cin>>n;
    ll k;cin>>k;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];


    ll ng=0,ok=1e9+1;
    while(abs(ng-ok)>1){
        ll mid=(ok+ng)/2;
        ll cnt=0;

        rep(i,n){
            cnt+=max(0ll,(ll)((a[i]-1)/mid));
        }

        if(cnt<=k){
            ok=mid;
        }else{
            ng=mid;
        }   
    }

    cout<<ok<<endl;
        

    return 0;
}

Measured memory_bytes: 4736
//https://codeforces.com/contest/1295/problem/A
//BROWNIE TK

#include <bits/stdc++.h>
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define pb push_back
#define popb pop_back()
#define pf push_front
#define popf pop_front()

#define si size()
#define be begin()
#define en end()
#define all(v) v.be, v.en

#define le length()
#define mp make_pair
#define mt make_tuple
#define acc(v) accumulate(all(v), 0)
#define F first
#define S second

#define pll pair<lli, lli>
#define pii pair<int, int>
#define pil pair<int, lli>

#define forz(i, n) for (int i = 0; i < n; i++)
#define fore(i, m, n) for (int i = m; i <= n; i++)
#define rforz(i, n) for (int i = n - 1; i >= 0; i--)
#define rfore(i, m, n) for (int i = n; i >= m; i--)

#define deci(n) fixed << setprecision(n)
#define high(n) __builtin_popcount(n)
#define highll(n) __builtin_popcountll(n)
#define parity(n) __builtin_parity(n)
#define ctz(n) __builtin_ctz(n)

#define bset(a, p) ((a) | (1ll << (p)))
#define bchk(a, p) ((a) & (1ll << (p)))
#define bxor(a, p) ((a) ^ (1ll << (p)));
#define brem(a, p) (bchk(a, p) ? (bxor(a, p)) : (a))
/*SOME BITMASK KNOWLEDGE
1)x & (x - 1):sets the last one bit of x to zero
power of two exactly when x & (x − 1) = 0.
2)x & -x:sets all the one bits to zero, except last one bit
3)x | (x - 1):inverts all the bits after the last one bit*/

#define lb lower_bound
#define ub upper_bound
#define er equal_range

#define findnot find_first_not_of

#define maxe *max_element
#define mine *min_element

#define mod 1000000007
#define mod2 998244353
#define gcd __gcd
#define kira ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)

#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl

#define oset tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define osetlli tree<lli, null_type, less<lli>, rb_tree_tag, tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements sbtriectly lesser than k
//2. find_by_order(k) : k-th element in the set
#define ofk order_of_key
#define fbo find_by_order
using namespace std;

/*STD funcions*/
lli power(lli x, lli y, lli p)
{
    lli res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
lli modi(lli a, lli m) { return power(a, m - 2, m); }
/*CODE BEGINS*/

int main()
{
    kira;
    string s;
    cin>>s;
    int n=int(s.si);
    forz(i,n)cout<<"x";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main() {
	int n;
	scanf("%d", &n);
	int num[200010];
	for (int i = 0; i < n; ++i) scanf("%d", num + i);
	
	long long cnt = 0;
	int i = 0, j = 0, r = 0;
	while (i < n) {
		while (j < n && (r & num[j]) == 0) {
			r |= num[j];
			j++;
		}
		cnt += j - i;
		r ^= num[i];
		i++;
	}
	printf("%lld\n", cnt);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
//~ #include <ext/pb_ds/assoc_container.hpp>
//~ #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//~ using namespace __gnu_pbds; 
#define mp make_pair
#define endl '\n'
typedef long long ll;
 
const int INF=1e9+5;
const ll lim=(ll)3e16;
const int N=4e5+5;
const int mod=1e9+7;	
const ll oo=1e18+5;

//~ typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;


int main(){
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
	int n,k;
	cin>>n>>k;
	int ans=0;
	while(n){
		++ans;
		n/=k;
	}
	cout<<ans;
	return 0;	
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!
import sys

def input():
    return sys.stdin.readline().strip()

N = int(input())
s = [input() for _ in range(N)]
M = int(input())
t = [input() for _ in range(M)]
a = set(s)
s_num = 0
t_num = 0
max_num = 0

for i in a:
    s_num = s.count(i)
    t_num = t.count(i)
    if max_num < s_num - t_num:
        max_num = s_num - t_num
print(max_num)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <bitset>
#include <math.h>
#include <iomanip>
#include <queue>
#define inp(X) cin >> X
#define out(X) cout << X << endl
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define MAX(A) *max_element(A.begin(),A.end())
#define MIN(A) *min_element(A.begin(),A.end())
#define SORT(A) sort(A.begin(),A.end())
using namespace std;

typedef long long int ll;
#define MOD 1000000007
#define INF 1000000001

ll gcd(ll x, ll y){
	if(y==0) return x;
	return gcd(y,x%y);
}

bool bfs(vector<vector<int>> g, vector<int> &dist, int sv)
{
	queue<int> q;
	q.push(sv);
	dist[sv]=0;
	while(!q.empty()){
		int now = q.front(); q.pop();
		for(auto v : g[now]){
			if(dist[v]!=-1) continue;
			dist[v] = dist[now]+1;
			q.push(v);
		}
	}
}

int main(void) {
	int r; cin >> r;
	out(3*r*r);
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n ; ++i)
#define REP(i,a,b) for(int i=a; i<b; ++i)
typedef long long ll;
//プロトタイプ宣言
int gcd(int , int);


int main(){
    string s;
    cin >> s;
    int ans = 0 , count = 0;
    rep(i,s.size()){
        if(i % 2 == 0 && s[i] != '1') ans++;
        else if(i % 2 == 1 && s[i] != '0') ans++;
    }
    rep(i,s.size()){
        if(i % 2 == 0 && s[i] != '0') count++;
        else if(i % 2 == 1 && s[i] != '1') count++;
    }
    cout << min(ans , count) << endl;
}








































//以下、ライブラリ
//ユークリッドの互除法

int gcd(int a, int b) {
  return b ? gcd(b, a%b) : a;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
//#define mod 10007
#define mod 1000000000000000000

using namespace std;

string s;
long long beki[1000005], sum[100005];

int main(void)
{
	cin >> s;
	long long n = s.size();
	if(n == 1){
		cout << s << endl;
		return 0;
	}
	reverse(s.begin(), s.end());
	
	beki[0] = 1;
	for(long long i = 1; i <= n; i++) beki[i] = beki[i-1] * 5 % mod;
	
	sum[0] = 1;
	for(long long i = 1; i <= n; i++){
		sum[i] = sum[i-1] + beki[i], sum[i] %= mod;
	}
	
	long long x = 1;
	for(long long i = 0; i < n-2; i++) x *= 2, x %= mod;
	
	long long ans = 0;
	for(long long i = 0; i < n; i++){
		long long tmp = 2;
		if(i > 0){
			tmp = sum[i-1] + beki[i-1] * 10 % mod, tmp %= mod;
		}
		ans += x * tmp % mod * (s[i]-'0') % mod, ans %= mod;
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#pragma region Header
#define _CRT_SECURE_NO_WARNINGS
#define print(x) printf("%d\n", x)
#define loop(len) for(int i=0; i<len; ++i)
#define outer(len) for(int i=0; i<len; ++i)
#define inner(s,len) for(int j=s; j<len; ++i)
#define foreach(a) for(int i : a)
#define veci vector<int>
#define vecii vector<long long>
#define pb push_back
#define pp pop_back
#define b begin
#define e end
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <string>
#include <cstring>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include<cmath>
#include<map>
typedef long long  ll;
using namespace std;
#pragma endregion

/*
___  ___     _   _   _____                   _   _ _
|  \/  |    | \ | | /  ___|                 | | | (_)
| .  . |_ __|  \| | \ `--.  __ _ _   _ ___  | |_| |_
| |\/| | '__| . ` |  `--. \/ _` | | | / __| |  _  | |
| |  | | |_ | |\  | /\__/ | (_| | |_| \__ \ | | | | |
\_|  |_|_(_)\_| \_/ \____/ \__,_|\__, |___/ \_| |_|_|
                                  __/ |
                                 |___/

______Am_not_too_proud____
*/


int n, p;
int A,B;
int p1, p2, p3;
int Contests;


int main() {
	ios::sync_with_stdio(0);
	cin >> n >> A >> B;

	loop(n) {
		cin >> p;
		if (p <= A)
			p1++;
		else if (p >= A + 1 && p <= B)
			p2++;
		else if (p >= B + 1)
			p3++;
	}
	
	while (p1 != 0 && p2 != 0 && p3 != 0) {
		p1--;
		p2--;
		p3--;
		Contests++;
	}

	cout << Contests << '\n';
	return 0;
}

Measured memory_bytes: 256
unittest
{
	assert( [ "3 3", ".#.", "..#", "#.." ].parse.expand.solve == 10 );
	assert( [ "2 4", "....", "...." ].parse.expand.solve == 0 );
	assert( [ "4 3", "###", "###", "...", "###" ].parse.expand.solve == 6 );

	assert( [ "5 3", "###", "...", "###", "...", "###" ].parse.expand.solve == 18 );		// 追加ケース
}



import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto hw = input.front.split.to!( long[] );
	auto ss = new string[ hw[ 0 ] ];
	foreach( ref s; ss )
	{
		input.popFront;
		s = input.front;
	}
	return tuple( hw[ 0 ], hw[ 1 ], ss );
}

auto solve( long h, long w, string[] ss )
{
	auto ans = 0L;
	auto lss = new long[][]( h, w );
	auto lc = 0L;
	
	for( auto i = 0; i < h; i++ )
	{
		for( auto j = 0; j < w; j++ )
		{
			auto bc = 0L;
			auto wc = 0L;
			lc++;
			
			// 島判定して島内の黒マスと白マスをカウント
			ss.checkBlack( i, j, lc, lss, bc, wc );
			
			// 黒マスと白マスの組数を計算
			ans += bc * wc;
		}
	}
	
	return ans;
}

void checkBlack( string[] ss, long i, long j, long lc, ref long[][] lss, ref long bc, ref long wc )
{
	// 黒マスは島判定済だったら再判定やらない
	if( ss[ i ][ j ] != '#' || 0 < lss[ i ][ j ] ) return;
	
	// 自分に島番号を付けて黒マス数に加算
	lss[ i ][ j ] = lc;
	bc++;
	
	// 隣の白マスチェック
	if( 0 <= i - 1             ) ss.checkWhite( i - 1, j, lc, lss, bc, wc );
	if( i + 1 < ss.length      ) ss.checkWhite( i + 1, j, lc, lss, bc, wc );
	if( 0 <= j - 1             ) ss.checkWhite( i, j - 1, lc, lss, bc, wc );
	if( j + 1 < ss[ i ].length ) ss.checkWhite( i, j + 1, lc, lss, bc, wc );
}

void checkWhite( string[] ss, long i, long j, long lc, ref long[][] lss, ref long bc, ref long wc )
{
	// 黒マスは島判定済でも別の島だったら再判定やる
	if( ss[ i ][ j ] != '.' || 0 < lss[ i ][ j ] ) return;
	
	// 自分に島番号を付けて白マス数に加算
	lss[ i ][ j ] = lc;
	wc++;
	
	// 隣の黒マスチェック
	if( 0 <= i - 1             ) ss.checkBlack( i - 1, j, lc, lss, bc, wc );
	if( i + 1 < ss.length      ) ss.checkBlack( i + 1, j, lc, lss, bc, wc );
	if( 0 <= j - 1             ) ss.checkBlack( i, j - 1, lc, lss, bc, wc );
	if( j + 1 < ss[ i ].length ) ss.checkBlack( i, j + 1, lc, lss, bc, wc );
}


Measured memory_bytes: 17660
using System;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            var a = int.Parse(input[0]);
            var b = int.Parse(input[1]);
            if (b % a == 0)
            {
                Console.WriteLine(a + b);
            }
            else
            {
                Console.WriteLine(b - a);
            }
        }
    }
}

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

typedef long long ll;
typedef long double ld;

map <char, int> ima;

int main(){
    ios_base::sync_with_stdio(false);
    cout.precision(10);
    cout<<fixed;

    string s;
    cin >> s;
    for(auto c : s){
        ima[c]++;
    }
    for(auto c : ima){
        if(c.second%2){
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
template<typename T> using v = vector<T>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
void dump_debug(T list) {
#ifdef MY_DEBUG
    each(e, list) cout << e << " ";
    printf("\n");
#endif
}

inline ll inl() {
    ll x;
    cin >> x;
    return x;
}

inline string ins() {
    string x;
    cin >> x;
    return x;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        string l = ins();
        ll n = l.size();
        vvl dp(n + 1, vl(2));
        dp[0][0] = 1;
        rep(i, n) {
            if (l[i] == '1') {
                dp[i + 1][0] += dp[i][0] * 2 % mod;
                dp[i + 1][1] += dp[i][1] * 2 % mod;
                dp[i + 1][1] += dp[i][0];
                dp[i + 1][1] += dp[i][1];

                dp[i + 1][0] %= mod;
                dp[i + 1][1] %= mod;
            } else {
                dp[i + 1][0] += dp[i][0];
                dp[i + 1][1] += dp[i][1];
                dp[i + 1][1] += dp[i][1] * 2 % mod;

                dp[i + 1][0] %= mod;
                dp[i + 1][1] %= mod;
            }
        }
        cout << (dp[n][0] + dp[n][1]) % mod << endl;

#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 5760
/*** ?????????????????????????????? ***/

#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)
#define INF 1<<20

int dx[4]={1, 0, -1, 0};
int dy[4]={0, 1, 0, -1};
int board[31][31];
int cost[4];
int hist[4][31][31];
int w, h;

void dfs(int x, int y, int ccost, int dir){
	if(!(x>=0&&x<w) || !(y>=0&&y<h)) return;
	if(hist[dir][y][x] <= ccost) return;
	hist[dir][y][x]=ccost;
	
	if(board[y][x]!=4){
		int ddir=(dir+board[y][x])%4;
		dfs(x+dx[ddir], y+dy[ddir], ccost, ddir);
	}
	REP(k, 0, 4){
		if(k!=board[y][x]){
			int ddir=(dir+k)%4;
			dfs(x+dx[ddir], y + dy[ddir], ccost+cost[k], ddir);
		}
	}
	
	return;
}

int main(){
	
	while(cin>>w>>h, w||h){
		board[31][31]={};
		cost[4]={};
		
		REP(i, 0, h){
			REP(j, 0, w){
				cin >> board[i][j];
			}
		}
		REP(i, 0, 4) cin >> cost[i];
		REP(k, 0, 4){
			REP(i, 0, h){
				REP(j, 0, w){
					hist[k][i][j]=INF;
				}
			}
		}
		
		dfs(0, 0, 0, 0);
		
		int ans=INF;
		REP(k, 0, 4) ans=min(ans, hist[k][h-1][w-1]);
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3296