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

using namespace std;


int main() {
    int h,w;
    cin>>h>>w;
    char ar[h][w];
    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
        {
            cin>>ar[i][j];
        }
    }
    long long int br[h][w];
    br[0][0]=1;
    int m = 1000000007;
    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
        {
            if(i==0&&j==0)
            continue;
            if(ar[i][j]=='#')
            {
                br[i][j]=0;
            }
            else
            {
                if(i==0)
                {
                    br[i][j]=br[i][j-1];
                }
                else if(j==0)
                {
                    br[i][j]=br[i-1][j];
                }
                else if(ar[i-1][j]=='#'&&ar[i][j-1]=='#')
                {
                    br[i][j]=0;
                }
                else if(ar[i-1][j]=='#')
                {
                    br[i][j]=br[i][j-1];
                }
                else if(ar[i][j-1]=='#')
                {
                    br[i][j]=br[i-1][j];
                }
                else
                {
                    br[i][j]=(br[i-1][j]+br[i][j-1])%m;
                }
            }
        }
    }
    cout<<(br[h-1][w-1]%(1000000007));
    return 0;
}



Measured memory_bytes: 9088
w, h, n = [int(x) for x in input().split()]
S = [0,w,0,h]

for i in range(n):
    x, y, a = [int(_) for _ in input().split()]

    if a == 1:
        S[0] = max(S[0], x)        
    if a == 2:
        S[1] = min(S[1], x)
    if a == 3:
        S[2] = max(S[2], y)        
    if a == 4:
        S[3] = min(S[3], y)

if S[0] < S[1] and S[2] < S[3]:
    ans = (S[1] - S[0]) * (S[3] - S[2])
else:
    ans = 0
    
print(ans)

Measured memory_bytes: 3064
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<cmath>
#include<limits>
#define ll long long
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define pint_INF 2000000000
#define ll_INF 	9223372036854775807
#define MOD 1000000007
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvc vector<vector<char>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
#define sysp system("PAUSE")
#define pi 3.14159265358979
using namespace std;

void C() {
	double A, B, H, M; cin >> A >> B >> H >> M;

	double vhour_hand, vmin_hand;
	vhour_hand = 2 * pi / 12 / 60;
	vmin_hand = 2 * pi / 60;
	double time = 60 * H + M;

	double temp = vmin_hand * time - vhour_hand * time;
	temp = max(temp, -temp);
	temp = fmod(temp, 2 * pi);
	double diff = min(temp, 2 * pi - temp);

	double ans = sqrt(pow(A, 2) + pow(B, 2) - 2 * A * B * cos(diff));

	
	printf("%.10f\n", ans);
}

void B() {
	int K; cin >> K;
	string s; cin >> s;

	if (s.size() > K) {
		string temp = s.substr(0, K);
		temp += "...";
		cout << temp << endl;
	}
	else {
		cout << s << endl;
	}
}

void A() {
	int N; cin >> N;
	int dig = N % 10;
	if (dig == 3) {
		cout << "bon" << endl;
	}
	else if (dig == 0 or dig == 1 or dig == 6 or dig == 8) {
		cout << "pon" << endl;
	}
	else {
		cout << "hon" << endl;
	}
}
int main() {
	A();
}

Measured memory_bytes: 3624
#![allow(unused_parens)]
#![allow(unused_imports)]
#![allow(non_upper_case_globals)]
#![allow(non_snake_case)]
#![allow(unused_mut)]
#![allow(unused_variables)]
#![allow(dead_code)]

use itertools::Itertools;
use proconio::input;
use proconio::marker::{Chars, Usize1};

#[allow(unused_macros)]
#[cfg(debug_assertions)]
macro_rules! mydbg {
    //($arg:expr) => (dbg!($arg))
    //($arg:expr) => (println!("{:?}",$arg));
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
      }
}
#[cfg(not(debug_assertions))]
macro_rules! mydbg {
    ($($arg:expr),*) => {};
}

macro_rules! echo {
    ($($a:expr),*) => {
          $(println!("{}",$a))*
      }
}

use std::cmp::*;
use std::collections::*;
use std::ops::{Add, Div, Mul, Sub};

#[allow(dead_code)]
static INF_I64: i64 = 92233720368547758;
#[allow(dead_code)]
static INF_I32: i32 = 21474836;
#[allow(dead_code)]
static INF_USIZE: usize = 18446744073709551;
#[allow(dead_code)]
static M_O_D: usize = 1000000007;
#[allow(dead_code)]
static PAI: f64 = 3.1415926535897932;

trait IteratorExt: Iterator {
    fn toVec(self) -> Vec<Self::Item>;
}

