akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
#define MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> Vl;
typedef vector<double> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<VS> VSS;  
typedef vector<VI> VVI;   // VVI a(n,vector<int>(m)) n * m 
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef long long ll;  //ll とdoubleは違う
// cout << << endl;
// cin >> ;
int main(){
    ll k=0,s=0,n,min=100000000000,ans=0;
    string s1,s2,s3;
    cin >> k >> s;

    for(int x=0;x<=k;x++){
        for(int y=0;y<=k;y++){
            int z = s - x - y;
            if (0<=z && z <= k) 
                ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main()
{
    int h, w;
    string grid[111];
    int i, j, k, l;
    cin >> h >> w;
    for (i = 0; i < h; i++) {
        cin >> grid[i];
    }
    for (i = 0; i <= w + 1; i++) {
        cout << "#";
    }
    cout << "\n";
    for (i = 0; i < h; i++) {
        cout << "#";
        cout << grid[i];
        cout << "#\n";
    }
    for (i = 0; i <= w + 1; i++) {
        cout << "#";
    }
    cout << "\n";
    return 0;
}


Measured memory_bytes: 256
import java.io.InputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        solve(System.in, System.out);
    }

    public static class Pair {
        int A;
        int B;
        public Pair(int a, int b){
            A = a;
            B = b;
        }
    }

    static void solve(InputStream is, PrintStream os) {
        // Your code here!
        Scanner scan = new Scanner(is);
        int H = scan.nextInt();
        int N = scan.nextInt();
        Pair[] pairs = new Pair[N];
        for(int i = 0; i < N; i++){
            pairs[i] = new Pair(scan.nextInt(), scan.nextInt());
        }

        Arrays.sort(pairs, (p1, p2) -> p1.A - p2.A);

        int costs[] = new int[H+1];
        Arrays.fill(costs, Integer.MAX_VALUE);
        costs[0] = 0;

        for(int i = 0; i <N; i++) {
            int A = pairs[i].A;
            int B = pairs[i].B;
            for(int j = 0; j < H+1; j++){
                int power = j + A;
                int cost = costs[j] + B;
                if(power >= H)
                    power = H;
                if(costs[j] == Integer.MAX_VALUE) continue;
                if(costs[power] == Integer.MAX_VALUE)
                    costs[power] = cost;
                if(cost < costs[power])
                    costs[power] = cost;
            }
        }

        os.println(costs[H]);
    }

}

Measured memory_bytes: 28832
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>

int main(){
    char s[20];
    char t[20];
    scanf("%s",s);
    scanf("%s",t);
    for(int i=0;i<strlen(s);i++){
        if(s[i]!=t[i]){
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
    return 0;
}

Measured memory_bytes: 1624
a,b,c=input().split()
a=int(a)
b=int(b)
c=int(c)
d=0
for i in range(1,a+1):
  if b<=(i//10000+(i//1000-(i//10000)*10))+(i//100-(i//1000)*10)+(i//10-(i//100)*10)+(i//1-(i//10)*10)<=c:
    d=d+i
print(d)


Measured memory_bytes: 8972
#include<bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
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; }
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long int ll;
typedef long double ld;
const ll INF=(1LL<<62);
const ld pi=acosl((ld)-1);
const ll mod = 1000000007;
// const ll mod = 1234567;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
#define endn "\n"
#define TO_STRING(VariableName) # VariableName

template <typename T>ostream &operator<<(ostream &out,const vector<T> &v) {rep(i,(int)v.size()-1)cout<<v[i]<<" ";cout<<v[(int)v.size()-1];return out;}
template <typename T1, typename T2>ostream &operator<<(ostream &out, const map<T1, T2> &p) {out << "(" << p.first << ", " << p.second << ")";return out;}
template <typename T1, typename T2>ostream &operator<<(ostream &out, const pair<T1, T2> &p){out << "(" << p.first << ", " << p.second << ")";return out;}
template<class T>void debag(const T &obj){cout<<obj<<endl;}

bool com(ld a,ld b){
	return (fabsl(a - b) <= LDBL_EPSILON * fmaxl(1.L, fmaxl(fabsl(a), fabsl(b))));
}

bool solve(){
	ll n;cin>>n;
	vector<ll>A(n+1);
	rep(i,n+1)cin>>A[i];
	vector<ll>maxV(n+1,1);
	vector<ll>maxV2(n+1,0);
	vector<ll>minV(n+1,0);
	maxV2[n]=A[n];
	minV[n]=A[n];
	for(int i=1;i<=n;i++){
		maxV[i]=min((maxV[i-1]-A[i-1])*2,INF/2);
		if(maxV[i]<0){
			cout<<-1<<endl;
			return false;
		}
	}
	ll ans=0;
	for(int i=n-1;i>=0;i--){
		minV[i]=(minV[i+1]+A[i]+1)/2;
		maxV2[i]=maxV2[i+1]+A[i];
		chmin(maxV2[i],maxV[i]);
		if(minV[i]>maxV[i]){
			cout<<-1<<endl;
			return false;
		}
		
		ans+=maxV2[i];
	}
	if(minV[n]>maxV[n]){
			cout<<-1<<endl;
			return false;
		}
	/*cout<<maxV<<endl;
	cout<<minV<<endl;
	cout<<maxV2<<endl;*/
	cout<<ans+A[n]<<endl;
	return false;
}

signed main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout<<fixed<<setprecision(30);
  solve();
}


Measured memory_bytes: 6344
import java.util.Scanner;

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

        int[] num;
        num = new int[3];
        int i, j, t;

        String line = sc.next();
        num[0] = Integer.parseInt(line);
        line = sc.next();
        num[1] = Integer.parseInt(line);
        line = sc.next();
        num[2] = Integer.parseInt(line);

        for(i=0; i<2; i++){
            for(j=2; j>i; j--){
                if(num[j-1] > num[j]){
                    t = num[j]; num[j] = num[j-1]; num[j-1] = t;
                }
            }
        }

        System.out.println(num[0]+ " " +num[1] + " " + num[2]);
        sc.close();
    }
}


