akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#define INF 1 << 28
#define MAX_DATA 1 << 17
using namespace std;

typedef pair<int,int> P;

template <class T>
class SegmentTree
{
private :
    int n;
    vector<T> data;
public :
    void init(int);
    void update(int, int);
    int query(int, int, int, int, int);
    int size();
    T top();
};

template <class T>
void SegmentTree<T>::init (int n_) {
    n = 1;
    while (n < n_ + 1) n *= 2;
    data.resize(n * 2);
    for (int i = 0; i < data.size(); i++) data[i] = 0;
}

template <class T>
void SegmentTree<T>::update (int k_, int l_) {
    for (int i = k_; i <= 1260 - 540 && i < l_; i++) {
        int tmp_ = i + n - 1;
        data[tmp_] = 1;
        while (tmp_) {
            tmp_ = (tmp_ - 1) / 2;
            data[tmp_] = data[tmp_ * 2 + 1] + data[tmp_ * 2 + 2];
        }
    }
}

template <class T>
int SegmentTree<T>::query (int a_, int b_, int k_, int l_, int r_) {
    if (r_ <= a_ || b_ <= l_) return 0;

    if (a_ <= l_ && r_ <= b_) {
        return data[k_];
    }
    else {
        T vl = query(a_, b_, k_ * 2 + 1, l_, (l_ + r_) / 2);
        T vr = query(a_, b_, k_ * 2 + 2, (l_ + r_) / 2, r_);

        return (vl + vr);
    }
}

template <class T>
int SegmentTree<T>::size () {
    return n;
}

template <class T>
T SegmentTree<T>::top () {
    return data[0];
}

int main()
{
    int N, M;
    while (cin >> N >> M, (N || M)) {
        int R;
        cin >> R;

        vector<SegmentTree<unsigned short> > p(M + 1);
        for (int i = 0; i < p.size(); i++) {
            p[i].init(1260 - 540);
        }
        map<P,int> dat;
        for (int i = 0; i < R; i++) {
            unsigned short t, n, m, s;
            cin >> t >> n >> m >> s;

            t -= 540;
            if (s) {
                dat[P(n,m)] = t;
            } else {
                int tmp = dat[P(n,m)];
                auto ite = dat.find(P(n,m));
                dat.erase(ite);
                p[m].update(tmp, t);
            }
        }

        for (auto i : dat) {
            p[i.first.second].update(i.second, INF);
        }

        int Q;
        cin >> Q;
        for (int i = 0; i < Q; i++) {
            unsigned short ts, te, m;
            cin >> ts >> te >> m;
            ts -= 540;
            te -= 540;
            cout << p[m].query(ts, te, 0, 0, p[m].size()) << endl;
        }
    }



    return 0;
}

Measured memory_bytes: 40176
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    queue< pair<string, int> > que;
    queue< pair<string, int> > ans;
    int N, q;
    cin >> N >> q;
    for(int i = 0; i < N; i++){
        string Name;
        int Time;
        cin >> Name >> Time;
        que.push({Name, Time});
    }
    
    int num = 0;
    while(!que.empty()){
        
        string ans_Name = que.front().first;
        int ans_Time = que.front().second;
        que.pop();
        if(ans_Time - q > 0){
            num += q; 
            que.push({ans_Name, ans_Time - q});
        }
        else{
            if(q - ans_Time == 0){
                num += q; 
                ans.push({ans_Name, num});                
            }
            else{
                num += ans_Time;
                ans.push({ans_Name, num});
            }
        }
        //cout << ans_Name << " " << ans_Time << " " << num << endl;
    }
    
    while(!ans.empty()){
        cout << ans.front().first << " " << ans.front().second << endl;
        ans.pop();
    }
    
}



Measured memory_bytes: 6292
import itertools
n = int(input())
l = []
for i in range(n):
    d = int(input())
    for dd in range(d):
        x, y = map(int, input().split())
        l.append([i, x-1, y])
 
ans = 0
for p in itertools.product([0, 1], repeat=n):
    for ll in l:
        if p[ll[0]] == 1 and p[ll[1]] != ll[2]:
            break
    else:
        ans = max(ans, sum(p))
print(ans)

Measured memory_bytes: 9212
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <limits.h>
using namespace std;
bool flag[101];
int d[101];
int f[101];
vector<int> v[101];
int t;
void dfs(int node){
	flag[node] = true;
	d[node] = t;
	bool finished = true;
	if (finished && f[node] == 0) f[node] = t;
	for (int i = 0; i < v[node].size(); ++i){
		int tmp = v[node][i];
		if (!flag[tmp]){
			++t;
			dfs(tmp);
			++t;
		}
	}
	f[node] = t;
}
int main(){
	int n; scanf("%d",&n);
	for (int i = 0; i < n; ++i){
		int u, k; scanf("%d %d",&u,&k);
		int tmp;
		for (int j = 0; j < k; ++j){
			scanf("%d", &tmp);
			v[u].push_back(tmp);
		}
	}
	v[0].push_back(1);
	dfs(0);
	++t;
	for (int i = 1; i <= n; ++i){
		if (d[i] == 0) dfs(i);
	}
	for (int i = 1; i <= n; ++i){
		cout << i << ' ' << d[i] << ' ' << f[i]+1 << '\n';
	}
}

Measured memory_bytes: 1228
#include <stdio.h>

int main()
{
  char s[5], t[5];
  scanf("%s%s", s,t);
  int a = 0;
  for(int i = 0; i < 3; i++) {
    if(s[i] == t[i]) a++;
  }
  printf("%d\n", a);
		       
  return 0;
}


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