impl<T: Iterator> IteratorExt for T {
    fn toVec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

trait CharExt {
    fn toNum(&self) -> usize;
    fn toAlphabetIndex(&self) -> usize;
    fn toNumIndex(&self) -> usize;
}
impl CharExt for char {
    fn toNum(&self) -> usize {
        return *self as usize;
    }
    fn toAlphabetIndex(&self) -> usize {
        return self.toNum() - 'a' as usize;
    }
    fn toNumIndex(&self) -> usize {
        return self.toNum() - '0' as usize;
    }
}

trait VectorExt {
    fn joinToString(&self, s: &str) -> String;
}
impl<T: ToString> VectorExt for Vec<T> {
    fn joinToString(&self, s: &str) -> String {
        return self
            .iter()
            .map(|x| x.to_string())
            .collect::<Vec<_>>()
            .join(s);
    }
}

trait StringExt {
    fn get_reverse(&self) -> String;
}
impl StringExt for String {
    fn get_reverse(&self) -> String {
        self.chars().rev().collect::<String>()
    }
}

trait UsizeExt {
    fn pow(&self, n: usize) -> usize;
}
impl UsizeExt for usize {
    fn pow(&self, n: usize) -> usize {
        return ((*self as u64).pow(n as u32)) as usize;
    }
}

fn main() {
    input! {
       N: usize,
       M:usize,
       H:[usize;N],
       path:[(Usize1,Usize1);M],
    }

    let mut m = vec![true; N];
    for &(a, b) in &path {
        if H[a] <= H[b] {
            m[a] = false;
        }
        if H[b] <= H[a] {
            m[b] = false;
        }
    }
    let mut ans = 0;
    for &item in &m {
        if item {
            ans += 1;
        }
    }
    echo!(ans);
}


Measured memory_bytes: 6632
N=int(input())
ans=0
for i in range(N+1):
    if i>1 and i%2==1:
        div=[1,i]
        for j in range(2,int(i**0.5)+1):
            if i%j==0:
                div.append(j)
                div.append(i//j)
        if len(div)==8:
            ans+=1
print(ans)

Measured memory_bytes: 9256
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<map>
using namespace std;
map<pair<long long,int>,long long>dp;
long long A;
long long calc(long long N,int last){
	if(N<=A)return N;
	if(dp.count(make_pair(N,last))){
		return dp[make_pair(N,last)];
	}
	long long ret=N;
	for(long long i=max(max(2,last),(int)sqrt(2*A)-10);i<sqrt(2*A)+10;i++){
		ret=min(ret,i+A+calc((N+i-1)/i,i));
	}
	return ret;
}
int main(){
	long long a,b;
	scanf("%lld%lld",&a,&b);
	A=b;
	long long ret=a;
	for(int i=1;i<42;i++){
		long long cur=a;
		long long P=pow(a,1.0/(i+1))-1;
		for(int j=0;j<4;j++){
			long long t=P+j;
			long long now=0;
			for(int k=0;k<=i;k++){
				now=t;
				long long f=t;
				for(int l=0;l<i;l++){
					f+=t;
					if(l<k)f++;
					now*=(t+(l<k));
					if(now>=a)now=a+1;
				}
				if(now>=a){
					cur=min(cur,f);
				}
			}
		}
		ret=min(ret,cur+i*b);
	}
	printf("%lld\n",ret);
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <list>
#include <map>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define pb push_back
#define all(x) (x).begin(), (x).end()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

int main() {
    int x, a;
    cin >> x >> a;
    if (x < a) cout << 0 << endl;
    else cout << 10 << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define FUP(i, a, b) for(int i = a; i <= b; i++)
#define FDOWN(i, a, b) for(int i = a; i >= b; i--)
#define MS(a, b) memset(a, b, sizeof(a))
#define ALL(v) v.begin(), v.end()
#define CIN(a) cin >> a;
#define CIN2(a, b) cin >> a >> b
#define CIN3(a, b, c) cin >> a >> b >> c
#define COUT(a) cout << a
#define COUT2(a, b) cout << a << ' ' << b
#define COUT3(a, b, c) cout << a << ' ' << b << ' ' << c
#define ENDL cout << '\n'
int dy[4] = { -1, 1, 0, 0 };
int dx[4] = { 0, 0, 1, -1 };

int N, M, a, b, ans = 0, cnt;
vector<int> arr[200001];
bool visited[200001];

void DFS(int node)
{
	cnt++;
	visited[node] = true;
	for (int next : arr[node])
	{
		if (!visited[next])
		{
			DFS(next);
		}
	}
}

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

	CIN2(N, M);
	while (M--)
	{
		CIN2(a, b);
		arr[a].push_back(b);
		arr[b].push_back(a);
	}
	MS(visited, false);
	FUP(i, 1, N)
	{
		cnt = 0;
		if (!visited[i])
		{
			DFS(i);
		}
		ans = max(cnt, ans);
	}
	COUT(ans);

	return 0;
}

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

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

using namespace std;

int main(){
	int k,n; scanf("%d%d",&k,&n);
	vector<int> a(n);
	rep(i,n) scanf("%d",&a[i]);

	int mx=k-a[n-1]+a[0];
	rep(i,n-1) mx=max(mx,a[i+1]-a[i]);
	printf("%d\n",k-mx);

	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define mod 1000000007

using namespace std;
int main()
{
	IOS;
	int n;
	cin>>n;
	vector<int> v,v1(n),v2(n);
	for(int y=0;y<n;y++)
	{
		int m;
		cin>>m;
		v.pb(m);
	}
	v1[0]=v[0];
	for(int y=1;y<n;y++)
	{
		v1[y]=v[y]+v1[y-1];
	}
	v2[n-1]=v[n-1];
	for(int y=n-2;y>=0;y--)
	{
		v2[y]=v[y]+v2[y+1];
	}
	int ans=INT_MAX;
	//cout<<v2[0];
	for(int y=0;y<n-1;y++)
	{
		ans=min(abs(v1[y]-v2[y+1]),ans);
	}
	cout<<ans<<"\n";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define whlie while
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repr(i,N) for(int i = (N) - 1; i >= 0; i--)
#define rep1(i,N) for(int i = 1; i <= (N) ; i++)
#define repr1(i,N) for(int i = (N) ; i > 0 ; i--)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
using namespace std; void solve();
using ll = long long; using vl = vector<ll>;
using vi = vector<int>; using vvi = vector< vector<int> >;
constexpr int inf = 1001001001;
constexpr ll infLL = (1LL << 61) - 1;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(7);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cerr << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,N) do { cerr << #v << " = "; array_out(v , N);cout << endl;} while(0)
#else
  #define trc(...)
  #define trca(...)
  int main(){solve();}
#endif
using P = pair<ll,ll>; using vp = vector<P>;
constexpr int MOD = /**/ 1000000007; //*/ 998244353;
/////////

bitset<20000> dp[100][100];

void solve(){
  ini(H , W);
  vvi a(H , vi(W , 0)) , b(H , vi(W , 0));
  in(a); in(b);
  rep(i , H) rep(j , W) a[i][j] = abs(a[i][j] - b[i][j]);
 
  rep(i , H) rep(j , W){
    if(i == 0 && j == 0) dp[i][j][a[i][j]] = 1;
    else{
      rep(k , 19000){
        int cur = a[i][j];
        if(i != 0){
          dp[i][j][k] = dp[i][j][k] | dp[i-1][j][abs(cur - k)];
          dp[i][j][k] = dp[i][j][k] | dp[i-1][j][abs(cur + k)];
        }
        if(j != 0){
          dp[i][j][k] = dp[i][j][k] | dp[i][j-1][abs(cur - k)];
          dp[i][j][k] = dp[i][j][k] | dp[i][j-1][abs(cur + k)];
        }
      }
    }
  }
 
  rep(i , 81){
    if(dp[H-1][W-1][i]) die(i);
  }
  
}

Measured memory_bytes: 20480
class Problem
  attr_accessor :a, :b, :c, :n, :m, :h, :w, :x, :y, :ans
  def initialize
    @n = gets.to_s.to_i
    @ans = Hash.new(0)
  end

  def solve
    n.times do
      s = gets.chomp
      ans[s] += 1
    end
    %w(AC WA TLE RE).each do |key|
      printf("%s x %d\n", key, ans[key])
    end
  end
end

pb = Problem.new
pb.solve

Measured memory_bytes: 14336
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp make_pair
#define sz(x) ((int)(x).size())
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define all(x) x.begin(),x.end()
#define y1 omg
#define INF 1000000010
#define FOR(x, n) for(int x=0; x<n; x++)
#define ini(x, n) memset(x, n, sizeof(x));
#define MOD ((int)1e9 + 7)
#define atoi(x) ((x)-'0')
#define int ll
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;

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

int d, s, t;

signed main() {
	cin >> d >> s >> t;
	if (d > s * t) cout << "No";
	else cout << "Yes";
}

Measured memory_bytes: 3632
//	Author : amnptl 
//	   Godbless
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define NeedForSpeed() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MOD (1000000007); // 1e9+7
int main()
{
	NeedForSpeed();
	string s,t; cin>>s>>t;
	char last = t.back();
	s = s + last;
	if(s==t) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;		
	return 0;
}

Measured memory_bytes: 3620
# coding:utf-8
import sys

# 最大公約数
def gcd(a, b):
  while b > 0:
    a, b = b, a%b
  return a

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

for s in sys.stdin:
  a, b = map(int,s.split())
  gcd_num = gcd(a, b)
  lcm_num = lcm(a, b)
  print "%d %d"%(gcd_num, lcm_num)

Measured memory_bytes: 4204
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <functional>
#include <complex>
#include <stack>
#include <tuple>
#include <array>
#include <ctype.h> // isdigit
#include <cassert>
using namespace std;

#define LE(n,m) ((n) < (m) + EPS * (abs(n) + abs(m)))
#define GE(n,m) ((n) + EPS * (abs(n) + abs(m)) > (m))
#define LT(n,m) ((n) + EPS * (abs(n) + abs(m)) < (m))
#define GT(n,m) ((n) > (m) + EPS * (abs(n) + abs(m)))
#define EQ(n,m) (abs((n)-(m)) < EPS * (abs(n) + abs(m)))

typedef long long int ll;
const int INF = (1<<30) - 1;
const double EPS = 1e-9;
const int MOD = 1000000007;

int N;
vector<int> A;

//g++ -std=c++0x -msse4.2 -O3
//#include <bits/stdc++.h>
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout.precision(16);
    //cout.setf(ios::fixed);
    
    cin >> N;
    A.resize(N);
    for(auto &v: A) cin >> v;
    
    ll ans = A[0] - 1;
    int s = 2;
    for(int i=1; i<N; i++){
        if(A[i] == s){
            s++;
            continue;
        }
        
        int x = (A[i]-1)/s;
        ans += x;
        A[i] -= x*s;
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 768
n, x, y = map(int, input().split())

klist = [0]*(n)
for i in range(1, n):
  for j in range(i+1, n+1):
    k = min(j-i, abs(j-y)+1+abs(x-i))
    klist[k] += 1

for _ in range(1, n):
  print(klist[_])

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

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

int main() {
  string S;
  cin >> S;
  if(S[2] == S[3] && S[4] == S[5]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
s = list(input())
ans = 0

for i in range(1, len(s)):
    if s[i] == s[i-1] == "0":
        s[i] = "1"
        ans += 1
    elif s[i] == s[i-1] == "1":
        s[i] = "0"
        ans += 1

print(ans)

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

int main() {
  int n, k;
  std::cin >> n >> k;

  int p = 1;
  for (int i = 0; i < n; i++) {
    if (p < k) {
      p *= 2;
    } else {
      p += k;
    }
  }

  std::cout << p << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;

// 和以外はseg木でよくねという発想の元、和のみを実装
#include <cassert>
template <typename T>
class BIT {
    const int n;
    vector<T> tree;

public:
    BIT(int _n) : n(_n), tree((size_t)_n, 0) {}

    // v[a] += w
    template <typename ID>
    void add(ID a, T w) {
        assert(0 <= a && a < n);
        for (int i = (int)a; i < n; i |= (i + 1)) 
            tree[(size_t)i] += w;
    }

    // v[0] + v[1] + ... + v[a-1]
    template <typename ID>
    T sum(ID a) {
        assert(0 <= a && a <= n);
        T res = 0;
        for (int i = (int)a - 1; i >= 0; i = (i & (i + 1)) - 1)
            res += tree[(size_t)i];
        return res;
    }

    // 総和
    T sum() { return sum(n); }

    // v[0] + v[1] + ... + v[a] >= w なる最小のa
    int lower_bound(T w) {
        int x = 0, beki = 1;
        for (int _n=n; _n>0; _n>>=1) beki <<= 1;
        for (int k=beki; k>0; k>>=1) {
            if (x + k <= n && tree[(size_t)(x + k - 1)] < w) {
                w -= tree[(size_t)(x + k - 1)];
                x += k;
            }
            cerr << k << ' ' << x << ' ' << tree[x] << '\n';
        }
        return x;
    }

    // set(被りなし)としての機能を見やすく
    // ただし同じものをたとえば二回pushする場合、値が+2となって一回のpopでは消えないというバグあり
    template <typename ID>
    void push(ID a) { add(a, 1); }

    template <typename ID>
    void pop(ID a) { add(a, -1); }
};

#include <map>
#include <set>
// vecのなかの全要素について座標圧縮を行い、元座標->圧縮後座標というmapを作る
// O(NlogN) 座圧後のサイズを返す
// org: もともとの各iに対する座標 値渡しなので破壊しません
// zip: 圧縮
// unzip: 復元
template <typename T>
int compress(vector<T> org, map<T, int> &zip, vector<T> &unzip) {
    sort(org.begin(), org.end()); 
    org.erase(unique(org.begin(), org.end()), org.end()); // vecの各要素を小さい順に重複を無くして並べたもの
    int i = 0;
    for (auto &oi : org) {
        zip[oi] = i;
        unzip.push_back(oi);
        i++;
    }
    return i;
}

int main() {
    long n;
    cin >> n;
    vector<long> a(n);
    for (auto &ai:a)
        cin >> ai;
    map<long, int> zip;
    vector<long> unzip;
    int k = compress(a, zip, unzip);
    int l = -1, r = k-1;
    while (r - l > 1) {
        int m = (l + r + 1) / 2,
            med = unzip[m];
        int rui = n;
        BIT<int> bit(2*n+1);
        bit.add(n, 1);
        long score = 0;
        // cerr << med << '\n' << rui;
        for (auto &ai:a) {
            if (ai > med) rui--;
            else rui++;
            bit.add(rui, 1);
            score += bit.sum(rui);
            // cerr << ' ' << rui;
        }
        // cerr << '\n' << score << '\n' << '\n';
        if (score >= (n * (n+1) / 2) / 2 + 1) r = m;
        else l = m;
    }
    cout << unzip[r] << '\n';
    return 0;
}

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

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

	sort(q.begin(), q.end());
	int ct = 0;
	for (int j = 0; j < n; j++) {
		if (p[j] != q[j]) ct++;
	}

	if (ct > 2) cout << "NO" << endl;
	else cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<bitset>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
typedef long long ll;
typedef long double ld;
#define str string
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
const ll gosenchou = 5000000000000000;
short gh[2][4] = { { 0,0,-1,1 },{ -1,1,0,0 } };
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct E {//辺の情報を入れる変数
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(H a, H b) {
	return sqrt(pow(a.x - b.x, 2.0) + pow(a.y - b.y, 2.0));
}//rad＝座標上の2点間の距離
ll ari(ll a, ll b, ll c) {
	return (a + b)*c / 2;
}//等差数列の和
ll fact(ll x, ll k, ll p) {//最大値、個数、あまり
	ll sum = 1;
	for (int i = 0; i < k; i++) {
		sum *= (x--);
		sum %= p;
	}
	return sum;
}//階乗(正）
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x%p;
		x = x * x%p;
		n >>= 1;
	}
	return res;
}//x^n%p
short ctos(char a) {
	return (int)(a - '0');
}
#define int long long
const long long Inf = 4523372036854775807;
const int inf = 15000000000;
//----------------------------------------------------
//++++++++++++++++++++++++++++++++++++++++++++++++++++
int n;
int a[1000000];
int v[1000000][2];
signed main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (i % 2 == 0) {
			v[a[i]][0]++;
		}
		else {
			v[a[i]][1]++;
		}
	}
	int ans = 0, sum = 0, sum2 = 0, sum3 = 0, sum4 = 0, res = 0, res2 = 0;
	for (int i = 0; i <= 100000; i++) {
		if (sum < v[i][0]) {
			res = i;
			sum3 = max(sum3, sum);
			sum = v[i][0];
		}
		else sum3 = max(sum3, v[i][0]);
		if (sum2 < v[i][1]) {
			res2 = i;
			sum4 = max(sum4, sum2);
			sum2 = v[i][1];
		}
		else sum4= max(sum4, v[i][1]);
	}
	if (res == res2) {
		cout << n - max(sum + sum4, sum2 + sum3) << endl;
	}
	else {
		cout << n - sum - sum2 << endl;
	}
}

Measured memory_bytes: 5888
#include<bits/stdc++.h>
using namespace std;
int a[222][222];
int col[222];
int n;
bool dfs(int x,int c)
{
	if(col[x]!=-1)
	{
		if(col[x]!=c){
			return false;
		}
		return true;
	}
	col[x] = c;
	for(int i=1;i<=n;++i)
	{
		if(a[x][i]==1){
			if(!dfs(i,!c)){
				return false;
			}
		}
	}
	return true;
}
int main() {
	cin>>n;
	memset(a,0x3f,sizeof a);
	memset(col,-1,sizeof col);
	
	for(int i=1;i<=n;++i) 
	{
		a[i][i] = 0;
		for(int j=1;j<=n;++j)
		{
			char c;
			cin>>c;
			if(c!='0')
			{
				a[i][j] = 1;
			}
		}
	}
	if(!dfs(1,0)){
		cout<<-1<<endl;
		return 0;
	}
	for(int k=1;k<=n;++k)
	{
		for(int i=1;i<=n;++i)
		{
			for(int j=1;j<=n;++j)
			{
				a[i][j] = min(a[i][j],a[i][k] + a[k][j]);
			}
		}
	}
	int ans = 0;
	for(int i=1;i<=n;++i)
	{
		for(int j=1;j<=n;++j)
		{
			//cout<<i<<" "<<j<<": "<<a[i][j]<<endl;
			ans=max(ans,a[i][j]);
		}
	}
	cout<<ans+1<<endl;
} 

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

using namespace std;


int main() {
    string s;
    cin >> s;
    int counter = 0;
    for(int i = 0; i < s.size(); i++) {
        counter += (s[i] - '0');
    }
    if(counter % 9 == 0) {
        puts("Yes");
    } else {
        puts("No");
    }
    return 0;
}

Measured memory_bytes: 3704
s=input()
l=list(s)

a=[[] for _ in range(1<<len(s)-1)]   
for i in range(1<<len(s)-1):
    w=i
    for j in range(len(s)-1):
        b=w%2
        a[i].append(b)
        w//=2
#print(a)
for h in range(1<<len(s)-1):
    y=l[0]+"".join(("+" if a[h][i] else "-")+l[i+1] for i in range(len(a[h])))
    if eval(y)==7:
        print(y+"=7")
        break

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

long long power_26(int a) {
	if (a == 0) { return 1; }
	return 26 * power_26(a - 1);
}

int main() {
	long long N;
	cin >> N;

	int L = 1;
	while (N > power_26(L)) {
		N -= power_26(L);
		L++;
	}
	
	N--;
	vector<char> ans(L);
	for (int i = 0; i < L; i++){
		ans[L - 1 - i] = N % 26 + 'a';
		N /= 26;
	}

	for (int i = 0; i < L; i++) cout << ans[i];
	cout << endl;

}

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


int main(){
  ll N,Y;
  cin >> N >> Y;
  Y/=1000;
  rep(i,N+1){
    rep(j,N+1){
      if(i+5*j<=Y&&(Y-i-5*j)%10==0&&i+j+(Y-i-5*j)/10==N){
        cout << (Y-i-5*j)/10 << " " << j << " " << i << endl;
        return 0;
      }
    }
  }
  cout << -1 << " " << -1 << " " << -1 << endl;
}
  
  

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

const int mod = 1e9 + 7;

void add(int &a, int b) {
    a += b;
    if (a >= mod) a -= mod;
    if (a < 0) a += mod;
}

int mul(int a, int b) {
    return (a * (ll) b) % mod;
}

int pw(int x, int n) {
    int res = 1;
    while (n > 0) {
        if (n % 2 == 1) {
            res = mul(res, x);
            n--;
        }
        x = mul(x, x);
        n /= 2;
    }
    return res;
}

const int N = 407;

int dp[N][N];
int kek[N][N];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, c;
    cin >> n >> c;
    vector <int> a(n), b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }
    for (int x = 0; x <= c; x++) {
        for (int i = 0; i < n; i++) {
            for (int j = a[i]; j <= b[i]; j++) {
                add(kek[i][x], pw(j, x));            
            }
        }
    }
    dp[0][0] = 1;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= c; j++) {
            for (int x = 0; j - x >= 0; x++) {
                add(dp[i][j], mul(dp[i - 1][j - x], kek[i - 1][x]));
            }
        }
    }
    cout << dp[n][c] << '\n';
    return 0;
} 

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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
const ll mod = ll(1e9) + 7;
const int INF = int(1e9);

int main() {
	cin.sync_with_stdio(false);
	int H, W;
	cin >> H >> W;
	char s[50][50] = {};
	rep(i, H) {
		rep(j, W)cin >> s[i][j];
	}
	rep(i, H) {
		rep(j, W) {
			if (s[i][j] == '.')continue;
			bool flag = false;
			if (i - 1 >= 0 && s[i - 1][j] == '#')flag = true;
			else if (i + 1 < H&&s[i + 1][j] == '#')flag = true;
			else if (j - 1 >= 0 && s[i][j - 1] == '#')flag = true;
			else if (j + 1 < W&&s[i][j + 1] == '#')flag = true;
			if(!flag){
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>//author::@whohet-->Het Patel
#define fasterthanlight ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define test int T; cin>>T; while(T--)
#define endl "\n"
#define int long long
#define uint unsigned long long
#define ld long double
#define pii pair<int,int>
#define vi vector<int>
#define vc vector<char>
#define vs vector<string>
#define vvi vector<vector<int>>
#define mii map<int,int>
#define msi map<string,int>
#define mis map<int,string>
#define pb push_back
#define mod 1000000007
#define PI 3.141592653589793238

using namespace std;

//author::@whohet-->Het Patel

signed main()
{
    fasterthanlight;
    int n;
    cin>>n;
    
    int x=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            for(int k=1;k<=n;k++)
            {
                int y=__gcd(j, k);
                x=x+__gcd(i,y );
            }
        }
    }
    
    cout<<x<<endl;
   // cout << "\n\n"<<"Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " seconds.\n";
    return 0;



    

    
    return 0;
}



Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<pi> vpi;
#define inf 1000000000
#define mod 1000000007
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rep1(i, a, b) for(int i =a; i >=b; i--)
#define f first
#define ss second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple


ll a, b, ans;

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

//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);


cin >> a >> b;

ll temp = b-a;

temp  = (temp+1)*temp/2;

ans = temp - b;

cout << ans << endl;



return 0;}


Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let a = read::<usize>();
    let v = read::<String>();
    if a >= 3200 {
        println!("{}", v);
    } else {
        println!("red");
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
import java.util.Scanner;
 
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int l = sc.nextInt();
        int[][] a = new int[n][m];
        int[][] b = new int[m][l];
        long[][] c = new long [n][l];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                a[i][j] = sc.nextInt();
            }
        }
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < l; j++) {
                b[i][j] = sc.nextInt();
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < l; j++) {
                for (int k = 0; k < m; k++) {
                    c[i][j] += a[i][k] * b[k][j];
                }
                System.out.print(c[i][j]);
                if (j != l-1)
                    System.out.print(" ");
            }
            System.out.println();
        }
    }
}




