akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime> 
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

typedef long long ll;

const int MOD = 1e9 + 7;
const int N = 2e6 + 7;

int add(int a, int b) {
    ll res = (ll)a + b;
    return res % MOD;
}

int sub(int a, int b) {
    ll res = (ll)a - b;
    res %= MOD;
    res += MOD;
    return res % MOD;
}

int mul(int a, int b) {
    ll res = (ll)a * b;
    return res % MOD;
}

int binpow(int a, int b) {
    int res = 1;
    while (b > 0) {
        if (b & 1) {
            res = mul(res, a);
        }
        a = mul(a, a);
        b /= 2;
    }
    return res;
}

int divv(int a, int b) {
	return mul(a, binpow(b, MOD - 2));
}

int f[N];

void init() {
	f[0] = 1;
	for (int i = 1; i < N; i++) {
		f[i] = mul(i, f[i - 1]); 
	}
}

int C(int n, int k) {
	return divv(f[n], mul(f[k], f[n - k]));
}

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

	init();
	int k;
	string s;
	cin >> k >> s;
	int n = (int)s.size();
	int all = k + n;
	int ans = 0;
	for (int suf = 0; suf <= k; suf++) {
		int p = C(all - suf - 1, n - 1);
		p = mul(p, binpow(25, (all - suf - n)));
		p = mul(p, binpow(26, suf));
		ans = add(ans, p);
	}
	cout << ans << endl;
}

Measured memory_bytes: 12284
#include<iostream>
#include<map>
using namespace std;
typedef long long ll;

int main(){
    int n;
    cin >> n;
    map<int,ll> m;
    ll sum = 0;
    for(int i = 0; i < n; i++){
        int a;  cin >> a;
        m[a]++;
        sum += a;
    }
    int q;
    cin >> q;
    while(q--){
        int b, c;
        cin >> b >> c;
        ll to = 0;
        if(m.count(b))  to = m[b], sum -= to*b, m.erase(b);
        if(to)  m[c] += to, sum += to*c;
        cout << sum << endl;
    }
    return 0;
}

Measured memory_bytes: 7580
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long a,b,c,d;
    cin>>a>>b>>c>>d;
    long long x1=a*c,x2=b*d,x3=a*d,x4=b*c;
    long long ans1=max(x1,max(x2,max(x3,x4)));
    cout<<ans1<<endl;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main()
{	int n;
	int a[100001],b[100001];
	long long sum=0;
	cin>>n;
	for(int i=1;i<=n+1;i++){
		cin>>a[i];
	}
	for(int i=1;i<=n;i++){
		cin>>b[i];
	}
	for(int i=0;i<=n;i++){
		if(b[i]>a[i]){		
			if(b[i]-a[i]-a[i+1]>0)
				{
				sum=sum+a[i]+a[i+1];
				a[i+1]=0;}
				
			else{
			
				a[i+1]=a[i+1]+a[i]-b[i];
				sum=sum+b[i];}
			}
		else{sum=sum+b[i];
		}
			
	}
	printf("%lld",sum);
	
	return 0;
}

Measured memory_bytes: 1024
#include "atcoder/lazysegtree"
#include "atcoder/modint"
#include <cstdio>

using namespace std;
using namespace atcoder;

using mint = modint998244353;
struct S {
	mint val;
	mint uint;
	S(mint val = 0, mint uint = 0) :val(val), uint(uint) {}
};
using F = long long;
const F ID = 0;
//S =S * S;
S op(S a, S b) { return { a.val + b.val, a.uint + b.uint }; }
//Sの単位元
S e() { return S();}
//S e() { return { 0, 0 }; }
//S = f(x);
S mapping(F f, S x) {
	if (f != ID) x.val = f * x.uint;
	return x;
}
//F = f * g;
F composition(F f, F g) { return (f != ID ? f : g); }
//Fの単位元
F id() { return ID; }

int main() {
	int N, Q;
	cin >> N >> Q;
	vector<S> a(N);
	mint p = 1;
	for (int i = N - 1; i >= 0; i--) {
		a[i] = S( p, p );
		p *= 10;
	}
	atcoder::lazy_segtree<S, op, e, F, mapping, composition, id> seg(a);
	for (int i = 0; i < Q; ++i) {
		int l, r, d;
		cin >> l >> r >> d;
		l--;
		r--;
		seg.apply(l, r + 1, d);
		cout << seg.all_prod().val.val() << endl;
	}
}


Measured memory_bytes: 10896
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <functional>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;

class Edge
{
	public:
	int yen;
	int snuk;
	int from;
	int to;

	Edge(int n,int y,int s)
	{
		to=n;
		yen=y;
		snuk=s;
	}

};

vector<Edge> g[100000];
ll dy[100000];
ll ds[100000];

int main()
{
	int n,m,s,t;
	cin>>n>>m>>s>>t;
	s--;t--;
	for(int i=0;i<m;i++)
	{
		int u,v,a,b;
		cin>>u>>v>>a>>b;
		u--;v--;
		g[u].push_back(Edge(v,a,b));
		g[v].push_back(Edge(u,a,b));
	}
	fill(dy,dy+100000,1e15-1);
	fill(ds,ds+100000,1e15-1);
	//yen dijk
	priority_queue<P,vector<P>,greater<P>> q;
	dy[s]=0;
	q.push(P(0,s));
	while(!q.empty())
	{
		P p=q.top();q.pop();
		if(p.first>dy[p.second])
			continue;
		for(int i=0;i<g[p.second].size();i++)
		{
			Edge e=g[p.second][i];
			if(dy[e.to]>p.first+e.yen)
			{
				dy[e.to]=p.first+e.yen;
				q.push(P(dy[e.to],e.to));
			}
		}
	}
	ds[t]=0;
	q.push(P(0,t));
	while(!q.empty())
	{
		P p=q.top();q.pop();
		if(p.first>ds[p.second])
			continue;
		for(int i=0;i<g[p.second].size();i++)
		{
			Edge e=g[p.second][i];
			if(ds[e.to]>p.first+e.snuk)
			{
				ds[e.to]=p.first+e.snuk;
				q.push(P(ds[e.to],e.to));
			}
		}
	}
	//end dijk
	vector<ll> ans;
	ans.push_back(dy[n-1]+ds[n-1]);//last year
	ll mi=ans[0];
	for(int i=n-2;i>-1;i--)
	{
		mi=min(mi,dy[i]+ds[i]);
		ans.push_back(mi);
	}
	reverse(ans.begin(),ans.end());
	for(int i=0;i<ans.size();i++)
		cout<<(ll)(1e15-ans[i])<<endl;
	return 0;
}

