akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

ostream& operator<<(ostream &out, string str) {
	for(char c : str) cout << c;
	return out;
}

template<class L, class R> ostream& operator<<(ostream &out, pair<L, R> p) {
	return out << "(" << p.first << ", " << p.second << ")";
}

template<class T> auto operator<<(ostream &out, T a) -> decltype(a.begin(), out) {
	out << "{";
	for(auto it = a.begin(); it != a.end(); it = next(it))
		out << (it != a.begin() ? ", " : "") << *it;
	return out << "}";
}

void dump() { cerr << "\n"; }
template<class T, class... Ts> void dump(T a, Ts... x) {
	cerr << a << ", ";
	dump(x...);
}

#ifdef DEBUG
#  define debug(...) cerr << "[" #__VA_ARGS__ "]: ", dump(__VA_ARGS__)
#else
#  define debug(...) false
#endif

#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define ST first
#define ND second

template<class T> int size(T && a) {
	return a.size();
}

using LL = long long;
using PII = pair<int, int>;

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

	int n, d;
	cin >> n >> d;

	vector<vector<int>> pos(n, vector<int>(d));
	REP(i, n) REP(j, d)
		cin >> pos[i][j];

	auto get_dist = [&](vector<int> a, vector<int> b) {
		LL total = 0;
		REP(i, d) {
			total += 1LL *(a[i] - b[i]) * (a[i] - b[i]);
		}

		LL d = sqrt(total);
		return (d * d == total);
	};

	int ans = 0;
	REP(i, n) REP(j, i)
		ans += get_dist(pos[i], pos[j]);

	cout << ans << "\n";
}


Measured memory_bytes: 256
// Practice AtCoder
// author:Leonardone @ NEETSDKASU

// 解説PDF読後

fn main() {
  let mut stdin = String::new();
  std::io::Read::read_to_string(&mut std::io::stdin(), &mut stdin). unwrap ();
  let mut stdin = stdin.split_whitespace();
  let mut get = || stdin.next(). unwrap ();
  macro_rules! get {
    ($t:ty) => (get().parse::<$t>(). unwrap ());
    () => (get!(i64));
  }
  let a = get!();
  let b = get!();

  let g = gcd(a,b);
  let ans = factors(g).len();
  println!("{}", ans);
}

fn gcd(a: i64, b: i64) -> i64 {
  if a==0 { b}
  else { gcd(b%a, a) }
}

fn factors(v: i64) -> Vec<i64> {
  let mut ret = vec![1];
  let mut v = v;
  for i in 2.. {
     if i*i > v { break; }
     if v % i == 0 {
       ret.push(i);
       while  v % i == 0 { v /= i; }
     }
  }
  if v > 1 { ret.push(v); }
  ret
}

Measured memory_bytes: 4352
def f(s):
  d=[-1]*-~n
  d[s]=0
  q=[s]
  while q:
    v=q.pop()
    c=d[v]+1
    for w in e[v]:
      if d[w]<0:
        d[w]=c
        q+=w,
  return d
n,u,v,*t=map(int,open(0).read().split())
e=[[]for _ in range(n+1)]
for a,b in zip(*[iter(t)]*2):
  e[a]+=b,
  e[b]+=a,
m=0
for a,b in zip(*map(f,(u,v))):
  if a<b:m=max(m,b-1)
print(m)

Measured memory_bytes: 82800
#include <cstdio>
const int MAXN = 105;
int seen[MAXN]{ };
int A, K, N, d;

int main() {
  scanf(" %d%d", &N, &K);
  for (int i = 0; i < K; ++i) {
    scanf("%d", &d);
    for (int j = 0; j < d; ++j) {
      scanf("%d", &A);
      seen[A] = true;
    }
  }
  int ret = 0;
  for (int i = 1; i <= N; ++i) {
    if (!seen[i]) ++ret;
  }
  printf("%d\n", ret);
  return 0;
}

Measured memory_bytes: 3224
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e5+5;
signed main(){
	int a,b,c;cin>>a>>b>>c;int num=0;
	for(int i=a;i<=b;i++){
		if(i%c==0)num++;
	}
	cout<<num<<"\n";
}

Measured memory_bytes: 3628
import java.util.Scanner;
import java.util.Arrays;
import java.util.stream.Stream;
import java.util.stream.IntStream;
import java.lang.StringBuilder;

public class Main {
  public static void main(String[] args ){
    Scanner sc = new Scanner(System.in);


    String N = sc.next();
    int[] cubes = new int[2];
    cubes[0] = 0;
    cubes[1] = 0;
    for(int i = 0; i < N.length(); i++) {
      int tmp =(int)(  N.charAt(i) - '0' );
      cubes[tmp] += 1;
    }

    System.out.println(Math.min(cubes[0], cubes[1]) * 2);
  }
}


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

