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

bool isPalindrome(const std::string& s) {
    
    for (size_t i = 0; i < s.size(); ++i) {
        if (s[i] != s[s.size()-1-i]) {
            return false;
        }
    }
    
    return true;
}

int main() {
    std::string S;
    std::cin >> S;

    size_t N = S.size();
    if (isPalindrome(S) && isPalindrome(S.substr(0, N/2)) && isPalindrome(S.substr(N/2 + 1, N/2))) {
        std::cout << "Yes\n";
    } else {
        std::cout << "No\n";
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	void Solve() {
		UL N, R; cin >> N >> R;
		if (N < 10) R += (10 - N) * 100;
		cout << R << endl;
	}


	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
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;
}
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 <typename T>
struct SegmentTree {
    int n;
    vector<T> node;
    T calc(T a, T b) {
        return max(a, b);
    }
    T e = 0;
    SegmentTree(vector<T> v) {
        int sz = v.size();
        n = 1;
        while (n < sz) {
            n *= 2;
        }
        node.resize(2 * n - 1, e);
        for (int i = 0; i < sz; i++) {
            node[i + n - 1] = v[i];
        }
        for (int i = n - 2; i >= 0; i--) {
            node[i] = calc(node[2 * i + 1], node[2 * i + 2]);
        }
    }
    SegmentTree(T sz) {
        n = 1;
        while (n < sz) {
            n *= 2;
        }
        node.resize(2 * n - 1, e);
    }
    void update(int x, T val) {
        x = n + x - 1;
        node[x] = val;
        while (x > 0) {
            x = (x - 1) / 2;
            node[x] = calc(node[2 * x + 1], node[2 * x + 2]);
        }
    }
    void add(int x, T val) {
        x = n + x - 1;
        node[x] += val;
        while (x > 0) {
            x = (x - 1) / 2;
            node[x] = calc(node[2 * x + 1], node[2 * x + 2]);
        }
    }
    T query(int a, int b, int k = 0, int l = 0, int r = -1) {
        if (r < 0) r = n;
        if (r <= a || b <= l) return e;
        if (a <= l && r <= b) return node[k];
        T vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
        T vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
        return calc(vl, vr);
    }
    T at(int x) {
        return node[n + x - 1];
    }
};
int main() {
    int n;
    cin >> n;
    vector<ll> h(n), a(n);
    rep(i, n) cin >> h[i];
    rep(i, n) cin >> a[i];
    vector<ll> dp(n + 10);
    SegmentTree<ll> segt(n + 10);
    rep(i, n) {
        chmax(dp[h[i]], segt.query(0, h[i]) + a[i]);
        segt.update(h[i], dp[h[i]]);
    }
    ll ans = 0;
    rep(i, n) {
        chmax(ans, dp[h[i]]);
    }
    cout << ans << endl;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define RALL(a)     (a).rbegin(),(a).rend()
#define PRINT(a)   cout << (a) << endl

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second

#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

using ll = long long int;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

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; }

const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

int main(){
  int n;
  cin >> n;
  int cnt_r=0;
  vector<char> c(n);
  REP(i,n){
    cin >> c[i];
    if(c[i]=='R')cnt_r++;
  }
  int ans = 0;
  REP(i,cnt_r){
    if(c[i]=='W')ans++;
  }
  cout << ans << endl;
}



Measured memory_bytes: 3504
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, y = 0;
  char S;
  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> S;
    if(S == 'Y')
      y++;
  }
  cout << (y == 0 ? "Three" : "Four") << endl;
} 

Measured memory_bytes: 256
fun main() {
    readLine() // skip
    val list = readLine()!!.split(" ").map { it.toLong() }.toLongArray()

    val group = list
        .asSequence()
        .groupBy { it }
        .mapValues { it.value.count().toLong() }
        .toMutableMap()

    val resultList = mutableListOf<Long>()
    var result = list.sum().toLong()

    val q = readLine()!!.toInt()
    (0 until q).map {
        val (b, c) = readLine()!!.split(" ").map { it.toLong() }
        result += (c - b) * (group[b] ?: 0L)
        resultList.add(result)

        group[c] = (group[c] ?: 0L) + (group[b] ?: 0L)
        group[b] = 0
    }

    resultList.forEach { println(it) }
}

Measured memory_bytes: 79532
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    string S;
    ll K;
    cin >> S >> K;
    K--;
    int size = S.size();
    rep(0, i, size)
    {
        if (S[i] != '1')
        {
            if (K < i)
            {
                cout << 1 << endl;
                return 0;
            }
            else
            {
                cout << S[i] << endl;
                return 0;
            }
        }
    }
    cout << 1 << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int search(int);
#define N 1000001
int num_1[N];
int num_2[N];

int main(){

  int n,q;
  int i,j;
  int sum=0;

  scanf("%d",&n);
  for(i=0;i<n;i++){   
    scanf("%d",&num_1[i]);
  }

  scanf("%d",&q);
  
  for(j=0;j<q;j++){   
    scanf("%d",&num_2[j]);
  }
  
  for(j=0;j<q;j++){
    sum+=search(j);
      }

  printf("%d\n",sum);

  return 0;
}

int search(int j){
  
  int i=0;
  num_1[N-1]=num_2[j];

  while(num_1[i]!=num_2[j]){   
    i++;
    if(i==N-1)return 0;
  }

  return 1;
}
    