using namespace std;

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

    string s;
    cin >> s;

    for (char &c : s)
        if (c == '?')
            c = 'D';

    cout << s;
}


Measured memory_bytes: 3716
function *main() {
  
  const N = parseInt((yield), 10);
  const P = (yield).split(" ").map(s => parseInt(s, 10));
  let m = 200001, ans = 0;
  for (let p of P) {
    if (p < m) ans++;
    m = Math.min(m, p);
  }
  console.log(ans);
  
}
const iter = main();
iter.next();
require("readline").createInterface({input: process.stdin, output: process.stdout}).on("line", line => iter.next(line));

Measured memory_bytes: 50624
//
//  main.c
//  Integer Cards
//
//  Created by yuta on 2019/05/25.
//  Copyright © 2019 501Software. All rights reserved.
//

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

typedef struct {
	int  B;
	long C;
} OPERATE;

int comp_op(const void *a, const void *b) {
	OPERATE op1 = *(const OPERATE*)a;
	OPERATE op2 = *(const OPERATE*)b;
	if (op1.C > op2.C) return -1;
	if (op1.C < op2.C) return 1;
	return 0;
}

int comp_int(const void* a, const void* b)
{
	long arg1 = *(const long*)a;
	long arg2 = *(const long*)b;
	
	if (arg1 < arg2) return -1;
	if (arg1 > arg2) return 1;
	return 0;
}


int main(int argc, const char * argv[]) {
	int N,M;
	
	// カード回数,操作回数入力
	scanf("%d %d",&N,&M);
	
	// カード配列作成
	long A[N];
	
	// 操作配列作成
	OPERATE operate[M];
	
	// カードの数字入力
	for (int i = 0 ; i < N ; i++) {
		scanf("%ld",&(A[i]));
	}
	
	// カード配列ソート
	qsort(A, N, sizeof(long), comp_int);

	// 操作入力
	for (int i = 0 ; i < M ; i++) {
		scanf("%d %ld",&operate[i].B,&operate[i].C);
	}
	
	// 操作配列ソート
	qsort(operate, M, sizeof(OPERATE), comp_op);

	// 操作処理
	int k=0;
	int j=0;
	int stop = 0;
	for(int i = 0; i < M; i++){
		
		for(j = 0 ; j < operate[i].B; j++){
			if(operate[i].C > A[k+j]) {
				A[k+j] = operate[i].C;
			}
			else {
				stop = -1;
				break;
			}
		}
		if (stop == -1){
			break;
		}
		k+=j;
	}
	
	
	
		/*
		for(int k = 0; k < B; k++) {
			int index=-1;
			long low = 9999999999;
			for (int j=0; j < N; j++) {
				if(low > A[j] && C > A[j]) {
					index = j;
					low = A[j];
				}
			}
			if (index == -1) {
				break;
			}
			else {
				A[index] = C;
			}
		}
	}

*/


	// 合計取得
	long t=0;
	for (int i = 0 ; i < N ; i++){
		t+=A[i];
//		printf("%ld ",A[i]);
	}
	
//	printf("\n");
	
	// Anser出力
	printf("%ld\n",t);
	return 0;
}


Measured memory_bytes: 4084
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#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> // dequef
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define all(a) (a).begin(), (a).end()
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int n;
  cin >> n;
  vi a(n);
  rep(i, n) cin >> a[i];
  sort(all(a)); reverse(all(a));
  ll ans = 0;
  for(int i = 0; i < n / 2; i++) ans += a[i];
  for(int i = 1; i < n / 2; i++) ans += a[i];
  if(n & 1) ans += a[n / 2];
  cout << ans << endl;
}

Measured memory_bytes: 4052
int main(void)
{
    int a,b,c;
    int tmp;
    scanf("%d %d %d",&a,&b,&c);

    if (a>b)
    {
        tmp = b;
        b = a;
        a = tmp;
    }
    if (b>c)
    {
        tmp = c;
        c = b;
        b = tmp;
        if(a>b)
        {
            tmp = b;
            b = a;
            a = tmp;
        }
    }
    printf("%d %d %d\n",a,b,c);
}



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

void fnInput(int& rnTrkSiz, vector<int>& rvnLod)
{
  int nLodSiz;
  cin >> nLodSiz >> rnTrkSiz;

  rvnLod.resize(nLodSiz);
  for (int i = 0; i < nLodSiz; i++)
    cin >> rvnLod[i];
}

int fnSimuAlloc(const vector<int>& cnrvnLod, int nTrkSiz, int nLimLod)
{
  int nCurLod;
  int nCntTrk = 0;

  for (int i = 0; i < cnrvnLod.size();    )
  {
    if (cnrvnLod[i] > nLimLod)  return 0;

    nCntTrk++;
    nCurLod = 0;
    while (i < cnrvnLod.size())
    {
      nCurLod += cnrvnLod[i];
      if (nCurLod > nLimLod)  break;

      i++;
    }
  }
  return (nCntTrk <= nTrkSiz);
}

void fnAlloc(const vector<int>& cnrvnLod, int nTrkSiz, int& rnMinLod)
{
  const int nMINLOD = 0;
  const int nMAXLOD = 1000000000;

  int nLow  = nMINLOD;
  int nHigh = nMAXLOD;
  rnMinLod  = nMAXLOD;

  while (nLow < nHigh)
  {
    int nLimLod = (nLow + nHigh) / 2;
    if (fnSimuAlloc(cnrvnLod, nTrkSiz, nLimLod))
    {
      rnMinLod = min(rnMinLod, nLimLod);
      nHigh = nLimLod;
    }
    else
      nLow = nLimLod + 1;
  }
}

