akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

int main(void){
	int r;
	cin >> r;
	cout << ((r<1200)?"ABC":((r<2800)?"ARC":"AGC")) << endl;
	return 0;
}


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

using namespace std;


int main(){
    while(true){
        int N,A,B,C,X;
        cin >> N >> A >> B >> C >> X;

        if(N==0) break;
        vector<int> Y(N);
        for(int j=0;j<N;j++) cin >> Y[j];

        int ind = 0;
        int s=0;
        for(int i=0;i<10002;i++){
            if(Y[ind] == X){
                ind++;
            }
            s = i;
            if(ind == Y.size()){
                break;
            }
            X = (A*X+B) % C;
        }
        if(s == 10001) cout << -1 << endl;
        else cout << s << endl;
    }
}

Measured memory_bytes: 1196
#include<bits/stdc++.h>
#define    ll      long long int
#define    Fori(a,b) for (ll i = a ; i<b ;i++ )
#define    Forj(a,b) for (ll j = a ; j<b ;j++ )
#define    Fork(a,b) for (ll k = a ; k<b ;k++ )
#define    W       while
#define    pb      push_back
#define    nl      cout<<endl
#define    mod     1000000007
#define    I       cin>>
#define    Out     cout<<
#define    DOD(i)  cout<<setprecision(i)<<fixed<<
#define    XXX     return 0
#define    Fast    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
using namespace std;
int main()
{
   Fast;
   ll r;I r;
    double pi=22.0/7;
    DOD(5) 2*pi*r;
   XXX;
}




Measured memory_bytes: 3772
def main():
    s = input()
    t = input()
    chk_dir = {}
    for i in range(len(s)):
        if not(s[i] in chk_dir.keys()):
            if (t[i] in chk_dir.values()):
                return print("No")
            else:
                chk_dir[s[i]] = t[i]
        elif chk_dir[s[i]] != t[i]:
            return print("No")

    print("Yes")

if __name__ == "__main__":
    main()

Measured memory_bytes: 3632
#include<stdio.h>
#include<stdlib.h>
int main(){
    int x,a,b;
    scanf("%d%d%d",&x,&a,&b);
    int disa = abs(a-x),disb = abs(b-x);
    if(disa<disb)printf("A\n");
    else printf("B\n");
}

Measured memory_bytes: 128
import itertools
import math

n = int(input())
P = [list(map(int,input().split())) for i in range(n)]

distance = []

for p in itertools.permutations(range(n)):
    for i in range(1,n):
        distance.append( ((P[p[i]][0]-P[p[i-1]][0])**2+(P[p[i]][1]-P[p[i-1]][1])**2)**(1/2) )

print(sum(distance)/math.factorial(n))

Measured memory_bytes: 60656
unittest
{
	assert( [ "5 2", "2 4 5 1 3", "3 4 -10 -8 8" ].solve == 8 );
	assert( [ "2 3", "2 1", "10 -7" ].solve == 13 );
	assert( [ "3 3", "3 1 2", "-1000 -2000 -3000" ].solve == -1000 );
	assert( [ "10 58", "9 1 6 7 8 4 3 2 10 5", "695279662 988782657 -119067776 382975538 -151885171 -177220596 -169777795 37619092 389386780 980092719" ].solve == 29507023469 );

	assert( [ "3 1", "2 3 1", "-1 -2 -3" ].solve == -1 );		// 追加ケース
}



import std.algorithm;
import std.conv;
import std.format;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = 0L;
	auto k = 0L;
	input.front.formattedRead!"%s %s"( n, k );
	input.popFront;
	auto ps = input.front.split.to!( long[] );
	ps[] -= 1;
	input.popFront;
	auto cs = input.front.split.to!( long[] );
	
	// １ループの長さと合計スコアを計算
	auto lls = new long[ n ];
	auto lts = new long[ n ];
	{
		auto gs = new long[ n ];
		gs[] = -1;
		foreach( s, ref ll, ref lt, ref g; lockstep( lls, lts, gs ) )
		{
			if( g < 0 )
			{
				for( auto p = ps[ s ]; gs[ p ] < 0; p = ps[ p ] )
				{
					ll++;
					lt += cs[ p ];
					gs[ p ] = s;
				}
			}
			else
			{
				lt = lts[ g ];
				ll = lls[ g ];
			}
		}
	}
	
	// スコアの最大値を計算
	auto ans = long.min;
	foreach( s, ll, lt; lockstep( lls, lts ) )
	{
		auto lc = k / ll;
		auto lr = k % ll;
		
		if( 0 < lc ) ans = max( ans, lt * lc );
		for( auto i = 1L, p = ps[ s ], t = 0L; i <= k && p != s; i++, p = ps[ p ] )
		{
			t += cs[ p ];
			ans = max( ans, t, t + lt * ( lc - ( lr < i ) ) );
		}
	}
	return ans;
}


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

