akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<sstream>
#include<complex>
#include<functional>
#include<vector>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<set>

const int MOD = 1000000007;

using namespace std;



int main(){

    int i,k,x;
    cin >> k >> x;
    for(i=0;i<2*k-1;i++){
        cout << x-k+i+1;
        cout << ' ';
    }

    cout << endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    s = input()
    t = input()
    for i in range(N):
        ok = True
        for j in range(N-i):
            if s[i+j] != t[j]:
                ok = False
                break
        if ok:
            print(i+N)
            return
    print(2*N)


if __name__ == "__main__":
    main()


Measured memory_bytes: 38256
import java.io.BufferedInputStream;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc=new Scanner(new BufferedInputStream(System.in));
        String a=sc.next();
        String b=sc.next();
        int x=sc.nextInt();
        int y=sc.nextInt();
        String p=sc.next();
        if(p.equals(a))
            x--;
        if(p.equals(b))
            y--;
        System.out.println(x+" "+y);


    }
}


Measured memory_bytes: 23764
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

typedef long long ll;
typedef pair<ll,ll> P;

ll gcd(ll a, ll b){
	return b == 0 ? a : gcd(b, a % b);
}

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

	ll n;cin >> n;
	ll ans = 0;
	REP(i, n)REP(j, n)REP(k, n){
		ans += gcd(i + 1, gcd(j + 1, k + 1));
	}

	cout << ans << endl;

	return 0;
}


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

int gcd(int a, int b) {
	return (b == 0 ? a : gcd(b, a % b));
}
int main() {
	int N;
	cin >> N;
	vector<int> x(N + 1);
	for (int i = 0; i < N + 1; i++) cin >> x[i];
	sort(x.begin(), x.end());
	int ans = x[1] - x[0];
	for (int i = 2; i < N + 1; i++) ans = gcd(ans, x[i] - x[i - 1]);
	cout << ans << endl;
}

Measured memory_bytes: 640
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<class T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<class T>inline auto vec2(class vector<T>::size_type h,class vector<T>::size_type w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}
template<class RandomAccessIterator>inline void psortb(RandomAccessIterator first,RandomAccessIterator last){using P=pair<decltype(first->first),decltype(first->second)>;sort(first,last,[](const P&p1,const P&p2){return p1.second<p2.second||(p1.second==p2.second&&p1.first<p2.first);});}

int main()
{
    ll n=in(),k=in();
    vector<ll>p(n);for(ll i=0;i<n;++i)p[i]=in();
    sort(p.begin(),p.end());
    cout<<accumulate(p.begin(),p.begin()+k,0ll)<<endl;
}



Measured memory_bytes: 3600
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define ll long long
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define F first
#define S second
#define P pair
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define V vector
#define RE return
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB push_back
#define PF push_front
#define FILL(a,b) memset(a,b,sizeof(a))
using namespace std;
int n;
class bit{
	public:
	int s[500005];
	void up(int p,int x){
		while(p<=n){
			s[p]+=x;
			p+=p&-p;
		}
	}
	int get(int p){
		int re=0;
		while(p){
			re=re+s[p];
			p-=p&-p;
		}
		RE re;
	}
	void clear(){
		FILL(s,0);
	}
}tree[26];
char c[500005],t;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n;
	FOR(i,1,n){
		cin>>c[i];
		tree[c[i]-'a'].up(i,1);
	}
	int ans,x,y,q;
	cin>>q;
	FOR(i,1,q){
		cin>>x;
		if(x==1){
			cin>>x>>t;
			tree[c[x]-'a'].up(x,-1);
			tree[t-'a'].up(x,1);
			c[x]=t;
		}else{
			ans=0;
			cin>>x>>y;
			x--;
			rep(j,0,26){
				ans+=(tree[j].get(y)>tree[j].get(x));
			}
			cout<<ans<<'\n';
		}
	}
	RE 0;
}



Measured memory_bytes: 51584
#include <bits/stdc++.h>
#define ll long long
#define fastIO cout << fixed << setprecision(12), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
using namespace std;

const int MOD = 1e9 + 7, N = 4e5 + 9;
int pow2[N];

int add(ll a, int b) {
	a += b;
	while(a >= MOD) a -= MOD;
	while(a < 0) a += MOD;
	return a;
}

int sub(int a, int b) {
	return (a - b + MOD) % MOD;
}

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

int main() {
	fastIO;
#ifdef LOCAL
	freopen("input.in", "rt", stdin);
#endif
	pow2[0] = 1;
	for (int i = 1; i < N; ++i)
		pow2[i] = mul(pow2[i - 1], 2);
	int n, zeros = 0, a1 = 0, a2 = 0;
	map<pair<ll, ll>, int> mp;
	ll x, y;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> x >> y;
		if(x == 0 && y == 0) {
			++zeros;
			continue;
		} else if(x == 0) {
			++a2;
			continue;
		} else if(y == 0) {
			++a1;
			continue;
		}
		ll g = __gcd(x, y);
		x /= g, y /= g;
		if(y < 0)
			x = -x, y = abs(y);
		mp[{x, y}]++;
	}
	int ans = add(pow2[a1], pow2[a2]);
	ans = sub(ans, 1);
	for(auto &it: mp) {
		if(!it.second) continue;
		ll y = it.first.first;
		ll x = it.first.second;
		y = -y;
		
		ll cur = 0;
		if(mp.find({x, y}) != mp.end()) {
			cur = mp[{x, y}];
			mp[{x, y}] = 0;
		}
		ans = mul(ans, sub(add(pow2[cur], pow2[it.second]), 1));
		it.second = 0;
	}
	ans = sub(ans, 1);
	ans = add(ans, zeros);
	cout << ans;
	return 0;
}


Measured memory_bytes: 17644
import bisect