int main() {
  // Grid Repainting 2
  int h, w; cin >> h >> w;
  vector<string> s(h);
  vector<vector<bool>> visited(h, vector<bool>(w));
  rep(i,h) cin >> s.at(i);

  vector<int> di = {1, 0, -1, 0};
  vector<int> dj = {0, 1, 0, -1};

  rep(i,h) {
    rep(j,w) {
      if (visited.at(i).at(j)) continue;
      if (s.at(i).at(j) == '#') {
        int cnt = 0;
        rep(k,4) {
          int ni = i + di[k];
          int nj = j + dj[k];
          if (0 <= ni && ni < h && 0 <= nj && nj < w) {
            if (s.at(ni).at(nj) == '.') { cnt++;
            } else {
              visited.at(i).at(j) == true;
              visited.at(ni).at(nj) == true;
            }
          }
        }
        if (cnt == 4) {
          cout << "No" << endl;
          return 0;
        }
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}

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

using namespace std;

#define ll long long
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef set<int> si;
typedef set<vi> svi;
typedef set<ll> sll;
typedef set<vll> svll;
typedef set<pii> spii;
typedef set<vpii> svpii;
typedef set<pll> spll;
typedef set<vpll> svpll;
typedef vector<si> vsi;
typedef vector<sll> vsll;
typedef vector<spii> vspii;
typedef vector<spll> vspll;
#define ft first
#define sc second
#define pb push_back
#define ins insert
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define all(v) v.begin(),v.end()
#define Sort(v) sort(all(v))
#define sortarr(a,n) sort(a,a+n)
#define tt ll tc; cin >> tc; while(tc--)
#define rep(var,start,end,interval) for(ll var=start;(interval>0 and var<end) or (interval<0 and var>end);var+=interval)
#define each(x,v) for(auto x : v)
#define takearr0(a,n) rep(z,0,n,1) cin >> a[z];
#define takearr1(a,n) rep(z,1,n+1,1) cin >> a[z];

const ll max_n = 1e6 + 5;

ll k;

int main()
{
	io;
	cin >> k;
	ll x = ((ll)7)%k,ans = -1;
	rep(i,1,k+1,1)
	{
		if(x == 0)
		{
			ans = i;
			break;
		}
		x *= 10;
		x += 7;
		x %= k;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end()
#define pb(x)  push_back(x);
#define INF9 1000000000 //10^9
#define MOD 1000000007 //10^9+7
using ll=long long;
using pii=pair<ll,ll>;
using vi=vector<int>;

int main() {
    int A,P;
    cin >> A >> P;
    cout << (A*3+P) / 2 << endl;
    return 0;
}


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

using namespace std;

#define ll long long

int main() {
    ll a, b, c, k; cin >> a >> b >> c >> k;
    if(k<=a) {
        cout << k << endl;
        return 0;
    }
    if(k<=a+b) {
        cout << a << endl;
        return 0;
    }
    cout << a - (k-(a+b)) << endl;

    return 0;
}

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

int main(){
  int A,B,C,D;
  string S;
  cin>>A>>B>>C>>D;
  for(int i=0; i<100; i++){
    C-=B;
    if(C<=0){S="Yes"; break;}
    A-=D;
    if(A<=0){S="No"; break;}
  }
  cout<<S<<endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int (i) = 0; i < (n); i++)
#define REP(i, m, n) for(int (i) = (m); (i) < (n); (i)++)
#define INF LLONG_MAX - 10
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a*b/gcd(a,b);};
int mod(int a,int b){return (a+b-1)/b;};
int month[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a < b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a > b){a=b;return true;}return false;};



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

    int n;
    cin >> n;
    int a[n];
    rep(i, n) cin >> a[i];
    
    sort(a, a + n);
    int sum[n + 10] = {};
    rep(i, n) {
        sum[i+1] = sum[i] + a[i];
    }
    
    int ans = 0;
    rep(i, n) {
        if(sum[i] * 2 >= a[i]) ans++;
        else ans = 0;
    }
    
    cout << ++ans << endl;
 	return 0;
}


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

void solve(std::istream &in, std::ostream &out);

int main() {
#ifdef LOCAL
  freopen("../IO/e.in", "r", stdin);
//  freopen("../IO/f.out", "w", stdout);
#else
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
#endif
  solve(std::cin, std::cout);
  return 0;
}




void solve(std::istream &in, std::ostream &out) {
  int n;
  in >> n;
  vector<pair<int, int>> A(n);
  for (int i = 0; i < n; ++i) {
    in >> A[i].first;
    A[i].second = i;
  }
  sort(A.rbegin(), A.rend());
  vector<vector<int64_t>> dp(n + 1, vector<int64_t>(n + 1, 0));
  int64_t mx = 0;
  for (int count = 0; count < n - 1; ++count) {
    int val = A[count].first;
    int pos = A[count].second;
    for (int l = 0; l <= count; ++l) {
      int r = n - (count - l) - 1;
      dp[l + 1][r] = max(dp[l + 1][r], dp[l][r] + (int64_t) (pos - l) * val);
      dp[l][r - 1] = max(dp[l][r - 1], dp[l][r] + (int64_t) (r - pos) * val);
    }
  }
  for (int i = 0; i < n; ++i) {
    mx = max({mx, dp[i][i] + (int64_t) abs(i - A.back().second) * A.back().first});
  }
  out << mx << '\n';
}

Measured memory_bytes: 34560
s = list(input())

s_set = set(s)

cnt = 101
for l in s_set:
    indexs = set([i for i, x in enumerate(s) if x == l])
    i = len(s)
    while len(indexs) < i:
        indexsList = list(indexs)
        for j in range(len(indexs)):
            n = indexsList[j]
            if n == 0:
                pass
            elif n == i - 1:
                indexs.remove(n)
                indexs.add(n-1)
            else:
                indexs.add(n-1)
        i -= 1
    cnt = min(cnt, len(s)-i)

print(cnt)

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

#define llint long long int

using namespace std;

int main(){
    llint N;

    cin >> N;

    llint ans = 0;

    for(llint K = 1; K <= N; K ++){
        ans += K * (N / K) * (N / K + 1) / 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.util.Arrays;
import java.util.stream.LongStream;
import java.util.TreeMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.Comparator;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        D solver = new D();
        solver.solve(1, in, out);
        out.close();
    }

    static class D {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            int M = in.nextInt();

            int[] A = new int[N];
            for (int i = 0; i < N; i++) {
                A[i] = in.nextInt();
            }
            Arrays.sort(A);

            Map<Integer, Integer> map = new TreeMap<>(Comparator.reverseOrder());
            for (int i = 0; i < M; i++) {
                int value = in.nextInt();
                int key = in.nextInt();
                if (map.containsKey(key)) {
                    value += map.get(key);
                }
                map.put(key, value);
            }

            int index = 0;
            for (Map.Entry<Integer, Integer> entry :
                    map.entrySet()) {
                int value = entry.getValue();
                int key = entry.getKey();
                if (N <= index || key <= A[index]) {
                    break;
                }
                for (int i = 0; i < value; i++) {
                    if (N <= index || key <= A[index]) {
                        break;
                    }
                    A[index++] = key;
                }
            }

            out.println(Arrays.stream(A).asLongStream().sum());
        }

    }
}



Measured memory_bytes: 95348
#include <stdio.h>

  int main()
  {
    int a,b,c,tmp;
    scanf("%d %d %d",&a,&b,&c);
    if(b < a)
    {
      tmp = b;
      b = a;
      a = tmp;
    }
    if(c < b)
    {
      tmp = c;
      c = b;
      b = tmp;
    }
    if(b < a)
    {
      tmp = b;
      b = a;
      a = tmp;
    }
    printf("%d %d %d\n",a,b,c);
    return 0;
  }



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

maxn =  1000005
prime = [0 for _ in range(maxn)]

for i in range(2, maxn):
    if prime[i] == 0:
        for j in range(i, maxn, i):
            prime[j] = i #最大質因數

st = set() #目前出現過的所有質因數，一開始為A[0]的所有質因數
a = A[0]
while prime[a]:
    st.add(prime[a])
    x = prime[a]
    while (a % x == 0):
        a //= x

pairwise = True
st2 = st #所有數共有的質因數，一開始為A[0]的所有質因數
for a in A[1:]:
    tmp = set()
    for j in st2:
        if a % j == 0:
            tmp.add(j)

    st2 = tmp
    if pairwise:
        while prime[a]:
            if prime[a] in st:
                pairwise = False
            st.add(prime[a])
            x = prime[a]
            while (a % x == 0):
                a //= x

if pairwise:
    print("pairwise coprime")
elif len(st2) == 0:
    print("setwise coprime")
else:
    print("not coprime")

Measured memory_bytes: 134632
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <functional>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define SQ(x) ((x)*(x))
#define Mod(x, mod) (((x)+(mod)%(mod))
#define MP make_pair
#define PB push_back
#define Fi first
#define Se second
#define INF (1<<29)
#define EPS 1e-10
#define MOD 1000000007

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int main()
{
  int N, x;
  cin >> N >> x;
  if(N == 2){
    if(x == 2) cout << "Yes\n1\n2\n3\n";
    else cout << "No\n";
  }else if(N == 3){
    if(x == 1 || x == 5) cout << "No\n";
    if(x == 2) cout << "Yes\n3\n1\n2\n4\n5\n";
    if(x == 3) cout << "Yes\n1\n2\n3\n4\n5\n";
    if(x == 4)cout << "Yes\n1\n2\n4\n5\n3\n";
  }else{
    if(x == 1 || 2*N-1 == x){
      cout << "No\n";
    }else if(x == 2 || x == 2*N-2){
      deque<int>d;
      d.push_back(x);
      d.push_front(1);
      d.push_back(2*N-1);
      vector<int>v;
      for(int i=2;i<2*N-1;i++){
	if(i==x) continue;
	v.push_back(i);
      }
      int vlen=v.size();
      for(int i=vlen/2-1;i>=0;i--) d.push_front(v[i]);
      for(int i=vlen/2;i<vlen;i++) d.push_back(v[i]);
      cout << "Yes\n";
      for(auto a: d)
	cout << a << endl;
    }else{
      deque<int>d;
      d.push_back(x);
      d.push_front(2*N-1);
      d.push_front(1);
      d.push_back(2);
      d.push_back(2*N-2);
      vector<int>v;
      for(int i=3;i<2*N-2;i++){
	if(i==x) continue;
	v.push_back(i);
      }
      int vlen = v.size();
      for(int i=vlen/2-1;i>=0;i--) d.push_front(v[i]);
      for(int i=vlen/2;i<vlen;i++) d.push_back(v[i]);
      cout << "Yes\n";
      for(auto a: d)
	cout << a << endl;
    }      
  }
  return 0;
}


Measured memory_bytes: 3064
import Text.Parsec
import Data.Bits

type Input  = (Int, Int)

input :: Parsec String () Input
input = (,) <$> decimal <* char ' ' <*> decimal <* endOfLine

decimal :: Parsec String () Int
decimal = read <$> many digit

main :: IO ()
main = getContents >>= print . either (error . show) solve . parse input ""

solve :: Input -> Int
solve (_A, _B) = f _A _B
  where
    f 0 b = g b
    f a b = g b `xor` g (a - 1)

    g x = case x `mod` 4 of
      0 -> x
      1 -> 1
      2 -> x `xor` 1
      3 -> 0

Measured memory_bytes: 508
from sys import stdin, setrecursionlimit
from collections import Counter, deque, defaultdict
from math import floor, ceil
from bisect import bisect_left
from itertools import combinations
setrecursionlimit(100000)

mod = int(1e9 + 7)


def main():
    from builtins import int, map
    S = int(input())

    A = [0] * (S + 1)
    A[0] = 1

    for s in range(1, S + 1):
        for k in range(s - 2):
            A[s] += A[k]
            A[s] %= mod

    print(A[S])


if __name__ == '__main__':
    main()


Measured memory_bytes: 68048
#include <bits/stdc++.h>
using namespace std;
 
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define CONTAINS(a, x) (a.find(x) != a.end())
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int)x.size()
#define nl cout << endl
#define F first
#define S second
 