Measured memory_bytes: 2688
#include <iostream>
#include <unordered_map>
#include <vector>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> vec(n);
  unordered_map<int, int> mp;
  rep(i, m) {
    int s, c;
    cin >> s >> c;
    if(mp.count(s)) {
      if(c != vec[s - 1]) {
        cout << -1 << endl;
        return 0;
      }
    }
    mp[s] = 1;
    vec[s - 1] = c;
  }
  if(n > 1) {
    if(mp.count(1) && vec[0] == 0) {
      cout << -1 << endl;
      return 0;
    }
    if(!mp.count(1)) vec[0] = 1;
  }
  rep(i, n) cout << vec[i];
  cout << endl;
  return 0;
}

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

int bubblesort(int A[], int N) {
    int sw = 0;
    bool flag = 1;
    for (int i = 0;flag; i++){
        flag = 0;
        for (int j = N-1; j >= i+1; j--){
            if (A[j] < A[j-1]){
                swap(A[j],A[j-1]);
                flag = 1;
                sw++;
            }
        }
    }
    return sw;
}


int main() {
    int N,sw;
    cin >> N;
    //vector<int> A(N);
    int A[100];
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    sw = bubblesort(A,N);
    for (int k = 0; k < N-1; k++) {
            cout << A[k] << " ";
        }
        cout << A[N-1] << endl;
    cout << sw << endl;
}


Measured memory_bytes: 3092
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>


using namespace std;

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

struct Ans {
	int fx;
	int fy;
	int tx;
	int ty;

	void write() {
		cout << fy + 1 << " ";
		cout << fx + 1 << " ";
		cout << ty + 1 << " ";
		cout << tx + 1;
		cout << endl;
	}
};

int main() {
	int h, w;
	cin >> h >> w;
	int a[h][w];
	int n = 0;

	rep(y, h) {
		rep(x, w) {
			cin >> a[y][x];
			a[y][x] = a[y][x] % 2;
			if (a[y][x] == 1) {
				n++;
			}
		}
	}
	n = n - (n % 1);

	int sx = 0;
	int sy = 0;
	int px = 0;
	int py = 0;
	bool is_move = false;
	vector<Ans> ans;


	for(int sy = 0; sy < h; sy++) {
		if (n == 0) {
			break;
		}
		int sx = (sy % 2 == 0) ? 0 : w - 1;
		while(sx >= 0 && sx <= w - 1) {
			if (is_move) {
				Ans tmp;
				tmp.fx = px;
				tmp.fy = py;
				tmp.tx = sx;
				tmp.ty = sy;
				ans.push_back(tmp);
			}

			if (a[sy][sx] == 1) {
				is_move = !is_move;
				n--;
			}
			if (n == 0) break;
			px = sx;
			py = sy;
			if (sy % 2 == 0) {
				sx ++;
			} else {
				sx --;
			}

		}
					
	} 
	cout << ans.size() << endl;
	for(auto cur : ans) {
		cur.write();
	}




	return 0;
}

Measured memory_bytes: 5232
#include <bits/stdc++.h>
#define all(x) x.begin(),x.end()
#define setval(arr,v) memset(arr,v,sizeof(arr));
#define lli long long int
#define ll long long
#define mod 1000000007
#define v vector
#define pb push_back
#define pf pop_front;
#define fi first
#define se second
using namespace std;

void solve()
{
    int t;
    cin>>t;
    if(t >= 30)
        cout<<"Yes";
    else
        cout<<"No";


}


int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t = 1;
    // cin>>t;
    while(t--)
    {
        solve();



    }
    return 0;

}



Measured memory_bytes: 3648
/*
*                                 Name : chaitanya
*
*                         Institute : ANITS,Visakhapatnam
*   "Don't regret anything you do, because in the end it makes you who you are."
*
*/
#include<cstdio>
#include<iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include<cstring>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>
#include<sstream>
#define infy  1000000000
#define all(x) begin(x),end(x)
#define ll long long int
#define ff first
#define ss second
#define pb push_back
const ll m = 1000000007;
using namespace std;

int main()
{
    ll x,m,d;
    cin >> x >> m >> d;
    x = abs(x);
    if( x == d)
    {
        if(m % 2 == 0)
            cout << x;
        else
            cout << 0;
    }
    else
    {
        ll cn = x/d;
        if( m >= cn)
        {
            m = m-cn;
            x = x-(d*cn);
            if( m % 2 == 0)
                cout << x;
            else
                cout << abs(x-d);
        }
        else
            cout << abs(x-(d*m));
    }
    return 0;    
}

Measured memory_bytes: 3584
module Main (main) where
  
import qualified Data.ByteString.Char8     as C8
import           Data.Maybe

main :: IO ()
main = do
  [n] <- readInts
  putStrLn . showAnswer $ solve n

type Input  = (Int)
type Output = Bool

solve :: Input -> Output
solve = cmp . show

cmp :: String -> Bool
cmp cs = (cs !! 0) == cs !! 2

-- utils
readInts :: IO [Int]
readInts = map (fst . fromJust . C8.readInt) . C8.words <$> C8.getLine

class ShowAnswer a where
  showAnswer :: a -> String

instance ShowAnswer Bool where
  showAnswer True  = "Yes"
  showAnswer False = "No"

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

