akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <iomanip>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long ll;

int main() {
	
	int a, b;

	cin >> a;
	cin >> b;

	if (b == 1) {
		cout << 0 << endl;
	}
	else if (b - a <= 0) {
		cout << 1 << endl;
	}
	else {
		if ((b - a) % (a - 1) == 0) {
			cout << 1 + (b - a) / (a - 1) << endl;
		}
		else {
			cout << 2 + (b - a) / (a - 1) << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Read, StdoutLock, Write};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::str::FromStr;

// small-and-large-integers.rs --- Small and Large Integers
// author: Seong Yong-ju <sei40kr@gmail.com>

#[allow(unused_macros)]
macro_rules! get {
  ($t:ty) => {
    {
      let mut line: String = String::new();
      stdin().read_line(&mut line).unwrap();
      line.trim().parse::<$t>().unwrap()
    }
  };
  ($($t:ty),*) => {
    {
      let mut line: String = String::new();
      stdin().read_line(&mut line).unwrap();
      let mut iter = line.split_whitespace();
      (
        $(iter.next().unwrap().parse::<$t>().unwrap(),)*
      )
    }
  };
  ($t:ty; $n:expr) => {
    (0..$n).map(|_|
                get!($t)
    ).collect::<Vec<_>>()
  };
  ($($t:ty),*; $n:expr) => {
    (0..$n).map(|_|
                get!($($t),*)
    ).collect::<Vec<_>>()
  };
  ($t:ty ;;) => {
    {
      let mut line: String = String::new();
      stdin().read_line(&mut line).unwrap();
      line.split_whitespace()
        .map(|t| t.parse::<$t>().unwrap())
        .collect::<Vec<_>>()
    }
  };
  ($t:ty ;; $n:expr) => {
    (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
  };
}

#[allow(unused_macros)]
macro_rules! debug {
  ($($a:expr),*) => {
    println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
  }
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("Failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("Failed to parse token")
}

#[allow(dead_code)]
fn with_bufwriter<F: FnOnce(BufWriter<StdoutLock>) -> ()>(f: F) {
    let out = stdout();
    let writer = BufWriter::new(out.lock());
    f(writer);
}

fn main() {
    let (a, b, k) = get!(i32, i32, i32);

    with_bufwriter(|mut out| {
        for n in a..min(a + k, b + 1) {
            writeln!(out, "{}", n).unwrap();
        }
        for n in max(a + k, b - k + 1)..b + 1 {
            writeln!(out, "{}", n).unwrap();
        }
    });
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
// const int MOD = 1e9 + 7;

int main() {
    ll N;
    cin >> N;
    cout << (N) * (N - 1) / 2 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using i64 = long long;

long long *fact, *inv;

template <typename T, typename U, typename V>
auto pow(T x_, U n_, V mod_) {
    std::common_type_t<T, U, V> ret = 1, x = x_, n = n_, mod = mod_;
    while(n > 0) {
        if ((n & 1) == 1) ret = (ret * x) % mod;
        x = (x * x) % mod;
        n >>= 1;
    }
    return ret;
}

template <typename T, typename U>
auto inverse(T x, U p) { return pow(x, p - 2, p); }

void init_factorial(int n, long long mod) {
    fact = new long long[n + 1];
    inv = new long long[n + 1];
    fact[0] = 1;
    for (long long i = 1; i <= n; i++) fact[i] = fact[i - 1] * i % mod;
    inv[n] = inverse(fact[n], mod);
    for (long long i = n; i > 0; i--) inv[i - 1] = inv[i] * i % mod;
}

int main() {
    constexpr i64 mod = 1000000007;
    int n, a, b, c, d;
    std::cin >> n >> a >> b >> c >> d;
    init_factorial(1010, mod);
    std::vector<i64> dp(1010);
    std::vector<std::vector<i64>> mk(1010, std::vector<i64>(1010));
    for (int i = a; i <= b; i++) {
        mk[i][0] = 1;
        for (int j = 1; j <= d; j++) mk[i][j] = mk[i][j - 1] * inv[i] % mod;
    }
    dp[0] = fact[n];
    for (int i = 0; i <= b - a; i++) {
        int m = a + i;
        std::vector<i64> next(1010);
        for (int j = 0; j <= n; j++) {
            for (int k = 0; k <= j / m; k++) {
                if (c <= k && k <= d) {
                    next[j] = (next[j] + dp[j - k * m] * inv[k] % mod * mk[m][k] % mod) % mod;
                } else {
                    next[j] = dp[j];
                }
            }
        }
        std::swap(dp, next);
    }

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

    return 0;
}


Measured memory_bytes: 8448
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

string sa,sb;

int main(){
	int n,m;
	int i,j,k;
	int a,b,c;
	cin>>n;
	cin>>sa>>sb;
	for(i=0;i<n;i++){
		cout<<sa[i]<<sb[i];
	}
	cout<<endl;
}

Measured memory_bytes: 256
//{{{
#include<algorithm>
#include<cmath>
#include<deque>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(printde) FUNC(printdbe) FUNC(printdwe) FUNC(printdu);
#endif
template <template <class T, class = std::allocator<T>> class V, class E>
istream& operator >> (istream& in, V<E>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    int n, m, v, p;
    cin >> n >> m >> v >> p;
    vector<int> as(n); cin >> as;
    sort(as.rbegin(), as.rend());
    printde(as);
    int in = p - 1, out = n;
    while(in + 1 < out){
        int piv = (in + out) / 2;
        bool ok = false;

        int vThre = p - 1 + n - piv;
        if(v <= vThre){
            printde(v <= vThre);
            ok = as[p - 1] <= as[piv] + m;
        }else{
            printde("else");
            ll rem = v - vThre;
            ll triangle = 0;
            for(int i = p; i <= piv - 1; i++){
                triangle += as[p - 1] - as[i];
            }
            printde(rem, triangle, rem * m <= triangle);
            if(rem * m <= triangle){
                ok = as[p - 1] <= as[piv] + m;
            }else{
                ll rem2 = rem * m - triangle;
                int width = piv - 1 - (p - 1) + 1;
                ok = as[p - 1] + ((rem2 + width - 1) / width) <= as[piv] + m;
                printde(as[p - 1] + ((rem2 + width - 1) / width), as[piv] + m);
            }
        }

        if(ok){
            in = piv;
        }else{
            out = piv;
        }
        printde(in, out);
    }
    cout << in + 1 << '\n';
}


Measured memory_bytes: 888
#include <cmath>
#include <iostream>
int main() {
  long long A, C;
  double B;
  std::cin >> A;
  std::cin >> B;
  C = (long long)floorl((long double)((A * B) / 10));
  C *= 10;
  A %= 100;
  C += (int)floor(A * B) % 10;
  std::cout << C;
  return 0;
}


Measured memory_bytes: 3764
def main():
    n, x, m = map(int, input().split())
    idx = [-1] * (m + 1)  # mで割った余り（0,1,...m-1）が何回目に出てきたか
    res = []  # 数列A

    for i in range(1, m + 3):  # 余りはm+1種類なのでm+2回計算すれば絶対ループが発生する
        if idx[x] == -1:  # 初めて
            idx[x] = i
            res.append(x)
            x = (x ** 2) % m
        else:  # 既出（ループ発見）
            len_loop = i - idx[x]
            len_head = idx[x] - 1
            break

    if n <= len_head + len_loop:  # 1ループ目までで出力する場合
        print(sum(res[:n]))
    else:
        ans = sum(res[:len_head])  # ループ前

        loop_count = (n - len_head) // len_loop
        ans += loop_count * sum(res[len_head:])  # ループ

        len_tail = (n - len_head) % len_loop
        ans += sum(res[len_head: len_head + len_tail])  # ループ後の余り

        print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 68924
#include <stdio.h>

int main(){
  int A,B,C,D;
  scanf("%d %d %d %d",&A,&B,&C,&D);
  
  while(1){
	C = C - B;
    if(0 >= C){
	  printf("Yes\n");
      break;
    }
    A = A - D;
    if(0 >= A){
	  printf("No\n");
      break;
    }
  }
  
  return 0;
}

Measured memory_bytes: 1644
#include <iostream>

int main()
{
  int five = 0;
  int seven = 0;
  for (int i = 0; i < 3; ++i)
  {
    int in;
    std::cin >> in;
    if (in == 5) ++five;
    if (in == 7) ++seven;
  }
  if (five == 2 && seven == 1)
  {
    std::cout << "YES" << std::endl;
  }
  else
  {
    std::cout << "NO" << std::endl;
  }
  return 0;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
#define pb push_back
#define st first
#define nd second
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
template <class T> T read(T &a) {
    a=0;char x=getchar();bool f=0;
    for(;x<'0'||x>'9';x=getchar())f|=x=='-';
	for(;x>='0'&&x<='9';x=getchar())a=(a<<3)+(a<<1)+x-'0';
    if(f)a=-a;
    return a;
}
using namespace std;

typedef pair<int, int> tp;

map<tp, LL> mp;

int main() {
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		double a;
		scanf("%lf", &a);
		a *= 1e9;
		LL b = llround(a);
		tp k;
		k.st = k.nd = 0;
		while (b % 5 == 0) {
			b /= 5;
			k.st++;
		} 
		while (b % 2 == 0) {
			b /= 2;
			k.nd++;
		}
		mp[k]++;
	}
	map<tp, LL>::iterator i, j;
	int ci, cj;
	LL ans = 0;
	for (i = mp.begin(), ci = 0; i != mp.end(); ++i, ++ci) {
		for (j = mp.begin(), cj = 0; j != mp.end(); ++j, ++cj) {
			tp a = i->first, b = j->first;
			if (a.st + b.st >= 18 && a.nd + b.nd >= 18) {
				if (ci < cj) ans += i->second * j->second;
				if (ci == cj) ans += i->second * (i->second - 1) / 2;
			}
		}
	}
	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3796
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.StringTokenizer;

public class Main {



	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		int n = sc.nextInt();
		int m = sc.nextInt();

		int[][] g = new int[n][m];

		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				g[i][j] = sc.nextInt() - 1;
			}
		}

		for (int i = 1; i <= n; i++) {
			int[] p = new int[n];
			boolean[] f = new boolean[m];
			int[] count = new int[m];

			for (int j = 0; j < n; j++) 
				count[g[j][0]]++; 

			for (int j = 0; j < m; j++) {
				if(count[j] > i)
					f[j] = true;
			}


			while(true) {

				for (int j = 0; j < n; j++) {
					while(p[j] < m && f[g[j][p[j]]]) {
						p[j]++;
						if(p[j] < m) {
							count[g[j][p[j] - 1]]--;
							count[g[j][p[j]]]++;
						}
					}
				}
				
				
				boolean can = true;
				boolean finish = true;
				for (int j = 0; j < n; j++) {
					if(p[j] == m) {
						can = false;
					}
				}
				
				for (int j = 0; j < m; j++) {
					if(count[j] > i) {
						f[j] = true;
						finish = false;
					}
				}
				
				if(!can)
					break;
				
				if(finish) {
					out.println(i);
					out.flush();
					return;
				}
			}
		}

		out.flush();
	}


	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public String next() throws IOException {
			while(st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}
	}	

}

Measured memory_bytes: 31348
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
    string s;
    cin >> s;
    vector<int> dpa(s.size() + 1);
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '<')dpa[i + 1] = dpa[i] + 1;
    }
    vector<int> dpb(s.size() + 1);
    for (int i = s.size(); i > 0; i--) {
        if (s[i - 1] == '>')dpb[i - 1] = dpb[i] + 1;
    }

    long long ret = 0;
    for (int i = 0; i < s.size() + 1; i++)ret += max(dpa[i], dpb[i]);
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 4740
#include<stdio.h>
int main()
{
    int N,i,x;
    scanf("%d", &N);
    for(i=1;i<=9;i++)
    {
        if(N%i==0)
        {
            x=N/i;
        }
    }
    if(x>=1&&x<=9)
        
        {
        printf("Yes");
        }
    else
        {
        printf("No");
        }
    return 0;
}

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

typedef long long int Long;
typedef long double Double;
const int MAXN = 1e5 + 4;

int n;
pair<int,int> A[MAXN];

int main() {
	scanf("%d", &n);
	for(int i = 0; i < n; ++i)
		scanf("%d%d", &A[i].first, &A[i].second);
	sort(A, A + n);

	int ans = A[0].first;
	for(int i = 1; i < n; ++i) {
		ans += A[i].first - A[i - 1].first - 1;
		++ans;
	}

	if(A[n - 1].second != 0) {
		ans += A[n - 1].second;
	}

	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll k, a, b;
    cin >> k >> a >> b;
 
    if(k <= a || b <= a+2) {
        out(k+1);
        re0;
    }
    
    ll cnt = a+1;  // いまの操作回数
    ll m = (k - cnt)/2;
    if(cnt%2 == k%2) {
        out(m*(b-a) + b);
    }
    else {
        out(m*(b-a) + b + 1);
    }
 
    re0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP0(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define REPB0(i,n) for(int i=n-1;i>=0;i--)
#define REPB1(i,n) for(int i=n;i>0;i--)
#define llong long long
#define INF 2000000000
#define NIL -1
#define N 1000
using namespace std;
int LCS(string X,string Y){
  int C[N+1][N+1];
  int m=X.size();
  int n=Y.size();
  int maxl=0;
  X=' '+X;
  Y=' '+Y;
  C[0][0]=0;
  REP1(i,m) C[i][0]=0;
  REP1(i,n) C[0][i]=0;
  REP1(i,m){
    REP1(j,n){
      if(X[i]==Y[j]) C[i][j]=C[i-1][j-1]+1;
      else C[i][j]=max(C[i-1][j],C[i][j-1]);
      maxl=max(maxl,C[i][j]);
    }
  }
  return maxl;
}
int main(){
  char a[1000],b[1000];
  string s1,s2;
  int n;
  scanf("%d",&n);
  REP0(i,n){

    scanf("%s %s",a,b);
    s1=a;s2=b;
    printf("%d\n",LCS(s1,s2));
  }
  return 0;
}

Measured memory_bytes: 7052
from collections import deque

H, W = map(int, input().split())

grid = [[-1]*W for _ in range(H)]

queue = deque([])

ans = 0

# while True:
#     f = 0
for i in range(H):
    s = input()
    for j, ss in enumerate(s):
        if ss =="#":
            queue.append((i, j))
            grid[i][j] = 0

#黒点をスタート地点とし、上下左右に移動した時の移動距離を記録していく
while queue:
    h, w = queue.popleft()
    for i in [h-1, h+1]:
            if i >= 0 and i < H:
                if grid[i][w] == -1:
                    grid[i][w] = grid[h][w]+1
                    queue.append((i, w))
    for j in [w-1, w+1]:
        if j >= 0 and j < W:
            if grid[h][j] == -1:
                grid[h][j] = grid[h][w]+1
                queue.append((h, j))

# print(grid)
print(max([max(b) for b in grid]))


Measured memory_bytes: 85980
<?php
$right = trim(fgets(STDIN));
$left = "";
$num = trim(fgets(STDIN));
$rev_flg = false;
for($i=0; $i<$num; $i++){
	$q = trim(fgets(STDIN));
	if($q==1){
		$rev_flg = !$rev_flg;
	}else{
		list($a, $f, $st) = explode(" ", $q);

		if($rev_flg == false){
			if($f==1){
				$left = $left . $st;
			}else{
				$right = $right . $st;
			}
		}else{
			if($f==1){
				$right = $right . $st;
			}else{
				$left = $left . $st;
			}
		}
	}
}

$str = strrev($left) . $right;
$str = $rev_flg == false ? $str : strrev($str);

echo $str . "\n";

Measured memory_bytes: 4856
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>

using namespace std;

typedef long long LL;
typedef vector<LL> VL;
#define REPD(i,a,b) for (LL i=(a);i<(b);i++)
#define REP(i,n) REPD(i,0,n)

LL inputValue(){
  LL a;
  cin >> a;
  return a;
};

string inputString(){
  string a;
  cin >> a;
  return a;
};

vector<LL> inputVector(LL a){
  vector<LL> rv;
  REP(i, a){
    LL input;
    cin >> input;
    rv.push_back(input);
  }
  return rv;
}

vector<string> inputVectorString(LL a){
  vector<string> rv;
  REP(i, a){
    string input;
    cin >> input;
    rv.push_back(input);
  }
  return rv;
}
vector<vector<LL>> inputVector2D(LL a, LL b){
  vector<vector<LL>> rv;
  REP(i, a){
    rv.push_back(vector<LL>());
    REP(j, b) {
      LL input;
      cin >> input;
      rv.at(i).push_back(input);
    }
  }
  return rv;
}

#if 0
#define debug(d) debug1(__LINE__,#d, d)
void debug1(LL line, const char* name, vector<LL>& v) {
  cout << line << ":" << name << ":vector<LL>(" << v.size() << ") ";
  REP(i, (LL)v.size()) {
    cout << v.at(i) << " ";
  }
  cout << endl;
}
void debug1(LL line, const char* name, LL i) {
  cout << line << ":" << name << ":LL " << i << endl;;
}
void debug1(LL line, const char* name, vector<string>& v) {
  cout << line << ":" << name << ":vector<string>(" << v.size() << ") ";
  REP(i, (LL)v.size()) {
    cout << v.at(i) << " ";
  }
  cout << endl;
}
void debug1(LL line, const char* name, vector<vector<LL>>& v) {
  cout << line << ":" << name << ":vector<vector<LL>>(" << v.size() << ") ";
  REP(i, (LL)v.size()) {
    REP(j, (LL)v.at(i).size()) {
      cout << v.at(i).at(j) << " ";
    }
    cout << ", ";
  }
  cout << endl;
}
#else
#define debug(n)
#endif

int main(int argc, const char * argv[]) {
	cout.precision(16);
  // source code

  auto s = inputString();

  bool easy = true;
  REP(i, s.size()) {
    if (i%2 == 0) {
      if (s[i] != 'R' &&
          s[i] != 'U' &&
          s[i] != 'D') {
        debug(i);
        easy = false;
      }
    } else {
      if (s[i] != 'L' &&
          s[i] != 'U' &&
          s[i] != 'D') {
        debug(i);
        easy = false;
      }
    }
  }
  cout << (easy ? "Yes" : "No") << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

class Main {
	double[][] p = new double[2][6];

	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		long[] w = new long[n];
		for (int i = 0; i < n; ++i) {
			w[i] = sc.nextLong();
		}
		@SuppressWarnings("unchecked")
		ArrayList<Integer>[] g = new ArrayList[n];
		for (int i = 0; i < n; ++i)
			g[i] = new ArrayList<>();
		int[] deg = new int[n];
		for (int i = 0; i < m; ++i) {
			int u = sc.nextInt() - 1;
			int v = sc.nextInt() - 1;
			g[u].add(v);
			g[v].add(u);
			++deg[u];
			++deg[v];
		}

		long[] f = new long[n];

		ArrayDeque<Integer> dq = new ArrayDeque<>();
		for (int i = 0; i < n; ++i) {
			if (deg[i] == 1 && i != 0) {
				dq.add(i);
			}
		}

		long ans = 0;
		while (!dq.isEmpty()) {
			int v = dq.pollFirst();
			for (int dst : g[v]) {
				if (deg[dst] == 0)
					continue;
				f[dst] = Math.max(f[dst], f[v] + w[v]);
				ans = Math.max(ans, f[dst]);
				--deg[dst];
				--deg[v];
				if (dst != 0 && deg[dst] == 1) {
					dq.addLast(dst);
				}
			}
		}

		for (int i = 0; i < n; ++i) {
			if (i == 0 || deg[i] > 0)
				ans += w[i];
		}
		System.out.println(ans);
	}

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


Measured memory_bytes: 120348
n = int(input())
list_a = []
list_b = []
list_a = list(map(int,input().split()))
list_b = list(map(int,input().split()))

x = 0
a = list_a[n]
for i in range(n):
    ii = n - i -1
    if list_a[ii] + a <= list_b[ii]:
        x += list_a[ii] + a
        a = 0
    elif a <= list_b[ii]:
        a = list_a[ii] + a - list_b[ii]
        x += list_b[ii]
    else:
        a = list_a[ii]
        x += list_b[ii]

print(x)

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

int main() {
  int N;
  std::cin >> N;

  std::vector<int> A(N);

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

  sort(A.begin(), A.end());

  for (int i = 0; i < N - 1; i++) {
    if (A[i+1] * 2 > A[A.size() - 1]) {
      std::cout << A[A.size() - 1] << " " << (A[i] >= A[A.size() - 1] - A[i+1] ? A[i] : A[i+1]) << std::endl;
      break;
    }
  }
}


Measured memory_bytes: 640
// include
#include <iostream>
#include <stdio.h>
#include<string.h>
#include<vector>
#include<string>
using namespace std;

// define, typedef
#define rpt(i, n) for(i = 0; i < (n); i++)
typedef long long ll;


int main(void) {
	int i = 0;
	string sa, sb, sc;
	char p = 'a';
	cin >> sa >> sb >> sc;

	while (true) {
		switch (p) {
			case 'a':
				if (sa.empty() == true) {
					cout << 'A';
					i = 1;
				}
				else {
					p = sa[0];
					sa.erase(sa.begin());
				}
				break;
			case 'b':
				if (sb.empty() == true) {
					cout << 'B';
					i = 1;
				}
				else {
					p = sb[0];
					sb.erase(sb.begin());
				}
				break;
			case 'c':
				if (sc.empty() == true) {
					cout << 'C';
					i = 1;
				}
				else {
					p = sc[0];
					sc.erase(sc.begin());
				}
				break;
		}
		if (i == 1) {
			break;
		}
	}

	return 0;
}

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

int main()
{
    int n; cin>>n;
    vector<int> p(n); for(auto& e: p) cin>>e;

    int res=0;
    for(int i=0; i+2<n; ++i) {
        int a=min({p[i], p[i+1], p[i+2]});
        int b=max({p[i], p[i+1], p[i+2]});
        if (p[i+1]!=a and p[i+1]!=b) ++res;
    }
    cout<<res<<endl;
}


Measured memory_bytes: 256
N = int(input())
p = list(map(int, input().split()))
res = 0
for i in range(N-2):
  if p[i] < p[i+1] < p[i+2]:
    res += 1
  elif p[i] > p[i+1] > p[i+2]:
    res += 1
print (res)

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main(){

    int h,w;
    int sum;
    while(cin >> h >> w, h!=0 && w!=0){
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                sum = (i+j);
                if(sum%2 == 0){
                    cout << "#";
                }else cout << ".";
            }
            cout << endl;
        }
        cout << endl;
    }
return 0;
}

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

using namespace std;
using ll = long long;
// constexpr int MOD = 1e9+7;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Vec2(T, n, m, xs) vector<vector<T>> xs(n, vector<T>(m))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) for(const auto &e : xs) cout << e << " "; cout << "\n"
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")

int main(void){
    int ans = 0, a = 0;
    Cin(string, s);
    for(const auto &c : s){
        if(c == 'A' || c == 'T' || c == 'G' || c == 'C'){
            a ++;
        }
        else{
            ans = max(ans, a);
            a = 0;
        }
    }
    ans = max(ans, a);
    Cout(ans);
}

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

//型定義
typedef long long ll;

//定数
const int INF=1e+9;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

// xのn乗%modを計算
ll mod_pow(ll x, ll n, ll mod){
    ll res = 1;
    while(n > 0){
        if(n & 1) res = res*x%mod;
        x = x*x%mod;
        n >>= 1;
    }
    return res;
}

int main(){
    ll N,K;
    cin>>N>>K;
    vector<ll> A(N);
    vector<ll> minus;
    vector<ll> plus;
    ll cnt0=0;
    

    REP(i,N){
        cin>>A[i];
        if(A[i]==0) cnt0++;
        if(A[i]>=0){
            plus.push_back(A[i]);
        }
        if(A[i]<0){
            minus.push_back(-A[i]);
        }
    }
    ll ans;
    sort(ALL(A),greater<ll>());
    sort(ALL(plus),greater<ll>());
    sort(ALL(minus),greater<ll>());
    
    if(N==K||plus.size()==0){
        ans=1;
        if(K%2==0){
            sort(ALL(A));
            
            REP(i,K){
                ans*=A[i];
                ans%=MOD;
            }
        }else{
            REP(i,K){
                ans*=A[i];
                ans%=MOD;
            }
        }
    }else if(plus.size()==1&&K%2==0){
        minus.push_back(plus[0]);
        sort(ALL(minus));
        ans=1;
        REP(i,K){
            ans*=minus[i];
            ans%=MOD;
        }
    }else{//答えがプラス
        if(K%2==0){
            ans=1;
            vector<ll> MINUS;
            REP(i,minus.size()){
                if(2*i+1>=minus.size()) break;
                MINUS.push_back(minus[2*i]*minus[2*i+1]);
            }

            REP(i,plus.size()){
                if(2*i+1>=plus.size()) break;
                MINUS.push_back(plus[2*i]*plus[2*i+1]);
            }
            sort(ALL(MINUS),greater<ll>());
            REP(i,K/2){
                ans*=MINUS[i]%MOD;
                ans%=MOD;
            }
        }else{
            ans=plus[0];
            vector<ll> MINUS;
            REP(i,minus.size()){
                if(2*i+1>=minus.size()) break;
                MINUS.push_back(minus[2*i]*minus[2*i+1]);
            }

            REP(i,plus.size()){
                if(2*i+2>=plus.size()) break;
                MINUS.push_back(plus[2*i+1]*plus[2*i+2]);
            }
            sort(ALL(MINUS),greater<ll>());
            REP(i,(K-1)/2){
                ans*=MINUS[i]%MOD;
                ans%=MOD;
            }

        }
        
        
    }

    while(ans<0){
        ans+=MOD;
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 8160
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    int n;
    cin>>n;
    string s[n];
    for(int i=0;i<n;++i){
        cin>>s[i];
        sort(s[i].begin(),s[i].end());
    }
    map<string,int> map;
    for(int i=0;i<n;++i){
        ++map[s[i]];
    }
    ll ans=0;
    for(auto i:map){
        ll t=i.second;
        ans+=t*(t-1)/2;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 18176
#include<bits/stdc++.h>
#define INF 9223372036854775807LL
#define inf 1000000007
#define lol long long
#define abs(x,y) (max(x,y)-min(x,y))
#define mp make_pair
#define fi first
#define se second
using namespace std;
lol a,b,c;
int x[100001],y[100001];
bool an[10];
bool o[10][10];
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  lol d=0,e=0,f=0;
  string s;
  cin >>a;
  for(int n=1;n<=a;n++){
    e=n*1.08;
    if(e==a){
      cout <<n<<'\n';
      return 0;
    }
  }
  cout <<":(\n";
  return 0;
}


Measured memory_bytes: 256
from collections import defaultdict
from sys import stdin
input = stdin.readline


def prime_fatorization(n):
  # O(sqrt(n))
  # a = []
  a = defaultdict(int)
  while not(n % 2):
    # a.append(2)
    a[2] += 1
    n //= 2
  f = 3
  while f * f <= n:
    if not(n % f):
      # a.append(f)
      a[f] += 1
      n //= f
    else:
      f += 2
  if n != 1:
    # a.append(n)
    a[n] += 1
  return a


def main():
  A, B = list(map(int, input().split()))

  aprime = prime_fatorization(A)
  bprime = prime_fatorization(B)

  aset = set(aprime.keys())
  bset = set(bprime.keys())

  print(1+len(aset & bset))


if(__name__ == '__main__'):
  main()


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

#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 // 10^9+7
#define INF 99999999999 //10^12-1
#define dev 998244353 //tenka1
#define P pair<int,int>
#define F first
#define S second
int a,b;
signed main(){
    cin>>a>>b;
    b*=2;
    int ans=max((int)(0),a-b);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		String s = String.valueOf(n);
		String[] a = s.split("");
		boolean judge = false;
		
		for(int i = 0; i < a.length; i++) {
			if(a[i].equals("7")) {
				judge = true;
				break;
			}
		}
		if(judge == true) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}

}


Measured memory_bytes: 35684
#include <iostream>
#include <cstdio>
#include <cstring>
#define N 100005
using namespace std;
struct edge{
	int k,next;
}e[N<<1];
int n,home[N],cnt=-1,IN[N],s[N],top,fa[N],col[N];
void add(int x,int y){
	cnt++;
	e[cnt].k=y;
	e[cnt].next=home[x];
	home[x]=cnt;
}
void dfs(int k,int F){
	fa[k]=F;
	for(int i=home[k];~i;i=e[i].next) if(e[i].k!=F){
		dfs(e[i].k,k);
	}
}
bool solve(){
	int x,y;
	while(top){
		x=s[top];y=fa[x];
		if(col[x]){
			top--;continue;
		}
		if(col[y]) return 1;
		col[y]=1;
		IN[fa[y]]--;
		top--;
		if(IN[fa[y]]==1) s[++top]=fa[y];
	}
	return 0;
}
int main(){
	memset(home,-1,sizeof(home));
	scanf("%d",&n);
	if(n==2) return puts("Second"),0;
	for(int i=1,x,y;i<n;i++){
		scanf("%d%d",&x,&y);
		add(x,y);add(y,x);
		IN[x]++;IN[y]++;
	}
	int S;
	for(int i=1;i<=n;i++)
		if(IN[i]==1) s[++top]=i;
		else S=i;
	dfs(S,0);
	if(solve()) puts("First");
	else puts("Second");
	return 0;
}

Measured memory_bytes: 3584
//----------------------------templates
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("tune=native")
    #pragma GCC target ("avx")
    //----------------------------
    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef unsigned long long ull;
    #define int ll

    #define FOR(i,j,n) for (int i=(int)(j);i<(n);i++)
    #define REP(i,n) for (int i=0;i<(int)(n);i++)
    #define REPS(i,n) for (int i=1;i<=(int)(n);i++)
    #define REPN(i,n) for (int i=(int)(n)-1;i>=0;i--)
    #define REPNS(i,n) for (int i=(int)(n);i>0;i--)

    #define I(n) scanf("%lld", &(n))
    #define LL(n) scanf("%lld", &(n))
    #define pb(n) push_back((n))
    #define mp(i,j) make_pair((i),(j))
    #define eb(i,j) emplace_back((i),(j))
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define uniq(v) v.erase( unique(v.begin(), v.end()), v.end() )

    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())

    typedef vector<int> vi;
    typedef pair<int,int> pi;
    typedef vector<pi> vpi;
    typedef vector<vi> vvi;
    typedef vector<vpi> vvpi;
    typedef vector<vvi> vvvi;

    const int mod = 1000000007;

//--------------------------------------------

int a[9],n,b;

signed main(){
    REP(i,9) I(a[i]);
    I(n);
    REP(i,n) {
        I(b);
        REP(j,9) if (a[j] == b) a[j] = 0;
    }

    bool bingo = 
        (!(a[0] || a[1] || a[2])) ||
        (!(a[3] || a[4] || a[5])) ||
        (!(a[6] || a[7] || a[8])) ||
        (!(a[0] || a[3] || a[6])) ||
        (!(a[1] || a[4] || a[7])) ||
        (!(a[2] || a[5] || a[8])) ||
        (!(a[0] || a[4] || a[8])) ||
        (!(a[2] || a[4] || a[6]));
    cout << (bingo ? "Yes" : "No") << endl; 
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int a,b,c;
    int i,j=0;
    scanf("%d %d %d",&a,&b,&c);
    for(i=a;i<=b;i++){
        if(c%i==0){
            j++;
        }
    }
    printf("%d\n",j);
}


Measured memory_bytes: 2112
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<int,P> PP;

vector<PP> v;
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

int main()
{
	int n,d;
	string s;
	cin >> n >> d;
	double data[n][d];
	rep(i,n){
		rep(j,d){
			cin >> data[i][j];
		}
	}
	int ans = 0;
	rep(i,n){
		for(int j = i+1; j<n;j++){
			double kyori = 0;
			rep(k,d){
				kyori += (data[i][k] - data[j][k]) * (data[i][k] - data[j][k]);
			}
			if(sqrt(kyori) == (int)sqrt(kyori)){
				ans++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
/*      西江月·证明
	即得易见平凡，仿照上例显然。
   留作习题答案略， 读者自证不难。

	反之亦然同理，推论自然成立。
	略去过程QED，由上可知证毕。*/
# pragma GCC optimize (1)
# pragma GCC optimize (2)
# pragma GCC optimize (3)
# pragma GCC optimize ("Ofast")
#include<iostream>
#include<queue>
#include<algorithm>
#include<cstdio>
#define kkk register
#define ll long long
#define inf 2147098934832ll
using namespace std;
ll read(){ll ans=0,f=1;char a=getchar();while(a>'9'||a<'0'){if(a=='-')f=-1;a=getchar();}while(a>='0'&&a<='9')ans=(ans<<3)+(ans<<1)+a-'0',a=getchar();return ans*f;}
//一条long long的黄金分割线-----------------------------------------------------------------------------------------------------------------------------------
ll n,ans;
int main(){
	n=read();
	for(int i=1;i<=n;i++){
		ll k=n/i;
		ans+=k*(k+1ll)*i/2;
	}
	cout<<ans;
	return 0; 
} 

Measured memory_bytes: 3620
import java.util.*;
import java.lang.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) {
        //コード
        Scanner scanner = new Scanner(System.in);
        Integer n = Integer.parseInt(scanner.next());

        Integer[] p = new Integer[n];
        for(int i = 0; i < n; i++) {
            p[i] = Integer.parseInt(scanner.next());
        }

        int count = 0;
        for(int i = 1; i < n -1; i++) {
            if(p[i-1] < p[i] != p[i] > p[i+1]) {
                count++;
            }
        }

        System.out.println(count);
    }
}

Measured memory_bytes: 23764
import sys

input = sys.stdin.buffer.readline

n, s = map(int, input().split())
A = list(map(int, input().split()))
mod = 998244353
dp = [[0] * (s + 1) for _ in range(n + 1)]
dp[0][0] = 1

for i in range(n):
    ni = i + 1
    for j in range(s + 1):
        nj = j
        dp[ni][nj] += 2 * dp[i][j]
        dp[ni][nj] %= mod
        nj = j + A[i]
        if nj <= s:
            dp[ni][nj] += dp[i][j]
            dp[ni][nj] %= mod
print(dp[n][s] % mod)


Measured memory_bytes: 135528
local N = io.read("n")
local A = {}
for i=1, N do
    A[i] = io.read("n")
end

local box = {}
for i=N, 1, -1 do
    local k = i
    local bi = A[i]
    for n=2,1000000 do
        k = k + i
        if k > N then
            break
        end
        bi = bi ~ box[k]
    end
    box[i] = bi
end
local M = 0
for i=1,N do
    if box[i] == 1 then
        M = M + 1
    end
end
print(M)
if M == 0 then return end
local sb = {}
for i=1,N do
    if box[i] == 1 then
        table.insert(sb, tostring(i))
    end
end
print(table.concat(sb, " "))


Measured memory_bytes: 20068
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        char[] s = sc.next().toCharArray();

        int result = 0;
        int max = 0;
        for (char c : s) {
            if ('A' == c || 'C' == c || 'G' == c || 'T' == c) {
                max++;
            } else {
                result = Math.max(result, max);
                max = 0;
            }
        }
        if (max > 0) {
            result = Math.max(result, max);
        }

        System.out.println(result);
    }
}

Measured memory_bytes: 23508
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#include <functional>
#include <set>
#define DB cerr<<"D"<<endl
#define pb push_back
using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
template<typename T, typename U, typename O> void caut(T a, U b, O c){cout<<"("<<a<<","<<b<<","<<c<<") ";} template<typename T, typename U> void caut(T a, U b){cout<<"("<<a<<","<<b<<") ";} template<typename T> void caut(T a){cout<<"("<<a<<") ";}
using P=pair<int,int>;
const ll M = 1e9+7, mx = 200000;
void add(ll& x, ll y) {x+=y; x%=M;}
void chmax(ll& x, ll y) {if (x<y) x=y;}

const int up[]={1,-1,0,0}, lf[]={0,0,1,-1};
bool vaild(int x, int y, int hh, int ww){return 0<=x&&x<hh&&0<=y&&y<ww;}

struct tup {
  ll x,y,c;
  bool operator<(const tup tt) const {
    if (c != tt.c) return c < tt.c;
    else if (x != tt.x) return x < tt.x;
    else return y < tt.y;
  }
  bool operator>(const tup tt) const {
    if (c != tt.c) return c > tt.c;
    else if (x != tt.x) return x > tt.x;
    else return y > tt.y;
  }
};

#include <random>
#include <ctime>

namespace r {
    random_device rd;
    mt19937 mt(rd());
    //mt19937 mt(time(NULL));
    int nd(int max) {return mt() % max + 1;}
    int nd2(int min, int max) {return mt() % (max - min + 1) + min;}
}

int main() {
  int h,w,k;
  //h=100, w=100, k=100;
  cin>>h>>w>>k;
  int fx,fy,lx,ly;
  cin>>fx>>fy>>lx>>ly; fx--; fy--; lx--; ly--;
  //fx=0, fy=0, lx=h-1, ly=w-1;

  string s[h];
  for(int i=0;i<h;i++) cin>>s[i];

  /*for(int i=0;i<h;i++) {
    s[i].assign('a',w);
    for(int j=0;j<w;j++) {
      if (i==fx&&j==fy||i==lx&&j==ly) s[i][j]='.';//cout<<".";
      else if (r::nd(5)==1) s[i][j]='@';
      else s[i][j]='.';
    }
  }*/

  ll an[h][w]; fill(an[0],an[h],LINF);
  queue<tup> que;
  an[fx][fy]=0; que.push({fx,fy,0});

  while(!que.empty()) {
    tup tp = que.front(); que.pop();
    int cs = tp.c+1;
    for(int i=0;i<4;i++) {
      int nx = tp.x, ny = tp.y;
      for(int j=0;j<k;j++) {
        nx+=up[i]; ny+=lf[i];
        if (vaild(nx,ny,h,w) && s[nx][ny]=='.') {
          if (cs < an[nx][ny]) {
            an[nx][ny]=cs;
            que.push({nx,ny,cs});
          } else if (cs == an[nx][ny]){
            an[nx][ny]=cs;
          } else {
            break;
          }
        } else {
          break;
        }
      }
    }
  }
  /*
  for(int i=0;i<h;i++) {
    for(int j=0;j<w;j++) {
      cout<<an[i][j]<<" ";
    }cout<<endl;
  }*/
  if (an[lx][ly] == LINF) {
    cout<<-1<<endl;
  } else {
    cout<<an[lx][ly]<<endl;
  }
}

Measured memory_bytes: 15228
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pi = pair<int, int>;
const int MAXN = 200005;
const int mod = 1e9 + 7;

lint n, m;

bool trial(lint x){
	lint lec = m - 2 * x;
	return lec >= 0 && lec / 2 + n >= x;
}

int main(){
	cin >> n >> m;
	lint s = 0, e = 1e13;
	while(s != e){
		lint m = (s+e+1) / 2;
		if(trial(m)) s = m;
		else e = m-1;
	}
	cout << s << endl;
}


Measured memory_bytes: 256
if __name__ == '__main__':
    TC = int(input())
    for _ in range(TC):
        maxDist = 0
        treasureX = 0
        treasureY = 0
        posX = 0
        posY = 0
        while True:
            x, y = [ int(x) for x in list(filter(lambda x: x != '', \
                input().strip().split(' '))) ]
            if x == 0 and y == 0:
                break
            posX += x
            posY += y
            dist = posX * posX + posY * posY
            if dist > maxDist or (dist == maxDist and posX > treasureX):
                maxDist = dist
                treasureX = posX
                treasureY = posY
        print(treasureX, treasureY)


Measured memory_bytes: 5612
// Package main provides
//
// File:  a.go
// Author: ymiyamoto
//
// Created on Wed Dec 26 21:24:13 2018
//
package main

import "fmt"

func abs(a int) int {
	if a <= 0 {
		return -a
	}
	return a
}

func main() {
	var a, b, c, d int
	fmt.Scan(&a, &b, &c, &d)
	if (abs(a-b) <= d && abs(b-c) <= d) || abs(a-c) <= d {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
/*
S[1] = T[1]なら何もしない。そうでないならS[1]をT[1]に変更。SにS[1]orT[1]が他にも含まれるならそれも変更
以降S[k]について同様の操作を繰り返す。S[k]の変更に伴ってi < kを満たすS[i]を変更することになったらアウト
*/

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

int main()
{
  string S, T;
  cin >> S >> T;
 
  for(int i = 0; i < S.length(); ++i)
  {
    if(S[i] == T[i])
    {
      continue;
    }
    
    char c1 = S[i];
    char c2 = T[i];
    
    for(int j = 0; j < S.length(); ++j)
    {
      bool changed = false;
      if(S[j] == c1)
      {
        S[j] = c2;
        changed = true;
      }
      else if(S[j] == c2)
      {
        S[j] = c1;
        changed = true;
      }
      
      if(changed && j < i)
      {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  
  cout << "Yes" << endl;
  return 0;
}    

Measured memory_bytes: 904
n,a,b=map(int,input().split())
mod = 10**9+7
comb1=1
for i in range(n-a+1,n+1):
  comb1*=i
  comb1%=mod
for i in range(1,a+1):
  comb1*=pow(i,mod-2,mod)
  comb1%=mod
comb2=1
for i in range(n-b+1,n+1):
  comb2*=i
  comb2%=mod
for i in range(1,b+1):
  comb2*=pow(i,mod-2,mod)
  comb2%=mod
print((pow(2,n,mod)-1-comb1-comb2)%mod)

Measured memory_bytes: 3064
#include<algorithm>
#include<iomanip>
#include<iostream>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<vector>
#include<bitset>
#include<cmath>
#define FOR(i,a,b) for(int i=(a); i<int(b); ++i)
#define RFOR(i,a,b) for(int i=(b)-1; i>=int(a); --i)
#define rep(i,n) FOR(i,0,n)
#define rep1(i,n) FOR(i,1,int(n)+1)
#define rrep(i, n) RFOR(i, 0, n)
#define rrep1(i, n) RFOR(i, 1, int(n) + 1)
#define all(c) begin(c), end(c)
#define al(d) d.begin(),d.end()
#define fill(n) std::setfill('0')<<std::right<<std::setw(n)
template <typename T>
using vec = std::vector<T>;
using vi = vec<int>;
using vvi = vec<vi>;
using pii = std::pair<int, int>;
using ll = long long;
using ld = long double;
using namespace std;
const int MOD = 1000000007;

template <typename T>
void putv(vector<T>& V){
	// cout << "The elements in the vector are: " << endl;
	for(auto x: V)
		cout << x << " ";
	cout << endl;
}
template <class T>
vector<T> getv(int n){
	vector<T> vec;
	rep(i,n){
		T input;
		cin >> input;
		vec.emplace_back(input);
	}
	return vec;
}

using AdjList = vector<vector<int>>;
using Weight = int;
using Flow = int;
struct Edge {
	int src, dst;
	Weight weight;
	Flow cap;
	Edge() : src(0), dst(0), weight(0) {}
	Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) {}
};
using Edges = std::vector<Edge>;
using Graph = std::vector<Edges>;
using Array = std::vector<Weight>;
using Matrix = std::vector<Array>;
void add_edge(Graph &g, int a, int b, Weight w = 1) {
	g[a].emplace_back(a, b, w);
	g[b].emplace_back(b, a, w);
}
void add_arc(Graph &g, int a, int b, Weight w = 1) { g[a].emplace_back(a, b, w); }
// Recieve edge(=(int,int)) as an adj list.
AdjList getadj(int N, int M){
	// Initialize all lists of the graph as a empty vector.
	vector<int> init;
	vector<vector<int>> graph(N,init);
	rep(i,M){
		int a, b;
		cin >> a >> b;
		graph[a-1].emplace_back(b-1);
		graph[b-1].emplace_back(a-1);
	}
// rep(i,N)
//  putv(graph[i]);
	return graph;
}
void out(bool ans){
	if(ans == true) cout << "yes" << endl;
	else cout << "no" << endl;
}
void Out(bool ans){
	if(ans == true) cout << "Yes" << endl;
	else cout << "No" << endl;
}
void OUT(bool ans){
	if(ans == true) cout << "YES" << endl;
	else cout << "NO" << endl;
}
ll gcd(const ll a, const ll b){
	return (b==0) ? a : gcd(b,a%b);
}
ll lcm(const ll a, const ll b){
	return a*(b/gcd(a,b));
}
ll Manhattan_dist(ll x1, ll y1, ll x2, ll y2){
	return abs(x1-x2) + abs(y1-y2);
}
// nをpで何回割れるか
ll hmt_p_divide_n(ll p, ll n){
	ll s = 0;
	while(n%p == 0){
		n /= p;
		s++;
	}
	return s;
}
int digit(ll n){
	int cntr = 0;
	while(n>0){
		n/=10;
		cntr++;
	}
	return cntr;
}


int main(){
	int N;
	cin >> N;
	vi b = getv<int>(N);
	vi ans;

	// putv(b);

	rep(j,N)
		for(int i=b.size()-1; i>=0; --i){
			if(b[i]==i+1){
				b.erase(b.begin()+i);
				ans.emplace_back(i+1);
				break;
			}
		}
	if(b.size()>0){
		cout << -1 << endl;
		return 0;
	}
	// cout << "b: "; 
	// putv(b);
	reverse(all(ans));
	rep(i,ans.size()) cout << ans[i]<<endl;

}



Measured memory_bytes: 256