void fnReSult(int nMinLod)
{
  cout << nMinLod << endl;
}

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

  int nTrkSiz, nMinLod = 0;
  vector<int> vnLod;

  fnInput(nTrkSiz, vnLod);
  fnAlloc(vnLod, nTrkSiz, nMinLod);
  fnReSult(nMinLod);

  return 0;
}

Measured memory_bytes: 3344
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n, h;
	cin >> n >> h;
	vector<ll> a(n), b(n);
	rep(i, n) cin >> a[i] >> b[i];

	ll res = 0;
	ll t = 0;
	sort(rall(a));

	rep(i, n) {
		if (b[i] >= a[0]) {
			res++;
			t += b[i];
		}
	}

	if (t >= h) {
		sort(rall(b));
		ll p = 0;
		ll ans = 0;
		rep(i, n) {
			if (b[i] >= a[0]) {
				p += b[i];
				ans++;
			}
			if (p >= h) {
				dunk(ans);
				break;
			}
		}
	}
	else {
		ll ans = res;
		h -= t;
		ans += h % a[0] == 0 ? h / a[0] : int(h / a[0]) + 1;
		dunk(ans);
	}

	return 0;
}

Measured memory_bytes: 1792
def main():
    N = int(input())
    points = [None] * N
    for i in range(N):
        x, y = map(int, input().split())
        points[i] = (x, y)
    ans = 0
    points.sort(reverse=True)
    topright = points[0][0] + points[0][1]
    bottomright = points[0][0] - points[0][1]
    for i in range(N):
        tr = points[i][0] + points[i][1]
        br = points[i][0] - points[i][1]
        ans = max([ans, abs(topright - tr), abs(bottomright - br)])
        topright = max(topright, tr)
        bottomright = max(bottomright, br)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 83368
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use itertools_num::ItertoolsNum;
#[allow(unused_imports)]
use std::cmp;
use std::collections::HashMap;
#[allow(unused_imports)]
use std::iter;
#[allow(unused_imports)]
use superslice::*;

fn run() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let h: usize = sc.read();
    let w: usize = sc.read();
    let d: usize = sc.read();
    let a = sc.read_matrix::<usize>(h, w);
    let q: usize = sc.read();

    let mut hmap = HashMap::new();
    for i in 0..h {
        for j in 0..w {
            hmap.insert(a[i][j] - 1, (i as i64, j as i64));
        }
    }

    let mut cum = vec![0; h * w];
    for i in d..(h * w) {
        cum[i] = cum[i - d]
            + (hmap[&i].0 - hmap[&(i - d)].0).abs()
            + (hmap[&i].1 - hmap[&(i - d)].1).abs();
    }
    for _ in 0..q {
        let l: usize = sc.read();
        let r: usize = sc.read();
        println!("{}", cum[r - 1] - cum[l - 1]);
    }
}

fn main() {
    std::thread::Builder::new()
        .name("run".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(run)
        .unwrap()
        .join()
        .unwrap();
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn read_pairs<T: std::str::FromStr>(&mut self, n: usize) -> Vec<(T, T)> {
        (0..n).map(|_| (self.read(), self.read())).collect()
    }
    pub fn read_pairs_1_indexed(&mut self, n: usize) -> Vec<(usize, usize)> {
        (0..n)
            .map(|_| (self.read::<usize>() - 1, self.read::<usize>() - 1))
            .collect()
    }
    pub fn read_chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
    pub fn read_char_grid(&mut self, n: usize) -> Vec<Vec<char>> {
        (0..n).map(|_| self.read_chars()).collect()
    }
    pub fn read_matrix<T: std::str::FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n)
            .map(|_| (0..m).map(|_| self.read()).collect())
            .collect()
    }
}


Measured memory_bytes: 6672
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
//#pragma GCC target("avx,avx2")
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")

//# include <x86intrin.h>
# include <bits/stdc++.h>

# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
 
template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void setIO(string s = "") {
	// cin.exceptions(cin.failbit); 
	// throws exception when do smth illegal
	// ex. try to read letter into int
	if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 2e6 + 9;
const int N = 6e5 + 123;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());
 
int rnd (int l, int r) {
	return uniform_int_distribution<int> (l, r)(gen);
}
 
int n, m, k;
ll pw[mxn];

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

ll fac[mxn], ifac[mxn], inv[mxn];

ll C (int n, int k) {
	if (k > n || k < 0) return 0;
	return mult(mult(fac[n], ifac[k]), ifac[n-k]);
}

int main () {
	SpeedForce;
	setIO();
	string s;
	cin >> n >> s;
	pw[0] = 1;
	fac[0] = ifac[0] = inv[1] = 1;
	for (int i = 2; i < mxn; ++i) {
		inv[i] = mult(mod - mod/i, inv[mod%i]);
	}
	for (int i = 1; i < mxn; ++i) {
		pw[i] = pw[i-1] * 25 % mod;
		fac[i] = mult(fac[i-1], i);
		ifac[i] = mult(ifac[i-1], inv[i]);
	}
	ll ans = 0;
	for (int i = 0; i <= n; ++i) {
		ans += mult(C(sz(s)+n, i+sz(s)), pw[n-i]);
		ans %= mod;
	}
	cout << ans % mod;

	return Accepted;
}