n = int(input())
a = list(map(int, input().split()))
total = sum(a)
cnt = [0] * (10 ** 5 + 1)  # cnt[i] i が現在何個あるか
for i in a:
    cnt[i] += 1
q = int(input())
for i in range(q):
    b, c = map(int, input().split())
    total += (c - b) * cnt[b]
    print(total)
    cnt[c] += cnt[b]
    cnt[b] = 0


Measured memory_bytes: 20948
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cmath>
#include <functional>
#include <queue>
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
using namespace std;
typedef long long ll;
//typedef unsigned long long ull;

const ll INF = 9223372036854775807;
const int inf = 2147483647;

int main() {
    int n,m;
    cin >> n >> m;
    vector<pair<int,int>> cd;
    vector<int> e;
    REP(i,m){
        int c,d;
        cin >> c >> d;
        cd.push_back(make_pair(d,c));
    }
    sort(cd.begin(),cd.end());
    REP(i,cd.size()){
        if(e.size()!=0){
            if(cd[i].second>e.back()){
                e.push_back(cd[i].first-1);
            }
        }else{
            e.push_back(cd[i].first-1);
        }
    }
    put(e.size());
    return 0;
}


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

int main() {
  char c;
  cin >> c ;
 vector <char> boin = {'a' ,'i' ,'u','e','o'};
 for ( int i = 0 ; i < 5 ; i++){
   if ( c == boin.at(i) ){
      cout << "vowel" << endl;
      break;
   }
   if( i == 4 ){
     cout << "consonant" << endl;
   }
  }
}



Measured memory_bytes: 256
inp = list(map(int, input().split()))
n = inp[0]
m = inp[1]

a = list(map(int, input().split()))
total = sum(a)

lim = total / (4 * m)
count = 0
flag = 0

for i in range(n):
    if a[i] >= lim:
        count += 1
    if count >= m:
        flag = 1
        break

if flag:
    print('Yes')
else:
    print('No')

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

using i64=int64_t;

#define rep(i,x,y) for(i64 i=i64(x),i##_max_for_repmacro=i64(y); i<i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
 
const int inf=1.01e9;
const i64 inf64=4.01e18;
const double eps=1e-9;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    i64 N;
    cin >> N;
    vector<i64> A(N);

    rep(i,0,N) cin >> A[i];

    if(A[0]!=0){
        cout << -1 << endl;
        return;
    }
    
    i64 ans=0;

    i64 h=0;
    for(int i=N-1; i>=0; --i){
        --h;
        if(h>A[i]){
            cout << -1 << endl;
            return;
        }
        if(h<A[i]){
            ans+=A[i];
            h=A[i];
        }
    }

    cout << ans << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 1792
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const long long infll = (long long) 1.01e18;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int maxn = 6005;
int n;
string s;
char tmp[maxn];

int read() {
  if (scanf("%d", &n) < 1) {
    return false;
  }
  scanf("%s", tmp);
  s = tmp;
  return true;
}

string ans;
int id[maxn];

void solve1(const string &t, const string curans) {
  for (int k = 0; k <= sz(t) / 2; k++) {
    string cur;
    int ca = 0, cb = 0;
    for (int i = 0; i < sz(t); i++) {
      if (t[i] == 'a') {
        if (ca >= k) {
          cur += t[i];
        }
        ca++;
      } else {
        if (cb >= k) {
          cur += t[i];
        }
        cb++;
      }
    }
    ans = max(ans, cur + curans);
  }
  {
    int ca = 0, cb = 0;
    for (int i = 0; i < sz(t); i++) {
      if (t[i] == 'a') {
        id[i] = ca;
        ca++;
      } else {
        id[i] = cb;
        cb++;
      }
    }
  }
  {
    string cur;
    for (int i = 0; i < sz(t);) {
      while (i < sz(t) && t[i] != 'a') {
        i++;
      }
      if (i >= sz(t)) {
        break;
      }
      int p = id[i];
      while (i < sz(t) && (t[i] != 'b' || id[i] != p)) {
        i++;
      }
      if (i >= sz(t)) {
        break;
      }
      cur += "ab";
    }
    ans = max(ans, cur + curans);
  }
}

void solve() {
  int bal = 0;
  ans = "";
  for (int i = 2 * n - 1, j = 2 * n; i >= 0; i--) {
    bal += (s[i] == 'a' ? 1 : -1);
    if (!bal) {
      string t = s.substr(i, j - i);
      solve1(t, ans);
      j = i;
    }
  }
  printf("%s\n", ans.c_str());
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


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

using namespace std;
using LL = long long;
using P = pair<int,int>;

int main(){
	int N, K;
	cin >> N >> K;
	vector<int> ans_prev(N);
	rep(i,N) cin >> ans_prev[i];
	vector<int> ans(N);
	rep(i,min(100,K)){
		rep(j,N) ans[j]=0;
		rep(j,N){
			int d=ans_prev[j];
			if(j-d>=0) ans[j-d]++;
			else ans[0]++;
			if(j+d+1<N) ans[j+d+1]--;
		}
		rep(j,N-1) ans[j+1]+=ans[j];
		rep(j,N) ans_prev[j]=ans[j];
	}
	rep(i,N-1) cout << ans[i] << " ";
	cout << ans[N-1] << endl;

	return 0;
}

Measured memory_bytes: 4796
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <functional>
using namespace std;
using Int = long long;
#define REP(i,n) for(int i=0;i<n;i++)
#define P(r) do{for(auto i:r){cout<<i<<' ';}cout<<'\n';}while(0)
int main()
{
    string s; cin >> s;
    s[5] = ' ';
    s[13] = ' ';
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let (Q, H, S, D): (i64, i64, i64, i64) = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap()
        )
    };
    let N: i64 = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };

    let C = {
        let mut C = vec![(8 * Q, 0), (4 * H, 1), (2 * S, 2), (D, 3)];
        C.sort();
        C
    };
    let (c, i) = C[0];
    let ans = if i == 3 {
        (N / 2) * c + (N % 2) * (C[1].0 / 2)
    } else {
        N * (c / 2)
    };

    println!("{}", ans);
}


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