Measured memory_bytes: 12276
# -*- coding: utf-8 -*-
# C

import sys
from collections import defaultdict, deque
from heapq import heappush, heappop
import math
import bisect
input = sys.stdin.readline

# 再起回数上限変更
# sys.setrecursionlimit(1000000)

n = int(input())
b = [1000000] + list(map(int, input().split())) + [1000000]

res = []

for i in range(n):
    res.append(min(b[i], b[i+1]))

print(sum(res))

Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define ld long double
const int M = 1e9+7;

vector<int> a;
vector<int> ind;
vector<int> dp;

int32_t main(){
	int n;
	cin>>n;
	if(n%2){
		cout << "0\n";
		return 0;
	}
	unsigned int ans = 0;
	n/=2;
	unsigned int cnt = 5;
	while(n && cnt<=n){
		ans += n/cnt;
		if(cnt*5LL > n)break;
		cnt *= (unsigned int)5LL;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
eval'H,W='+gets.split*?,
s=$<.read.tr".#
","10"
c=s.count ?1
W+=t=1
c,t=c-1,(t|t<<1|t>>1|t<<W|t>>W)&s.to_i(2)while~c<0&&t<1<<H*W-1
p c

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

int main(){
    string S;
    cin >> S;
    int c = 0;
    for(int i = 0; i < 4; i++){
        if(S[i] == '+'){
            c++;
        } else {
            c--;
        }
    }

    cout << c;
 
    return 0;
}

Measured memory_bytes: 256
from collections import deque;h,w=map(int,input().split());m=[input()for _ in[0]*h];v=[[-1]*w for _ in[0]*h];q=deque([[0,0]]);v[0][0]=0;c=sum(t.count('#')for t in m)
while q:
 y,x=q.popleft()
 for i,j in([1,0],[-1,0],[0,1],[0,-1]):
  t,u=y+i,x+j
  if t+1and t<h and u+1and u<w and m[t][u]=='.'and v[t][u]<0:v[t][u]=v[y][x]+1;q.append([t,u])
print(-(v[h-1][w-1]<0)or h*w-c-v[h-1][w-1]-1)

Measured memory_bytes: 40560
package main

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

type bySecond []([2]int)

func (s bySecond) Len() int {
	return len(s)
}
func (s bySecond) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}
func (s bySecond) Less(i, j int) bool {
	return s[i][1] < s[j][1]
}

func main() {
	var n int
	var iArr []([2]int)

	fmt.Scanf("%d", &n)

	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)

	iArr = make([]([2]int), n)
	for i := 0; i < n; i++ {
		// fmt.Scanf("%d %d", &iArr[i][0], &iArr[i][1])
		s.Scan()
		iArr[i][0], _ = strconv.Atoi(s.Text())
		s.Scan()
		iArr[i][1], _ = strconv.Atoi(s.Text())
	}

	sort.Sort(bySecond(iArr))

	total := 0
	isOk := true
	for i := 0; i < n; i++ {
		// fmt.Printf("%d,%d %d\n", iArr[i][0], iArr[i][1], total)
		total += iArr[i][0]
		if total > iArr[i][1] {
			isOk = false
			break
		}
	}

	if isOk {
		fmt.Print("Yes")
	} else {
		fmt.Print("No")
	}
}


Measured memory_bytes: 6272
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    H, W = in_nn()
    a = np.array(read().split(), np.int32).reshape((H, W))

    odd_count = np.count_nonzero(a % 2 == 1)
    if odd_count % 2 == 1:
        odd_count -= 1

    count = 0
    x, y = 0, 0
    px, py = -1, -1
    odd_f = False

    ans = []
    while True:

        if odd_f:
            ans.append((py + 1, px + 1, y + 1, x + 1))
            if a[y][x] % 2 == 1:
                odd_f = False
        else:
            if a[y][x] % 2 == 1:
                odd_f = True

        px, py = x, y
        if a[y][x] % 2 == 1:
            count += 1
            if count >= odd_count:
                break

        if y % 2 == 0:
            if x == W - 1:
                y += 1
            else:
                x += 1
        else:
            if x == 0:
                y += 1
            else:
                x -= 1

        if y >= H:
            break

    print(len(ans))
    for a in ans:
        print(*a)


if __name__ == '__main__':
    main()


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

vector<long long> input(long long N){
    long long i;
    vector<long long> output(N);
    for(i=0;i<N;i++)cin>>output[i];
    return output;
}

int main(){
    long long N,i,j,result;
    vector<long long> A;
    cin>>N;
    A=input(N);

    for(i=0;i<N;i++){
        j=0;
        while(A[i]%2==0){
            A[i]/=2;
            j++;
        }
        if(i==0)result=j;
        if(j<result)result=j;
    }

    cout<<result<<endl;
}

Measured memory_bytes: 256
k, n = map(int, input().split())
a = list(map(int, input().split()))
b = []
for i in range(n-1):
    x = a[i+1]-a[i]
    b.append(x)
b.append(a[0]+k-a[n-1])

c = max(b)
print(k-c)

