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

using namespace std;

const int MAX_N = 114, INF = 1e4;

int N, M, F[MAX_N][MAX_N];
char grid[MAX_N][MAX_N];

int main() {
    scanf("%d%d", &N, &M);
    for (int i = 1; i <= N; i++) scanf("%s", grid[i] + 1);
    for (int i = 1; i <= N; i++)
        for (int j = 1; j <= M; j++)
            F[i][j] = INF;
    F[1][1] = grid[1][1] == '#';
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= M; j++) {
            if (i < N) F[i + 1][j] = min(F[i + 1][j], F[i][j] + (grid[i][j] != grid[i + 1][j]));
            if (j < M) F[i][j + 1] = min(F[i][j + 1], F[i][j] + (grid[i][j] != grid[i][j + 1]));
        }
    }
    printf("%d\n", (F[N][M] + 1) / 2);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int x[900][900],h,w,a,y[900],s;
queue<int>Q,R;
int main(){
	while(true){
		memset(x,0,sizeof(x));
		memset(y,0,3600);
		cin>>w>>h;
		if(!w){break;}
		for(int i=0;i<h*2-1;i++){
			if(i%2==1){
				for(int j=0;j<w;j++){
					cin>>a;
					if(!a){
						x[(i/2)*30+j][(i/2+1)*30+j]=1;
					}
				}
			}
			else{
				for(int j=0;j<w-1;j++){
					cin>>a;
					if(a==0){
						x[(i/2)*30+j][(i/2)*30+j+1]=1;
					}
				}
			}
		}
		Q.push(0);
		s=1;
		y[0]=1;
    	while(y[(h-1)*30+(w-1)]==0){
			while(!Q.empty()){
				a=Q.front();
				for(int j=0;j<900;j++){
					if((x[a][j]==1||x[j][a]==1)&&y[j]==0){
						y[j]=1;
						R.push(j);
					}
				}
				Q.pop();
			}
			while(!R.empty()){
				Q.push(R.front());
				R.pop();
			}
			s++;
			if(s>=1000){s=0;break;}
		}
		while(!Q.empty()){
			Q.pop();
		}
		cout<<s<<endl;
	}
}

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

b = list(enumerate(a))

l = sorted(b[:2*n], key=lambda x: x[1], reverse=True)
r = sorted(b[n:], key=lambda x: x[1])

big = [0] * (3*n)
small = [0] * (3*n)

for i, (pos, z) in enumerate(l):
    big[pos] = i
for i, (pos, z) in enumerate(r):
    small[pos] = i

first = sum(a[:n])
second = 0
for pos, z in r[:n]:
    second += z
i = 2 * n
j = n-1
ans = first - second
for split in range(n, 2*n):
    if big[split] < i:
        first += a[split]
        i -= 1
        while l[i][0] > split:
            i -= 1
        first -= l[i][1]
    if small[split] <= j:
        second -= a[split]
        j += 1
        while r[j][0] < split:
            j += 1
        second += r[j][1]
    ans = max(ans, first - second)
print(ans)

Measured memory_bytes: 68700
#include <bits/stdc++.h>
using namespace std;
int main(){
 int N;
  cin>>N;
  long double sum=0;
  for(int i=0;i<N;i++){
  long double a;
    cin>>a;
    sum+=(1/a);
  }
  cout<<1/sum<<endl;
  
}

Measured memory_bytes: 3760
#include<iostream>
#include<cmath>
using namespace std;
using ll = long long;

ll gcd(ll a, ll b) {
    if (a < b)swap(a, b);
    ll r = a % b;
    while (r != 0) {
        a = b; b = r; r = a % b;
    }
    return b;
}

ll cnt(ll n)
{
    ll rtn = 0;
    for (ll i = 2; i <= sqrt(n); i += (i > 2) + 1)
    {
        if (n % i == 0)
        {
            while (n % i == 0)n /= i;
            rtn++;
        }
    }
    if (n > 1)rtn++;
    return rtn;
}

int main() {
    ll a, b;
    cin >> a >> b;
    if (a < b)swap(a, b);
    ll g = gcd(a, b);
    cout << cnt(g) + 1 << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();

		int acCnt = 0;
		int waCnt = 0;
		int tleCnt = 0;
		int reCnt = 0;

		for (int i = 0; i < N; i++) {
			String status = sc.next();
			switch (status) {
			case "AC":
				acCnt++;
				break;
			case "WA":
				waCnt++;
				break;
			case "TLE":
				tleCnt++;
				break;
			case "RE":
				reCnt++;
				break;
			}

		}
		System.out.println("AC x "+acCnt);
		System.out.println("WA x "+waCnt);
		System.out.println("TLE x "+tleCnt);
		System.out.println("RE x "+reCnt);

	}
}

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

