akhauriyash/Code-Regression huggingface dataset:
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int n,k,R,S,P,ans=0; cin>>n>>k>>R>>S>>P;
    string t; cin>>t;
    rep(i,k){
        char pre='.';
        for(int j=i;j<n;j+=k){
            if(pre!=t[j]){
                if(t[j]=='r') ans+=P;
                else if(t[j]=='s') ans+=R;
                else ans+=S;
                pre=t[j];
            }
            else pre='.';
        }
    }
    cout<<ans<<endl;
}


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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;
template <typename T>
using V = std::vector<T>;

using namespace std;

int main() {
  V<int> a(3);
  rep(i, 3) cin >> a[i];
  sort(all(a));
  out(a[2] - a[0]);
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
const int mod = 1e9 + 7;

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

    //パターンの数は Σ N+1_C_i, i= 0 ~ N-K+1 だが重複を考慮
    //i個を選んだ時の和は SUMmax - SUMmin + 1 通り (i = 0 ~ N-K+1)
    ll sm = 0;
    ll Smx = 0, Smn = 1; //初回補正のため1から
    for(ll i = 0; i <= N-K+1; ++i){
        Smn += i-1;
        Smx = N*i - Smn;
        sm =(sm + Smx - Smn + 1) % mod;
    //cout << i << ":" << Smx << "," << Smn << ":" << Smx - Smn + 1 << endl;
    }
    cout << sm << endl;
}

Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<utility>
#include<queue>
#define rep(i, n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	int n, k;
	cin>>n>>k;
	int h;
	vector<int> v;
	rep(i, n){
		cin>>h;
		v.push_back(h);
	}
	if(k>=n){
		cout<<0<<endl;
		return 0;
	}
	sort(v.begin(), v.end(), greater<int>());
	int long long c=0;
	for(int i=k;i<n;i++){
		c+=v[i];
	}
	cout<<c<<endl;
	return 0;
}

Measured memory_bytes: 1400
c = list(map(int,input().split()))
N,M = c[0],c[1]
X = list(map(int,input().split()))
if N>=M:
  print(0,end="")
else:
  X.sort()
  differences = [X[i+1]-X[i] for i in range(len(X)-1)]
  differences.sort()
  for i in range(N-1):
    differences.pop()
  print(sum(differences),end="")

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