Measured memory_bytes: 25840
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int n, ans = 0;
    cin >> n;
    int a[n];
    for(int i = 0;i < n; i++)
    {
        cin >> a[i];
    }
    sort(a, a + n);
    for(int i = 2; i < n; i++)
    {
        for(int j = 0, k = i - 1; j < k;)
        {
            if(j < k && a[j] + a[k] > a[i])
            {
                ans += k - j;
            }
            if(a[j] + a[k] <= a[i])
            {
                j++;
            }
            else
            {
                k--;
            }
            
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3608
#include<stdio.h>
int main(void)
{
	int a,b,sum,diff,pro;
	scanf("%d%d",&a,&b);
	
	sum=a+b;
	diff=a-b;
	pro=a*b;
	
	if(sum>=diff&&sum>=pro)
	printf("%d",sum);
	
	else if(diff>=sum&&diff>=pro)
	printf("%d",diff);
	
	else
	printf("%d",pro);
	

	return 0;
}

Measured memory_bytes: 1724
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <string>
#include <cstdio>
using namespace std;

#define int long long
#define INF 1e18

signed main() {
    int a, b, c, x; cin >> a >> b >> c >> x;
    int cnt = 0;

    for(int i = 0; i <= a; i++) {
        for(int j = 0; j <= b; j++) {
            for(int k = 0; k <= c; k++) {
                if(500 * i + 100 * j + 50 * k == x) cnt++;
            }
        }
    }

    cout << cnt << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
typedef long long ll;

int main() {
    int h, w;
    cin >> h >> w;

    char s[1010][1010];
    vector<pair<int, int> > b;
    for (int i = 0; i < h; i++) {
        cin >> s[i];
        for (int j = 0; j < w; j++) {
            if (s[i][j] == 'B') b.emplace_back(i, j);
        }
    }

    int far = 0, far_i, far_j;
    for (int i = 0; i < b.size(); i++) {
        if (abs(h / 2 - b[i].first) + abs(w / 2 - b[i].second) > far) {
            far = abs(h / 2 - b[i].first) + abs(w / 2 - b[i].second);
            far_i = b[i].first;
            far_j = b[i].second;
        }
    }

    //cout << far_i << " " << far_j << endl;

    int ans = 0;
    for (int i = 0; i < b.size(); i++) {
        ans = max(ans, abs(far_i - b[i].first) + abs(far_j - b[i].second));
    }

    cout << ans << endl;

}


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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,sum=0;
	string s;
	cin>>n;
	vector<ll>v(6);
	for(ll i=0;i<n;i++){
		cin>>s;
		if(s.substr(0,1)=="M")v.at(0)++;
		if(s.substr(0,1)=="A")v.at(1)++;
		if(s.substr(0,1)=="R")v.at(2)++;
		if(s.substr(0,1)=="C")v.at(3)++;
		if(s.substr(0,1)=="H")v.at(4)++;
	}
	for(int i=0;i<3;i++){
		for(int j=i+1;j<4;j++){
			for(int k=j+1;k<5;k++){
				sum+=v.at(i)*v.at(j)*v.at(k);
			}
		}
	}
	cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

int main()
{
	int n, m;
	int ans = 0;
	std::cin >> n >> m;
	std::vector<int> L;
	std::vector<int> R;
	for (int i = 0; i < m; i++)
	{
		int l, r;
		std::cin >> l >> r;
		L.push_back(l);
		R.push_back(r);
	}
	std::vector<int>::iterator itr = std::max_element(L.begin(), L.end());
	std::vector<int>::iterator itr2 = std::min_element(R.begin(), R.end());
	if (*itr2 >= *itr)
		ans = (*itr2 - *itr) + 1;
	
	std::cout << ans << '\n';
}


Measured memory_bytes: 1276
#include <iostream>
using namespace std;
int n;
int cnt[102];
int count;
int main(){
	cin>>n;
	for(int i=0;i<n;++i)cin>>cnt[i];
	for(int i=0;i<n-1;++i){
		int min_idx=i;
		for(int j=i+1;j<n;++j){
			if(cnt[j]<cnt[min_idx])
				min_idx=j;
		}
		if(min_idx==i)
			continue;
		swap(cnt[i],cnt[min_idx]);
		count++;
	}
	for(int i=0;i<n-1;++i)
		cout<<cnt[i]<<' ';
	cout<<cnt[n-1]<<'\n';
	cout<<count<<'\n';
}

Measured memory_bytes: 3084
package main

import (
	"fmt"
)

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

	arr := []string{}
	for i := 0; i < n; i++ {
		var str string
		fmt.Scan(&str)
		arr = append(arr, str)
	}
	
	arr2 := make([]string, len(arr))
	copy(arr2, arr)

	// bubble sort
	flag := 1
	for flag > 0 {
		flag = 0
		for j := n-1; j > 0; j-- {
			if arr[j-1][1] > arr[j][1] {
				arr[j-1], arr[j] = arr[j], arr[j-1]
				flag = 1
			}
		}
	}

	fmt.Print(arr[0])
	for i := 1; i < n; i++ {
		fmt.Print(" ")
		fmt.Print(arr[i])
	}
	fmt.Println()
	fmt.Println("Stable")

	// selection sort
	for i := 0; i < n; i++ {
		minj := i
		for j := i+1; j < n; j++ {
			if arr2[j][1] < arr2[minj][1] {
				minj = j
			}
		}
		arr2[i], arr2[minj] = arr2[minj], arr2[i]
	}

	stable := true
	fmt.Print(arr2[0])
	stable = stable && arr[0] == arr2[0]
	for i := 1; i < n; i++ {
		fmt.Print(" ")
		fmt.Print(arr2[i])
		stable = stable && arr[i] == arr2[i]
	}
	fmt.Println()
	if stable {
		fmt.Println("Stable")
	} else {
		fmt.Println("Not stable")
	}
}



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

int main() {
  string s;
  cin >> s;
  if(s.at(0) == s.at(1)){
    cout << "Bad" << endl;
  }
  else if(s.at(1) == s.at(2)){
    cout << "Bad" << endl;
  }
   else if(s.at(2) == s.at(3)){
    cout << "Bad" << endl;
  }
  else{
    cout << "Good" << endl;
  }
}


Measured memory_bytes: 256
use std::io::*;

fn main() {
    let i = stdin();
    solve(&mut i.lock(), &mut stdout());
}

fn solve(i: &mut BufRead, o: &mut Write) {
    let mut c = Vec::new();
    for _ in 0..3 {
        c.push(read_nums(i));
    }
    let r1 = c[2][2] - c[2][0] - c[1][2] + c[1][0] == 0;
    let r2 = c[2][2] - c[2][0] - c[1][2] + c[1][1] - c[0][1] + c[0][0] == 0;
    let r3 = -c[2][1] + c[2][0] + c[0][1] - c[0][0] == 0;
    let r4 = -c[2][2] + c[2][0] + c[0][2] - c[0][0] == 0;
    let r = r1 && r2 && r3 && r4;

    /*
    eliminate(
    [
    a0 + b0 = c00,
    a1 + b0 = c10,
    a2 + b0 = c20,

    a0 + b1 = c01,
    a1 + b1 = c11,
    a2 + b1 = c21,

    a0 + b2 = c02,
    a1 + b2 = c12,
    a2 + b2 = c22,
    ],
    [a0,a1,a2,b0,b1,b2])
    */

    writeln!(o, "{}", if r { "Yes" } else { "No" }).unwrap();
}

fn read_line(i: &mut BufRead) -> String {
    let mut line = String::new();
    i.read_line(&mut line).unwrap();
    line.trim().to_string()
}
fn read_nums(i: &mut BufRead) -> Vec<isize> {
    read_line(i)
        .split(' ')
        .map(|x| x.parse().unwrap())
        .collect()
}


Measured memory_bytes: 4476
var
   st:ansistring; bo:boolean;
   
begin
  readln(st);
  if pos('C',st)<>0 then
    bo:=true
  else
     begin
       writeln('No');
       halt;
     end;
  delete(st,1,pos('C',st));
  if pos('F',st)<>0 then 
    bo:=true
  else
    bo:=false;
  if bo then writeln('Yes')
  else
    writeln('No');
end.

Measured memory_bytes: 128
#include <iostream>
#include <fstream>

#include <cmath>
#include <string>

using namespace std;

typedef struct {
    int num;
    char suit;
} trump_t;


void bubbleSort(trump_t *t, int n);
void selectionSort(trump_t *t,int n);
void pp_sorting(trump_t *t,int n);
int main(){

    int n,flag=1;
    string s;
    trump_t t0[36], t1[36];
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> s;
        t0[i].suit = s[0];
        t0[i].num = s[1] - '0';
        t1[i] = t0[i];
    }
    bubbleSort(t0,n);
    pp_sorting(t0,n);
    cout << "Stable" << endl;
    selectionSort(t1,n);
    pp_sorting(t1,n);
    for(int i=0;i<n;i++){
        if((t0+i)->suit != (t1+i)->suit){ flag = 0; break;}
    }
    cout << ((flag)? "Stable" : "Not stable" )<< endl;

    return 0;
}

void bubbleSort(trump_t *t, int n){
    for(int i=0;i<n;i++){
        for(int j=0;j<n-1-i;j++){
            if((t+j)->num > (t+j+1)->num){
                trump_t temp = *(t+j);
                *(t+j) = *(t+j+1);
                *(t+j+1) = temp;
            }
        }
    }
}

void selectionSort(trump_t *t, int n){
    int ans = 1;
    for(int i=0;i<n;i++){
        int minj=i;
        for(int j=i;j<n;j++){
            if((t+j)->num < (t+minj)->num){
                minj = j;
            }
        }
        if(minj != i){
            trump_t temp = *(t+i);
            *(t+i) = *(t+minj);
            *(t+minj) = temp;
        }
    }
}

void pp_sorting(trump_t *t,int N){
    for(int i=0;i<N-1;i++){
        cout << (t+i)->suit << (t+i)->num << " ";
    }
    cout << (t+N-1)->suit << (t+N-1)->num << endl;
}




Measured memory_bytes: 3156
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define INF 1LL << 60;
#define LLINF 1e12
#define PI 3.14159265359
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
int ny, nx;
typedef long long ll;
using namespace std;

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

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

ll llmin(ll x, ll y) { return x < y ? x : y; }
ll llmax(ll x, ll y) { return x > y ? x : y; }

template <typename Container>
bool exist_in(const Container &c, const typename Container::value_type &v)
{
    return (c.end() != std::find(c.begin(), c.end(), v));
}

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

ll nCr(int n, int r)
{
    if (n == r or n == 0)
        return 1;
    if (n < r)
        return 0;
    if (r == 1)
        return n;
    return nCr(n - 1, r - 1) + nCr(n - 1, r);
}

//std::cout << std::defaultfloat << std::setprecision(10);
////////////////////////////////////////
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    ll A,B,N; cin >> A >> B >> N;
    ll cnt=0, res=0;

    FOR(j,1,llmin(B,N)+1){
        ll times = (B>N) ? llmin(B,N) : llmin(B,N)-1;
        if(times * j > N) break;
        ll hold = floor(A * times * j / B) - A * floor(times * j / B);
        if(hold > res) res = hold;
    }

    cout << res << endl;

    return 0;
}


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