#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPL(i,a,n) for(ll i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define SORTVG(v) sort(v.begin(),v.end(),greater<>())
#define SORTV(v) sort(v.begin(),v.end())
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define INF LLONG_MAX/2
#define int long long

typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> Vi;

template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}
template<class T> void YesNo(T& a) {if(a){cout << "Yes" << ENT;}else{cout << "No" << ENT;}}
template<class T> void YESNO(T& a) {if(a){cout << "YES" << ENT;}else{cout << "NO" << ENT;}}
template<class T> void AorB(T& a, string A,string B) {if(a){cout << A << ENT;}else{cout << B << ENT;}}

int atcoder(){
    int n,ans=0;
    cin>>n;
    Vi a(n),b(n),c(n);
    REP(i,0,n){
        cin>>a[i]>>b[i];
        c[i]=a[i]+b[i];
        ans-=b[i];
    }
    SORTVG(c);
    REP(i,0,n){
        if(i%2==0) ans+=c[i];
    }
    cout<<ans<<ENT;
    return 0;
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    atcoder();
    return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int R,G,B,N;
  cin >>R>>G>>B>>N;
  int ans=0;
  
 for(int i=0;i<=N;i++){
 for(int j=0;j<=N;j++){
   int a=N-(i*R+j*G);
   
   if(a%B==0){if(a>=0){ans++;}} 
 }
 }
  
  cout <<ans<<endl;
}

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

#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ii pair<int,int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<ii>

using namespace std;

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//#ifndef ONLINE_JUDGE
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	//#endif
	ll n,m;
	cin>>n>>m;
	vi a(n);
	for(int i=0;i<n;++i){
		cin>>a[i];
	}
	ll lcm = a[0];
	for(int i=1;i<n;++i){
		lcm = lcm/__gcd((ll)a[i],lcm)*(ll)a[i];
	}
	for(int i=0;i<n;++i){
		if(((lcm/2)-a[i]/2)%a[i]!=0){
			cout<<0<<endl;
			return 0;
		}
	}
	cout<<(m-(lcm/2)+lcm)/lcm<<endl;
	return 0;
}

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

using namespace std;

typedef pair<int, int> P;
typedef pair<P, int> PP;

int mas[222][222];

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

int cnt;

void bfs(int sx, int sy, int st)
{
  queue<PP> que;
  que.push(PP(P(sx, sy), st));
  while(!que.empty()){
    PP p = que.front(); que.pop();
    int x = p.first.first, y = p.first.second, t = p.second;
    if(t < 0 || mas[x][y]++) continue;
    cnt++;
    for(int i = 0; i < 6; i++){
      int nx = x + dx[i], ny = y + dy[i];
      que.push(PP(P(nx, ny), t-1));
    }
  }
}

int main()
{
  int t, n;
  while(cin >> t >> n, t || n){
    memset(mas, 0, sizeof(mas));
    for(int i = 0; i < n; i++){
      int x, y;
      cin >> x >> y;
      x += 111; y += 111;
      mas[x][y] = 1;
    }
    int sx, sy;
    cin >> sx >> sy;
    sx += 111; sy += 111;
    cnt = 0;
    bfs(sx, sy, t);
    cout << cnt << endl;
  }
  return 0;
}

Measured memory_bytes: 1432
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;


int main() {
    
    int n,k;
    cin>>n>>k;
    vi v(n);
    rep(i,n)cin>>v[i];
    vi dp(n+10,INF);
    dp[0]=0;
    rep(i,n){
        rep(j,k){
            chmin(dp[i+j+1],dp[i]+abs(v[i+j+1]-v[i]));
        }
    }
    fin(dp[n-1]);
}


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

int main() {
    int n;
    cin >> n;
    int a, b, c;
    cin >> a >> b >> c;
    vector<vector<int>> dp(n, vector<int>(3));
    dp[0][0] = max(a, b);
    dp[0][1] = max(b, c);
    dp[0][2] = max(c, a);
    for (int i = 1; i < n; ++i) {
        cin >> a >> b >> c;
        // can optimize redundant addition but pretty trivial
        dp[i][0] = max(a + dp[i-1][1], b + dp[i-1][2]);
        dp[i][1] = max(b + dp[i-1][2], c + dp[i-1][0]);
        dp[i][2] = max(c + dp[i-1][0], a + dp[i-1][1]);
    }
    cout << max(max(dp[n-1][0], dp[n-1][1]), dp[n-1][2]) << endl;

    return 0;
}

Measured memory_bytes: 5760
s = gets.chomp

len = s.length
flg = true
len.times do |i|
  if i % 2 == 0
    #奇数
    if s[i] != 'R' && s[i] != 'U' && s[i] != 'D'
      flg = false
    end
  else
    #偶数
    if s[i] != 'L' && s[i] != 'U' && s[i] != 'D'
      flg = false
    end
  end
end

if flg
  puts "Yes"
else
  puts "No"
end

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define forn(i, a, n) for (int i = a; i < n; ++i)
#define ford(i, a, n) for (int i = n - 1; i >= a; --i)
#define fore(i, a, n) for (int i = a; i <= n; ++i)
#define all(a) (a).begin(), (a).end()
#define fs first
#define sn second
#define trace(a)\
    for (auto i : a) cerr << i << ' ';\
    cerr << '\n'
#define eb emplace_back

#ifndef M_PI
const ld M_PI = acos(-1.0);
#endif