def divisor(x):
    div = []
    div_append = div.append
    for i in range(1, int(x**.5)+1):
        if x % i == 0:
            div_append(i)
            div_append(x//i)
    div.sort()
    return div


div = divisor(m)
for d in div[::-1]:
    if m // n >= d:
        ans = d
        break
print(ans)


Measured memory_bytes: 3188
#include <iostream>
#include <stdio.h>
#include <vector>
#include <utility>
#include <string>
#include <algorithm>
#include <cmath>
 
typedef long long ll;

#define rep(i,n) for(ll i = 0; i < n; i++)
 
using namespace std;
 
const ll INF = ll(1e18)+1;
const double PI=3.14159265358979323846;
 
int main(){
  ll x, ans=0;
  cin >> x;
  while(100){
    if(x>=500){
      x-=500;
      ans+=1000;
      continue;
    }
    else if(x>=5){
      x-=5;
      ans+=5;
      continue;
    }
    else{
      break;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;long long int K,i;cin>>S>>K;
  for(i=0;i<K;i++)if(S.at(i)!='1')break;
  if(i==K)cout<<"1"<<endl;
  else cout<<S.at(i)<<endl;
}

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

int main(){
  int n;
  cin >> n;

  vector<int> A(n);
  for(int i=0; i<n;  ++i) cin >> A[i];

  vector<int> rev(n);
  for(int i=0; i<n; ++i) rev[A[i]-1] = i+1;
  for(int i=0; i<n; ++i) cout << rev[i] << endl;
  return 0;
}

Measured memory_bytes: 1664
getNums :: String -> [Int]
getNums xs = (read $ fst h :: Int) : case snd h of
                      [] -> []
                      (_:xs') -> getNums xs'
  where h = break (== ' ') xs

judgeNum :: [Int] -> String
judgeNum [a,b,c] = case b - a == c - b of
                    True -> "YES"
                    False -> "NO"


main = do
  str <- fmap (judgeNum.getNums) getLine :: IO String
  putStrLn str

Measured memory_bytes: 508
_ = input()
l = list(map(int,input().split()))
flag = True
if 0 in l:
    print(0)
else:
    ans = 1
    for i in l:
        ans *= i
        if ans > 10**18:
            print(-1)
            flag = False
            break
    if(flag):
        print(ans)

Measured memory_bytes: 21776
program main
    read(*, *)n,m
    do i=0,n
       do j=0,n-i
          k = n - i - j
          if(i*10000 + j*5000 + k*1000 /= m)cycle
          write(*, *)i, j, k
          stop
       enddo
    enddo
    write(*, *) -1, -1, -1
end

Measured memory_bytes: 256
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <functional>
// using namespace __gnu_pbds;
using namespace std;

// typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag,
// tree_order_statistics_node_update> pbds;

#define ll long long
#define ld long double
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define fr(i,a,b) for(i=a;i<=b;i++)
#define fr2(i,a,b) for(i=a;i>=b;i--)
#define sf(a) scanf("%d", &a)
#define sf2(a,b) scanf("%d%d", &a, &b)
#define sf3(a,b,c) scanf("%lld%lld%lld", &a, &b, &c)
#define sf(a) scanf("%d", &a)
#define pf(a) printf("%d\n", a)
#define err1(a) cout<<a<<endl
#define err2(a,b) cout<<a<<" "<<b<<endl
#define err3(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl
#define err4(a,b,c,d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl
#define imi INT_MIN
#define ima INT_MAX
#define speedup ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define frein freopen ("input.txt", "r", stdin) 
#define freout freopen ("output.txt", "w", stdout)
#define fre freopen ("input.txt", "r", stdin);freopen ("output.txt", "w", stdout)
#define err(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define SIZE 1000002
#define all(v) v.begin(), v.end()
ll expo(ll a,ll b,ll m){if(a==0) return 1;ll res=1;while(b){if(b%2==1)res=((res%m)*(a%m))%m;a=((a%m)*(a%m))%m;b/=2;}return res%m;}
ld expo2(ld a,ll b){ld res=1;while(b){if(b%2==1)res=(res*a);a=(a*a);b/=2;}return res;}

const ll m = 1e9 + 7;

int main() {
    speedup;
    ll n;
    cin >> n;
    ll a[n+2], i, pos[n+2];
    fr(i, 1, n) {
        cin >> a[i];
        pos[a[i]] = i;
    }
    ll len = 1, curr_pos = pos[1], curr_len = 1;
    fr(i, 2, n) {
        if(pos[i] > curr_pos) {
            curr_len++;
            len = max(len, curr_len);
        } else {
            curr_len = 1;
        }   
        curr_pos = pos[i];
    }
    cout << n - len;
}

Measured memory_bytes: 3328
def main():
    while True:
        a, b = map(int, input().split())
        if a == 0:
            return
        k = int(input())
        p = [tuple(map(lambda x: int(x) - 1, input().split())) for _ in range(k)]

        root = [[0 for j in range(a)] for i in range(b)]

        root[0][0] = 1
        for i in range(0, b):
            for j in range(0, a):
                if i == 0 and j == 0:
                    continue
                if (j, i) in p:
                    root[i][j] = 0
                else:
                    root[i][j] = (root[i - 1][j] if i - 1 >= 0 else 0) + (root[i][j - 1] if j - 1 >= 0 else 0)

        print(root[b - 1][a - 1])


if __name__ == '__main__':
    main()




Measured memory_bytes: 5612
"use strict";

/**
 * Resolves problem.
 * @param  {string} input
 * @returns {string}
 */
const main = function(input) {
    const args = input.split(" ").map(x => parseInt(x));
    const A = args[0];
    const B = args[1];
    return (A <= 8 && B <= 8) ? "Yay!" : ":(";
};

const output = main(require("fs").readFileSync("/dev/stdin", "utf8"));
console.log(output); // console.log outputs with trailing new line!


Measured memory_bytes: 7372
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
using namespace std;
const int MOD = 1e9+7;
using ll = long long;
using vi = vector<int>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(x) x.begin(), x.end()

int main() {
    int a,b;
    cin >> a >> b;
    vector<string> vector(a);
    rep(i,a){
      cin >> vector.at(i);
    }
    sort(vector.begin(), vector.end());
  rep(i,a){
      cout << vector.at(i);
    }
  cout << endl;
}

Measured memory_bytes: 3632
import sys
A,B = map(int,input().split(" "))

sentinel1 = 0
N = 1
while sentinel1 < 101:
    sentinel1 = int(N * 0.08)
    sentinel2 = int(N * 0.1)
    if sentinel1 == A:
        if sentinel2 == B:
            print(N)
            sys.exit()
    N = N + 1

print(-1)

Measured memory_bytes: 39280
<?php
$input = explode(' ', trim(fgets(STDIN)));

$n = (int)$input[0];
$k = (int)$input[1];
$c = (int)$input[2];
$s = trim(fgets(STDIN));
// 勤務可能日の累積和
// $o_sum = [0];
// for ($i=0; $i < $n; $i++) { 
// 	$prev = $o_sum[$i];
// 	if ($s[$i] == "o") {
// 		$o_sum[] = $prev + 1;
// 	} else {
// 		$o_sum[] = $prev;
// 	}
// }

// 予定を前から詰めていった場合と、後から詰めていった場合とで、一致する日を確認する（それは必ず働く日である可能性がある）
$from_front = [];
$cur = 0;
while (count($from_front) < $k) {
	if ($s[$cur] == "o") {
		$from_front[] = ($cur + 1);
		$cur += $c + 1;
	} else {
		$cur += 1;
	}
}
$from_back = [];
$cur = $n - 1;
while (count($from_back) < $k) {
	if ($s[$cur] == "o") {
		$from_back[] = ($cur + 1);
		$cur -= ($c + 1);
	} else {
		$cur -= 1;
	}
}
sort($from_back);

$result = [];
foreach ($from_front as $idx => $fr) {
	if ($from_back[$idx] == $fr) {
		$result[] = $fr;
	}
}
echo implode(PHP_EOL, $result);

Measured memory_bytes: 32364
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

const int MAX_N = 2*(int)1e5 + 5;

struct Graph{
public:
	int to;
	int cost;
	int depth;
};

struct XYC{
public:
	int x, y, c;

	XYC(){}

	void setX(int _x){
		x = _x;
	}

	void setY(int _y){
		y = _y;
	}

	void setC(int _c){
		c = _c;
	}

	int getX(void){
		return x;
	}

	int getY(void){
		return y;
	}

	int getC(void){
		return c;
	}
		
	bool operator<(const XYC &xyc) const{
		return (x != xyc.x ? x < xyc.x : y < xyc.y);
	}
};

vector<Graph> G[MAX_N];

int sumCost[MAX_N]; // ?????±???????????????????????????????¨?
int numNode[MAX_N]; // ?????±?????????????????????????????°
int maxDepth; 	// ?????§??±???

bool used[MAX_N];

void dfs(int curr, int depth, int prev){
	if (used[curr]) return;
	used[curr] |= true;

	for (int i = 0; i < G[curr].size(); ++i){
		int next = G[curr][i].to;
		if (!used[next] && next != prev){
			G[curr][i].depth = depth;
			maxDepth = max(maxDepth, depth);
			dfs(next, depth + 1, curr);
		} // end if
	} // end for
}

void dfs2(int curr, int depth, int prev){
	if (used[curr]) return;
	used[curr] |= true;	
	
	for (int i = 0;i < G[curr].size(); ++i){
		int next = G[curr][i].to;
		if (!used[next] && next != prev){
			sumCost[depth] += G[curr][i].cost;
			++numNode[depth]; 
			dfs2(next, depth + 1, curr);
		} // edn if
	} // end for
}

int main()
{
	memset(sumCost, 0., sizeof(sumCost));
	memset(numNode, 0, sizeof(numNode));
	maxDepth = 0;

	rep (i, MAX_N) G[i].clear();
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	double p; cin >> p;
	int N; cin >> N;
	vector<XYC> xyc(N-1);

	rep (i, N-1){
		int x, y, c;
		cin >> x >> y >> c;
		--x, --y;
		xyc[i].setX(x);
		xyc[i].setY(y);
		xyc[i].setC(c);
	} // end rep

	sort(ALL(xyc));

	rep (i, N-1){
		G[xyc[i].getX()].push_back((Graph){xyc[i].getY(), xyc[i].getC(), 0});
		G[xyc[i].getY()].push_back((Graph){xyc[i].getX(), xyc[i].getC(), 0});
	} // end rep

	memset(used, false, sizeof(used));	
	dfs(0, 1, -1);
	memset(used, false, sizeof(used));	
	dfs2(0, 1, -1);

	double orig = 0.;
	double currp = p;
	for (int i = 1; i <= maxDepth; ++i){
		orig += (double)sumCost[i] * currp;
		currp *= p;
	} // end for

	double res = orig;
//	cerr << "orig: " << orig << endl;
	currp = p;
	for (int k = 1; numNode[k] != 0; ++k){
		res += sumCost[k] * currp;
		res += numNode[k] * currp * orig;
		currp *= p;
//		cerr << "numNode: " << numNode[k] << " sumCost: " << sumCost[k] << endl;
	} // end for

	printf("%.8lf\n", res);

	return 0;
}

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

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

int main() {

    int N, M;
    cin >> N >> M;
    vector<int> digits(N, -1);

    rep(i,M) {
        int s, c;
        cin >> s >> c;
        s--;
        if (digits[s] < 0) digits[s] = c;
        else if (digits[s] != c) {
            cout << -1 << endl;
            return 0;
        }
        if (N > 1 && s == 0 && c == 0) {
            cout << -1 << endl;
            return 0;
        }
    }

    if (N == 1) {
        cout << (digits[0] >= 0 ? digits[0] : 0) << endl;
    } else {
        rep(i,N) {
            if (digits[i] >= 0) cout << digits[i];
            else cout << (i == 0 ? 1 : 0);
        }
    }

    cout << endl;
    
    return 0;
}

Measured memory_bytes: 256
package main

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

func main() {
	n := nextInt()
	m := nextInt()
	xs := make([]int, n)
	for i := 0; i < n; i++ {
		xs[i] = nextInt()
	}
	ys := make([]int, m)
	for i := 0; i < m; i++ {
		ys[i] = nextInt()
	}
	p := int(math.Pow10(9)) + 7

	var X, Y int
	for i, x := range xs {
		X += i*x - (n-(i+1))*x
	}
	for i, y := range ys {
		Y += i*y - (m-(i+1))*y
	}

	fmt.Println((X % p) * (Y % p) % p)
}

// Input. ----------

var sc = bufio.NewScanner(os.Stdin)

func init() {
	//sc.Buffer([]byte{}, math.MaxInt64)
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}

	return i
}

func nextString() string {
	sc.Scan()
	if err := sc.Err(); err != nil {
		panic(err)
	}

	return sc.Text()
}

// ---------- Input.

// Util. ----------

func min(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}

func max(x, y int) int {
	return int(math.Max(float64(x), float64(y)))
}

// ---------- Util.


Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
int main() {
    int X, N;
    cin >> X >> N;
    set<int> p;
    for (int i = 0; i < N; i++) {
        int x;
        cin >> x;
        p.insert(x);
    }
    for (int i = 0;; i++) {
        if (p.find(X-i) == p.end()) {
            cout << X-i << endl;
            return 0;
        }
        if (p.find(X+i) == p.end()) {
            cout << X+i << endl;
            return 0;
        }
    }
}

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

int main() {
  int n;
  cin >> n;
  vector<int> b(n - 1);
  for (int i = 0; i < n - 1; i++) {
    cin >> b[i];
  }
  int ans = 0;
  vector<int> a(n);
  a[0] = b[0];
  a[n - 1] = b[n - 2];
  for (int i = 1; i < n - 1; i++) {
    a[i] = min(b[i - 1], b[i]);
  }
  for (int i = 0; i < n; i++) {
    ans += a[i];
  }
  cout << ans << endl;
  return 0;
}

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

void Main() {
    // input
    int N;
    string S;
    cin >> N;
    cin >> S;


    // translate
    u_int64_t r = 0;
    u_int64_t g = 0;
    u_int64_t b = 0;
    for (int i = 0; i < N; i++) {
        if (S[i] == 'R') {
            r++;
        } else if (S[i] == 'G') {
            g++;
        } else {
            b++;
        }
    }
    u_int64_t ans = r * g * b;

    for (int D = 1; D < N / 2 + 1; D++) {
        for (int i = 0; i + 2 * D < N; i++) {
            if((S[i] - S[i+D]) * (S[i+D] - S[i+D+D]) * (S[i+D+D]-S[i]) != 0) {
                if (ans == 0) {

                } else {
                    ans--;
                }
            }
        }
    }


    // output

    cout << ans << endl;

}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<int>>;
#define MAX 1000000
#define MOD 1000000007
#define INF 1000000000

int main(){
  int N;
  cin>>N;
  vector<ll> A(N);
  for(int i=0;i<N;i++){
    cin>>A.at(i);
  }
  bool flag=true;
  int i=N-1;
  int number=A.at(N-1);
  ll ans=0;
  ans+=number;
  while(i>=0){
    while(A.at(i)==number){
      number--;
      i--;
      if(i<0||number<0){
        break;
      }
    }
    if(i<0){
      break;
    }
    if(A.at(i)<number){
      flag=false;
      break;
    }else{
      ans+=A.at(i);
      number=A.at(i);
    }
  }
  if(A.at(0)!=0){
    flag=false;
  }
  if(flag){
    cout<<ans<<endl;
  }else{
    cout<<-1<<endl;
  }
}


Measured memory_bytes: 1792
import sys
from pprint import pprint

def solve(s):

  len_s = len(s)
  
  r = 0
  l = 0
  pos = [0] * len_s
  last_r_pos = 0
  for i in xrange(len_s):
    # print "l:",l,"r:",r,"last_r:",last_r_pos
    if s[i] == "R":
      if r == 0 and l > 0:
        if l % 2 == 0:
          pos[last_r_pos] += l / 2
          pos[last_r_pos + 1] += l / 2
        else:
          pos[last_r_pos] += l / 2 + 1
          pos[last_r_pos + 1] += l / 2
        l = 0
      last_r_pos = i
      r += 1

    elif s[i] == "L":
      if r > 0:
        if r % 2 == 0:
          pos[i] += r / 2
          pos[i-1] += r / 2
        else:
          pos[i] += r / 2
          pos[i-1] += r / 2 + 1
        pos[i] += 1
        r = 0
      else:
        l += 1
        r = 0

  if l > 0:
    if l % 2 == 0:
      pos[last_r_pos] += l / 2
      pos[last_r_pos + 1] += l / 2
    else:
      pos[last_r_pos] += l / 2 + 1
      pos[last_r_pos + 1] += l / 2

  # pprint(pos)
  print " ".join(map(str, pos))


if __name__ == '__main__':

  s = sys.stdin.readline().strip()
  solve(s)

Measured memory_bytes: 37020
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int N,A,B;
  cin>>N>>A>>B;
  cout<<min(N*A,B)<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(ll i = 0; i < (n); ++i )
#define rep_rev(n,i) for(ll i = n; i >= 0; --i )
using namespace std;
using P = pair<int, int>;
const long long INF = 1LL << 60;

int main(){
  int N,K; cin >> N >> K;
  vector<int> p(N);
  int idx[2];
  int t = 0;
  ll sum = 0;
  double ans = 0;
  rep(i,N){
    cin >> p[i];
    if(i == K-1){
      for(int j = 0; j < K; ++j) sum += p[j];
      if(t < sum){
        t = sum;
        idx[0] = 0;
        idx[1] = K-1;
      }
      sum -= p[0];
    }
    else if(i > K-1){
      sum += p[i];
      if(t < sum){
        t = sum;
        idx[0] = i-K+1;
        idx[1] = i;
      }
      sum -= p[i-K+1];
    }
  }
  for(int i = idx[0]; i <= idx[1]; ++i){
    int tmp = 0;
    rep(j,p[i]) tmp += j+1;
    ans += (double)tmp/(double)p[i];
  }
  cout << fixed << setprecision(10) << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
l = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]
n = input("")
if n in l:
    print("A")
else:
    print("a")

Measured memory_bytes: 9136
n,x,y = map(int,input().split())

ans = [0] * (n-1)

for i in range(n-1):
	for j in range(i+1,n):
		leng = min(j - i - 1, abs(j-y+1) + abs(i-x+1))
		ans[leng] += 1

for i in range(n-1):
	print(ans[i])


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
	ost<<"{"<<p.first<<","<<p.second<<"}";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
	ost<<"{";
	for(int i=0;i<v.size();i++){
		if(i)ost<<",";
		ost<<v[i];
	}
	ost<<"}";
	return ost;
}

signed main(){
	int N;
	cin>>N;
	int ans=0;
	vint V(N),C(N);
	rep(i,N)cin>>V[i];
	rep(i,N)cin>>C[i];
	rep(i,N)if(V[i]>C[i])ans+=V[i]-C[i];
	cout<<ans<<endl;
	return 0;
}

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

typedef long long ll;

int dp[3001][3001];

string longestCommon(string &a, string &b, int num){
    int i = 0,j = 0;
    string s ;
    while(num>0){
        if(a[i] == b[j]){
            s.push_back(a[i]);
            i++; j++;
            num--;
        }
        else{
            if(dp[i+1][j]>dp[i][j+1]){
                i++;
            }else{
                j++;
            }
        }
    }
    return s;
}

int lcs(string &a, string &b, int i, int j){
    if(i == a.length() || j == b.length()){
        return 0;
    }
    if(dp[i][j] != -1){
        // cout<<"CALLED"<<endl;
        return dp[i][j];
    }
    if(a[i] == b[j]){
        dp[i][j] = 1 + lcs(a,b,i+1,j+1);
        return dp[i][j];
        // cout<<res<<endl;
    }
    
    dp[i][j] = max(lcs(a,b,i+1,j),lcs(a,b,i,j+1));
    return dp[i][j];
}

int main() {
    string a,b,res;
    cin>>a>>b;
    memset(dp,-1,sizeof dp);
    int num = lcs(a,b,0,0);
    cout<<longestCommon(a,b,num)<<"\n";
}


Measured memory_bytes: 39232
uses Math;
var
	N,K,i,j:Longint;
	x,y,c:Array[1..60]of Longint;
	rr:Array[1..60]of double;
	L,R,M,a,t,d,ri,rj,yy:double;
	flag:Boolean;
function count(tx,ty:double):Boolean;
var i,cnt:Longint;
begin
	cnt:=0;
	for i:=1 to N do if sqr(X[i]-tx)+sqr(Y[i]-ty)<sqr(rr[i])+0.000000001 then inc(cnt);
	count:=cnt>=K;
end;
begin
	read(N,K);
	for i:=1 to N do read(x[i],y[i],c[i]);
	L:=0;
	R:=1000000;
	while R-L>0.000001 do begin
		M:=(L+R)/2;
		for i:=1 to N do rr[i]:=M/c[i];
		flag:=False;
		for i:=1 to N do begin
			if count(X[i],Y[i])then begin
				flag:=True;
				break;
			end;
		end;
		if not flag then begin
			for i:=2 to N do begin
				for j:=1 to i-1 do begin
					d:=sqr(X[i]-X[j])+sqr(Y[i]-Y[j]);
					ri:=rr[i];
					rj:=rr[j];
					yy:=4*sqr(ri)*d-sqr(sqr(ri)+d-sqr(rj));
					if yy<0 then continue;
					a:=arctan2(sqrt(yy),sqr(ri)+d-sqr(rj));
					t:=arctan2(Y[j]-Y[i],X[j]-X[i]);
					if count(X[i]+ri*cos(t+a),Y[i]+ri*sin(t+a)) then flag:=True
					else if count(X[i]+ri*cos(t-a),Y[i]+ri*sin(t-a))then flag:=True;
					if flag then break;
				end;
				if flag then break;
			end;
		end;
		if flag then R:=M else L:=M;
	end;
	writeln(R:0:9);
end.


Measured memory_bytes: 128
//自称高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
    int ans = 0;
    int tmp;
    int n, T;
    cin >> n >> T;
    int c, t, top = 999999;
    REP(i, n){
        cin >> c >> t;
        if(top > c && t <= T){
            top = c;
            
        }
    }
    if(top < 2000) cout << top << endl;
    else cout << "TLE" << endl;
}

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

#define in_fre freopen("redir.txt", "r", stdin);
#define out_fre freopen("out5.txt", "w", stdout);
#define fast() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define debug(i) printf("\nDebug %d\n",i);
#define mod 1000000007
#define ll long long int

int main()
{	
clock_t begin, end;
double time_spent;
begin = clock();

//	fast();
#ifndef ONLINE_JUDGE
	in_fre
	out_fre
#endif

ll n;
cin>>n;
ll ar[n]={0},br[100005]={0},sum=0;
for (int i = 0; i < n; ++i)
{cin>>ar[i];br[ar[i]]++;sum+=ar[i];
}
ll q;
cin>>q;
for (int i = 0; i < q; ++i)
{ ll b,c;
	cin>>b>>c;
	//if(br[b]!=0)
	{
		sum=sum-br[b]*b+br[b]*c;
		cout<<sum<<"\n";
		//br[b]=0;
		br[c]=br[c]+br[b];
		br[b]=0;
	}
}

end = clock();
time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
cerr<<"Time spent = "<<time_spent<<endl;

return 0;
}

Measured memory_bytes: 5316
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

alias Point = Tuple!(int, "x", int, "y");

int maxBipartiteMatching(bool[][] g) {

    bool mbm(int p, int[] left, int[] right, bool[][] g, bool[] used) {
        for (int i = 0; i < right.length; i++) {
            if (g[p][i] && right[i] == -1) {
                left[p] = i;
                right[i] = p;
                return true;
            }
        }

        for (int i = 0; i < right.length; i++) {
            if (g[p][i] && !used[i]) {
                used[i] = true;
                if (mbm(right[i], left, right, g, used)) {
                    left[p] = i;
                    right[i] = p;
                    return true;
                }
            }
        }
        return false;
    }

    auto n = g.length;
    auto left = new int[n];
    auto right = new int[n];
    left[] = -1;
    right[] = -1;
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        auto used = new bool[n];
        if (mbm(i, left, right, g, used)) {
            cnt++;
        }
    }
    return cnt;
}