int main(){
    int i,j,k;
    int H,W;

    cin >> H >> W;

    string pic[H];

    for(i=0;i<H;i++){
        cin >> pic[i];
    }

    for(i=0;i<W+2;i++)cout << '#';
    cout << endl;

    for(i=0;i<H;i++){
        for(j=0;j<W+2;j++){

            if(j == 0){
                cout << '#';
                continue;
            }
            if(j == W+1){
                cout << '#';
                cout << endl;
                continue;
            }

            cout << pic[i][j-1];

        }
    }

    for(i=0;i<W+2;i++)cout << '#';
    cout << endl;

}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace ABC105
{
    class C
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());

            var ans = "";
            if (N == 0) ans = "0";
            while (N != 0)
            {
                if (N % 2 != 0)
                {
                    N--;
                    ans = "1" + ans;
                }
                else
                {
                    ans = "0" + ans;
                }
                N /= -2;
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13140
import sys

nx = input().split()
n = int(nx[0])
x = int(nx[1])
count = 0


lenlist = []
for i in range(n + 1):
    if i == 0:
        lenlist.append(1)
    else:
        lenlist.append(lenlist[-1] * 2 + 3)

pcountlist = []
for i in range(n + 1):
    if i == 0:
        pcountlist.append(1)
    else:
        pcountlist.append(pcountlist[-1] * 2 + 1)


def incr_count(nn, xx):
    global count

    if nn == 0:
        if xx > 0:
            count += 1
        return

    if xx <= 1:
        pass
    if 1 < xx and xx <= lenlist[nn] // 2:
        incr_count(nn - 1, xx - 1)
    if lenlist[nn] // 2 < xx:
        count += pcountlist[nn - 1]
        count += 1
        incr_count(nn - 1, xx - lenlist[nn] // 2 - 1)


incr_count(n, x)
print(count)


Measured memory_bytes: 3064
s=input()
t=input()
ans=[]
for i in range(len(s)-len(t)+1):
  cnt=0
  for j in range(len(t)):
    if (s[i+j]==t[j]) or (s[i+j]=='?'):
      if j==len(t)-1:
        ss=s[:i]+t+s[i+j+1:]
        if ss.count('?')>0:
          ss=ss.replace('?','a')
        ans.append(ss)
      else:
        pass
    else:
      break
if ans!=[]:
  print(min(ans))
else:
  print('UNRESTORABLE')

Measured memory_bytes: 3064
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	scan := bufio.NewScanner(os.Stdin)
	var in []int
	scan.Scan()
	scan.Scan()
	for _, v := range strings.Split(scan.Text(), " ") {
		i, _ := strconv.Atoi(v)
		in = append(in, i)
	}

	insertionSort2(in)

}

func insertionSort(in []int)  {
	trace(in)
	// 遍历序列
	for i := 1; i < len(in); i++ {
		// 从序列开头寻找比待插入元素大的元素
		for j := 0; j < i; j++ {
			if in[i] < in[j] {
				v := in[i]
				// 向后移动元素
				for k := i - 1; k >= j; k-- {
					in[k+1] = in[k]
				}
				// 插入
				in[j] = v
			}
		}
		trace(in)
	}
}

func insertionSort2(in []int)  {
	trace(in)
	// 遍历序列
	for i := 1; i < len(in); i++ {
		v := in[i]
		j := i - 1
		for j >= 0 && in[j] > v {
			in[j+1] = in[j]
			j--
		}
		in[j+1] = v
		trace(in)
	}
}

func trace(in []int) {
	if len(in) > 0 {
		fmt.Print(in[0])
		for _, i := range in[1:] {
			fmt.Print(" ", i)
		}
	}

	fmt.Println("")
}


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

int main() {
  
    int K;
    int A[32] = { 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 };
 
    cin >> K;
    
    cout << A[K-1] << endl;
    return 0;

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		for (int i=0;i<3;i++) {
			if(s.charAt(i)=='1') System.out.print(9);
			else if (s.charAt(i)=='9') System.out.print(1);
			else System.out.print(s.charAt(i));
		}

	}
}


Measured memory_bytes: 22740
import math

a, v = map(int, input().split(" "))
b, w = map(int, input().split(" "))
t = int(input())

if w >= v:
    print("NO")
    exit()

fast = abs(v - w)
dist = abs(b - a)

if fast * t >= dist:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 9188
#include<iostream>
#include<vector>
#include<queue>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<cstring>
#include<iomanip>
#include<set>
using namespace std;

typedef long long ll;
typedef pair<int,int> P;
#define INF 1000000100
#define rep(i,n) for (int i=0;i<n;i++)