const ld eps = 1e-9;
const int INF = 2000000000;
const ll LINF = 1ll * INF * INF;
const ll MOD = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, c, k;
    cin >> n >> c >> k;
    vector<int> t(n);
    forn(i, 0, n) cin >> t[i];
    sort(all(t));
    int ans = 0;
    int i = 0;
    while (i < n) {
        int t0 = t[i] + k;
        int i0 = i;
        while (i < n && t[i] <= t0 && i - i0 + 1 <= c) ++i;
        ++ans;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,X;
  cin>>N>>X;
  int count=1;
  int sum=0;
  vector<int>L(N);
  for(int i=0;i<N;i++){
    cin>>L.at(i);
    sum=sum+L.at(i);
    if(sum<=X){
      count=count+1;
    }
    else{
      break;
    }
  }
  cout<<count<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
typedef long long int ll;

int main(void){
    ll x,y;
    scanf("%lld%lld", &x,&y);

    ll tmp = x;
    ll cnt = 0;
    while(tmp <= y){
        cnt += 1;
        tmp *= 2;
    }

    printf("%lld\n", cnt);
    return 0;
}

Measured memory_bytes: 128
use io::*;
use std::*;

fn solve(N: i64) {
    let change = if (N % 1000 != 0) {
        1000 - (N % 1000)
    } else {
        0
    };
    println!("{}", change);
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
fn main() {
    let con = read_string();
    let mut scanner = Scanner::new(&con);
    let mut N: i64;
    N = scanner.next();
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(move || solve(N)).unwrap().join().unwrap();
}

pub mod io {
    use std;
    use std::str::FromStr;

    pub struct Scanner<'a> {
        iter: std::str::SplitWhitespace<'a>,
    }

    impl<'a> Scanner<'a> {
        pub fn new(s: &'a str) -> Scanner<'a> {
            Scanner {
                iter: s.split_whitespace(),
            }
        }

        pub fn next<T: FromStr>(&mut self) -> T {
            let s = self.iter.next().unwrap();
            if let Ok(v) = s.parse::<T>() {
                v
            } else {
                panic!("Parse error")
            }
        }

        pub fn next_vec_len<T: FromStr>(&mut self) -> Vec<T> {
            let n: usize = self.next();
            self.next_vec(n)
        }

        pub fn next_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.next()).collect()
        }
    }

    pub fn read_string() -> String {
        use std::io::Read;

        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }

    pub fn read_line() -> String {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_owned()
    }
}


Measured memory_bytes: 2224
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

ll mod = ((ll) (1e9+7));
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N;
  cin >> N;
  ll a[N],b[N];
  rep(i,N) cin >> a[i];
  rep(i,N) cin >> b[i];
  pair<ll, ll> h[2*N];//(座標), PC:0 cable:1
  rep(i,N){
    h[i] = mp(a[i], 0);
  }
  rep(i,N){
    h[i+N] = mp(b[i], 1);
  }
  sort(h, h+2*N);
  ll count=0; //pc+ cable-
  //  ll sum=0;
  ll ans=1LL;
  rep(i,2*N){
    if(h[i].second==0){
      count++;
      if(count <=0){
	ans = (ans* abs(count-1))%mod;
      }
    }else{
      count--;
      if(count>=0){
	ans = (ans* abs(count+1))%mod;
      }
    }
  }
  cout << ans << endl;
  return 0;
    

}


Measured memory_bytes: 4992
using System;

namespace A___Buttons
{
    class Program
    {
        static void Main(string[] args)
        {
            var read = Console.ReadLine().Split(' ');
            var A = int.Parse(read[0]);
            var B = int.Parse(read[1]);

            if(A==B)
            {
                Console.WriteLine(A*2);
            }else{
                var large = Math.Max(A,B);
                Console.WriteLine(large+(large-1));
            }
                
        }
    }
}


Measured memory_bytes: 11092
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder_20190707_1
{
    class Program
    {
        static void Main(string[] args)
        {
            int town = int.Parse(Console.ReadLine());
            double[][] place = new double[town][];

            for(int i = 0; i < town; i++)
            {
                place[i] = new double[2];
                string[] s = Console.ReadLine().Split(' ');
                place[i][0] = double.Parse(s[0]);
                place[i][1] = double.Parse(s[1]);
            }

            double distance = 0;

            for(int i = 0; i < town; i++)
            {
                for(int j = 0; j < town; j++)
                {
                    distance += Math.Sqrt(Math.Pow(place[i][0] - place[j][0],2) + Math.Pow(place[i][1] - place[j][1],2));
                }
            }

            Console.Write(distance / town);

            Console.ReadLine();
        }
    }
}

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

int main(){
	int n, taro=0, hanako=0;
	string T, H;
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> T >> H;
		if(T == H){
			taro++; hanako++;
		}
		else if(T < H) hanako += 3;
		else taro += 3;
	}
	cout << taro << " " << hanako << endl;
	return 0;
}

Measured memory_bytes: 1208
#include<iostream>
#include<vector>
#include<bits/stdc++.h>
#define lli long long int
#define mod 1000000007
#define pb push_back
#define mk make_pair
#define fastio ios_base::sync_with_stdio(false); cout.tie(NULL);
using namespace std;

lli par[200001],sz[200001];

lli find(lli a)
{
	if(par[a]<0)
		return a;
	return par[a]=find(par[a]);
}

void Union(lli a,lli b)
{
	par[b]=a;
	sz[a]+=sz[b];
}