using namespace std;
using ll = long long;

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << #x << ": " << x << endl;
#define popcnt __builtin_popcount


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

    ll sum = 0, xorsum=0, res=0;
    int left=0, right=0;
    while(left<N){
        while(right<N&&(sum+A[right])==(xorsum^A[right])){
            sum+=A[right];
            xorsum^=A[right];
            right++;
        }
        res+=(right-left);//区間の長さを足す！！！！leftが増加した時の場合がカウントされないため。

        if(left==right){
            right++;
        }else{
            sum-=A[left];
            xorsum^=A[left];
            left++;
        }
    }
    cout<<res<<endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incID(i, l, r) for(LL i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(LL i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(LL i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(LL i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC static_cast
#define SI(v) SC<int>(v.size())
#define SL(v) SC<LL >(v.size())
#define RF(e, v) for(auto & e: v)
#define ef else if
#define UR assert(false)

// ---- ----

int n, d[200][200];
string s[200];

int c[200];
void dfs(int v, int cc) {
	if(c[v] != 0) {
		if(c[v] == cc) { return; } else { cout << -1 << endl; exit(0); }
	}
	c[v] = cc;
	inc(i, n) {
		if(s[v][i] == '0') { continue; }
		dfs(i, -cc);
	}
}

void f(int v) {
	inc(i, n) { c[i] = 0; }
	dfs(v, +1);
}

int main() {
	cin >> n;
	inc(i, n) { cin >> s[i]; }
	
	inc(i, n) { f(i); }
	
	int INF = 777;
	inc(i, n) {
	inc(j, n) {
		d[i][j] = (s[i][j] == '0' ? INF : 1);
	}
	}
	inc(k, n) {
	inc(i, n) {
	inc(j, n) {
		setmin(d[i][j], d[i][k] + d[k][j]);
	}
	}
	}
	inc(i, n) {
	inc(j, n) {
		if(i == j || d[i][j] == INF) { d[i][j] = 0; }
	}
	}
	
	int ans = 0;
	inc(i, n) {
	inc(j, n) {
		setmax(ans, d[i][j]);
	}
	}
	
	cout << ans + 1 << endl;
	
	return 0;
}


Measured memory_bytes: 512
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

#n = int(input())
n,k,q = [int(i) for i in readline().split()]
a = [int(readline())-1 for i in range(q)]


res = [k-q]*n



for i in a:
    res[i] += 1


for i in res:
    if i > 0: print("Yes")
    else: print("No")



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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll n, d;
  cin >> n >> d;

  if(n % (d * 2 + 1) == 0)
    cout << n / (d * 2 + 1) << endl;
  else
    cout << n / (d * 2 + 1) + 1 << endl;
  
  
}


Measured memory_bytes: 256
/*
      author : nishi5451
      created: 11.08.2020 00:58:09
*/

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


int main(){
    int n;
    cin >> n;
    cout << "ABC" << n << endl;

    return 0;
}

Measured memory_bytes: 3636
import Text.Printf
import Control.Applicative

main :: IO ()
main = do
  [a,b] <- words <$> getLine
  -- (maxCount, minCount) <-
  -- printf "%d %d\n" (maximum countList) (minimum countList)
  if a == "H"
  then if b == "H"
       then putStrLn "H"
       else putStrLn "D"
  else if b == "H"
       then putStrLn "D"
       else putStrLn "H"


Measured memory_bytes: 380
_,M,s,*A=`dd`.split.map &:to_i
*b=a=[r=0]*(2*M+1)
A.each{|e|
	e+=M if e<s
	k=e-s
	if k>1
		a[s+1]+=1
		a[e]-=k
		a[e+1]+=k-1
	end
	r += k
	s = e%M
}
0.upto(2*M-2){|i|
	a[i+1] += a[i]
}
0.upto(2*M-2){|i|
	a[i+1] += a[i]
}
p r - M.times.map{|i|a[i]+a[i+M]}.max

Measured memory_bytes: 12944
function Main(input) {
    input = input.trim().split("\n").map(function(x) { return x.split(" ")});
    let S = input[0][0];
    if (S[S.length - 1] == 's') console.log(S + "es");
    else console.log(S + "s");
}



Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

int main(){
  int a,b;
  cin >> a >> b;
  if(a==b)
    cout << "a == b" << endl;
  else if(a < b)
    cout << "a < b"<< endl;
  else if(a > b)
    cout << "a > b" << endl;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define srt(a) sort(a.begin(),a.end())
#define rsrt(a) sort(a.rbegin(),a.rend())
#define lb(a,b) lower_bound(a.begin(),a.end(),b)
#define ub(a,b) upper_bound(a.begin(),a.end(),b)
#define MOD ((int)(1e9+7))
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define float long double
#define sqrt sqrtl
#define cbrt cbrtl
typedef vector<int> vi;
typedef vector<float> vf;
typedef pair<float,int> fi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<fi> vfi;
typedef vector<vi> vvi;
typedef vector<vf> vvf;
typedef vector<vii> vvii;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef priority_queue<int> pqi;
typedef priority_queue<ii> pqii;
typedef priority_queue<fi> pqfi;
typedef priority_queue <int, vector<int>, greater<int> > rpqi; 
typedef priority_queue <ii, vector<ii>, greater<ii> > rpqii; 
typedef priority_queue <fi, vector<fi>, greater<fi> > rpqfi; 


int32_t main()
{
	IOS
	string s;cin>>s;
	int n=s.length();
	bool b=1;int cnt=0;
	for(int i=2;i<=n-2;i++)if(s[i]=='C')cnt++;
	if(cnt!=1)b=0;
	if(s[0]!='A')b=0;
	for(int i=0;i<n;i++)
	{
		if(s[i]!='A' && s[i]!='C' && isupper(s[i]))b=0;
	}
	if(b)cout<<"AC"<<endl;
	else cout<<"WA"<<endl;
}
			
	


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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

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

int main() {
   ll n, a, b;
   cin >> n >> a >> b;

   if (a > b) {
      cout << 0 << endl;
      return 0;
   }
   if (n==1) {
      if (a == b) {
         cout << 1 << endl;
      } else {
         cout << 0 << endl;
      }
      return 0;
   }

   // cout << (b-a) * (n-2) + 1 << endl;
   ll x = a + (n-1) *b;
   ll y = (n-1) * a + b;
   cout << x - y + 1 << endl;

   return 0;
}

Measured memory_bytes: 256
# coding: utf-8
s = input()

for i, x in enumerate(s):
    if x == "A":
        i_a = i
        break

for i, x in enumerate(s[::-1]):
    if x == "Z":
        i_z = len(s) - (i + 1)
        break

print(i_z - i_a + 1)


Measured memory_bytes: 3560
#include <math.h>

#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;

int main() {
    int a;
    string s;
    cin >> a;
    cin >> s;
    if (a >=3200) {
        cout << s << endl;
    } else {
        cout << "red" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

void partition(int a[], int p, int r) {
  int i = p - 1;
  for (int j = p; j <= r - 1; j++) {
    if (a[j] <= a[r]) {
      i++;
      int tmp = a[i];
      a[i] = a[j];
      a[j] = tmp;
    }
  }
  int tmp = a[i+1];
  a[i+1] = a[r];
  a[r] = tmp;
  
  for (int k = 0; k <= r; k++) {
    if (k == i + 1) {
      printf("[%d]", a[k]);
    } else {
      printf("%d", a[k]);
    }
    if (k == r) {
      printf("\n");
    } else {
      printf(" ");
    }
  }
}
int main() {
  int n;
  scanf("%d", &n);
  int a[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  partition(a, 0, n - 1);
  return 0;
}



Measured memory_bytes: 2108
#include<iostream>
using namespace std;
int main(){
	int a[3];
	cin>>a[0]>>a[1]>>a[2];
	int minv=0x7fffffff;
	for(int i=0;i<2;++i)
		for(int j=i+1;j<3;++j)
			minv=min(minv,a[i]+a[j]);
	cout<<minv<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String S = sc.next();
        int count = 0;
        int ans = 0;
        for (int i = 0; i < N; i++) {
            if (S.charAt(i) == 'I') {
                count++;
                ans = Math.max(ans, count);
            } else {
                count--;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 22996
#include <stdio.h>
#include <math.h>
#include <string.h>
#define rep(i,a,n) for(int i=a;i<n;i++)

int main(){
	double x1,y1,x2,y2;
	scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
	printf("%.10lf\n",sqrt(pow((x1-x2),2)+pow((y1-y2),2)));
	return 0;
}

Measured memory_bytes: 1084
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

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

  i64 N, K;
  cin >> N >> K;
  vector<i64> A(N);
  for (auto& x : A) {
    cin >> x;
  }
  vector<i64> acc(N + 1);
  map<i64, int> pcnt;
  pcnt[0]++;
  i64 ans = 0;
  REP(i, N) {
    if (i - K + 1 >= 0) {
      i64 px = (acc[i - K + 1] - ((i + 1) % K) + K) % K;
      pcnt[px]--;
    }
    i64 rem = (acc[i] + A[i]) % K;
    acc[i + 1] = rem;
    i64 p = (rem - 1 - (i % K) + K) % K;
    i64 c = pcnt[p];
    ans += c;
    pcnt[p]++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incID(i, l, r) for(LL i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(LL i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(LL i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(LL i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC static_cast
#define SI(v) SC<int>(v.size())
#define SL(v) SC<LL >(v.size())
#define RF(e, v) for(auto & e: v)
#define ef else if
#define UR assert(false)

// ---- ----

int main() {
	int n, t;
	vector<pair<int, int>> v;
	cin >> n >> t;
	inc(i, n) {
		int a, b;
		cin >> a >> b;
		v.EB(a, b);
	}
	sort(ALL(v));
	
	vector<int> dp(6001, -1e9);
	dp[0] = 0;
	int ans = 0;
	inc(i, n) {
		dec(j, t) {
			if(dp[j] < 0) { continue; }
			setmax(dp[j + v[i].FI], dp[j] + v[i].SE);
			setmax(ans, dp[j] + v[i].SE);
		}
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cassert>

using namespace std;


int main() {

  int N;

  cin >> N;
  vector< vector<long long> > A(N, vector<long long>(N));

  for (auto i=0;i <N; i++)
  for (auto j=0;j <N; j++) cin >> A[i][j];

  vector<long long> F( 1<<17, 0);

  // consider all sub sets of {1..N}
  vector<int> l(16, 0);
  for (long long s = 1; s < (1<<N); s++) {
    l.resize(0);

    auto ss= s;
    int c = 0;
    while(ss != 0) {
      if (ss & 1 ) l.push_back(c);
      ss = ss >> 1;
      c++;
    }

    // for (auto tt=0; tt<l.size(); tt++) 
    // cout << "l" << l[tt] << "  ";
    // cout << endl;
    F[s] = 0;
    for (auto i=0; i < l.size(); i++)
    for (auto j=i+1; j < l.size(); j++) F[s] += A[l[i]][l[j]];

    auto L = l.size();

    for (int j = s; j; j = (j-1)&s) {
      F[s] = max( F[s], F[s^j]+F[j]);
    }

    // cout << endl;
  }


  cout << F[ (1<<N)-1] << endl;

  return 0;
}

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

int main()
{	
	double e[2];
	int a[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };

	while (cin >> e[0] >> e[1]) {
		int j = 0;

		for (int i = 0; i < 2; i++) {
			if (e[i] >= 1.1)
				a[j]++;
			else if (e[i] >= 0.6 && e[i] < 1.1)
				a[j + 1]++;
			else if (e[i] >= 0.2 && e[i] < 0.6)
				a[j + 2]++;
			else if (e[i] < 0.2)
				a[j + 3]++;

			j += 4;
		}
	}

	for (int i = 0; i < 4; i++)
		cout << a[i] << " " << a[i + 4] << endl;

	return 0;
}


Measured memory_bytes: 3148
#include<stdio.h>

int main(void){
	
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	
	if((a<b)&&(b<c)){
		printf("Yes\n");
		
	}else{
		printf("No\n");
	}	
	
	return 0;
}

Measured memory_bytes: 576
#include <vector>
#include <iostream> // C++11 以前
#include <utility>  // C++11 以降
#include <cstdint>

// begin
class union_find {
private:
  std::vector< int_fast32_t > data_;

public:
  union_find(std::size_t size) : data_(size, -1) {}

  std::size_t size() const {
    return data_.size();
  }

  // x を含む集合の representative を経路圧縮しながら返す
  int_fast32_t get_root(int_fast32_t x) {
    return (data_[x] < 0 ? x : data_[x] = get_root(data_[x]));
  }

  // x が集合の representative なら true を返す
  bool is_root(int_fast32_t x) {
    return x == get_root(x);
  }

  // x と y が同じ集合に含まれるなら ture を返す
  bool is_same(int_fast32_t x, int_fast32_t y) {
    return get_root(x) == get_root(y);
  }

  // x を含む集合と y を含む集合を併合
  void unite(int_fast32_t x, int_fast32_t y) {
    x = get_root(x); y = get_root(y);
    if (x == y) return;

    if (data_[x] > data_[y]) std::swap(x, y);
    data_[x] += data_[y];
    data_[y] = x;
  }

  // x を含む集合の要素数を返す
  int_fast32_t element_count(int_fast32_t x) {
    return -data_[get_root(x)];
  }
};
// end

#include <iostream>
using namespace std;

// https://onlinejudge.u-aizu.ac.jp/courses/library/3/DSL/1/DSL_1_A
void solver1() {
  int n, q;
  cin >> n >> q;

  union_find uf(n);
  while (q--) {
    int com, x, y;
    cin >> com >> x >> y;

    if (com == 0) {
      uf.unite(x, y);
    }
    else {
      cout << uf.is_same(x, y) << endl;
    }
  }
}

int main() {
  solver1();
}



Measured memory_bytes: 3196
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};

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; }

struct Timer{
    chrono::system_clock::time_point start, end;
    Timer(){ start = chrono::system_clock::now(); }
    ~Timer(){
        end = chrono::system_clock::now();
        auto msec = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cerr<<"time : "<<msec<<" ms"<<endl;
    }
};




signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    // Timer TM;

    ll h,w;
    ll n;
    cin>>h>>w>>n;
    if(h<w) swap(h,w);
    cout<<n/h+(n%h!=0)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    char s[7];
    for(int i=0;i<6;i++){
        scanf("%s",&s[i]);
    }
    if(s[2]==s[3]&&s[4]==s[5]){
        printf("Yes");
    }else{
        printf("No");
    }
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<tuple>
#include<queue>
#include<climits>
#include<functional>
#include<algorithm>
using namespace std;

typedef tuple<int, int, int> Point;
typedef tuple<int, Point> Node;
int Next[2][9][2] ={
    {
        {-2, 1}, {-1, 1}, {0, 1}, {1, 1}, {2, 1},
        {-1, 2}, {0, 2}, {1, 2},
        {0, 3}
    },
    {
        {-2, -1}, {-1, -1}, {0, -1}, {1, -1}, {2, -1},
        {-1, -2}, {0, -2}, {1, -2},
        {0, -3}
    },

};
enum {LEFT, RIGHT};
enum {Y, X, SIDE};
enum {COST, POINT};
enum {START = -2, TOP, NIL};

int Dijkstra(const vector<vector<int>>& cliff, const Point& start) {
    int result = INT_MAX;
    int h = cliff.size();
    int w = cliff.front().size();
    vector<vector<vector<int>>> cost(h, vector<vector<int>>(w, vector<int>(2, INT_MAX)));
    priority_queue<Node, vector<Node>, greater<Node>> q;
    q.push(Node(0, start));
    while(!q.empty()) {
        int c = get<COST>(q.top());
        Point point = get<POINT>(q.top());
        q.pop();
        if(cost[get<Y>(point)][get<X>(point)][get<SIDE>(point)] != INT_MAX) continue;
        cost[get<Y>(point)][get<X>(point)][get<SIDE>(point)] = c;
        for(const auto& d: Next[get<SIDE>(point)]) {
            int y = get<Y>(point) + d[Y];
            int x = get<X>(point) + d[X];
            if(y < 0 || h  <= y) continue;
            if(x < 0 || w  <= x) continue;
            if(cliff[y][x] == NIL) continue;
            if(cliff[y][x] == START) continue;
            if(cliff[y][x] == TOP) {
                result = min(result, c);
            } else {
                Point next_point(y, x, get<SIDE>(point) ^ 1);
                q.push(Node(c + cliff[y][x], next_point));
            }
        }
    }
    return result;
}

int main() {
    int w, h;
    while(cin >> w >> h, w | h) {
        vector<vector<int>> cliff(h, vector<int>(w));
        for(auto& line: cliff) for(auto& v: line) {
            char c;
            cin >> c;
            if(c == 'S') v = START;
            else if(c == 'T') v = TOP;
            else if(c == 'X') v = NIL;
            else v = c - '0';
        }

        int answer = INT_MAX;
        for(int y = 0; y < h; y++) for(int x = 0; x < w; x++) {
            if(cliff[y][x] != START) continue;
            answer = min({answer, Dijkstra(cliff, Point(y, x, LEFT)), Dijkstra(cliff, Point(y, x, RIGHT))});
        }
        cout << ((answer == INT_MAX) ? -1 : answer) << endl;
    }
}

Measured memory_bytes: 1428
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
int n=Integer.parseInt(s);
char c[]=s.toCharArray();
int fn=0;
for(int i=0;i<c.length;i++){
	String k=String.valueOf(c[i]);
	fn+=Integer.parseInt(k);
}

if(n%fn==0){
	System.out.println("Yes");
}else{
	System.out.println("No");
}
	}}

Measured memory_bytes: 21844
x1,y1,r1 = map(float,input().split())
x2,y2,r2 = map(float,input().split())
a,b = x2-x1,y2-y1
d = (a**2+b**2+r1**2-r2**2)/2
x = (d*a+b*(((a**2+b**2)*r1**2 - d**2)**0.5))/(a**2+b**2)
y = (d*b-a*(((a**2+b**2)*r1**2 - d**2)**0.5))/(a**2+b**2)

z = (d*a-b*(((a**2+b**2)*r1**2 - d**2)**0.5))/(a**2+b**2)
w = (d*b+a*(((a**2+b**2)*r1**2 - d**2)**0.5))/(a**2+b**2)
if x < z:
    print(x1+x,y1+y,end=' ')
    print(x1+z,y1+w)

elif x > z:
    print(x1+z,y1+w,end=' ')
    print(x1+x,y1+y)
elif y < w:
    print(x1+x,y1+y,end=' ')
    print(x1+z,y1+w)
else:
    print(x1+z,y1+w,end=' ')
    print(x1+x,y1+y)

Measured memory_bytes: 7716
import math


data = [ "a","b","c","d","e","f","g","h","i","j" ]


result = []


def create( max_letter, remaining_depth, text ):
    if remaining_depth == 0:
        result.append(text)
        return
    
    for i in range(0,max_letter+1):
        new_text = text + data[i]
        create( max(i+1,max_letter),remaining_depth-1,new_text )
        
    
        
        





N = int(input())

create( 0,N,"")

result.sort()
for line in result:
    print(line)










    

    
        
    
                
    



Measured memory_bytes: 61340
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<iomanip>

using namespace std;

int main()
{
	int n,a,b,c,d;
	cin >> n >> a >> b >> c >> d;
	string s;
	cin >> s;
	
	bool canjamp=false;
	if(s[b-1-1]=='.' and s[b-1+1]=='.')canjamp=true;
	bool ans=false;
	int now=b-1;
	s+='.';
	while(true)
	{
		if(s[now+1]=='.')
			now++;
		else if(s[now+2]=='.')
			now+=2;
		else
		{
			cout << "No" << endl;
			return 0;
		}

		if(now==d-1)
		{
			if(s[now-1]=='.' and s[now+1]=='.')
				canjamp=true;
			break;
		}
		if(now>d-1)
		{
			cout << "No" << endl;
			return 0;
		}

		if(s[now-1]=='.' and s[now+1]=='.')
			canjamp=true;
	}

	if(c>d)
	{
		if(!canjamp)
		{
			cout << "No" << endl;
			return 0;
		}
	}
	
	now=a-1;
	while(true)
	{
		if(s[now+1]=='.')
			now++;
		else if(s[now+2]=='.')
			now+=2;
		else
		{
			cout << "No" << endl;
			return 0;
		}

		if(now==c-1)
		{
			if(s[now-1]=='.' and s[now+1]=='.')
				canjamp=true;
			break;
		}
		if(now>c-1)
		{
			cout << "No" << endl;
			return 0;
		}

		if(s[now-1]=='.' and s[now+1]=='.')
			canjamp=true;
	}


	cout << "Yes" << endl;



}



Measured memory_bytes: 640
import java.io.PrintWriter;
import java.util.*;

public class Main {
	public static class Node {
		int idx;
		ArrayList<Node> edges = new ArrayList<>();
		public Node(int idx) {
			this.idx = idx;
		}
	}
	public static class Graph {
		int N;
		Node[] nodes;
		public Graph(int n) {
			N = n;
			nodes = new Node[N];
			for(int i=0; i<N; i++)
				nodes[i] = new Node(i);
		}
		
		public void addEdge(int a, int b) {
			nodes[a].edges.add(nodes[b]);
			nodes[b].edges.add(nodes[a]);
		}
		
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);

		int N = sc.nextInt();
		Graph g = new Graph(N);

		int M = sc.nextInt();
		for(int i=0; i<M; i++) {
			int a = sc.nextInt()-1;
			int b = sc.nextInt()-1;
			g.addEdge(a, b);
		}
		
		LinkedList<Integer> ans = new LinkedList<>();
		boolean[] visited = new boolean[N];
		
		visited[0] = true;
		ans.add(0);
		for(int i=0; i<2; i++) {
			int cur = 0;
			while(true) {
				int next=-1;
				for(Node n : g.nodes[cur].edges) {
					if(!visited[n.idx]) {
						next = n.idx;
						break;
					}
				}
				if(next<0)
					break;
				visited[next] = true;
				if(i==0)
					ans.push(next);
				else
					ans.add(next);
				cur = next;
			}
		}
	
		pw.println(ans.size());
		Iterator<Integer> it = ans.iterator();
		while(it.hasNext())
			pw.print((it.next()+1) + (it.hasNext() ? " " : "\n"));
		
		sc.close();
		pw.close();
	}
}


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


int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> x(M), y(M);
    for(int i = 0; i < M; ++i){
        cin >> x[i] >> y[i];
        --x[i], --y[i];
    }

    vector<int> num_balls(N, 1);
    vector<bool> r_in(N, false);
    r_in[0] = true;
    for(int i = 0; i < M; ++i){
        --num_balls[x[i]];
        ++num_balls[y[i]];
        if(r_in[x[i]] == true) r_in[y[i]] = true;
        if(num_balls[x[i]] == 0) r_in[x[i]] = false;
    }
    int ans = 0;
    for(int i = 0; i < N; ++i){
        if(r_in[i]) ++ans;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) max_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h, w;
    cin >> h >> w;
    ves field(h);
    rep(i,h) cin >> field[i];
    ve_vei d(h, vei(w, -1));
    vector<i_i> que;
    rep(i,h) rep(j,w) {
        if (field[i][j] == '#') {
            que.emplace_back(i, j);
            d[i][j] = 0;
        }
    }
    rep(b,que.size()) {
        for (int dx = -1; dx <= 1; dx++) {
            for (int dy = -1; dy <= 1; dy++) {
                if (dx * dx + dy * dy == 1) {
                int xk = que[b].fs + dx;
                int yk = que[b].sc + dy;
                if (xk >= 0 && yk >= 0 && xk < h && yk < w && d[xk][yk] == -1) {
                    que.emplace_back(xk, yk);
                    d[xk][yk] = d[que[b].fs][que[b].sc] + 1;
                }
            }
        }
        }
    }
  cout << d[que.back().fs][que.back().sc] << endl;
  return 0;
}

Measured memory_bytes: 14708
#!/usr/bin/env python3

from collections import namedtuple
from operator import attrgetter

City = namedtuple("City", "ID, pref, year")

N, M = map(int, input().split())

Cities = []
for ID in range(M):
    pref, year = map(int, input().split())
    Cities.append(City(ID, pref, year))

def get_sID(Cities):
    temp = Cities.copy()

    temp.sort(key=attrgetter("year"))
    temp.sort(key=attrgetter("pref"))

    lid = 1
    currentPref = None
    for City in temp:
        if currentPref != City.pref:
            currentPref = City.pref
            lid = 1

        yield City.ID, "{0:0>6}{1:0>6}".format(City.pref, lid)
        lid += 1

for _, sID in sorted(get_sID(Cities)):
    print(sID)


Measured memory_bytes: 38652
n=int(input())
s=input()

r=s.count('R')
g=s.count('G')
b=s.count('B')

ans=r*g*b
for i in range (n):
  for d in range (n):
    j=i+d
    k=j+d
    if k>=n:
      break
    if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:
      ans-=1

print(ans)

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

const int MAX = 500000;
const int SENTINEL = 2000000000;

int *L, *R;
int cnt;

void merge(int a[], int n, int left, int mid, int right){
    int n1 = mid - left;
    int n2 = right - mid;
    for(int i=0; i<n1; ++i) L[i] = a[left+i];
    for(int i=0; i<n2; ++i) R[i] = a[mid+i];

    L[n1] = R[n2] = SENTINEL;
    int i=0, j=0;
    for(int k=left; k<right; ++k){
        ++cnt;
        if(L[i] <= R[j]){
            a[k] = L[i++];
        }else{
            a[k] = R[j++];
        }
    }
}

void mergeSort(int a[], int n, int left, int right){
    if(left + 1 < right){
        int mid = (left + right) / 2;
        mergeSort(a, n, left, mid);
        mergeSort(a, n, mid, right);
        merge(a, n, left, mid, right);
    }
}


int main(){
    int *a, n;
    cnt = 0;

    cin >> n;
    a = new int[n];
    for(int i=0; i<n; ++i) cin >> a[i];

    L = new int[n/2 + 2];
    R = new int[n/2 + 2];
    mergeSort(a, n, 0, n);
    delete[] L, R;

    for(int i=0; i<n; ++i){
        if(i) cout << " ";
        cout << a[i];
    }
    delete[] a;

    cout << endl;

    cout << cnt << endl;
}



Measured memory_bytes: 6668
#include "bits/stdc++.h"

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

int main() {

    ll H, W;
    cin >> H >> W;
        
    if(H == 1 || W == 1){
        cout << 1 << endl;
        return 0;
    }

    if(((H * W) % 2) == 1){
        cout << (H  *  W) / 2 + 1 << endl;
    }else{
        cout << (H  *  W) / 2 << endl;
    }
 

}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstdlib>

using namespace std;

char num1[5]={'.', ',', '!', '?', ' '};
char num2[]="abc", num3[]="def", num4[]="ghi", num5[]="jkl", num6[]="mno", num7[]="pqrs", num8[]="tuv", num9[]="wxyz";

char func(int x, int y);

int main()
{
	int n, ch;
	cin >> n;
	ch = getchar();
	for(int i = 0; i < n; i++){
		int c1, c2=-1, c3=0;
		char c;
		while(1){
			c1 = getchar();
			if(c1 == '\n'){
				cout << endl;
				break;
			} else if(c1 == '0'){
				if(c2 != -1){
					c = func(c2, c3);
					cout << c;
					c3 = 0;
					c2 = -1;
				}
			} else {
				if(c1 == c2) c3++;
				else {
					c1 = c1 - '0';
					c2 = c1;
					c3++;
				}
			}
		}
	}
	return 0;
}

char func(int x, int y)
{
	int z;
	if(x == 1) return num1[(y-1)%5];
	else if(x == 2) return num2[(y-1)%3];
	else if(x == 3) return num3[(y-1)%3];
	else if(x == 4) return num4[(y-1)%3];
	else if(x == 5) return num5[(y-1)%3];
	else if(x == 6) return num6[(y-1)%3];
	else if(x == 7) return num7[(y-1)%4];
	else if(x == 8) return num8[(y-1)%3];
	else return num9[(y-1)%4];
}

Measured memory_bytes: 1152
#include <bits/stdc++.h> 
#include <vector>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;
using Field=vector<vector<int>>;

int main(){
    int n;
    cin>>n;
    vector<int> d(n);
    rep(i,n)cin>>d[i];
    sort(d.begin(),d.end());
    if(d[n/2]==d[n/2-1]){
        cout<<0<<endl;
        return 0;
    }else{
        cout<<d[n/2]-d[n/2-1]<<endl;
        return 0;
    }
}


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

int main(int argc, char *argv[])
{
    int Taro = 0, Hanako = 0;
    int num;
    scanf("%d", &num);
    char TaStr[100] = {'\0'}, HaStr[100] = {'\n'};

    for (int i = 0; i < num; i++)
    {
        scanf("%s %s", TaStr, HaStr);
        if (strcmp(TaStr, HaStr) > 0)
        {
            Taro += 3;
        }
        else if (strcmp(TaStr, HaStr) < 0)
        {
            Hanako += 3;
        }
        else
        {
            Taro++;
            Hanako++;
        }
    }
    printf("%d %d\n", Taro, Hanako);
    return 0;
}



Measured memory_bytes: 3200
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int T, card[16];

bool is_same_number(int a, int b, int c){
	if (a == b && a == c) return true;
	else return false;
}

bool is_sequense(int a, int b, int c){
	if (a == b - 1 && a == c - 2) return true;
	else return false;
}

bool is_good_set(int a, int b, int c){
	return is_same_number(a, b, c) || is_sequense(a, b, c);
}

bool is_all_good_set(){
	return is_good_set(card[0], card[1], card[2]) 
			&& is_good_set(card[3], card[4], card[5])
			&& is_good_set(card[6], card[7], card[8]);
}

int win(){
	sort(card, card + 9);
	do {
		if (is_all_good_set()) return 1;
	} while (next_permutation(card, card + 9));
	return 0;
}

int main(){
	cin >> T;
	for (int t = 0; t < T; t++){
		for (int i = 0; i < 9; i++){
			cin >> card[i];
		}
		string color;
		for (int i = 0; i < 9; i++){
			cin >> color;
			if (color == "G") card[i] += 10;
			else if (color == "B") card[i] += 20;
//			cout << card[i];
		}
		cout << win() << endl;
	}
}

Measured memory_bytes: 1224
import sys
input = sys.stdin.readline

def same_tree(node_a, node_b):
    if node_a.root() == node_b.root():
        return True

def unite(node_a, node_b):
    root_a = node_a.root()
    root_b = node_b.root()
    if root_a == root_b:
        return
    if root_b.depth > root_a.depth:
        root_a, root_b = root_b, root_a
    root_b.is_root = False
    root_b.parent = root_a
    root_a.depth = max(root_a.depth, root_b.depth+1)

class Node:
    def __init__(self):
        self.is_root = True
        self.parent = None
        self.depth = 1
    
    def root(self):
        node = self
        while not node.is_root:
            node = node.parent
        return node

def main():
    N = int(input())
    
    nodes = [Node() for i in range(N)]

    # 各町の座標をタプル(i, x, y)に入れて配列に格納
    xy = []
    for i in range(N):
        x, y = map(int, input().split())
        xy.append((i, x, y))
    
    # 使う可能性のある辺のみを取り出す
    edges = []
    xy = sorted(xy, key=lambda x: x[1])# x座標昇順
    # print("x:", xy)
    for i in range(1, N):
        edges.append((xy[i][1] - xy[i-1][1], xy[i-1][0], xy[i][0]))
    xy = sorted(xy, key=lambda x: x[2])# y座標昇順
    # print("y:", xy)
    for i in range(1, N):
        edges.append((xy[i][2] - xy[i-1][2], xy[i-1][0], xy[i][0]))
    
    ans = 0
    edges = sorted(edges)
    # print(edges)
    for (cost, a, b) in edges:
        if not same_tree(nodes[a], nodes[b]):
            unite(nodes[a], nodes[b])
            ans += cost
    print(ans)




if __name__ == "__main__":
    main()

Measured memory_bytes: 62620