#define what_is(x) cout << #x << " = " << x << endl
#define boost ios::sync_with_stdio(false);cin.tie(NULL)
#define CASET int ___T, case_n = 1; cin >> ___T; while (___T-- > 0) 
 
 
#define rep(it, st, en) for(ll it = st; it < en; it++)
#define rep1(it, st, en) for(ll it = st; it <= en; it++)
#define per(it, st, en) for(ll it = en - 1; it >= st; it--)
 
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll,ll> pll;
 
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<ii> vii;
typedef vector<vi> vvi;
 
ll INF = 1E9;
ll M = 1E9 + 7;
 
inline ll max_(ll a, ll b) { return (a>b)?a:b; }
inline ll min_(ll a, ll b) { return (a<b)?a:b; }
 
inline ll power (ll a,ll p){
    ll res = 1, x = a;
    while ( p ) {
        if ( p & 1 ) res = ( res * x );
        x = ( x * x ); p >>= 1;
    }
    return res;
}
 
template <typename T> ostream& operator<<(ostream& os, const vector<T> &p){os << "[ "; for (T x: p) os << x << " "; os << "]" << endl; return os;}
template <typename T> ostream& operator<<(ostream& os, const set<T> &p){os << "{ "; for (T x: p) os << x << " "; os << "}" << endl; return os;}
template <typename Tk, typename Tv> ostream& operator<<(ostream& os, const map<Tk, Tv> &p){os << "{ "; for (pair<Tk, Tv> x: p) os << x << " "; os << "}" << endl; return os;}
template <typename Tk, typename Tv> ostream& operator<<(ostream& os, const pair<Tk, Tv> &p){os << "{" << p.first << ',' << p.second << "}";return os;}