int main()
{
	fastio;
	lli n,m,i,j,a,b,one=0,ans=0;
	map<lli,lli> mp;
	cin>>n>>m;
	for(i=1;i<=n;i++)
		par[i]=-1, sz[i]=1;
	for(i=0;i<m;i++)
	{
		cin>>a>>b;
		a=find(a);
		b=find(b);
		if(a!=b)
			Union(a,b);
	}
	for(i=1;i<=n;i++)
	{
		if(par[i]==-1 && sz[i]>1)
			ans=max(ans,sz[i]);
		if(sz[i]==1)
			one++;
	}
	if(one==n)
		cout<<1;
	else
		cout<<ans;	
	return 0;
}


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

void t(int roma[], char str[]);
int len;

int main(void)
{
	char str[1005];
	int roma[1005];
	int ans, i, j;
	
	while (scanf("%s", str) != EOF){
		
		t(roma, str);
		i = len - 2;
		j = roma[i + 1];
		ans = roma[i + 1];
		
		while (0 <= i){
			if (roma[i] < j){
				ans -= roma[i];
			}
			else {
				ans += roma[i];
				j = roma[i];
			}
			i--;
		}
		printf("%d\n", ans);
	}
	
	return (0);
}

void t(int roma[], char str[])
{
	int i;
	
	len = strlen(str);
	
	for (i = 0; i < len; i++){
		
		if (str[i] == 'I'){
			roma[i] = 1;
		}
		else if (str[i] == 'V'){
			roma[i] = 5;
		}
		else if (str[i] == 'X'){
			roma[i] = 10;
		}
		else if (str[i] == 'L'){
			roma[i] = 50;
		}
		else if (str[i] == 'C'){
			roma[i] = 100;
		}
		else if (str[i] == 'D'){
			roma[i] = 500;
		}
		else if (str[i] == 'M'){
			roma[i] = 1000;
		}
	}
}

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

void solve()
{
    long long t,n,m,i,j,k=0,kk=0,x,y,z=0,mn=0,mx,a[10],cnt=0;
    map < ll , ll > mp,mp1;
    vector < ll > v;
    set < ll > st;

    cin >> n;

    for(i=0;i<n;i++)
    {
        cin >> x;
        v.push_back(x);
        st.insert(x);
        mp[x]++;
    }

    for(auto it=mp.begin();it!=mp.end();it++)
    {
        x = it->first;
        y = it->second;
        cnt+=(y*(y-1))/2;
    }

    for(auto x : st)
    {
        mp1[x]=cnt-mp[x]+1;
    }

    for(i=0;i<n;i++)
    {
        cout << mp1[v[i]] << endl;
    }

}

int main()
{
     long long t,n,m,i,j,k=0,kk=0,x,y,z=0,mn,mx;

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

     //cin >> t;

     //while(t--)
     solve();

}


Measured memory_bytes: 24944
#include <stdio.h>

int main() {
    int n;
    int a;
    scanf("%d",&n);
    for (int i = 0; i < n; i++) {
        scanf("%d ", &a);
        if (a % 2 == 1) {
            ;
        }
        else if (a % 2 == 0 && (a % 5 == 0 || a % 3 == 0)) {
            ;
        }
        else {
            printf("DENIED\n");
            return 0;
        }
    }
    printf("APPROVED\n");
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>

int main()
{
	int h1, m1, h2, m2, k;
	scanf("%d %d %d %d %d", &h1, &m1, &h2, &m2, &k);
	
	int hr = h2 - h1;
	int min = m2 - m1;
	int res = hr * 60 + min - k;
	printf("%d", res);		
	
	return 0;
}

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

using namespace std;

int cnt[100010], sum[100010];
int n;
char str[100010];
int main()
{
    scanf("%d", &n);
    scanf("%s", str);

    memset(sum, 0, sizeof(sum));
    for(int i=0; i<n; i++)
    {
        sum[str[i]-'a']++;
    }

    int ans = 0;
    memset(cnt, 0, sizeof(cnt));
    for(int i=0; i<n-1; i++)
    {
        cnt[str[i]-'a']++;
        int temp = 0;
        for(int j=0; j<26; j++)
        {
            if (cnt[j] != 0 && cnt[j] != sum[j]) temp++;
        }
        ans = max(ans, temp);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1024
N = int(input())
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())
ABCDE = [A,B,C,D,E]

min_abcde = min(ABCDE)

if N % min_abcde == 0:
    X = N // min_abcde
else:
    X = (N // min_abcde) + 1

print(X+4)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i,  n) for (int i  =  0; i < (int)(n); ++i)
#define REPR(i,  n) for (int i  =  n - 1; i >= 0; --i)
using namespace std;
#define int long long int
//------------ATCODER TEMPLATE-------------

signed main() {
  string S; cin >> S;
  if (S.back() == 's') cout << S + "es" << endl;
  else                 cout << S + "s" << endl;
  return 0;
}


Measured memory_bytes: 3628
//#define _GLIBCXX_DEBUG
    #include <iostream>
    #include <bits/stdc++.h>
     
     
    using namespace std;
    #define ll long long
    #define ld long double
    #define  P pair<ll,ll>
    #define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
    #define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
    #define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
    #define sortAl(v) sort(v.begin(),v.end())
    #define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
    #define cout(n) cout<<fixed<<setprecision(n)
     
    int main(){
        cin.tie(0);
        ios::sync_with_stdio(false);
        ll a,b,t;
        cin>>a>>b>>t;
        cout<<(t/a)*b<<endl;
    }

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

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;

#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()
#define vprint(v) for(auto e:v){cout<<e<<" ";};cout<<endl;
#define vvprint(vv) for(auto v:vv)vprint(v);

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

    ll N, Q;
    cin >> N >> Q;

    auto comp = [](vll& l, vll& r){
        if(l[0]>r[0]) return true;
        else if(l[0]==r[0] && l[2]>r[2]) return true;
        else return false;
    };
    priority_queue<vll, vvll, decltype(comp)> exq(comp);

    rep(i, N){
        ll s, t, x;
        cin >> s >> t >> x;
        exq.push({s-x, x, 1});
        exq.push({t-x, x, -1});
    }

    priority_queue<vll, vvll, decltype(comp)> dq(comp);
    rep(i, Q){
        ll d;
        cin >> d;
        dq.push({d, i});
    }

    multiset<ll> sx;
    vll ans(Q);

    while(!dq.empty()){
        auto dv = dq.top();
        ll d = dv[0], idx = dv[1];
        dq.pop();
        while(!exq.empty()){
            auto exv = exq.top();
            ll e = exv[0], x = exv[1], etype = exv[2];
            if(e<=d){
                if(etype==1) sx.insert(x);
                else sx.erase(x);
                exq.pop();
            }
            else break;
        }
        if(sx.size()==0){
            ans[idx] = -1;
        }
        else{
            ll x = *sx.begin();
            ans[idx] = x;
        }
    }

    rep(i, Q) cout << ans[i] << endl;
}


Measured memory_bytes: 46928
#include <iostream>
#include <algorithm>
#include <string.h>
#include <vector>

using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned ll
#define db double
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PII pair<int, int>

int n,a,k;

int gcd(int a,int b) {
	return b==0?a:gcd(b,a%b);
}

int main() {
	scanf("%d%d",&n,&k);
    int num;
	int mx;
	scanf("%d",&num);
	mx=num;
	for (int i=1;i<n;i++) {
		scanf("%d",&a);
		mx=max(mx,a);
		num=gcd(num,a);
	}
	if (k%num==0&&mx>=k) printf("POSSIBLE\n");
	else printf("IMPOSSIBLE\n");
}


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

#define rep(i, n) for (int i = 0; i < (int) (n); i++)
#define Rrep(i,n) for(int i=((int)n-1); i>=0; i--)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define INF 2e15
#define MOD 10e9+7

typedef vector<int> vint;
typedef long long ll;



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

        int n;
        cin>>n;
        ll d;
        cin>>d;

        int cnt=0;

        rep(i,n){
                ll tmp1,tmp2;
                cin>>tmp1>>tmp2;
                ll tmp3=tmp1*tmp1;
                ll tmp4=tmp2*tmp2;
                ll tmp5=d*d;
                if(tmp3+tmp4<=tmp5){
                        cnt++;
                }
        }
        cout<<cnt<<endl;

        return 0;
}