// B...a

Measured memory_bytes: 66844
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pb push_back
#define f(i,n) for(int i=0; i<n; ++i)
#define fi(i,st,n) for(int i=st; i<=n; ++i)
#define veci vector<int>
#define vecp vector<pair<int,int> >
#define vecl vector<ll>
int prime[100000+10];

ll lcm(ll a, ll b) {
	return a*b/__gcd(a,b);
}

ll power(ll a, ll n, ll mod) {
	ll res = 1;
	while(n > 0) {
		if(n&1) {
			res = (res*a)%mod;
		}
		a = (a*a)%mod;
		n = n/2;
	}
	return res;
}

ll sum(int arr[], int n) {
	ll res = 0;
	f(i,n) {
		res += arr[i];
	}
	return res;
}

void seive() {
	prime[1] = 0;
	for(int i=2; i<=100000; i++) {
		prime[i] = 1;
	}
	for(ll i=2; i<=100000; i++) {
		if(prime[i]) {
			for(ll j=i*i; j<=100000; j+=i) {
				prime[j] = 0;
			}
		}
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t = 1;
//	cin>>t;
	while(t--){
		ll d,t,s;
		cin>>d>>t>>s;
		if(s*t >= d) {
			cout<<"Yes\n";
		}
		else {
			cout<<"No\n";
		}
 	}
 	return 0;
}


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

int main()
{
    int n,l;
    string s[100];
    cin>>n>>l;
    for(int i=0;i<n;i++){
        cin>>s[i];
    }
    sort(s,s+n);
    for(int i=0;i<n;i++){
        cout<<s[i];
    }
    
    return 0;
}


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

const int N=1010;
const int M=2010<<2;
const long long oo=(long long)1<<60;
long long d[N], c[M];
int st[N], b[M], nex[M];
int tot, n, m, i, j, x, y, z;
bool g[N];
int q[N * M], ss[N];

void spfa(int start)
{
    int t=0,h;
	for (i=1;i<=n;i++) d[i]=-oo;
	q[++t]=start,h=d[start]=0,g[start]=true;
	ss[1] = 0;
	while (h < t)
	{
		h++,x=q[h],g[x]=false;
		for (j=st[x];j;j=nex[j])
		{
			if (d[x]+c[j]>d[b[j]])
			{
				d[b[j]]=d[x]+c[j];
				if (!g[b[j]]) t++,q[t]=b[j],g[b[j]]=true;
				ss[t] = ss[h] + 1;
				if (ss[t] > n)
				{
				     if (b[j] == n)
				     {
				         d[n] = -oo;
				         return;
                     }
                     if (ss[t] > 2 * n) t--;
                }
			}
		}
	}
}

void add(int x, int y, int z)
{
    b[++tot] = y;
    c[tot] = z;
    nex[tot] = st[x];
    st[x] = tot;
}

int main()
{
	ios::sync_with_stdio(false);
    cin>>n>>m;
    d[1] = 0;
    for (i = 1; i <= m; i++)
    {
        cin>>x>>y>>z;
        add(x, y, z);
    }
    spfa(1);
    if (d[n] > -oo) cout<<d[n]<<endl;
            else puts("inf");
    return 0;
}


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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

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

//main code

int main(int argc, char const* argv[])
{
	int n;
	cin >> n;
	VL h(n);
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}
	VL dp(n,0);
	dp[1] = abs(h[0] - h[1]);
	for (int i = 2; i < n; i++) {
		dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]),dp[i-2] + abs(h[i] - h[i-2]));
	}
	cout << dp[n-1] << endl;
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
using namespace std;

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