int main() {
    boost;
    if(fopen("inp.txt", "r")){
      freopen("inp.txt", "r", stdin);
      freopen("outp.txt", "w", stdout);
    }

    ll n,l,r;
    cin>>n;

    ll ans=0;
    while (n--) {
        cin>>l>>r;
        ans+=(r-l+1);
    }

    cout<<ans;

    return 0;
}

Measured memory_bytes: 256
#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 rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#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 eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#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 tuple<int, int, int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int A[303][303];
int main() {
  int h,w,k;
  cin >> h >> w >> k;

  vector<string> cake(h);
  rep(ih,h){
    cin >> cake[ih];
  }
  
  int id = 1;
  rep(y,h){
    int num = 0;
    rep(x,w) if(cake[y][x] == '#') num++;

    if(num == 0){
      if(y){
        rep(x,w) A[y][x] = A[y-1][x];
      }
    }
    else{
      int c = 0;
      rep(x,w){
        if(cake[y][x] == '#'){
          c++;
          if(c>1) id++;
        }
        A[y][x] = id;
      }
      id++;
    }
  }

  drep(y,h-1){
    rep(x,w)if(!A[y][x])A[y][x] = A[y+1][x];
  }

  rep(y,h){
    rep(x,w){
      cout<<A[y][x]<<" ";
    }
    cout<<endl;
  }

  return 0;
}

Measured memory_bytes: 1280
#include<iostream>
#include<cstring>

using namespace std;

typedef long long ll;
const int MAX = (1<<18);

class SegmentTree{
public:
  int n;
  ll dat[MAX];

  void init(int num){
    n = 1;
    while(n < num) n*=2;
    memset(dat,0,sizeof(dat));
  }

  void update(int k, ll a){
    k += n-1;
    dat[k] = a;

    while(k > 0){
      k = (k-1)/2;
      dat[k] = max(dat[k*2+1],dat[k*2+2]);
    }
  }

  ll query(int a, int b, int k, int l, int r){
    if(r <= a || b <= l) return 0;
    
    if(a <= l && r <= b) return dat[k];

    ll vl = query(a,b,k*2+1,l,(l+r)/2);
    ll vr = query(a,b,k*2+2,(l+r)/2,r);
    return max(vl,vr);
  }
};

int main(){

  ll n;
  cin >> n;
  SegmentTree st;
  st.init(n);
  
  ll ans = 0;
 
  for(int i = 0; i < n; i++){
    ll x;
    cin >> x;
    ll nex = st.query(1,x+1,0,0,st.n)+x;
    st.update(x,nex);
    ans = max(ans,nex);
  }
  cout << (n*(n+1LL))/2LL - ans << endl;

  return 0;
}

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

int main(){
    int N;
    cin >> N;
    string a[N];
    set<string> b;
    for(int i = 0; i < N; i++)
    {
        cin >> a[i];
        b.insert(a[i]);
    }
    cout << b.size() << endl;
}

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


