akhauriyash/Code-Regression huggingface dataset:
# https://atcoder.jp/contests/abc108/tasks/arc102_a
# C - Triangular Relationship
import copy
import itertools
N, K = list(map(int, input().split()))
ab_list = []

# 2 * a = (X + Y - Z) * K
# a = (X + Y - Z) * K / 2
# が成り立つ
# Kが偶数の場合は
# a = T * K または a = T * (1/2)K
# a + b = T * K なので、a, b, cのいずれか１つが a % (1/2)K == 0なら、全てそうである必要がある
# Kが偶数の場合は (1/2)*Kが整数にならないので
# a = T * K

if K % 2 == 0:
    a_list = [x for x in range(1, N + 1) if x % K == 0]
    p = len(a_list) ** 3
    a_list = [x for x in range(1, N + 1) if (x % (0.5 * K)) == 0 and not (x % K == 0)]
    p += len(a_list) ** 3
else:
    a_list = [x for x in range(1, N + 1) if x % K == 0]
    p = len(a_list) ** 3

print(p)


Measured memory_bytes: 11420
from sys import stdin

class QueueNode(object):
	def __init__(self,data,next=None,prev=None):
		self.data = data
		self.next = next
		self.prev = prev

class LinkList(object):
	def __init__(self,head=None):
		self.head = head
		self.tail = head
		self.cur  = head

	def insert_q(self,data):
		node = QueueNode(data)

		if self.cur is None:
			self.head = node
			self.tail = node
			self.cur  = node
			return

		currentNode = self.cur
		preNode = currentNode.prev

		if currentNode.prev is None:
			currentNode.prev = node
			node.next = currentNode
			self.head = self.cur = node
		else:
			if self.tail is not None:
				currentNode.prev = node
				node.prev = preNode
				node.next = currentNode
				preNode.next = node
				self.cur = node
			else:
				currentNode.next = node
				node.prev = currentNode
				node.next = None
				self.cur = node
				self.tail = node


	def move_q(self,mv):
		currentNode = self.cur
		cnt = mv
		while cnt != 0:
			if mv < 0:#prev
				if currentNode.prev is None:
					self.head = self.cur = currentNode
					break
				else:
					currentNode = currentNode.prev
					self.cur = currentNode
					cnt += 1
			else:#next
				if currentNode.next is None:
					self.cur = currentNode
					break
				else:
					currentNode = currentNode.next
					self.cur = currentNode
					cnt -= 1


	#カレントを削除する
	def delete_q(self):
		currentNode = self.cur
		nexNode = currentNode.next
		preNode = currentNode.prev

		#自身の前がいない（=先頭）
		if preNode is None:
			nexNode.prev = None
			self.head = nexNode
			self.cur = nexNode
		#自身の後ろがいない（=末尾）
		elif nexNode is None:
			preNode.next = None
			self.tail = None
		else:
			preNode.next = currentNode.next
			nexNode.prev = currentNode.prev
			self.cur = currentNode.next

	#先頭を表示する
	def print_q(self):
		if self.head is not None:
			print(self.head.data)

	#全体表示（先頭から）
	def print_all(self):
		if self.head is not None:
			currentNode = self.head
			while currentNode.next is not None:
				print(currentNode.data)
				currentNode = currentNode.next

if __name__ == '__main__':

	loopnum = int(input())

	ll = LinkList()
	ll.insert_q("E")
	for i in range(loopnum):
		cmd = stdin.readline().strip().split()
		if cmd[0] == "0":
			t = int(cmd[1])
			ll.insert_q(t)
		elif cmd[0] == "1":
			t = int(cmd[1])
			ll.move_q(t)
		else:
			ll.delete_q()
	ll.print_all() 



Measured memory_bytes: 89096
LI = lambda: list(map(int, input().split()))

X, K, D = LI()


def main():
    x = abs(X)
    a = x // D
    if K <= a:
        ans = x - K * D
        print(ans)
        return
    
    x -= a * D
    k = K - a
    if k % 2 == 0:
        ans = x
    else:
        ans = abs(x - D)
    print(ans)
    
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 9180
module BIT = struct
  let create n v = (n, Array.make (n+1) v)
  let add idx v (l, a) =
    let rec f i =
      if i <= l then begin
        a.(i) <- a.(i) + v;
        f (i + i land (-i))
      end
    in f idx
  let query idx (_, a) = let rec f i v =
      if i = 0 then v
      else f (i - i land (-i)) (v + a.(i))
    in f idx 0
end

let rec upper_bound l r p =
  if l+1 >= r then l else
  let m = (l+r) / 2 in
  if p m then upper_bound m r p else upper_bound l m p

let () =
  Scanf.scanf "%d" @@ fun n ->
  let a = Array.init n (fun _ -> Scanf.scanf " %d" ((+) 0)) in
  let b = Array.init n (fun i -> a.(i)) in
  Array.sort (-) b;
  upper_bound 0 n (fun idx ->
    let v = b.(idx) in
    let c = Array.init (n+1) (fun i ->
      if i = 0 then 0
      else if a.(i-1) >= v then 1 else -1) in
    for i = 1 to n do c.(i) <- c.(i) + c.(i-1) done;

    let bit = BIT.create (2*n+2) 0 in
    let ofs = n+1 in

    let x =
      Array.fold_left (fun s v ->
        let s = s + BIT.query (v+ofs) bit in
        BIT.add (v+ofs) 1 bit; s
      ) 0 c
    in x >= n * (n+1) / 2 / 2
  ) |> fun idx -> Printf.printf "%d\n" b.(idx)

Measured memory_bytes: 21632
#include <algorithm>
#include <cstring>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
using ll = long long;

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

  int a = x / 500;
  int b = (x - a * 500) / 5;

  cout << 1000 * a + 5 * b;
  return 0;
}


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

