akhauriyash/Code-Regression huggingface dataset:
S=input()
N=len(S)

J=S[:int((N-1)/2)]
K=S[int((N+3)/2)-1:]

S_R=''.join(list(reversed(S)))
J_R=''.join(list(reversed(J)))
K_R=''.join(list(reversed(K)))

if (S==S_R)and(J==J_R)and(K==K_R):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
int main(void){
int n,x;
vector<int>a;
int ans=0;
scanf("%d",&n);
for(int i=0;i<2*n;i++){
scanf("%d",&x);
a.push_back(x);
}
sort(a.begin(),a.end());
for(int i=0;i<n;i++)ans+=a[2*i];
printf("%d\n",ans);
return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ll long long
#define ull unsigned long long
#define nl '\n'
#define INF 1e18 + 5
#define f(i, n) for (int i = 0; i < n; ++i)

using namespace std;
void solve() {
    int n = 2;
    vector<ll> a(n), b(n);
    f(i, n) cin >> a[i];
    f(i, n) cin >> b[i];
    bool hasZero = (a[0] <= 0 && a[1] >= 0) || (a[1] <= 0 && a[0] >= 0) ||
                   (b[0] <= 0 && b[1] >= 0) || (b[1] <= 0 && b[0] >= 0);
    ll ans = -INF;
    for (auto e : a) {
        for (auto g : b) {
            ans = max(ans, e * g);
        }
    }
    if (hasZero) ans = max(ans, (ll)0);
    cout << ans << nl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    solve();
}

Measured memory_bytes: 3652
#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip


def main():
    n = int(input())

    s = 0

    c = n
    while c:
        c //= 5
        s += c // 2

    print(0 if n % 2 else s)


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

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

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

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

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


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


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()


Measured memory_bytes: 29292
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define rep(i,n) for(int i = 0;i < n;i++)
#define NIL = -1;

unsigned getdigit(unsigned NUM){
    return log10(NUM) + 1;
}

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

ll lcm(ll a,ll b){
    a / gcd(a,b) * b;
}
const ll mod = 1e9 + 7;
const ll INF = 1e9 + 7;

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


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

bool isprime(ll a){
    if (a <= 1) return false;
    for (ll I = 2;I*I <= a;I++){
        if (a % I == 0) return false;
    }
    return true;
}

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

    ll ans = INF;

    for (int i = x;;i++){
        if (isprime(i)){
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define forr(i,a,n) for(int i=a; i<n; i++)
#define SPEED ios_base :: sync_with_stdio(false), cin.tie(NULL), cout.tie(0)
int main() 
{
	SPEED; 
	int a,b;
	cin>>a>>b;
	if(b>=a) 
	{
	    forr(i,0,b) cout<<a;
	}
	else  forr(i,0,a) cout<<b;
	return 0;
}

Measured memory_bytes: 256
from decimal import *

getcontext().prec = 28
a,b,c = map(int,input().split())
a = Decimal(str(a))
b = Decimal(str(b))
c = Decimal(str(c))
if 4*(a*b) < (c-a-b)**2 and c > (a+b):
    print('Yes')
else:
    print('No')


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

using namespace std;
#define M 1000000007

int main()
{
    multiset<int>m;
    int n;
    cin>>n;

    int arr[n],mx=0;
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
  
  for(int i=0;i<n;i++){
        m.insert(arr[i]);
        mx=max(mx,arr[i]);
    }

    bool se=false,pa=true,no;
    int a=arr[0];
    for(int i=1;i<n;i++)
    {
        a=(__gcd(a,arr[i]));
    }

    if(a==1) se=true;

    a=2;
    int done[1000005]={0};
    while(a<=(mx/2))
    {
        while(done[a]>0)
            a++;
        int b=a,i=2;
        int co=0;
        while(b<=mx)
        {
            if(m.count(b)) co+=m.count(b);
            done[b]++;
            b=a*i;
            i++;

            if(co>=2) break;
        }

        if(co>=2)
        {
            pa=false;
            break;
        }
    }

    if(pa) cout<<"pairwise coprime";
    else if(se) cout<<"setwise coprime";
    else cout<<"not coprime";

    return 0;
}

Measured memory_bytes: 58136
#include <cassert>
#include <algorithm>
#include <array>
#include <bitset>
#include <cctype>
#include <cstdint>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <memory>
#include <utility>
#include <limits>
 
#define rep(i, a, b) for (long long i = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  debug_out(t...);
}
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if(b==0)return 1;
  if ((a == 0)||(mod!=-1&&(a+mod)%mod==0))return 0;
  long long x = 1;
  while (b > 0) {
    if (b & 1)x = (mod!=-1)?(x * a) % mod:x*a;
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}

// const long long MOD = 998244353;
const long long MOD = 1e9 + 7;

using ll = long long;
using P=std::pair<long long,long long>;

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

  ll n;
  std::cin>>n;
  
  std::string s;
  std::cin>>s;
  
  for(auto& e:s){
    int num=e-'A';
    num=(num+n)%26;
    e='A'+num;
  }
  std::cout<<s<<"\n";

  return 0;
}



Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline

def main():
    N,A,B = map(int,input().split())
    
    if (B-A)%2 == 0:
        print((B-A)//2)
    else:
        print(min((A+B-1)//2,(2*N+1-A-B)//2))
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;
type I = usize;

fn main() {
    input!{
      s: chars,
    }
    for i in 0..s.len() {
        print!("{}", if s[i] == '1' { 9 } else { 1 });
    }
    println!();
}


Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {
	public static boolean isPrime(int x) {
		if(x <= 1) {
			return false;
		} else {
			for (int i = 2; i <= Math.sqrt(x); i++) {
				if (x % i == 0) {
					return false;
				}
			}
			return true;
		}
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int count = 0;
		for (int i = 0; i < n; i++) {
			if (isPrime(sc.nextInt())) {
				count++;
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 41892
n,k=map(int,input().split())
a=list(map(int,input().split()))
aa=a+a
lp=[-1]*n
dn={}
for i in range(2*n):
    x=aa[i]
    if x in dn:
        dn[x].append(i)
    else:
        dn[x]=[i]
from bisect import bisect_right,bisect_left
now_idx=0
ka=set(())
cnt=1
while True:
    v=a[now_idx]
    tmp=bisect_right(dn[v],now_idx)
    next_idx=dn[v][tmp]
    if next_idx>=n:
        cnt+=1
        next_idx%=n
    if next_idx in ka:
        break
    ka.add(next_idx)
    lp[next_idx]=cnt
    now_idx=next_idx+1
    now_idx%=n
ml=max(lp)
k%=ml
ans=[]
#print(lp,k)
c=set(())
for i in range(n):
    if lp[-1-i]==-1 or lp[-1-i]%ml!=k:
        ans.append(str(a[-1-i]))
    else:
        break
ans.reverse()
dnn={}
m=len(ans)
for i in range(m):
    if ans[i] in dnn:
        dnn[ans[i]].append(i)
    else:
        dnn[ans[i]]=[i]
aans=[]
i=0
while i<m:
    tmp=bisect_right(dnn[ans[i]],i)
    if tmp==len(dnn[ans[i]]):
        aans.append(ans[i])
        i+=1
    else:
        i=dnn[ans[i]][tmp]+1
print(' '.join(aans))



Measured memory_bytes: 144324
import java.util.Scanner

import scala.collection.Searching._
import scala.annotation.tailrec
import scala.collection.mutable
import scala.collection.immutable._
import scala.io.StdIn.readLine

class IUnionFind(val size: Int) {

  private case class Node(var parent: Option[Int], var treeSize: Int)

  private val nodes = Array.fill[Node](size)(new Node(None, 1))

  def union(t1: Int, t2: Int): IUnionFind = {
    if (t1 == t2) return this

    val root1 = root(t1)
    val root2 = root(t2)
    if (root1 == root2) return this

    val node1 = nodes(root1)
    val node2 = nodes(root2)

    if (node1.treeSize < node2.treeSize) {
      node1.parent = Some(t2)
      node2.treeSize += node1.treeSize
    } else {
      node2.parent = Some(t1)
      node1.treeSize += node2.treeSize
    }
    this
  }

  def connected(t1: Int, t2: Int): Boolean = t1 == t2 || root(t1) == root(t2)

  def root(t: Int): Int = nodes(t).parent match {
    case None => t
    case Some(p) => root(p)
  }
}

object Main {
  val m = (1 << 9) - 1

  def solve(sc: => Scanner): Unit = {
    val A = Array.fill(3)(sc.nextInt)
    println(A.sum - A.max + A.max * (1 << sc.nextInt))
  }

  def recursive(now: Int, A: Array[List[Int]]): Int = {
    if (A(now).size == 0) (now) else {
      val next = A(now).head
      A(now) = A(now).filter(_ != next)
      A(next) = A(next).filter(_ != now)
      recursive(next, A)
    }
  }

  def check(A: Array[List[Int]]): Boolean = {
    A.map(_.size == 0).fold(true)((a, b) => a & b)
  }

  def shift(n: Long): Long = {
    if (n == 0) (0) else if (n == 1) (1) else (shift(n - 1) << 1)
  }

  def unShift(n: Long): Long = {
    if (n == 0) (0) else (unShift(n >> 1) + 1)
  }

  def calc(v: Long): Long = (v + 1) * v / 2

  def gcd(i: Long, j: Long): Long = {
    if (i < j) (gcd(j, i)) else (if (j == 0) (i) else (gcd(j, i % j)))
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    solve(sc)
  }
}

object Util {
  def getPermutation(begin: Long = 0): Stream[Long] =
    Stream.cons(begin, getPermutation(begin + 1))

  def getPrimeList(): Stream[Long] =
    getPrimeListRecursive(getPermutation(begin = 2))

  private def getPrimeListRecursive(A: Stream[Long]): Stream[Long] =
    Stream.cons(A.head, getPrimeListRecursive(A.tail.filter(_ % A.head != 0)))

  def fib(a: Long = 0, b: Long = 1, mod: Long = Long.MaxValue): Stream[Long] = a #:: fib(b % mod, (a + b) % mod, mod)
}

Measured memory_bytes: 27344
#!/usr/bin/ python3.8
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, M, *A = map(int, read().split())
A.sort(reverse=True)
x = A[M - 1]
S = sum(A)

answer = 'Yes' if 4 * M * x >= S else 'No'
print(answer)


Measured memory_bytes: 2940
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
int main()
{
    vector<int> a;
    for (int i = 1; i < 1 + 3; i++){
        int x;
        cin >> x;
        a.push_back(x);
    }
    sort(a.begin(), a.end(), greater<int>());

    int ans = 0;
    for (int i = 0; i < a.size() - 1; i++)
    {
        ans += a[i] - a[i + 1];
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
//shara's here
#include <bits/stdc++.h>
using namespace std;
typedef int q;
typedef double w;
typedef string s;
typedef long long ll;
int main(){
    s ss;
    cin>>ss;
    if(ss[0]=='a'&&ss[1]=='b'&&ss[2]=='c'){cout<<"Yes";}
    else if(ss[0]=='b'&&ss[1]=='a'&&ss[2]=='c'){cout<<"Yes";}
    else if(ss[0]=='b'&&ss[1]=='c'&&ss[2]=='a'){cout<<"Yes";}
    else if(ss[0]=='a'&&ss[1]=='c'&&ss[2]=='b'){cout<<"Yes";}
    else if(ss[0]=='b'&&ss[1]=='a'&&ss[2]=='c'){cout<<"Yes";}
    else if(ss[0]=='c'&&ss[1]=='b'&&ss[2]=='a'){cout<<"Yes";}
    else if(ss[0]=='c'&&ss[1]=='a'&&ss[2]=='b'){cout<<"Yes";}
    else{cout<<"No";}
return 0;}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1e9+7;

int main()
{
  ll n,m,d;
  cin>>n>>m>>d;
  cout<<fixed<<setprecision(20);
  if (d==0) {
    cout<<(double)(m-1)/n<<endl;
  } else {
    cout<<(m-1)*(n-d)*2.0/(double)(n*n)<<endl;
  }
}

Measured memory_bytes: 3744
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

#define rep(i, n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);



int main() {
    int n;
    cin >> n;
    vector<ll> v(n);
    vector<ll> m;
    vector<ll> s;
    bool f = true;
    bool t = true;
    bool zero=true;

    rep(i, n) {
        cin >> v[i];

//        if (v[i] > 0)f = false;
//        if (v[i] < 0)t = false;
        if(v[i]!=0)zero=false;
        if (v[i] >= 0){s.push_back(v[i]);}
        else m.push_back(v[i]);
    }
    //vector<ll> c;
    //sort(c.begin(),c.end());
    sort(v.begin(), v.end());

    vector<pair<ll, ll>> ans;




        ll mi=v[0];
        ll ma=v[n-1];
        int p;
        int pl=0;int ne=0;
        rep(i,n){
            if(v[i]<0){
                p=i;
                ne++;
            }else{
                pl++;
            }
        }

        p++;

    if((n-ne-pl)==n){
        cout<<0<<endl;
        rep(i,n-1){
            cout<<0<<" "<<0<<endl;
        }
        return 0;
    }

    if(n==2){
        cout<<v[1]-v[0]<<endl;
        cout<<v[1]<<" "<<v[0]<<endl;
        return 0;
    }
    p=min(n-1,p);
    for(int i=1;i<p;i++){
            ans.push_back({ma,v[i]});
            ma-=v[i];
        }
        for(int i=p;i<n-1;i++){
            ans.push_back({mi,v[i]});
            mi-=v[i];
        }
        ans.push_back({ma,mi});
        cout<<ma-mi<<endl;

//
//        ll las2=s[s.size()-1];//せいの大きいのma
//        for(int j=1;j<m.size();j++){
//            ans.push_back({las2,m[j]});
//            las2-=m[j];
//        }
//
//        ll las=m[0];//負の小さいのmi
//        for(int i=0;i<s.size()-1;i++){
//            ans.push_back({las,s[i]});
//            las-=s[i];
//        }
//
//
//        ans.push_back({las2,las});
//
//        ll m=las2-las;
//
//
//        cout<<m<<endl;




        rep(i,ans.size()){
            cout<<ans[i].first<<" "<<ans[i].second<<endl;
        }




    return 0;
}


Measured memory_bytes: 5872
/**
 * Sergey Kopeliovich (burunduk30@gmail.com)
 */

#include <bits/stdc++.h>

using namespace std;

#define forn(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
	int n, a, ma = 0;
	scanf("%d", &n);
	unordered_map<int, int> cnt(n);
	forn(i, n) scanf("%d", &a), cnt[a]++;
	for (int x = 0; x <= int(1e5); x++) 
		ma = max(ma, cnt[x - 1] + cnt[x] + cnt[x + 1]);
	printf("%d\n", ma);
}

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

int main(){
	long long N,X,M;
	cin >> N >> X >> M;
	long long ans=X,tmp=X,tmp2;
	map<long long,long long> mems;
	mems[X]=0;
	vector<long long> loopsum;
	loopsum.push_back(X);
	for(long long loop=1;loop<N;loop++){
		tmp2=(tmp*tmp)%M;
		tmp=tmp2;
		if(tmp==0){
			break;
		}else if(mems.count(tmp)){
			long long looplg=loop-mems[tmp];
			tmp2=loopsum[loop-1];
			if(mems[tmp])
				tmp2-=loopsum[mems[tmp]-1];
			ans+=tmp2*((N-loop)/looplg);
			if((N-loop)%looplg){
				ans+=loopsum[mems[tmp]+(N-loop)%looplg-1];
				if(mems[tmp])ans-=loopsum[mems[tmp]-1];
			}
			break;
		}else{
			loopsum.push_back(loopsum[loop-1]+tmp);
			mems[tmp]=loop;
			ans+=tmp;
		}
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

int main(){
    int W, a, b, ans;
    cin >> W >> a >> b;
    if(a < b){
        if(a + W > b) ans = 0;
        else ans = b - a - W;
    }

    else {
        if(b + W > a) ans = 0;
        else ans = a - b - W;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        //BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        //StringTokenizer st = new StringTokenizer(br.readLine());
        //PrintWriter pw = new PrintWriter("Main.out");

        int n = sc.nextInt();
        int[] sticks = new int[n];
        for(int i = 0; i<n; i++){
            sticks[i] = sc.nextInt();
        }
        Arrays.sort(sticks);
        int diff = 0;
        for(int i = 0; i<n; i++){
            loop : for(int j = i+1; j<n; j++){
                for(int k = j+1; k<n; k++){
                    if(triangle(sticks[i], sticks[j], sticks[k])){
                        diff++;
                        //continue loop;
                    }
                    else{
                        continue loop;
                    }
                }
            }
        }
        System.out.println(diff);
    }

    public static boolean triangle(int a, int b, int c){
        if(a + b > c && a + c > b && b + c > a){
            return true;
        }
        return false;
    }
}

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

int main(){
    int N, D, X;
    cin >> N >> D >> X;
    vi A(N);
    rep(i, N) cin >> A[i];

    int choco = 0;
    rep(i, N){
        rep(j, D){
            if(j*A[i] + 1 <= D){
                choco++;
            }
        }
        cout << endl;
    }

    cout << choco + X << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define MAX 600

struct rest{
  int start, end;
  inline void set(int a, int b){ start = a; end = b; }
  bool operator < (const rest &a) const { return end < a.end; }
} rests[MAX];

int n, m, restlen;
bool exist[MAX];

int main(){
  int a, b;
  while(scanf("%d%d", &n, &m) == 2){
    restlen = 0;
    memset(exist, true, sizeof(exist));
    
    for(int i = 0; i < m; i++){
      scanf("%d%d", &a, &b);
      if(a < b){ rests[restlen].start = a; rests[restlen].end = b; restlen++; }
    }
    sort(rests, rests + restlen);
    
    for(int i = 0; i < m; i++){
      for(int j = i - 1; j >= 0; j--)
      if(exist[j] && rests[j].end >= rests[i].start){
        rests[i].start = min(rests[i].start, rests[j].start);
        exist[j] = false;
      }
    }
    
    int ans = n + 1;
    for(int i = 0; i < m; i++) 
    if(exist[i]) ans += (rests[i].end - rests[i].start) << 1;
    printf("%d\n", ans);
  }
  return 0;
}

Measured memory_bytes: 1044
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
constexpr int MOD = 1000000007;
constexpr int INF = 2000000000;
using namespace std;

int main() {
	int n;
	cin >> n;
	int a;
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		sort(s.begin(),s.end());
		string ss = s;
		for (int i = 0; i < 4; i++) {
			swap(ss[i], ss[7 - i]);
		}
		cout << stoi(ss) - stoi(s) << endl;
	}
}

Measured memory_bytes: 3160
//#pragma GCC optimize(2)
// Happy TLE and WA every day!
// by: zxb the vegetable chicken
#include<bits/stdc++.h>
#define mp              make_pair
#define rep(i,n)        for(int i = 0; i < n; i++)
#define foreach(i,c)    for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define BINF            0x7fffffff
#define INF             0x3f3f3f3f
#define LINF            3223372036854775807
#define END(s)          {cout<<s; return 0;}
#define CON(s)          {cout<<s; continue;}
#define BRE(s)          {cout<<s; break;}
#define pb              push_back
#define All(a)          a.begin(), a.end()  //with A in CAPITAL!!!
#define sz(a)           (int)a.size()
#define F               first
#define S               second
#define Time            clock()/CLOCKS_PER_SEC
//#define usingFiles
using namespace std;

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

inline bool Read(int& x){
	x = 0;
	int c;
	int sign = 1;
	while( (c = getchar()) < '0' || c > '9' ) if(c == '-') sign = -1;
	x = c ^ '0';
	while( (c = getchar()) >= '0' && c <= '9' ) x = (x<<3) + (x<<1) + (c ^ '0');
	x *= sign;
	return 1;
}

inline bool Write(int x){
	if(x >= 10) Write(x / 10);
	putchar(x % 10 + '0');
	return 1;
}

const int rp = 666666;
const bool debug = 1;
const bool I_good_vegetable_a = 1;

int n;
int a[3][100100];
int dp[3][100100];

signed main(){
	ios::sync_with_stdio(false);
	#ifdef usingFiles
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	cin >> n;
	rep(i, n) cin >> a[0][i] >> a[1][i] >> a[2][i];
	dp[0][0] = a[0][0];
	dp[1][0] = a[1][0];
	dp[2][0] = a[2][0];
	for(int i = 1; i < n; i++){
		dp[0][i] = max(dp[1][i - 1], dp[2][i - 1]) + a[0][i];
		dp[1][i] = max(dp[0][i - 1], dp[2][i - 1]) + a[1][i];
		dp[2][i] = max(dp[1][i - 1], dp[0][i - 1]) + a[2][i];
	}
	cout << max(dp[0][n - 1], max(dp[1][n - 1], dp[2][n - 1]));
	return 0;
}

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

void dfs(int i,vector<int> adj[],int dp[],int v[])
{
    v[i]=1;
    
    for(auto it=adj[i].begin();it!=adj[i].end();it++)
    {
        if(v[*it]==0)
        {
           dfs(*it,adj,dp,v);
        }
        dp[i]=max(dp[i],1+dp[*it]);
    }
}

int main()
{
    int n;
    cin>>n;
    
    vector<int> adj[n];
    
    int e;
    cin>>e;
    
    int a,b;
    for(int i=0;i<e;i++)
    {
        cin>>a>>b;
        adj[a-1].push_back(b-1);
    }
    
    int dp[n]={0};
    int v[n]={0};
    
    for(int i=0;i<n;i++)
    {
        if(v[i]==0)
        {
            dfs(i,adj,dp,v);
        }
    }
   
    int m=0;
    for(int i=0;i<n;i++)m=max(m,dp[i]);//cout<<dp[i]<<" ";
    cout<<m;
    return 0;
}


Measured memory_bytes: 9216
{-# LANGUAGE BangPatterns #-}
import Control.Arrow
import Control.Monad.Fix
import Data.Foldable
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VMM
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VM
import qualified Data.ByteString.Char8 as B
import qualified Data.Set as S
import System.IO.Unsafe
import Debug.Trace

uread :: VU.Unbox a => Int -> VM.IOVector a -> a    
uread i v = unsafePerformIO $ VM.read v i

uwrite :: VU.Unbox a => Int -> a -> VM.IOVector a -> VM.IOVector a
uwrite i a v = unsafePerformIO $ VM.write v i a >> return v

umodify :: VU.Unbox a => Int -> (a -> a) -> VM.IOVector a -> VM.IOVector a
umodify i f v = unsafePerformIO $ VM.modify v f i >> return v

uthaw :: VU.Unbox a => VU.Vector a -> VM.IOVector a
uthaw = unsafePerformIO . VU.thaw

ufreeze :: VU.Unbox a => VM.IOVector a -> VU.Vector a
ufreeze = unsafePerformIO . VU.freeze

dijkstra
  :: Int  -- ^ nodes
  -> V.Vector (VU.Vector (Int, Double))  -- ^ edges from i-th node: (end, cost)
  -> Int  -- ^ start node
  -> VU.Vector Double  -- ^ constructed graph
dijkstra n edges s =
  ufreeze $ snd $ fix (\f (nodes,costs) -> case S.minView nodes of
    Nothing -> (S.empty,costs)
    Just ((c,n), nodes) ->
      if c <= uread n costs
        then
          let es = edges V.! n in
            f $ VU.foldl' (\(ns,cs) (e,ec) ->
              let c' = c + ec in if c' < uread e costs
                then (S.insert (c',e) ns, uwrite e c' cs)
                else (ns,cs)
              ) (nodes,costs) es
        else f (nodes,costs)) (nodes0,costs0)
  where
    costs0 :: VM.IOVector Double
    costs0 = uwrite s 0 (uthaw $ VU.replicate n $ fromIntegral (maxBound :: Int))

    nodes0 :: S.Set (Double,Int)
    nodes0 = S.singleton (0,s)

solve :: Int -> Int -> Int -> Int -> Int -> VU.Vector (Int,Int,Int) -> Double
solve xs ys xt yt n xyr = graph VU.! (n+1)
  where
    big = fromIntegral (maxBound :: Int)

    dist2C :: (Int,Int,Int) -> (Int,Int,Int) -> Double
    dist2C (x1,y1,r1) (x2,y2,r2) = (sqrt (fromIntegral $ (x1-x2)^2 + (y1-y2)^2) - fromIntegral (r1+r2)) `max` 0

    toIndex (i,j) = i * (n+2) + j

    distMemo = ufreeze $ foldl' (\acc (i,j) ->
      let c1 = if i == n then (xs,ys,0) else if i == n+1 then (xt,yt,0) else xyr VU.! i
          c2 = if j == n then (xs,ys,0) else if j == n+1 then (xt,yt,0) else xyr VU.! j in
        uwrite (toIndex (i,j)) (dist2C c1 c2) acc
      ) (uthaw $ VU.replicate ((n+2)*(n+2)) big) [(i,j) | i <- [0..n+1], j <- [0..n+1], i /= j]
    edges = V.force $ V.generate (n+2) (\e -> VU.map (\i -> (i, distMemo VU.! toIndex (i,e))) $ VU.fromList [0..n+1])
    graph = dijkstra (n+2) edges n

main = do
  let readInt = fmap (second B.tail) . B.readInt

  (xs,ys,xt,yt) <- (\vec -> (vec VU.! 0, vec VU.! 1, vec VU.! 2, vec VU.! 3)) . VU.unfoldrN 4 readInt <$> B.getLine
  n <- (\vec -> (vec VU.! 0)) . VU.unfoldrN 1 readInt <$> B.getLine
  xyr <- VU.replicateM n $ (\vec -> (vec VU.! 0, vec VU.! 1, vec VU.! 2)) . VU.unfoldrN 3 readInt <$> B.getLine
  print $ solve xs ys xt yt n xyr


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

int main() {
    long long K; cin >> K;
    cout << 50 << endl;
    rep(i, 0, 51) if(i != 50 - K % 50) cout << i + K / 50 << " ";
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
n,k = map(int,input().split())
m = n
l = n
res = 0
cnt = 0
tmp = m
while m < k:
    m *= 2
    cnt += 1
res += (1/n)*(0.5)**cnt
for i in range(1,n):
    cnt = 0
    l = n
    l -= i
    cnt = 0
    while l < k:
        l *= 2
        cnt += 1
    res += (1/n)*(0.5)**cnt
print(res)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char** argv) {
	int h1,h2,m1,m2;
	int k;
	cin>>h1>>m1>>h2>>m2>>k;
	cout<<max(0,(h2-h1)*60+(m2-m1)-k);
	return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;

int main(){
	int N; cin>>N;
	vector<int> rest(N+1);
	REP(i,N)cin>>rest[i];
	vector<int> sum(N+1,0);
	vector<int> ans(N+1,0);
	int ans_cnt = 0;
	for(int i = N; i > 0; --i){
		if(sum[i]%2 != rest[i]){
			ans[i] = 1;
			++ans_cnt;
			for(int k = 1; k*k <= i; ++k){
				if(i%k == 0){
					++sum[k];
					if(k!= i/k)++sum[i/k];
				}
			}
		}
		// printf("%d has ended\n", i);
		// REP(i,N)cout<<sum[i]<<' ';
		// cout<<endl<<line<<endl;
	}
	cout<<ans_cnt<<endl;
	REP(i,N)if(ans[i] == 1)cout<<i<<endl;
	return 0;
}

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

int main()
{
    int a,b;
    char s[11],t[11],u[11];
    scanf("%s %s %d %d %s",s,t,&a,&b,u);

    if(strcmp(s,u) == 0)printf("%d %d",a - 1,b);
    else printf("%d %d",a,b - 1);
}


Measured memory_bytes: 128
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;

const int mxN = 1e5 + 5, mod = 1e9 + 7;
vector<int> adj[mxN];
long long answer = 1, k;

void dfs(int node, int parent = -1) {
	long long cur = parent == -1 ? k - 1 : k - 2;
	for(int x : adj[node]) {
		if(x == parent)
			continue;
		if(cur <= 0) {
			answer = 0;
			return;
		}
		answer = answer * cur % mod;
		--cur;
		dfs(x, node);
	}
}

int main() {
	int n;
	cin >> n >> k;
	for(int i = 1; i < n; ++i) {
		int u, v;
		cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	answer = k;
	dfs(1);
	cout << answer;
}


Measured memory_bytes: 13524
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp15
{
    class Class91
    {
        static void Main()
        {
            string S = Console.ReadLine();
            bool A = S.Contains("A");
            bool B = S.Contains("B");
            if (A)
            {
                if (B) { Console.WriteLine("Yes"); }
                else { Console.WriteLine("No"); }
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


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

int main() {
  int A, B, K;
  cin >> A >> B >> K;
  int ans;
  for (int i = min(A,B); i > 0; i--) {
    if (A % i == 0 && B % i == 0) {
      K--;
      if (K==0) {
        cout << i << endl;
        return 0;
      }
    }
  }
}


Measured memory_bytes: 3604
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
using namespace std;
int n,m,ans,sum;
struct Edge{
	int u,v;
}edge[300];
int father[60];
int Find(int x)
{
	int y=x;while(y!=father[y])y=father[y];
	while(y!=x)
	{
		int tmp=father[x];
		father[x]=y;
		x=tmp;
	}
	return y;
}
bool Union(int x,int y)
{
	x=Find(x);y=Find(y);if(x!=y){
		father[x]=y; return true;
	}
	return false;
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int u,v;scanf("%d%d",&edge[i].u,&edge[i].v);
	}
	for(int i=1;i<=m;i++)
	{
		for(int k=1;k<=n;k++)father[k]=k;sum=n;
		for(int j=1;j<=m;j++)
		{
			if(i!=j)
			{
				if(Union(edge[j].u,edge[j].v))sum--;
			}
		}
		if(sum>1)ans++;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
int mod = 998244353;
// int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b; if (a >= mod) a -= mod; }


void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(10);
  int T;
  T = 1;
  while (T--) solve();
}

void solve() {
  int n = 4;
  vector<vector<int> > G(4);
  rep(i, 3) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    G[a].eb(b);
    G[b].eb(a);
  }

  rep(i, 4) if (sz(G[i]) == 0) { cout << "NO" << endl; return; }

  int o = 0, e = 0;
  rep(i, 4) if (sz(G[i]) % 2) o++; else e++;
  // cout << o << " " << e << endl;

  // 始点, 終点以外は入って出る
  if (o == 2) cout << "YES" << endl;
  else cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
    int n; cin>>n;
    string s, t; cin>>s>>t;
    for(int i=0; i<n; i++){
        if(s.substr(i)==t.substr(0, n-i)){
            cout<<n+i<<endl; return 0;
        }
    }
    cout<<2*n<<endl;
    return 0;
}

Measured memory_bytes: 256
unittest
{
	assert( [ "5", "3 2 4 1 2" ].parse.expand.solve == 2 );
	assert( [ "10", "10 71 84 33 6 47 23 25 52 64" ].parse.expand.solve == 36 );
	assert( [ "7", "1 2 3 1000000000 4 5 6" ].parse.expand.solve == 999999994 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	input.popFront;
	auto as = input.front.split.to!( long[] );
	return tuple( as );
}

auto solve( long[] as )
{
	// 累積和表に変換
	as = 0 ~ as;
	for( auto i = 1L; i < as.length; i++ )
	{
		as[ i ] += as[ i - 1 ];
	}
	
	// QとRの境界を仮置き
	auto ans = long.max;
	auto cs = [ 0L, 1L, 2L, 3L, as.length.signed - 1 ];
	for( ; cs[ 2 ] + 2 < as.length; cs[ 2 ]++ )
	{
		// PとQの差が最小になる境界を探索
		for( auto c = cs[ 1 ], e = long.max; c < cs[ 2 ]; c++ )
		{
			auto p = as[ c ] - as[ cs[ 0 ] ];
			auto q = as[ cs[ 2 ] ] - as[ c ];
			auto d = max( p, q ) - min( p, q );
			if( e <= d ) break;
			e = d;
			cs[ 1 ] = c;
		}
		
		// RとSの差が最小になる境界を探索
		if( cs[ 3 ] <= cs[ 2 ] ) cs[ 3 ] = cs[ 2 ] + 1;
		for( auto c = cs[ 3 ], e = long.max; c < cs[ 4 ]; c++ )
		{
			auto r = as[ c ] - as[ cs[ 2 ] ];
			auto s = as[ cs[ 4 ] ] - as[ c ];
			auto d = max( r, s ) - min( r, s );
			if( e <= d ) break;
			e = d;
			cs[ 3 ] = c;
		}
		
		// PQRSの最大値と最小値の差を計算
		auto p = as[ cs[ 1 ] ] - as[ cs[ 0 ] ];
		auto q = as[ cs[ 2 ] ] - as[ cs[ 1 ] ];
		auto r = as[ cs[ 3 ] ] - as[ cs[ 2 ] ];
		auto s = as[ cs[ 4 ] ] - as[ cs[ 3 ] ];
		ans = min( ans, max( p, q, r, s ) - min( p, q, r, s ) );
	}
	return ans;
}


Measured memory_bytes: 11348
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>
#include <numeric>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using ll = long long int;
using ul = unsigned long long int;
const ll LL_MAX (1LL<<60);
const ll MOD (1000000007);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

ll f(ll n)
{
    if (n%2==0) n/=2;
    else n=3*n+1;

    return n;
}

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

    ll s;
    cin >> s;
    unordered_set<ll> ss;

    ss.insert(s);

    ll cnt(0);
    while (true)
    {
        s = f(s);

        cnt++;

        if (ss.find(s)==ss.end())
            ss.insert(s);
        else
            break;
    }

    cout << cnt+1 << endl;

    return 0;
}


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

#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define FOR(i,n,m) for (ll i=n; i<(ll)(m); i++)
#define pb push_back
#define INF 1000000007LL
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)

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

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

ll H, W;
string S[55];
ll dist[55][55];

bool isOk(ll x, ll y) {
    if (x < 0 || y < 0) return false;
    if (x >= W || y >= H) return false;
    if (S[y][x] == '#') return false;
    
    return true;
}

void solve() {
    REP(i, H) REP(j, W) dist[i][j] = INF * INF;
    queue<pair<ll, ll>> q;
    dist[0][0] = 0;
    q.push(make_pair(0, 0));
    while (!q.empty()){
        ll px = q.front().first;
        ll py = q.front().second;
        q.pop();
        REP(i, 4) {
            ll nx = px + dx[i];
            ll ny = py + dy[i];
            if (isOk(nx, ny) && dist[ny][nx] == INF * INF) {
                dist[ny][nx] = dist[py][px] + 1;
                q.push(make_pair(nx, ny));
            }
        }
        
    }
}
int main(){
    ios::sync_with_stdio(false);
    cin >> H >> W;
    ll cnt = 0;
    REP(i, H) {
        cin >> S[i];
        REP(j, W) {
            if (S[i][j] == '.') cnt++;
        }
    }
    solve();
    if (dist[H-1][W-1] == INF * INF) {
        cout << -1 << endl;
    } else {
        cout << cnt - dist[H-1][W-1] - 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int n, q, L[N], R[N], C[N];
int main()
{
    scanf("%d%d", &n, &q);
    set < pair < int , int > > S, T;
    for (int i = 1; i <= q; i++)
    {
        scanf("%d%d", &L[i], &R[i]);
        C[L[i]] ++; C[R[i] + 1] --;
    }
    for (int i = 1; i <= n; i++)
        C[i] += C[i - 1];
    int cnt = 0;
    for (int i = 1; i <= n; i++)
        if (C[i] == q)
            cnt ++;
    printf("%d\n", cnt);
    return 0;
}

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

using namespace std;

int main(){
    long long n, ans = LONG_LONG_MAX; cin >> n;
    for(long long i = 1; i <= sqrt(n); ++i){
        if(n % i == 0){
            ans = min(ans, abs(i - 1) + abs(n / i - 1));
        }
    }
    cout << ans;
    return 0;
}


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

using namespace std;




int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k;
    cin >> n >> k;
    double res=0;
    vector<double> v(n);
    for (int i=0;i<n;++i){
        double temp;
        cin >> temp;
        v[i] = (1+temp)/2;


    }

    double maxs=0,temp=0;
    for (int i=0;i<k;++i){
        temp += v[i];
    }
    for (int i=0;i<n-k;++i){
        maxs = max(temp,maxs);
        temp += v[i+k]- v[i];



    }maxs = max(temp,maxs);
    cout << fixed<< setprecision(12) << maxs;
    return 0;
}


Measured memory_bytes: 4748
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define ull unsigned long long
#define pb(a) push_back(a)
#define INF 100000000001
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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


int main()
{
    string s="ACL";
    int k;
    cin >> k;
    REP(i, k) cout << s;
    cout << endl;
}


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


    using namespace std;
    typedef long long ll;
    # define M_PI  3.14159265358979323846
    const int MOD=1e9+7;

    void solve(){
        int n;
        cin>>n;
        vector<ll>leaf(n+1);
        for(int i=0;i<=n;i++)
            cin>>leaf[i];
        if(leaf[0]>=2){
            cout<<-1;
            return;
        }
        vector<ll>sum(n+2);
        for(int i=1;i<=n+1;i++)
            sum[i]=sum[i-1]+leaf[i-1];
        vector<ll>n_leaf(n+1);
        n_leaf[0]=1-leaf[0];
        for(int i=1;i<=n;i++){
            n_leaf[i]=(2LL*n_leaf[i-1]) - leaf[i];
            n_leaf[i]=min(n_leaf[i],sum[n+1]-sum[i+1]);
            if(n_leaf[i]<0){
                cout<<-1;
                return;
            }
        }
//        for(int i=0;i<=n;i++)
//            cout<<sum[i]<<" ";
//        cout<<"\n";
//        for(int i=0;i<=n;i++)
//            cout<<n_leaf[i]<<" ";
//        cout<<"\n";
        ll ans=0;
        for(int i=0;i<=n;i++)
            ans+=leaf[i]+n_leaf[i];
        cout<<ans;
    }

    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        cout<<fixed;
        cout<<setprecision(10);
        int t=1;
//        cin>>t;
        for(int i=1;i<=t;i++){
            solve();
        }
        return 0;
    }


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

using namespace std;
using ll =long long;
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
#define leftunique(a) {sort((a).begin(),(a).end());(a).erase(unique((a).begin(),(a).end()),(a).end());}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
static const ll INF = 1LL << 60;
//Write From this Line

int main()
{
	string s;
	cin >> s;
	ll k;
	cin >> k;
	vector<string> sub;
	ll n = s.length();
	rep(i,n){
		For(j,1,6){ 
			sub.push_back(s.substr(i,j));
		}
	}
	sort(sub.begin(),sub.end());
	unique(sub.begin(),sub.end());
	cout << sub[k-1] << endl;
}


Measured memory_bytes: 1660
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
constexpr int MOD = 1000000007;

using namespace std;


signed main() {
  string s, t;
  cin >> s >> t;
  int N = s.size();
  int M = t.size();

  vector<int> v(N);
  REP(i, N) v[i] = s[i]-'a';

  vector<vector<int>> vec(26);
  REP(i, N) vec[v[i]].push_back(i);
  REP(i, 26) vec[i].push_back(N+1);

  REP(i, M) if(vec[t[i]-'a'].size() == 1){
    cout << -1 << endl;
    return 0;
  }

  int now = 0;
  int line = 0;
  REP(i, M){
    int a = t[i]-'a';
    now = *lower_bound(ALL(vec[a]), now);
    if(now == N+1){
      now = 0;
      line++;
      now = *lower_bound(ALL(vec[a]), now);
    }
    now++;
  }

  cout << N*line+now << endl;

  return 0;
}

Measured memory_bytes: 2492
#include <iostream>
#include<vector>
#include<algorithm>
#include <queue>
#include <string>
#include <set>
#include <bitset>

using namespace std;
#define ff(i,n,m) for(int i=n;i<m;i++)
#define i64 int64_t
#define tos(x) to_string(x)

int main() {
	const int inf = 1000000000;
	int n, m;
	cin >> n >> m;
	int a[1000], b[1000], c[1000];
	int dist[100][100];

	ff(i, 0, m) {
		cin >> a[i] >> b[i] >> c[i];
		a[i]--;
		b[i]--;
	}
	ff(i, 0, n) {
		ff(j, 0, n) {
			if (i == j) {
				dist[i][j] = 0;
			}
			else {
				dist[i][j] = inf;
			}
		}
	}
	ff(i, 0, m) {
		dist[a[i]][b[i]] = min(dist[a[i]][b[i]], c[i]);
		dist[b[i]][a[i]] = min(dist[b[i]][a[i]], c[i]);
	}
	ff(k, 0, n) {
		ff(i, 0, n) {
			ff(j, 0, n) {
				dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
			}
		}
	}
	int ans = m;
	ff(i, 0, m) {
		bool s = false;
		ff(j, 0, n) {
			if (dist[j][a[i]] + c[i] == dist[j][b[i]]) {
				s = true;
				break;
			}
		}
		if (s) {
			ans--;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256