Measured memory_bytes: 3612
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
#include <set>
using namespace std;

static vector<int32_t> memo;
static int32_t dp(int32_t rest)
{
	if (rest < 1)
		return 0;
	if (memo[rest] > -1)
		return memo[rest];

	int32_t res = dp(rest - 1) + 1;

	int32_t six_power = 6;
	while (rest >= six_power) {
		res = min(res, dp(rest - six_power) + 1);
		six_power *= 6;
	}

	int32_t nine_power = 9;
	while (rest >= nine_power) {
		res = min(res, dp(rest - nine_power) + 1);
		nine_power *= 9;
	}

	memo[rest] = res;
	return memo[rest];
}

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

	memo.resize(N + 1);
	fill(memo.begin(), memo.end(), -1);
	cout << dp(N) << endl;

	return 0;
}


Measured memory_bytes: 5376
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n,a,b = f()
    x = f()
    dp = [0]*n
    for i in range(1,n):
        dp[i] = min(dp[i-1]+a * (x[i] - x[i-1]), dp[i-1]+b)
    
    print(dp[n-1])
    

solve()


Measured memory_bytes: 14480
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repe(i, n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
const int INF = 1e9;
const ll mod = 1000000007;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b / gcd(a,b);}

int main() {
    int d;
    cin >> d;
    if (d == 25) {
        cout << "Christmas" << "\n";
    }
    if (d == 24) {
        cout << "Christmas Eve" << "\n";
    }
    if (d == 23 ) {
        cout << "Christmas Eve Eve" << "\n";
    }
    if (d == 22) {
        cout << "Christmas Eve Eve Eve" << "\n";
    }
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
	long long N,A,B;			//N,number, A:min, B:max
	long long n;

	scanf("%lld %lld %lld",&N,&A,&B);

	n = (B-A)*(N-2)+1; //(A+B+(N-2)*B) - (A+B+(N-2)*A) + 1;
	if(A>B) n = 0;
	if(A != B && N == 1) n = 0;
	printf("%lld\n",n);

	return 0;
}


Measured memory_bytes: 128
p ('1'..$_).inject (a=[1,2,3])[0]{|s|x=Hash[*"N1E6W2S3R5L7".split("")][gets[0]].to_i;a[x/3],a[x%3]=a[x%3],7-a[x/3];s+a[0]}while'0'<gets.chop!

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

int cost(vector<int> &x, int p) {
  int res = 0;
  for (auto i : x) {
    res += (i - p) * (i - p);
  }
  return res;
}
int main() {
  int n;
  cin >> n;
  vector<int> x(n);
  for (int i = 0; i < n; i++)
    cin >> x[i];
  int m = 1 << 29;
  for (int i = 1; i <= 100; i++) {
    m = min(m, cost(x, i));
  }
  cout << m << endl;
}


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

int bs(vector<int> &arr, int l,int r,int x){
	int ans = -1;
	while(l <= r){
		int m = (l + r) / 2;
		if(arr[m] <= x){
			ans = m;
      l = m + 1;
		}
		else{
			r = m - 1;
		}
	}
	return ans;
}

int main() {
	int l, r, d;
	cin >> l >> r >> d;
	
	vector<int>cr;
	for(int i = l; i <= r;i++){
		cr.push_back(i);
	}
	int cnt = 0;
	for(int t = 1; t < 100000; t++){
		if(t * d > r){
			break;
		} 
		else if (bs(cr, 0, (cr.size() - 1), t * d) != -1){
			cnt++;
		}
	}
	cout << cnt << endl;
	return 0; 
}

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