int main(){
	ll q, ans = 0;cin >> q;
	priority_queue<ll> s;
	priority_queue<ll, vector<ll>, greater<>> l;
	for(ll _ = 0;_ < q;++_){
		ll t;cin >> t;
		if(t == 1){
			ll a, b;cin >> a >> b;
			ans += b;
			s.push(a);
			l.push(a);
			ll x = s.top();s.pop();
			ll y = l.top();l.pop();
			if(x > y){
				ans += x - y;
				swap(x, y);
			}
			s.push(x);
			l.push(y);
		}
		else {
			cout << s.top() << " " << ans << endl;
		}
	}
}


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

int dic[10000000];
char str[12];

void insert();
void find();
int Getkey();
int Getchar(char);

int main(){
  int i, n;
  char infi[7];
  scanf("%d",&n);
  for(i = 0; i < n; i++){
    scanf("%s %s",infi,str);
    if(infi[0] == 'i')
      insert();
    else find();
  }

  return 0;
}

void insert(){
  dic[Getkey()] = 1;
}

void find(){
  if(dic[Getkey()] == 1) printf("yes\n");
  else printf("no\n");
}

int Getkey(){
  int i, sum = 0, t = 1;
  for(i = 0; i < strlen(str); i++){
    sum += t * (Getchar(str[i]));
    t *= 4;
  }
  return sum;
}

int Getchar(char alpha){
  if(alpha == 'A') return 1;
  else if(alpha == 'C') return 2;
  else if(alpha == 'G') return 3;
  else return 4;
}

Measured memory_bytes: 6724
fun main(args: Array<String>) {
    val n = readLine()?.toInt() ?: return
    val a = readLine()?.split(" ")?.map(String::toInt) ?: return
    val counter = hashMapOf<Int, Int>()
    a.forEach { aa ->
        counter[aa]?.let {
            println("NO")
            return
        } ?: run {
            counter[aa] = 1
        }
    }
    println("YES")
}

Measured memory_bytes: 80664
n = int(input())                                                                                                        
seq = [int(x) for x in input().split()]                                                                                 
cur_d = float('inf')                                                                                                    
ans = 0                                                                                                                 
for i in seq:                                                                                                               
  if i < cur_d:
    cur_d = i
    ans += 1
print(ans) 

Measured memory_bytes: 24744
acute, right, obtuse = 0, 0, 0
while True:
    a, b, c = sorted(map(int, input().split()))
    if a + b <= c:
        print(acute + right + obtuse, right, acute, obtuse)
        break
    d = a ** 2 + b ** 2
    e = c ** 2
    if d == e:
        right += 1
    elif d < e:
        obtuse += 1
    else:
        acute += 1


Measured memory_bytes: 5600
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
using namespace std;

#define FOR(i, s, e) for (int i = (s); i <= (e); i++)

int N;

int C[510];
int S[510];
int F[510];