Measured memory_bytes: 256
// ABC175-C
#include <bits/stdc++.h>
#define endl "\n"
#define rep(i,n) for(int i=0;i<int(n);i++)
#define e_b emplace_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ipair;
typedef pair<ll,ll> lpair;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v) //vectorの中身を見る
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
void map_p(map<int,int>& d){cout<<"map: ";for(auto a : d){cout<<"{"<<a.first<<":"<<a.second<<"}";}cout<<endl;} //mapの中身を見る
void set_p(set<int>& d){cout<<"set: ";for(int a : d){cout<<a<<" ";}cout<<endl;} //setの中身を見る


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);

    ll n,ans=0,now,next;
    cin>>n;
    cin>>now;
    rep(i,n-1){
        cin>>next;
        if(now>next){
            ans+=(now-next);
        }else{
            now=next;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3660
#include<iostream>
#include <algorithm>
using namespace std;
int N_MAX = 8;
class MP
{
  public:
  int ad,de,co;
  int num();
  int cpr(MP mp);
  void copy(MP mp);
  MP* min(MP* mpp);
  void mag(int n, int a, int* l);
  void mag2(int n, int a, int b, int* l);
  void mag3(int n, int a, int b, int c, int* l);
};
int MP::num(){
  return ad+de+co*10;
}
int MP::cpr(MP mp){
  int m1,m2;
  m1=num();
  m2=mp.num();
  if(m1>m2) return 1;
  else if(m1==m2) return 0;
  else return -1;
}
void MP::copy(MP mp){
  ad=mp.ad; de=mp.de; co=mp.co; return;
}
MP* MP::min(MP* mpp){
  if(cpr(*mpp)>=0) return mpp;
  else return this;
}
void MP::mag(int n, int a, int* l){
  int res,t;
  if(n==1){
    if(l[0]>=a){
      ad=0;
      de=l[0]-a;
      co=0;
      return;
    } else {
      ad=a-l[0];
      de=0;
      co=0;
      return;
    }
  } else {
    MP mp1,mp2,mp3;
    MP* mpp;
    mp1.mag(n-1,a,l+1);
    mp2.mag(1,a,l);
    mp3.mag(n-1,a-l[0],l+1);
    mp3.co++;
    mpp=mp1.min(&mp2);
    mpp=mp3.min(mpp);
    copy(*mpp);
    return;
  }
}
void MP::mag2(int n, int a, int b, int* l){
  MP mpn,mpa,mpb,mpa1,mpa2,mpb1,mpb2;
  MP* mpp;
  if(n==2){
    mpb.mag(1,b,l);
    mpa.mag(1,a,l+1);
    ad=mpa.ad+mpb.ad;
    de=mpa.de+mpb.de;
    co=mpa.co+mpb.co;
    return;
  } else {
    mpn.mag2(n-1,a,b,l+1);
    mpa1.mag(1,a,l);
    mpa2.mag(n-1,b,l+1);
    mpb1.mag(1,b,l);
    mpb2.mag(n-1,a,l+1);
    mpa1.ad+=mpa2.ad; mpa1.de+=mpa2.de; mpa1.co+=mpa2.co;
    mpb1.ad+=mpb2.ad; mpb1.de+=mpb2.de; mpb1.co+=mpb2.co;
    if(a-l[0]>b)
      mpa.mag2(n-1,a-l[0],b,l+1);
    else
      mpa.mag2(n-1,b,a-l[0],l+1);
    mpb.mag2(n-1,a,b-l[0],l+1);
    mpa.co++;
    mpb.co++;
    mpp=mpn.min(&mpa);
    mpp=mpb.min(mpp);
    mpp=mpa1.min(mpp);
    mpp=mpb1.min(mpp);
    copy(*mpp);
    return;
  }
}
void MP::mag3(int n, int a, int b, int c, int* l){
  MP mpn,mpa,mpb,mpc,mpa1,mpa2,mpb1,mpb2,mpc1,mpc2;
  MP* mpp;
  if(n==3){
    mpc.mag(1,c,l);
    mpb.mag(1,b,l+1);
    mpa.mag(1,a,l+2);
    ad=mpa.ad+mpb.ad+mpc.ad;
    de=mpa.de+mpb.de+mpc.de;
    co=mpa.co+mpb.co+mpc.co;
    return;
  } else {
    mpn.mag3(n-1,a,b,c,l+1);
    mpa1.mag(1,a,l);
    mpa2.mag2(n-1,b,c,l+1);
    mpb1.mag(1,b,l);
    mpb2.mag2(n-1,a,c,l+1);
    mpc1.mag(1,c,l);
    mpc2.mag2(n-1,a,b,l+1);
    mpa1.ad+=mpa2.ad; mpa1.de+=mpa2.de; mpa1.co+=mpa2.co;
    mpb1.ad+=mpb2.ad; mpb1.de+=mpb2.de; mpb1.co+=mpb2.co;
    mpc1.ad+=mpc2.ad; mpc1.de+=mpc2.de; mpc1.co+=mpc2.co;
    if(a-l[0]>b)
      mpa.mag3(n-1,a-l[0],b,c,l+1);
    else if(a-l[0]>c)
      mpa.mag3(n-1,b,a-l[0],c,l+1);
    else
      mpa.mag3(n-1,b,c,a-l[0],l+1);
    if(b-l[0]>c)
      mpb.mag3(n-1,a,b-l[0],c,l+1);
    else
      mpb.mag3(n-1,a,c,b-l[0],l+1);
    mpc.mag3(n-1,a,b,c-l[0],l+1);
    mpa.co++;
    mpb.co++;
    mpc.co++;
    mpp=mpn.min(&mpa);
    mpp=mpb.min(mpp);
    mpp=mpc.min(mpp);
    mpp=mpa1.min(mpp);
    mpp=mpb1.min(mpp);
    mpp=mpc1.min(mpp);
    copy(*mpp);
    return;
  }
}
int main()
{
  int n,a,b,c;
  cin >> n >> a >> b >> c;
  int l[N_MAX];
  int res;
  MP mp;
  for(int i=0;i<n;i++)
    cin >> l[i];
  sort(l,l+n);
  mp.mag3(n,a,b,c,l);
  res=mp.num();
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define k 10001

void CountingSort(int A[],int B[],int n){
  int C[k+1];

 for(int i=0;i<=k;i++){
    C[i] = 0;
 }

 for(int j=0;j<n;j++){
    C[A[j]]++;
}

 for(int i=1;i<=k;i++){
    C[i] = C[i] + C[i-1];
 }

 for(int j=n-1;j>=0;j--){
    B[C[A[j]]-1] = A[j];
    C[A[j]]--;
 }

}

int main(){
  int n;

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

 for(int j=0;j<n-1;j++){
	printf("%d ",B[j]);
}
printf("%d\n",B[n-1]);
return 0;
}


Measured memory_bytes: 17396
#include <stdio.h>
int main()
{
    int i, j;
    for ( i = 1; i <= 9; i++)
    {
        for ( j = 1; j <= 9; j++)
        {
            printf("%dx%d=%d\n", i, j, i * j);
        }
    }
    return 0;
}

Measured memory_bytes: 524
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<ctime>
#include<set>
#include<map>
#include<queue>
#include<stack>
#define sqr(x) ((x)*(x))
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define fzin fz1(i,n)
#define fzim fz1(i,m)
#define fzjn fz1(j,n)
#define fzjm fz1(j,m)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
#define inc(x,y) {x+=(y);if(x>=mod)x-=mod;}
#define dec(x,y) {x-=(y);if(x<0)x+=mod;}
using namespace std;
long long n,m,i,j,a[25];
long long dfs(int l,int r,int lx,int rx)
{
	if(l+1==r)return 0;
	long long ans=1e18,i;
	fz(i,l+1,r-1){
		ans=min(ans,dfs(l,i,lx,lx+rx)+dfs(i,r,lx+rx,rx)+(lx+rx)*a[i]);
	}
	return ans;
}
int main()
{
	cin>>n;
	fz1(i,n){
		cin>>a[i];
	}
	cout<<dfs(1,n,1,1)+a[1]+a[n]<<endl;
	return 0;
}

Measured memory_bytes: 384
a,b = input().split()
a
l1 = ['1','3','5','7','8','10','12']
l2 = ['4','6','9','11']
if (a in l1) == (b in l1) == 1:
    print('Yes') 
elif (a in l2) == (b in l2) == 1:
    print('Yes') 
else:
    print('No')



Measured memory_bytes: 3060
n, m = map(int, input().split())

gates = [0] * (n + 2)
for _ in range(m):
    l, r = map(int, input().split())
    gates[l] += 1
    gates[r + 1] -= 1

for i in range(n):
    gates[i + 1] += gates[i]

ans = 0
for i in range(n + 1):
    if gates[i] == m:
        ans += 1
print(ans)

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

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

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

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

ld dp[3010][3010];

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n;
  cin>>n;
  ld p[n];
  REP(i,n)cin>>p[i];
  
  REP(i,3010)REP(j,3010)dp[i][j]=0;
  dp[0][0]=1-p[0];
  dp[0][1]=p[0];
  
  REP1(i,n){
    dp[i][0] = dp[i-1][0]*(1-p[i]);
    REP1(j,n+1)
      dp[i][j]=dp[i-1][j]*(1-p[i])+dp[i-1][j-1]*p[i];
  }
  
  ld ans=0;
  for(ll i=n/2+1; i<=n; i++){
    ans += dp[n-1][i];
  }
  
  
  cout<<Decimal;
  cout<<ans<<endl;
}

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

int main(){
	int N,K,d;
	int Sn;
	cin >> N >> K;
	vector<int> S(N,1);
	int loop,loop2;
	for(loop=0;loop<K;loop++){
		cin >> d;
		for(loop2=0;loop2<d;loop2++){
			cin >> Sn;
			S[Sn-1] = 0;
		}
	}
	int ans;
	for(loop=0;loop<N;loop++){
		if(S[loop])
			ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3600
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define rep(i, s, n) for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t) for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...) \
    type __VA_ARGS__;  \
    read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
    return b > a && (a = b, true);
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
    return b < a && (a = b, true);
}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(
        sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail &... tail) {
    cin >> head;
    read(tail...);
}

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x) : x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

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

    var(int, N);
    vector<i64> a(N);
    read(a);

    sort(all(a), greater<>());

    dump(a);

    i64 ans = 0;
    {
        const i64 L = N / 2;
        const i64 H = N - L;

        auto itr = a.cbegin();
        i64 highSum = accumulate(itr, itr + H, 0LL) * 2;
        i64 lowSum = accumulate(itr + H, itr + N, 0LL) * 2;

        if (H == L) {
            highSum -= a[H - 1];
            lowSum -= a[H];
        } else {
            highSum -= a[H - 1];
            highSum -= a[H - 2];
        }

        dump(H, L, highSum, lowSum);
        chmax(ans, highSum - lowSum);
    }

    {
        const i64 H = N / 2;
        const i64 L = N - H;

        auto itr = a.cbegin();
        i64 highSum = accumulate(itr, itr + H, 0LL) * 2;
        i64 lowSum = accumulate(itr + H, itr + N, 0LL) * 2;

        if (H == L) {
            highSum -= a[H - 1];
            lowSum -= a[H];
        } else {
            lowSum -= a[H];
            lowSum -= a[H + 1];
        }

        dump(H, L, highSum, lowSum);
        chmax(ans, highSum - lowSum);
    }

    print(ans);
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int  ,int > pii;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll maxn  = 3e6;
const ll mod =1e9+7;
const ld PI = acos((ld)-1);