int calc(Point[] ab, Point[] cd) {
    assert(ab.length == cd.length);

    auto n = ab.length;
    auto g = new bool[][](n, n);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (ab[i].x < cd[j].x && ab[i].y < cd[j].y) {
                g[i][j] = true;
            }
        }
    }
    return maxBipartiteMatching(g);
}

void main() {
    int n = readint;

    Point[] ab, cd;
    for (int i = 0; i < n; i++) {
        auto xy = readints;
        ab ~= Point(xy[0], xy[1]);
    }
    for (int i = 0; i < n; i++) {
        auto xy = readints;
        cd ~= Point(xy[0], xy[1]);
    }

    writeln(calc(ab, cd));
}


Measured memory_bytes: 380
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>

using namespace std;
typedef long long ll;

int main(){

    int n;
    cin >> n;

    ll ans = 0;
    for(int i = 0; i < n; i++){
        int l, r;
        cin >> l >> r;
        ans += (r - l + 1);
    }    
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        while (true) {
            int h = sc.nextInt();
            int w = sc.nextInt();
            if (h == 0) {
                break;
            }
            write(h, w);
            System.out.println("");
        }

    }

    static void write(int h, int w) {
        for (int i = 1; i <= h; i++) {
            for (int j = 1; j <= w; j++) {
                System.out.print("#");
            }
            System.out.println("");
        }
    }

}