int main()
{
    cin >> N;
    FOR(i, 1, N - 1)
    {
        cin >> C[i] >> S[i] >> F[i];
    }

    FOR(start, 1, N)
    {
        int cost = 0;
        FOR(now, start, N - 1)
        {

            int next;
            if (cost % F[now] == 0)
                next = cost;
            else
                next = cost + F[now] - (cost % F[now]);
            int nextTime = max(S[now],next);


            cost += nextTime - cost;
            cost += C[now];
        }

        cout << cost << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rfor(i, a, b) for(int i = a; i < (int)b; i++)
#define all(ary) (ary).begin(), (ary).end()
#define debug(x) cerr << #x << ": " << x << '\n'
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
using namespace std;
using v = vector<int>;
using ll = long long;
template <class T = int> T in(){ T x; cin >> x; return (x);}

int main(int argc, char *argv[]){
    int a, b, h; cin >> a >> b >> h;
    cout << (a + b) * h / 2 << endl;
    return 0;
}

Measured memory_bytes: 256
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

// Sort
type Val struct {
	id, num int
}
type ByNum []Val

func (a ByNum) Len() int           { return len(a) }
func (a ByNum) Less(i, j int) bool { return a[i].num < a[j].num }
func (a ByNum) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	S := sc.nextStr()
	set := make(map[rune]bool)
	for _, r := range S {
		set[r] = true
	}
	ans := 'a'
	for {
		if !set[ans] {
			break
		}
		ans += 1
	}

	if (ans - 1) == 'z' {
		fmt.Fprintln(wtr, "None")
	} else {
		fmt.Fprintln(wtr, string(ans))
	}
	wtr.Flush()
}


Measured memory_bytes: 1024
#include <stdio.h>
int main(){
	int n,a,b;
	int count;
	scanf("%d%d%d",&n,&a,&b);
	if(n==1){
		if(a==b){
			printf("1\n");
		}
		else{
			printf("0\n");
		}
	}else{
		if(a>b){
			printf("0");
		}else{
			printf("%lld",(long long)(b-a)*(n-2)+1);	
		}
	}
//	if(a>b){
//		printf("0");
//	}
//	else if(a==b&&n==1){
//		printf("1");
//	}
//	else if(n>1&&a<b){
//		int temp=n-1;
//		int p,q;
//		p=a*temp+b;
//		q=b*temp+a;
//		count=q-p+1;b(n-1)+a-a(n-1)-b=b(n-2)+a(2-n)=(b-a)(n-2)
//		printf("%d",count);
//	}
//	else{
//		printf("0");
//	}
	return 0;
}

Measured memory_bytes: 128
#![allow(non_snake_case)]
#![allow(unused_imports)]
use proconio::input;
use std::cmp::max;
use std::cmp::min;
use std::collections::HashMap;
use std::collections::VecDeque;

// a^n (mod m)
fn mod_pow(a: i64, n: u32, m: i64) -> i64 {
    if n == 0 {
        return 1;
    }

    if n == 1 {
        return a % m;
    }

    if n % 2 == 1 {
        let k = mod_pow(a, (n - 1) / 2, m);
        let mut ans = (a * k) % m;
        ans = (ans * k) % m;
        return ans;
    } else {
        let k = mod_pow(a, n / 2, m);
        let ans = (k * k) % m;
        return ans;
    }
}

fn main() {
    input! {
        N: usize,
    }
    const MOD: i64 = 1000_000_000 + 7;

    // 10^N - (1以上,0) - (0,1以上) - (0,0)
    let mut ans: i64 = mod_pow(10, N as u32, MOD);

    let one_zero = mod_pow(9, N as u32, MOD) - mod_pow(8, N as u32, MOD);
    let zero_one = mod_pow(9, N as u32, MOD) - mod_pow(8, N as u32, MOD);
    let zero_zero = mod_pow(8, N as u32, MOD);

    ans = (ans + MOD - one_zero) % MOD;
    ans = (ans + MOD - zero_one) % MOD;
    ans = (ans + MOD - zero_zero) % MOD;

    println!("{}", ans);
}


Measured memory_bytes: 2168
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;



class Main {

	public static void main(String[] args) {
		try {
		BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
		
		while(true) {
			String[] str = buf.readLine().split(" ");
			int a = Integer.parseInt(str[0]);
			int b = Integer.parseInt(str[2]);
			String operator = str[1];
			if(operator.equals("+")) { 
				  System.out.println(a + b);
			 }else if(operator.equals("-")) { 
				  System.out.println(a - b);
			 }else if(operator.equals("*")) { 
				  System.out.println(a * b);
			 }else 	if(operator.equals("/")) { 
				  System.out.println(a / b);
			 }else if(operator.equals("?")) {
				break;			
			 }else {
					return;
				}
			}
		}catch(IOException e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 17028
n=int(input())
a=list(map(int,input().split()))
from collections import Counter
b=[]
c=[]
for i in range(n):
    b.append(i+1+a[i])
    c.append(i+1-a[i])
b=Counter(b)
c=Counter(c)
ans=0
for i,v in b.items():
    ans+=v*c[i]
print(ans)


Measured memory_bytes: 144308
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

const int mod = 1e9+7;

int d;
vector<int> c;
vector<vector<int>> s;

vector<int> argsort(vector<int> v) {
    vector<int> indices(v.size());
    iota(indices.begin(), indices.end(), 0);
    // ソートする。
    sort(indices.begin(), indices.end(), [&v](int i1, int i2) {
        return v[i1] < v[i2];
    });
    return indices;
}

int greedy(int date) {
    vector<int> score(26, 0);
    rep (i, 26) {
        score[i] = s[date][i];
    }
    vector<int> indices = argsort(score);
    return indices[0];
}

int main() {
    cin >> d;
    c.resize(26);
    rep (i, c.size()) {
        scanf("%d", &c[i]);
    }
    s.resize(d, vector<int>(26));
    rep (i, d) {
        rep (j, c.size()) {
            cin >> s[i][j];
        }
    }
    rep (i, d) {
        cout << greedy(i) + 1 << endl;
    }
}




Measured memory_bytes: 3744
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
// using namespace __gnu_pbds;
#define lli long long int
#define llu unsigned long long int
#define fr(va, beg, end) for (lli va = beg; va < end; va++)
#define pb push_back
#define rt return 0
#define endln "\n"
#define all(x) x.begin(), x.end()
#define sz(x) (lli)(x.size())
const lli MOD = 1e9 + 7;
// cout << fixed << setprecision(0) << pi <<endl;
// typedef tree<int, null_type, less<int>, rb_tree_tag,
//              tree_order_statistics_node_update>
//     new_data_set;
// for multiset
// typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
//              tree_order_statistics_node_update>
//     new_data_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)

void solve() {
    lli n, a, k;
    cin >> n >> k;
    vector<lli> v;
    for (lli i = 0; i < n; i++) {
        cin >> a;
        v.pb(a);
    }

    vector<lli> vis(n + 2, 0), tm(n + 2, 0);
    lli cur = 1, cnt = 0;
    lli beg = 1;

    vis[1] = 1;
    tm[1] = 0;
    lli flag = 0;

    while (1) {
        cur = v[cur - 1];
        if (vis[cur] == 1) {
            flag = 1;
            break;
        }
        tm[cur] = beg;
        vis[cur] = 1;
        beg++;
        cnt++;
        if (cnt == k) {
            cout << cur << endl;
            return;
        }
    }

    if (flag == 1) {
        lli len = beg - tm[cur];
        k -= cnt;
        k--;
        k = k % len;
        while (k--) {
            cur = v[cur - 1];
        }
        cout << cur << endl;
    }
}

int main(void) {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    // lli t; cin >> t; while(t--)
    solve();
    rt;
}

Measured memory_bytes: 7960
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  string s;
  cin >> s;
  bool ok = false;
  if(s[0]==s[1] && s[1]==s[2]) ok = true;
  if(s[1]==s[2] && s[2]==s[3]) ok = true;
  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

if s[0] == 'R':
    left_happy = 1
else:
    left_happy = 0
if s[-1] == 'L':
    right_happy = 1
else:
    right_happy = 0
edge_happy = left_happy + right_happy

renzoku = 0
original_happy = 0
before = 0
unhappy = 0
for i in range(n):
    now = s[i]
    if before == now:
        renzoku += 1
    else:
        original_happy += renzoku
        renzoku = 0
    if before == 'R' and now == 'L':
        unhappy += 1
    before = now
original_happy += renzoku

if edge_happy == 0:
    if k <= unhappy:
        print(original_happy + k*2)
    else:
        print(original_happy + unhappy*2 + 1)
elif edge_happy == 1:
    if k <= unhappy:
        print(original_happy + k*2)
    else:
        print(original_happy + unhappy*2)
else:
    if k < unhappy:
        print(original_happy + k*2)
    else:
        print(original_happy + unhappy*2 - 1)

Measured memory_bytes: 3316
n,m,c=map(int,input().split())
b=list(map(int, input().split()))
a=[list(map(int,input().split())) for _ in range(n)]

cnt=0
for i in range(n):
    cal=c
    for j in range(m):
        cal += a[i][j]*b[j]
    if cal>0:
        cnt+=1
    

print(cnt)


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <set>
#include <numeric>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cstring>
#include <queue>
#include <numeric>
#include <iomanip>
#define ll long long
using namespace std;
const int MAXN = 300005;
vector<int> tree[MAXN];
int in[MAXN];
int ans = 0;
int dp[MAXN];
int dfs(int here,int dad){
    int ccn = 0;
    for(int i=0;i<tree[here].size();i++){
        int there = tree[here][i];
        if(there == dad) continue;
        dfs(there,here);
        dp[here] += dp[there];
        ccn += (dp[there] > 0);
    }
    if(dad == -1){
        if(in[here]-1 > ccn){
            dp[here] += ((in[here]-1)-ccn);
        }
    }
    else{
        if(in[here]-2 > ccn){
            dp[here] += ((in[here]-2)-ccn);
        }
    }
    return 0;
}
int main(){
    ios::sync_with_stdio(false); cin.tie(0);
    int n;  cin>>n;
    int lim = 0;
    int root = 0;
    for(int i=1;i<=n-1;i++){
        int u,v; cin>>u>>v;
        tree[u].push_back(v);
        tree[v].push_back(u);
        in[u]++; in[v]++;
        lim = max(lim,in[u]);
        lim = max(lim,in[v]);
    }
    for(int i=1;i<=n-1;i++){
        if(in[i] >=3) root = i;
    }
    if(in[root]<=2){
        cout<<1; exit(0);
    }
    dfs(root,-1);
    cout<<max({1,dp[root]});
    
    return 0;
}


Measured memory_bytes: 15872
#include<cmath>
#include<iostream>
#define f(x) x*x
using namespace std;
int main(){
  int d,sum; // 面積
  while(cin >> d){
    sum = 0;
    for(int i=d;i<600;i+=d){
      sum += (f(i) * d);
    }
    cout << sum << endl;
  }
}

Measured memory_bytes: 1160
N = int(input())
len = list(map(int, input().split()))

# 定理 : 一番長い辺が他の N−1 辺の長さの合計よりも真に短い場合に限り、条件を満たすN角形が描ける。
# 条件を満たすN角形が描けるなら Yes、そうでないなら No を出力せよ。

short_len = sum(len) - max(len)
result = 'Yes' if short_len > max(len) else 'No'
print(result)

Measured memory_bytes: 9156
#include<stdio.h>
int main()
{
    int i,j,s=0,k=0,n,x,y;
    scanf("%d", &n);
    int a[n+5];
    for(i=0;i<n;i++)
    {
        scanf("%d", &a[i]);
        if(a[i]>k)
            k=a[i];
        s=s+a[i];
    }
    s=s-k;
    if(s>k)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}

Measured memory_bytes: 1628
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    string s,t; cin >> s >> t;
    sort(s.begin(),s.end());
    sort(t.rbegin(),t.rend());
    if(s < t) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


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 re
#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())
X = I()
lcm = 360 * X // gcd(360,X)
print(lcm//X)


Measured memory_bytes: 10540
n,m,k=map(int,input().split())
mod=998244353
ans=0

#-------------------------------------------------------------------
MAX_N = 10**6

fact = [1]
fact_inv = [0]*(MAX_N+4)
for i in range(MAX_N+3):
  fact.append(fact[-1]*(i+1)%mod)

fact_inv[-1] = pow(fact[-1],mod-2,mod)
for i in range(MAX_N+2,-1,-1):
  fact_inv[i] = fact_inv[i+1]*(i+1)%mod

def mod_comb_k(n,k,mod):
  return fact[n] * fact_inv[k] % mod * fact_inv[n-k] %mod 
#-------------------------------------------------------------------

for x in range(0,k+1):
  ans+=m*pow(m-1,n-1-x,mod)*mod_comb_k(n-1,x,mod)
  ans%=mod
if ans<0:
  ans+=mod
print(ans)

Measured memory_bytes: 88176
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
int main()
{
    priority_queue < pii , vector<pii> , greater <pii> > a;
    int V, E;
    cin >> V >> E;
    vector <pii> vec[V];
    int mar[V],dis[V];
    for(int i=0;i<E;i++)
    {
        int u,v,d;
        cin >> u >> v >> d;
        vec[u].push_back(make_pair(v,d));
        vec[v].push_back(make_pair(u,d));
    }
    for(int i=0;i<V;i++)
    {
        mar[i]=0;
        dis[i]=INT_MAX;
    }
    dis[0]=0;
    a.push(make_pair(0,0));
    int sum=0;
    for(;!a.empty();)
    {
        pii t=a.top();
        a.pop();
        if(mar[t.second]==0)
        {
            for(int i=0;i<vec[t.second].size();i++)
            {
                if(dis[vec[t.second][i].first]>vec[t.second][i].second)
                {
                    dis[vec[t.second][i].first]=vec[t.second][i].second;
                    a.push(make_pair(dis[vec[t.second][i].first],vec[t.second][i].first));
                }
            }
            mar[t.second]=1;
            sum+=dis[t.second];
        }
    }
    cout << sum << endl;
}



Measured memory_bytes: 6236
// #include C/C++ {
#include <bits/stdc++.h>
// }
using namespace std;
// #typedef {
typedef long long int64;
typedef pair <int, int> PII;
typedef pair <int64, int64> PLL;
// }

// #parameter{
#ifdef _DEBUG

#define TYPE decltype
#define RF(filename) {freopen((filename), "r", stdin);}
#define WF(filename) {freopen((filename), "w", stdout);}
#define DF(filename) {freopen((filename), "w", stderr);}
#define eprintf printf

#else

#define TYPE __typeof
#define RF(filename) {;}
#define WF(filename) {;}
#define DF(filename) {;}
#define eprintf(...)
#define fprintf(...)

#endif

// #define {
#define SZ(a) ((int)(a).size())
#define X first
#define Y second
#define MP make_pair
#define L(x) ((x)<<1)
#define R(x) ((x)<<1 | 1)
#define max3(x, y, z) (max(max((x), (y)), (z)))
#define min3(x, y, z) (min(min((x), (y)), (z)))
#define BIT(x, i) (((x) >> (i)) & 1)
#define ALL(it) (it).begin(), (it).end()
#define FILL(__space, __val) memset(__space, __val, sizeof(__space))
#define MOVE(__spaceTo, __spaceFrom) memmove(__spaceTo, __spaceFrom, sizeof(__spaceTo))
#define UNIQUE(__vector) sort(ALL(__vector)), __vector.resize(unique(ALL(__vector)) - __vector.begin())
#define FOR(it, c) for( TYPE((c).begin()) it = (c).begin(); it != (c).end(); it++)
/////////////////////////////////////////////////////////////
const double PI = acos(-1.0);
const double EPS = 1e-6;

#define MAX_N 55
#define MAX_M 55
#define MOD (int)(1e9+7)
#define INF ((1 << 30) - 1)
#define BINF ((1LL << 62) - 1LL)
#define NONE -1
#define NIL 0
// }

/////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////
int main() {
	RF("input.txt");
	// WF("output.txt");
	DF("err.txt");
	
	int N;
	scanf("%d", &N);
	int res = 0;
	for (int base = 1; base <= N; base *= 100) {
		int upper_limit = min(N, base * 10 - 1);
		res += upper_limit - base + 1;
	}
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 256
import math
a, b, h, m = map(float, input().split())
mm = (m % 60.0) * 6.0
hh = h * 30.0 + m * 0.5

rad = (mm - hh) * math.pi / 180.0
c = math.sqrt(math.pow(a, 2) + math.pow(b, 2) - 2 * a * b * math.cos(rad))

print(c)


Measured memory_bytes: 9436
fun main(args: Array<String>){
    val fare : IntArray = IntArray(4)
    //val fare1: Array<Int> = arrayOfNulls(3)
    //if(fare != null)
    for(i in fare.indices){
        //fare[i] = Integer.parseInt(readLine()!!)
        fare[i] = readLine()!!.toInt()
    }
    val bus = if(fare[0] >= fare[1]) fare[1] else fare[0]
    val train = if(fare[2] >= fare[3]) fare[3] else fare[2]
    val sum = bus + train
    println(sum)
}


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

        using namespace std;

        #define pb push_back
        #define mp make_pair
        #define fr first
        #define sc second

        typedef long long int lli;

        lli n, m, a, b;
        string ans = "";

        int main(){
            cin>>a>>b;
            if(a < b){
                while(b--)
                    ans += to_string(a);
                cout<<ans<<endl;
            }
            else if(a > b){
                while(a--)
                    ans += to_string(b);
                cout<<ans<<endl;
            }
            else{
                while(a--)
                    ans += to_string(b);
                cout<<ans<<endl;
            }
            return 0;
        }


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

#define ll long long
#define db double
#define f first
#define s second
const int mod=1e9+7;

int main()
{
    int n,a;
    cin>>n>>a;;
    int m=n/500;
    int t=n-m*500;
    if(a>=t)puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
void debug() {cout<<endl;}
template<typename T,typename... Args>
void debug(T x,Args... args) {cout<<x<<" ";debug(args...);}
#define forn(i,a,b) for(int i=a;i<b;++i)
#define SZ(x) int(x.size())
#define pb push_back
#define F first
#define S second
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    ll ans = 0, x = 1e8;
    while (n--) {
        string a, b;
        cin >> a >> b;
        if (b == "JPY") {
            ans += stoll(a)*x;
        } else {
            ll i = stoll(a.substr(0, SZ(a)-9));
            ll j = stoll(a.substr(SZ(a)-8));
            ans += (i*x+j)*380000.0;
        }
    }
    cout << fixed << setprecision(6) << double(ans)/x << endl;
}

Measured memory_bytes: 3684
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <bits/stdc++.h>
using namespace std;
using i32 = int; using i64 = long long int; using f64 = double; using str = string;
template <typename T> using vec = vector<T>;
template <typename T> using heap = priority_queue<T, vec<T>, greater<T>>;
#define times(n, i) for (i32 i = 0; i < (n); ++i)
#define range(a, b, i) for (i32 i = (a); i < (b); ++i)
#define upto(a, b, i) for (i32 i = (a); i <= (b); ++i)
#define downto(a, b, i) for (i32 i = (a); i >= (b); --i)
#define all(xs) (xs).begin(), (xs).end()
#define sortall(xs) sort(all(xs))
#define reverseall(xs) reverse(all(xs))
#define uniqueall(xs) (xs).erase(unique(all(xs)), (xs).end())
#define even(x) (((x) & 1) == 0)
#define odd(x) (((x) & 1) == 1)
#define append emplace_back
const i64 MOD = 1000000007;

i32 n, c, k;
vec<i32> t;

i32 main()
{
    cin >> n >> c >> k;
    t.resize(n);
    times(n, i) {
        cin >> t[i];
    }
    sortall(t); reverseall(t);
    i32 ans = 0;
    while (t.size()) {
        i32 t0 = *(--t.end());
        i32 cnt = 0;
        while (cnt < c && t.size() && *(--t.end()) <= t0+k) {
            t.pop_back();
            cnt++;
        }

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

Measured memory_bytes: 640
import java.util.Scanner;

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

        int check = 999999;
        int sum = 0;

        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int l = Integer.parseInt(sc.next());

        for (int i = 0 ; i < n ; i ++) {
            if (Math.abs(l + i) < Math.abs(check)) {
                check = l + i;
            }
            sum += l + i;
        }
        sum -= check;
        System.out.print(sum);

    }
}


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

int main(){
  	long N, K, ans=0;
  	cin >> N >> K;
  	vector<long> H(N);
  	
  	for(int i=0; i<N; i++){
    	cin >> H[i];	
    }
  	
  	sort(H.begin(), H.end());
  	
  	for(int i=0; i<N-K; i++){
    	ans+=H[i];
    }
  
  	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#define _USE_MATH_DEFINES
#include<iostream>
#include<sstream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<unordered_map>
#include<math.h>
#include<iterator>

using namespace std;

int main(){

  string s;
  cin >> s;
  int count=0;
  int del =0;
  for(int i=0;i<s.length();i++){
    if(s[i]=='T'){
      if(count >0 ){
        count--;
        del+=2;
      }
    }else{
      count ++;
    }
  }
  cout << s.length()-del <<endl;
  return 0;

}


Measured memory_bytes: 640
n = int(input())
A = [int(x) for x in input().split()]


def f(isPlus):
    sum = 0
    ret = 0
    for a in A:
        sum += a
        if isPlus:
            if sum <= 0:
                ret += abs(sum) + 1
                sum = 1
        else:
            if sum >= 0:
                ret += abs(sum) + 1
                sum = -1

        isPlus = not isPlus
    return ret


a1 = f(True)
a2 = f(False)
print(min(a1, a2))


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

int main() {
  int n;

  cin >> n;

  vector<int> h(n,0);
  vector<int> dp(n,0);

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

  dp[1]=abs(h[0]-h[1]);

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

  // for(int i=0;i<n;i++) {
  //   cout << dp[i] << endl;
  // }


  cout << dp[n-1] << endl;

  return 0;
}


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

int cat(int a, int b) {
	return b == 0 ? a : cat(a, b / 10) * 10 + b % 10;
}

int main() {
	int a, b, n, x, yes;

	scanf("%d%d", &a, &b);
	n = cat(a, b);
	yes = 0;
	for (x = 1; x <= sqrt(n); x++)
		if (x * x == n) {
			printf("Yes\n");
			return 0;
		}
	printf("No\n");
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll n,h1[100005],h[100005];
    cin>>n;
    for(int i=1;i<=n;i++)cin>>h[i];
    memset(h1,0,sizeof(h1));
    h1[0]=h1[1]=0;
    h1[2]=abs(h[1]-h[2]);
    for(int i=3;i<=n;i++)
    {
        if(((abs(h[i-1]-h[i])+h1[i-1])>
            (abs(h[i-2]-h[i])+h1[i-2])))
            h1[i]+=abs(h[i-2]-h[i])+h1[i-2];
        else h1[i]+=abs(h[i-1]-h[i])+h1[i-1];
    }
    cout<<h1[n]<<"\n";
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

const ll INF = 1e12;
ll dp[2005][2005];

int main() {
    // 貪欲ではダメそう、右に移動するものと左に移動するもの、DP
    // dp[i][j] 左はi個決めて、右はj個決める
    // 大きい活発度から左右に入れる場合、O(N^2)でも大丈夫
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    vector<P> que;
    rep(i, N) que.emplace_back(A[i], i);
    sort(que.begin(), que.end());
    // rep(i, N+2) rep(j, N+2) dp[i][j] = INF;
    dp[0][0] = 0;
    int people = 0;
    while (!que.empty()) {
        people++;
        auto p = que.back(); que.pop_back();
        int move = p.first, ind = p.second;
        // 左に入れる
        for (int i = 1; i <= N; i++) {
            int right = people - i; // 右にいる人
            if (right < 0) break;
            int left = i-1; // 左にいた人
            dp[i][right] = max(dp[i][right], dp[left][right] + (ll)move * abs(ind - (i-1)));
        }
        // 右に入れる
        for (int i = 1; i <= N; i++) {
            int left = people - i; // 左にいる人
            if (left < 0) break;
            int right = i-1; // 右にいた人
            dp[left][i] = max(dp[left][i], dp[left][right] + (ll)move * abs(ind - ((N-1)-(i-1))));
        }
    }
    ll ans = 0;
    rep(i, N) ans = max(ans, dp[i][N-i]);
    cout << ans << '\n';
    return 0;
    // ll, 0, -, 1i, for s&g, debug
}

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

int main()
{
    for (double a, b, c, d, e, f; cin >> a >> b >> c >> d >> e >> f; )
        cout << fixed << setprecision(3)
            << (b*f - c*e)/(b*d - a*e) + 0.0
            << " "
            << (a*f - c*d)/(a*e - b*d) + 0.0 << endl;

    return 0;
}

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

int main () {
    int N, D;
    cin >> N >> D;
    vector <double> vec(N), date(N);
    for (int i=0; i<N; i++) {
        cin >> vec.at(i) >> date.at(i);
    }

    int count=0;

    for (int i=0; i<N; i++) {
        if (sqrt(vec.at(i)*vec.at(i)+date.at(i)*date.at(i)+0.0)<=D) {
            count++;
        }
    }
    cout << count << endl;
}


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

const int INF = 1e9;
int main(){
	
	int n;
	cin >> n;
	
	vector<int> w(n);
	rep(i,n) cin >> w[i];
	
	vector<int> cumsum_w(n); cumsum_w[0] = w[0];
	rep(i,n-1) cumsum_w[i+1] = cumsum_w[i] + w[i+1];
	

	int res = INF;
	rep(i,n-1){
		res = min( res, abs(cumsum_w[n-1] - 2* cumsum_w[i])); 
		//cout << cumsum_w[n-1] - 2*cumsum_w[i]<< endl;
	}

	cout << res << endl;

	/*
	rep(i,n){
		cout << cumsum_w[i] << " ";
	}
	27 23 76 2 3 5 62 52
	27 50 126 128 131 136 198 250 
*/
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>

#define STARTUP {(cin.tie(0));\
 (ios::sync_with_stdio(false));}

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).size()
#define MAX(list) std::max(list)
#define MIN(list) std::min(list)
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(),(list).rend())
#define VECCIN(vec) const int size = (vec).size(); REP(i,size) cin>>(vec)[i];

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
std::istream& operator>>(std::istream& is, std::pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

using ll = long long;
using namespace std;
ll mod = 1'000'000'007;

const int INF = 1'050'000'000;

int main() {
    STARTUP;

    string S;
    cin >> S;
    YESNO(S[0] == S[2], "Yes", "No");
    return 0;
}

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


for j in range(k):
    b=[0]*n
    for i in range(0,n):
        l=max(0,i-a[i])
        r=min(n-1,i+a[i])
        b[l]+=1
        if(r+1<n):
            b[r+1]-=1
    for i in range(1,n,1):
        b[i]+=b[i-1]
    if a==b:
        break
    a=b

print(' '.join(map(str,a)))


Measured memory_bytes: 148444
/* ***********************************************
Author        :taciturnity
Created Time  :2020/2/21 8:23:51
File Name     :TEST.cpp
************************************************ */

#include <iostream>
#include <vector>
#include <queue>
#include <cstdio>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <cmath>
#include <bitset>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define ll long long
#define INF 0x3f3f3f3f
#define rep(i,x,y) for(int i = x;i <= y;++i)
#define fori(i,x,y) for(int i = x;i >= y; -- i)
#define bug puts("--------------")
#define out(x) cout<<x<<'\n';
inline char gc(){char op[2];scanf("%s",op);return op[0];}
const int N = 2e5+10;
const double eps = 0.00000001;
const ll mod = 1e9 ;
using namespace std;
ll read()
{
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
ll a[N],b[N],c[N];
int main(){
    ll x = read(),y = read(),A = read(),B = read(),C = read();
    ll ans = 0;
    rep(i,1,A) a[i] = read();
    rep(i,1,B) b[i] = read();
    rep(i,1,C) c[i] = read();
    sort(a+1,a+A+1,greater<ll>());
    rep(i,1,x) ans += a[i];
    sort(b+1,b+B+1,greater<ll>());
    rep(i,1,y) ans += b[i];
    sort(c+1,c+C+1,greater<ll>());
    int p1 = x,p2  = y,l = 1;
    while(p1>=1&&p2>=1){
        if(l > C) break;
        if(a[p1]< b[p2]){
            if(a[p1]<c[l]) ans -= a[p1--],ans += c[l++];
            else break;
        }
        else {
            if(b[p2]<c[l]) ans -= b[p2--],ans += c[l++];
            else break;
        }
    }
    while(p1>=1&&l<=C&&c[l]>a[p1]){
        ans -= a[p1];
        ans += c[l];
        l ++;p1 --;
    }
    while(p2>=1&&l<=C&&c[l]>b[p2]){
        ans -= b[p2];
        ans += c[l];
        l ++;p2 --;
    }
    cout <<ans;
}

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

typedef long long ll; 
ll m=1e9+7;
ll dp[1002][1002];


int main(){
  ll n,k;
  cin>>n>>k;
  dp[0][0]=1;

  for(int i=0;i<n;i++)
    for(int j=0;j<=k;j++){
      (dp[i+1][j]+=j*dp[i][j])%=m;
      (dp[i+1][j+1]+=dp[i][j])%=m;
    }
  cout<<dp[n][k]<<endl;
  return 0;
}




Measured memory_bytes: 10896
#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using tp3 = tuple<int, int, int>;
using Mat = vector<vector<ll>>;
constexpr int INF = 1 << 28;
constexpr ll INFL = 1ll << 60;
constexpr int dh[4] = { 0,1,0,-1 };
constexpr int dw[4] = { -1,0,1,0 };
bool isin(const int H, const int W, const int h, const int w) {
    return 0 <= h && h < H && 0 <= w && w < W;
}
template<typename T>
void output(const T& val) {
    cout << val << endl;
}
template<typename T>
void output(const vector<T>& vec, const bool newline = false) {
    for (const T& val : vec)cout << val << (newline ? '\n' : ' '); cout << endl;
}
template<typename T>
void output(const vector<vector<T>>& mat) {
    for (const auto& row : mat)output(row);
}
// ============ template finished ============

int solve(const vector<string>& maze, const int sh, const int sw) {
    const int H = maze.size(), W = maze.front().size();
    vector<vector<int>> d(H, vector<int>(W, INF));
    priority_queue<tp3, vector<tp3>, greater<tp3>> pq;
    d[sh][sw] = 0;
    pq.push(make_tuple(0, sh, sw));
    while (!pq.empty()) {
        int score, h, w;
        tie(score, h, w) = pq.top(); pq.pop();
        rep(dir, 4) {
            int nh = h + dh[dir], nw = w + dw[dir];
            if (!isin(H, W, nh, nw) || maze[nh][nw] == '#' || d[nh][nw] <= score + 1)continue;
            d[nh][nw] = score + 1;
            pq.push(make_tuple(score + 1, nh, nw));
        }
    }
    int res = 0;
    for (const auto& row : d)for (const auto& col : row)if (col != INF)res = max(res, col);
    return res;
}

int main()
{
    int H, W;
    cin >> H >> W;
    vector<string> maze(H);
    rep(h, H)cin >> maze[h];

    int res = 0;
    rep(h, H)rep(w, W)if (maze[h][w] != '#')res = max(res, solve(maze, h, w));
    output(res);
    return 0;
}


Measured memory_bytes: 256
#include<string>
#include<iostream>
#include<cstdio>
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N = (int) 1e5;
int n, k;
long long a[N + 5], ans = (long long)2e15;
int main()
{
	cin >> n >> k;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	for (int i = 1; i + k - 1 <= n; i++)
	{
		int l = i, r = i + k - 1;
		ans = min(ans, a[r] - a[l] + min(abs(a[l]), abs(a[r])));
	}	cout << ans;
	return 0;
}


Measured memory_bytes: 1024
import java.util.*;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Set;
import java.util.HashSet;
import java.util.Collection;


public class Main{
   

    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int X=sc.nextInt();
        int max=0;
        if(X==1){
            System.out.println(1);
        }else{
            for(int i=2;i<=(int)Math.pow(X,0.5);i++){
                for(int j=1;(int)Math.pow(i,j)<=X;j++){
                    if((int)Math.pow(i,j)>=max){
                        max=(int)Math.pow(i,j);
                    }
                }
            }
            System.out.println(max);
        }
        

    }

        
        
    }


Measured memory_bytes: 21716
#include <stdio.h>

int main(int argc, char const *argv[]) {
	char str[101];
	int n, m, k;
	int ans;

	fgets(str, 100, stdin);

	str[0] = str[0] == '1' ? '9' : '1';
	str[1] = str[1] == '1' ? '9' : '1';
	str[2] = str[2] == '1' ? '9' : '1';

	printf("%s\n", str);

	return 0;
}


Measured memory_bytes: 128
#include <math.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <queue>
#include <sstream>
#include <vector>

using namespace std;
using Graph = vector<vector<int>>;

using ll = long long;
typedef pair<ll, ll> P_ll;
typedef pair<int, int> P;

const ll INF_ll = 1e17;
const int INF = 1e8;

int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  vector<ll> X(1e5 + 1, 0);
  ll sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    X[A[i]]++;
    sum += A[i];
  }

  int Q;
  cin >> Q;
  vector<ll> ans_v;
  for (int i = 0; i < Q; i++) {
    ll B, C;
    cin >> B >> C;
    ll n_B = X[B];
    X[C] += n_B;
    X[B] = 0;
    sum = sum - B * n_B + C * n_B;
    ans_v.push_back(sum);
  }

  for (int i = 0; i < Q; i++) {
    cout << ans_v[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 5852
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define ll long long
#define Mid ((L+R)/2)
#define pi pair<int,int>
#define pii pair<int,pi>
#define deb(x) cout<<#x<<"="<<x<<endl
#define go ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
int n,a[300],b[300];
int main()
{
    go;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i]>>b[i];
    for(int i=2;i<n;i++)
    {
        if(a[i]!=b[i]) continue;
        if(a[i-1]!=b[i-1]) continue;
        if(a[i-2]!=b[i-2]) continue;
        cout<<"Yes";
        return 0;
    }
    cout<<"No";
    return 0;
}


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

int main(){
  int a,sum=100000,b;
  cin >>a;

  for(int i=0;i<a;i++){
    b=sum/20;
    if(b%1000==0)sum+=b;
    else sum+=(b/1000+1)*1000;
  }
  cout <<sum<<endl;
  return 0;
}

Measured memory_bytes: 1160
// Author : Mohamed Sameh
#include <bits/stdc++.h>
typedef long long ll ;
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SZ(a) (int)a.size()
#define Flush fflush(stdout);
using namespace std ;
string x;
const int N = 100;
ll dp[10009][N+1][2];
int n, sz;
const int M = 1e9 + 7;
ll solve(int idx = 0, int sum = 0, bool fl = 0)
{
  sum%=n;
  if (idx == sz)return sum == 0;
  ll &ret = dp[idx][sum][fl];
  if (~ret)return ret;
  ret = 0;
  int mx = fl ? 9 : x[idx] - '0';
  for (int i = 0; i <= mx; i++)
  {
    ret = (ret + solve(idx + 1, sum + i, (fl | (i < mx))) % M)%M;
  }
  return ret;
}
int main()
{
  memset(dp, -1, sizeof dp);
  cin >> x >> n;
  sz = SZ(x);
  cout << (solve()-1+M)%M <<"\n";
}


Measured memory_bytes: 20228
from math import ceil


def solve(string):
    a, b = map(int, string.split())
    ans = ceil(a / 0.08)
    while ans // 10 < b:
        ans += 1
    return str(ans) if ans * 2 // 25 == a and ans // 10 == b else "-1"


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))


Measured memory_bytes: 2940
a,b=map(int,input().split())
"""a,bの最大公約数"""
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

"""a,bの最小公倍数"""
def lcm(a,b):
    return a*b//gcd(a,b)
print(lcm(a,b))

Measured memory_bytes: 2940
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include <list>
#include<numeric>
#include<queue>
#include<stack>
#define rep(i,n) for(int i=0;i<(n);++i)
#define _GLIBCXX_DEBUG
using namespace std;
typedef pair<int, int> P;
typedef long long ll;

int main() {
    int n;
    double m;
    cin >> n >> m;
    double sum = 0;
    vector<double>v1(n);
    rep(i, n) {
        cin >> v1[i];
        sum += v1[i];
    }
    double count = 0;
    rep(i, n) {
        if (v1[i] >= sum / (4 * m)) {
            count++;
        }
    }
    if (count >= m) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}


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

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

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

  unordered_set<int> pressed;
  int now = 0;
  for (int i = 0; i < n; i++) {
    if (pressed.find(now) != pressed.end()) break;
    if (now == 1) {
      cout << i << '\n';
      return 0;
    }
    pressed.insert(now);
    now = a[now];
  }
  cout << -1 << '\n';
  return 0;
}

Measured memory_bytes: 4772