akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define all(a) (a).begin(),(a).end()

using namespace std;

int main(int argc, char const *argv[]) {
  string O,E;
  std::cin >> O >> E;
  if(O.size()>E.size()){
    for (size_t i = 0; i < E.size(); i++) {
      printf("%c%c",O[i],E[i]);
    }
    printf("%c\n",O[O.size()-1]);
  }else{
    for (size_t i = 0; i < E.size(); i++) {
      printf("%c%c",O[i],E[i]);
    }
    printf("\n");
  }
  return 0;
}


Measured memory_bytes: 256
# アルゴリズムイントロダクション 15.4 LCS
# Longest Common Subsequenceをとり、以下を返す
# b: 結果
# c: そこまでのlongestのcount(内部用)
def lcs_length(x, y):
    m, n = len(x), len(y)
    b = [[0 for _ in range(n + 1)] for _ in range(m + 1)]
    c = [[0 for _ in range(n + 1)] for _ in range(m + 1)]
    for i in range(1, m + 1):
        for j in range(1, n + 1):
            if x[i - 1] == y[j - 1]:
                c[i][j] = c[i - 1][j - 1] + 1
                b[i][j] = '↖'
            elif c[i - 1][j] >= c[i][j - 1]:
                c[i][j] = c[i - 1][j]
                b[i][j] = "↑"
            else:
                c[i][j] = c[i][j - 1]
                b[i][j] = "←"
    return c, b

# アルゴリズムイントロダクション 15.4 LCS
# bを基にもともとのinput xから共通部分を抜き出す。
def lcs_decode(b, X, i, j):
    import collections
    res = collections.deque([])
    while True:
        # print("i={0}, j={1} b={2}".format(i,j,b[i][j]))
        if i == 0 or j == 0:
            break
        if b[i][j] == '↖':
            res.appendleft(X[i - 1])
            i -= 1
            j -= 1
        elif b[i][j] == "↑":
            i -= 1
            continue
        else:
            j -= 1
            continue
    return res




n = int(input())
import collections
d = collections.defaultdict(list)
m = -1
dat = []
for _ in range(n):
    s = input()
    s = "".join(sorted(list(s)))
    dat.append(s)
cs = dat[0]
for i in range(1, n):
    c, b = lcs_length(cs, dat[i])
    cs = "".join(lcs_decode(b, cs, len(cs), len(dat[i])))
print(cs)

Measured memory_bytes: 42352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pll = pair<ll, ll>;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, m, n) for(ll i = m; i > n; i--)
#define Rep(i, m, n) for(ll i = m; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define lmax(x, y) max<ll>(x, y)
#define lmin(x, y) min<ll>(x, y)
#define tmax(x, y, z) lmax((x), lmax((y), (z)))
#define tmin(x, y, z) lmin((x), lmin((y), (z)))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define ZERO(a) memset(a, 0, sizeof(a))
const ll INF = 1LL << 60;
const ll MM = 1000000000; const ll MOD = MM + 7; const ll MMM=9223372036854775807;//2^63 -1
#define ADD(a,b) a = (a + ll(b)) % MOD
#define MUL(a,b) a = (a * ll(b)) % MOD
ll GCD(ll x, ll y){ if(y == 0) return x; else return GCD(y, x % y);}
ll LCM(ll x, ll y){ return x / GCD(x, y) * y;}
template<class T> inline bool chmin(T& a, T b){ if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b){ if(a < b){ a = b; return true;} return false;}
template<typename A, size_t N, typename T> void FILL(A (&array)[N], const T &val){ fill( (T*)array, (T*)(array+N), val );}
// struct edge{ ll from, to, cost; };
// struct edge{ ll to, cost; };
// using Graph = vector<vector<ll>>;  // 重み無し
// using Graph = vector<edge>;  // 辺
// using Graph = vector<vector<edge>>;  // 重み付き
ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
ll ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//cout << fixed << setprecision(10);
// priority_queue<ll, vector<ll>, greater<ll>> pq;


map<ll, ll> prime_factor(ll n){
    map<ll, ll> res;
    for(ll i=2; i*i<=n; i++){
        while(n%i == 0){
            ++res[i];
            n /= i;
        }
    }
    if(n != 1) res[n] = 1;
    return res;
}