#define pb push_back
#define endl '\n'
#define dokme(x) return(cout << x , 0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ms(x , y) memset(x , y , sizeof x);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
ll pw(ll a, ll b, ll md = mod){ll res = 1;while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);}

int x;
string t;

int main(){
    migmig
    cin >> t;
    x = t.size();
    int n = 0 , s = 0 , e = 0 , w = 0;
    for(int i = 0 ; i < x ; i ++){
		if(t[i] == 'N')n++;
		if(t[i] == 'S')s++;
		if(t[i] == 'E')e++;
		if(t[i] == 'W')w++;
	} 
    if(n){
		if(!s)dokme("No");
	}
    
    if(s){
		if(!n)dokme("No");
	}
    
    if(e){
		if(!w)dokme("No");
	}
	
    if(w){
		if(!e)dokme("No");
	}
	cout << "Yes";
    return(0);
}

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

int N, M;
vector<string> S, T;

void abc091b() {
  map<string, int> mp;
  for (int i = 0; i < N; i++) {
    mp[S[i]]++;
  }
  for (int i = 0; i < M; i++) {
    mp[T[i]]--;
  }
  int ans = 0;
  for (auto p : mp) {
    ans = max(ans, p.second);
  }
  cout << ans << "\n";
  return;
}

int main() {
  cin >> N;
  S.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> S[i];
  }
  cin >> M;
  T.resize(M);
  for (int i = 0; i < M; i++) {
    cin >> T[i];
  }
  abc091b();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <limits>