int main(){
    int N,M,K;
    cin >> N >> M >> K;
    int a[N], b[M];
    rep(i,N) cin >> a[i];
    rep(i,M) cin >> b[i];

    ll A[N+1], B[M+1];
    A[0]=B[0]=0;
    for(int i=1;i<=N;i++){
        A[i]=A[i-1]+a[i-1];
    }
    for(int j=1;j<=M;j++){
        B[j]=B[j-1]+b[j-1];
    }

    int j=M;
    int ans=0;
    rep(i,N+1){
        if(A[i]>K) break;
        while(B[j]>K-A[i]) j--;
        ans = max(ans, i+j);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 7864
// Palindromic Numbers
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
    int A, B;
    int count = 0;
    cin >> A >> B;
    for (int i = A; i <= B; ++i) {
        int a, b, c, d;
        a = i % 10;
        b = i / 10 % 10;
        c = i / 1000 % 10;
        d = i / 10000 % 10;
        if (a == d && b == c) ++count;
    }
    cout << count <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
#include <iterator> 
#include <map>
#include <queue>
#include <set>
#define rep(i,n) for(int i=0;i<(n); ++i)
#define log(i,n) log(n)/log(i);
using namespace std;
typedef long long ll;


int main()
{
	ll x, y, z, k;
	cin >> x >> y >> z >> k;
	vector<ll>a(x), b(y), c(z), ab;
	rep(i, x)cin >> a[i];
	rep(i, y)cin >> b[i];
	rep(i, z)cin >> c[i];

	for (ll i = 0; i < x; i++) {
		for (ll k = 0; k < y; k++) {
			ab.push_back(a[i]+b[k]);
		}
	}

	sort(ab.begin(), ab.end());
	reverse(ab.begin(), ab.end());
	vector<ll>abc;

	for (ll i = 0; i < min((ll)3000, x * y); i++) {
		for (ll k = 0; k < z; k++) {
			abc.push_back(ab[i]+c[k]);
		}
	}
	
	sort(abc.begin(), abc.end());
	reverse(abc.begin(), abc.end());

	rep(i, k)cout << abc[i] << endl;
}



Measured memory_bytes: 43368
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {
 
  public static void main(String[] args) throws IOException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    String readStr;
    int[] numPatternCount = new int[19];
    int i, j, k, l;
    int size = 9;
    int sum;
    for (i = 0; i <= size; i++)
      for (j = 0; j <= size; j++)
        for (k = 0; k <= size; k++)
          for (l = 0; l <= size; l++) {
            sum = i + j + k + l;
            if (sum > 18)
              break;
            numPatternCount[sum]++;
          }
    
    while ((readStr = reader.readLine()) != null) {
      int n = Integer.parseInt(readStr);
      System.out.println(
              n > 36 ? 0 :
                      numPatternCount[n > 18 ? numPatternCount.length - (n - numPatternCount.length) - 2 : n]
      );
    }
  }
 
}

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

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;
const long long MOD = (long long)1e9 + 7;

int main(){
    int k;
    cin >> k;
    queue<ll> q;
    for(int i = 1; i < 10; i++){
        q.push(i);
    }
    for(int i = 0; i < k - 1; i++){
        ll t = q.front();
        q.pop();
        ll u = t * 10 + (t % 10);
        if(u % 10 != 0){ q.push(u - 1); }
        q.push(u);
        if(u % 10 != 9){ q.push(u + 1); }
    }
    ll ans = q.front();
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define rep(i, s, N) for(ll i{s}; i < N; i++)
#define rem(i, N, s) for(ll i{N}; i > s; i--)
using namespace std;using ll = long long int;using ld = long double;using P = pair<ll,ll>;const int MOD = (int)1e9+7;const string rt = "\n";const string sp = " ";/* 最大公約数 */template<typename T> T gcd(T a, T b){return b != 0 ? gcd(b, a % b) : a;}/* UnionFind */template<typename T> struct UnionFind{vector<T> par;UnionFind(T n) : par(n, -1){}void init(T n){par.assign(n, -1);}T root(T x){if (par[x] < 0) return x;else return par[x] = root(par[x]);}bool issame(T x, T y){return root(x) == root(y);}bool merge(T x, T y){x = root(x); y = root(y);if(x == y) return false;if(par[x] > par[y]) swap(x, y);par[x] += par[y];par[y] = x;return true;}int size(int x) {return -par[root(x)];}};/* コンビネーション */template<typename T> ll combpm(T N_, T C_) {const int NUM_=400001;static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];if (fact[0]==0) {inv[1]=fact[0]=factr[0]=1;for (int i=2;i<=NUM_;++i) inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%MOD, factr[i]=factr[i-1]*inv[i]%MOD;}if(C_<0 || C_>N_) return 0;return factr[C_]*fact[N_]%MOD*factr[N_-C_]%MOD;}/* 多次元ベクター */template<class T>vector<T> mvec(size_t a){return vector<T>(a);}template<class T, class... Ts>auto mvec(size_t a, Ts... ts){return vector<decltype(mvec<T>(ts...))>(a, mvec<T>(ts...));}/* テスト関数 */void test(ll n){cout << "test" << n << endl;}/* 小数点以下 */void fixsp(ll n){cout << fixed << setprecision(n);}void defsp(ll n){cout << defaultfloat << setprecision(n);}/* 重み付きUnionFind */struct WUnionFind {vector<int> par;vector<int> rank;WUnionFind(int n = 1) {init(n);}void init(int n = 1) {par.resize(n); rank.resize(n);for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0;}int root(int x) {if (par[x] == x) {return x;}else {int r = root(par[x]);return par[x] = r;}}bool issame(int x, int y) {return root(x) == root(y);}bool merge(int x, int y) {x = root(x); y = root(y);if (x == y) return false;if (rank[x] < rank[y]) swap(x, y);if (rank[x] == rank[y]) ++rank[x];par[y] = x;return true;}};/* IO高速化 */void fastio(){ios::sync_with_stdio(false);cin.tie(NULL);}
/* ここからコード開始 */

int main(){
  fastio;
  ll N, T;
  cin >> N >> T;
  ll ans{MOD}, minimum{MOD};
  rep(i, 0, N){
    ll c{}, t;
    cin >> c >> t;
    if(t <= T){
      ans = min(ans,c);
      minimum = t;
    }
  }
  if(ans == MOD) cout << "TLE" << rt;
  else cout << ans << rt;
}

Measured memory_bytes: 256
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
#define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }
typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

lint readL(){
  lint res;
#ifdef ONLINE_JUDGE
  scanf("%I64d",&res);
#else
  scanf("%lld",&res);
#endif
  return res;
}
void printL(lint res){
#ifdef ONLINE_JUDGE
  printf("%I64d",res);
#else
  printf("%lld",res);
#endif
}

//const int INF=5e8;

int n,m,K;
lint ar[100005];

lint dp[305][100005];

int dq[100005],s,t;
int main(){
  cin>>n>>m>>K;
  REP(i,n) cin>>ar[i];

  memset(dp,-1,sizeof(dp));
  REP(i,n) dp[1][i]=ar[i];
  REPN(i,K,1){
    s=t=0;
    REP(j,n){
      while(s<t && j-dq[s]>m) ++s;
      if(s<t) chmax(dp[i+1][j],dp[i][dq[s]]+ar[j]*(i+1));
      if(dp[i][j]==-1) continue;
      while(s<t && dp[i][dq[t-1]]<=dp[i][j]) --t;
      dq[t++]=j;
    }
  }
  lint res=-1;
  REP(i,n+1) chmax(res,dp[K][i]);
  cout<<res<<endl;
  return 0;
}





Measured memory_bytes: 239488
num = [int(input()) for _ in range(5)]
num2 = [n if n % 10 == 0 else n - (n%10) + 10  for n in num]

c = []
for i, j  in enumerate(num):
    n = j
    for k,l in enumerate(num2):
        if  k == i:
            continue
        else:
            n += l
    c.append(n)

print(int(min(c)))

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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define ALL(v) v.begin(),v.end()
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cout<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<int, int> P;
struct Edge{ll from, to, cost;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

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

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}

ll frac[100100];
ll fracinv[100100];

void gen_frac(){
  frac[0]=1;
  fracinv[0]=modinv(frac[0], MOD);
  rep(i, 100010){
    frac[i+1]=mod(frac[i]*(i+1), MOD);
    fracinv[i+1]=modinv(frac[i+1], MOD);
  }
}

ll comb(ll n,ll k){
  ll tmp = frac[n];
  tmp = mod(tmp * fracinv[k], MOD);
  tmp = mod(tmp * fracinv[n - k], MOD);
  return tmp;
}

/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll N, K;
  cin >> N >> K;
  llvec A(N, 0);
  gen_frac();
  rep(i, N) cin >> A[i];
  sort(ALL(A));

  ll ans = 0;
  rep(i, N){
    if(N - i >= K-1){
      ans = mod(ans - mod(A[i]*comb(N-1-i, K-1), MOD), MOD);
    }
    if(i>=K-1){
      ans = mod(ans + mod(A[i] * comb(i, K-1), MOD), MOD);
    }
  }

  cout << ans;
  
  
  return 0;
}


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