int main(){
    int N, g;
    ll sum;
    cin >> N;
    sum = 0;
    for(int i = 1; i <= N; i++){
        for(int j = 1; j <= N; j++){
            for(int k = 1; k <= N; k++){
                g = __gcd(__gcd(i,j), __gcd(j,k));
                sum += g;
            }
        }
    }

    cout << sum << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

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

  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  cout << *max_element(a.begin(), a.end()) - *min_element(a.begin(), a.end()) << endl;

  return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    int n; cin >> n;
    map <int, int> cnt;
    vector <int> hats;
    int hat;
    REP(i, n){
        cin >> hat;
        hats.push_back(hat);
        cnt[hat]++;
    }
    sort(hats.begin(), hats.end());
    bool result = true;
    if (n%3 == 0){
        for(auto it:cnt){
            if(it.second % (n/3) != 0){
                result = false;
            }
        }
        if((hats[0]^hats[n/3]^hats[n*2/3]) != 0){
            result = false;
        }
    } else {
        if(hats[n-1] != 0) {
            result = false;
        }
    }
    if (result){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 4216
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
  int A, B;
  cin >> A >> B;
  
  if (A <= 8 && B <= 8) {
    cout << "Yay!" << endl;
  } else {
    cout << ":(" << endl;
  }
 
}

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

#define pout(n)  printf ("%d\n", n)
#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)

typedef long long ll;
using namespace std;
 
int main (){
  double a,b;
  cin >> a >> b;

  if(a > b){
      puts("GREATER");
  }
  else if(a < b){
    puts("LESS");
  }
  else puts("EQUAL");
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define sz(x) (int)(x).size()
typedef vector<int> vi;
// #define ll long long 
#define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
const int MOD = 998244353; //1e9+7;
int mpow(int a,int b,int p=MOD){a=a%p;int res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
const int N=2*1e5+2;

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	string s,t;
	cin>>s>>t;
	int n=s.length();
	int next[n][26];
	int ma[26];
	for(int i=0;i<26;i++) ma[i]=-1;
	for(int i=n-1;i>=0;i--)
	{
		ma[s[i]-'a']=i;
		for(int j=0;j<26;j++) next[i][j]=ma[j];
	}
	int ans=0;
	int pos=0;
	for(int i=0;i<t.length();i++)
	{
		int o=next[pos][t[i]-'a'];
		// cout<<t[i]<<" ";
		// cout<<o<<" ";
		if(o==-1&&pos==0)
		{
			cout<<"-1";
			return 0;
		}
		if(o==-1)
		{
			ans+=n;
			pos=0;
			i--;
			continue;
		}
		pos=o+1;
		if(pos==n)
		{
			// cout<<"*";
			ans+=n;
			pos=0;
		}
	}
	ans+=(pos);
	cout<<ans;
}
// I never lose. I either win or I learn

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

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
typedef vector<int>vint;
typedef pair<int,int>pint;

int H,W;
int a[50][50];

signed main(){
    cin>>H>>W;
    rep(i,H)rep(j,W){
        char c;
        cin>>c;
        if(c=='W')a[i][j]=0;
        else if(c=='B')a[i][j]=1;
        else a[i][j]=2;
    }

    int ans=114514;

    for(int i=1;i<H-1;i++){
        for(int j=i+1;j<H;j++){
            int cnt=0;
            for(int y=0;y<i;y++)rep(x,W)if(a[y][x]!=0)cnt++;
            for(int y=i;y<j;y++)rep(x,W)if(a[y][x]!=1)cnt++;
            for(int y=j;y<H;y++)rep(x,W)if(a[y][x]!=2)cnt++;
            ans=min(ans,cnt);
        }
    }

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

Measured memory_bytes: 3104
def main():
    class UnionFind:
        def __init__(self, N):
            """
            N:要素数
            root:各要素の親要素の番号を格納するリスト.
                ただし, root[x] < 0 ならその頂点が根で-root[x]が木の要素数.
            rank:ランク
            """
            self.N = N
            self.root = [-1] * N
            self.rank = [0] * N

        def __repr__(self):
            return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

        def find(self, x):
            """頂点xの根を見つける"""
            if self.root[x] < 0:
                return x
            else:
                while self.root[x] >= 0:
                    x = self.root[x]
                return x

        def union(self, x, y):
            """x,yが属する木をunion"""
            # 根を比較する
            # すでに同じ木に属していた場合は何もしない.
            # 違う木に属していた場合はrankを見てくっつける方を決める.
            # rankが同じ時はrankを1増やす
            x = self.find(x)
            y = self.find(y)
            if x == y:
                return
            elif self.rank[x] > self.rank[y]:
                self.root[x] += self.root[y]
                self.root[y] = x
            else:
                self.root[y] += self.root[x]
                self.root[x] = y
                if self.rank[x] == self.rank[y]:
                    self.rank[y] += 1

        def same(self, x, y):
            """xとyが同じグループに属するかどうか"""
            return self.find(x) == self.find(y)

        def count(self, x):
            """頂点xが属する木のサイズを返す"""
            return - self.root[self.find(x)]

        def members(self, x):
            """xが属する木の要素を列挙"""
            _root = self.find(x)
            return [i for i in range(self.N) if self.find == _root]

        def roots(self):
            """森の根を列挙"""
            return [i for i, x in enumerate(self.root) if x < 0]

        def group_count(self):
            """連結成分の数"""
            return len(self.roots())

        def all_group_members(self):
            """{ルート要素: [そのグループに含まれる要素のリスト], ...}の辞書を返す"""
            return {r: self.members(r) for r in self.roots()}


    import sys
    input = sys.stdin.readline
    n, q = map(int, input().split())
    ans = [0, 1]
    uf = UnionFind(n)
    for i in range(q):
        t, u, v = map(int, input().split())
        if t:
            print(ans[uf.same(u, v)])
        else:
            uf.union(u, v)

main()


Measured memory_bytes: 79888
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

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

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

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

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	N := getInt()
	h := make([]int, N)
	for i := 0; i < N; i++ {
		h[i] = getInt()
	}
	ans := 0
	prev := h[0]
	cnt := 0
	for i := 1; i < N; i++ {
		// out(prev, h[i], cnt)
		if prev < h[i] {
			cnt = 0
		} else {
			cnt++
		}
		ans = max(cnt, ans)
		prev = h[i]
	}
	out(ans)
}


Measured memory_bytes: 3072
n = int(input())
a = [int(_) for _ in input().split(' ')]

if n % 3 == 0:
    a.sort()
    m = n // 3
    if a[0] == a[m - 1] and a[m] == a[2 * m - 1] and a[2 * m] == a[3 * m - 1]:
        if a[0] ^ a[m] ^ a[2 * m] == 0:
            print('Yes')
        else:
            print('No')
    else:
        print('No')
else:
    if max(a) == 0:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 14116
#B
n, m = map(int, input().split())
k = []
a = []
for i in range(n):
    l = list(map(int, input().split()))
    k.append(l[0])
    a.append(l[1:l[0] + 1])
# print(k, a)
ans = [0] * m
for i in range(n):
    b=k[i]
    for j in range(b):
        ans[a[i][j]-1] += 1
# print(ans)
count = 0
for i in range(m):
    if ans[i] == n:
        count += 1
print(count)

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

using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n); i > 0; i--)
#define print(n) cout << n << endl

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

    ll n,k,c;
    string s;
    cin >> n >> k >> c >> s;
    vector<ll> f(k);
    vector<ll> r(k);
    int x = 0;
    rep(i,n){
        if(s[i]=='o'){
            f[x] = i;
            i += c;
            x++;
            if(x>=k) break;
        }
    }
    x = k-1;
    rrep(i,n){
        if(s[i-1]=='o'){
            r[x] = i-1;
            i -= c;
            x--;
            if(x<0) break;
        }
    }
    rep(i,k) if(f[i]==r[i]) print(f[i]+1);

    return 0;
}