#include <queue>
#include <iomanip>
#include <set>

template<typename T> bool chmax(T &a,T b){
    if(a<b){
        a=b;
        return true;
    }
    return false;
}

template<typename T> bool chmin(T &a,T b){
    if(a>b){
        a=b;
        return true;
    }
    return false;
}

using namespace std;
#define ALL(X) X.begin(),X.end()
using ll = long long int;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
const int MOD=1000000007;
//const int MOD=998244353;
const int INTMAX=1001001000;
const ll LLMAX=1010010010010010000;

bool comp(vll a,vll b){
    return a[0]<b[0];
}

bool comp2(vll a,vll b){
    return a[1]<b[1];
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll N;
    cin>>N;
    vvll X(N,vll(2));
    for(ll i=0;i<N;i++){
        cin>>X[i][0];
        X[i][1]=i;
    }
    
    sort(ALL(X),comp);
    
    ll a=X[N/2-1][0];
    ll b=X[N/2][0];
    
    for(ll i=0;i<N/2;i++){
        X[i][0]=0;
    }
    for(ll i=N/2;i<N;i++){
        X[i][0]=1;
    }
    
    sort(ALL(X),comp2);
    
    for(ll i=0;i<N;i++){
        if(X[i][0]==0)cout<<b<<endl;
        else cout<<a<<endl;
    }
    
    return 0;
}


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

int main() {
  string S;
  int Q;
  cin >> S >> Q;
  int T, F;
  char C;

  int rev = 0;
  for (int i = 0; i < Q; i++){
    cin >> T;
    if (T == 1){
      rev++;
    }
    if (T == 2){
      cin >> F >> C;
      if ((F + rev) % 2 == 1){
        S.insert(S.begin(), C);
      }
      else if ((F + rev) % 2 == 0){
        S.push_back(C);
      }
    }
  }
  
  if (rev % 2 == 1){
    reverse(S.begin(), S.end());
  }
  cout << S << endl;
}

Measured memory_bytes: 900
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
 
int main() {
  //int N; cin >> N;
  vector<int> v = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int K;cin >> K;
  cout << v.at(K-1) << endl;

}

Measured memory_bytes: 256
inf = float('inf')

n = int(input())
a = tuple(int(x) for x in input().split())

d = [[inf] * n for _ in range(n)]
for i in range(n):
    d[i][i] = 0

c = [0]
for aa in a:
    c.append(c[-1] + aa)

for i in range(n - 1, -1, -1):
    for j in range(i + 1, n):
        for k in range(i, j):
            # [i, k], (k, j]
            d[i][j] = min(d[i][j], d[i][k] + d[k + 1][j])
        d[i][j] += c[j + 1] - c[i]
# print(d)
# print(c)
print(d[0][n - 1])


Measured memory_bytes: 46556
#include <cstdio>
#include <cstring>

const int MAX_H = 100;
const int MAX_W = 100;

//?????\
int H, W;
char g[MAX_H][MAX_W + 1];

int d[4][2] = {{0, -1}, {0, 1}, {1, 0}, {-1, 0}};        //??????

//??±???????????????g[i][j]????±??±????
void dfs(int x, int y, int c){
    for(int i = 0; i < 4; i ++){
        int nx = x + d[i][0], ny = y + d[i][1];
        if(0 <= nx && nx < H && 0 <= ny && ny < W && g[nx][ny] == c){
            g[nx][ny] = '1';
            dfs(nx, ny, c);
        }
    }
}

void solve(){
    //????????????????????°????????°?????????????????\???????????°????????°???
    int ans = 0;
    for(int i = 0; i < H; i ++){
        for(int j = 0; j < W; j ++){
            if(g[i][j] != '1'){
                ans ++;
                char c = g[i][j];
                g[i][j] = '1';
                dfs(i, j, c);
            }
        }
    }
    printf("%d\n", ans);
}

int main(int argc, char const *argv[]){

    while(scanf("%d %d", &H, &W)){
        if(H == 0 && W == 0) break;
        for(int i = 0; i < H; i ++){
            scanf("%s", g[i]);
        }
        solve();
    }

    return 0;
}

