akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        new Main().run();
    }

    private void run() {
        Scanner scanner = new Scanner(System.in);
        int A = scanner.nextInt();
        int B = scanner.nextInt();
        int C = scanner.nextInt();
        int K = scanner.nextInt();

        int i = 0;
        while (A >= B) {
            B = B + B;
            i++;
            if (i > K) {
                System.out.println("No");
                return;
            }
            if (A < B) break;
        }

        while (B >= C) {
            C = C + C;
            i++;
            if (i > K) {
                System.out.println("No");
                return;
            }
            if (B < C) break;
        }
        System.out.println("Yes");
    }
}

Measured memory_bytes: 35668
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
   string s1,s2;
   cin>>s1>>s2;
   int c=0;
   for(int i=0;i<3;i++)
   {
       if(s1[i]==s2[i])
        c++;
   }
   cout<<c<<endl;
}


Measured memory_bytes: 256
n = int(input())
l0 = 2
l1 = 1
if n == 0:
    ans = l0
elif n == 1:
    ans = l1
else:
    for i in range(2, n + 1):
        if i % 2 == 0:
            l0 = l0 + l1
        else:
            l1 = l0 + l1
    ans = max(l0, l1)
print(ans)

Measured memory_bytes: 3060
#ifdef OJ_MISC_OFFLINE

#include "prolog.h"

#else
#define LOG
#define PRINT
#define LCERR
#include <iostream>
auto optimize_cpp_stdio = []() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::setvbuf(stdout, nullptr, _IOFBF, BUFSIZ);
    return 0;
}();
#endif

#include <algorithm>
#include <array>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>

namespace {

using namespace std;

int solve() {
    // handle IO here
    int N;
    cin >> N;
    int digits = to_string(N).size();
    int result = 0;
    if (digits == 1) {
        result = N;
    } else if (digits == 2) {
        result = 9;
    } else if (digits == 3) {
        result = 9 + N - 100 + 1;
    } else if (digits == 4) {
        result = 909;
    } else if (digits == 5) {
        result = 909 + N - 10000 + 1;
    } else if (digits == 6) {
        result = 90909;
    }
    cout << result << '\n';
    return 0;
}

} // anonymous namespace

#ifdef OJ_MISC_OFFLINE

#include "epilog.h"

#else

int main() {
    return solve();
}

#endif


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

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

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
	int n, p[101], m[101][101];
  cin >> n;
  for(int i = 1; i <= n; i++) cin >> p[i - 1] >> p[i];

  for(int i = 1; i <= n; i++) m[i][i] = 0;
  for(int l = 2; l <= n; l++) {
    for(int i = 1; i <= n - l + 1; i++) {
      int j = i + l - 1;
      m[i][j] = (1 << 21);
      for(int k = i; k <= j - 1; k++) {
        m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
      }
    }
  }
  cout << m[1][n] << endl;
  return 0;
}


Measured memory_bytes: 3176
#include<stdio.h>
int main()
{
	int a[5],i,g,t,p,r[5];
	while(1){
		g=p=t=0;
		scanf("%d",&a[0]);
		if(a[0]==0){
			break;
		}
		scanf("%d%d%d%d",&a[1],&a[2],&a[3],&a[4]);
		for(i=0;i<5;i++){
			switch(a[i]){
			case 1:
				g++;
				break;
			case 2:
				t++;
				break;
			case 3:
				p++;
				break;
			}
		}
		if((g!=0&&t!=0&&p!=0)||g==5||t==5||p==5){
			for(i=0;i<5;i++){
				r[i]=3;
			}
		}else if(g==0){
			for(i=0;i<5;i++){
				if(a[i]==2){
					r[i]=1;
				}else{
					r[i]=2;
				}
			}
		}else if(t==0){
			for(i=0;i<5;i++){
				if(a[i]==3){
					r[i]=1;
				}else{
					r[i]=2;
				}
			}
		}else{
			for(i=0;i<5;i++){
				if(a[i]==1){
					r[i]=1;
				}else{
					r[i]=2;
				}
			}
		}
		for(i=0;i<5;i++){
			printf("%d\n",r[i]);
		}
	}
	return 0;
}

Measured memory_bytes: 1740
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <map>
#include <utility>
#include <numeric>
#define ll long long
#define REP(i, x) for(int (i) = 0; (i) < (x); (i) ++)
#define pi 3.1415926535
const int MOD = 1000000007;
using namespace std;

ll GCD(ll a, ll b) {
	ll r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}

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

int main() {
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	ll ans = b - a + 1;
	ll e = a / c;
	if (a%c == 0) {
		e--;
	}
	ll f = b / c;
	ll g = a / d;
	if (a%d == 0) {
		g--;
	}
	ll h = b / d;
	ll i = a / LCM(c, d);
	if (a% LCM(c, d) == 0) {
		i--;
	}
	ll j = b / LCM(c, d);
	ans -= f - e + h - g;
	ans += j - i;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
x,y,a,b,c=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))

ri=sorted(r)[::-1]

qi=q[::]
pi=p[::]
pi=sorted(pi)[::-1]
pi=pi[:x]
qi=sorted(qi)[::-1]
qi=qi[:y]

l=pi+qi
l=sorted(l)
k=0
for i in range(min(c,x+y)):
    if l[i]>ri[i]:
        break
    else:
        k=i+1
print(sum(l[k:])+sum(ri[:k]))

Measured memory_bytes: 113388
def gcd(x, y):
    while y!=0:
        x, y = y, x % y # x,yの大小が逆でも、入れ替わるので、OK
    return x