Measured memory_bytes: 5012
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do{cout << "\033[32;1m" << #x << "->" ; err(x);} while(0)
void err(){cout << "\033[39;0m" << endl;}
template<template<typename...> class T,typename t,typename... A>
void err(T<t> a,A... x){for (auto v:a) cout << v << ' '; err(x...);}
template<typename T,typename... A>
void err(T a,A... x){cout << a << ' '; err(x...);}
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
        print(v[i],i==(int)(v.size())-1?suc:2);
}
const int INF=0x3f3f3f3f;
struct Edge{
	int to;ll w;
};
const int maxn=1e5+7;
vc<Edge> G[2][maxn];
ll dis[2][maxn];
ll a[maxn],b[maxn];
ll ans[maxn];
struct D{
	int u;
	ll d;
	bool operator<(const D& a)const{
		return d>a.d;
	}
};
bool vis[maxn];
void dij(int x,int st)
{
	memset(dis[x],0x3f,sizeof(dis[x]));
	memset(vis,0,sizeof(vis));
	dis[x][st]=0;
	priority_queue<D> q;
	q.push({st,0});
	while(!q.empty())
	{
		auto u=q.top();
		q.pop();
		if(vis[u.u]) continue;
		vis[u.u]=1;
		for(auto e:G[x][u.u])
		{
			int v=e.to;
			if(dis[x][v]>u.d+e.w)
			{
				dis[x][v]=u.d+e.w;
				q.push({v,dis[x][v]});
			}
		}
	}
}
int main()
{
	int n,m,s,t;
	cin>>n>>m>>s>>t;
	for(int i=0,u,v;i<m;i++)
	{
		cin>>u>>v>>a[i]>>b[i];
		G[0][u].push_back({v,a[i]});
		G[0][v].push_back({u,a[i]});
		G[1][u].push_back({v,b[i]});
		G[1][v].push_back({u,b[i]});
	}
	dij(0,s);
	dij(1,t);
	ll cur=0x3f3f3f3f3f3f3f3f;
	for(int i=n-1;i>=0;i--)
	{
	//	dbg(i,dis[0][i],dis[1][i]);
		cur=min(cur,dis[0][i+1]+dis[1][i+1]);
		ans[i]=cur;
	}
	ll mx=1e15;
	for(int i=0;i<n;i++)
		cout<<mx-ans[i]<<"\n";
}


Measured memory_bytes: 20804
n=int(input())
task=[]
for i in range(n):
    cost,limit=map(int,input().split())
    task.append([cost,limit])

task.sort(key=lambda x: x[1])
#print(task)
time=0
flag=True
for cost,limit in task:
    time+=cost
    if time>limit:
        flag=False
        break
if flag:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 38092
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.Text;
using System.Threading.Tasks;

namespace B_coins
{
    class Program
    {
        static void Main(string[] args)
        {
            int total =int.Parse(ReadLine());
            int[] n = new int[total+1];
            for (int i = 0; i < total; i++) {
                n[i] = int.Parse(ReadLine());
            }
            Array.Sort (n);
            int count = 1;
            for (int m = 0; m < total; m++) {
                if (n[m] != n[m + 1]) {
                    count++;
                }
            }
            count--;
            WriteLine("{0}",count);
            ReadKey();
        }
    }
}



Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll a;
    double b;
    cin>>a>>b;
    ll B=b*100+0.1;
    cout<<a*B/100<<'\n';
}

Measured memory_bytes: 3740
N = int(input())
S = input()
whitecount = [0 for i in range(N+1)]
for i in range(N):
    if S[i] == ".":
        whitecount[i+1] = whitecount[i] + 1
    else:
        whitecount[i+1] = whitecount[i]
ans = 1000000
for i in range(N+1):
    anstemp = i - whitecount[i] + (whitecount[-1] - whitecount[i])
    ans = min(anstemp, ans)
print(ans)


Measured memory_bytes: 11396
from math import sqrt, factorial
from fractions import gcd
from sys import setrecursionlimit
from itertools import product
from string import ascii_lowercase as abc
setrecursionlimit(10000000)

def inpl(): return list(map(int, input().split()))
A, B, C, D = inpl()
E = C*D//gcd(C, D)
X = B//C - (A-1)//C
Y = B//D - (A-1)//D
Z = B//E - (A-1)//E
print(B-A+1-X-Y+Z)

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

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

    int ans = 0;
    for(int i = 0; i < n; ++i) {
        ans = __gcd(ans, a[i]);
    }

    cout << ans << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>