int main(void){
  int i,n,rst[6];
  float x;

  memset(rst,0,sizeof(rst));

  scanf("%d",&n);
  while(n--){
    scanf("%f",&x);

    if(x<165.0){
      rst[0]++;
    }
    else if(x<170.0){
      rst[1]++;
    }
    else if(x<175.0){
      rst[2]++;
    }
    else if(x<180.0){
      rst[3]++;
    }
    else if(x<185.0){
      rst[4]++;
    }
    else{
      rst[5]++;
    }
  }

  for(i=0;i<6;i++){
    printf("%d:",i+1);
    while(rst[i]--){
      putchar('*');
    }
    putchar('\n');
  }

  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define TRACE(x) x
#define WATCH(x) TRACE( cout << #x" = " << x << endl)
#define PRINT(x) TRACE(printf(x))
#define WATCHR(a, b) TRACE( for(auto c = a; c != b;) cout << *(c++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end()); } )

#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define sz(v) (int) (v).size()

#define rep(i,a,b) for(int (i) = (a); (i) < (b); ++(i))
#define trav(a, x) for(auto& a : x)

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define shandom_ruffle random_shuffle
#define funoredered_map __fast_unordered_map
template<class Key, class Value, class Hash = std::hash<Key>>
using funordered_map = __gnu_pbds::gp_hash_table<Key, Value, Hash>;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

constexpr int INF = 0x3f3f3f3f;
constexpr int NINF = 0xc0c0c0c0;
constexpr double EPS = 1e-8;
constexpr ll MOD = 1000000007LL;

template <typename T>
using ordered_set = 
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

inline ll modPow( ll a, ll b, ll mod = MOD) {
    ll res = 1; a %= mod; assert(b >= 0);
    for(;b;b>>=1) {
        if(b&1) res = (res * a) % mod;
        a = (a * a) % mod;
    }
    return res;
}

inline int cmp_double( double x, double y, double tol = EPS) {
    return (x <= y + tol) ? ( x + tol < y) ? -1 : 0 : 1;
}

constexpr int maxV = 1e5 + 13;

long long DP[maxV][2];
int main()
{
	ios::sync_with_stdio(0); cin.tie(NULL);
    int n; long long k;
    for(int j = 0; j < 2; ++j) for(int i = 0; i < maxV; ++i) DP[i][j] = INF;

    DP[0][0] = 0LL;
    
    cin >> n >> k;
    vector<long long> W(n + 1);
    vector<long long> V(n + 1);
    for(int i = 1; i <= n; ++i) { cin >> W[i] >> V[i]; }
    
    for(int i = 1; i <= n; ++i) {
        for(int v = 0; v < maxV; ++v) {
            DP[v][i % 2] = DP[v][ (i % 2) ^ 1];
            if( v < V[i] ) continue; 
            DP[v][ i % 2 ] = min( DP[v - V[i] ][ (i % 2) ^ 1] + W[i], DP[v][i % 2]);
        }
    }
    
    for(int v = maxV - 1; v >= 0; --v) {
        if( DP[v][ n % 2] <= k) {
            cout << v << endl;
            return 0;
        }
    }
}



Measured memory_bytes: 1920
#include<stdio.h>

int main(){
    float max, min, m[10000];
    int i, count = 0;

    while(scanf("%f", &m[count]) != EOF){
        count++;
    }
    max = min = m[0];
    for(i = 1; i < count; i++){
        if(max < m[i]) max = m[i];
        else if(min > m[i]) min = m[i];
    }
    printf("%g\n", max-min);
    return 0;
}

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

#define all(x) x.begin(),x.end()
#define pb(x) emplace_back(x)
#define forn(i,N) for(int i=0;i<N;i++)

using namespace std;
using ll=long long int;
using ld=long double;
using vi=vector<int>;
using vll=vector<ll>;
using vd=vector<double>;

int main() {
//freopen("input.txt","rt",stdin);
ios::sync_with_stdio(false);
cin.tie(nullptr);

string s;
cin>>s;
cout<<count(all(s),'1')<<endl;
return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
struct UnionFind {
    vector<int> A;
    UnionFind(int n) : A(n, -1) {}
    int find(int x) {
        if (A[x] < 0) return x;
        return A[x] = find(A[x]);
    }
    void unite(int x, int y) {
        x = find(x), y = find(y);
        if (x == y) return;
        if (A[x] > A[y]) swap(x, y);
        A[x] += A[y];
        A[y] = x;
    }
};
int main() {
    int N, H, W; cin >> N >> H >> W;
    vector<tuple<int, int, int>> A;
    A.reserve(N);
    for (int i = 0; i < N; i++) {
        int r, c, a; cin >> r >> c >> a; r--, c--;
        A.emplace_back(a, r, c);
    }
    sort(rbegin(A), rend(A));
    UnionFind uf(H + W);
    vector<int> score(H + W, 1);
    Int ans = 0;
    for (int i = 0; i < N; i++) {
        int a, r, c; tie(a, r, c) = A[i];
        int rid = uf.find(r);
        int cid = uf.find(H + c);
        if (rid == cid) {
            if (score[rid] > 0) {
                score[rid]--;
                ans += a;
            }
        } else {
            if (score[rid] + score[cid] > 0) {
                uf.unite(rid, cid);
                score[uf.find(rid)] = score[rid] + score[cid] - 1;
                ans += a;
            }
        }
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 2944
//Be Name Khoda, Besmellah Rahmane Rahim, In The Name Of God;
//#include<bits/stweight++.h>
#include<iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include<bitset>
#include<list>
#include<cassert>
#include<numeric>
#include <stdio.h>
#include <string.h>
#include<iomanip>
#include<unordered_map>
#include<unordered_set>
#include <iostream>
#include <fstream>

using namespace std;

const int N = 5e5 + 5;;
int p[N];
int q[N];
int c[N];
int n, k;

void merge_sort(int l, int r) 
{
    if (r - l == 1)
    {
        return;
    }
    int mid = (l + r) / 2;
    merge_sort(l, mid);
    merge_sort(mid, r);
    for (int i = mid - 1, mn = N; i >= l; i--) 
    {
        mn = min(mn, q[i]);
        c[i] = mn;
    }
    int pl = l;
    int pr = mid;
    int p = l;
    vector <int> vec;
    while (vec.size() != r - l) 
    {
        if (pl == mid)
        {
            vec.push_back(q[pr++]);
        }
        else 
        {
            if (pr == r)
            {
                vec.push_back(q[pl++]);
            }
            else 
            {
                if (q[pr] + k <= c[pl])
                {
                    vec.push_back(q[pr++]);
                }
                else
                {
                    vec.push_back(q[pl++]);
                }
            }
        }
    }
    for (int i = l; i < r; i++)
    {
        q[i] = vec[i - l];
    }
}

int main() 
{
    cin >> n >> k;
    for (int i = 0; i < n; i++)
    {
        cin >> p[i];
    }
    for (int i = 0; i < n; i++)
    {
        q[p[i] - 1] = i;
    }
    merge_sort(0, n);
    for (int i = 0; i < n; i++)
    {
        p[q[i]] = i + 1;
    }
    for (int i = 0; i < n; i++)
    {
        cout << p[i] << endl;
    }
}




Measured memory_bytes: 9584
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rint register int
#define rep(i, l, r) for (rint i = l; i <= r; i++)
#define per(i, l, r) for (rint i = l; i >= r; i--)
#define mset(s, _) memset(s, _, sizeof(s))
#define pb push_back
#define pii pair <int, int>
#define mp(a, b) make_pair(a, b)

inline int read() {
  int x = 0, neg = 1; char op = getchar();
  while (!isdigit(op)) { if (op == '-') neg = -1; op = getchar(); }
  while (isdigit(op)) { x = 10 * x + op - '0'; op = getchar(); }
  return neg * x;
}
inline void print(int x) {
  if (x < 0) { putchar('-'); x = -x; }
  if (x >= 10) print(x / 10);
  putchar(x % 10 + '0');
}

const int maxn=2*1e5+5;
char s[maxn];
char a[maxn],b[maxn];
int n;

int main(){
    //freopen("in.txt","r",stdin);
    int t=0,m,op;
    char srr;
    int js1=0,js2=0;
    scanf("%s%d",s,&n);
    while(n--){
        scanf("%d",&m);
        if(m==1) t^=1;
        else{
            scanf("%d %c",&op,&srr);
            op--;
            if(op^t){   //没有翻转添加在后面
                a[++js1]=srr;
            }else{    //没有翻转添加在前面
                b[++js2]=srr;
            }
        }
    }
    if(t==0){
        for(int i=js2;i>=1;i--){
            printf("%c",b[i]);
        }
        printf("%s",s);
        for(int i=1;i<=js1;i++){
            printf("%c",a[i]);
        }
    }
    else{
        for(int i=js1;i>=1;i--){
            printf("%c",a[i]);
        }
        int len=strlen(s);
        for(int i=len-1;i>=0;i--){
            printf("%c",s[i]);
        }
        for(int i=1;i<=js2;i++){
            printf("%c",b[i]);
        }
    }
    return 0;
}



Measured memory_bytes: 896
#include<bits/stdc++.h>
#define rep(i,f,n) for(ll i=(f); (i) < (n); i++)
#define repe(i,f,n) for(ll i=(f); (i) <= (n); i++)
using namespace std;
using ll = long long;
#define MOD (ll)1000000007
#define PI 3.14159265359
//#define P pair<ll, ll>
//printf("%.10f\n")
//cout << fixed << setprecision(10);
template<class T> inline bool chmax(T& a, T b){if (a < b) { a = b; return true; } return false;}
template<class T> inline bool chmin(T& a, T b){if (a > b) { a = b; return true; } return false;}
ll INF = 1e+18;
int iINF = 1e9;

int
main()
{
  int N; cin >> N;
  vector<ll> arr(N);
  rep(i, 0, N) cin >> arr[i];

  map<ll, ll> m;
  vector<ll> acum(N + 1);
  acum[0] = 0;
  m[0] += 1;
  rep(i, 0, N){
    acum[i + 1] = acum[i] + arr[i];
    m[acum[i + 1]] += 1;
  }

  ll ans = 0;
  for(auto x: m){
    ans += (x.second * (x.second - 1)) / 2;
  }

  cout << ans << endl;

}


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

int main() {
  int A, B, K;
  cin >> A >> B >> K;
  int i;
  int j = 0;
  for (i = max(A, B); i > 0; i--) {
    if (A % i == 0 && B % i == 0) {
      j++;
      if (j == K) {
        break;
      }
    }
  }
  cout << i << endl;
}

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

using ll = long long int;
using P = pair<int, int>;
using P3 = pair<int, P>;
using PP = pair<P, P>;
constexpr int INF = 1 << 30;
constexpr ll MOD = ll(1e9) + 7;
constexpr int di[] = {0, 1, 0, -1};
constexpr int dj[] = {1, 0, -1, 0};

struct RMQ{
    int N;
    vector<P> node;
    void init(int n){
        N = 1;
        while(N<n) N<<=1;
        node.assign(N*2-1,{0,0});
    }
    void update(int k, P x){
        k += N-1;
        node[k] = x;
        while(k > 0){
            k = (k-1)/2;
            node[k] = max(node[k*2+1],node[k*2+2]);
        }
    }
    P query(int a, int b){return query(a, b, 0, 0, N);}
    P query(int a, int b, int k, int l, int r){
        if(r <= a || b <= l) return {-INF,-INF};
        if(a <= l && r <= b) return node[k];
        return max(query(a,b,k*2+1,l,(l+r)/2),query(a,b,k*2+2,(l+r)/2,r));
    }
};

RMQ rmq;

bool solve(){
    int N, R, L;
    cin >> N >> R >> L;
    rmq.init(N);
    for(int i=0;i<N;i++){
        rmq.update(i,P(0,-i));
    }
    int tp = 0;
    vector<int> cnt(N);
    for(int i=0;i<R;i++){
        int d, t, x;
        cin >> d >> t >> x;
        d--;
        int id = abs(rmq.query(0,N).second);
        cnt[id] += t-tp;
        tp = t;
        P tmp = rmq.query(d,d+1);
        tmp.first += x;
        rmq.update(d,tmp);
    }
    cnt[abs(rmq.query(0,N).second)] += L-tp;
    int ans = 0, maxi = 0;
    for(int i=0;i<N;i++){
        if(cnt[i] > maxi){
            maxi = cnt[i];
            ans = i+1;
        }
    }
    cout << ans << endl;
    return false;
}

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



Measured memory_bytes: 5224
H,W=map(int,input().split())
H-=1
W-=1
p=[]
for i in range(H+1):
  p+=[list(map(int,input().split()))]
s=[]
se=[]
h=0
w=0
f=False
x=[]
while h != H+1:
  if p[h][w] % 2 == 1:
    if f == True:
      x += s
      s=[]
      f =  False
    else:
      f = True
      se = [h,w]
      
  if w != W:
    if f==True:
      s+=[[h+1,w+1,h+1,w+2]]
    w+=1
  else:
    if f==True and h != H:
      f=False
      p[se[0]+1][se[1]]+=1
      x+=[[se[0]+1,se[1]+1,se[0]+2,se[1]+1]]

    w=0
    h+=1
    s=[]

print(len(x))
for i in x:
  print(*i)

Measured memory_bytes: 31304
#include <stdio.h>

int main(void) {

	char s[6];
  
  	//reads in string from stdin
  	for (int i = 0; i < 6; i++) {
    	scanf("%c", &s[i]);
    }

  	//check if its coffee-like
  	if (s[2] == s[3] && s[4] == s[5]) {
    	printf("Yes\n");
    } else {
    	printf("No\n");
    }
  
	return 0;
}

Measured memory_bytes: 128
import sys
input = sys.stdin.readline

from heapq import heappop, heappush

N, Q = map(int, input().split())
event_list = []
for i in range(N):
  s, t, x = map(int, input().split())
  event_list.append([s-x, 1, x])
  event_list.append([t-x, -1, x])

for i in range(Q):
  event_list.append([int(input()), 2, 0])

ans = []
event_list.sort()
x_set = set()
x_list = []
for time, event, x in event_list:
  if event == 1:
    x_set.add(x)
    heappush(x_list, x)
  elif event == -1:
    x_set.remove(x)
  else:
    while x_list and x_list[0] not in x_set:
      heappop(x_list)
    if x_list:
      ans.append(x_list[0])
    else:
      ans.append(-1)

print(*ans, sep='\n')


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

int main()
{
	vector<int> v;
	for(int i=0;i<5;i++)
	{
		int x;
		cin>>x;
		v.push_back(x);
	}
	for(int i=0;i<v.size();i++)
	{
		if(v[i]==0)
		{
			cout<<i+1<<endl;
		}
	}
	return 0;
}



Measured memory_bytes: 3564
# @oj: atcoder
# @id: hitwanyang
# @email: 296866643@qq.com
# @date: 2020-04-30 11:24
# @url:https://atcoder.jp/contests/dp/tasks/dp_d
import sys,os
from io import BytesIO, IOBase
import collections,itertools,bisect,heapq,math,string
# region fastio

BUFSIZE = 8192

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# ------------------------------
def main():
    nv=list(map(int,input().split()))
    n,v=nv[0],nv[1]
    wc=[list(map(int,input().split())) for i in range(n)]
    w=[x[0] for x in wc]
    c=[x[1] for x in wc]
    dp=[[0]*(v+1) for i in range(n+1)]
    for i in range(1,n+1):
        for j in range(v+1):
            if j>=w[i-1]:
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i-1]]+c[i-1])
            else:
                dp[i][j]=dp[i-1][j]
        # print (dp)
    print (dp[n][v])
if __name__ == "__main__":
    main()

Measured memory_bytes: 118512
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>
#include<set>
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
const int INF = 1e9;

int main() {
	int n, k;
	cin >> n >> k;
	vector<int>h(n);
	//cout << 1;
	rep(i, n) {
		cin >> h[i];
	}
	ll dp[100001];
	rep(i, n) {
		dp[i] = INF;
	}
	dp[0] = 0;
	rep(i,n) {
		rep(j, k+1) {
			if (i - j >= 0) {
				chmin(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
			}
		}
		//cout << dp[i] << endl;

	}
	cout << dp[n - 1];
	return 0;
}

Measured memory_bytes: 4316
n,m = map(int,input().split())
acli = [0]*n
wali = [0]*n
acsi = 0
wasi = 0
for i in range(m):
    p,s = map(str,input().split())
    if acli[int(p)-1] == 0:
        if s == 'AC':
            acli[int(p)-1] = 1
            acsi += 1
        elif s == 'WA':
            wali[int(p)-1] += 1
for j in range(n):
    if acli[j] == 1 and wali[j] != 0:
        wasi += wali[j]
print(acsi,wasi)

Measured memory_bytes: 75888
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <string>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <climits>
using namespace std;

typedef long long ll;

const int N = (int)2e5+77;

int n,m,h,w;
int a[11111];
int c[111][111];
int vis[111][111];
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};

void dfs(int x, int y, int col) {
    if (x < 0 or x >= h or y < 0 or y >= w) return;
    vis[x][y] = 1;
    if (!a[col]) col++;
    c[x][y] = col;
    a[col]--;
    for (int i = 0; i < 4; i++) {
        int xx = x + dx[i];
        int yy = y + dy[i];
        if (vis[xx][yy]) continue;
        dfs(xx, yy, col);
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> h >> w;
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    dfs(0, 0, 1);
    for (int i = 0; i < h; i++, cout << endl) for (int j = 0; j < w; j++) cout << c[i][j] << " ";
    return 0;
}

Measured memory_bytes: 896
#include <iostream>
#define INF 1000000
using namespace std;

int main(){
	int n,m,C[21];
	cin >> n >> m;
	int T[n+1];
	T[0] = 0;
	for(int i = 1;i <= n;i++){
		T[i] = INF;
	}
	for(int i = 0;i < m;i++){
		cin >> C[i];
		for(int j = C[i];j <= n;j++){
			T[j] = min(T[j],T[j-C[i]]+1);
		}
	}
	cout << T[n] <<endl;

	return 0;
}

Measured memory_bytes: 1356
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()


char maze[30][30];
int H,W;
int d[30][30];
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int bfs(int sx,int sy,int gx,int gy){
    queue<pair<int,int>> que;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            d[i][j]=INF;
        }
    }
    que.push(make_pair(sx,sy));
    d[sx][sy]=0;
    while(!que.empty()){
        pair<int,int> p=que.front();
        que.pop();
        if(p.first==gx && p.second==gy) break;
        for(int i=0;i<4;i++){
            int nx=p.first+dx[i];
            int ny=p.second+dy[i];
            if(0<=nx && nx<H && 0<=ny && ny<W && maze[nx][ny]!='#' && d[nx][ny]==INF){
                que.push(make_pair(nx,ny));
                d[nx][ny]=d[p.first][p.second]+1;
            }
        }
    }
    return d[gx][gy];
}