Measured memory_bytes: 34896
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;} return 0;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    string s; cin >> s;
    if (s == "ABC") {
        cout << "ARC" << endl;
    } else {
        cout << "ABC" << endl;
    }
    return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
  int N;
  cin >> N;
  int n500=N/500;;
  int n5=(N%500)/5;
  cout << n500*1000+n5*5;
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main(){
    std::string s, t;
    std::cin >> s >> t;

    int sSz = s.size(), tSz = t.size(), i = sSz - tSz;
    for(; 0 <= i; --i){
        bool flg2 = true;
        int j = 0;
        std::string sub = s.substr(i, tSz);
        while(flg2 && j < tSz){
            flg2 = '?' == sub.at(j) || sub.at(j) == t.at(j);
            ++j;
        }
        if(flg2){
            break;
        }    
    }

    std::string ans = "UNRESTORABLE";
    if(0 <= i){
        s.replace(i, tSz, t);
        for(int i = 0; i < sSz; ++i){
            if('?' == s.at(i)){
                s.at(i) = 'a';
            }
        }
        ans = s;
    }    

    std::cout << ans << std::endl;

    return 0;
}

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

struct restaurant
{
	int num;
	int point;
	string s;
};

void bubblesort(restaurant r[], int n)
{
	for (int i = 0; i < n; i++) {
		for (int j = n - 1; j > i; j--) {
			if (r[j - 1].s > r[j].s) {
				restaurant temp = r[j - 1];
				r[j - 1] = r[j];
				r[j] = temp;
			}
			else if ((r[j-1].s==r[j].s)&&(r[j-1].point<r[j].point))
			{
				restaurant temp = r[j - 1];
				r[j - 1] = r[j];
				r[j] = temp;
			}
		}
	}
}