using namespace std;

int main(){
  int n,tmp;
  vector<int> A;
  cin >> n;

  for(int i=0;i<n;i++){
    cin >> tmp;
    A.push_back(tmp);
  }
  sort(A.begin(),A.end());

  int max = *max_element(A.begin(),A.end());
  int dist;
  int min_dist=max;
  int cp;

  for(int i=0;i<n;i++){
    dist = abs(max/2 + max%2 - A[i]);
    if(dist < min_dist){
      min_dist = dist;
      cp = i;
    }
  }

  cout << max << " " << A[cp] << endl;

  return 0;
}


Measured memory_bytes: 892
#include <iostream>
using namespace std;
int main(){
int n;
while(cin >> n)
 { int s = 0,m = 1, l;
for(int i = 2; i <= n; i++)
 { int j = i; l = 0;
 if(j % 2 != 0)
continue;
else
{
while(j%2==0)
{ l++; j/=2; }
}
 if(l>s) { s = l; m = i; }
 }
cout << m << endl; }
return 0;
}

Measured memory_bytes: 256
my $n = int <>;
my $ichinokurai = $n % 10;
if( grep { $ichinokurai == $_ } (2, 4, 5, 7, 9) )  {
    print 'hon';
}
elsif ( grep { $ichinokurai == $_ } (0, 1, 6, 8) ) {
    print 'pon';
}
else {
    print 'bon';
}

Measured memory_bytes: 4696
#include<bits/stdc++.h>
using namespace std;
double l;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin>>l;
    l=double(l/3);
    l=double(pow(l,3));

    cout<<fixed<<setprecision(12)<<l;
}


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

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;

int gcd(int a, int b){
  if(a > b)return gcd(b, a);
  if(a == 0)return b;
  return gcd(a, b % a);
}

int main(int argc, char const* argv[])
{
  int n, m;
  cin >> n >> m;
  string s, t;
  cin >> s >> t;
  int g = gcd(n, m);
  int mm = m / g;
  int nn = n / g;
  bool flag = true;
  for(int k = 0; k < n; k += nn){
    int l = (ll)k * (ll)mm / (ll)nn;
    if(l < m){
      if(s[k] != t[l]){
        flag = false;
        break;
      }
    }
  }
  if(!flag)cout << "-1" << endl;
  else{
    cout << (ll)n * (ll)m / g << endl;
  }
	return 0;
}


Measured memory_bytes: 512
var
	a,b: integer;
begin
	readln(a,b);
	if (a>b) and (b>1) then
		writeln('Alice')
	else if (a=1) and (b>1) then
		writeln('Alice')
	else if (b>a) and (a>1) then
		writeln('Bob')
	else if (b=1) and (a>1) then
		writeln('Bob')
	else
		writeln('Draw');
end.

Measured memory_bytes: 128
from sys import stdin
def input():
    return stdin.readline().strip()

h, w = map(int, input().split())
ch, cw = map(int, input().split())
ch += 1
cw += 1
dh, dw = map(int, input().split())
dh += 1
dw += 1
g = ['#' * (w + 4)] * 2 
for _ in range(h):
    g.append('##' + input() + '##')
g.append('#' * (w + 4))
g.append('#' * (w + 4))

d1 = [(-1, 0), (0, -1), (0, 1), (1, 0)]
d2 = [(-2, -2), (-2, -1), (-2, 0), (-2, 1), (-2, 2), (-1, -2), (-1, -1),
(-1, 1), (-1, 2), (0, -2), (0, 2), (1, -2), (1, -1), (1, 1), (1, 2),
(2, -2), (2, -1), (2, 0), (2, 1), (2, 2)]

from collections import deque
# BFS BFS
seen = [[-1] * (w+2) for _ in range(h+2)]
todo = deque([(0, ch, cw)])
while len(todo) > 0:
    history = []
    while len(todo) > 0:
        cost, x, y = todo.popleft()
        if seen[x][y] == -1:
            if x == dh and y == dw:
                print(cost)
                exit()
            seen[x][y] = cost
            history.append((cost, x, y))
        else:
            continue

        for i in range(4):
            dx, dy = d1[i]
            if g[x+dx][y+dy] == '.' and seen[x+dx][y+dy] == -1:
                todo.append((cost, x+dx, y+dy))

    for j in history:
        cost, x, y = j
        for i in range(20):
            dx, dy = d2[i]
            if g[x+dx][y+dy] == '.' and seen[x+dx][y+dy] == -1:
                todo.append((cost+1, x+dx, y+dy))

print(-1)

Measured memory_bytes: 107268
// AOJ 0529: Darts
// 2017.9.4 bal4u@uu
// 2017.11.14

#include <stdio.h>
#include <stdlib.h>

int p[1003];
int s[1000010], n;
char buf[20], *bp;

int cmp(int *a, int *b) { return *a - *b; }

int bsch(int x)
{
	int m, l = 0, r = n;

    while (l < r) {
        m = (l + r) >> 1;
		if (s[m] == x) return m;
        if (s[m] < x) l = m + 1; else r = m;
    }
	return l-1;
}

int getint()
{
	int n = 0;
	while (*bp >= '0') n = (n<<3) + (n<<1) + (*bp++ & 0xf);
	return n;
}