int main(){
    cin>>H>>W;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin>>maze[i][j];
        }
    }
    int ans=0;

	rep(i,H){
		rep(j,W){
			rep(k,H){
				rep(l,W){
					if(maze[i][j]=='#') continue;
					if(maze[k][l]=='#') continue;
					ans=max(ans,bfs(i,j,k,l));
				}
			}
		}
	}
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    static int modP = 1000000007;
    static long inf  = 1 << 61;

    static int n, target;

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

        for(int i = 0; i <= n; i++) {
            for(int j = 0; j <= n; j++) {
                int k = n - i - j;
                if(k < 0) continue;

                if(i*10000 + j*5000 + k*1000 == target) {
                    System.out.format("%d %d %d\n", i, j, k);
                    return;
                }
            }
        }

        print("-1 -1 -1");
    }

    static void print(String s) {
        System.out.println(s);
    }

    static void print(int i) {
        System.out.println(i);
    }

    static void print(long i) {
        System.out.println(i);
    }

    static void print(float i) {
        System.out.println(i);
    }
}

Measured memory_bytes: 23764
def main():
    n, m, l = tuple(map(int, input().split()))
    matA = [[0 for j in range(m)] for i in range(n)]
    matB = [[0 for k in range(l)] for j in range(m)]
    matC = [[0 for k in range(l)] for i in range(n)]

    for i in range(n):
        tmp = list(map(int, input().split()))
        for j in range(m):
            matA[i][j] = tmp[j]

    for j in range(m):
        tmp = list(map(int, input().split()))
        for k in range(l):
            matB[j][k] = tmp[k]


    for i in range(n):
        for k in range(l):
            for j in range(m):
                matC[i][k] += matA[i][j] * matB[j][k]

    for i in range(n):
        for k in range(l):
            if k == l-1:
                print(matC[i][k])
            else:
                print(matC[i][k], end=' ')