int main() {
	string s;
	cin >> s;
	string k = "keyence";

	string he = "";
	for (int i = 0; i < 7; i++) {
		if (s.at(i) == k.at(i))he += s.at(i);
		else break;
	}

	string ta = "";
	for (int i = 0; i < 7; i++) {
		if (s.at(s.length() - 1 - i) == k.at(6 - i))ta = k.at(6 - i) + ta;
		else break;
	}
	if (he.length() + ta.length() >= 7)cout << "YES" << endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 256
#!/mnt/c/Users/moiki/bash/env/bin/python
# N,K = list(map(int, input().split()))
# h = list(map(int, input().split()))

# (N,K), h = map(int, input().split()), list(map(int, input().split()))
N,K,*h = map(int, "\n".join([input(), input()]).split())

# suml = [1e9 for i in range(N)]
# suml[0] = 0


suml = [0]*N

# for i in range(1,N):
for i,e_h in enumerate(h):
    if i == 0:
        continue

    start = max(0, i-K)
    cost  = min(cst + abs( e_h - hgh) for cst, hgh in 
                   zip(suml[start:i], h[start:i]))
    # cost  = min(cst + abs( h[i] - hgh ) for cst, hgh in 
    #               zip(suml[start:i], h[start:i]))
    suml[i] = cost

print(suml[-1])
        



Measured memory_bytes: 14056
#include <stdio.h>
#include <math.h>

typedef struct Point{
	double x,y;
}Point_t;

void kock(int n, Point_t a,Point_t b);

int main()
{
	Point_t a, b;
	int n;
	
	scanf("%d",&n);
	
	a.x=0;
	a.y=0;
	b.x=100;
	b.y=0;
	
	printf("%.8f %.8f\n",a.x,a.y);
	kock(n,a,b);
	printf("%.8f %.8f\n",b.x,b.y);
	
	return 0;
}

void kock(int n, Point_t a,Point_t b)
{
	Point_t s,t,u;
	double th=M_PI*60.0/180.0;
	if(n==0)
	{
		return;
	}
	
	s.x=(2.0*a.x+1.0*b.x)/3.0;
	s.y=(2.0*a.y+1.0*b.y)/3.0;
	t.x=(1.0*a.x+2.0*b.x)/3.0;
	t.y=(1.0*a.y+2.0*b.y)/3.0;
	u.x=(t.x-s.x)*cos(th)-(t.y-s.y)*sin(th)+s.x;
	u.y=(t.x-s.x)*sin(th)+(t.y-s.y)*cos(th)+s.y;
	
	kock(n-1,a,s);
	printf("%.8f %.8f\n",s.x,s.y); 
	kock(n-1,s,u);
	printf("%.8f %.8f\n",u.x,u.y); 
	kock(n-1,u,t);
	printf("%.8f %.8f\n",t.x,t.y); 
	kock(n-1,t,b);
}


Measured memory_bytes: 2036
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {
	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		ArrayList<Integer> array = new ArrayList<Integer>();
		try{
			while(true){
				char[]a= br.readLine().toCharArray();
				array.add(parseInt(a));
			}
		}catch(Exception e){
		}

		for(int v : array){
			System.out.println(v);
		}
	}

	public static int parseInt(char a){
		int temp = 0;
		switch(a){
		case 'I':
			temp = 1;break;
		case 'V':
			temp = 5;break;
		case 'X':
			temp = 10;break;
		case 'L':
			temp = 50;break;
		case 'C':
			temp = 100;break;
		case 'D':
			temp = 500;break;
		case 'M':
			temp = 1000;break;
		}
		return temp;
	}

	static int[] getNumbers(char[] a){
		int[] numbers = new int[a.length];
		for(int i = 0; i < numbers.length; i++){
			numbers[i] = parseInt(a[i]);
		}
		if(numbers.length > 1){
			for(int i = 1; i < numbers.length; i++){
				if(numbers[i] > numbers[i - 1]){
					numbers[i -1] *= -1;
				}
			}
		}

		return numbers;
	}

	public static int parseInt(char[] romanValue){
		int temp = 0;
		int[] numbers = getNumbers(romanValue); 
		for(int i = 0; i < numbers.length; i++){
			temp += numbers[i];
		}
		return temp;
	}

}

Measured memory_bytes: 16884
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, [graph1; $len:expr]) => {{
        let mut g = vec![vec![]; $len];
        let ab = read_value!($next, [(usize1, usize1)]);
        for (a, b) in ab {
            g[a].push(b);
            g[b].push(a);
        }
        g
    }};
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => (read_value!($next, usize) - 1);
    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        read_value!($next, [$t; len])
    }};
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (let _ = write!(out,$($format)*););
    }
    input! {
        n: usize,
        xy: [(i64, i64); n],
    }
    const INF: i64 = 1 << 40;
    let mut xma = -INF;
    let mut xmi = INF;
    let mut yma = -INF;
    let mut ymi = INF;
    for (x, y) in xy {
        let (x, y) = (x + y, x - y);
        xma = max(xma, x);
        xmi = min(xmi, x);
        yma = max(yma, y);
        ymi = min(ymi, y);
    }
    puts!("{}\n", max(xma - xmi, yma - ymi));
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 3972
#include<bits/stdc++.h>
#define int long long
using namespace std;
constexpr int mod=1e9+7;
signed main(){
    int n,k,a[200000];
    cin>>n>>k;
    for(int i=0;i<n;i++)
        cin>>a[i];
    for(int i=0;i<k;i++){
        bool ok=1;
        for(int j=0;j<n;j++)
            if(a[j]!=n)
                ok=0;
        if(ok)
            break;
        int imos[200001]={};
        for(int j=0;j<n;j++){
            imos[max(j-a[j],0ll)]++;
            imos[min(j+a[j]+1,n)]--;
        }
        for(int j=0;j<n;j++)
            imos[j+1]+=imos[j];
        for(int j=0;j<n;j++)
            a[j]=imos[j];
    }
    for(int i=0;i<n;i++)
        cout<<a[i]<<(i+1==n?'\n':' ');
}

Measured memory_bytes: 6720
n=int(input())
s=input()
t=input()
actualfail=0
for i in range(n):
  fail=0
  for j in range(n-i):
    if s[i+j]!=t[j]:
      fail=1
      break
  if fail==0:
    actualfail=1
    break
if actualfail==1:
  print(n+i)
else:
  print(2*n)