int main()
{
	int sz, m, a, i, j, ans;

	while (fgets(bp=buf, 20, stdin) && *bp != '0') {
		n = getint(), bp++, m = getint();
		ans = 0, p[0] = 0, sz = 1;
		while (n--) {
			fgets(bp=buf, 20, stdin);
			a = getint();
			if (a < m) p[sz++] = a;
			else if (a == m) ans = m;
		}
		if (ans > 0) goto done;
		
		for (n = 0, i = 0; i < sz; i++) for (j = i; j < sz; j++) {
			if ((s[n] = p[i]+p[j]) < m) n++;
			if (s[n] == m) ans = m;
		}
		if (ans > 0) goto done;
		qsort(s, n, sizeof(int), cmp);	

		for (i = 0; i < n; i++) {
			j = bsch(m - s[i]);
			if (s[i] + s[j] > ans) ans = s[i]+s[j];
		}
done:	printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 5724
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll x, a, b;
  in3(x, a, b);
  if(abs(a - x) < abs(b - x))
    out("A");
  else
    out("B");
  memi;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	int n;
	int[] array;
	public static void main(String args[]) {
		Main main = new Main();
	}
	Main() {
		Scanner scan = new Scanner(System.in);
		n = scan.nextInt();
		array = new int[n];
		for (int i = 0; i < n; i++) {
			array[i] = scan.nextInt();
		}
		this.writeArray();
		for (int i = 1; i < n; i++) {
			int v = array[i];
			int j = i - 1;
			for(; j >= 0 && array[j] > v; j--) {
				array[j+1] = array[j];
			}
			array[j+1] = v;
			this.writeArray();
		}
	}
	public void writeArray() {
		for (int i = 0; i < n; i++) {
			if (i < n - 1)
				System.out.print(array[i] + " ");
			else
				System.out.println(array[i]);
		}
	}
}



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

int main() {
  int N;

  cin >> N;

  for (int i = 1; i < 10; i++) {
    for (int j = 1; j < 10; j++) {
      if (i * j == N) {
	cout << "Yes" << endl;
	return 0;
      }
    }
  }

  cout << "No" << endl;

  return 0;
}


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

using Int = long long;
using Edge = pair<int, Int>; // (接続先の頂点,重み)
using Node = vector<Edge>; // 隣接する辺のリスト
using NodeList = vector<Node>;

int main() {
    int n;
    cin >> n;
    auto nodes = NodeList(n, Node(0));
    rep(i, n - 1) {
        int a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        nodes[a].push_back(Edge(b, c));
        nodes[b].push_back(Edge(a, c));
    }
    int q, k;
    cin >> q >> k;
    k--;
    auto distanceList = vector<Int>(n);
    function<void(int, int, Int)> dfs = [&nodes, &dfs, &distanceList](int index, int parent, Int dist) {
        auto &node = nodes[index];
        distanceList[index] = dist;
        for (auto &edge : node) {
            auto nextIndex = edge.first;
            auto nextDist = edge.second;
            if (nextIndex == parent) continue;
            dfs(nextIndex, index, dist + nextDist);
        }
    };
    dfs(k, -1, 0);
    rep(i, q) {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        cout << distanceList[x] + distanceList[y] << endl;
    }
}

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

int main() {
	int N;cin>>N;
	vector<int>A(N),sorted(N);
	for(int i=0;i<N;i++){
		cin>>A[i];
		sorted[i] = A[i];
	}
	sort(sorted.begin(),sorted.end());
	
	for(int i=0;i<N;i++){
		if(A[i] >= sorted[N/2])cout<<sorted[N/2-1]<<endl;
		else cout<<sorted[N/2]<<endl;
	}
	
	
	return 0;
}

Measured memory_bytes: 3712
import java.util.*;
import java.lang.*;
   
public class Main{
  public static void main(String[] args){
    Scanner stdIn=new Scanner(System.in);
    double r=stdIn.nextDouble();
    double S=Math.PI*r*r, C=Math.PI*2*r;
    System.out.printf("%.6f %.6f",S,C);
  }
}


Measured memory_bytes: 28236
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ft first
#define sd second
#define pb push_back
using namespace std;
const ll mod = 1e9+7;

ll power(ll a, ll b, ll m = mod) {
    ll x = 1;
    while(b) {
        if(b & 1) {
            x = 1ll * x * a % m;
        }
        a = 1ll * a * a % m;
        b /= 2;
    }
    return x;
}

const int N = 5e5;
// ll a[N];

signed main() {  
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);    
    
    int x; cin >> x;
    if(x == 1) return cout << 1, 0;
    for(int i = x;  ; i++) {
        bool ok = 1;
        for(ll j = 2; j * j <= i; j++) {
            if(i % j == 0) {ok = 0; break;}
        }
        if(ok) {
            cout << i << endl;
            return 0;
        }
    }
 
    return 0;
    
}
    


Measured memory_bytes: 256
import java.util.*;

public class Main {
  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int K = sc.nextInt();
    
    int ans = 0;
    for (int i = 1; i <= K-1; i++) {
      boolean even = i % 2 == 0;
      for (int j = i + 1; j <= K; j++) {
        if (even && j % 2 == 1 || !even && j % 2 == 0) {
            ans++;
        }
      }
    }
    
    System.out.println(ans);
  }
}

Measured memory_bytes: 23124
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    MOD = 1000000007
    N, *A = map(int, read().split())
    C = [0] * (N + 1)
    C[0] = 3
    ans = 1
    for a in A:
        ans = ans * C[a] % MOD
        C[a] -= 1
        C[a + 1] += 1

    print(ans)

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 13980
import java.util.Scanner;

public class Main
{
	public static void main(String args[])
	{
		Scanner input = new Scanner(System.in);
		int a = input.nextInt();
		int b = input.nextInt();
		System.out.println(gcd(a, b));
	}

	public static int gcd(int a, int b)
	{
		if( a%b == 0 )
			return b;
		else
			return gcd(b, a%b);
	}
}

Measured memory_bytes: 26260