if __name__ == '__main__':
    main()


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

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

  vector<bool> red(N, 0);
  red.at(0) = 1;
  vector<int> ball(N, 1);

  for (int i = 0; i < M; i++) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    ball.at(x)--;
    ball.at(y)++;
    if (red.at(x)) red.at(y) = 1;
    if (ball.at(x) == 0) red.at(x) = 0;
  }

  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (red.at(i) && ball.at(i) > 0) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <algorithm>
#include<string>
using namespace std;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int A[3];
    cin >> A[0] >> A[1] >> A[2];
    sort(A, A + 3);
    if (A[0] == A[1]) cout << A[2] << endl;
    if (A[1] == A[2]) cout << A[0] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
  bool YesFlag = false;
  int N, M, input;
  int sum = 0, ans = 0;
  vector<int> A;
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
      cin >> input;
      sum += input;
      A.push_back(input);
  }
  for(int i=0;i<N;i++){
    if (A[i] >= (float)sum / (float)(4 * M)){
      ans++;
    }
    if(ans >= M){
      YesFlag = true;
      break;
    }
  }
  if(YesFlag){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
/*
                                               
 ____                 ______           _____   
|    |            ___|\     \      ___|\    \  
|    |           |    |\     \    |    |\    \ 
|    |           |    |/____/|    |    | |    |
|    |        ___|    \|   | |    |    |/____/|
|    |       |    \    \___|/     |    ||    ||
|    |       |    |\     \        |    ||____|/
|____|  ___  |\ ___\|_____|  ___  |____|       
|    | |   | | |    |     | |   | |    |       
|____| |___|  \|____|_____| |___| |____|       
  \(             \(    )/           \(         
   '              '    '             '      
   				template v.1.4   
                                           
*/
#include <bits/stdc++.h>

#define fi first
#define se second
#define pb push_back
#define sz(s) (int)s.size()
#define OPTIMIZE ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(x) cerr << "#" << x << ": " << x << '\n';
#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define FORD(i, a, b) for (int i = b; i >= a; i--)
#define FORL(i, a, b) for (LL i = a; i <= b; i++)
#define FORDL(i, a, b) for (LL i = b; i >= a; i--)

using namespace std;

typedef long long LL;
typedef pair<int,int> ii;
typedef pair<LL,LL> pll;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef vector<ii> vii;
typedef vector<pll> vll;

const LL MODPRIME = 1e9 + 7;
const double EPS  = 1e-12;
const LL MAXL = 4e18;
const LL MINL = -4e18;
const int MAXI = 2e9;
const int MINI = -2e9;

int H, W;
char arr[405][405];
vector<ii> rest;
bool visit[405][405];
int dx[]={-1, 0, 0, 1};
int dy[]={0,-1,1,0};
LL ans, pagar, titik;

bool cek(int x, int y){
	return (x >= 0 && x < H && y >= 0 && y < W);
}

void DFS(int x, int y, int gil){
	if (gil == 0) pagar++;
	else titik++;
	arr[x][y] = '*';
	for (int i = 0; i < 4; i++){
		int nx = x + dx[i];
		int ny = y + dy[i];
		if (cek(nx, ny) && arr[nx][ny] != '*'){
			if (gil == 0 && arr[nx][ny] == '.'){
				DFS(nx, ny, 1-gil);
			}else if (gil == 1 && arr[nx][ny] == '#'){
				DFS(nx, ny, 1-gil);
			}
		}
	}
}

int main(){
	// #ifndef ONLINE_JUDGE
	// 	freopen("in.txt", "r", stdin);
	// #endif
	//OPTIMIZE
	cin >> H >> W;
	for (int i = 0; i < H; i++){
		for (int j = 0; j < W; j++){
			cin >> arr[i][j];
		}
	}
	for (int i = 0; i < H; i++){
		for (int j = 0; j < W; j++){
			if (arr[i][j] == '#'){
				pagar = 0;
				titik = 0;
				DFS(i, j, 0);
				ans += pagar * titik;
			} 
		}
	}
	cout << ans << '\n';
	return 0;
}

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

int compare(int n,int a){
  if(n<a){
    return n;
  }else{
    return a;
  }
}
int main(){
  int n,k,acount;
  cin >> n >> k;
  if(k<0){
    acount = 0;
  }else if(k<3){
    acount = 1;
  }else if(k<5){
    acount = 2;
  }else if(k<9){
    acount = 3;
  }else{
    acount = 4;
  }
  acount = compare(n,acount);
  int res=1;
  for(int i=0;i<acount;i++){
    res *= 2;
  }
  for(int i=0;i<n-acount;i++){
    res += k;
  }
  cout << res << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll  a,b,aa,bb;
	cin>>a>>b;
	aa=max(a,b);
	bb=min(a,b);
	rep(i,aa){
		cout<<bb;
	}
	cout<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

#define N 100000

/** Application main entry point. */
int main (
  int     argc,
  char  * argv[ ]
  )
{
  int i;

  for ( ; ; )
  {
    int a[ N ];
    int n, k;
    int res, v;

    scanf ( "%d%d", &n, &k );
    if ( !( n | k ) ) break ;
    for ( i = 0; i < n; ++i )
    {
      scanf ( "%d", a + i );
    }

    v = 0;
    for ( i = 0; i < k; ++i )
    {
      v += a[ i ];
    }
    res = v;
    for ( i = k; i < n; ++i )
    {
      v += a[ i ] - a[ i - k ];
      if ( v > res )  res = v;
    }

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

  return ( 0 );
}

Measured memory_bytes: 0