int main()
{
    ll a,res;
    cin>>a;
    res=a+(a*a)+(a*a*a);
    cout<<res<<endl;





    return 0;
}


Measured memory_bytes: 3592
#AtCoder

import sys
import math
import itertools

N = int(input())
A = list(map(int, input().split()))
all = 1
for n in range(N):
	all = all*A[n]

sum = 0
for n in range(N):
	sum += all/A[n]

print(all/sum)


"""

"""


Measured memory_bytes: 3060
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
const ll MOD = 1e9+7;
long long modpow(long long a, long long n) {
  long long res = 1;
  while (n > 0) {
      if (n & 1) res = res * a % MOD;
      a = a * a % MOD;
      n >>= 1;
  }
  return res;
}
int main(){
    ll n;
    ll a[100010];
    std::cin >> n;
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }
    sort(a,a+n);
    if(n%2==1){
        if(a[0] == 0){
            for (int i = 0; i < n/2; i++) {;
                if ( a[i*2+1] == a[i*2+2] && a[i*2+1] == 2*(i+1) ){
                    continue;
                }else{
                    std::cout << 0 << std::endl;
                    return 0;
                }
            }
            std::cout << modpow(2,n/2) << std::endl;
            return 0;
        }else{
            std::cout << 0 << std::endl;
            return 0;
        }
    }else{
        for (int i = 0; i < n/2; i++) {
            if ( a[i*2] == a[i*2+1] && a[i*2] == 2*(i)+1 ){
                continue;
            }else{
                std::cout << 0 << std::endl;
                return 0;
            }
        }
        std::cout << modpow(2,n/2) << std::endl;
        return 0;
    }
}

Measured memory_bytes: 1024
for i in range(int(input())):
    s=input()
    t=input()
    a=[0]
    for i in s:
        for j in range(len(a)-1,-1,-1):
            b=t.find(i,a[j])+1
            if b:
                if j+1<len(a):
                    a[j+1]=min(a[j+1],b)
                else:
                    a.append(b)
    print(len(a)-1)


Measured memory_bytes: 5616
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int row_cout	=	sc.nextInt();
		int column_cout	=	sc.nextInt();

		int[][]	matrix			=	new int[row_cout][column_cout];
		int[]	vector			=	new int[column_cout];
		int[]	multiplication	=	new int[row_cout];

		for(int row = 0; row < row_cout; row++) {
			for(int column = 0; column < column_cout; column++) {
				matrix[row][column] = sc.nextInt();
			}
		}

		for(int column = 0; column < column_cout; column++) {
			vector[column] = sc.nextInt();
		}
		sc.close();

		for(int row = 0; row < row_cout; row++) {
			for(int column = 0; column < column_cout; column++) {
				multiplication[row] = multiplication[row] + (matrix[row][column] * vector[column]);
			}
		}

		for(int row = 0; row < row_cout; row++) {
			System.out.println(multiplication[row]);
		}
	}
}


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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

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

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}


void solve()
{
  // ll n, k; cin >> n >> k;
  // ll x, y, z; cin >> x >> y >> z;
  ll a, b; cin >> a;
  string s; cin >> s;
  // vector<ll> a(n); rep(i, n) cin >> a[i];
  b = (s[0]-'0') * 100 + (s[2]-'0')*10 + (s[3]-'0');
  
  ll ans = 0;
  // bool ok = false;
  ans = a * b;
  cout <<( ans / 100) << endl;
  // cout << (ok?"Yes":"No") << endl;
}


int main(void)
{
  // ll t; cin >> t; REP(i, t)
  solve();
}


Measured memory_bytes: 3632
#include<stdio.h>
int main(){
 
    int a,b,i;
    char op;
 
    for(i=1; ;i++){
 
    scanf("%d %c %d", &a, &op, &b);
 
    if(op=='?')break;
 
    if(op=='+'){
    printf("%d\n",a+b);
    }
 
    if(op=='-'){
    printf("%d\n",a-b);
    }
    if(op=='*'){
    printf("%d\n",a*b);
    }
    if(op=='/'){
    printf("%d\n",a/b);
    }
 
    }
 
    return 0;
 
}

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