int main()
{
	int n;
	restaurant r[100];

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> r[i].s >> r[i].point;
		r[i].num = i + 1;
	}

	bubblesort(r, n);

	for (int i = 0; i < n; i++) {
		cout << r[i].num << endl;
	}

	return 0;
}

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

#define ll long int

int main(){
    ll n,k;
    cin >> n >> k;
    ll ans = 0;
    
    if(k % 2 == 0){
        ll t = n / k;
        ans += t*t*t;
        t = (n / (k / 2) - n / k);
        ans += t*t*t;
    }else{
        ll t = n / k;
        ans += t*t*t;
    }

    cout << ans << endl;

}

Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A: Remaining Time
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int a, b;
  cin >> a >> b;
  printf("%d\n", (a + b) % 24);
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;
const int kmax = 510000;

long long fact[kmax], fact_inv[kmax], inv[kmax];

int gcd(int a, int b)
{
    if (!b) {
        return a;
    }

    return gcd(b, a % b);
}

void init_comb()
{
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < kmax; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}

long long comb(int n, int r)
{
    if (n < r) {
        return 0;
    }

    if (n < 0 || r < 0) {
        return 0;
    }

    return fact[n] * (fact_inv[r] * fact_inv[n - r] % mod) % mod;
}

int main()
{
    int n, m;
    std::cin >> n >> m;

    std::vector<int> is_ok(n + 1, true);
    for (int i = 0; i < m; i++) {
        int temp;
        std::cin >> temp;

        is_ok[temp] = false;
    }

    std::vector<long long> dp(n + 1, 0);
    dp[0] = 1;

    for (int i = 0; i < n; i++) {
        if (i + 1 <= n && is_ok[i + 1]) {
            dp[i + 1] += dp[i];
            dp[i + 1] %= mod;
        }

        if (i + 2 <= n && is_ok[i + 2]) {
            dp[i + 2] += dp[i];
            dp[i + 2] %= mod;
        }
    }

    std::cout << dp[n] << std::endl;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define M 1000000007
#define ll long long
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define REPI(i,a,b) for(ll i=b-1;i>=a;i--)
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define G(a,b) get<a>(b)
#define VI vector<int>
#define VLL vector<long long>

#define o_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define o_setll tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set

ll modI(ll a, ll m);
ll gcd(ll a, ll b);
ll powM(ll x, unsigned ll y, unsigned ll m);
void pairsort(int a[], int b[], int n);
void pairsortll(ll a[],ll b[],ll n);
ll logint(ll x,ll y);


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

ll powM(ll x,ll y,ll m)
{
    if(y==0) return 1;
    ll p=powM(x,y/2,m)%m;
    p=(p*p)%m;
    return (y%2==0)?p:(x*p)%m;
}

ll modI(ll a, ll m)
{
    ll m0=m,y=0,x=1;
    if(m==1) return 0;
    while(a>1)
    {
        ll q=a/m;
        ll t=m;
        m=a%m;
        a=t;
        t=y;
        y=x-q*y;
        x=t;
    }
    if(x<0) x+=m0;
    return x;
}

void pairsort(int a[],int b[],int n)
{
    pair<int,int> v[n];
    REP(i,0,n)
    {
        v[i].F=a[i];
        v[i].S=b[i];
    }
    sort(v,v+n);
    REP(i,0,n)
    {
        a[i]=v[i].F;
        b[i]=v[i].S;
    }
}

void pairsortll(ll a[],ll b[],ll n)
{
    pair<ll,ll> v[n];
    REP(i,0,n)
    {
        v[i].F=a[i];
        v[i].S=b[i];
    }
    sort(v,v+n);
    REP(i,0,n)
    {
        a[i]=v[i].F;
        b[i]=v[i].S;
    }
}

ll logint(ll x,ll y)
{
    ll ans=0;
    ll a=1;
    for(ll i=0;i<=x;i++)
    {
        if(x<a)
        {
            return ans;
        }
        ans++;
        a*=y;
    }
    return -1;
}

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

    /*
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    */

    ll q=1;
    //cin>>q;
    while(q--)
    {
        ll n,k;
        cin>>n>>k;
        ll ans=0;
        REP(i,0,n)
        {
            ll t;
            cin>>t;
            if(t>=k) ans++;
        }
        cout<<ans;
    }

    return 0;
}


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