//
#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0, sizeof(x))
#define mm(x) memset((x), -1, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#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 UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define bit(n) (1LL << (n))
#define bitset(a, b) (a) |= (1 << (b))
#define bitunset(a, b) (a) |= ~(1 << (b))
#define bitcheck(a, b) ((((a) >> (b)) & 1) == 1)
#define bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
const int INF = (int)1e18;
const int MOD = (int)1e9 + 7;
const double EPS = (double)1e-10;
const int dx[] = { -1, 0, 0, 1, 0, -1, -1, 1, 1 };
const int dy[] = { 0, -1, 1, 0, 0, 1, -1, 1, -1 };

//
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
//
inline int toInt(string s) {
	int v;
	istringstream sin(s);
	sin >> v;
	return v;
}
template <class T>
inline string toString(T x) {
	ostringstream sout;
	sout << x;
	return sout.str();
}

//
struct Accelerate_Cin {
	Accelerate_Cin() {
		cin.tie(0);
		ios::sync_with_stdio(0);
		cout << fixed << setprecision(20);
	};
};

int H, W; 
string s[410];
int x = 0, y = 0;//xが黒yが白
bool visited[410][410];
void dfs(int Y,int X) {
	if (visited[Y][X]==true)return;
	visited[Y][X] = true;
	for (int k = 0; k < 4; ++k) {
		int ny = Y + dy[k], nx = X + dx[k];
		if (ny >= H || ny < 0 || nx >= W || nx < 0 || visited[ny][nx] || s[ny][nx] == s[Y][X])continue;
		dfs(ny, nx);
	}
	if (s[Y][X] == '#') {
		x++;
	}
	else {
		y++;
	}
	return;
}
signed main() {
	cin >> H >> W;
	for (int i = 0; i < H; ++i)cin >> s[i];
	int ans = 0;
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			dfs(i, j);
			ans += x * y;
			x = 0;
			y = 0;
		}
	}
	cout << ans << endl;
	return 0;
}


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

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

  int n;
  cin >> n;
  int sum = 0;
  vector<int> a(n);
  for (auto& x : a) cin >> x, sum += x;

  double avg = 1.0 * sum / n;

  int ans = 0;
  for (int i = 1; i < n; ++i)
    if (abs(avg - a[i]) < abs(avg - a[ans])) ans = i;
  cout << ans;
}

Measured memory_bytes: 256
#include<stdio.h>
#include <string.h>
int main()
{
	int x,y,xa,ya,i=0;
	scanf("%d %d",&x,&y);
	
	if(x>0 && y>0){
		xa=x;
		ya=y;
		
		if(xa>ya){
			i=2+xa-ya;
		}else if(xa<ya){
			i=ya-xa;
		}else{
			i=0;
		}
	}else if(x<0 && y>0){
		xa=-1*x;
		ya=y;
		if(xa>ya){
			i=xa-ya+1;
		}else if(xa<ya){
			i=1+ya-xa;
		}else{
			i=1;
		}
	}else if(x<0 && y<0){
		xa=-1*x;
		ya=-1*y;
		if(xa>ya){
			i=xa-ya;
		}else if(xa<ya){
			i=ya-xa+2;
		}else{
			i=0;
		}
	}else if(x>0 && y<0){
		xa=x;
		ya=-1*y;
		if(xa>ya){
			i=1+xa-ya;
		}else if(xa<ya){
			i=ya-xa+1;
		}else{
			i=1;
		}
	}else if(x==0 && y<0){
		i=-1*y+1;
	}else if(x==0 && y>0){
		i=y;
	}else if(x<0 && y==0){
		i=-1*x;
	}else if(x>0 && y==0){
		i=x+1;
	}
		
	
	printf("%d\n",i);
	
	
	return 0;
}


Measured memory_bytes: 128
n = int(input())
r = []
for i in range(n):
    x, l = map(int, input().split())
    r.append((x - l, x + l))
r.sort(key=lambda _x: _x[1])
cnt = 1
limit = r[0][1]
for ri in r[1:]:
    if ri[0] >= limit:
        cnt += 1
        limit = ri[1]
print(cnt)

Measured memory_bytes: 18260
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define f first
#define s second
#define pb push_back
signed main()
{
   int n,m,x;
   cin>>n>>m>>x;
   int a[n][m];
   int cost[n];
   for(int i=0;i<n;i++)
   {
       cin>>cost[i];
       for(int j=0;j<m;j++)
        cin>>a[i][j];
   }
   vector<int>ans;


   for(int i=0;i<(1ll<<n);i++)
   {
       vector<int>v;
       int arr[m]={0};
       for(int j=0;j<n;j++)
       {
           if(i&(1<<j))
           {
              v.pb(j);
           }
       }
       int c=0;


    for(int j=0;j<v.size();j++)
       {
           for(int k=0;k<m;k++)
            arr[k]+=a[v[j]][k];
            c+=cost[v[j]];
       }


       bool flag=true;
       for(int j=0;j<m;j++)
       {
           if(arr[j]<x)
           {
               flag=false;
               break;
           }
       }
       if(flag)
        ans.pb(c);

   }
   if(ans.size()==0)
    cout<<-1<<endl;
   else
   {
      int r=*min_element(ans.begin(),ans.end());
    cout<<r<<endl;
   }

}


Measured memory_bytes: 3656
a = int(input())
b = int(input())
c = int(input())
x = int(input())

ans = 0
for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      if 500*i + 100*j + 50*k == x:
        ans += 1