int main()
{
ll k ;
cin >> k ;
vector<ll> a(k);
rep(i, k){
  cin >> a[k-1-i];
}
if(a[0]!=2){
cout << -1 << endl;
return 0;
}
ll mx=3,mi=2;
rep(i,k-1){
  if((mi+a[i+1]-1)/a[i+1] *a[i+1]>mx){
    cout << -1 << endl;
    return 0;
  }
  mi=(mi+a[i+1]-1)/a[i+1] *a[i+1];
  mx=mx/a[i+1] *a[i+1]+a[i+1]-1;
}

cout << mi << " " << mx << endl;
return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define PRECISION std::cout << std::fixed << std::setprecision(20);
  
using namespace std;
 
const ll inf = 2e9;
const ll N = 1e5+100;
const ll bits = 20;
const ll mod = 1e9+7;
const ld pi = 3.14159265358979323846;


int main(){
    FASTIO;
    PRECISION;

	int arr[10] = {0};
	
	int temp;
	
	for(int i=0;i<3;i++){
		cin>>temp;
		arr[temp]++;
	}
	
	int two=0,one=0;
	
	for(int i=1;i<=9;++i){
		if(arr[i]==2){
			two=1;
		}
		if(arr[i]==1){
			one =1;
		}
	}
	
	if(two&&one){
		cout<<"Yes\n";
	}else{
		cout<<"No\n";
	}

}

Measured memory_bytes: 256
h,w = map(int,input().split())
M = []
for i in range(h):
    M.append(input())
L = []
R = []
U = []
D = []
Total = []
for i in range(h):
    s = [0]*w
    L.append(s)
for i in range(h):
    s = [0]*w
    R.append(s)
for i in range(h):
    s = [0]*w
    U.append(s)
for i in range(h):
    s = [0]*w
    D.append(s)
for i in range(h):
    s = [0]*w
    Total.append(s)
for i in range(h):
    for j in range(w):
        if M[i][j] == '.':
            if j == 0:
                L[i][j] = 1
            else:
                L[i][j] = L[i][j-1]+1
for i in range(h):
    for j in range(w-1,-1,-1):
        if M[i][j] == '.':
            if j == w-1:
                R[i][j] = 1
            else:
                R[i][j] = R[i][j+1]+1
for i in range(h):
    for j in range(w):
        if M[i][j] == '.':
            if i == 0:
                U[i][j] = 1
            else:
                U[i][j] = U[i-1][j]+1
for i in range(h-1,-1,-1):
    for j in range(w):
        if M[i][j] == '.':
            if i == h-1:
                D[i][j] = 1
            else:
                D[i][j] = D[i+1][j]+1
for i in range(h):
    for j in range(w):
        Total[i][j] += L[i][j]+R[i][j]+U[i][j]+D[i][j]-3
ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans,Total[i][j])
print(ans)

Measured memory_bytes: 211844
import numpy as np
import math
n,d = map(int,input().split())
a = []
for i in range(n):
    a.append([x for x in map(int,input().split())])

a = np.array(a)
ctn = 0
for i in range(0,n-1):
    for j in range(i+1,n):
        if np.sqrt(np.sum((a[i]-a[j])**2)) % 1 == 0:
            ctn +=1

print(ctn)

Measured memory_bytes: 19612
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
long long int mod = (long long int)1000000007;
using namespace std;

void solve()
{
    ll i,j,k,n;
    std::cout.precision(10);
    
  string s;
  cin>>s;
  n=s.size();
  int yes=1;
  int l=0,r=n-1;
  while(l<r)
  {
   	if(s[l]!=s[r])
    {
     	yes=0; 
    }
    l++;
    r--;
  }
  l=0;
  r=(n-1)/2-1;
  while(l<r)
  {
   	if(s[l]!=s[r])
    {
     	yes=0; 
    }
    l++;
    r--;
  }
  l=(n+3)/2-1;
  r=(n-1);
while(l<r)
  {
   	if(s[l]!=s[r])
    {
     	yes=0; 
    }
    l++;
    r--;
  }
  if(yes==1)
  {
   cout<<"Yes"; 
  }
  else
  {
	cout<<"No";
  }
  
}

int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    int i,j,k;
    int t;
    std::cout.precision(10);
    t=1;
    while(t--)
    {
        solve();
        cout<<"\n";
    }
}

Measured memory_bytes: 3644
import Control.Monad

goodIDs' :: [[Integer]] -> [[Integer]]
goodIDs' [] = []
goodIDs' ([i,p,q]:xs) = do
    let m = p * q
    let ixs = [ [i2 , p2 , q2] | [i2 , p2 , q2] <- xs , i2 == i]
    let rest= [ [i3 , p3 , q3] | [i3 , p3 , q3] <- xs , i3 /= i]
    foldr (\ [_,p10,q10] [i11,m11] -> [i11,m11 + p10 * q10]) [i,m] ixs : goodIDs' rest

goodIDs :: [[Integer]] -> [Integer]
goodIDs = map head . filter (\ [_,m] -> m >= 1000000) . goodIDs'

printResult :: [Integer] -> IO ()
printResult [] = putStrLn "NA"
printResult xs = mapM_ print xs

solve :: Int -> IO ()
solve n = replicateM n getLine
    >>= return . map (map read) . map words
    >>= printResult . goodIDs
    
main :: IO ()
main  = readLn
    >>= (\ n -> if n == 0 then return () else solve n >> main)