Measured memory_bytes: 1504
def power(a, b, P):
	if b == 0:
		return 1
	elif b == 1:
		return a % P
	elif b % 2 == 0:
		return (power(a, b//2, P) ** 2) % P
	else:
		return (power(a, b//2, P) ** 2 * a) % P
 

N, P = (int(i) for i in input().split())
S = input()
l = [0]*N
ls = [0]*(N+1)
if P != 2 and P != 5:
    po = [1]*N
    for i in range(N-1):
        po[i+1] = (po[i]*10)%P
    d = [0]*P
    d[0] = 1
    b = 0
    for i in range(N):
        a = int(S[N-1-i]) * po[i]
        l[i] = a%P
        b += l[i]
        b %= P
        d[b] += 1
    ans = 0
    for a in d:
        ans += (a-1)*a//2
    print(ans)
else:
    ans = 0
    for i in range(N):
        if int(S[i]) % P == 0:
            ans += (i+1)
    print(ans)

Measured memory_bytes: 46172
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long cc;
static const cc MAX = 1000000;
cc i, j, N, Q, M, k, n = 0, A[MAX], B[MAX], p[MAX], x[MAX];
cc Ans=0, sub = 0, flag = 0;
string S, T;
char vec[10];

//vector<pair<cc, cc>>pairs(N);

int main() {	
	cin >> N >> M;
	for (i = 0; i <= N; i++) {
		for (j = 0; j <= N; j++) {
			sub = M - (i + j);
			if ((0 <= sub) && (sub <= N))
				Ans += 1;
		}
	}


	cout << Ans << endl;
	return 0;
}

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

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

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; }
const long long INF = 1LL << 60;
typedef pair<int, int> PR;

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define fr(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijo(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i <=n;i++){
    num*=yakusu[i];
  }
  return num;
}

//cout<<""<<endl;
int main(){
 int N;cin>>N;
  vl T(N),A(N);
  rep(i,N){
    cin>>T[i]>>A[i];
  }
  rep(i,N-1){
    if(A[i+1]<A[i]&&T[i+1]<T[i]){
      ll ti=max(  (T[i]+T[i+1]-1)/T[i+1]  , (A[i]+A[i+1]-1)/A[i+1] );      
      A[i+1]*=ti;
      T[i+1]*=ti;
    }
    else if(A[i+1]<A[i]){
      ll ti=(A[i]+A[i+1]-1)/A[i+1]; 
      A[i+1]*=ti;
      T[i+1]*=ti;
    }
    else if(T[i+1]<T[i]){
      ll ti=(T[i]+T[i+1]-1)/T[i+1]; 
      A[i+1]*=ti;
      T[i+1]*=ti;
    }
  }
 
  cout<<A[N-1]+T[N-1]<<endl;
  
}






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

int main()
{
  string s;
  cin >> s;
  int x = stoi(s);
  int fx = 0;
  for (int i = 0; i < s.size(); i++) fx += (int)(s.at(i) - '0');
  if(x % fx == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        String s = input.next();
        if(s.substring(0,Math.min(s.length(),4)).equals("YAKI")){
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <queue>
#include <utility>
using namespace std;
int h,w;
char c[50][50];
int d[50][50];
int num;
int X[4]={0,-1,0,1},Y[4]={-1,0,1,0};
int main(){
    cin>>h>>w;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>c[i][j];
            if(c[i][j]=='.')num++;
        }
    }
    d[0][0]=1;
    queue<pair<int,int>> que;
    que.push(make_pair(0,0));
    while(!que.empty()){
        pair<int,int> p=que.front();
        que.pop();
        int x=p.first,y=p.second;
        for(int i=0;i<4;i++){
            int nx=x+X[i],ny=y+Y[i];
            if(nx<0||h<=nx||ny<0||w<=ny||c[nx][ny]=='#'||d[nx][ny]!=0)continue;
            d[nx][ny]=d[x][y]+1;
            que.push(make_pair(nx,ny));
        }
    }
    if(d[h-1][w-1]==0)cout<<-1<<endl;
    else cout<<num-d[h-1][w-1]<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	static boolean isNumber(char val){
		try{
			Integer.parseInt(val+"");
			return true;
		}catch(NumberFormatException e){
			return false;
		}
	}
	static int henkan(String n){
		return Integer.parseInt(n);
	}
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		int sum=0;
		while(in.hasNext()){
			String input = in.nextLine();
			String memo="";
			boolean sw = false;
			for(int s=0;s<input.length();s++){
				if(isNumber(input.charAt(s))){
					memo+=input.charAt(s);
					sw=true;
				}else if(sw){
					sw=false;
					sum+=henkan(memo);
					memo="";
				}else{
					sw=false;
					memo="";
				}
			}
			if(sw)sum+=henkan(memo);
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 17632
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb emplace_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
#define dupli(a) a.erase(unique(all(a)),a.end())
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vvvvi=vector<vvvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const ll INF=1001001001;
const ll mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}
ll dp[3005][3005];
vi v;
ll n;
ll dfs(int i,int j){
    if(dp[i][j]!=inf)return dp[i][j];
    if(i>j)return 0;
    if((n+i+j)&1)dp[i][j]=max(dfs(i+1,j)+v[i],dfs(i,j-1)+v[j]);
    else dp[i][j]=min(dfs(i+1,j)-v[i],dfs(i,j-1)-v[j]);
    return dp[i][j];
}
int main(){
    cin>>n;
    v=vi(n);
    rep(i,n)cin>>v[i];
    rep(i,n)rep(j,n)dp[i][j]=inf;
    out(dfs(0,n-1));
}

Measured memory_bytes: 74072
import java.io.*;
public class Main {
    static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    public static void main(String[] args) throws IOException {
        int N = Integer.parseInt(in.readLine());
        double[][] dp = new double[N + 1][N + 1];
        dp[0][0] = 1;

        String[] s = in.readLine().split(" ");

        for (int i = 1; i <= N; i++) {
            double p = Double.parseDouble(s[i - 1]);
            dp[i][0] = dp[i - 1][0] * (1 - p);
            for (int j = 1; j <= N; j++) {
                dp[i][j] = dp[i - 1][j - 1] * p + dp[i - 1][j] * (1 - p);
            }
        }

        double ans = 0;
        for (int i = (N + 1) / 2; i <= N; i++) {
            ans += dp[N][i];
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 107584