n = int(input())
a = list(map(int, input().split()))

if n == 2:
    print(max(a))

elif n>=3:
    l = [-1] * n
    r = [-1] * n
    l[0] = a[0]  #一番左を左に挿入
    r[-1] = a[-1] #一番右を右に挿入
# print(l)
# print(r)

    for i in range(1, n): #左から最大公約数をn-1回計算していく
        l[i] = gcd(l[i-1], a[i]) # l[0]とa[1]の最大公約数をl[1]に挿入⇒
        # l[1]とa[2]の最大公約数をl[2]に挿入。隣同士素があったら、それ以降右側全て1
    for i in range(n-2, -1, -1): #右から最大公約数を計算していく
        r[i] = gcd(r[i+1], a[i]) # r[n-1]とa[n-2]の最大公約数をr[n-2]に挿入

        # print("l",l) # lはn-1桁のlist
        # print("r",r)

    ans = max(r[1], l[-2]) # rの左から2番目とlの右から2番目の大きい方を、ansに挿入.
        # 右端、左端は、最大公約数ではないため。(元々の数列)

    for i in range(1, n-1): #両端を切り取った中で、lは右側に寄せて、rは左側に寄せているので、
        g = gcd(l[i-1], r[i+1]) #
        ans = max(ans, g)
        # print(i, g, ans)
    print(ans)

Measured memory_bytes: 14080
fn main() {
    let mut s: Vec<char> = readln();
    let mut t: Vec<char> = readln();
    s.sort();
    t.sort();
    t.reverse();
    if s < t {
        println!("Yes");
    } else {
        println!("No");
    }
}

// --- template ---
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::HashSet;

pub trait FromLn {
    fn fromln(s: &str) -> Self;
}
pub fn readln<T: FromLn>() -> T {
    let mut buf = String::new();
    let _ = ::std::io::stdin().read_line(&mut buf).unwrap();
    T::fromln(buf.trim())
}
pub fn readlns<T: FromLn>(n: usize) -> Vec<T> {
    let mut vs = vec![];
    for _ in 0..n {
        vs.push(readln());
    }
    vs
}
macro_rules! fromln_primitives {
    ($($t:ty),*) => { $(
        impl FromLn for $t {
            fn fromln(s: &str) -> $t {
                s.parse().unwrap()
            }
        }
    )* }
}
fromln_primitives!(
    String,
    bool,
    f32,
    f64,
    isize,
    i8,
    i16,
    i32,
    i64,
    usize,
    u8,
    u16,
    u32,
    u64
);
impl<T> FromLn for Vec<T>
where
    T: FromLn,
{
    fn fromln(s: &str) -> Vec<T> {
        s.split_whitespace().map(T::fromln).collect()
    }
}
impl FromLn for Vec<char> {
    fn fromln(s: &str) -> Vec<char> {
        s.chars().collect()
    }
}
macro_rules! fromln_tuple {
    ($($t:ident),*) => {
        impl<$($t),*> FromLn for ($($t),*) where $($t: FromLn),* {
            fn fromln(s: &str) -> ($($t),*) {
                let mut it = s.split_whitespace();
                let t = ($($t::fromln(it.next().unwrap())),*);
                assert_eq!(it.next(), None);
                t
            }
        }
    }
}
fromln_tuple!(A, B);
fromln_tuple!(A, B, C);
fromln_tuple!(A, B, C, D);
fromln_tuple!(A, B, C, D, E);
fromln_tuple!(A, B, C, D, E, F);


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

#ifdef ARTEM
	#define deb(x) x
#else
	#define deb(x)
	const int LIMIT = 2 * int(1e5) + 123;
#endif

void solve();

int main() {
	solve();
}

/* ================ actual code starts here ================ */

void solve() {
	vector<int> a(3);
	for(int i = 0; i < 3; i++)
		scanf("%d", &a[ i ]);
	sort(a.begin(), a.end());

	if(a[ 0 ] == 5 && a[ 1 ] == 5 && a[ 2 ] == 7)
		printf("YES\n");
	else
		printf("NO\n");
}

Measured memory_bytes: 3684
#include <iostream>
#include <string>
#include <cmath>
#include <set>
#include <utility>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <cstdio>
#include <cstring>

using namespace std;

constexpr long long mod = 1000000007;
constexpr double eps = 0.0000000001;

typedef long long ll;
typedef long long unsigned ull;

int main() {
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a,a+3);
    if((a[0]==a[1] && a[1] != a[2]) || (a[2]==a[1] && a[1] != a[0])) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"os"
)

var (
	n, m int
	a, b int
	mp   = make(map[int][]int)
)

func main() {
	fmt.Scan(&n, &m)
	for i := 0; i < m; i++ {
		fmt.Scan(&a, &b)
		mp[a] = append(mp[a], b)
	}

	for _, v := range mp[1] {
		for _, w := range mp[v] {
			if w == n {
				fmt.Println("POSSIBLE")
				os.Exit(0)
			}
		}
	}

	fmt.Println("IMPOSSIBLE")
}


Measured memory_bytes: 23552
N,K = map(int, input().split())
A = list(map(int,input().split()))

binK = bin(K)[2:]
maC = 0

B = [0 for _ in [0]*40]

for i in range(N):
    C = bin(A[i])[2:][::-1]
    maC = max(maC,len(C))
    for j in range(len(C)):
        B[j] = B[j] + int(C[j])
        
an = 0

PPP = max(len(binK),maC)
KK = [int(t < N/2) for t in B[:len(binK)][::-1]]