Measured memory_bytes: 5492
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define INF INT_MAX
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
#define sec second
#define fir first
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
typedef vector<int> Vec;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};



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

	int n, k;
	cin >> n >> k;
	int ans = 0;
	for(int b = 1; b <= n; b++) {
		int p = n / b;
		int r = n % b;
		ans += p * (max(b - k, 0LL));
		if(!k) ans--;
		ans += max(r + 1 - k, 0LL);
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

#define DUMP(x) std::cerr << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define IMP cout << "IMPOSSIBLE" << endl
#define Imp cout << "Impossible" << endl
#define imp cout << "impossible" << endl
#define M1 cout << "-1" << endl
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

template <typename T>
ostream &operator<<(ostream &os, vector<T> &v)
{
    os << "{";
    rep(i, v.size()) os << v[i] << (i == (int)v.size() - 1 ? "" : ", ");
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &p)
{
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }
struct in
{
    const size_t n = 0;
    in() = default;
    in(size_t n) : n(n){};
    template <typename T>
    operator T()
    {
        T ret;
        cin >> ret;
        return ret;
    }
    template <typename T>
    operator vector<T>()
    {
        assert(n != 0);
        vector<T> ret(n);
        for (auto &x : ret)
            cin >> x;
        return ret;
    }
};

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using vpint = vector<pint>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

void Main()
{
    vvint a(3, vint(3));
    rep(i, 3) rep(j, 3) cin >> a[i][j];

    int n = in();

    vint b = in(n);
    setint st;
    rep(i, n) st.insert(b[i]);

    vvint c(3, vint(3, 0));
    rep(i, 3) rep(j, 3)
    {
        bool ok = true;
        rep(k, n)
        {
            if (st.count(a[i][j]) == 0)
                ok = false;
        }
        if (ok)
            c[i][j] = 1;
    }

    bool ans = false;
    rep(i, 3)
    {
        bool yoko = true;
        bool tate = true;
        rep(j, 3)
        {
            if (!c[i][j])
                yoko = false;
            if (!c[j][i])
                tate = false;
        }
        ans |= yoko || tate;
    }
    bool n1 = true;
    bool n2 = true;
    rep(i, 3)
    {
        if (!c[i][i])
            n1 = false;
        if (!c[2 - i][i])
            n2 = false;
    }
    ans |= n1 || n2;

    if (ans)
        Yes;
    else
        No;
}

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


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>
#include <stdio.h>
#include <queue>
#include <cmath>
#include <utility>
#include <map>
#include <functional>

using namespace std;
typedef long long ll;
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)




int main() {
	int i;
	ll N;
	cin >> N;
	int n = (int)sqrt(N);
	for (i = n; i >= 1; --i) {
		if (N % i == 0) {
			cout << (int)log10(N / i) +1 << endl;
			return 0;
		}
	}

	return 0;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int a[1000],b[1000],leng=0;
int f(){
    int i,j;
    for(i=1;i<=leng;i++)
    if(b[a[i]]>0)return 1;
    return 0;
}
int main(){
    int i,j,l;
    long long k,n,m;
    cin>>k>>n;
    for(i=1;i<=n;i++)cin>>l,b[l]++;
    m=k;
    while(m>0){
        a[++leng]=m%10;
        m/=10;
    }
    while(f()){
        int s1=f(); 
        a[s1]++;
        k++;
        while(a[s1]>=10)a[s1]=0,s1++,a[s1]++;
        leng=max(leng,s1);
    }
    cout<<k<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int a,b,c,d;
    cin >> a >> b >> c;
    if (a >= b && a >= c){
        if(b >= c){
            d = (a - b) + (b - c);
        }
        else{
            d = (a - c) + (c - b);
        }
    }
    if (b >= a && b >= c){
        if(a >= c){
            d = (b - a) + (a - c);
        }
        else{
            d = (b - c) + (c - a);
        }
    }
    if (c >= b && c >= a){
        if(a >= b){
            d = (c - a) + (a - b);
        }
        else{
            d = (c - b) + (b - a);
        }
    }
    cout << d;
    return 0;
}


Measured memory_bytes: 256
from collections import defaultdict
from itertools import product, groupby
from math import pi
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = 10 ** 10
MOD = 1000000007


def main():
    N = int(input())
    S1 = input()
    S2 = input()

    pre_is_v = S1[0] == S2[0]
    ans = 3 if pre_is_v else 6
    i = 1 if pre_is_v else 2
    while i < N:
        is_v = S1[i] == S2[i]
        if pre_is_v and not is_v:
            ans = (ans * 2) % MOD
        elif pre_is_v and is_v:
            ans = (ans * 2) % MOD
        elif not pre_is_v and not is_v:
            ans = (ans * 3) % MOD

        pre_is_v = is_v
        i += 1 if is_v else 2

    print(ans % MOD)

if __name__ == '__main__':
    main()


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

int n,m;
int ans=0;
vector<vector<int>>s(12);
vector<int>k(12);
vector<bool>on(12,false);
vector<int>p(12);

void cal(void){
  for(int i=0;i<m;i++){
    int counter=0;
    for(int j=0;j<k.at(i);j++){
        if(on.at(s.at(i).at(j)-1)){
          counter++;
        }
    }
    if(counter%2!=p.at(i)){
      return;
    }
  }
  ans++;
}

void dfs(int d){
  if(d==n){
    cal();
    return;
  }
  on.at(d)=false;dfs(d+1);
  on.at(d)=true;dfs(d+1);
}

int main() {
  cin >>n>>m;
  for(int i=0;i<n;i++){
    int z;
    cin>>k.at(i);
    for(int j=0;j<k.at(i);j++){
      cin>>z;
      s.at(i).push_back(z);
    }
  }
  for(int i=0;i<m;i++){
    cin>> p.at(i);
  }
  dfs(0);
  cout <<ans;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, K: int, S: str):
    S_list = list(S)
    S_list[K-1] = S_list[K-1].lower()
    S = ''.join(S_list)
    print(S)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, K, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include<stdio.h>
int main(){

  int n,x,i,j,k,count;

  while(1){
    count=0;
    scanf("%d%d",&n,&x);
    if(n == 0 && x == 0)break;


    for(i=1;i<=n;i++){
      for(j=i+1;j<=n;j++){
	for(k=j+1;k<=n;k++){

	  if(i+j+k==x){
	    count++;
	  }

	}
      }
    }
      printf("%d\n",count);
  }
  return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h> 
#define LL long long
#define clr(x,i) memset(x,i,sizeof(x))
using namespace std;
const int N=5005;
string s,ans;
vector<int> v[27];
int n,K,sum[27];
set<string> S;
int main()
{
	ios::sync_with_stdio(0);
	cin>>s>>K; n=s.size();
	int ch=26;
	for(int i=0;i<n;i++){
		string x;
		for(int j=0;j<5&&i+j<n;j++)
		  x.push_back(s[i+j]),S.insert(x);
	}
	int k=0;
	for(set<string>::iterator it=S.begin();it!=S.end();it++){
		k++;
		if(k==K){
			cout<<*it<<endl;
			break;
		}
	}
	return 0;
}



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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  if ( abs(c-a) <= d ) {
    cout << "Yes" << endl;
  }
  else if ( abs(b-a) <= d && abs(c-b) <= d) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
import java.util.Scanner

import scala.annotation.tailrec
import scala.collection.mutable.ArrayBuffer
import scala.math._

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val writer = new java.io.PrintWriter(System.out)
    writer.println(solve(sc))
    writer.flush()
  }

  case class Lightbulb(switches: Seq[Int], condition: Int)

  def solve(sc: Scanner): String = {
    val (n, m) = (sc.nextInt(), sc.nextInt())
    val switchesList = (0 until m).map { _ =>
      val k = sc.nextInt()
      IndexedSeq.fill(k)(sc.nextInt() - 1)
    }
    val conditionList = IndexedSeq.fill(m)(sc.nextInt())
    val lightbulbs = (0 until m).foldLeft(ArrayBuffer.empty[Lightbulb]) { (acc, i) =>
      acc += Lightbulb(switchesList(i), conditionList(i))
      acc
    }.toIndexedSeq
    debug(n, m, lightbulbs)

    var countOfAllOn = 0
    getSwitchPatterns(n).foreach { sp =>
      val countOfOn = lightbulbs.foldLeft(0) { (acc, lightbulb) =>
        if (sp.zipWithIndex.filter { case (_, i) => lightbulb.switches.contains(i) }.map(_._1).sum % 2 == lightbulb.condition) {
          acc + 1
        } else {
          acc
        }
      }
      if (countOfOn == lightbulbs.size) countOfAllOn += 1
    }
    countOfAllOn.toString
  }

  def getSwitchPatterns(n: Int): IndexedSeq[ArrayBuffer[Int]] = {
    @tailrec
    def dfs(sp: IndexedSeq[ArrayBuffer[Int]], n: Int): IndexedSeq[ArrayBuffer[Int]] = {
      if (n > 0) {
        sp.zipWithIndex.foreach { case (a, i) =>
          a += floor(i / (pow(2, n) / 2) % 2).toInt
        }
        dfs(sp, n - 1)
      } else sp
    }

    dfs(IndexedSeq.fill(pow(2, n).toInt)(ArrayBuffer.empty[Int]), n)
  }

  private def debug(x: Any): Unit = {
    if (System.getenv("LOCAL_DEBUG") != null) println(x)
  }
}


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 444;