int main(){
    ll n, p; cin >> n >> p;
    auto mp = prime_factor(p);
    ll ans = 1;
    for(auto p: mp){
        if(p.second >= n) ans *= pow(p.first, p.second/n);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3968
use std::io::{stdout, Write, BufWriter};

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

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

fn main() {
    input!{ n: usize }
    println!("{}", 2i32.pow((n as f64).log2().floor() as u32));
}


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

int main()
{
    long long a,b,v,w,t,l;
    cin>>a>>v;
    cin>>b>>w;
    cin>>t;
    l=llabs(a-b);
    if (l<=(v-w)*t) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main() {
    int A,B;
    cin >> A >> B;
    int count = 0;
    for (int i = A; i <= B; ++i) {
       int a,b,c,d = 0;
       a = i % 10; //5桁目
       b= i / 10000 % 10; //1
       c= i / 1000 % 10; //4
       d= i / 10 % 10; //2

       if(a == b && c ==d){
           count++;
       }
    }
    cout << count;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

const int N = 1e2 + 10;

int n;
int a[N];

int selection_sort(int a[], int n)
{
    int i, j, t, sw = 0, minj;
    for(i = 0; i < n - 1; i++)
    {
        minj = i;
        for(int j = i; j < n; j++)
        {
            if(a[j] < a[minj]) minj = j;
        }
        swap(a[i], a[minj]);
        if(i != minj) sw++;
    }

    return sw;
}

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

    cin >> n;

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

    int sw =selection_sort(a, n);

    for(int i = 0; i < n; i++)
    {
        if(i > 0) cout << ' ';
        cout << a[i];
    }
    cout << endl;

    cout << sw << endl;

    return 0;
}


Measured memory_bytes: 3184
#include <stdio.h>

int main() {
	int h, w;
	int a[26] = {};
	int two, four, odd;
	char c;
	scanf("%d %d", &h, &w);

	for (int i = 0; i < h; i++)
	{
		scanf("\n");
		for (int j = 0; j < w; j++)
		{
			scanf("%c", &c);
			a[(int)(c - 'a')]++;
		}
	}
	
	odd = (h % 2)*(w % 2);
	two = w*(h % 2) + h*(w % 2) - odd * 2;
	//four = w*h - two;

	for (int i = 0; i < 26; i++)
	{
		switch (a[i] % 4)
		{
		case 0:
			//four -= a[(int)(i - 'a')];
			break;
		case 1:
			odd--;
			//four -= a[(int)(i - 'a')] - 1;
			break;
		case 2:
			two -= 2;
			//four -= a[(int)(i - 'a')] - 2;
			break;
		case 3:
			odd--;
			two -= 2;
			four -= a[(int)(i - 'a')] - 3;
			break;
		default:
			break;
		}

		if (two < 0 || odd < 0) {
			printf("No");
			return 0;
		}
	}
	printf("Yes");
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(void) {
  int a = 0;
  int b = 0;
  int c = 0;

  scanf("%d", &a);
  scanf("%d", &b);
  scanf("%d", &c);

  if (a < b) {
    if(b < c) {
      printf("Yes\n");
    } else {
      printf("No\n");
    }
  } else {
    printf("No\n");
  }
  
  return 0;
}

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

int main()
{
    int n;

    cin >> n;
    vector<string> s(n);
    vector<string> smax(n);
    rep(i, n) {
        cin >> s[i];
    }

    sort(s.begin(), s.end());
    //最大回数取得
    int mx = 0; //最大回数
    int cnt = 0;
    int mcnt = 0;
    rep(i, n-1) {
        if (s[i] == s[i + 1]) {
            //一致
            ++cnt;
            if (cnt > mx) {
                //最大を更新
                mx = cnt;
                smax[0] = s[i];
                mcnt = 0;
            }
            else if (cnt == mx) {
                //最大と同じ
                ++mcnt;
                smax[mcnt] = s[i];
            }
        }
        else {
            //不一致
            cnt = 0;
        }
    }
    //結果
    if (cnt>0)
        rep(i, (mcnt+1)) {
            std::cout << smax[i] << endl;
        }
    else
        rep(i, n) {
        std::cout << s[i] << endl;
    }
}



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

using namespace std;

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define repr(i, j) for(int i = j; i >= 0; --i)
#define INF (1 << 30)
#define MOD 1e9 + 7

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<int, P> Pi;

#define MAX 1000000

bool prime[1000000];
int N, X;
int price[30];
int dp[MAX + 1];

void PrimeJudge() {
	memset(prime, true, sizeof(prime));
	prime[0] = false;
	FOR(i, 1, sqrt(MAX)) {
		if(prime[i]) {
			for(int j = (i + 1); (i + 1) * j <= MAX; ++j) {
				prime[(i + 1) * j - 1] = false;
			}
		}
	}
	return;
}

int main() {
	PrimeJudge();
	while(scanf("%d %d", &N, &X), N || X) {
		memset(dp, 0, sizeof(dp));
		rep(i, N) scanf("%d", &price[i]);
		rep(i, N) FOR(j, price[i], X + 1) {
			dp[j] = max(dp[j], dp[j - price[i]] + price[i]);
		}
		bool flag = false;
		for(int i = X; i >= 0; --i) if(dp[i] - 1 >= 0) {
			if(prime[dp[i] - 1]) {
				printf("%d\n", dp[i]);
				flag = true;
				break;
			}
		}
		if(!flag) printf("NA\n");
	}
	return 0;
}

Measured memory_bytes: 7992
#include <bits/stdc++.h>
using namespace std;
int main(){
  while (1){
    int n;
    cin >> n;
    if (n == 0){
      break;
    }
    vector<string> s(n);
    for (int i = 0; i < n; i++){
      cin >> s[i];
    }
    vector<string> t(n);
    for (int i = 0; i < n; i++){
      int m = s[i].size();
      t[i] += s[i][0];
      for (int j = 0; j < m - 1; j++){
        if (s[i][j] == 'a' || s[i][j] == 'i' || s[i][j] == 'u' || s[i][j] == 'e' || s[i][j] == 'o'){
          t[i] += s[i][j + 1];
        }
      }
      t[i] += '#';
    }
    sort(t.begin(), t.end());
    int ans = -1;
    for (int i = 0; i < n - 1; i++){
      if (t[i] == t[i + 1]){
        ans = -1;
        break;
      } else {
        int m = min(t[i].size(), t[i + 1].size());
        for (int j = 0; j < m; j++){
          if (t[i][j] != t[i + 1][j]){
            ans = max(ans, j + 1);
            break;
          }
        }
      }
    }
    cout << ans << endl;
  }
}


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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

ll  fct[200200], inv[200200];
void init(int cmx, ll mod){
	auto bin_pows =[](ll x, ll n, ll mod){
		ll res = 1LL;
		for(; n > 0; n >>=1, x = x*x %mod) if(n & 1) res = res * x %mod;
		return res;
	};
	fct[0] = fct[1] = inv[1] = 1;
	for(int i=2;i<cmx+3;i++) fct[i] = fct[i-1] * i % mod;
	inv[cmx] = bin_pows(fct[cmx], mod-2, mod);
	for(int i=cmx;i>=1;i--) inv[i-1] = inv[i] * i % mod;
}
ll nCk(ll n, ll k, ll mod) {
	ll ret =fct[n] * inv[k] % mod * inv[n-k] % mod;
	return ret;
}

int main(){
	cin.tie(0); ios_base::sync_with_stdio(false);
	int h,w,a,b;
	cin >>h >>w >>a >>b;
	
	init(h+w+50, MD);
	
	int dy=h-a, dx=b+1;
	
	ll ans = 0;
	while(dx <=w){
		//dbg(dy,dx,dy+dx-2, dy-1, h-1-dy + w-dx, h-1-dy);
		ll w1 = nCk(dy+dx-2, dy-1, MD);
		ll w2 = nCk(h-1-dy + w-dx, h-1-dy, MD);
		(ans += w1 * w2) %=MD;
		dx++;
	}
	cout << ans <<endl;
	return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstdlib>
#include <stack>
#include <vector>
#define INF 0x3f3f3f3f
#define MOD 1000000009
# define FOR(i,a,n) for(register int i=a; i<=n; ++i)
# define FDR(i,a,n) for(register int i=a; i>=n; --i)
typedef long long ll;
typedef unsigned long long ull;

inline int scan() {
    int x=0,f=1; char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}
inline void Out(int a) {
    if(a<0) {putchar('-'); a=-a;}
    if(a>=10) Out(a/10);
    putchar(a%10+'0');
}
using namespace std;

int main()
{
    ll n, m;
    cin >> n >> m;
    if(n != 1 && m != 1)
    cout << m*n-(m*2+(n-2)*2) << endl;
    else
    {
        if(n == 1 && m != 1)cout << m-2 << endl;
        else if(m == 1 && n!=1)cout << n-2 << endl;
        else if(n == 1&& m == 1)cout << 1 << endl;
    }
    return 0;
}
/*
                 ___====-_  _-====___
           _--^^^#####//      \\#####^^^--_
        _-^##########// (    ) \\##########^-_
       -############//  |\^^/|  \\############-
     _/############//   (@::@)   \\############\_
    /#############((     \\//     ))#############\
   -###############\\    (oo)    //###############-
  -#################\\  / VV \  //#################-
 -###################\\/      \//###################-
_#/|##########/\######(   /\   )######/\##########|\#_
|/ |#/\#/\#/\/  \#/\##\  |  |  /##/\#/  \/\#/\#/\#| \|
`  |/  V  V  `   V  \#\| |  | |/#/  V   '  V  V  \|  '
   `   `  `      `   / | |  | | \   '      '  '   '
                    (  | |  | |  )
                   __\ | |  | | /__
                  (vvv(VVV)(VVV)vvv)
                  ÁúÉñ±£ÓÓ ÓÀÎÞbug
*/


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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

LL modinv(LL a) {
    LL b = MOD, u = 1, v = 0;
    while (b) {
        LL t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= MOD;
    if (u < 0) u += MOD;
    return u;
}

LL moddev(LL a, LL b){
	return a * modinv(b) % MOD;
}

void Main()
{
    LL n,k,s;
    cin >> n >> k >> s;
    LL big = 1e9;

    bool first = true;

    FOR(i,0,k){
        if(!first){
            cout << " ";
        }
        else{
            first = false;
        }
        cout << s;
    }

    FOR(i,k,n){
        if(!first){
            cout << " ";
        }
        else{
            first = false;
        }

        if(s == big){
            cout << big-1;
        }
        else{
            cout << s+1;
        }
    }

    cout << endl;

	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define all(v) (v).begin(),(v).end()

#define PII pair<int,int>
#define mp make_pair
#define st first
#define nd second
#define pb push_back
#define lint long long int
#define VI vector<int>

#define debug(x) {cout <<#x <<" = " <<x <<endl; }
#define debug2(x,y) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y <<endl; } 
#define debug3(x,y,z) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y << ", " << #z << " = " << z <<endl; } 
#define debugv(x) {{cout <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<endl; }}
#define debugt(t,n) {{cerr <<#t <<" = "; FOR(it,0,(n)) cerr <<t[it] <<", "; cerr <<endl; }}

#define make( x) int (x); scanf("%d",&(x));
#define make2( x, y) int (x), (y); scanf("%d%d",&(x),&(y));
#define make3(x, y, z) int (x), (y), (z); scanf("%d%d%d",&(x),&(y),&(z));
#define make4(x, y, z, t) int (x), (y), (z), (t); scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define makev(v,n) VI (v); FOR(i,0,(n)) { make(a); (v).pb(a);} 
#define IOS ios_base::sync_with_stdio(0)
#define HEAP priority_queue

#define read( x) scanf("%d",&(x));
#define read2( x, y) scanf("%d%d",&(x),&(y));
#define read3(x, y, z) scanf("%d%d%d",&(x),&(y),&(z));
#define read4(x, y, z, t) scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define readv(v,n) FOR(i,0,(n)) { make(a); (v).pb(a);}
#define jeb() fflush(stdout);

using namespace std;

const int max_n = 3005;
const int mod = 1e9 + 7;
char s[max_n];

int n, d;
int dp[max_n][max_n];


int main () {
	read(n);
	scanf("%s", s);
	dp[0][0] = 1;
	FOR(i,1,n) {
		int pref = 0;
		int suf = 0;
		FOR(j,0,i+1) {
			suf += dp[i-1][j];
			suf %= mod;
		}
		FOR(j,0,i+1) {
			if (s[i-1] == '>') {
				dp[i][j] = pref;
			} else {
				dp[i][j] = suf; 
			}
			pref = (pref +  dp[i-1][j]) % mod;
			suf = (suf + mod - dp[i-1][j]) % mod;
		}
	}
	int ans = 0;
	FOR(j,0,n) {
		ans += dp[n-1][j];
		ans %= mod;
	}
	printf("%d\n", ans);
}	





Measured memory_bytes: 34176
from itertools import accumulate
import sys
# python template for atcoder1
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))

dp = [[float(0)]*N for _ in range(N)]
a_acc = [0]+list(accumulate(A))


def dfs(l, r):
    """
    List[l:r]
    """
    if dp[l][r-1] != float('inf'):
        return dp[l][r-1]
    if r-l == 1:
        dp[l][r-1] = 0
        return 0
    if r-l == 2:
        dp[l][r-1] = A[l]+A[r-1]
        return dp[l][r-1]
    else:
        dp[l][r-1] = min(dfs(l, v)+dfs(v, r)
                         for v in range(l+1, r))+a_acc[r]-a_acc[l]
        return dp[l][r-1]


def bfs():
    for d in range(2, N+1):
        for l in range(0, N-d+1):
            r = l + d
            #print("l,r->", l, r)
            tmp = float('inf')
            for m in range(l+1, r):
                tmp = min(tmp, dp[l][m-1]+dp[m][r-1])
            #print("tmp->", tmp)
            #print("acc->", a_acc[r]-a_acc[l])
            dp[l][r-1] = tmp+a_acc[r]-a_acc[l]


# print(a_acc)
bfs()
# print(dp)
ans = int(dp[0][-1])
print(ans)


Measured memory_bytes: 43884
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define printYes() cout << "Yes" << endl;
#define printNo() cout << "No" << endl;
#define printVector(v) rep(i, v.size()) cout << x << endl;

int main()
{
  int N;
  cin >> N;
  vector<int> pole(N, 0);
  rep(i, N)
  {
    cin >> pole[i];
  }
  sort(pole.rbegin(), pole.rend());

  long long H = 0;
  long long W = 0;
  rep(i, N - 1)
  {
    if (pole[i] == pole[i + 1])
    {
      if (H == 0)
        H = pole[i];
      else
      {
        W = pole[i];
        break;
      }
      i++;
    }
  }
  long long ans = H * W;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define isOn(x,k) ((x)&(1<<k))
const int N=1e5+6 , oo=0x3f3f3f3f;
long long   t,m;

long long  n;
int main(){
   char c[3][3];
   for(int i=0;i<3;++i){
    for(int j=0;j<3;++j)
        cin>>c[i][j];
   }
cout<<c[0][0]<<c[1][1]<<c[2][2]<<"\n";


}


Measured memory_bytes: 256
#include <iostream>
 
using namespace std;
 
#define rep(i, n) for (int i = 0; i < n; i++)
 
int main(void) {
    string s;
    cin >> s;
    int ans = 0; // 数を数えるための変数。これが答えになる
    rep(i, 3) {
        if (s[i] == '1') {
            ans++; // '1'があればansを1増やす
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<iomanip>
using namespace std;

int main(void)
{
	string s;
	cin >> s;
	cout << s[0] << s.size() - 2 << s[s.size() - 1];
	return 0;
}

Measured memory_bytes: 256
def cal(a, sign, b):
    if sign == "+":
        return a + b
    if sign == "*":
        return a * b
    if sign == "-":
        return a - b
    if sign == "/":
        return a // b
        
while True:
    a, sign, b = input().split()
    if sign == "?":
        break
    print(cal(int(a),sign,int(b)))


Measured memory_bytes: 5596
#include<iostream>
#include<map>
#include<algorithm>
using namespace std;

int T,N;
int t[30];
int dp[101][30];
int mask[101];

const int INF = 1e8;

int maxDay;

void init(){
  for(int i = 0 ; i < 101 ; i++){
    mask[i] = 0;
    for(int j = 0 ; j < 30 ; j++){
      dp[i][j] = INF;
    }
  }
  maxDay = 0;
}

void input(){
  for(int i = 0 ; i < T ; i++){
    cin >> t[i];
  }
  cin >> N;
  for(int i = 0 ; i < N ; i++){
    int d,m;
    cin >> d >> m;
    maxDay = max(maxDay,d);
    d--;
    mask[d] |= (1 << m);
  }
}

void solve(){
  init();
  input();

  dp[0][0] = 0;

  for(int i = 0 ; i < maxDay ; i++){
    for(int j = 0 ; j < T ; j++){
      if(dp[i][j] == INF)continue;
      int bit = ((1 << t[j])-1);
      if(bit & mask[i])continue;
      dp[i+1][0] = min(dp[i+1][0],dp[i][j] + 1);
      dp[i+1][(j+1)%T] = min(dp[i+1][(j+1)%T],dp[i][j]);
    }
  }
  int res = INF;
  for(int i = 0 ; i < T ; i++){
    res = min(res,dp[maxDay][i]);
  }
  cout << res << endl;
}

int main(){
  while(cin >> T,T){
    solve();
  }
  return 0;
}

Measured memory_bytes: 1172
n, x, y = map(int,input().split())
dist = [0] * n
x -= 1
y -= 1
for i in range(n):
  for j in range(i+1, n):
    dist[min(j-i, abs(x-i)+abs(y-j)+1, abs(y-i)+abs(x-j)+1)] += 1
for d in dist[1:]:
  print(d)

Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ut i=(a);i<(ut)(b);i++)
#define REP(i,b) FOR(i,0,b)
#define ALL(c) c.begin(),c.end()
#define PB push_back
#define cat //cout << __LINE__ << endl;
using namespace std;
typedef long long LL;
typedef double ld;
typedef LL ut;
typedef vector<ut> VI;
typedef pair<ut,ut> pr;
typedef pair<ut,pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef priority_queue<pr,Vpr,greater<pr> > PQ;
using namespace std;
const int SIZE=5*1e5;
const LL INF=1LL<<58;
const LL p=1e9+7;
LL N,M;
LL DP[302][302][302];
int main(){
	cin >> N >> M;
	DP[0][1][1]=1;
	REP(i,M){
		REP(j,N+1){
			FOR(k,j,N+1){
				DP[i][j][k]%=p;
	//			if(DP[i][j][k])
	//			cout <<i <<" " << j << " " << k << " " << DP[i][j][k] << endl;
				DP[i+1][k][k]+=DP[i][j][k]*j%p;
				DP[i+1][j][k]+=DP[i][j][k]*(k-j)%p;
				DP[i+1][j][k+1]+=DP[i][j][k]*(N-k)%p;				
			}
		}
	}
	cout << DP[M][N][N]%p << endl;
	return 0;
}

Measured memory_bytes: 214656
def bomb(f,x,y):
    rf = f[:][:]
    rf[y][x] = 0
    for i in [-3,-2,-1,1,2,3]:
        if 0 <= x+i <= 7:
            if rf[y][x+i] == 1: rf = bomb(rf,x+i,y)
        if 0 <= y+i <= 7:
            if rf[y+i][x] == 1: rf = bomb(rf,x,y+i)
    return rf


n = int(raw_input())
for data in range(1,n+1):
    f = []
    raw_input()
    for line in range(8):
        f.append(map(int, list(raw_input())))
    x = int(raw_input())-1
    y = int(raw_input())-1

    f = bomb(f,x,y)

    print "Data %d:"%(data)
    for i in range(8):
        print "".join(map(str, f[i]))

Measured memory_bytes: 4280
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {in_a: usize, in_b: usize, in_c: usize, in_d: usize};

    let turn1 = (in_c - 1) / in_b;
    let turn2 = (in_a - 1) / in_d;

    if turn1 <= turn2 {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 2160
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second

typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

void Main()
{
	int n;
  	cin >> n;
  	vll a(n), b(n), c(n);
  	rep(i,n) cin >> a[i];
  	rep(i,n) cin >> b[i];
  	rep(i,n) cin >> c[i];
  	sort(all(a));
  	sort(all(b));
  	sort(all(c));
  	
  	// a[i] < b[j] < c[k] を満たす (i,j,k) の組を数える
  	ll ans = 0;
  	
  	// lower_bound: ソートされた配列内で key 以上の要素の内の一番左側のイテレータを返す
  	// upper_bound: ソートされた配列内で key より大きい要素の内の一番左側のイテレータを返す
 	rep(i,n){
    	ll na = lower_bound(all(a), b[i]) - a.begin();
      	ll nc = c.end() - upper_bound(all(c), b[i]);
      	ans += na*nc;
    }
  
  	cout << ans << endl;
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,s,n) for(int i=s;i<n;i++)
typedef long long int ll;
typedef pair<int, int> P;
typedef long double ld;
void ans(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}

const ll INF=1001001001;

int main(){
  int n,k,r,s,p;cin>>n>>k>>r>>s>>p;
  string st;cin>>st;
  vector<int> v(n,0);
  int ans=0;
  
  rep(i,n){
    if(i>=k && st.at(i-k)==st.at(i) && v.at(i-k)==1){
      continue;
    }
    
    if(st.at(i)=='r'){
      ans+=p;
      v[i]=1;
    }
    
    if(st.at(i)=='s'){
      ans+=r;
      v[i]=1;
    }
    if(st.at(i)=='p'){
      ans+=s;
      v[i]=1;
    }
    
  }
  
  cout<<ans<<endl;
}

Measured memory_bytes: 896
// header {{{
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <complex>
#include <utility>
#include <string>
#include <sstream>
#include <queue>
#include <map>
#include <list>
#include <set>
#include <stack>
// #include <tuple>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

#define ALPHABET    (26)
#define EPS         (1e-10)
#define INF         (1000000005LL)
#define MOD         (1000000007LL)
// #define EQ(a, b)    (abs((a)-(b)) < EPS)
inline bool EQ(double a, double b) {return abs(a-b) < EPS;}
// ciling(x/y) = (x+y-1)/y

// template<class T>
// using P = pair<T, T>;
using ll  = long long;
using ull = unsigned long long;
// }}}

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

    ll ans = 1000000000LL*1000000LL;
    for(int i=1;i<n;i++){
        ans = min(ans, abs(s[n]-s[i]-s[i]));
    }
    printf("%lld\n", ans);
    return 0;
}


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

 struct s
 {
    char word[32];
    int freq,len;
 };

int main(){
  int i = 0;
  int Max_f,Max_l,f,l,j;
  Max_f = 0;
  Max_l = 0;
  struct s w[500];

  
  while(scanf("%s",w[i++].word) != EOF){
    w[i-1].len = strlen(w[i-1].word);
    ++(w[i-1].freq);
    if(Max_l < w[i-1].len){
      Max_l = w[i-1].len;
      l = i-1;
    }

    for(j=0;j < i-1;j++){
      if(!(strcmp( w[j].word , w[i-1].word))) ++(w[j].freq);
      if(Max_f < w[j].freq){
        Max_f = w[j].freq;
        f = j;
      }
    }
  }

  printf("%s %s\n",w[f].word,w[l].word);

  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define ll long long
#define BUF 1e5
#define INF 1 << 30
constexpr ll mod = 1e9 + 7;
using namespace std;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

void dfs(int node, vector<vector<int>> &tree, vector<int> &parent, vector<int> &out) {
    int p = parent[node];
    if (tree[node].size() == 1 && node != 0) {
        if (out[node] == 0) {
            cout << p + 1 << " " << node + 1 << endl;
            out[p] = (++out[p]) % 2;
        } else {
            cout << node + 1 << " " << p + 1 << endl;
            out[node] = (++out[node]) % 2;
        }
    } else {
        for (int adj : tree[node]) {
            if (adj == p)
                continue;
            dfs(adj, tree, parent, out);
        }
        if (node != 0) {
            if (out[node] == 0) {
                cout << p + 1 << " " << node + 1 << endl;
                out[p] = (++out[p]) % 2;
            } else {
                cout << node + 1 << " " << p + 1 << endl;
                out[node] = (++out[node]) % 2;
            }
        }
    }
}

int main() {
    cin >> N >> M;
    vector<vector<int>> g(N);
    for (int i = 0; i < M; i++) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }

    if (M % 2 != 0) {
        cout << -1 << endl;
        return 0;
    }
    vector<int> flag(N, 0);
    vector<int> out(N, 0);
    vector<vector<int>> tree(N);
    vector<int> parent(N);
    set<pair<int, int>> set;
    queue<int> q;
    q.push(0);
    parent[0] = -1;
    while (!q.empty()) {
        int now = q.front();
        q.pop();
        int p = parent[now];
        for (int adj : g[now]) {
            if (adj == p)
                continue;
            if (flag[adj]) {
                set.insert({min(now, adj), max(now, adj)});
                continue;
            }
            flag[adj] = 1;
            q.push(adj);
            parent[adj] = now;
            tree[now].push_back(adj);
            tree[adj].push_back(now);
        }
    }
    for (auto edge : set) {
        int u = edge.first;
        int v = edge.second;
        cout << u + 1 << " " << v + 1 << endl;
        out[u] = (++out[u]) % 2;
    }
    dfs(0, tree, parent, out);
}

Measured memory_bytes: 18176
data = input()
data = data.split(" ")
n = int(data[0])
k = int(data[1])
sum = 0
for b in range(1, n+1):
    sum += (n//b*max(0,b-k)+max(0,n%b-k+1))
if k == 0: sum-=n
print(sum)

Measured memory_bytes: 39280
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
const int M = 1046527;
const int L = 14;
char data[M][L];

int getchar(char c)
{
	if(c == 'A')
		return 1;
	else if(c == 'C')
		return 2;
	else if(c == 'G')
		return 3;
	else if(c == 'T')
		return 4;
	else
		return 0;
}

long long getkey(char str[])
{
	long long sum = 0,p = 1;
	for(int i = 0; i < strlen(str); ++i)
	{
		sum += p*getchar(str[i]);
		p *= 5; 
	}
	return sum;
}

int h1(long long key) { return key%M; }
int h2(long long key) { return 1+key%(M-1); }

bool Find(char str[])
{
	long long key,h;
	key = getkey(str);
	for(int i = 0; ; ++i)
	{
		h = (h1(key)+i*h2(key))%M;
		if(strcmp(data[h],str) == 0)
			return true;
		else if(strlen(data[h]) == 0)
			return false;
	}
	return false;
}

void Insert(char str[])
{
	long long key,h;
	key = getkey(str);
	for(int i = 0; ; ++i)
	{
		h = (h1(key)+i*h2(key))%M;
		if(strcmp(data[h],str) == 0)
			break;
		else if(strlen(data[h]) == 0)
		{
			strcpy(data[h],str);
			break;
		}
	}
}

int main()
{
	char str[L],com[9];
	int n,h;
	cin >> n;
	while(n--)
	{
		scanf("%s %s",com,str);
		if(com[0] == 'i')
			Insert(str);
		else
		{
			if(Find(str))
				printf("yes\n");
			else
				printf("no\n");
		}
	}
	return 0;
}


Measured memory_bytes: 17432
#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
#define vv(type, name, h, ...) vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...) vector<vector<vector<type>>> name(h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
using namespace std;
typedef long double ld;
typedef long long lli;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<ii> vii;

#define deb(x) cout << #x": " << (x) << endl;

const int N = 1e5+5;
const lli INF = 1e18;
const lli MOD = 1e9+7;

vi primes(1,2);
vector<vector<ld>>nk;
void sieve(){
	vi m(N+1,0);
	for(int i = 4; i<N; i+=2)m[i]=1;
	for(int i = 3; i*i<=N; i+=2)if(!m[i])for(int j = i*i; j<N; j+=i)m[j]=1;
	for(int i = 3; i<N; i+=2)if(!m[i])primes.pb(i);
}

void pascal(){
	nk =vector<vector<ld>>(N,vector<ld>(N,0.0));
	fore(i,0,N)nk[i][0]=nk[i][i]=1.0;
	fore(i,1,N)fore(j,1,i)nk[i][j]=nk[i-1][j-1]+nk[i-1][j];
}

lli gcd(lli a, lli b){return (b?gcd(b,a%b):a);}

lli lcm(lli a, lli b){
	if(a<b)swap(a,b);
	lli c = gcd(a,b);
	a/=c;
	return a*b;
}

int popcount(lli x) { return __builtin_popcountll(x); }

lli poww(lli a, lli b){
	lli res =1;
	while(b){
		if(b&1) res = res * a;
		a = a*a;
		b/=2;
	}
	return res;
}

lli powm(lli a, lli b){
	lli res =1;
	while(b){
		if(b&1) res = (res * a)%MOD;
		a = (a*a)%MOD;
		b/=2;
	}
	return res;
}

bool isPrime(lli x){
	if(x==1)return 0;
	for(auto i:primes){
		if(i*i>x)return 1;
		if(x%i==0)return 0;
	}
	return 1;
}


lli SUM(lli a, lli b, lli mod=MOD){
	return (a+b+mod)%mod;
}

lli PROD(lli a, lli b, lli mod=MOD){
	a%=mod; b%=mod;
	return a*b % mod;
}

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

vvi graph(int n, int m){
	vv(int,v,n+1,0);
	fore(i,0,m){
		int a,b; cin>>a>>b;
		v[a].pb(b);
		v[b].pb(a);
	}
	return v;
}

// ---- コーディングはここから！ ('-')7


void solve(){
	int n; cin>>n;
	vi v(n); fore(i,0,n)cin>>v[i],v[i]--;
	vi a(n), b(n-1);
	fore(i,0,n)cin>>a[i];
	fore(i,0,n-1)cin>>b[i];
	lli sum = 0;
	fore(i,0,n){
		sum+=a[v[i]];
		if(i and v[i]-1==v[i-1])sum+=b[v[i-1]];
	}

	cout<<sum<<ENDL;

}

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


Measured memory_bytes: 3596
using System;
using System.Collections.Generic;
using System.Linq;

namespace CompetitiveProgramming
{
    class Program
    {
        static void Main(string[] args)
        {
            MainStream();
        }

        static void MainStream()
        {
            int flag = 0;
            int n = int.Parse(Console.ReadLine());
            var list = new List<char[]>() ;

            for (var i = 0; i < n; i++)
            {
                char[] tmp = Console.ReadLine().ToCharArray();
                list.Add(tmp);
            }

            for (var i =0;i<n;i++)
            { 
                if (i!=0)
                {
                    if (list[i][0] != list[i - 1].Last())
                    {
                        flag = 1;
                        break;
                    }

                    for(var j=0; j<i;j++)
                    {
                        if(list[i].Length==list[j].Length)
                        {
                            for(var m =0;m<list[i].Length;m++)
                            {
                                if(list[i][m]!=list[j][m])
                                {
                                    break;
                                }
                                if(m == list[i].Length-1)
                                {
                                    flag = 1;
                                }
                            }
                        }
                        if(flag==1)
                        {
                            break;
                        }
                    }
                }
            }

            if(flag == 1)
            {
                Console.WriteLine("No");
            }
            else
            {
                Console.WriteLine("Yes");
            }
        }



    }
}


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

int main() {
  int a;
  cin >> a;
  cout << a+a*a+a*a*a << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using Int = long long;  // clang-format off
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define ALL(v) std::begin(v), std::end(v)
#define RALL(v) std::rbegin(v), std::rend(v)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef dump
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sat Aug 15 22:15:43 JST 2020
 **/

template <class T> bool chmin(T& a, const T& b) { return a > b ? a = b, true : false; }
template <class T> bool chmax(T& a, const T& b) { return a < b ? a = b, true : false; }

template <class T, class S> T make_vec(S x) { return x; }
template <class T, class... Ts> auto make_vec(size_t n, Ts... ts) {
    return std::vector<decltype(make_vec<T>(ts...))>(n, make_vec<T>(ts...));
}

/// @docs src/Graph/AbstractDijkstra.md
template <class Dist, class Key, class Delta>  // Delta: Key from, (Key to, Dist d -> void) update -> void
std::map<Key, Dist> dijkstra(Key s, Delta delta) {
    std::map<Key, Dist> dist;
    using P = std::pair<Dist, Key>;
    auto cmp_first = [](const P& a, const P& b) { return a.first > b.first; };
    std::priority_queue<P, std::vector<P>, decltype(cmp_first)> q{cmp_first};
    q.push({dist[s] = Dist(), s});
    while (!q.empty()) {
        std::pair<Dist, Key> p = q.top();
        q.pop();
        if (dist[p.second] < p.first) continue;
        delta(p.second, [&](Key to, Dist d) -> void {
            if (dist.count(to) && dist[to] <= p.first + d) return;
            q.push({dist[to] = p.first + d, to});
        });
    }
    return dist;
}

bool is_palindrome(const std::string& s) { return s == std::string(s.rbegin(), s.rend()); }
const Int INF = 1e18;
const std::string dummy = "01";
signed main() {
    Int n;
    std::cin >> n;
    auto ss = make_vec<std::string>(2, n, "");
    std::vector<Int> c(n);
    REP(i, n) std::cin >> ss[0][i] >> c[i], ss[1][i] = std::string(RALL(ss[0][i]));
    using Key = std::pair<std::string, bool>;
    auto delta = [&](Key from, auto update) -> void {
        REP(i, n) {
            std::string s = from.first == dummy ? "" : from.first;
            std::string t = ss[!from.second][i];
            bool nxt_b = from.second ^ (s.size() < t.size());
            if (s > t) std::swap(s, t);
            if (s != t.substr(0, s.size())) continue;
            std::string nxt_s = t.substr(s.size(), t.size() - s.size());
            update(Key{nxt_s, nxt_b}, c[i]);
        }
    };
    Key s = {dummy, 0};
    auto res = dijkstra<Int>(s, delta);
    Int ans = INF;
    for (auto& p : res) {
        if (is_palindrome(p.first.first)) chmin(ans, p.second);
    }
    std::cout << (ans == INF ? -1 : ans) << std::endl;
}


Measured memory_bytes: 3816
from collections import deque
H,W=map(int,input().split())
A=[list(input()) for _ in range(H)]

q=deque()

#黒マスを探す
for w in range(W):
    for h in range(H):
        if A[h][w]=='#':
            q.append((h,w,0))

#BFS
ans=0
while q:
    h,w,d = q.popleft()
    ans=max(ans,d)
    for dh,dw in [(0,1),(1,0),(0,-1),(-1,0)]:
        nh,nw = h+dh, w+dw
        if nh<0 or nh>=H or nw<0 or nw>=W:
            continue
        if A[nh][nw]=='#':
            continue
        A[nh][nw]='#'
        q.append((nh,nw,d+1))

print(ans)

Measured memory_bytes: 161500
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;


int main(void){
  int n,m,i,a,dp[100005]={};
  const int mod=1e9+7;
  
  cin >> n >> m;
  for (i=0;i<m;i++){
    cin >> a;
    dp[a]=-1;
  }
  
  dp[0]=1;
  for (i=1;i<=n;i++){
    if (dp[i]==0){
      if (i-2>=0 && dp[i-2]>=0) dp[i]=(dp[i]+dp[i-2])%mod;
      if (dp[i-1]>=0) dp[i]=(dp[i]+dp[i-1])%mod;
    }
  }
  
  cout << dp[n] << endl;
  
  return 0;
}

Measured memory_bytes: 640
#include <algorithm>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;

void solve(int W, int w, vector<int>& a) {
  if (W % w == 0) {
    return;
  }
  vector<int> s(W + 1, 0);
  for (int i = 1; i < w; i++) {
    s[i] = (W + w - 1) / w;
  }
  for (int i = w; i <= W; i++) {
    s[i] = s[i - w] - 1;
  }
  for (int i = 0; i < W; i++) {
    a[i] = s[i + 1] - s[i];
  }
}

int main() {
  int H, W, h, w;
  cin >> H >> W >> h >> w;
  if (H % h == 0 && W % w == 0) {
    cout << "No" << endl;
    return 0;
  }
  vector<int> ys(H, 0), xs(W, 0);
  solve(H, h, ys);
  solve(W, w, xs);
  cout << "Yes" << endl;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cout << (ys[i] + xs[j]) << " ";
    }
    cout << endl;
  }
  return 0;
}


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

typedef long long ll;
const ll INF = 1e18;
const int BIG = 1e9 + 555;

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

	int n;
	cin >> n;
	cout << n * n * n << '\n';
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define N (1<<17)

using namespace std;

int a, b, ans;

bool pali(int x) {
	string s = to_string(x);
	for(int i=0; i<s.size(); i++) {
		if(s[i]!=s[s.size()-i-1])
			return false;
	}
	return true;
}

int main() {
	cin.tie(0); 
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	cin >> a >> b;
	for(int i=a; i<=b; i++) {
		if(pali(i))
			ans++;
	}
	cout << ans;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstring>
#include<vector>
#include<stack>
using namespace std;
#define INT(x) int x; scanf("%d",&x)
#define INPUT(x) scanf("%d",&x)
#define REP1(x,n) for(int x = 0; x < n; x++)
#define REP2(x,s,e) for(int x = s; x <= e; x++)
#define BR printf("\n")
#define INF 2000000000

vector<int> V[100];//0 origin
bool complete[100] = {};
stack<int> S;
int time_ = 1;
int NodeStump[100][2] = {};//find,end

void DFS(){
    if (S.empty()) return;
    NodeStump[S.top()][0] = time_;
    time_++;
    
    REP1(i,V[S.top()].size()){
        if (NodeStump[V[S.top()][i]][0] == 0){
            S.push(V[S.top()][i]);
            DFS();
        }
    }
    
    complete[S.top()] = true;
    NodeStump[S.top()][1] = time_;
    S.pop();
    time_++;
}

int main(){
    INT(N);
    
    REP1(i,N){
        int from,n;
        scanf("%d %d",&from,&n);
        REP1(j,n){
            INT(to);
            V[i].push_back(to - 1);
        }
    }
    
    REP1(i,N){
        if(!complete[i]){
        S.push(i);
        DFS();
        }
    }
    
    REP1(i,N) printf("%d %d %d\n",i+1,NodeStump[i][0],NodeStump[i][1]);
    
    return 0;
}

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

int     get_g(int i, vector<int> &grp) {
        if (i==grp.at(i)) return i;
        return get_g(grp.at(i), grp);
}

int     main() {
        int N, M;
        cin >>N >>M;
        vector<int> p(N+1, 0);
        vector<int> grp(N+1, 0);
        vector<int> num_of_grp(N+1, 0);
        for (int i=1; i<=N; i++) {
                cin >>p.at(i);
                grp.at(i)=i;
                num_of_grp.at(i)=1;
        }
        vector<int> x(M, 0);
        vector<int> y(M, 0);
        for (int i=0; i<M; i++)
                cin >>x.at(i) >>y.at(i);
        for (int i=0; i<M; i++) {
                int xx=x.at(i);
                int yy=y.at(i);
                xx=get_g(xx, grp);
                yy=get_g(yy, grp);
                // Already in same group, do nothing
                if (xx==yy) continue;
                // Put into one group
                if (num_of_grp.at(xx)==num_of_grp.at(yy)) {
                        grp.at(max(xx, yy)) = get_g(min(xx, yy), grp);
                        num_of_grp.at(min(xx, yy)) *=2;
                } else if (num_of_grp.at(xx) > num_of_grp.at(yy)) {
                        grp.at(yy) = xx;
                        num_of_grp.at(xx) += num_of_grp.at(yy);
                } else {
                        grp.at(xx) = yy;
                        num_of_grp.at(yy) += num_of_grp.at(xx);
                }
        }
        int S=0;
        for (int i=1; i<=N; i++) {
                if (i==p.at(i))
                        S++;
                else if (get_g(i, grp)==get_g(p.at(i), grp))
                        S++;
        }
        cout <<S <<endl;
        return 0;
};

Measured memory_bytes: 2176
#include<iostream>
#include<cmath>

#define all(x) (x).begin(),(x).end()
#define puts(x) cout<< x << endl;
#define rep(i,m,n) for(int i=m;i<n;i++)
#define fore(i,a) for(auto i:a)
#define ll long long
using namespace std;
int n;
int x[105];
int main(){
    cin>>n;
    rep(i,0,n){
        cin>>x[i];
    }
    int min_sum=0;
    rep(j,0,n){
        min_sum+=pow(x[j],2);
    }
    rep(i,1,101){//中心点
        int sum=0;
        rep(j,0,n){
            sum+=pow((x[j]-i),2);
        }
        min_sum=min(min_sum,sum);
    }
    puts(min_sum)
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>	
#include <deque>
#include <set>
#include <climits>
#include <memory>
#include <numeric>
#include <utility>


#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define fore(i,a) for(auto &i:a)
#define INF INT_MAX/2;
#define PI 3.14159265358979323846264338327950L;
const int INF2 = 1001001001;
typedef long long ll;
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;
//ll llmax = 10000000000000000000ll;
const ll LINF = 1e18 + 100;
using namespace std;
using Graph = vector<vector<int>>;



int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}


 // 最大公約数計算
 
ll gcd(ll a, ll b)
{
	if (b == 0) {
		return a;
	}
	else {
		return gcd(b, a % b);
	}
}
// 最小公倍数の計算

ll lcm(ll a, ll b)
{
	ll g = gcd(a, b);

	return a / g * b;
}

struct union_find
{
	vector<int> par, r;
	union_find(int n)
	{
		par.resize(n);
		r.resize(n);
		init(n);
	}


	void init(int n)
	{
		for (int i = 0; i < n; i++) par[i] = i;
		for (int i = 0; i < n; i++) r[i] = 0;
	}

	int find(int x)
	{
		if (par[x] == x)return x;
		else return find(par[x]);
	}

	void unite(int x, int y)
	{
		x = find(x);
		y = find(y);

		if (r[x] < r[y])
		{
			par[x] = y;
		}
		else
		{
			par[y] = x;
			if (r[x] == r[y])
			{
				r[x]++;
			}
		}
	}
};

const int MAX_N = 110000;

int memo[MAX_N];

int rec(int n) {
	if (n == 0)return 0;
	if (memo[n] != -1)return memo[n];

	int res = n;

	for (int pow6 = 1; pow6 <= n; pow6 *= 6)res = min(res, rec(n - pow6) + 1);

	for (int pow9 = 1; pow9 <= n; pow9 *= 9)res = min(res, rec(n - pow9) + 1);

	return memo[n] = res;
}

int calc(int x) {
	int ret = 0;
	while (x % 2 == 0) {
		x /= 2;
		ret++;
	}

	return ret;
}

int a[12][12];
int D;
ll G;
vector<ll> P, C;

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

	int n,k;

	cin >> n >> k;
	if (n * k % 2 == 0)cout << "No" << endl;
	else cout << "Yes" << endl;
	
	
	
}
	

Measured memory_bytes: 256