Measured memory_bytes: 54532
'use strict';
(function(stdin) { 
  var inputs = stdin.toString();
  var params = inputs.split('\n')[0].split(' ').map(Number);
  (function(a,b) {
     console.log(a * b,(a + b) * 2);//????????????????????????
  }(params[0],params[1])); 
}(require('fs').readFileSync('/dev/stdin', 'utf8')));

Measured memory_bytes: 7376
#include <cstdio>
#include <algorithm>

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

using namespace std;

const int max_n = 200000;

int n, m, q;
int bit[max_n * 2 + 1];

void add(int i, int x){
	while(i <= n * 2){
		bit[i] += x;
		i += i & -i;
	}
}

int sum(int i){
	int s = 0;
	while(i > 0){
		s += bit[i];
		i -= i & -i;
	}
	return s;
}
 
int main(){
    scanf("%d%d%d", &n, &m, &q);
    int p = 0;
    rep(i, m){
        int a;
        scanf("%d", &a);
        int len = n - i;
        if(a % 2 == 0){
            a = a % len;
        }
        else{
            a = a % len;
            a = (len - a) % len;
        }
        int lb = -1, ub = n * 2 - 1;
        while(ub - lb > 1){
            int mid = (lb + ub) / 2;
            int del = sum(mid + 1) - sum(p + 1);
            if(mid - p - del >= a){
                ub = mid;
            }
            else{
                lb = mid;
            }
        }
        p = ub % n;
        // printf("first: %d\n", p);
        add(p + 1, 1);
        add(p + n + 1, 1);
        lb = -1, ub = n * 2 - 1;
        while(ub - lb > 1){
            int mid = (lb + ub) / 2;
            int del = sum(mid + 1) - sum(p + 1);
            if(mid - p - del >= 1){
                ub = mid;
            }
            else{
                lb = mid;
            }
        }
        p = ub % n;
        // printf("second: %d\n", p);
    }
    rep(i, q){
        int t = 0;
        scanf("%d", &t);
        int v = sum(t + 1) - sum(t);
        printf("%d\n", 1 - v);
    }
	return 0;
}

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