print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<string> 
#include<map>
#include<set>
#include<vector>
#include<string.h> 
#include<math.h>
#include<stdio.h> 
#include<queue>
using namespace std; 
int main()
{string s;
cin>>s;
for(int i=0;i<s.size();i+=2)
cout<<s[i];
system("pause");
return 0;
}

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

using namespace std;

#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define cl(x,v) memset((x), (v), sizeof(x))
#define db(x) cerr << #x << " == " << x << endl
#define dbs(x) cerr << x << endl
#define _ << ", " <<

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<int, pii> piii;
typedef pair<ll,ll> pll;
typedef pair<ll, pll> plll;
typedef vector<int> vi;
typedef vector <vi> vii;

const ld EPS = 1e-9, PI = acos(-1.);
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f, MOD = 1e9+7;
const int N = 1e3+5;
int h,w;
ll memo[N][N];
char a[N][N];

int dp(int i, int j){
    //cout << "i: " << i << " j: " << j << "\n";
    //if(i<1 or j<1) return 0;
    if(i == 1 and j == 1) return memo[i][j] = 1;
    if(~memo[i][j]) return memo[i][j];
    else{
        ll left = 0, top = 0;
        if(a[i][j-1] == '.') left = dp(i,j-1);
        if(a[i-1][j] == '.') top = dp(i-1,j);
        return memo[i][j] = ((left + top) % MOD);
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    memset(memo,-1,sizeof(memo));
    for(int i=0;i<N;i++) a[0][i] = a[i][0] = '#';
    cin >> h >> w;
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            cin >> a[i][j];
        }
    }
    ll ans = dp(h,w);
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 9216
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
typedef long long ll;
const ll inf = 1e18;
int main(){
    int n; cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    sort(ALL(a));
    
    ll x,y,z;
    x = a[n-1];
    y = inf;
    z = inf;
    rep(i,n-1){
        ll d = abs(x - 2*a[i]);
        if(d < z){
            z = d;
            y = a[i];
        }
    }
    cout << x << " " << y << endl;
}

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

#define     Boost               ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define     all(cont)           cont.begin(),cont.end()
#define     rall(cont)          cont.rbegin(),cont.rend()
#define     foreach(cont)       for(auto &value: cont)
#define     show(val)           cout<< #val << " -> " << val << endl
#define     flush               cin.ignore(numeric_limits<streamsize>::max(), '\n')
#define     Case                cout<< "Case "<< ++cs << ": "
#define     mk                  make_pair
#define     pb                  push_back
#define     ff                  first
#define     ss                  second

typedef     long long                   ll ;
typedef     unsigned long long          ull ;
typedef     pair <int, int>             pii ;

const ll INF = (1LL<<60)-1 ;


char func(char a,char b){
    if(a > b) swap(a,b) ;
    if(a=='B' && b=='G') return 'R' ;
    else if(a=='B' && b=='R') return 'G' ;
    else if(a=='G' && b=='R') return 'B' ;
}

//#define DEBUG
int main()
{
    Boost;

    #ifdef DEBUG
    freopen("input.txt","r",stdin);    // Read
    freopen("output.txt","w",stdout);  // Write
    #endif

    int n ;
    string str ;
    cin>> n >> str ;
    
    vector<int> r(n),g(n),b(n) ;
    if(str[n-1] == 'R') r[n-1] = 1 ;
    else if(str[n-1] == 'G') g[n-1] = 1 ;
    else if(str[n-1] == 'B') b[n-1] = 1 ;
    for(int i=n-2; i>=0; i--){
        r[i] = r[i+1] ;
        g[i] = g[i+1] ;
        b[i] = b[i+1] ;
        if(str[i] == 'R') r[i]++;
        else if(str[i] == 'G') g[i]++ ;
        else if(str[i] == 'B') b[i]++ ;
    }
    
    ll sum = 0 ;
    for(int i=0; i<n; i++){
        ll temp = 0;
        for(int j=i+1; j<n; j++){
            if(str[i] == str[j]) continue ;
            char ch = func(str[i],str[j]) ;
            if(ch == 'R') temp += r[j] ;
            else if(ch == 'G') temp += g[j] ;
            else if(ch == 'B') temp += b[j] ;
            int diff = j-i ;
            if(j+diff <n && str[j+diff] == ch) temp-- ;
        }
        sum += temp ;
    }
    
    cout<< sum << endl ;

    return 0;
}




Measured memory_bytes: 3672
def getN():
    return int(input())

def getMN():
    return list(map(int, input().split()))

def getlist():
    return list(map(int, input().split()))
import sys

n = getN()
nums = getlist()
nums.sort()

from bisect import bisect_left
insert = bisect_left(nums, 0)


if insert == 0:
    print(sum(nums) - 2 * nums[0])
    tmp = nums[0]
    for num in nums[1:-1]:
        print(tmp, num)
        tmp = tmp - num
    print(nums[-1], tmp)
    sys.exit()

if insert == len(nums):
    nums.sort(reverse=True)
    print(abs(sum(nums)) + 2 * nums[0])
    tmp = nums[0]
    for num in nums[1:]:
        print(tmp, num)
        tmp = tmp - num
    sys.exit()

neg = nums[:insert]
pos = nums[insert:]
neg_end = neg[0]
pos_end = pos[-1]
print(abs(sum(neg)) + sum(pos))
for ne in neg[1:]:
    print(pos_end, ne)
    pos_end -= ne

for po in pos[:-1]:
    print(neg_end, po)
    neg_end -= po

print(pos_end, neg_end)




"""
5
8 9 -2 -3 10
"""


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

int main() {
  int a;
  int b;
  int c;
  cin >> a;
  cin >> b;
  cin >> c;
  
  if ((b * 10 + c) % 4 == 0) {
    cout << "YES" << endl;
  }
  
  else {
    cout << "NO" << endl;
  }
}



Measured memory_bytes: 256