struct dsu0 {
    vector<int> par, siz;
    int n;
    int cc;
    int largest;
    void init(int n) {
	assert(n>0);
	this->n=n;
	cc=n;
	par.resize(n+10);siz.resize(n+10);
	for (int i=0; i<n; i++) par[i]=i,siz[i]=1;
	largest=1;
    }
    int parent(int x) {
	assert(x>=0 && x<n);
	return par[x]==x?x:par[x]=parent(par[x]);
    }
    bool join(int x, int y) {
	x=parent(x);y=parent(y);
	if (x==y) return false;
	cc--;
	if (siz[x]<siz[y]) swap(x,y);
	siz[x]+=siz[y];par[y]=x;
	largest=max(largest,siz[x]);
	return true;
    }
};

int n, m;
int g[maxn][maxn];

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

    cin>>n>>m;
    for (int i=0; i<n; i++) {
	string s;
	cin>>s;
	for (int j=0; j<m; j++) {
	    if (s[j]=='#') g[i][j]=1;
	}
    }

    dsu0 dsu;
    dsu.init(n*m);

    const vector<pair<int,int>> mo = {{0,1},{0,-1},{-1,0},{1,0}};
    
    for (int i=0; i<n; i++) {
	for (int j=0; j<m; j++) {
	    for (auto p: mo) {
		int di=p.first+i;
		int dj=p.second+j;
		if (di<0||dj<0||di>=n||dj>=m) continue;
		if (g[i][j]+g[di][dj]==1) {
		    dsu.join(i*m+j,di*m+dj);
		}
	    }
	}
    }

    ll res = 0;

    
    map<int,vector<pair<int,int>>> mp;


    for (int i=0; i<n; i++) {
	for (int j=0; j<m; j++) {
	    int k = i*m+j;
	    mp[dsu.parent(k)].push_back({i,j});
	}
    }

    for (auto p: mp) {
	int black = 0;
	int white = 0;
	for (auto cd: p.second) {
	    if (g[cd.first][cd.second]) black++; else white++;
	}

	res += 1ll*black*white;
    }

    cout<<res<<endl;    
    return 0;
}


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

typedef long long ll;
typedef pair<int,int> ii;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n; cin>>n;
	double x; string u;
	map<string,double> ct;
	for (int i=0; i<n; i++)
		cin>>x>>u, ct[u]+=x;
	cout<<setprecision(10)<<fixed<<ct["JPY"]+ct["BTC"]*380000<<"\n";
	return 0;
}

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

int A[110], ans[110];