int main(void){
	char number[1001];
	char *np;
	int i,sum;
	np = number;

	while(1){
		scanf("%s", number);
		if(number[0] == '0'){
			return 0;
		}

		i = 0;
		sum = 0;

		while(1){
			sum += *(np+i) - '0';
			i++;
			if(*(np+i) == '\0' || i > 1001){
				break;
			}
		}
		printf("%d\n", sum);
	}

	return 0;
}

Measured memory_bytes: 536
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#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 fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
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;}
const int P = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;


int main(void){
  ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
  int p,q,r;
  int ans=INF;
  int time[3];
  cin >> time[0] >> time[1] >> time[2];
  for(int i=0;i<3;++i){
    for(int j=0;j<3;++j){
      for(int k=0;k<3;++k){
        if(i==k||j==k||i==j) continue;
      	ans = min(ans,time[i] + time[j]);
      }
    }
  }
  cout << ans << endl;
//////////////////////////////////////////////////////
return 0;
}

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


int main()
{
	int n, ans = 0, a = 0, b = 0, cnt = 1;
	cin>> n;
	vector<int> p(n), q(n), order(n);
	for(int i=0;i<n;i++){
		cin>>p[i];
	}
	for(int i=0;i<n;i++){
		cin>>q[i];
	}
	for(int i=0;i<n;i++){
		order[i] = i+1;
	}
	do{
		bool pflag = true, qflag = true;
		for(int i=0;i<n;i++){
			if(order[i]!=p[i]){
				pflag = false;
				break;
			}
		}
		for(int i=0;i<n;i++){
			if(order[i]!=q[i]){
				qflag = false;
				break;
			}
		}
		if(pflag) a = cnt;
		if(qflag) b = cnt;
		cnt++;
	}while(next_permutation(order.begin(), order.end()));
	
	ans = abs(a-b);
	cout<< ans <<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
#define pa pair<int,int>
const int N=3e2+10; 
const int mod=998244353;
using namespace std;

int a[N];
ll dp[N][N*N],dp2[N][N*N];
int up(ll &x,ll y){x+=y; return x>=mod?x-=mod:0;}
int main()
{
	int n,s=0; scanf("%d",&n);
	for(int i=1;i<=n;++i) scanf("%d",&a[i]),s+=a[i];
	dp[0][0]=dp2[0][0]=1;
	for(int i=1;i<=n;++i)
	{
		for(int j=s;j>=0;--j)
		{
			j>=a[i]&&up(dp[i][j],dp[i-1][j-a[i]]);
			up(dp[i][j],dp[i-1][j]*2%mod);
		}
	}
	for(int i=1;i<=n;++i)
	{
		for(int j=s;j>=0;--j)
		{
			j>=a[i]&&up(dp2[i][j],dp2[i-1][j-a[i]]);
			up(dp2[i][j],dp2[i-1][j]);
		}
	}
	ll ans=1; for(int i=1;i<=n;++i) ans=ans*3%mod;
	for(int i=(s+1)/2;i<=s;++i) up(ans,mod-dp[n][i]*3%mod);
	if(s%2==0) up(ans,dp2[n][s/2]*3%mod);
	printf("%lld\n",ans);
return 0;
}
/*
*/

Measured memory_bytes: 454144
#include <bits/stdc++.h>
#define rep(i, n) for(ll i=0;i<n;i++)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (b>a) { 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 long long INF = 2LL << 60;

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

int main(int argc, char const *argv[]){
    ll a;
    string s;
    cin >> a >> s;
    ll b = (s[0]-'0')*100+(s[2]-'0')*10+(s[3]-'0');
    cout << a*b/100 << endl;
}




Measured memory_bytes: 3588
#include<bits/stdc++.h>
#define QS ios_base::sync_with_stdio(false);
typedef long long ll;
const ll INF = 1e18;
const int MOD = 1e9+7;
using namespace std;

int main(){
//freopen("output.txt", "w", stdout);
    QS
    ll n; cin >> n;
    cout << n*n << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int K,T;cin >> K >> T;
  priority_queue<int> pque;
  rep(i,T){
    int x;cin >> x;
    pque.push(x);
  }
  while(pque.size()>1){
    int p = pque.top();pque.pop();
    int q = pque.top();pque.pop();
    --p;--q;
    if(p!=0)pque.push(p);
    if(q!=0)pque.push(q);
  }
  if(pque.empty())cout << 0 << endl;
  else cout << pque.top()-1 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void) {
	int num[2] = {};

	char ch;
	while( (ch = getchar()) != EOF ) {
		num[ch - 'A'] ++;
	}
	if( num[0] && num[1] ) {
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	return 0;
}


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

int main()
{
    ll n;
    string s;
    set<string>st;
    cin>>n;
    getline(cin,s);
    for(ll i=0;i<n;i++){
        getline(cin,s);
        st.insert(s);
    }
    cout<<st.size();
    return 0;
}


Measured memory_bytes: 19032
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
typedef long long ll;
using namespace std;
int main(){
    string s1,s2,s3;
    cin>>s1>>s2>>s3;
    char a,b,c;
    a = s1[0]-32;
    b = s2[0]-32;
    c = s3[0]-32;
    cout<<a<<b<<c<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> T gcd(T a, T b){return !b?a:gcd(b,a%b);}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
mt19937 R(chrono::system_clock().now().time_since_epoch().count());

const int N = 505,inf=0x3f3f3f3f;
int n,d[N][N],res;bool gg[N][N];
int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};
void dfs(int x, int y){
	rep(i,0,3){
		int nx=x+dx[i],ny=y+dy[i];
		if(d[nx][ny]>d[x][y]+(!gg[x][y])){
			d[nx][ny]=d[x][y]+(!gg[x][y]);dfs(nx,ny);
		}
	}
}
int main() {
	read(n);rep(i,1,n)rep(j,1,n)d[i][j]=min(min(i-1,n-i),min(j-1,n-j));
	rep(t,1,n*n){
		int c;read(c);int x=(c-1)/n+1,y=(c-1)%n+1;
	//	cerr<<x<<' '<<y<<' '<<d[x][y]<<endl;
		res+=d[x][y];gg[x][y]=1;
		dfs(x,y);
	}
	cout<<res;
	return 0;
}


Measured memory_bytes: 24148
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    String s = sc.next();
    String t = sc.next();
    int ans = 0;
    for (int i = 0; i < s.length(); i++) {
      if (s.charAt(i) != t.charAt(i)) {
        ans++;
      }
    }
    pw.println(ans);
  }
}