Measured memory_bytes: 38256
parseline(str=readline()) = parse.(Int, split(str))
function Ki()
    N, Q = parseline()
    tree = [Int[] for _ in 1:N]
    score = zeros(Int, N)
    for _ in 1:N-1
        a, b = parseline()
        push!(tree[a], b)
        push!(tree[b], a)
    end
    for _ in 1:Q
        p, x = parseline()
        score[p] += x
    end
    que = [1]
    seen = fill(false, N)
    seen[1] = true
    while !isempty(que)
        parent = popfirst!(que)
        for child in tree[parent]
            if !seen[child]
                score[child] += score[parent]
                push!(que, child)
                seen[child] = true
            end
        end
    end
    for s in score
        print(s, " ")
    end
end
Ki()

Measured memory_bytes: 257060
#include<iostream>
#include<fstream>
#include<algorithm>
#include<vector>
#include<math.h>
#include<cmath>
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<stdio.h>
#include<queue>
using namespace std;
int main()
{
  string a[4];
  cin>>a[0]>>a[1]>>a[2];
  cout<<a[0][0]
      <<a[1][1]
      <<a[2][2]<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include <set>
#include <cassert>
#include<cmath>
#include<climits>
#include<iomanip>
using namespace std;
#define MOD 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define all(hoge) hoge.begin(),hoge.end()
const long long INF = 1LL << 60;


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

class UnionFind {
	vector<int> data;
public:
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int find(vector<long long> &arr, long long obj) {
	if (arr[arr.size() - 1] < obj)return arr.size()-1;
	if (arr[0] > obj)return -1;

	int min = 0; int max = arr.size() - 1;
	for (int i = 0; i < arr.size(); i++) {
		if (arr[min+(max-min) / 2] > obj) {
			max = min + (max - min) / 2;
		}
		else {
			min = min + (max - min) / 2;
		}
		if (max - min == 1) {
			return min;
		}
	}


}

//約数求める //約数
void divisor(ll n,vector<ll> &ret) {
	for (ll i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ret.push_back(i);
			if (i * i != n) ret.push_back(n / i);
		}
	}
	sort(ret.begin(), ret.end());
	
}
//階乗
long long factorial(long long n, long long mod) {
	long long ret = 1;
	for (long long i = 1; i <= n; i++) {
		ret = (ret * i) % mod;
	}
	return ret;
}
//モジュラ逆数
long long inv_mod(long long n, long long mod) {
	long long a = n % mod, b = mod - 2, ret = 1;
	while (b > 0) {
		if (b & 1) ret = (ret * a) % mod;
		a = (a * a) % mod;
		b >>= 1;
	}
	return ret;
}

long long nPr(long long n, long long r, long long mod) {
	long long ret = 1;
	for (long long i = n; i >= n - r + 1; i--) {
		ret = ret * (i % mod) % mod;
	}
	return ret;
}

long long nCr(long long n, long long r, long long mod) {
	return nPr(n, r, mod) * inv_mod(factorial(r, mod), mod) % mod;
}

bool compare_by_b(pair<ll, ll> a, pair<ll, ll> b) {//降順second
	if (a.second != b.second) {
		return a.second > b.second;
	}
	else {
		return a.first > b.first;
	}
}

bool compare_by_a(pair<ll, ll> a, pair<ll, ll> b) {//降順first
	if (a.first != b.first) {
		return a.first > b.first;
	}
	else {
		return a.second > b.second;
	}
}

ll gcd(ll m, ll n){
	if (n == 0)return m;
	return gcd(n, m%n);
}//gcd


int main() {
	int q;
	cin >> q;
	rep(i, q) {
		ll a, b;
		cin >> a >> b;
		ll temp = (ll)sqrt(a*b);
		if (temp * temp == a * b) {
			temp--;
		}
		if (temp*(temp + 1) < a*b) {
			if (a == b) {
				cout << temp * 2  << endl;
			}
			else {
				cout << temp * 2 - 1 << endl;
			}
		}
		else
		{
			cout << (temp - 1) * 2 << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
using namespace std;
#define LL long long
LL FindNum(LL N);

int main()
{
    LL N,M;
    cin >> N;
    M=FindNum(N);
    cout << M+N/FindNum(N)-2;
}

LL FindNum(LL N)
{
    for(int i=sqrt(N);i>=2;i--)
    {

        if(N%i==0)
            return i;

    }
    return N;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b,n;
  cin>>n;
  if(n==1){
    cout<<"Hello World\n";
  }else{
    cin>>a>>b;
    cout<<a+b<<"\n";
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int maxn=2e5+5;
const int INF=1e9+7;

int main()
{
    string str;
    double x;
    int n;
    cin>>n;

    double s=0;
    while (n--)
    {
        cin>>x>>str;

        if (str=="JPY")
        s+=x;
        else 
        {
            s+=(x*380000.0);
        }
    }

    cout<<s<<endl;
   

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
#define MOD 1000000007
using ll = long long;
using namespace std;
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 (a>b) { a=b; return 1; } return 0; }

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
vector<int> a(n,0);
ll total = 0;
rep(i, n){
    cin >> a[i];
    total+=a[i];
}
sort(a.begin(), a.end(),greater<int>());
if(4*m*a[m-1]>=total){
    cout << "Yes" << endl;
}
else{
    cout << "No" << endl;
}

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

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }



string check = "yuiophjklnm";
string str;


bool isright(char c) {
    for (int i = 0; i < check.size(); ++i)
        if (check[i] == c) return true;
    return false;
}

int main() {
    while (cin >> str) {
        if (str == "#") break;
        
        int con = 0;
        bool now = isright(str[0]);
        for (int i = 1; i < str.size(); ++i) {
            bool nex = isright(str[i]);
            
            if (nex != now) {
                ++con;
                now = nex;
            }
        }
        cout << con << endl;
    }
    
    return 0;
}


Measured memory_bytes: 1188
#include <stdio.h>

int main(void)
{
  unsigned long k, a, b;
  unsigned long sum = 1;
  int i;

  scanf("%ld %ld %ld", &k, &a, &b);

  if (a + 2 >= b)
    sum += k;
  else {
    while (sum < a) {
      sum++;
      k--;
    }
    sum += k / 2 * (b - a) + k % 2;
  }

  printf("%ld\n", sum);

  return 0;
}


Measured memory_bytes: 128
n,h=map(int,input().split())
a=[]
for i in range(n):
  b,c=map(int,input().split())
  a+=[[b,0],[c,1]]
a.sort(reverse=1)
i=0
ans=0
while h>0:
  if a[i][1]==1:
    h-=a[i][0]
    ans+=1
  else:
    ans+=0--h//a[i][0]
    h=0
  i+=1
print(ans)

Measured memory_bytes: 30564
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1001001001
#define LINF 1001001001001001001
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LLP;

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

  if (N > 1 && M > 1) cout << (N - 2) * (M - 2) << endl;
  else if (N == 1 && M > 1) cout << (M - 2) << endl;
  else if (M == 1 && N > 1) cout << (N - 2) << endl;
  else cout << 1 << endl;

  return 0;
}

Measured memory_bytes: 3528
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>

int main() {

    int n;

    scanf("%d", &n);

    int chkflg = 0;

    if (n <= 81) {

        for (int i = 1; i <= 9; i++) {

            if (n % i == 0) {

                int j = n / i;

                //printf("%d %d\n", i, j);

                if (j >= 1 && j <= 9) {
                    chkflg = 1;
                    break;
                }

            }
        }
    }

    printf("%s", (chkflg == 1 ? "Yes" : "No"));

    return 0;

}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int mod = 1e9+7;

vector<int> G[100005];

pair<ll,ll> dfs(int u, int par){

    ll subt_root_white = 1;
    ll subt_root_black = 0;

    for(int v : G[u]){
        if(v == par) continue;
        pair<ll,ll> tmp = dfs(v,u);
        
        subt_root_black = ((subt_root_white*tmp.second)%mod + (subt_root_black*tmp.first)%mod + (subt_root_black*tmp.second)%mod);
        subt_root_white = (subt_root_white*tmp.first)%mod;
    }

    return make_pair((subt_root_black + subt_root_white)%mod , subt_root_white);
}


int main(){

    int n; cin >> n;
    for(int i = 1; i < n; i++){
        int from, to;
        cin >> from >> to;
        G[from].push_back(to);
        G[to].push_back(from);
    }

    pair<ll,ll> tmp = dfs(1,-1);
    cout << (tmp.first + tmp.second)%mod << endl;

    return 0;
}

Measured memory_bytes: 12672
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<numeric>
#include<set>
#include<string>
#include<utility>
#include<vector>

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define all(x)  (x).begin(), (x).end()
#define MAX 10000
using namespace std;
typedef long long ll;

int main(){
  int n, k; cin >> n >> k;
  vector<int> vec(50);
  rep(i, 0, n){
    cin >> vec[i];
  }
  sort(vec.begin(), vec.begin()+n);
  int ans = 0;
  per(i, n-k, n){
    ans += vec[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
def chk(S):
    n = len(S)
    i = n
    while i > 0:
        if S[i-5:i] == 'dream' or S[i-5:i] == 'erase':
            i -= 5
        elif S[i-6:i] == 'eraser':
            i -= 6
        elif S[i-7:i] == 'dreamer':
            i -= 7
        else:
            return False
    return True

S = input()
if chk(S):
    print("YES")
else:
    print("NO")
    

Measured memory_bytes: 3188
using System;
class ProgramA
    {
        static void Main(string[] args)
        {
            //入力
            string[] input = Console.ReadLine().Split(' ');
            int m = int.Parse(input[0]);
            int n = int.Parse(input[1]);

            //奇数なら(n+1)/2、偶数ならn/2。intは切り捨てなのでこれで解答可能
            Console.WriteLine((m-1)*m/2 + n*(n-1)/2);
        
        }
}

Measured memory_bytes: 11220
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int a, b;
	cin >> a >> b;
	cout << max({a + b, a - b, a * b}) << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 256
n,m = map(int,input().split())

k = [0] * n
a = [0] * n

for i in range(0,n):
    info = input().split()
    k[i] = info[0]
    a[i] = info[1:]

l = a[0][:]
for k in range(1,n):
    new = []
    for x in l:
        if x in a[k]:
            new.append(x)
    l = new[:]

print(len(l))

Measured memory_bytes: 3064
//#pragma GCC optimize(2)
//#pragma GCC optimize(3,"Ofast","inline")


#include<stdio.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<string>
#include<sstream>
#include<algorithm>
#include<map>
//#include<unordered_map>
#include<set>
#include<queue>
#include<deque>
#include<stack>
#include<vector>
#include<bitset>
using namespace std;
typedef long long ll; 
typedef unsigned int ull; 
typedef pair<ll, ll> pll; 
const int mod = 1e9 + 7;
const int N = 1e6 + 5;
struct ed{
	int to, nxt, w;
}e[N << 1];
int head[N], tot = 1;
void add(int u, int v){
	e[tot].to = v, e[tot].nxt = head[u], head[u] = tot++;
}

int l, n, m;
int a[60][3];
int  main()
{
	while (~scanf("%d", &l))
	{
		m = 0;
		n = 0;
		if (!l)
		{
			a[m][0] = 1;
			a[m][1] = 2;
			a[m][2] = 0;
			m++;
		}
		else if (l <= (1 << 19))
		{
			while ((1 << n) <= l)
				n++;
			for (int i = 1; i < n; i++)
			{
				a[m][0] = i;
				a[m][1] = i + 1;
				a[m][2] = 0;
				m++;
				a[m][0] = i;
				a[m][1] = i + 1;
				a[m][2] = 1 << (i - 1);
				m++;
			}
			for (int i = n - 1, j = 1 << (n - 1); i >= 1; i--)
			{
				if (j + (1 << (i - 1)) <= l)
				{
					a[m][0] = i;
					a[m][1] = n;
					a[m][2] = j;
					m++;
					j += 1 << (i - 1);
				}
			}
			
		}
		else
		{
			n = 20;
			for (int i = 1; i < n; i++)
			{
				a[m][0] = i;
				a[m][1] = i + 1;
				a[m][2] = 0;
				m++;
				a[m][0] = i;
				a[m][1] = i + 1;
				a[m][2] = 1 << (i - 1);
				m++;
			}
			for (int i = n - 1, j = 1 << (n - 1); i >= 1; i--)
			{
				while (j + (1 << (i - 1)) <= l)
				{
					a[m][0] = i;
					a[m][1] = n;
					a[m][2] = j;
					m++;
					j += 1 << (i - 1);
				}
			}
		}
		printf("%d %d\n", n, m);
		for (int i = 0; i < m; i++)
			printf("%d %d %d\n", a[i][0], a[i][1], a[i][2]);
	}
}

Measured memory_bytes: 3780
#include<iostream>
#include<algorithm>
using namespace std;
int n,a[2050];
long long ans=0;

int find(int i,int j){
	int lb=j,ub=n;
	while(ub-lb>1){
		int mid = (lb+ub)/2;
		if(a[i]+a[j]<=a[mid])ub=mid;
		else lb=mid;
	}
	return ub-j-1;
}

int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n);
	for(int i=0;i<=n-2;i++){
		for(int j=i+1;j<=n-1;j++){
			int c=find(i,j);
			ans+=c;
		}
	}cout<<ans<<endl; return 0;
}

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

template<long long mod>
class modint{
private:
  long long a;
public:
  constexpr modint(const long long x = 0) noexcept : a(x%mod) {}
  constexpr long long& value() noexcept { return a; }
  constexpr const long long& value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint& operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if(a >= mod) a -= mod;
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if(a < rhs.a) a += mod;
    a -= rhs.a;
    return *this;
  }
  constexpr modint& operator*=(const modint rhs) noexcept {
    a = a*rhs.a%mod;
    return *this;
  }
  constexpr modint& operator/=(modint rhs) noexcept {
    long long k = mod-2;
    while(k > 0){
      if(k&1){
        *this *= rhs;
      }
      rhs *= rhs;
      k /= 2;
    }
    return *this;
  }
  friend ostream& operator<<(ostream &os, const modint &X){
    return os << X.a;
  }
  friend istream& operator>>(istream &is, modint &X){
    is >> X.a;
    X.a %= mod;
    if(X.a < 0) X.a += mod;
    return is;
  }
};

template<typename T>
struct CumSum{
private:
  size_t size;
  vector<T> data;
public:
  CumSum(vector<T> dat){
    size = dat.size();
    data.resize(size+1,0);
    for(size_t i = 0; i < size; ++i)
      data[i+1] = data[i] + dat[i];
  }
  T getsum(size_t l, size_t r){//0-indexed, [l,r)
    return data[r] - data[l];
  }
  T getsum(size_t r){//0-indexed, [0,r)
    return data[r];
  }
};

int main(){
  using mint = modint<(int)1e9+7>;
  int N, K;
  cin >> N >> K;
  vector<int> V;
  V.push_back(0);
  for(int i = 1; i*i <= N; ++i){
    V.push_back(i);
    if(N/i != i)
      V.push_back(N/i);
  }
  sort(V.begin(), V.end());
  int M = V.size();
  map<int,int> R;
  for(int i = 1; i < M; ++i)
    R[V[i]] = i;
  vector<mint> dp(M,0);
  dp[1] = 1;
  for(int i = 0; i < K; ++i){
    CumSum<mint> cs(dp);
    vector<mint> dp_(2*M);
    for(int j = 1; j < M; ++j){
      dp_[j] = cs.getsum(R[N/V[j]]+1)*(V[j]-V[j-1]);
    }
    dp = dp_;
  }
  mint ans = 0;
  for(int i = 0; i < M; ++i){
    ans += dp[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 8160
#include <bits/stdc++.h>
using namespace std;
int main(){
  int64_t sum=0,count=0,N,i;
  cin>>N;
  int64_t A[N];
  for(i=0;i<N;i++){
    cin>>A[i];
  }
  for(i=0;i<N;i++){
    sum+=A[i];
    sum=sum%((int64_t)(1000000000+7));
  }
  for(i=0;i<N;i++){
    sum-=A[i];
    if(sum<0) sum+=1000000000+7;
    count+=((int64_t)(sum*A[i]))%((int64_t)(1000000000+7));
  }
  count=count%((int64_t)(1000000000+7));
  cout<<count<<endl;
}

Measured memory_bytes: 5208
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
    vector<int> size;
    UnionFind(int N): par(N),size(N) {

         //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++){
            par[i] = i;
            size[i] = -1;
        }
            
    }
    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

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

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
    int getsize(int x){
        return -size[root(x)];
    }
    int getNunion(){
        map<int,int> m;
        rep(i,par.size()){
            m[this->root(i)]++;
        }
        return int(m.size());
    }
};

int main(){
    ll N,M;
    cin >> N >> M;
    vector<ll> X(M), Y(M), Z(M);
    UnionFind tree(N);
    rep(i,M){
        cin >> X[i] >> Y[i] >> Z[i];
        //tree.unite(0,1);
        tree.unite(int(--X[i]), int(--Y[i]));
    }
    cout << tree.getNunion() << endl;
}

Measured memory_bytes: 8064
def main():
    N = int(input())
    A = list(map(int, input().split(" ")))
    B = list(map(int, input().split(" ")))
    C = list(map(int, input().split(" ")))
    result = 0
    meal_num = -5
    for a in A:
        if a == meal_num + 1:
            result += C[a - 2]
        result += B[a - 1]
        meal_num = a
    print(result)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <stdio.h>
int main(void){
  int i,j;
  char s[8][9];
  for(i=0;i<8;i++)
    scanf("%s",s[i]);
  puts("90");
  for(i=0;i<8;i++){
    for(j=0;j<8;j++){
      printf("%c",s[7-j][i]);
    }
    puts("");
  }
  puts("180");
  for(i=0;i<8;i++){
    for(j=0;j<8;j++){
      printf("%c",s[7-i][7-j]);
    }
    puts("");
  }
  puts("270");
  for(i=0;i<8;i++){
    for(j=0;j<8;j++){
      printf("%c",s[j][7-i]);
    }
    puts("");
  }
  return 0;
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
#define float long double 

int32_t main()
{
  IOS;
  int n,k;
  cin>>n>>k;

  int arr[n];
  for(int i=0; i<n; i++)
  {
    cin>>arr[i];
  }

  sort(arr, arr+n);

  int total = 0;
  for(int i=0; i<k; i++)
  {
    total+=arr[i];
  }

  cout<<total<<endl;
  
  return 0;
}

Measured memory_bytes: 3668
#include <algorithm>
#include <climits>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <vector>

#define int long long int
constexpr int INF = std::numeric_limits<int>::max();
constexpr int NINF = std::numeric_limits<int>::min();
using namespace std;

void solve() {
  string S; cin >> S;

  S = S.substr(0, S.size()-1);

  int ans = 0;
  for (int i = 1; i <= S.size()/2; i++) {
    string s = S.substr(0, i);
    s = s+s;
    if (equal(s.begin(), s.end(), S.begin())) {
      ans = s.size();
    }
  }

  cout << ans << endl;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;
int main(){
    int n;
    cin>>n;
    int d=n;
    vector<int> r;
    while(d){
        r.push_back(d%10);
        d/=10;
    }
    int sum=0;
    for(int i=0;i<r.size();i++){
        sum+=r[i];
    }
    if(0==n%sum){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
//#pragma GCC optimize("Ofast")
//#define _GLIBCXX_DEBUG
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
//#define int ll
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define floatprec(dig) fixed << setprecision(dig)
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define invar(typ, var) typ var; cin >> var;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX / 2;
const ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
const double EPS = 1e-9;

signed main(void) {
  cin.tie(0); ios::sync_with_stdio(false);
  
  int N, M;
  cin >> N >> M;
  vi v(N);
  rep(i, M) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    v[a]++;
    v[b]++;
  }
  
  rep(i, N){
    if(v[i] % 2 != 0) {
      fin("NO");
      return 0;
    }
  }
  fin("YES");
  
  
}

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

int main() {
  string a;
  cin>>a;
  bool ans=true;
  for(int i=0;i<a.size();i++){
    if(a.at(i)!=a.at(a.size()-1-i)){
      ans=false;
    }
  }
  for(int i=0;i<(a.size()-1)/2;i++){
    if(a.at(i)!=a.at((a.size()-1)/2-1-i)){
      ans=false;
    }
  }
  for(int i=(a.size()+3)/2-1;i<a.size();i++){
    if(a.at(i)!=a.at((3*a.size()+3)/2-2-i)){
      ans=false;
    }
  }
  if(ans){
    cout<<"Yes";
  }
  else{
    cout<<"No";
  }
}


Measured memory_bytes: 256
possible_appearances = ->(dice) {
  table = 
     [[0, 1, 2, 3, 4, 5], [3, 1, 0, 5, 4, 2], [1, 5, 2, 3, 0, 4], [5, 1, 3, 2, 4, 0],
      [1, 2, 0, 5, 3, 4], [3, 5, 1, 4, 0, 2], [5, 4, 2, 3, 1, 0], [2, 1, 5, 0, 4, 3],
      [1, 0, 3, 2, 5, 4], [5, 2, 1, 4, 3, 0], [2, 4, 0, 5, 1, 3], [4, 5, 3, 2, 0, 1],
      [3, 4, 5, 0, 1, 2], [4, 0, 2, 3, 5, 1], [1, 3, 5, 0, 2, 4], [2, 0, 1, 4, 5, 3],
      [0, 4, 3, 2, 1, 5], [4, 2, 5, 0, 3, 1], [4, 3, 0, 5, 2, 1], [2, 5, 4, 1, 0, 3],
      [3, 0, 4, 1, 5, 2], [0, 3, 1, 4, 2, 5], [0, 2, 4, 1, 3, 5], [5, 3, 4, 1, 2, 0]]
  result = []
  table.each do |dice1|
    another = Array.new(6, 0)
    dice1.each_with_index {|n, i| another[n] = dice[i]}
    result << another
  end
  result.uniq
}

solve = ->(dices) {
  s = dices.size
  (s - 1).times do |i|
    appearances = possible_appearances.(dices[i])
    (i + 1).upto(s - 1) do |j|
      return "No" if appearances.include?(dices[j])
    end
  end
  "Yes"
}

n = gets.to_i
dices = []
n.times {dices << gets.split.map(&:to_i)}
puts solve.(dices)



Measured memory_bytes: 7052
#include<stdio.h>

int l(int i){return 2*i;}


int main(){
  int v, p;
  int a[512+30];
  int i;
  int r;
  scanf("%d", &v);
  i=1;
  while(i<=v){
    scanf("%d", &a[i]);
  i++;
  }
  
  

  for(i=1;i<=v;i++){
    p = i / 2;
    r = 2 * i + 1;
    printf("node %d: key = %d, ", i,a[i]); 
   
    if(i != 1) printf("parent key = %d, ", a[p]); 
    if(l(i) <= v) printf("left key = %d, ", a[l(i)]); 
    if(r <= v) printf("right key = %d, ", a[r]); 
    puts("");
  }
  
  return 0;
}


Measured memory_bytes: 2056
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import Data.IntMap.Strict (IntMap)
import qualified Data.IntMap.Strict as IMS
import Data.List (mapAccumL)

main :: IO ()
main = do
  let
    init :: [Int] -> (Int, IntMap Int)
    init = foldl step (0, IMS.empty)
      where
        step :: (Int, IntMap Int) -> Int -> (Int, IntMap Int)
        step (s, m) x = (s + x, IMS.insertWith (+) x 1 m)
    update :: (Int, IntMap Int) -> [(Int, Int)] -> [Int]
    update sm0 = snd . mapAccumL step sm0
      where
        step :: (Int, IntMap Int) -> (Int, Int) -> ((Int, IntMap Int), Int)
        step (s, m) (b, c) = ((s', m'), s')
          where
            k = IMS.findWithDefault 0 b m :: Int
            s' = s + k * (c - b) :: Int
            m' = IMS.insertWith (+) c k . IMS.delete b $ m :: IntMap Int
  n <- unsafeTextToInt <$> T.getLine :: IO Int
  as <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  let
    sm0 = init as :: (Int, IntMap Int)
  q <- unsafeTextToInt <$> T.getLine :: IO Int
  bcs <- sequence . replicate q $ unsafeListToPair . map unsafeTextToInt . T.words <$> T.getLine :: IO [(Int, Int)]
  mapM_ print . update sm0 $ bcs

unsafeListToPair :: [a] -> (a, a)
unsafeListToPair [x, y] = (x, y)
{-# INLINE unsafeListToPair #-}

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
{-# INLINE unsafeTextToInt #-}


Measured memory_bytes: 70032
#include <iostream>
using namespace std;
 
int main() {
	int H,W;
 
	while(1){
		cin >> H >> W;
		if(H==0 && W==0)break;
		for(int i = 0; i < H; i++){
		for(int k = 0; k < W; k++){
			if((i+k)%2 == 0) cout << "#";
			else cout << ".";
		}	
		cout << "\n";
		}
		cout << "\n";
	}
	return 0;
}

Measured memory_bytes: 3052
import java.util.Scanner;

public class Main {
	void run() {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		int x = scan.nextInt();
		int y = scan.nextInt();
		if (a + b < c * 2) {
			System.out.println(a * x + b * y);
		} else {
			if (x < y) {
				System.out.println(Math.min((c * 2) * x + (y - x) * b, c * 2 * y));
			} else {
				System.out.println(Math.min((c * 2) * y + (x - y) * a, c * 2 * x));
			}
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}
}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin >> n >> k;
  int i,j;
  i=n/2;
  j=n%2;
  if(j==0){
    if(k<=i)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  else{
    if(k<=i+1)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
}
  

Measured memory_bytes: 256
#include <cstdlib>
#include <iostream>
#include <queue>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
typedef unsigned long long u64;
typedef signed long long l64;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  l64 x, a, b;
  cin >> x >> a >> b;
  if (a >= b) cout << "delicious" << endl;
  else if (a+x >= b) cout << "safe" << endl;
  else cout << "dangerous" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){

  char ch;
  
  while(1){
    scanf("%c", &ch);
    if(ch == '\n') break;
    if(65 <= ch && ch <= 96){
      ch += 32;
    }else if(97 <= ch && ch <= 154){
      ch -= 32;
    }
    printf("%c", ch);
  }
  printf("\n");
}



Measured memory_bytes: 2600
n = int(input())
a = [list(input()) for _ in range(n)]
ans = 0
for s in range(n):
  f = 1
  for i in range(n):
    if not f:
      break
    for j in range(n):
      if a[(i+s)%n][j] != a[(j+s)%n][i]:
        f = 0
        break
  if f:
    ans += n
print(ans)

Measured memory_bytes: 44764
import numpy as np
h, n = map(int, input().split())
ab = np.array([np.fromstring(input(), dtype=np.int64, sep=" ") for _ in range(n)])

a = ab[:, 0]
b = ab[:, 1]

dp = np.zeros(10**6, dtype=np.int)

for i in range(1,h+1):
    dp[i] = (dp[i-a]+b).min()

print(dp[h])

Measured memory_bytes: 12644
n,a,b = input().split()
n = int(n)
a = int(a)
b = int(b)

def digitSum(n):
    s = str(n)
    array = list(map(int, s))
    return sum(array)

ans = int(0)

for i in range(1, n+1):
    if digitSum(i) >= a and digitSum(i) <= b:
        ans += i
print(ans)

Measured memory_bytes: 3064
#include "vector"
#include "set"
#include "map"
#include "unordered_set"
#include "unordered_map"
#include "string"
#include "iostream"
#include "algorithm"
#include "queue"

using namespace std;

#define ll long long
#define INF 2e9
#define INF2 4611686018427387904
//#define MOD 1000000007
#define MOD 998244353
#define MAX_SIZE 1000000000

typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v) { bool first = true; for (const auto& j: v) { if (!first) { os << " "; } first = false; os <<j; } os << "\n"; return os; }
template<typename T>
istream& operator>>(istream& is, vector<T>& v) { for (auto& elem : v) { is >> elem; } return is; }

vector<ll> f;
void set_f(int n) { f.resize(n+1); f[0] = 1; for (int i=1; i<= n; i++) { f[i] = (f[i-1] * i) % MOD;} }
ll nod(ll a, ll b) { if (b == 0) { return a; } else { return nod(b, a % b); } }
ll pw(ll x, ll n, ll m=MOD) { if (n == 0) { return 1;} if (n%2 == 0) { return pw((x*x) % m, n/2, m); } return (pw(x, n-1, m) * x) % m; }
ll dv(ll a, ll b) { return (a * pw(b, MOD - 2)) % MOD; }
ll c_n_k(int n, int k) { if (k > n) { return 0; } if (k < 0) { return 0; } return dv(dv(f[n], f[k]), f[n-k]); }

void solve() {
    int n;
    cin >> n;
    vi a(n);
    cin >> a;

    unordered_map<int, int> m;
    ll ans = 0;
    for (int i=0; i<n; i++) {
        ans += m[i - a[i]];
        m[i + a[i]]++;
    }

    cout << ans;
}

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

    if (0) {
        int tests;
        cin >> tests;
        for (int t = 1; t <= tests; t++) {
            //cout << "Case #" << t << ": ";
            solve();
            //cout << "\n";
        }
    } else {
        solve();
        cout << endl;
    }

    return 0;
}

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

const int INF = 10000000;
const int MAX_V = 11;

int d[MAX_V][MAX_V];
int V;

void warshall_floyd() {
  for ( int k = 0; k < V; k++ ) {
    for (int i = 0; i < V; i++ ) {
      for ( int j = 0; j < V; j++ ) {
	d[i][j] = min(d[i][j], d[i][k] + d[k][j] );
      }
    }
  }
}


int main() {

  int m;
  while ( cin >> m,m ) {
  for ( int i = 0; i < 51; i++ ) {
    for ( int j = 0; j < 51; j++ ) {
      if ( i == j ) d[i][j] = 0;
      else d[i][j] = INF;
    }
  }

  int a,b,c;
  int maxn = 0;
  for ( int i = 0; i < m; i++ ) {
    cin >> a >> b >> c;
    maxn = max(maxn,max(a,b));
    d[a][b] = d[b][a] = c;
  }
  V = maxn + 1;
  warshall_floyd();


  int mincost = INF;
  int num;
  for ( int i = 0; i <= maxn; i++ ) {
    int total = 0;    
    for ( int j = 0; j <= maxn; j++ ) {
      if ( i != j ) {
	total += d[i][j];
      }
    }
    if ( mincost > total ) {
      mincost = total;
      num = i;
    }
  }
  cout << num << " " << mincost << endl;
  }

  return 0;
}

Measured memory_bytes: 1160
ac = 0
wa = 0
tle = 0
re = 0
for i in range(int(input())):
    n = input().upper()
    if n == 'AC':
        ac += 1
    elif n == 'WA':
        wa += 1
    elif n == 'TLE':
        tle += 1
    else:
        re += 1

print(f'AC x {ac}')
print(f'WA x {wa}')
print(f'TLE x {tle}')
print(f'RE x {re}')


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

namespace RacconVSMonster
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine();            
            long monsterHealth = long.Parse(input);

            List<long> monster = new List<long>();
            long monstersNumber = 1;
            long attacksMade = monsterHealth / 2;
            while (monsterHealth >= 1)
            {
                monsterHealth /= 2;
                monster.Add(monstersNumber);
                monstersNumber *= 2;                    
            } 
              
            Console.WriteLine(monster.Sum());
        }
    }
}

Measured memory_bytes: 13268
#include<iostream>
using namespace std;
 
void swap(int* a, int* b);
 
int main(){
  int a, b, c;
  cin >> a >> b >> c; // ????????????
  
  if(a > b) {
    swap(&a, &b);
  }
  if(a > c) {
    swap(&a, &c);
  }
  if(b > c) {
    swap(&b, &c);
  }
  
  cout << a << ' ' << b  << ' ' << c << endl; // ??¨???
  return 0;
}

void swap(int* a, int* b) {
  int temp;
  temp = *a;
  *a = *b;
  *b = temp;
}

Measured memory_bytes: 3076
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	map<int,int>m;
	map<int,int>::iterator it;
	while(n--){
		int a;
		cin>>a;
		it = m.find(a);
		if(it!=m.end()) it->second+=1;
		else m.insert(make_pair(a,1));
	}
	if(m.size()%2) cout<<m.size();
	else cout<<m.size()-1;
}

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

int main(){
    string n;
    cin >> n;
    reverse(n.begin(), n.end());
    if(n[0] == '1' || n[0] == '0' || n[0] == '6' || n[0] == '8'){
        cout << "pon" << endl;
    }
    else if(n[0] == '3'){
        cout << "bon" << endl;
    }
    else cout << "hon" << endl;
}

Measured memory_bytes: 3620
#include <iostream>

using namespace std;

typedef long long ll;

int main()
{
    ll a;

    cin>> a;

    ll b = a;

        ll c3 = a %10;
        a /= 10;

        ll c2 = a % 10;
        a/=10;

        ll c1 = a %10;

    if(c1 == 7 || c2 == 7 || c3 == 7) cout<< "Yes\n";

    else cout<< "No\n";

	return 0;
}



Measured memory_bytes: 3600