#define all(x)        (x).begin(),(x).end()
#define eb            emplace_back
#define mp            make_pair
#define pb            push_back
#define fi            first
#define se            second
#define sz(x)         ((int)(x).size())
#define rep(x,y,z)    for(int x=y;x<z;x++)
#define per(x,z,y)    for(int x=z-1;x>=y;x--)
#define trav(y,x)     for(auto& y:x)
#define pii           pair<int, int>
#define pll           pair<ll, ll>
#define vi            vector<int>
#define vpi           vector<pii>

int dbg = 0;
#define cri           if(0)
#define shame         cri cerr<<(++dbg)<<"\n\n";

// aaaaaaaaaaaaaaaa
void solve() {
  int N;
  scanf("%d", &N);
  ll ans = 0;
  rep(i, 1, N + 1)
    if (i % 3 && i % 5)
      ans += i;
  printf("%lld\n", ans);
}

int main() {
  // int _; scanf("%d", &_); while (_--)
  solve();
	return 0;
}



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

using namespace std;

struct Graph {
    struct Edge {
        int u, v;
        int cost;
        Edge(int _u, int _v, int _cost) : u(_u), v(_v), cost(_cost) {}
    };
    int n, m;
    bool is_digraph;
    vector<vector<int>> g;
    vector<Edge> e;