Measured memory_bytes: 26320
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i=0;i < (int)(n);i++)
const ll mod = 1e9+7;
int main(){
    int n;
    string s;
    cin >> n;
    ll ans = 1LL;
    for (ll i=1;i <= n;i++){
        ans*=i;
        ans%=mod;    
    }
    cout << ans%mod << endl;

    return 0;
}

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

int main(){
    int a, b;
    cin >> a >> b;
    
    if (a >= b){
        rep(i, a) cout << b;
        cout << endl;
    }else{
        rep(i, b) cout << a;
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<functional>
#include<cstdlib>
#include<stdexcept>
#include<numeric>
#include<cmath>
#include<fstream>
#include<memory>
#include<algorithm>
#include<cstring>
#include<ctime>
#include<deque>
#include<sstream>
#include<iomanip>
#include<sstream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<climits>
#include<map>
#include<set>
#include<list>
#include<cassert>
#include<deque>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define INF 1<<27
#define all(n) n.begin(),n.end()
#define insert(a,b,c,d) PP(P(a,b),P(c,d))
#define F first
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define S second
#define ppins(a,b,c,d) PP(P(a,b),P(c,d))
#define pb push_back
#define pf push_front
using namespace std;
typedef pair<int,int> P;
typedef pair<P,P> PP;
typedef long long ll;
typedef unsigned long long ull;
int n,hx,hy,dx,dy;
vector<P> vec;
int LIM;
bool Found;
const double EPS = 1e-10;

void print(int used)
{
  rep(i,n)
	{
	  if(used>>i&1)
	    cout << "1";
	  else
	    cout << "0";
	}
      cout << endl;
}

bool Input()
{
  cin >> n >> hx >> hy >> dx >> dy;
  if(n+hx+hy+dx+dy == 0)
    return true;
  
  vec.clear(),LIM = 0,Found = false;
  rep(i,n)
    {
      int X,Y;
      cin >> X >> Y;
      vec.pb(P(X,Y));
      LIM = LIM|(1<<i);
    }
  return false;
}

bool isCan(P my,double ene,P p,int used)
{

  double cost = sqrt(pow(p.F-my.F,2)+pow(p.S-my.S,2));
 
  rep(i,n)
    {
      if((used>>i)&1)
	continue;

      double dist = sqrt(pow(vec[i].F-dx,2)+pow(vec[i].S-dy,2));

      //cout << "circle : " << ene+cost << " , dist : " << dist << endl;
      if(ene+cost >= dist)
	return false;
    }
  return true;
}

bool check(int used,P my,double cost)
{
  rep(i,n)
    {
      if(used>>i&1)
	continue;
      if(hypot(vec[i].F-dx,vec[i].S-dy) - (hypot(vec[i].F-my.F,vec[i].S-my.S)+cost) < EPS)
	{
	  return false;
	}
    }
  return true;
}

void rec(P my,double cir,int used)
{
  if(Found)
    return;

  if(used == LIM)
    {
      Found = true;
      return;
    }
 
  if(!check(used,my,cir))
    return;

  rep(i,n)
    {
      if((used>>i)&1)
	continue;
      rec(vec[i],cir+hypot(vec[i].F-my.F,vec[i].S-my.S),used|(1<<i));
    }

}

int main(){
  while(true)
    {
      if(Input())
	break;
    
 
      rec(P(hx,hy),0,0);
      Found?cout << "YES" << endl:cout << "NO" << endl;
    }
return 0;
}

Measured memory_bytes: 1204
#include<iostream>
#include<cstdio>
#include<unordered_map>
using namespace std;
typedef long long ll;
const ll p=1000000000000000009;
const int base=250001;
unordered_map<ll,int> mp;
int n,dig[250005];
__int128 pw[250005]={1},hsh[250005];
ll ans;
char s[250005];
ll qpow(__int128 a,ll b){
    ll res=1;
    while(b){
        if(b&1)
            res=res*a%p;
        a=a*a%p;
        b>>=1;
    }
    return res;
}
__int128 power(int x){
    return x>=0?pw[x]:qpow(pw[-x],p-2);
}
int main(){
    ios::sync_with_stdio(false);
    ll val;
    int i;
    cin>>n>>s+1;
    for(i=1;i<=n;i++)
        pw[i]=pw[i-1]*base%p;
    for(i=1;i<=n;i++){
        switch(s[i]){
            case '+':
                dig[i]=dig[i-1];
                hsh[i]=(hsh[i-1]+power(dig[i]))%p;
                break;
            case '-':
                dig[i]=dig[i-1];
                hsh[i]=(hsh[i-1]-power(dig[i])+p)%p;
                break;
            case '<':
                dig[i]=dig[i-1]+1;
                hsh[i]=hsh[i-1];
                break;
            case '>':
                dig[i]=dig[i-1]-1;
                hsh[i]=hsh[i-1];
        }
    }
    for(i=0;i<=n;i++){
        if(mp.count(hsh[i]))
            ans+=mp[hsh[i]];
        val=(hsh[i]+hsh[n]*power(dig[i]))%p;
        if(mp.count(val))
            mp[val]++;
        else
            mp[val]=1;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 22104
#include <iostream>
#include <algorithm>
#include <stack>
#include <string>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <list>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

struct node{
	int key;
	node *parent, *left, *right;
};

node *root, *NIL;

void insert(int k) {
	node *y = NIL;
	node *x = root;
	node *z;

	z = (node *)malloc(sizeof(node));
	z->key = k;
	z->left = NIL;
	z->right = NIL;

	while( x != NIL) {
		y = x;
		if( z->key < x->key) x = x->left;
		else x = x->right;
	}
	z->parent = y;
	if( y == NIL) {
		root = z;
	} else if( z->key < y->key){
		y->left = z;
	} else {
		y->right = z;
	}
}

node * find(int k) {
	node *x = root;
	node *y = NIL;
	while( x != NIL && k != x->key) {
		if( k < x->key) x = x->left;
		else if( k > x->key) x = x->right;
	}
	return x;
}

node * mini(node *u) {
	while( u->left != NIL) {
		u = u->left;
	} return u;
}

node * Successor(node *u) {
	if( u->right != NIL)return mini(u->right);
	node *y = u->parent;
	//while( y != NIL && u == y->right) {
		u = y;
		y = y->parent;
	//}
	//return y;
}

void Delete(node *z) {
	node *y;
	node *x;
	if( z->left == NIL || z->right == NIL) y = z;
	else y = Successor(z);
	if( y->left != NIL) {
		x = y->left;
	} else {
		x = y->right;
	}

	if( x != NIL) {
		x->parent = y->parent;
	}

	if( y->parent == NIL) {
		root = x;
	} else {
		if( y == y->parent->left) {
			y->parent->left = x;
		} else {
			y->parent->right = x;
		}
	}

	if(y != z) {
		z->key = y->key;
	}
	free(y);
}


void Preorder(node *t) {
	if( t == NIL) return;
	printf(" %d", t->key);
	Preorder(t->left);
	Preorder(t->right);
}

void Inorder(node *t) {
	if( t == NIL) return;
	Inorder(t->left);
	printf(" %d", t->key);
	Inorder(t->right);
}

void Postorder(node *t) {
	if( t == NIL) return;
	Postorder(t->left);
	Postorder(t->right);
	printf(" %d", t->key);
}

int main(){
	int x, n;
	string st;
	cin >> n;
	for( int i = 0; i < n; i++) {
		cin >> st;
		if(st[0] == 'i') {
			cin >> x;
			insert(x);
		} else if(st[0] == 'p'){
			Inorder(root);
			cout << endl;
			Preorder(root);
			cout << endl;
		} else if( st[0] == 'f'){
			cin >> x;
			node *t = find(x);
			if( t == NIL) cout << "no";
			else cout << "yes";
			cout <<endl;
		} else {
			cin >> x;
			Delete( find(x) );
		}
	}
	return 0;
}

Measured memory_bytes: 19976
#include<bits/stdc++.h>
using namespace std;
vector<pair<pair<string,int>,int>> resBook;
bool comp(pair<pair<string,int>,int> x,pair<pair<string,int>,int> y){
	int compVal = (x.first.first).compare(y.first.first);
	if(compVal > 0){
		return false;
	}
	else if(compVal<0){
		return true;
	}
	else{
		return x.first.second > y.first.second;
	}
}
int main(){
	int N;
	cin>>N;
	for(int i=0;i<N;i++){
		string city;
		int rating;
		cin>>city>>rating;
		resBook.push_back(make_pair(make_pair(city,rating),i+1));
		//cout<<resBook[i].first<<resBook[i].second<<endl;
	}
	sort(resBook.begin(),resBook.end(),comp);
	for(auto c:resBook)
		cout<<c.second<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <climits>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <sstream>
#include <numeric>
// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>

///////////////////////////////////////////////////////////////
// namespace
///////////////////////////////////////////////////////////////
using namespace std;
// namespace mp = boost::multiprecision;

///////////////////////////////////////////////////////////////
// types
///////////////////////////////////////////////////////////////
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
// using mpi = mp::cpp_int;
// using mpf = mp::number<mp::cpp_dec_float<1024>>;

///////////////////////////////////////////////////////////////
// mod https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a
///////////////////////////////////////////////////////////////
// ll MOD = 1000000007;
//
// ll mod(long long val) {
//     long long res = val % MOD;
//     if (res < 0) res += MOD;
//     return res;
// }
//
// ll modinv(ll a) {
//     ll b = MOD, u = 1, v = 0;
//     while (b) {
//         ll t = a / b;
//         a -= t * b; swap(a, b);
//         u -= t * v; swap(u, v);
//     }
//     u %= MOD;
//     if (u < 0) u += MOD;
//     return u;
// }
//
// const int MAX = -1;
// ll fac[MAX], finv[MAX], inv[MAX];
// void com_init() {  // initialize nCk table with O(N)
//     fac[0] = fac[1] = 1;
//     finv[0] = finv[1] = 1;
//     inv[1] = 1;
//     for (int i = 2; i < MAX; i++){
//         fac[i] = fac[i - 1] * i % MOD;
//         inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
//         finv[i] = finv[i - 1] * inv[i] % MOD;
//     }
// }
// ll com(int n, int k){  // nCk
//     if (n < k) return 0;
//     if (n < 0 || k < 0) return 0;
//     return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
// }


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


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

// @@ !! LIM()

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  vector<ll> v(3);
  for (ll i = 0; i < 3 ;i++) cin >> v.at(i);
  sort(v.begin(), v.end());
  cout << v.at(0) + v.at(1) << endl;

  return 0;
}



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

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

  int a, b, c;
  cin >> a >> b >> c;

  int count = b/a;
  if (count >= c) count = c;
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int a,b,k;
    cin >> a >> b;
    if(a>=0 && b<=1000000000)
    {
        if(((a+b)%2)==0)
        {
            k= (a+b)/2;
            cout << k << endl;
        }
        else
        {
            cout << "IMPOSSIBLE" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3584
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
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; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    for(int c = 1; c <= 3; c++){
        if((a*b*c)%2 == 1){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner

fun main(args: Array<String>) {
	val scanner = Scanner(System.`in`)
	val n = scanner.nextInt()
	val x = scanner.nextLong()
	var ans = 0L

	var bef = scanner.nextLong()	//a1
	repeat(n-1){
		var a = scanner.nextLong()
		if (bef+a>x){
			ans+=bef+a-x
			a =  if (bef-x>0) 0 else x-bef
		}
		bef = a
	}
	println(ans)
}

Measured memory_bytes: 54804
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; ++i)
#define all(a) (a).begin(), (a).end()

int N;

struct Edge {
  int to, w;
};

vector<vector<Edge>> G;
vector<int> ans;

void dfs(int d, int u, int p) {
  ans[u] = d;

  for (Edge& e : G[u]) {
    if (e.to == p) continue;
    dfs((d + e.w) % 2, e.to, u);
  }
}

int main() {
  cin >> N;
  G.resize(N);
  ans.resize(N);

  rep(i, N - 1) {
    int u, v, w;
    cin >> u >> v >> w;
    --u, --v;
    G[u].push_back(Edge{v, w});
    G[v].push_back(Edge{u, w});
  }

  dfs(0, 0, -1);

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

  return 0;
}


Measured memory_bytes: 8192
#include"bits/stdc++.h"
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define INF 1e+9


int main() {
	int a, b;
	cin >> a >> b;
	if (a > b) swap(a, b);
	if ((b - a) % 2 == 0) {
		cout << a + ((b - a) / 2) << endl;
	}
	else {
		cout << "IMPOSSIBLE" << endl;
	}


	return 0;
}

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

#define watch(x) cerr << (#x) << ": " << (x) << endl
#define int long long

void sinsert(vector<int>& v, int i) {
    v.insert(lower_bound(v.begin(), v.end(), i), i);
}

int left(vector<int>& seen, int sz, int fnd, int ind) {
    if(fnd == 1) return 0;
    int lsz = seen[fnd-1]-seen[fnd-2];
    int rsz = seen[fnd]-ind;
    return lsz*rsz;
}

int right(vector<int>& seen, int sz, int fnd, int ind) {
    if(fnd == sz-1) return 0;
    int rsz = seen[fnd+1]-seen[fnd];
    int lsz = ind-seen[fnd-1];
    return lsz*rsz;
}

int32_t main() {

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

    vector<int> index(n+1);
    for(int i = 0; i < n; ++i) {
        index[p[i]] = i;
    }

    vector<int> seen = {-1, index[n], n};
    int sz = 3;

    int ans = 0;
    
    for(int num = n-1; num > 0; --num) {
        int ind = index[num];
        int it = lower_bound(seen.begin(), seen.end(), ind) - seen.begin();

        int c1 = left(seen, sz, it, ind), c2 = right(seen, sz, it, ind);

        ans += (c1+c2)*num;
        
        sinsert(seen, ind);
        sz++;
    }

    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 3448
import java.util.*

/**
 * 行列.
 */
data class Matrix(val elements: List<List<Long>>) {
    /**
     * 行数.
     */
    val row = this.elements.size
    /**
     * 列数.
     */
    val col = if (this.row > 0) this.elements[0].size else 0

    /**
     * 指定された行列の要素を返します.
     * @param row 行
     * @param col 列
     * @return 要素
     */
    fun get(row: Int, col: Int) = this.elements.get(row).get(col)

    /**
     * 行列の掛け算の結果を返します.
     * @param other 乗数の行列
     */
    fun times(other: Matrix): Matrix = Matrix(
        elements.map { e ->
            (0..other.col - 1).map { col ->
                e.foldIndexed(0L, {row, acc, a -> acc + a * other.get(row, col)})
            }
        }
    )

    override fun toString(): String =
        this.elements.map { it.joinToString(" ") }.joinToString("\n")
}

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val n = scanner.nextInt()
    val m = scanner.nextInt()
    val l = scanner.nextInt()
    val A = Matrix((1..n).map {
        (1..m).map { scanner.nextLong() }
    })
    val B = Matrix((1..m).map {
        (1..l).map { scanner.nextLong() }
    })
    println(A.times(B))
}


Measured memory_bytes: 56864
#include <bits/stdc++.h>
#define mp make_pair
#define F first
#define S second
#define ll long long
using namespace std;
const int LIM = 4e6+3;
pair<int,int> arr[LIM+3];
int main(){
  int n;cin >> n;
  bool is = true;
  int last = -1;
  for(int i = 0;i<n;i++)
  {
    int x;cin >> x;
    if(!i)x--;
    else if(x-1 >=last)x--;
    if(x < last)is = false;
    last = x;
  }
  if(is)puts("Yes");
  else puts("No");
}

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

class Program
{
    public static void Main()
    {
        int N = int.Parse(Console.ReadLine());
        var W = Console.ReadLine().Split(' ').Select(p => int.Parse(p)).ToArray();

        int min = 0;

        for(int p = 0; p < N; p++)
        {
            int sum = 0;
            for(int m = 0; m <= p; m++)
            {
                sum = sum + W[m];
            }

            int sum2 = 0;
            for (int m = p + 1; m < N; m++)
            {
                sum2 = sum2 + W[m];
            }

            if(p == 0)
            {
                min = Math.Abs(sum - sum2);
            }
            else if(Math.Abs(sum - sum2) < min)
            {
                min = Math.Abs(sum - sum2);
            }

        }

        Console.WriteLine(min);

    }

}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;;
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;
 
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll h,w,n;cin >> h >> w >> n;
  cout << (n + max(h,w)-1) / max(h,w) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 32768
#define F for(i=0;++i<N;)
int64_t a[N]={},b[N],c[N]={},n,k,i;
int main(){std::cin>>n>>k;F a[i]=i<n?i:n,b[i]=n/i;while(--k){F c[i]=c[i-1]+b[i];for(b[--i]=c[n/i];--i;a[i]=c[i])b[i]=(b[i+1]+a[i]*(n/i-n/(i+1)))%0x3B9ACA07LL;}std::cout<<b[1];}

Measured memory_bytes: 1024
void main() {
    int[] tmp = readln.split.to!(int[]);
    int l = tmp[0] + tmp[1], r = tmp[2] + tmp[3];
    if (l > r) {
        "Left".writeln;
    } else if (l == r) {
        "Balanced".writeln;
    } else {
        "Right".writeln;
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll M, D;
  cin >> M >> D;
  ll ans = 0;
  REP(i, M) FOR(j, 1, D + 1) {
    if (j % 10 >= 2 && (j / 10) >= 2 && (j % 10) * (j / 10) == i + 1) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 888
#include<stdio.h>
int main() {
  int N, m, ans;
  int n[100];
  int i;
  while (1) {
    scanf("%d", &N);
    if (!N) break;
    for (i = 0; i < N; i ++) scanf("%d", &n[i]);
    scanf("%d", &m);
    int l, r, mid;
    l = 0; r = N - 1;
    for (ans = 0; l <= r; ans ++) {
      mid = (l + r) / 2;
      if (n[mid] == m) {
	ans ++; break;
      } else if (n[mid] > m) r = mid - 1;
      else l = mid + 1;
    }
    printf("%d\n", ans);
  }
  return 0;
}

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

int main(){
    int n; cin >> n;
    int ans = 0;

    vector<int> b; b.resize(n-1);

    cin >> b[0];
    ans += b[0];
    for (int i=1;i<n-1;i++){
        cin >> b[i];
        ans += min(b[i], b[i-1]);
    }
    ans += b[n-2];

    cout << ans << endl;
}

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

int p,q,sum;
int x[4]={-1,0,0,1},y[4]={0,-1,1,0};
string c[50];
bool n,m;
void kazoeru(int a,int b){
    sum++;
    c[a][b]=0;
    for(int i=0;i<4;i++){
	int dx=a+x[i],dy=b+y[i];
	if(dx>=0&&dx<p&&dy>=0&&dy<q){
	    if(c[dx][dy]=='.'){kazoeru(dx,dy);}
	    else if(c[dx][dy]=='B')n=true;
	    else if(c[dx][dy]=='W')m=true;}
	}
    }
int main(){
    while(cin>>q>>p,p|q){
	for(int f=0;f<p;f++){
	   cin>>c[f];
	}
	int N=0,M=0;
	for(int f=0;f<p;f++){
	   for(int g=0;g<q;g++){
	       if(c[f][g]=='.'){sum=0;n=m=false;kazoeru(f,g);
		  if(!m&&n)M+=sum;
		  else if(m&&!n)N+=sum;
		   }}}
		   cout<<M<<" "<<N<<endl;
	}
}

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

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a: i64,
        b: i64,
    }
    let x = (a-b).abs();
    if x % 2 == 0 {
        println!("{}",  (((a - b) / 2) - a).abs());
    } else {
        println!("IMPOSSIBLE");
    }
}


Measured memory_bytes: 4352
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

int main()
{
    long long int a, b;
    scanf("%lld %lld",&a,&b);
    if((a+b)%2==0)
    {
        printf("%lld",(a+b)/2);
    }
    else
    {
        printf("IMPOSSIBLE");
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int MOD = 1000000007;
typedef long long ll;

template<typename T> void print(const T & v);


int main() {
    int N;
    cin >> N;
    vector<ll> a(N);
    rep(i, N) cin >> a[i];

    ll ans = 0;
    for(int i = 0; i < N; i++){
        while(a[i] % 2 == 0){
            ans++;
            a[i] /= 2;
        }
    }
    cout << ans << endl;
    return 0;
}


// Use For Debug
template <typename T>
void print(T const & v){
    for(int i = 0; i < v.size(); i++){
        if(i) cout << " ";
        cout << v[i];
    }
    cout << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b); (i) >= (a); --(i)) //Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

int main()
{
    int n,k;
    cin >> n >> k;
    if (n >= k * 2 - 1) {
        YES;
    }else{
        NO;
    }
    return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**4)

n, k = map(int, input().split())
stirling = [[-1 for _ in range(k+1)] for _ in range(n+1)]

MOD = 10**9 + 7

def rec(nn, kk):
    if nn < kk or kk == 0:
        return 0
    if kk == 1 or kk == nn:
        return 1
    if stirling[nn][kk] == -1:
        stirling[nn][kk] = (kk * rec(nn-1, kk) + rec(nn-1, kk-1)) % MOD
    return stirling[nn][kk]

print(sum(rec(n, kk) for kk in range(k+1)) % MOD)


Measured memory_bytes: 30668
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<queue>
#include<cmath>
#define ll long long
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
static const int MAX = 100;
static const int MAXN = 100001;


int main(){
    int n, m;
    cin >> n >> m;
    vector<int> A(n);
    int k = 0;
    rep(i,n){
        cin >> A[i];
        k += A[i];
    }
    sort(A.begin(), A.end());

    for(int i = n-1; i >= n-m; i--){
        if(A[i] < (k + 4*m - 1) / (4*m)){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>                          //include all library  
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <sstream>
#include <vector>
#include <stack>
#include <queue>
//#include <priority_queue>
#include <string.h>
#include <functional> // greater<int> はfunctionalヘッダ
using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)          //REP(i, 10){...} //i=0～i=9までのループ
#define REPR(i, n) for(int i = n;i >= 0;i--)        //REPR(i, 10){...} //i=10～i=0までのループ
#define FOR(i, m, n) for(int i = m;i < n;i++)       //FOR(i, 3, 10){...} //i=3～i=9までのループ
#define FORR(i, m, n) for(int i = m;i >= n;i--)     //FORR(i, 10, 3){...} //i=10～i=3までのループ
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
#define PI 3.141592653589
#define npos -1

int main()
{
  string str;
  cin >> str;
  if(str.substr(0,4) =="YAKI") cout << "Yes";
  else cout << "No";
}



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

int a,b,c,ans,x[5000],r,d;
string s;


int  main()
{
    cin>>r>>d>>x[2000];
    for(int i=2001;i<11+2000;i++){
        x[i]=r*x[i-1]-d;
        cout<<x[i]<<endl;
    }
}


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

namespace AtCoder
{
    class Program
    {
        static long n;

        static void Main(string[] args)
        {
            n = int.Parse(Console.ReadLine());
            int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int[] b = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int[] c = Console.ReadLine().Split().Select(int.Parse).ToArray();

            int ans = 0;
            for (int i = 0; i < n; i++) {
                ans += b[a[i] - 1];
                if (i > 0 && a[i] == a[i - 1] + 1) {
                    ans += c[a[i - 1] - 1];
                }
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13396
use std::collections::BTreeSet;

const MOD: usize = 998244353;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let s = sc
        .chars()
        .into_iter()
        .map(|c| c as usize - 'a' as usize)
        .collect::<Vec<_>>();
    let n = s.len();
    if n <= 3 {
        println!("{}", brute_force(s));
        return;
    }
    if (1..n).all(|i| s[i - 1] == s[i]) {
        println!("1");
        return;
    }
    let mut dp = vec![vec![vec![0; 2]; 3]; 3];
    dp[0][0][0] = 1;
    for i in 0..n {
        let mut next_dp = vec![vec![vec![0; 2]; 3]; 3];
        for last in 0..3 {
            for cur_mod in 0..3 {
                for next in 0..3 {
                    let next_mod = (cur_mod + next) % 3;
                    for in_a_row in 0..2 {
                        let next_in_a_row = if (last == next && i > 0) || in_a_row == 1 {
                            1
                        } else {
                            0
                        };

                        next_dp[next][next_mod][next_in_a_row] += dp[last][cur_mod][in_a_row];
                        next_dp[next][next_mod][next_in_a_row] %= MOD;
                    }
                }
            }
        }
        dp = next_dp;
    }

    let modulo = s.iter().sum::<usize>() % 3;
    let mut ans = 0;
    for last in 0..3 {
        ans += dp[last][modulo][1];
    }
    if (1..n).all(|i| s[i - 1] != s[i]) {
        ans += 1;
    }
    println!("{}", ans % MOD);
}

fn brute_force(s: Vec<usize>) -> usize {
    let mut set = BTreeSet::new();
    let n = s.len();
    set.insert(s);
    loop {
        let mut next = BTreeSet::new();
        for s in set.iter() {
            for i in 1..n {
                if s[i - 1] != s[i] {
                    let mut s = s.clone();
                    let replace = match s[i - 1] + s[i] {
                        1 => 2,
                        2 => 1,
                        3 => 0,
                        _ => unreachable!(),
                    };
                    s[i - 1] = replace;
                    s[i] = replace;
                    next.insert(s);
                }
            }
        }
        let prev = set.len();
        set.extend(next);
        if prev == set.len() {
            return set.len();
        }
    }
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    ll a,b;
    cin>>a>>b;
    ll cnt=0,x=0;
    if(b==1){
        cout<<0<<endl;
        return 0;
    }
    while(x<b){
       if(cnt==0) x+=a;
       else x+=(a-1);
        cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef double long dl;
typedef pair < int , int > pii;
typedef pair < pii, pii > p2i;
const int maxn = (int) 3e5 + 1;
const int mod = (int) 1e9 + 7;
const ll inf = (ll)1e18;

#define fi first
#define se second
#define acel ios_base :: sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define next continue

ll a, b, c, x, y;
int main(){
    cin >> a >> b >> c >> x >> y;
    if(c * 2 < a + b){
        ll ans = min(x, y) * c * 2;
        if(x > y){
            if(c * 2 < a){
                ans += (x - y) * c * 2;
            }
            else {
                ans += (x - y) * a;
            }
        }
        else {
            if(c * 2 < b){
                ans += (y - x) * c * 2;
            }
            else {
                ans += (y - x) * b;
            }
        }
        cout << ans;
    }
    else {
        cout << (x * a)+ (y * b);
    }
}


Measured memory_bytes: 256
import numpy as np

def solve(x, N, K):
    ans = 300000000
    for i in range(N - K + 1):
        x1 = x[i]
        x2 = x[i + K - 1]
        if x1 >= 0:
            ans = min(ans, x2)
        elif x2 <= 0:
            ans = min(ans, -x1)
        else:
            ans= min(ans, x2 - x1 + min(x2, -x1))
    return ans


stdin = open(0, 'rb')
pin = np.fromstring(stdin.read(), dtype=np.int64, sep=' ')
N, K = pin[:2]
x = pin[2:]
ans = solve(x, N, K)
print(ans)

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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define fi first
#define se second
#define setpre(x) cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ cout << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , ";
    logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 200000;

/* ...o(^-^)o... */

vector<int> G[MAX];
int h, w;

int id(int i, int j){
    return i * w + j;
}
P idinv(int id){
    return P(id / w, id % w);
}

vector<string> vs;
bool seen[MAX];
lint bl, wh;

void dfs(int s){
    seen[s] = true;
    if(vs[idinv(s).fi][idinv(s).se] == '.') wh++; else bl++;
    for(int& t : G[s]){
        if(seen[t]) continue;
        dfs(t);
    }
}

int main(){
    cin >> h >> w;
    rep(i, h){
        string s; cin >> s; vs.push_back(s);
        rep(j, w){
            if(j != 0 && s[j] != s[j-1]){
                G[id(i, j)].push_back(id(i, j-1));
                G[id(i, j-1)].push_back(id(i, j));
            }
            if(i != 0 && s[j] != vs[i-1][j]){
                G[id(i, j)].push_back(id(i-1, j));
                G[id(i-1, j)].push_back(id(i, j));
            }
        }
    }
    lint ans = 0;
    rep(i, h*w){
        if(seen[i]) continue;
        bl = 0; wh = 0;
        dfs(i);
        ans += bl * wh;
    }
    out(ans);
}

Measured memory_bytes: 15360
// atcoder/abc145/A/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  while (cin >> n) {
    cout << n * n << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define nl '\n'
typedef long long ll;
typedef long double ld;
//////////////////////////////////////////////////////////////////////

const int N = 1e5+5;
int n,a[N];

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

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

  int ans = 0;
  for(int i=1;i<=n;i++){
    if(a[i]==i){
      if(i<n)
	swap(a[i],a[i+1]);
      ans++;
    }
  }
  cout << ans << nl;
  
  return 0;
};


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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) {is >> x;} return is;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'['; for(T i: a) {out<<i<<',';} out<<']'; return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<40;
const ll MOD = 1000000007;

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

  ll n;
  cin >> n;
  vector<ll> a(n);
  REP(i, n) cin >> a[i];

  // dp1[i][j] = dp1[i+1][k] + j (a[i]*4^j <= a[i+1]*4^k を満たす最小のk)
  auto dp1 = make_v<ll>(n, 16);
  REP(i, 16) dp1[n-1][i] = i;
  for(ll i=n-2; i>=0; --i) {
    ll tmp = 1;
    REP(j, 16) {
      ll k = 0, t = 1;
      while(a[i] * tmp > a[i+1] * t) {
        t *= 4;
        k++;
      }
      if(k <= 15) dp1[i][j] = dp1[i+1][k] + j;
      else dp1[i][j] = dp1[i+1][15] + (k - 15) * (n - i - 1) + j;
      tmp *= 4;
    }
  }

  // REP(i, 16) {
  //   REP(j, n) cerr << dp1[j][i] << " ";
  //   cerr << endl;
  // }

  REP(i, n) a[i] *= -2;
  auto dp2 = make_v<ll>(n, 16);
  REP(i, 16) dp2[0][i] = i;
  FOR(i, 1, n) {
    ll tmp = 1;
    REP(j, 16) {
      ll k = 0, t = 1; 
      while(a[i-1] * t > a[i] * tmp) {
        t *= 4;
        k++;
      }
      if(k <= 15) dp2[i][j] = dp2[i-1][k] + j;
      else dp2[i][j] = dp2[i-1][15] + (k - 15) * i + j;
      tmp *= 4;
    }
  }

  // num1[i] = (区間[i,n)で最小の操作回数)
  vector<ll> num1(n, LLINF);
  // num2[i] = (区間[0,i]で最小の操作回数)
  vector<ll> num2(n, LLINF);
  REP(i, n) {
    REP(j, 16) {
      chmin(num1[i], dp1[i][j]*2);
      chmin(num2[i], dp2[i][j]*2+i+1);
    }
  }
  // cerr << num1 << endl << num2 << endl;

  ll ans = LLINF;
  chmin(ans, num1[0]);
  chmin(ans, num2[n-1]);
  REP(i, n-1) chmin(ans, num2[i] + num1[i+1]);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 70528
//TINY_OUNCE911666
// You are not prepared!

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

int n;

int32_t main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	cin >> n;
	for (int i = 1; i <= 9; ++i) {
		if (n % i == 0) {
			if (n/i <= 9) {
				cout << "Yes";
				return 0;
			}
		}
	}
	cout << "No";
}


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

string s;
int main()
{
   
    cin>>s;
    if( (s[0]==s[1]and s[1]==s[2]) || (s[1]==s[2] and s[2]==s[3]) )
        cout<<"Yes";
    else
        cout<<"No";
}


Measured memory_bytes: 256
# 文字が2種類になるまで減る
# 2種類になったら終了
# 両端の文字が違うならその2種類が残る→偶数個残る
# 両端の文字が同じならその文字+1種→奇数個残る

s = input()
iseven = len(s)&1==0
issame = s[0]==s[-1]
print('Second' if iseven^issame else 'First')

Measured memory_bytes: 3316
#include<stdio.h>
 
int mata[100][100],matb[100];
 
int main(void){
    int i,j,n,m,k;
 
    scanf("%d %d",&n,&m);
    for(i = 0;i < n;i++)
        for(j = 0;j < m;j++)
            scanf("%d",&mata[i][j]);
    for(i = 0;i < m;i++)
        scanf("%d",&matb[i]);
 
    for(i = 0;i < n;i++){
        k = 0;
        for(j = 0;j < m;j++)
            k += mata[i][j] * matb[j];
        printf("%d\n",k);
    }
    return 0;
}


Measured memory_bytes: 2048