int main() {
	int N, M;
	cin >> N >> M;
	int cnt=0;
	for(int i=0; i<M; ++i){
		cin >> A[i];
		cnt += A[i]%2;
	}
	if(cnt>2){
		cout << "Impossible" << endl;
		return 0;
	}
	if(cnt>0){
		bool flag=false;
		for(int i=0; i<M; ++i){
			if(A[i]%2==1){
				if(flag){
					swap(A[i], A[M-1]);
				}else{
					swap(A[i], A[0]);
					flag=true;
				}
			}
		}
	}
	cout << A[0];
	for(int i=1; i<M; ++i) cout << ' ' << A[i];
	cout << endl;
	int bs=0;
	if(A[0]>1){
		ans[bs]=A[0]-1;
		++bs;
	}
	A[0]=2;
	for(int i=0; i<M-1; ++i){
		ans[bs]=A[i];
		++bs;
	}
	if(A[M-1]>1){
		ans[bs]=A[M-1]-1;
		++bs;
	}
	cout << bs << endl;
	cout << ans[0];
	for(int i=1; i<bs; ++i) cout << ' ' << ans[i];
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long a,b,sum,k;
int main()
{
    cin>>k>>a>>b;
    if(a>=k) 
    {cout<<1<<endl;return 0;}
    if(b>=a) return cout<<-1<<endl,0;
    if((k-a)%(a-b)>=1)  
    sum=1;
    cout<<((k-a)/(a-b)+sum)*2+1<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    ll a;
    string b;
    cin >> a >> b;
    vector<ll> num;
    rep(i, (int)b.size()) {
        if (b[i] == '.') continue;
        num.push_back(b[i]-'0');
    }
    //for (auto n: num) {
    //    cout << n << " ";
    //}
    //cout << endl;
    ll b_100 = (num[0] * 100 + num[1] * 10 + num[2]);
    //cout << b_100 << endl;
    ll ans = (a * b_100) / 100;
    cout << ans << endl;
    return 0;
}


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

using namespace std;

#define F first
#define S second
#define MAX_N 100010
#define mod 1000000007

typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vbl;

int main() {
  //freopen("input.in", "r", stdin);
  int h, w;
  cin >> h >> w;
  string a[h+1];
  ll dp[h+1][w+1];

  for (int i = 1 ; i <= h ; i++) {
    cin >> a[i];
    for (int j = 1 ; j <= w ; j++) {
      dp[i][j] = 0;
    }
  }

  dp[h][w] = 1;

  for (int i = h ; i >= 1 ; i--) {
    for (int j = w ; j >= 1 ; j--) {
      if (i < h && a[i+1][j-1] == '.') {
        dp[i][j] += dp[i+1][j];
        dp[i][j] %= mod;
      }
      if (j < w && a[i][j] == '.') {
        dp[i][j] += dp[i][j+1];
        dp[i][j] %= mod;
      }
    }
  }

  cout << dp[1][1] << endl;

  return 0;
}

Measured memory_bytes: 9088
#"Bad"が二回出たり。"Bad""Good"になったりする。なぜだ？？　　
S = input()
Pass = list(S)

if Pass[0]==Pass[1]:
    print("Bad")
elif Pass[1]==Pass[2]:
    print("Bad")
elif Pass[2]==Pass[3]:
    print("Bad")
else:
    print("Good")



Measured memory_bytes: 9028
#include <bits/stdc++.h>
using namespace std;
int main()
{
   string s1,s2;
   getline(cin,s1);
   getline(cin,s2);
   int l1,l2,i,j;
   l1=s1.length();
   l2=s2.length();
   int dp[l1+1][l2+1];
   for(i=0;i<=l1;i++){
       for(j=0;j<=l2;j++){
           if(i==0||j==0){
               dp[i][j]=0;
           }
           else{
               if(s1[i-1]==s2[j-1]){
                   dp[i][j]=1+dp[i-1][j-1];
               }
               else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
           }
       }
   }
   //cout<<dp[l1][l2];
//   for(i=0;i<=l1;i++){
//       for(j=0;j<=l2;j++){
//           cout<<dp[i][j]<<" ";
//       }
//       cout<<endl;
//   }
   int tmp=0;
   i=l1;
   j=l2;
   char str[dp[l1][l2]+1];
   str[dp[l1][l2]]='\0';
   int id =dp[l1][l2]-1 ;
   while(i>0 && j>0){
       if(s1[i-1]==s2[j-1]){
           str[id--]=s1[i-1];
           i--;
           j--;
           
       }
       else if(dp[i-1][j]>dp[i][j-1]){
           i--;
       }
       else j--;
   }
   cout<<str;
   return 0;
}

Measured memory_bytes: 35456
n,m,l = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(n)]
B = [list(map(int, input().split())) for _ in range(m)]

C = [[0 for k in range(l)] for i in range(n)]
for i in range(n):
    for k in range(l):
        for j in range(m):
            C[i][k] += A[i][j] * B[j][k]

for i in range(n):
    print(*C[i])


Measured memory_bytes: 7060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
ll gcd(ll a, ll b)
{
    if (a % b == 0)
    {
        return b;
    }
    else
    {
        return gcd(b, a % b);
    }
}
ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll a, b, c, d;
    cin >> a >> b >> c >> d;

    ll dd = b / d - (a - 1) / d;
    ll cc = b / c - (a - 1) / c;
    ll kou = b / lcm(c, d) - (a - 1) / lcm(c, d);
    // cout << cc << "," << dd << "," << kou << "," << lcm(c, d) << endl;
    ll cnt = (b - a + 1) - (cc + dd - kou);
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3636
/*
	RAone00
	Rohit sharma
	*/

	#include <bits/stdc++.h>
	using namespace std;

	typedef long long ll;
	typedef long double ld;
	typedef pair < ll, ll > pll;
	typedef vector < vector < ll > > matrix;
	typedef vector < ll > vll;

	#define pb push_back
	#define debug(x) cout << (#x) << " is " << (x) << endl
	#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)

	const ll mod = 1e9 + 7;
	const ll inf = LLONG_MAX;
	const ll N = 1e5 + 10;

	
	int main() {
	    fast_io();
	    int a, b;
	    cin >> a >> b;
	    for (int i = 1; i < 1009; ++i) {
	    	int x = i * 0.08;
	    	int y = i * 0.1;
	    	if ((a == x) && (b == y)) {
	    		cout << i << "\n";
	    		return 0;
	    	} 
	    }
	    cout << "-1\n";
	    return 0;
	}

  

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

int main()
{
	int a, b, c, d;
	scanf("%d%d%d%d", &a, &b, &c, &d);
	while (true)
	{
		c -= b;
		if (c <= 0)
		{
			puts("Yes");
			return 0;
		}
		a -= d;
		if (a <= 0)
		{
			puts("No");
			return 0;
		}
	}
}


Measured memory_bytes: 1660