for k in range(PPP):
    if k < len(binK):
        an = an + max(B[k], N-B[k])*(2**k)
    else:
        an = an + B[k]*(2**k)

#t = PPP-1 
#an1 = an + (N-B[t])*(2**t)
#an0 = an + (B[t])*(2**t)


#flag = 0
#if an0 >= an1:
#    print(an0)
#    flag = 1
#else:
for l in range(len(binK)):
    if int(binK[l]) > KK[l]:
        break
    if int(binK[l]) < KK[l]:
        ll = len(KK) - l -1
        an = an - max(B[ll], N-B[ll])*(2**ll) + min(B[ll], N-B[ll])*(2**ll)
            
#if flag < 1:
print(an)

Measured memory_bytes: 14620
#include <bits/stdc++.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;
double const PI = acos(-1);
int const N = 3000 + 10;
int a[N], n;
ll dp[N][N][2];

ll solve(int l, int r, bool turn){
	if (l > r)
		return 0;
	ll &dp = ::dp[l][r][turn];
	if (dp != -1)
		return dp;
	if (turn)
		dp = max(solve(l + 1, r, 0) + a[l], solve(l, r - 1, 0) + a[r]);
	else
		dp = min(solve(l + 1, r, 1) - a[l], solve(l, r - 1, 1) - a[r]);
	return dp;
}

int main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	memset(dp, -1, sizeof(dp));
	cin >> n;
	for (int i = 0; i < n; ++i) cin >> a[i];
	cout << solve(0, n - 1, 1);
	return 0;
}

Measured memory_bytes: 141952
#include <stdio.h>
int main(){
  int n,t,u,s,v;
  scanf("%d",&n);
  s=n/100;
  t=n-s*100;
  v=t/10;
  u=t-v*10;
  if(n/100==7){
	printf("Yes");
  }else if(t/10==7){
    printf("Yes");
  }else if(u==7){
    printf("Yes");
  }else{
    printf("No");
  }

  return 0;
}

Measured memory_bytes: 1724
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n, m, l = sc.nextInt()
  val A = new Matrix(n, m, List.fill(n, m)(sc.nextInt()))
  val B = new Matrix(m, l, List.fill(m, l)(sc.nextInt()))
  A.printDotProduct(B)

  class Matrix(rs: Int, cs: Int, d: List[List[Int]]) {
    val rowSize = rs
    val colSize = cs
    val data = d
    val colList: List[List[Int]] = (for (i <- 0 to colSize - 1) yield data.map(e => e(i))).toList

    def printDotProduct(o: Matrix): Unit = {
      for (i <- 0 to rowSize - 1) {
        var result = List.empty[Long]
        for (j <- 0 to o.colList.size - 1) {
          result = calcElement(data(i), o.colList(j)) :: result
        }
        println(result.reverse.mkString(" "))
      }

      def calcElement(ownRow: List[Int], objCol: List[Int]): Long = ownRow.zip(objCol).map(e => e._1.toLong * e._2.toLong).sum
    }
  }
}

Measured memory_bytes: 188528
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,l;
    cin>>n>>l;
    int sum=0;
    int pie[n+1];
    int m1,m2;
    for(int i=1;i<=n;i++){
        pie[i]=l+i-1;
        sum+=pie[i];
    }
    for(int i=1;i<=n;i++){
        if(i==1){
            m2=sum-pie[i];
            m1=abs(pie[i]);
            //cout<<m2<<endl;
        }
        else{
            if(abs(pie[i])<m1){
            m2=sum-pie[i];
            m1=abs(pie[i]);
           // cout<<m2<<endl;
            }
        }
    }
    cout<<m2<<endl;
}


Measured memory_bytes: 256
n, k, q = list(map(int, input().split()))
a = [int(input()) for i in range(q)]
p = [k-q]*n

for i in range(q):
    p[a[i]-1] += 1
    
for n in p:
  if n>0:
    print("Yes")
  else:
    print("No")


Measured memory_bytes: 55896
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <functional>
#include <utility>
#include <queue>
#include <vector>
#include <string>
#include <stack>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
const ll  MOD = 1000000007;
typedef pair<ll,ll> P;

ll N,A,B;
ll x[100100];
int main(){
  cin >> N >> A >> B;
  rep(i,N){
    cin >> x[i];
  }
  ll pos = x[0];
  ll ans = 0;
  rep(i,N-1){
    ans += min(B,(x[i+1] - pos)*A);
    pos = x[i+1];
  }
  cout << ans << endl;

}


Measured memory_bytes: 1024
import java.util.*;

class Main{