Measured memory_bytes: 41204
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
const int MOD = 1000000007;
const int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;



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

  int X;
  cin >> X;
  int m = X / 500, n = (X % 500) / 5;
  cout << m * 1000 + n * 5 << endl;

}

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

int main() {
  int X, N;
  cin >> X >> N;
  vector<int> bac(1000, 0);
  for (int i = 0; i < N; ++i) {
    int a;
    cin >> a;
    bac[a] = 1;
  }
  int mi = 1000, res = -1;
  for (int i = 0; i < 1000; ++i) {
    if (bac[i]) continue;
    if (mi > abs(X - i)) {
      mi = abs(X - i);
      res = i;
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 3632
//
//  atcoder.cpp
//
//
///
#include <bits/stdc++.h>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/bimap/bimap.hpp>
#include <boost/bimap/multiset_of.hpp>
#include <boost/multi_array.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/icl/interval_map.hpp>

#define REP(i, N) for(int i=0; i<(N); i++)
#define REC(f, ...) (void)0; const auto f = [&](const auto f, __VA_ARGS__)
using namespace std;
using namespace boost::integer;

using ll = long long;
namespace bst = boost;
namespace icl = boost::icl;
template<typename T> class in {
    T value;
public:
    in() { cin >> value; }
    operator const T&() const { return value; }
    operator T&() { return value; }
    in& operator=(T source) { value = source; return *this; }
};
template<> class in<string> : public string {
public:
    in() { cin >> *this; }
};
template<class T> class inseq : public T {
public:
    template<typename... Arg> inseq(Arg... arg) : T(forward<Arg>(arg)...) { for (auto&& i : *this) cin >> i; }
};
template<class T> using invec = inseq<vector<T>>;

auto solve() {
  in<ll> A;


  return A + A*A + A*A*A;
}

template<typename T> void plot(const T& func) { cout << setprecision(9) << func() << endl; }
template<> void plot<void()>(void(&func)()) { func(); }

int main() {
  plot(solve);

  return 0;
}


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

using namespace std;


int main()
{
  int N, A[100000];
  int v[100000];
  memset(v, -1, sizeof(v));


  scanf("%d", &N);
  for(int i = 0; i < N; i++) {
    scanf("%d", &A[i]);
    A[i] = (A[i] + i) % N;
  }

  int ret = 0, sum = 1;

  for(int i = 0; i < N; i++) {
    if(~v[i]) continue;
    int now = i, rev = sum;
    v[now] = sum++;
    while(v[A[now]] == -1) {
      now = A[now];
      v[now] = sum++;
    }
    if(v[A[now]] < rev) continue;
    ret += v[now] - v[A[now]] + 1;
  }
  printf("%d\n", ret);

}

Measured memory_bytes: 3912
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007
ll isPrime[1000010]={0};
vector<ll> Prime;

void sieve(){
	ll i,j;
	isPrime[0] = isPrime[1] = 1;
	for( i=2; i<1000010; i++)if(isPrime[i]==0)for(j=2*i; j<1000010; j+=i)isPrime[j]=1;
	for( i=1; i<1000010; i++)if(isPrime[i]==0)Prime.push_back(i);
}
ll modMul(ll a,ll b,ll mod){
	ll res=0;
	if(mod<=MOD){
        return ((a%mod)*(b%mod))%mod;
	}
	while(b){
		if(b&1)res = (res+a)%mod;
		a = (2*a)%mod;
		b = b/2;
	}
	return res;
}
ll modPow(ll x,ll n,ll mod){
	ll r = 1;
	while(n){
		if(n&1)r = modMul(r,x,mod);
		x = modMul(x,x,mod);
		n = (n>>1);
	}
	return r;
}
/*vector<int>v;
void printDivisors(int n) 
{ 
    // Vector to store half of the divisors 3343434 
    for (int i=1; i<=sqrt(n); i++) 
    { 
        if (n%i==0) 
        { 
            if (n/i == i) // check if divisors are equal 
                if (i%2!=0){
                	v.push_back(i);
				} 
            else
            { 
                if (i%2!=0){
                	v.push_back(i);
				}  
  
                // push the second divisor in the vector 
                if ((n/i)%2!=0){
                	v.push_back(n/i);
				} 
            } 
        } 
    } 
  
    // The vector will be printed in reverse 
} 
*/

void solve (){
	int n,m;
	cin>>n>>m;
	
	char a[n][m];
	for (int i=0;i<n;i++){
		for (int j=0;j<m;j++){
			cin>>a[i][j];
		}
	}
	long long int dp[n][m];
	if (a[0][0]=='.'){
		dp[0][0]=1;
	}
	else{
		dp[0][0]=0;
	}
	for (int i=1;i<n;i++){
		if (a[i][0]=='.'){
			dp[i][0]=dp[i-1][0];
		}
		else{
			dp[i][0]=0;
		}
	}
		for (int i=1;i<m;i++){
		if (a[0][i]=='.'){
			dp[0][i]=dp[0][i-1];
		}
		else{
			dp[0][i]=0;
		}
	}
	
	int p=0;
	for (int i=1;i<n;i++){
		for (int j=1;j<m;j++){
			if (dp[i-1][j]==0 && dp[i][j-1]==0){
				dp[i][j]=0;
			}
			if (a[i][j]=='#'){
				dp[i][j]=0;
			}
			else if (dp[i-1][j]==0){
				dp[i][j]=(dp[i][j-1])%MOD;
			}
			else if (dp[i][j-1]==0){
				dp[i][j]=(dp[i-1][j])%MOD;
			}
			else{
				dp[i][j]=((dp[i-1][j]%MOD)+(dp[i][j-1]%MOD))%MOD;
			}
			
		}
		
	}
	
	
		cout<<dp[n-1][m-1]<<endl;
	
	
}
	
	

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


Measured memory_bytes: 12348
#include "bits/stdc++.h"
using namespace std;
const int maxn = 200200;
long long f(long long x){
  if(x%4 == 0) return x;
  if(x%4 == 1) return 1;
  if(x%4 == 2) return x + 1;
  return 0;
}
int main(){
  long long a, b;
  cin >> a >> b;
  cout << (f(b) ^ (a == 0 ? 0 : f(a - 1))) << endl;
  return 0;
}


Measured memory_bytes: 256