    Graph(int _n) : n(_n), m(0) {
        assert(n >= 1);
        g.resize(n);
        set_di(false);
    }
    Graph(int _n, int _m, bool _di=false) : n(_n) {
        assert(n >= 1);
        g.resize(n);
        e.reserve(_m);
        m = 0;
        set_di(_di);
        input(_m);
    }
    void set_di(bool _di) {
        is_digraph = _di;
    }
    inline void add(int u, int v, int cost=1) {
        assert(0 <= u && u < n);
        assert(0 <= v && v < n);
        if (is_digraph) {
            //outdeg[u]++; indeg[v]++;
            g[u].emplace_back(m);

        } else {
            //deg[u]++; deg[v]++;
            g[u].emplace_back(m);
            g[v].emplace_back(m);
        }
        e.emplace_back(u, v, cost);
        m++;
    }
    void input(int _m) {
        int u, v, c;
        for (int i = 0; i < _m; i++) {
            cin >> u >> v >> c;
            u--; v--; // input 1-based
            add(u, v, -c); // here negative
        }
    }
    template <typename T=int>
    vector<T> bellman_ford(int s, int additional_rounds);
};

// single source shortest path
// allow negative, but not -cycle
template <typename T>
vector<T> Graph::bellman_ford(int s, int additional_rounds) {
    //const int INF = 0x3f3f3f3f;
    const long long INF = 0x3f3f3f3f3f3f3f3f;
    vector<T> d(n, INF);
    d[s] = 0;
    // if detect, add another round
    for (int i = 0; i < n-1 + additional_rounds; i++) {
        // add flag early stop for constant optimization
        for (auto& k: e) {
            if (d[k.u] < INF && d[k.v] > d[k.u] + k.cost)
                d[k.v] = d[k.u] + k.cost;
        }
    }
    return d;
}
using ll=long long;
void solve() {
    int n, m;
    cin >> n >> m;
    Graph g(n,m,true);
    auto s = g.bellman_ford<ll>(0, 0);
    auto d = g.bellman_ford<ll>(0, n);
    if (s[n-1] != d[n-1]) cout << "inf";
    else cout << -s[n-1];
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 384
n = int(input())
card_dict = {}
for symbol in ["S", "H", "C", "D"]:
    card_dict[symbol] = []
for i in range(n):
    symbol, number = input().split(" ")
    card_dict[symbol].append(number)
for symbol in ["S", "H", "C", "D"]:
    for number in range(1, 14):
        if str(number) not in card_dict[symbol]:
            print("{} {}".format(symbol, number))



Measured memory_bytes: 5600
N = int(input())
T = [0]
X = [0]
Y = [0]
for n in range(N):
  t,x,y = map(int,input().split())
  T.append(t)
  X.append(x)
  Y.append(y)

for n in range(N):
  D = abs(X[n+1]+Y[n+1]-X[n]-Y[n])
  if T[n+1]-T[n] == D:
    pass
  elif T[n+1]-T[n]>D and (T[n+1]-T[n]-D)%2==0:
    pass
  else:
    print("No")
    exit()
    
print("Yes")


Measured memory_bytes: 17704
use std::io::{self, BufRead};

fn main() {
  let stdin = io::stdin();
  let mut lines = stdin.lock().lines();
  let xs: Vec<usize> = lines.next().unwrap().unwrap().split(' ').map(|x| x.parse().unwrap()).collect();
  let (h, w) = (xs[0], xs[1]);
  let n = h * w;
  let mut cells: Vec<Vec<char>> = Vec::new();
  for _ in 0..h {
    let cs = lines.next().unwrap().unwrap().chars().collect();
    cells.push(cs);
  }
  let mut es: Vec<Vec<usize>> = vec![Vec::new(); n];
  for i in 0..h {
    for j in 0..w {
      if cells[i][j] == '#' {
        continue;
      }
      let k = i * w + j;
      if i > 0 && cells[i-1][j] == '.' {
        es[k].push((i - 1) * w + j);
      }
      if i < h - 1 && cells[i+1][j] == '.' {
        es[k].push((i + 1) * w + j);
      }
      if j > 0 && cells[i][j-1] == '.' {
        es[k].push(i * w + j - 1);
      }
      if j < w - 1 && cells[i][j+1] == '.' {
        es[k].push(i * w + j + 1);
      }
    }
  }
  let mut ds: Vec<Vec<usize>> = vec![vec![usize::max_value(); n]; n];
  for i in 0..n {
    ds[i][i] = 0;
    for j in &es[i] {
      ds[i][*j] = 1;
    }
  }
  for k in 0..n {
    for i in 0..n {
      for j in 0..n {
        let d = if ds[i][k] < usize::max_value() && ds[k][j] < usize::max_value() { ds[i][k] + ds[k][j] } else { usize::max_value() };
        if ds[i][j] > d {
          ds[i][j] = d;
        }
      }
    }
  }
  let def = 0;
  let ans = ds.iter().map(|l| l.into_iter().filter(|d| **d < usize::max_value()).max().unwrap_or(&def)).filter(|d| **d < usize::max_value()).max().unwrap_or(&def);
  println!("{}", ans);
}

Measured memory_bytes: 4352
#include<iostream>
using namespace std;
long long dp[3005][3005],a,b,c,d;
const long long mod=998244353;
int main(){
	cin>>a>>b>>c>>d;
	dp[a][b]=1;
	for(int i=a;i<=c;i++){
		for(int j=b;j<=d;j++){
			if(i==a&&j==b) continue;
			dp[i][j]=(dp[i-1][j]*j%mod+dp[i][j-1]*i%mod-(i-1)*(j-1)*dp[i-1][j-1]%mod+10*mod)%mod;
		}
	}
	cout<<dp[c][d];
}

Measured memory_bytes: 73492
#include <iostream>
#include <algorithm>
#include <string.h>
#include <math.h>
#include <vector>

using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned ll
#define db double
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PII pair<int, int>

const int N=110;
int n,a[3][N],dp[3][N];

int main()
{
    scanf("%d",&n);
    for (int i=1;i<=2;i++) {
        for (int j=1;j<=n;j++) {
            scanf("%d",&a[i][j]);
        }
    }
    dp[1][1]=a[1][1];
    for (int i=2;i<=n;i++) dp[1][i]=dp[1][i-1]+a[1][i];
    dp[2][1]=dp[1][1]+a[2][1];
    for (int i=2;i<=n;i++) dp[2][i]=max(dp[1][i],dp[2][i-1])+a[2][i];
    printf("%d\n",dp[2][n]);
}


Measured memory_bytes: 384
#include <bits/stdc++.h> 
#define ll long long
#define the_num 1000000007
#define ano_num 998244353
#define forn(n) for(int i=0;i<n;i++)
#define For(i,start_i,n) for(int i=start_i;i<n;i++)
#define test int t;cin >> t;while(t--)
#define all(v) v.begin(),v.end()
#define in_arr(arr,n) int arr[n];forn(n) cin >> arr[i];
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define take(data_type,n) data_type n;cin >> n;
using namespace std;
  
int main(){ 
    fast
    double a,b,h,m;
    cin >> a >> b >> h >> m;
    cout.precision(15);
    double pi = 2.0*acos(0.0);
    cout << sqrt(a*a + b*b - 2*a*b*cos(pi*(h/6.0 + m/360.0 - m/30.0))) << '\n';
} 

Measured memory_bytes: 4244
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,n,m) for(int i=n;i<m;i++)
#define elif else if
#define INF 1000000007
using namespace std;
int gcd(int a,int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int m,n,cnt=0,aa[220000];
pair<int,int> pp[220000];
string s,ss[220000];
char c;
queue<int> que;
signed main(){
    cin>>s;
    rep(i,s.size()){
        if(s[i]=='?'){
            cout<<'D';
        }else{
            cout<<s[i];
        }
    }
}

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


public class Test
{	
    public static void Main()
	{
	    int n = int.Parse(Console.ReadLine());
	    int a = int.Parse(Console.ReadLine());
	    if(n%500 <= a) Console.WriteLine("Yes");
	    else Console.WriteLine("No");
	} 
}

Measured memory_bytes: 11092
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::pair;

using std::vector;
using std::sort;

int main(){
    int N;
    cin >> N;
    vector<int> t(N+1);
    vector<int> x(N+1);
    vector<int> y(N+1);
    t[0]=0;
    x[0]=0;
    y[0]=0;
    for(int i=1;i<=N;i++){
        cin >> t[i];
        cin >> x[i];
        cin >> y[i];
    }

    for(int i=0;i<N;i++){
        int time=t[i+1]-t[i];
        int dist=std::abs(x[i+1]-x[i])+std::abs(y[i+1]-y[i]);
        if(time < dist || (time-dist)%2==1){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}



Measured memory_bytes: 1408
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<utility>
#include<numeric>
#include<vector>
#include<map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<functional>
#include<iterator>
#include<cmath>
#include<cctype>

using namespace std;

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

const int INF = 1e9;
const ll LINF = 1e18;

struct edge{int to,cost;};


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

	int n,m;
	cin >> n >> m;
	
	int a,b;
	vector<int> from1,toN;
	for(int i=0;i<m;i++){
		cin >> a >> b;
		if(a == 1 && b == n){
			cout << "POSSIBLE\n";
			return 0;
		}
		else if(a == 1)	from1.push_back(b);
		else if(b == n) toN.push_back(a);
	}
	sort(toN.begin(),toN.end());
	for(auto i=from1.begin();i!=from1.end();i++){
		if(binary_search(toN.begin(),toN.end(),*i)){
			cout << "POSSIBLE\n";
			return 0;
		}
	}
	cout << "IMPOSSIBLE\n";
	return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --i)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

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

    vector<int> D(K);
    rep(i, K) cin >> D[i];

    auto f = [&](int x) {
        bool res = true;
        while (x > 0) {
            int m = x % 10;
            if (find(D.begin(), D.end(), m) != D.end()) return false;
            x /= 10;
        }
        return true;
    };

    while (1) {
        if (f(N)) break;
        N++;
    }

    cout << N << endl;
}

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

int main(void) {
	int H, N;
	cin >> H >> N;
	vector<int>A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	int aa = 0;
	for (int i = 0; i < N; i++) {
		aa += A[i];
	}

	if (aa >= H) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


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

int main() {
    string s;
    cin >> s;
    s.pop_back();
    while (s.size() > 0) {
        if (s.size() % 2) {
            s.pop_back();
            continue;
        }
        int f = 1;
        for (int i = 0; i < s.size() / 2; i++) {
            if (s[i] != s[i + s.size() / 2]) f = 0;
        }
        if (f) break;
        s.pop_back();
    }
    cout << s.size() << endl;
    return 0;
}

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

int main(){
    int N; cin >> N;
    map<string,int> A;
    string before,after;
    cin >> before;
    A[before]++;
    
    rep(i,N-1){
        cin >> after;
        if(before.at(before.size()-1)==after.at(0) && A[after]==0){
            A[before]++;
            before=after;
        }else{
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
}

Measured memory_bytes: 256