    static final int DIV = 100000007;
    static final int MAX = 2000000000;

    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int [] ary = new int[n];
        for(int i = 0;i<n;i++)ary[i] = sc.nextInt();
        sc.close();
        long ans = MAX;
        for(int i = 0;i < n-k+1;i++){
            int a = ary[i];
            int b = ary[k+i-1];
            long sub = a-b;
            if(sub<0)sub *= -1;
            if(a<0)a*=-1;
            if(b<0)b*=-1;
            long tmp = sub+(a<b?a:b);
            if(tmp<ans)ans=tmp;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 51040
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(10000000)

P = [0.0 for i in range(110000)]
ans = [0.0 for i in range(110000)]
for i in range(100020):
    p = 1.0 - P[i]
    mul = 1.0
    for j in range(1, 11):
        P[i + j] += p * mul
        for k in range(j):
            mul /= 2
for i in range(1, 100020):
    ans[i] = ans[i - 1] + P[i]

while True:
    n = input()
    if n == 0:
        break
    print ans[n]


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

void insertionSort(int A[], int N){
    for(int i = 0; i< N; i++){
        int v = A[i];
        int j = i - 1;
        while(j >= 0 && A[j] > v){
            A[j + 1] = A[j];
            j--;
        }
        A[j + 1] = v;
        for(int i = 0; i < N - 1; i++){ 
        cout << A[i] << ' ';
    }

    cout << A[N - 1] << endl;
    }
}

int main(){
    int N;
    cin >> N;
    int A[N];

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

    insertionSort(A, N);

    return 0;
}


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

using namespace std;

int main(){
  char input;
  cin >> input;
	
  if(input == 'a' || input == 'i' || input == 'u' || input == 'e' || input == 'o')
    cout << "vowel" << endl;
  else
    cout << "consonant" << endl;
}

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

using namespace std;

int main() {
    int K;
    cin >> K;
    vector<int> nums;
    nums.push_back(1);
    nums.push_back(1);
    nums.push_back(1);
    nums.push_back(2);
    nums.push_back(1);
    nums.push_back(2);
    nums.push_back(1);
    nums.push_back(5);
    nums.push_back(2);
    nums.push_back(2);
    nums.push_back(1);
    nums.push_back(5);
    nums.push_back(1);
    nums.push_back(2);
    nums.push_back(1);
    nums.push_back(14);
    nums.push_back(1);
    nums.push_back(5);
    nums.push_back(1);
    nums.push_back(5);
    nums.push_back(2);
    nums.push_back(2);
    nums.push_back(1);
    nums.push_back(15);
    nums.push_back(2);
    nums.push_back(2);
    nums.push_back(5);
    nums.push_back(4);
    nums.push_back(1);
    nums.push_back(4);
    nums.push_back(1);
    nums.push_back(51);
    for (int i = 0; i<K; ++i){
        if (i+1 == K) {
            cout << nums[i];
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

main() {
    // no, no
    // b, no
    // no, a
    // b, a
    int64_t n;
    cin >> n;

    int64_t count = 0;
    int64_t count_b = 0;
    int64_t count_a = 0;
    bool has_a_only = false;
    bool has_b_only = false;
    for (auto _ : irange(0L, n)) {
        string ss;
        cin >> ss;
        for (auto i : irange(0uL, ss.size() - 1)) {
            if (ss[i] == 'A' && ss[i + 1] == 'B') {
                ++count;
            }
        }

        if (ss[ss.size() - 1] == 'A') {
            ++count_a;
            if (ss[0] != 'B') {
                has_a_only = true;
            }
        }
        if (ss[0] == 'B') {
            ++count_b;
            if (ss[ss.size() - 1] != 'A') {
                has_b_only = true;
            }
        }
    }

    if (!has_a_only && !has_b_only && min(count_a, count_b) > 0) {
        count += min(count_a, count_b)  - 1;
    } else {
        count += min(count_a, count_b);
    }

    cout << count << endl;
}

Measured memory_bytes: 256
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n,m = readInts()
dic = defaultdict(int)
A = set()
for i in range(m):
    a,b = input().split()
    if dic['AC'+a] != 1:
        if b == 'AC':
            dic['AC'] += 1
            dic['AC'+a] = 1
        else:
            dic['WA'] += 1
            dic['WA'+a] += 1
    A.add(a)
for a in A:
    if dic['AC'+a] != 1:
        dic['WA'] -= dic['WA'+a]
print(dic['AC'],dic['WA'])


Measured memory_bytes: 32932
x, k, d = map(int, input().split())
count = abs(x)//d
if count > k:
    if x < 0:
        print(abs(x+k*d))
    else:
        print(abs(x-k*d))
else:
    if x < 0:
        ans1 = x+count*d
    else:
        ans1 = x-count*d
    if ans1 > 0:
        ans2 = ans1-d
    else:
        ans2 = ans1+d
    if (k-count)%2==0:
        print(abs(ans1))
    else:
        print(abs(ans2))

Measured memory_bytes: 9196
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 100000000;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(n); i++)


int main() {
    ll k;
    cin >> k;
    string s;
    cin >> s;
    ll l = s.length();
    string ans = "";
    if (k >= l) ans = s;
    else{
        rep1(i,k){
            ans.push_back(s[i]);
        }
        ans += "...";
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
n,m,q = map(int,input().split())
kouho = [int(i) for i in range(1,m+1)]
kouho_list = [1]*(n+1)
Input = []
for i in range(q):
    tmp = [int(i) for i in input().split()]
    Input.append(tmp)

def rec(N,Min):
    global ans
    if N==1:
        ans =0
    if N==n:
        score = 0
        for i in range(q):
            a,b,c,d = Input[i][0],Input[i][1],Input[i][2],Input[i][3]
            if kouho_list[b-1]-kouho_list[a-1] == c:
                score += d
        ans = max(ans,score)
        return 0
    for i in range(Min,m+1):
        kouho_list[N] = i
        rec(N+1,i)
rec(1,1)
print(ans)

Measured memory_bytes: 9148
h, w = map(int, input().split())
r = [list(input()) for i in range(h)]
new_h = [0] * w
new_r = [new_h for i in range(2*h)]
for i in range(0, 2*h, 2):
  new_r[i] = r[(i+1)//2]
  new_r[i+1] = r[(i+1)//2]
for i in new_r:
  print(*i,sep="", end="\n")

Measured memory_bytes: 4596
#include <bits/stdc++.h>
#define FOR(i,k,n) for(int i=(k);i<(int)(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using ll = int64_t;

int main() {
  string s;
  cin>>s;
  int n = s.size();
  int e = 0, o = 0;
  REP(i,n) {
    if ((s[i] == '0') != ((i % 2) == 0)) {
      ++e;
    } else {
      ++o;
    }
  }
  cout << min(e, o) << endl;
  return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 100000
#define rep(i,n) for(i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int dp[2][55][3005]; 

int main(void) {
  int i,j,k;
  int n,m,s;
  while(1){
    cin>>n>>m>>s;
    if(n==0)break;
    rep(i,2)rep(j,55)rep(k,3005)
      dp[i][j][k]=0;
    dp[0][0][0]=1;

    bool c=false;
    rep(i,m){
      int cnt=0;
      rep(j,n*n+1)rep(k,s+1)if(dp[i%2][j][k]>0){
	//	cout<<i<<" "<<j<<" "<<k<<" "<<dp[i%2][j][k]<<endl;
	(dp[(i+1)%2][j][k]+=dp[i%2][j][k])%=MOD;
	if(k+i+1<=s)
	  (dp[(i+1)%2][j+1][k+i+1]+=dp[i%2][j][k])%=MOD,cnt++;
	dp[i%2][j][k]=0;
      }
      if(c&&cnt==0)break;
      if(cnt==0)c=true;
    }
    cout<<dp[m%2][n*n][s]<<endl;
  }
}





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

int main(void){
    int a,b,c,k;
    cin >> a >> b >> c >> k;
    int sum = 0;
    
    int xa = min(a,k);
    k = k - xa;

    int xb = min(b,k);
    k = k - xb;

    int xc = min(c,k);
    k = k - xc;

    sum  = xa - xc;
    cout << sum << endl;
}

Measured memory_bytes: 3608
#include <iostream>
#include <string>
#include <map>
#include <math.h>
#include <vector>
using namespace std;

int main(){
    int s, w;
    cin >> s >> w;
    if (w >= s) {
        cout << "unsafe" << endl;
    } else {
        cout << "safe" << endl;
    }
    return 0;
}

Measured memory_bytes: 3624
#include<iostream>
using namespace std;
#define MAX 100000

int parent(int i) { return i / 2; }
int left(int i) { return 2 * i; }
int right(int i) { return 2 * i + 1; }

int main() {
  int H, i, A[MAX + 1];

  cin >> H;
  for ( i = 1; i <= H; i++ ) cin >> A[i];

  for ( i = 1; i <= H; i++ ) {
    cout << "node " << i << ": key = " << A[i] << ", ";
    if ( parent(i) >= 1 ) cout << "parent key = " << A[parent(i)] << ", ";
    if ( left(i) <= H ) cout << "left key = " << A[left(i)] << ", ";
    if ( right(i) <= H ) cout << "right key = " << A[right(i)] << ", ";
    cout << endl;
  }

  return 0;
}


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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<double> vd;
typedef vector<vd> vdd;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);

template <typename First>
void debug_print_in(First first){
  cerr << first << endl;
  return;
}

template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}

void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

template <typename First>
void OUT(First first){
  cout << first << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template<class t, class u> void chmax(t&a,u b){if(a<b)a=b;};
template<class t, class u> void chmin(t&a,u b){if(a>b)a=b;};
int popcount(int t){return __builtin_popcount(t);} //GCC
int popcount(ll t){return __builtin_popcountll(t);} //GCC

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i,MAT.size()){
    REP(j,MAT[i].size()){
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll K;
  IN(K);
  string S;
  IN(S);

  if(S.size()<=K){
    OUT(S);
  }else{
    string S_ans = "";
    REP(i,K) S_ans += S[i];
    S_ans += "...";

    OUT(S_ans);

  }

  return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, b, n) for (int i = b; i < n; ++i)

using namespace std;
using ll = long long;

void solve(long N, vector<long> A, vector<long> B) {
  ll ans = 0;
  REP(i, N) {
    const long j = N - i - 1;
    const long ext = (A[j] + ans) % B[j];
    if (ext)
      ans += B[j] - ext;
  }
  cout << ans << endl;
  
}

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

  long N;
  cin >> N;

  vector<long> A(N);
  vector<long> B(N);
  REP(i, N)
    cin >> A[i] >> B[i];

  solve(N, move(A), move(B));

  return 0;
}


Measured memory_bytes: 1792
#include <algorithm>
#include <array>
#include <cassert>
#include <iostream>
#include <sstream>
#include <string>
#include <tuple>
#include <vector>
// #include <queue>
// #include <map>

using namespace std;

namespace atcoder {
namespace {

pair<float, int> solve(istream& in)
{
  long long W, H, x, y;
  in >> W >> H >> x >> y;
  assert(0 < W && 0 < H);
  return make_pair(0.5 * W * H, (W == 2 * x && H == 2 * y) ? 1 : 0);
}

[[gnu::unused]] void test()
{
  {
    constexpr auto str = R"(
2 3 1 2
)";
    stringstream in{str};
    const auto ans = solve(in);
    assert(ans.first == 3.0000);
    assert(ans.second == 0);
  }

  {
    constexpr auto str = R"(
2 2 1 1
)";
    stringstream in{str};
    const auto ans = solve(in);
    assert(ans.first == 2.0000);
    assert(ans.second == 1);
  }
  {
    constexpr auto str = R"(
2 2 0 0
)";
    stringstream in{str};
    const auto ans = solve(in);
    assert(ans.first == 2.0000);
    assert(ans.second == 0);
  }
  {
    constexpr auto str = R"(
2 2 2 2
)";
    stringstream in{str};
    const auto ans = solve(in);
    assert(ans.first == 2.0000);
    assert(ans.second == 0);
  }
  {
    constexpr auto str = R"(
2 3 0 0
)";
    stringstream in{str};
    const auto ans = solve(in);
    assert(ans.first == 3.0000);
    assert(ans.second == 0);
  }
}

} // namespace
} // namespace atcoder

////////////////////////////////////////////////////////////////
int main()
{
  using namespace atcoder;
  // test();
  const auto ans = solve(cin);
  cout << ans.first << ' ' << ans.second << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

void printVector(int n, vector<int> &a)
{
    for (int i = 0; i < n - 1; i++)
    {
        cout << a[i] << ' ';
    }
    cout << a[n - 1] << endl;
}

void insertionSort(vector<int> &a, int n)
{
    for (int i = 1; i < n; ++i)
    {
        int v = a[i];
        int j = i - 1;
        while (j >= 0 && a[j] > v)
        {
            a[j + 1] = a[j];
            j--;
        }
        a[j + 1] = v;
        printVector(n, a);
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++)
        cin >> A[i];
    printVector(N, A);
    insertionSort(A, N);
    return 0;
}


Measured memory_bytes: 3136
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
  ll n;
  cin >> n;
  vl x(n),l(n);
  rep(i,n){
    cin >> x[i] >> l[i];
  }
  vector<P> p(n);
  rep(i,n){
    p[i].first=x[i]+l[i];
    p[i].second=x[i]-l[i];
  }
  sort(p.begin(),p.end());
  ll cnt=1,i=0;
  ll r=p[i].first;
  while(i<n){
    if(r>p[i].second){
      i++;
    }
    else{
      r=p[i].first;
      cnt++;
      i++;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;

ll factmod(ll a,ll b,ll m) {
  if(a<b)return 0;
  ll s=1;
  while(a>=b){
    s = s*a % m;
    a -= 1;
  }
  return s;
}

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


ll modinv(ll a, ll m) {
  if(gcd(a,m)!=1)return 0;
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

ll combmod(ll a,ll b,ll m){
  if(b==0)return 1;
  ll c=factmod(a,a-b+1,m);
  ll d=modinv(factmod(b,1,m),m);
  ll e=(c*d)%m;
  return e;
}

int main(){

  ll n,m;
  cin >> n >> m;

  ll s=0;
  ll c[n+1]={};
  
  ll a=factmod(m,m-n+1,mod)*factmod(m,m-n+1,mod);
  a%=mod;
  s+=a;

  //cout << a << endl;

  for(int i=0;i<n;i++){
    a*=(n-i);
    a%=mod;
    a*=modinv(i+1,mod);
    a%=mod;
    a*=(m-i);
    a%=mod;
    a*=modinv(m-i,mod);
    a%=mod;
    a*=modinv(m-i,mod);
    a%=mod;
    a*=-1;
    s+=a;
    s+mod;
    s%=mod;
    //cout << a << endl;
  }
  s+=mod;
  s%=mod;
  cout << s << endl;

  
}

Measured memory_bytes: 7488
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define INF 10e16
#define MOD 1000000007
#define  mod 998244353
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[8]={-1,0,1,0};
int dy[8]={0,-1,0,1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//--------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????        memset()!!!!!!!!!!!!       ペナを減らせ!!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    int a,b,c;cin>>a>>b>>c;
    int k;cin>>k;
    int ans=0;
    int t=max(a,max(b,c));
    while(k--)
        t*=2;
    cout<<t+a+b+c-max(a,max(b,c))<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------






Measured memory_bytes: 256
def readinput():
    n=int(input())
    a=list(map(int,input().split()))
    return n,a

def countingSort(n,a,k):
    c=[0]*(k+1)
    for i in range(n):
        c[a[i]]+=1
    for i in range(1,k+1):
        c[i]=c[i]+c[i-1]
    b=[0]*n
    for j in range(n-1,-1,-1):
        b[c[a[j]]-1]=a[j]
        c[a[j]]-=1
    return b

def main(n,a):
    b=countingSort(n,a,10000)
    return b 
    
if __name__=='__main__':
    n,a=readinput()
    ans=main(n,a)
    print(' '.join(map(str,ans)))



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

int main(){
    int n;   cin >> n;
    map<ll, ll> d;
    ll x;  
        for(int i=0; i<n; i++){
            cin >> x;
            d[x] += 1;
        }
    int m;  cin >> m;
    string ans="YES";
        for(int i=0; i<m; i++){
            cin >> x;
            if(d[x]<1){
                ans = "NO";
                break;
            }
            d[x] -= 1;
        }
    cout << ans << endl;
}


Measured memory_bytes: 12800
//given n integers and an integer m such that n>m then there exits a pair
//(a-b) such that (a-b)%m==0


#include<bits/stdc++.h>
using namespace std;
typedef  long long int ll;
const ll M=1000000007;
void solve(){
string s;
cin>>s;
ll ans=0;
for(int i=0;i<s.size();i++){
    ans+=(s[i]-'0');
}
if(ans%9==0)cout<<"Yes";
else cout<<"No";
}

int main(){
 int t=1;
 //cin>>t;
 while(t--){
        solve();
        cout<<endl;
 }
}


Measured memory_bytes: 3712
package main

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

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

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

	h := make([]int, n)
	for i := 0; i < n; i++ {
		scanner.Scan()
		h[i], _ = strconv.Atoi(scanner.Text())
	}

	var max int
	for i := 0; i < n; i++ {
		if h[i]+1 < max {
			fmt.Println("No")
			return
		}

		if h[i] > max {
			max = h[i]
		}
	}

	fmt.Println("Yes")
}


Measured memory_bytes: 3072
#include <iostream>
#include <vector>

using namespace std;

bool comp(pair<int,int> a, pair<int, int> b ){
  return a.first < b.first;
}

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

  vector<pair<int, int> > ct(n);
  for(int i=0; i<n; i++){
    int c, t;
    std::cin >> c >> t;
    ct[i] = make_pair( c, t );
  }

  sort(ct.begin(), ct.end(), comp);

  for(int i=0; i<n; i++){
    if( t >= ct[i].second ){
      std::cout << ct[i].first << '\n';
      return 0;
    }
  }
  std::cout << "TLE" << '\n';

  return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
int dp[1000000]={999999};
int h[1000005];


int main()
{
    int n,k;
    cin>>n>>k;
    for(int i=0;i<n;i++)
        cin>>h[i];

    dp[0]=0;

    for(int i=1;i<n;i++)
    {
        dp[i] = dp[i - 1] + abs(h[i] - h[i - 1]);

        for(int j=1;i-j>=0 and j<=k;j++)
        dp[i]= min( dp[i], dp[i-j]+abs(h[i]-h[i-j]));
    }
    cout<<dp[n-1];
}



Measured memory_bytes: 2816
// 20
/****************************************************
https://searleser97.gitlab.io/algorithms/template.cpp
****************************************************/

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define forr(_, x, n) for (int _ = x; _ > n; _--)
#define fos(_, x, n, s) for (int _ = x; _ < n; _ += s)
#define forn(_, x, n) fos(_, x, n, 1)
#define rep(_, n) forn(_, 0, n)
#define fi first
#define se second
#define pb push_back
#define pairii pair<int, int>
#define all(x) x.begin(), x.end()
#define cerr(s) cerr << "\033[48;5;196m\033[38;5;15m" << s << "\033[0m"
// typedef __int128_t lli;
typedef long long int li;
typedef long double ld;
// 12
void _main(int tc) {
  int n, k;
  cin >> n >> k;
  vector<bool> s(10);
  rep(i, k) {
    int x;
    cin >> x;
    s[x] = 1;
  }

  forn(i, n, (int) 1e6) {
    string str = to_string(i);
    bool flag = 0;
    for (auto& c : str) {
      if (s[c - '0']) {
        flag = 1;
        break;
      }
    }
    if (!flag) {
      cout << i << endl;
      return;
    }
  }
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  _main(0); return 0;
  int tc;
  cin >> tc;
  rep(i, tc) _main(i + 1);
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    abc097c()
}

fun abc097c() {
    val s = readLine()!!
    val k = readLine()!!.toInt()

    val set = mutableSetOf<String>()
    for (i in s.indices) {
        var count = 0
        for (j in i + 1..s.length) {
            if (count >= k) break
            set.add(s.substring(i, j))
            count++
        }
    }

    println(set.sorted()[k - 1])
}


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

using namespace std;

const double PI = 3.141592653589;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define int long long
#define all(c) (c).begin(),(c).end()
#define M 1000000007
#define INF LLONG_MAX
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ", "; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}
// Use pr(a,b,c,d,e) or cerr<<anything or prc(v.begin(),v.end()) or prc(v,v+n)
//  
int h, w;
char maze[20][20];
int ans[20][20];
int dx[] = {0, 1, -1, 0};
int dy[] = {1, 0, 0, -1};
void init()
{
    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
        {
            ans[i][j] = M;
        }
    }
}
bool valid(int x, int y)
{
    return (x >= 0 && x < h && y >=0 && y < w);
}

void f(int x, int y)
{
    for(int i=0;i<4;i++)
    {
        int xx = x + dx[i], yy = y + dy[i];
        if(valid(xx, yy))
        {
            if(maze[xx][yy] == '#') continue;
            else if(ans[xx][yy] > ans[x][y] + 1)
            {
                ans[xx][yy] = ans[x][y] + 1;
                f(xx, yy);
            }
        }
    }
}
int mx()
{
    int ret = 0;
    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
        {
            if(ans[i][j] < M) ret = max(ret, ans[i][j]);
        }
    }
    return ret;
}
    

int32_t main()
{
    fastio;
    //freopen("file.in", "r", stdin);
    //freopen("file.out", "w", stdout);
    cin >> h >> w;
    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
        {
            cin >> maze[i][j];
        }
    }
    int ret = 0;
    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
        {
            if(maze[i][j] == '#') continue;
            init();
            ans[i][j] = 0;
            f(i, j);
            ret = max(ret, mx());
        }
    }
    cout << ret << "\n";

    

    return 0;
}



Measured memory_bytes: 256
io = STDIN
n,k=io.gets.split.map(&:to_i)
def pw(i,k)
  cnt=0
  while i < k
    i*=2
    cnt+=1
  end
  cnt
end
ans=(1..n).inject(0) do |s,i|
  pw=pw(i,k)
  (1/2.0)**pw*1/n.to_f + s
end
puts ans


Measured memory_bytes: 1788
#include<algorithm>
#include<cassert>
#include<climits>
#include<cmath>
#include<cstring>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << endl

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-8;

const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

template<typename T>
bool chmax(T& a, T b, bool equal = false){
    if(a < b || equal && a == b){
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool chmin(T& a, T b, bool equal = false){
    if(b < a || equal && a == b){
        a = b;
        return true;
    }
    return false;
}

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

    vector< vector<int> > a(n);
    rep(i, n){
        a[i].resize(n - 1);
        rep(j, n - 1){
            cin >> a[i][j];
            --a[i][j];
        }
    }

    vector<int> deg(n * n + 2, 0);
    vector< vector<int> > g(n * n + 2);
    rep(i, n * n){
        g[n * n].emplace_back(i);
        ++deg[i];
        g[i].emplace_back(n * n + 1);
        ++deg[n * n + 1];
    }

    rep(i, n){
        rep(j, n - 2){
            int from = min(i, a[i][j]) * n + max(i, a[i][j]);
            int to = min(i, a[i][j + 1]) * n + max(i, a[i][j + 1]);
            g[from].emplace_back(to);
            ++deg[to];
        }
    }

    stack<int> st;
    rep(i, n * n + 2){
        if(deg[i] == 0){
            st.push(i);
        }
    }

    vector<int> dag;
    while(!st.empty()){
        int v = st.top();
        st.pop();
        dag.emplace_back(v);
        for(auto to : g[v]){
            --deg[to];
            if(deg[to] == 0){
                st.push(to);
            }
        }
    }

    if((int)dag.size() != n * n + 2){
        return -1;
    }

    vector<int> dp(n * n + 2, -IINF);
    dp[n * n] = 0;
    vector<bool> visited(n * n + 2, false);

    rep(i, n * n + 2){
        int v = dag[i];
        visited[v] = true;
        for(auto to : g[v]){
            if(visited[to]){
                return -1;
            }
            chmax(dp[to], dp[v] + 1);
        }
    }

    return dp[n * n + 1] - 1;
}

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

    int ans = solve();
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 76532
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1
sys.setrecursionlimit(10**6)
n,U,V = map(int,input().split())
U-=1;V-=1
G = [[] for i in range(n)]
for i in range(n-1):
  a,b = map(int,input().split())
  a-=1;b-=1
  G[a].append(b)
  G[b].append(a)
Aokidis = [0]*n
Takahashidis = [0]*n
def dfs(node,dis,TorA,pre):
  if TorA == "Takahashi":Takahashidis[node] = dis
  else:Aokidis[node] = dis
  for vi in G[node]:
    if vi == pre:continue
    dfs(vi,dis+1,TorA,node)
dfs(U,0,"Takahashi",-1)
dfs(V,0,"",-1)
for i in range(n):
  if Takahashidis[i] <= Aokidis[i]:
    ans = max(ans,Aokidis[i]-1)
print(ans)

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

int main(){
	string s;
	cin >> s;
	int N=s.size();
	sort(s.begin(),s.end());
	int cnt=1;
	for(int i=0;i<N-1;i++){
		if(s.at(i)==s.at(i+1)){
			cnt++;
		}
		else if(cnt%2!=0){
			break;
		}
		else{
			cnt=1;
		}
	}
	if(cnt%2){
		cout << "No" << endl;
	}
	else{
		cout << "Yes" << endl;
	}
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	double a, b, c;
	
	scanf("%lf", &a);
	
	c = 1;
	for (b = 1; b <= a; b++) {
		c *= b;
	}
	
	printf("%.0f\n", c);
	
	return (0);
}	

Measured memory_bytes: 648
#ifdef _DEBUG
#define _CRT_SECURE_NO_WARNINGS
#include "MyLib.h"
#else
#define main_A main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define MGN 8
#define LINF (LONG_MAX/2)
using namespace std;
typedef long long ll; typedef unsigned long long ull;
typedef vector<int> vi; typedef vector<vi> vvi; 
typedef vector<ll> vl; typedef vector<vl> vvl;
typedef vector<double> vd; typedef vector<string> vs;
typedef pair<int, int> pii; typedef pair<ll, ll> pll;
typedef vector<bool> vb; typedef vector<vb> vvb;
template <typename T>
using keyVal = pair<string, T>;
template<typename T>
bool val_greater(const keyVal<T>& left, const keyVal<T>& right) {
    return left.second > right.second;}
vs split(string str, char sep) {
    vs v; stringstream ss(str); string t;
    while (getline(ss, t, sep)) v.push_back(t);
    return v;}
vs re_search_g(string s, regex re) {
    vs ret; smatch mc; auto it = s.cbegin();
    while (regex_search(it, s.cend(), mc, re)) {
        ret.push_back(mc[0]);
        it += mc.position(0) + mc.length();}
    return ret;}
#endif

void init_global_A() {}


int main_A() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string S; cin >> S;
    
    int ans = 0;
    for(auto c : S){
        if (c == '1') ans++;
    }

    cout << ans << endl;

    return 0;
}

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

int main() {
    int N, M, A[10010];
    cin >> N >> M;
    for(int i = 0; i < M; i++) cin >> A[i];

    int total = 0;
    for(int i = 0; i < M; i++) {
        total += A[i];
    }

    if(total > N) {
        cout << -1 << endl;
    } else {
        cout << N - total << endl;
    }

    return 0;
}

Measured memory_bytes: 3680
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;

int main(void) {
    int A, B, M;
    cin >> A >> B >> M;
    vector<int> a(A), b(B);
    for(int i=0; i<A; i++) {
        cin >> a[i];
    }
    for(int i=0; i<B; i++) {
        cin >> b[i];
    }

    int ans = *min_element(a.begin(), a.end()) + *min_element(b.begin(), b.end());
    while(M--) {
        int x, y, c;
        cin >> x >> y >> c;
        ans = min(ans, a[--x] + b[--y] - c);
    }

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


Measured memory_bytes: 1024