akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main(){
  int n, q;  scanf("%d %d", &n, &q);
  char s[100005];  scanf("%s", s);

  int ac[100005] = {0}, now = 0;
  for(int i=1; i<n; i++){
    if(s[i-1]=='A' && s[i]=='C')
      now++;
    ac[i] = now;
  }
  
  while(q--){
    int a, b;  scanf("%d %d", &a, &b);
    printf("%d\n", ac[b-1]-ac[a-1]);
  }

  return 0;
}


Measured memory_bytes: 2176
#include <stdio.h>

int main()
{
	int s[6],i;
	for(i=0;i<6;i++)
	{
		scanf("%d",&s[i]);
		if(s[i]==0)
		{
			printf("%d\n",i+1);
			break;
		}
	}
	
	return 0;
}

Measured memory_bytes: 1688
# https://atcoder.jp/contests/dp/tasks/dp_a

import itertools
import collections
import bisect

def main():
    N = int(input())
    H = list(map(int, input().split()))

    # big value
    INF = int(1e15)
    dp = [INF] * N
    dp[0] = 0

    for i in range(N):
        if i + 1 < N:
            dp[i + 1] = min(dp[i + 1], dp[i] + abs(H[i + 1] - H[i]))
        if i + 2 < N:
            dp[i + 2] = min(dp[i + 2], dp[i] + abs(H[i + 2] - H[i]))

    # print(dp)
    print(dp[N-1])

if __name__ == '__main__':
    main()


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

#define X first
#define Y second
#define LL long long
#define ULL unsigned long long
#define PB push_back
#define MP make_pair
#define PII pair<int,int>
#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define IN freopen("in", "r", stdin);
#define OUT freopen("out", "w", stdout);

int main()
{
	int n,k;
	int zm[26]={0};
	scanf("%d%d",&n,&k);
	for (int j=1;j<=n;++j)
	{
		char s[30];
		scanf("%s",s);
		++zm[s[0]-'A'];
	}
	sort(zm,zm+26);
	reverse(zm,zm+26);
	int ans=n/k;
	for (int j=1;j<k;++j)
	{
		n-=zm[j-1];
		ans=min(ans,n/(k-j));
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<string>

using namespace std;

int main(){
	string G;
	getline(cin,G);
	for(int i=0;i<G.size();i++){
		if(isupper(G[i])){
			G[i]=tolower(G[i]);
		}else if(islower(G[i])){
			G[i]=toupper(G[i]);
		}
	}
	cout<<G<<endl;
	return 0;
}

Measured memory_bytes: 1180
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<set> 
#include<map> 
using namespace std;
#define mid 1000000007
set<string>c;  
int main(){
	int a;
	cin>>a;
	while(a--){
		string s;
		cin>>s;
		c.insert(s);
	}
	cout<<c.size();
	return 0;
}

Measured memory_bytes: 19252
#include<cstdio>
#include<vector>
using namespace std;
const int MAXN = 100000;
const int MOD = int(1E9) + 7;
vector<int>rev[MAXN + 5];
int a[MAXN + 5], f[MAXN + 5], dis[MAXN + 5], dep[MAXN + 5];
bool vis[MAXN + 5], vis2[MAXN + 5], tag[MAXN + 5];
int siz, del, ans = 1, tmp;
void dfs1(int x) {
	siz++;
	if( rev[x].size() >= 2 ) tmp = x;
	vis[x] = true;
	for(int i=0;i<rev[x].size();i++)
		if( !vis[rev[x][i]] ) dfs1(rev[x][i]);
	if( !vis[a[x]] ) dfs1(a[x]);
}
int dfs2(int x) {
	if( rev[x].size() == 0 ) return 1;
	else if( rev[x].size() == 1 ) {
		int d = dfs2(rev[x][0]);
		if( d == -1 ) return -1;
		else return d + 1;
	}
	else return -1;
}
int fact[MAXN + 5], inv[MAXN + 5], fun[MAXN + 5];
int pow_mod(int b, int p) {
	int ret = 1;
	while( p ) {
		if( p & 1 ) ret = 1LL*ret*b%MOD;
		b = 1LL*b*b%MOD;
		p >>= 1;
	}
	return ret;
}
void init() {
	fact[0] = 1;
	for(int i=1;i<=MAXN;i++)
		fact[i] = 1LL*fact[i-1]*i%MOD;
	inv[MAXN] = pow_mod(fact[MAXN], MOD-2);
	for(int i=MAXN-1;i>=0;i--)
		inv[i] = 1LL*inv[i+1]*(i+1)%MOD;
	fun[0] = 1;
	for(int i=1;i<=MAXN;i++)
		fun[i] = 1LL*fun[i-1]*(2*i-1)%MOD;
}
int comb(int n, int m) {
	return 1LL*fact[n]*inv[m]%MOD*inv[n-m]%MOD;
}
int main() {
	init(); int N;
	scanf("%d", &N);
	for(int i=1;i<=N;i++) {
		scanf("%d", &a[i]);
		rev[a[i]].push_back(i);
	}
	for(int i=1;i<=N;i++)
		if( !vis[i] ) {
			tmp = -1; siz = 0; dfs1(i);
 			if( tmp != -1 ) {
 				int nw = tmp;
 				do {
 					vis2[nw] = true;
 					nw = a[nw];
				}while( !vis2[nw] );
				if( nw != tmp ) {
					ans = 0;
					continue;
				}
				int p = nw; del = 1;
				do {
					tag[p] = true;
					if( rev[p].size() > 2 ) 
						del = 0;
					p = a[p];
				}while( p != nw );
				if( del == 0 ) {
					ans = 0;
					continue;
				}
				int tmp;
				do {
					if( rev[p].size() == 2 )  {
						dep[p] = tag[rev[p][0]] ? dfs2(rev[p][1]) : dfs2(rev[p][0]);
						if( dep[p] == -1 ) del = 0;
						tmp = p;
					}
					p = a[p];
				}while( p != nw );
				p = nw = tmp;
				int lst = 0;
				do {
					p = a[p]; lst++;
					dis[p] = lst;
					if( rev[p].size() == 2 ) {
						lst = 0;
						if( dis[p] > dep[p] ) del = 2LL*del%MOD;
						else if( dis[p] < dep[p] ) del = 0;
					}
				}while( p != nw );
				ans = 1LL*ans*del%MOD;
			}
			else f[siz]++;
		}
	for(int i=1;i<=N;i++) {
		if( (i & 1) && i != 1 ) {
			del = 0;
			for(int j=0;j<=f[i];j+=2)
				del = (del + 1LL*comb(f[i], j)*fun[j/2]%MOD*pow_mod(i, j/2)%MOD*pow_mod(2, f[i]-j)%MOD)%MOD;
			ans = 1LL*del*ans%MOD;
		}
		else {
			del = 0;
			for(int j=0;j<=f[i];j+=2)
				del = (del + 1LL*comb(f[i], j)*fun[j/2]%MOD*pow_mod(i, j/2)%MOD)%MOD;
			ans = 1LL*del*ans%MOD;
		}
	}
	printf("%d\n", ans);
}

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

int n;
long long c[10][10];

int main() {
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		int a=i;
		int b=a%10;
		while(a>=10)a/=10;
		c[a][b]++;
	}
	long long ans=0;
	for(int i=1;i<10;i++){
		for(int j=1;j<10;j++){
			ans+=c[i][j]*c[j][i];
		}
	}
	printf("%lld",ans);
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int a,b,c;

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

    if(a == b || b == c || c == a ){
        if(!(a == b && b == c)){
            printf("Yes");
        }else{
            printf("No");
        }
    }else{
        printf("No");
    }
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 100;

int a[N];
int n;

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
	sort(a+1, a+n+1);
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = i + 1; j <= n; j++) {
			if (j - i > 1) {
				for (int k = i + 1; k < j; k++) {
					if (a[i] + a[k] > a[j] && a[i] + a[j] > a[k] && a[k] + a[j] > a[i]) ans++;
				}
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
object Main extends App {

  import scala.io.StdIn._
  import scala.math._
  val state = new State(readLine.trim)
  implicit val target = readLine.trim.toList
    println(searchMaxCount(state, target).left.get)
  def searchMaxCount(state: State, rest: List[Char], currentPosition: Int = 0, depth: Int = 30, maxSuccessDepth: Int = 0)(implicit target: List[Char]): Either[Int, Int] = {
    if (depth == 0) Right(currentPosition)
    else {
      rest match {
        case Nil ⇒ searchMaxCount(state, target, currentPosition, depth - 1, maxSuccessDepth)
        case h::t ⇒
          searchMaxCount(state, target, currentPosition, depth - 1, maxSuccessDepth) match {
            case l@Left(_) ⇒ l
            case Right(position) ⇒
              state.nextIndex(position, h) match {
                case Some(next) ⇒ searchMaxCount(state, t, next + 1, depth, math.max(depth - 1, maxSuccessDepth))
                case None ⇒ Left(math.max(depth - 1, maxSuccessDepth))
              }
          }
      }
    }
  }

  class State(state: String){
    val length: Int = state.length
    val indices: Range = state.indices
    private val mLowerIndices = ('a' to 'z').map{c ⇒ state.zipWithIndex.filter(_._1 == c).map(_._2).toArray}.toArray
    private val mUpperIndices = ('A' to 'Z').map{c ⇒ state.zipWithIndex.filter(_._1 == c).map(_._2).toArray}.toArray
    def nextIndex(current: Int, target: Char): Option[Int] = {
      val array = if (target.isUpper) mUpperIndices(target - 'A') else mLowerIndices(target - 'a')
      val index = lowerBound(array, current)
      if (array.indices.contains(index)) Some(array(index))
      else None
    }
  }
  @inline
  def lowerBound[T](array: Array[T], target: T)(implicit ord: Ordering[T]): Int = {
    var left = 0
    var right = array.length
    while (left < right){
      val mid = (left + right) / 2
      if (ord.compare(array(mid), target) < 0){
        left = mid + 1
      }else {
        right = mid
      }
    }
    right
  }
  @inline
  def upperBound[T](array: Array[T], target: T)(implicit ord: Ordering[T]): Int = {
    var left = 0
    var right = array.length
    while (left < right){
      val mid = (left + right) / 2
      if (ord.compare(array(mid), target) <= 0){
        left = mid + 1
      }else {
        right = mid
      }
    }
    right
  }
  implicit class Extension[T](val value :T){
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
    def let[R](func: T ⇒ R): R = func(value)
  }
}


Measured memory_bytes: 316632
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T

main :: IO ()
main = do
  (n : _) <- map unsafeSignedDecimal . T.words <$> T.getLine :: IO [Int]
  print $ (pred n) `div`2

unsafeSignedDecimal :: T.Text -> Int
unsafeSignedDecimal s = case T.signed T.decimal s of
  Right (n, _) -> n


Measured memory_bytes: 508
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
diff = [a - b for a, b in zip(A, B)]
upper = sorted([x for x in diff if x > 0])
lower = sorted([x for x in diff if x < 0], reverse=True)
ans = N - len([x for x in diff if x == 0])
while upper and lower:
    rest = upper.pop()
    while lower:
        tgt = lower.pop()
        if rest + tgt >= 0:
            rest += tgt
        else:
            lower.append(tgt + rest)
            break
if lower:
    print(-1)
else:
    print(ans - len(upper))

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

int main()
{
  int a,b,c;
  cin>>a>>b>>c;
  int arr[10];
  memset(arr,0,sizeof(arr));
  arr[a]++;
  arr[b]++;
  arr[c]++;
  int cnt=0,cnttr=0;
  for(int i=0;i<10;i++)
  {
    if(arr[i]==2)
    {
      cnt++;
    }
    else if(arr[i]==3) cnttr=1;
  }
  if(cnt==1) cout<<"Yes";
  else cout<<"No";
  return 0;
}
    

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
using namespace std;
map<string, int> table;
int main() {
  string word, frequent, longest; // input, max frequency, and longest
  size_t N=0; // frequency of the string "frequent"
  while (cin >> word) {
    table[word] += 1;
    if (table[word] > N) {
      N = table[word];
      frequent = word;
    }
    if (word.size() > longest.size()) 
      longest = word;
  }
  cout << frequent << " " << longest << endl;
}

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

int main() {
    string s ; cin>>s;
    vector<bool>dp((int)s.size() + 1213  , 0);
    int n = s.size();
    dp[0] = 1;
    for(int i =  0 ; i < n; ++i){
        if(dp[i] == 0)continue;
        if(i + 5 <= n && s.substr(i , 5) == "dream")dp[i + 5] = 1; 
        if(i + 5 <= n && s.substr(i , 5) == "erase")dp[i + 5] = 1; 
        if(i + 7 <= n && (s.substr(i , 7) == "dreamer"))dp[i + 7] = 1;
        if(i + 6 <= n && s.substr(i , 6) == "eraser")dp[i + 6] = 1;
    }
    if(dp[n])cout << "YES\n";
    else cout << "NO\n";
}

Measured memory_bytes: 3780
import sys 
def solve():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))

    p_bool = [False] * n
    ne_p = 1
    p_bool[ne_p-1] = True
    step = 0
    for i in range(n):
        ne_p = a[ne_p-1]
        step += 1
        if p_bool[ne_p-1]:
            break
        else:
            p_bool[ne_p-1] = True
        if step == k:
            print(ne_p)
            sys.exit()
    
    p_list = []
    sta = ne_p
    for i in range(n):
        ne_p = a[ne_p-1]
        step += 1
        p_list.append(ne_p)
        if ne_p == sta:
            break
        if step == k:
            print(ne_p)
            sys.exit()

    len_l = len(p_list)
    left = k-step
    left -= (left//len_l) * len_l
    print(p_list[left-1])
    # p_list = [1]
    # ne_p = a[0]
    # p_bool = [False] * n
    # p_bool[0] = True
    # check = False
    # step = 0
    # for _ in range(n):
    #     p_bool[ne_p-1] = True
    #     p_list.append(ne_p)
    #     step = 0
    #     if step == k:
    #         #print(ne_p)
    #         sys.exit()
    #     ne_p = a[ne_p-1]
    #     # if ne_p in p_list:
    #     #     ind = p_list.index(ne_p)
    #     #     break
    #     if p_bool[ne_p-1]:
    #         check = True
    #         break
        
    # #print(p_list)
    # #print(p_bool)
    # if check:
    #     ind = p_list.index(ne_p)
    # else:
    #     ind = 0
    # k = k - ind
    # #print(ind)
    # #print(k)
    # #print(p_list)
    # #print(k%(len(p_list)-ind))
    # print(p_list[ind + k%(len(p_list)-ind)])

solve()

Measured memory_bytes: 32404
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define pll pair<ll,ll>
#define v vector<ll>
#define st stack<ll>
#define pq  priority_queue <int>
#define q queue<ll>
#define mod 1000000005
using namespace std;
 char ch[1000000];
int main(){
    int r;
    cin>>r;
    cout<<(r*r)<<endl;
    return 0;
   }

Measured memory_bytes: 3632
using System.Linq;
using static System.Console;

public static class Program
{

    static bool isAble = false;

    public static void Main()
    {
        var line = ReadLine().Split(' ').Select(int.Parse).ToArray();
        var k = int.Parse(ReadLine());
        Calc(line[0], line[1], line[2], k);
        WriteLine(isAble ? "Yes" : "No");
    }

    public static void Calc(int a, int b, int c, int k)
    {
        if (k == 1)
        {
            if (a * 2 < b && b < c)
            {
                isAble = true;
                return;
            }
            else if (a < b * 2 && b * 2 < c)
            {
                isAble = true;
                return;
            }
            else if (a < b && b < c * 2)
            {
                isAble = true;
                return;
            }
        }
        else
        {
            Calc(a * 2, b, c, k - 1);
            Calc(a, b * 2, c, k - 1);
            Calc(a, b, c * 2, k - 1);
        }
    }
}

Measured memory_bytes: 28220
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int main() {
  int x;
  cin >> x;

  int a = x / 500;
  int b = (x % 500) / 5;
  cout << a * 1000 + b * 5 << endl;

  return 0;
}

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

using namespace std;

typedef long int li;
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pt;

#define fi first
#define se second
#define dump(x) cout << #x << " = " << x << endl

li n, L, res, sum, tmp;

int main () {
    cin >> n >> L;
    sum=0;
    for(li i=1; i<=n; i++) {
        sum+=L+i-1;
    }
    tmp=100000;
    //dump(sum);
    for (li i=1; i<=n; i++) {
        //dump(sum-fabs(sum-L-i+1));
        if(tmp>fabs(sum-(sum-L-i+1))) {
            tmp = fabs(sum-fabs(sum-L-i+1));
            res= sum-L-i+1;
        }
    }
    cout << res;
}


Measured memory_bytes: 256
N,A,B=map(int,input().split())
while True:
    if A+1<B:
        A+=1
    elif 1<A:
        A-=1
    else:
        print("Borys")
        break
    if A<B-1:
        B-=1
    elif B<N:
        B+=1
    else:
        print("Alice")
        break

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

int main(){
    int N,M; cin>>N>>M;
    int conN,conM;
    conN=(N*(N-1))/2;
    conM=(M*(M-1))/2;
    if(N==1){
        conN=0;
    }
    if(M==1){
        conM=0;
    }
    cout<<conN+conM;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

i64 largest_rectangle(vi hist) {
    hist.push_back(0);
    using ii = pair<i64, int>;
    stack<ii> st;
    i64 ret = 0;
    for (int i = 0; i < hist.size(); i++) {
        if (st.empty() || st.top().first < hist[i]) {
            st.push(ii(hist[i], i));
        } else {
            int s;
            while (st.size() && st.top().first >= hist[i]) {
                ret = max(ret, st.top().first * (i - st.top().second));
                s = st.top().second;
                st.pop();
            }
            st.push(ii(hist[i], s));
        }
    }
    
    return ret;
}

int main() {
    int h, w;
    cin >> h >> w;
    vvi b(h, vi(w));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            int c;
            cin >> c;
            if (c == 0) {
                if (i == 0) {
                    b[i][j] = 1;
                } else {
                    b[i][j] = b[i - 1][j] + 1;
                }
            } else {
                b[i][j] = 0;
            }
        }
    }

    i64 ret = 0;
    for (int i = 0; i < h; i++) {
        ret = max(ret, largest_rectangle(b[i]));
    }
    cout << ret << endl;
}


Measured memory_bytes: 18180
#include <bits/stdc++.h>
#define loop(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  loop(i,0,n)
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << endl

using namespace std;

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  int n, l;
  cin >> n >> l;
  vector<string> s(n);
  rep(i, n) cin >> s[i];
  sort(s.begin(), s.end());
  rep(i, n){
    cout << s[i];
  }
  cout << endl;

  
  return 0;
}


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

int main() {
  int a, b;
  cin >> a >> b;
  int x;
  for (int i = 1; i <= 999; ++i) {
    for (int j = i + 1; j <= 999; ++j) {
      int tower1 = (1 + i) * i / 2, tower2 = (1 + j) * j / 2;
      if (tower1 - a == tower2 - b)
        x = tower1 - a;
    }
  }
  cout << x << endl;
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>

#include <numeric>
#include <utility>
#include <complex>

#include <sstream>
#include <iostream>
#include <iomanip>

#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <ctime>

// namespace
using namespace std;

// type alias
using ll = long long;
using ull = unsigned long long;
using comp = complex<double>;

// constant
static const ll MOD = 1000000007LL;
static const double PI = 3.14159265358979323846;

// conversion
inline ll toint(string s) { ll v; istringstream sin(s); sin >> v; return v; }
template<class t> inline string tostring(t x) { ostringstream sout; sout << x; return sout.str(); }

// print
#define RET(x) return cout << x << endl, 0;

// for loop
#define REP(i, a, b) for ((i) = (ll)(a);(i) < (ll)(b);(i)++)
#define REPD(i, a, b) for (ll i = (ll)(a);(i) < (ll)(b);(i)++)
#define REPI(v, vs) for (auto& v : vs)

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl
#define DEBUG(x) cerr << #x << " = " << (x) << " (l" << __LINE__ << ")" << " " << __FILE__ << endl

#define MAX_VALUE 9223372036854775807

int solve() {
	ll n, k;
	cin >> n >> k;

	vector<ll> as(n);
	REPD(i, 0, n) cin >> as[i];

	ll low = 1, high = 1000000000, mid = (low + high) / 2;
	while (high - low >= 2) {
		ll curr_k = 0;
		REPD(i, 0, n) {
			curr_k += (as[i] - 1) / mid;
		}

		if (curr_k <= k) {
			high = mid;
		}
		else{
			low = mid;
		}
		mid = (low + high) / 2;
	}

	{
		ll curr_k = 0;
		REPD(i, 0, n) {
			curr_k += (as[i] - 1) / low;
		}
		if (curr_k <= k) {
			RET(low);
		}
	}

	RET(high);

	return 0;
}

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

	solve();

	return 0;
}


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

#define pb push_back
#define tam 1234567
#define offset 1020000
#define se second
#define fi first
#define pitem item*
#define ptr tre*
#define forr(i,p,n) for(ll i=p;i<n;i++)
using namespace std;
typedef long long ll;
const ll MOD=1000000007 ;
ll mult(ll a,ll b, ll p=MOD){return ((a%p)*(b%p))%p;}
ll add(ll a, ll b, ll p=MOD){return (a%p + b%p)%p;}
typedef pair<ll,ll> ii;
typedef pair<ll,ii> iii;
typedef vector<vector<ll> > vvi;
typedef long double lldb;
int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	string txt;
	cin>>txt;
	ll tot=0,numW=0;
	int n = txt.size();
	forr(i,0,n)
	{
		if (txt[i]=='W')
		{
			tot+=i-numW;
			numW++;
		}
	}
	cout<<tot<<endl;
	return 0;
}//asdfds

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

typedef long long ll;

int n, a[100005 * 3], c;
ll ans;

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

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

    sort(a, a + 3 * n);

    for (int i = 3 * n - 2; c++ < n; i-=2) {
        ans += a[i];
    }
    cout << ans << endl;

    return 0;
}

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

int main()
{
	int N;
	
	int count = 0;
	
	while(cin >> N)
	{
		for(int a = 0; a < 10; a++)
		{
			for(int b = 0; b < 10; b++)
			{
				for(int c = 0; c < 10; c++)
				{
					for(int d = 0; d < 10; d++)
					{
						int s = a + b + c + d;
						if(s == N)count++;
						else if(s > N)break;
					}
				}
			}
		}
                cout << count << endl;
            	count = 0;
        }
	return 0;
}

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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16

struct RangeMaxQuery{
  ll dat[(1<<19)-1];
  ll size;

  void init(ll n_){
    size=1;
    while(size<n_) size*=2;
    for(ll i=0;i<2*size-1;i++)dat[i]=-INF;
  }

  void update(ll k,ll a){
    k+=size-1;
    dat[k]=a;
    while(k>0){
      k=(k-1)/2;
      dat[k]=max(dat[k*2+1],dat[k*2+2]);
    }
  }

  ll subquery(int a,int b,int k,int l,int r){
    if(r<=a||b<=l)return -INF;
    if(a<=l&&r<=b)return dat[k];
    else{
      return max(subquery(a,b,k*2+1,l,(l+r)/2),subquery(a,b,k*2+2,(l+r)/2,r));
    }
  }
  
  ll query(int a,int b){
    return subquery(a,b,0,0,size);
  }
};


ll n;
ll a[111111];
RangeMaxQuery rmq;

int main(){
	cin.sync_with_stdio(false);
  cin>>n;
  rep(i,n){
    cin>>a[i];
  }
  rmq.init(n+1);
  rmq.update(0,0);
  rep(i,n){
    ll sum=a[i]+rmq.query(0,a[i]);
    rmq.update(a[i],sum);
  }
  cout<<n*(n+1)/2-rmq.query(0,n+1)<<endl;
	return 0;
}

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

#define all(x) x.begin(), x.end()

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
 
const int Maxn = 1e5 + 10;
const ll Inf = LONG_LONG_MAX >> 2;
const int Log = 20;

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	string a;
	cin >> a;
	int n = a.size();
	for(int i = 0; i + 1 < n; i++){
		if(a[i] == a[i + 1]) return cout << i + 1 << " " << i + 2 << '\n', 0;
	}
	for(int i = 0; i + 2 < n; i++){
		if(a[i] == a[i + 2]) return cout << i + 1 << " " << i + 3 << '\n', 0;
	}
	cout << "-1 -1\n";
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int h1, h2, m1, m2, k, ans;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    ans = (h2 - h1) * 60 + (m2 - m1) - k;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3592
import java.util.Scanner;

public class Main{
    public static void main(String[] args){

        Scanner scan = new Scanner(System.in);

        int t = scan.nextInt();
        int[] a = new int[t];

        for(int i=0;i<t;i++){
            a[i] = scan.nextInt();
        }

        while(t-->0){
            if(t==0){
                System.out.print(a[t]);
            }else{
            System.out.print(a[t] + " ");
            }
        }
        System.out.println();
    }
}


Measured memory_bytes: 26188
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        char[] S = sc.next().toCharArray();
        if(S[2] == (S[3]) && S[4] == (S[5])){
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

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

  
int LCS_Length(char [] ,char []);
char X[1001],Y[1001];
int c[1001][1001];
int x,y;
int main(void){
  int i;
  int n;
  scanf("%d",&n);
  
  for(i=1;i<=n;i++){
    scanf("%s %s",X,Y);
  
    printf("%d\n",LCS_Length(X,Y));
    
}
   
   
  return 0;
}
 
int LCS_Length(char X[] ,char Y[]){
  int i,j;
  x = strlen(X);
  y = strlen(Y);
   
  for(i=1;i<=x;i++){
    c[i][0] = 0;
  }
  for(j=0;j<=y;j++){
    c[0][j] = 0;
  }
   
  for(i=1;i<=x;i++){
    for(j=1;j<=y;j++){
      if(X[i-1]==Y[j-1]){
    c[i][j]=c[i-1][j-1]+1;
      }
      else if(c[i-1][j]>=c[i][j-1]){
    c[i][j]=c[i-1][j];
      }
      else{
    c[i][j]=c[i][j-1];
      }
    }
  }
  return c[x][y];
}

Measured memory_bytes: 4524
def main():
    A, B, K = map(int, input().split())

    end = min(A+K, B)
    for i in range(A, end):
        print(i)

    start = B-K+1
    if end >= start:
        start = end
    for i in range(start, B+1):
        print(i)


if __name__ == '__main__':
    main()


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

using namespace std;

int main(){
	int n;
	cin >> n;
	if(n % 2 == 0){
		cout << n/2 - 1 << endl; 
	} else {
		cout << (n-1)/2 << endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<class T, class Func = function<T(T, T)>>
class segtree {
    vector<T> obj;
    int offset;
    Func updater;
    T e;
    int bufsize(int num) {
        int i = 1;
        for (; num + 1 >i; i <<= 1);
        offset = i - 1;
        return (i << 1) - 1;
    }
    T query(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l)return e;
        if (a <= l && r <= b)return obj[k];
        else return updater(query(a, b, k * 2 + 1, l, (l + r) / 2), query(a, b, k * 2 + 2, (l + r) / 2, r));
    }
public:
    T query(int a, int b) {//[a,b)
        return query(a, b, 0, 0, offset + 1);
    }
    void updateall(int l = 0, int r = -1) {
        if (r < 0)r = offset + 1;
        l += offset, r += offset;
        do {
            l = (l - 1) >> 1, r = (r - 1) >> 1;
            for (int i = l; i < r; i++)obj[i] = updater(obj[i * 2 + 1], obj[i * 2 + 2]);
        } while (l);
    }
    void update(int k, T &a) {
        k += offset;
        obj[k] = a;
        while (k) {
            k = (k - 1) >> 1;
            obj[k] = updater(obj[k * 2 + 1], obj[k * 2 + 2]);
        }
    }
    segtree(int n, T e, const Func &updater = Func()) :obj(bufsize(n), e), e(e), updater(updater) {}
    segtree(vector<T> &vec, T e, const Func &updater = Func()) :obj(bufsize(vec.size()), e), e(e), updater(updater) {
        copy(vec.begin(), vec.end(), obj.begin() + offset);
        updateall();
    }
    typename vector<T>::reference operator[](int n) {
        return obj[n + offset];
    }
};
int main(){
    Int N; cin >> N;
    vector<Int>v(N);
    for(auto& e : v) cin >> e;
    auto sgt = segtree<Int>((int)N,0LL,[](Int a, Int b){return a + b;});
    Int ans = 0;
    while(true){
        bool flag = true;
        for(int i = 0; i < v.size(); ++i){
            Int num = sgt.query(0,i) + sgt.query(i + 1,(int)N) + v[i];
            Int m = num % N;
            Int r = num / N;
            if(r > 0) flag  = false;
            ans += r;
            v[i] = m;
            sgt.update(i,r);
        }
        if(flag) break;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

bool equals(int a[3], int b[3], int c[3]){
	rep(i,3){
		if(not (a[i] == b[i] and b[i] == c[i])){
			return false;
		}
	}
	return true;
}

int main(){
	int a[3][3];
	rep(i,3){
		rep(j,3){
			cin >> a[i][j];
		}
	}

	int l1[3], l2[3], l3[3];
	rep(a1,101){
		rep(i,3) l1[i] = a[0][i] - a1;
		rep(a2,101){
			rep(i,3) l2[i] = a[1][i] - a2;
			rep(a3,101){
				rep(i,3) l3[i] = a[2][i] - a3;
				if(equals(l1, l2, l3)){
					cout << "Yes" << endl;
					return 0;
				}
			}
		}
	}
	cout << "No" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC

const int INF = 1e9;
int solve(string s, int up) {
    int n = s.size();
    vector <int> pref(n + 1);
    for (int i = 0; i < n; ++i) {
        int x;
        if (s[i] == '1')
            x = 1;
        else
            x = -1;

        pref[i + 1] = pref[i] + x;            
    }   

    vector <int> suff(n + 1, -INF);
    for (int i = n - 1; i >= 0; --i)
        suff[i] = max(suff[i + 1], pref[i + 1]);

    int rem = 0, cur = 0;
    int mn = 0;
    for (int i = 0; i < n; ++i) {
        if (s[i] == '?') {
            if (suff[i] + 2 * (rem + 1) <= up) {
                ++rem;
                ++cur;
            }   
            else {
                --cur;
            }   
        }   
        else if (s[i] == '1') {
            ++cur;
        }   
        else {
            --cur;
        }   

        //cout << "cur : " << cur << endl;
        
        mn = min(mn, cur);
    }
    return up - mn;
}   

signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif  

    string s;
    cin >> s;

    int n = s.size();

    int mx = 0, cur = 0;
    for (int i = 0; i < n; ++i) {
        if (s[i] == '1') {
            ++cur;
        }   
        else {
            --cur;
        }   
        mx = max(mx, cur);        
    }   
    
    cout << min(solve(s, mx), solve(s, mx + 1)) << endl;
}

Measured memory_bytes: 21812
#include <bits/stdc++.h>
using namespace std;
int main(){
     int x,y;
     cin >> x >> y;
     if(y%2 != 0){ 
       cout<<"No"<<endl;
     }else { 
       int a,b;
       b = (y/2)-x;
       a = 2*x - (y/2);
       if(a >= 0 && b>= 0){ 
         cout<<"Yes"<<endl;
       }else{ 
         cout<<"No"<<endl;
       }
     }


}    

Measured memory_bytes: 3632
"""
author : halo2halo
date : 4, Feb, 2020
"""

import sys
# import itertools
# import math
# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


A, B = map(int, readline().split())
print(A*B//gcd(A,B))

Measured memory_bytes: 3060
#D
n = int(input())
work = []
for i in range(n):
    a,b = map(int,input().split())
    work.append([a,b])
#締め切りの早さでソート
work.sort(key=lambda x:x[1])

time = 0
flg = True
for i in range(n):
    time += work[i][0]
    if time > work[i][1]:
        flg = False
        break
        
if flg:
    print('Yes')
    
else:
    print('No')

Measured memory_bytes: 38028
T = int(input())

ABCD = []
for i in range(T):
    a,b,c,d = map(int,input().split())
    ABCD.append((a,b,c,d))

for abcd in ABCD:
    a,b,c,d = abcd
    # 初日にダメになる
    if a < b:
        print("No")
    # 在庫補充が追いつかない
    elif d < b:
        print("No")
    # 補充タイミングが十分に早い
    elif c >= b:
        print("Yes")
    else:
        #print(a,b,c,d,a%b,d%b)
        e = a%b
        f = d%b
        list = [a]
        if f==0:
            if c<e<b:
                print("No")
            else:
                print("Yes") 
        else:
            cnt = 0
            while cnt < 100:
                g = ((c-e)//f+1)*f+e
                if g < b:
                    print("No")
                    cnt += 10000
                else:
                    if g in list:
                        print("Yes")
                        cnt += 10000
                    else:
                        list.append(g)
                        a = g
                        e = a%b
                        f = d%b
                        cnt += 1


Measured memory_bytes: 3064
#include<iostream>
    #include<math.h>
    #include<iomanip>
    #include<vector>
	#include<algorithm>
    using namespace std;
    #define PI 3.14159265358979
	#define rep(i,n) for(int i=0;i<n;i++)
   #include<queue>


int main(void)
{
    int N,M;
     

    cin>>N>>M;
    priority_queue<int> price;

    for(int i=0;i<N;i++) 
    {   
        int a;
        cin>>a;
        price.push(a);

    } 


    for(int i=0;i<M;i++)
    {
	int p = price.top(); price.pop();

    p = floor(p/2);
    price.push(p);
    }

    long money=0;
    rep(i,N)
    {
        money += price.top(); price.pop();
    }

    cout<<money<<endl;
}





Measured memory_bytes: 892
#include <iostream>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <cmath>
#define INF 100000000
#define ll long long int

using namespace std;

int main(){
  int N,Q; cin>>N>>Q;
  string s; cin>>s;
  s = 'X' + s + 'Y';

  vector <int> dp; dp.resize(s.size()+10,0);

  for(int i=1;i<s.size();i++){
    if(s[i] == 'C' and s[i-1] == 'A'){

      dp[i] = dp[i-1] + 1;

    } else {
      dp[i] = dp[i-1];
    }
  }

  vector <int> R; vector<int> L;

  for(int i=0;i<Q;i++){
    int l,r; cin>>l>>r;
    L.push_back(l);
    R.push_back(r);

  }


  for(int i=0;i<Q;i++){
    
    cout<<dp[R[i]] - dp[L[i]]<<endl;
  }

  return 0;
}

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

int n, m, G[777][777], col[777], c[2];
bitset<777>f;

void dfs(int x,int fl){
  if (col[x]==-1) col[x]=fl;
  else{
    if (col[x]!=fl){
      puts("-1"); exit(0);
    }
    return;
  }
  col[x]=fl; ++c[fl];
  for (int y=1;y<=n;++y)
    if (!G[x][y]&&y!=x)
      dfs(y,fl^1);
}

int main(){
  int x, y;
  cin>>n>>m;
  for (int tim=m;tim--;){
    scanf("%d%d",&x,&y);
    G[x][y]=G[y][x]=1;
  }
  f[0]=1;
  memset(col,-1,sizeof col);
  for (int i=1;i<=n;++i)
    if (col[i]==-1){
      c[0]=c[1]=0;
      dfs(i,0);
      f=(f<<c[0])|(f<<c[1]);
    }
  int ans=1e8;
  for (int i=0;i<=n;++i)
    if (f[i]) ans=min(ans,i*(i-1)/2+(n-i)*(n-i-1)/2);
  cout<<ans<<endl;
}


Measured memory_bytes: 2432
package main

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

func main() {
	var n int
	fmt.Scan(&n)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	as := make([]int, n)
	for i := range as {
		sc.Scan()
		as[i], _ = strconv.Atoi(sc.Text())
	}
	sort.Sort(sort.Reverse(sort.IntSlice(as)))
	ans := as[0]
	for i := 2; i < n; i++ {
		ans += as[i/2]
	}
	fmt.Println(ans)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}


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


void solve(long long A, long long B, long long C, long long K){
if(A>=K)cout<< K <<endl;
else if((A+B>=K)&&(A<K))cout<< A <<endl;
else if((A+B+C>=K)&&(A+B<K))cout<< A-(K-B-A) <<endl;
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    long long K;
    scanf("%lld",&K);
    solve(A, B, C, K);
    return 0;
}


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

using namespace std;

int main(int argc, char *argv[])
{
    vector<vector<int>> v(100005);
    int N, M, H[100005];

    cin >> N >> M;
    for (int i = 1; i <= N; i++) {
        cin >> H[i];
    }

    for (int i = 1; i <= M; i++) {
        int A, B;
        cin >> A >> B;
        v[A].push_back(B);
        v[B].push_back(A);
    }

    int ans = 0;
    for (int i = 1; i <= N; i++) {
        int sz = v[i].size();
        if (sz == 0) {
            ans++;
            continue;
        }
        bool b = true;
        for (auto x : v[i]) {
            if (H[i] <= H[x]) {
                b = false;
                break;
            }
        }
        if (b) {
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 8804
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long

int main(){
	ll n,a,b;
	scanf("%lld %lld %lld",&n,&a,&b);
	ll *x = (ll *)malloc(sizeof(ll) * n);
	FOR(i,0,n) scanf("%lld",&x[i]);

	ll sum = 0;
	FOR(i,0,n-1){
		ll tmp = (x[i+1]-x[i])*a<b ? (x[i+1]-x[i])*a:b;
		sum += tmp;
	}
	printf("%lld\n",sum);
}

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

int main() {
	int d[3];
	scanf("%d%d%d", &d[0], &d[1], &d[2]);
	for (int i = 0; i < 3; i++) {
		for (int j = i + 1; j < 3; j++) {
			if (d[i] > d[j]) {
				int tmp = d[i];
				d[i] = d[j];
				d[j] = tmp;
			}
		}
	}
	printf("%d", d[0] + d[1]);







}


Measured memory_bytes: 128
#include<iostream>
#include<set>
#include<string>

using namespace std;

int main() {
	int n;
	cin >> n;
	int last = -1;
	set<string> s;
	for (int i = 0; i < n; i++) {
		string x;
		cin >> x;
		if (last == -1 || last == x[0]) {
			last = x.back();
			if (s.count(x)) {
				cout << "No" << endl;
				return 0;
			}
			s.emplace(x);
		}
		else {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pl;

#define sl(x) scanf("%lld",&x)
#define pl(x) printf("%lld\n",x)
#define sz(x) ((int)x.size())
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define rs(v) { s(v) ; r(v) ; }
#define r(v) {reverse(all(v));}
#define pb push_back
#define F first
#define S second
#define f(i,n) for(ll i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)

const ll mod = 1000000007;
const ll inf = (ll)5e16;
const ld eps = 1e-12;
const ll N = 1000005;
const ll LOGN = 19;
const ld PI = 3.14159265358979323846;
ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
ll power(ll a, ll b, ll m = mod) { if(b == 0) return 1; if(b == 1) return (a % m); ll x = power(a, b / 2, m); x = mul(x, x, m); if(b % 2) x = mul(x, a, m); return x;}
ll is[105];
int main()
{
    ios_base::sync_with_stdio(0);
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    for(ll i = a; i < b; i++) is[i]++;
    for(ll i = c; i < d; i++) is[i]++;
    ll ans = 0;
    for(ll i = 0; i <= 100; i++) ans += (is[i] == 2);
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define fore(i, b, e) for (int i = (int)(b); i <= (int)(e); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long i64;
typedef unsigned long long u64;
typedef long double ld;
typedef long long ll;
// #define sz(x) int((x).size())
const int inf  = 1e9;

const int maxn = 305;

int n, m;
char s[maxn][maxn];
int mm[maxn][maxn];

int d[maxn][maxn];

void scan() {
    cin >> n >> m;
    forn(i, n) cin >> s[n-i-1];
    forn(i, max(n, m)) forn(j, i) swap(s[i][j], s[j][i]);
    swap(n, m);
}

void relax(int &x, int y) { x = min(x, y); }

void solve() {
    i64 res = 0;
    forn(i, n-1) {
        fore(x, 0, m) mm[0][x] = mm[x][0] = 0;
        fore(x, 1, m) fore(y, 1, m) {
            mm[x][y] = mm[x-1][y-1] + (s[i][m-x] == s[i+1][m-y]);
        }

        forn(x, m+2) forn(y, m+2) d[x][y] = inf;
        d[0][0] = 0;
        forn(x, m+1) forn(y, m+1) {
            if (x != m) relax(d[x+1][y], d[x][y] + mm[m-x][m-y]);
            if (y != m) relax(d[x][y+1], d[x][y] + mm[m-x][m-y]);
//             cerr << x << " " << y << ": " << d[x][y] << endl;
        }
        res += d[m][m];
        cerr << i << ": " << d[m][m] << endl;
    }
    cout << res << endl;
}

int main() {
#ifdef LOCAL
    freopen("d.in", "r", stdin);
#endif

    scan();
    solve();

#ifdef LOCAL
    cerr << "Time elapsed: " << clock() / 1000 << " ms" << endl;
#endif
    return 0;
}


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

int main(){

	string n;
	cin >> n;
	string ans = "No";
	if(n[0] == n[1] && n[1] == n[2]) ans = "Yes";
	else if(n[1] == n[2] && n[2] == n[3]) ans = "Yes";
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> 
using namespace __gnu_pbds; 
using namespace std;

#define ld long double
#define int long long
#define pb push_back 
#define Z(c) (int)(c).size()
#define L(c) c[Z(c)-1]
#define F first
#define S second
#define nl "\n"
#define mii map<int,int> 
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define rep(i,iv,n) for(int (i)=(iv);(i)<(n);++(i))
#define FO fflush(stdout) 
#define D1(x) cerr <<"At line "<<__LINE__<<" "<<#x<<"="<<x<<nl
#define D2(x,y) cerr <<"At line "<<__LINE__<<" "<<#x<<"="<<x<<" "<<#y<<"="<<y<<nl
#define D3(x,y,z) cerr <<"At line "<<__LINE__<<" "<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<nl
#define tr(it,ct) for(auto &(it) : (ct))
#define pi acos(-1)
#define prt(ct) for(auto &(it) : (ct)) cerr<<it<<" "; cerr<<nl
#define prtp(ct) for(auto &(it) : (ct)) cerr<<it.F<<" "<<it.S<<nl; cerr<<nl

typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > pii;
typedef vector< pii > vp;
typedef tree<int, null_type, less<int>, rb_tree_tag, 
             tree_order_statistics_node_update> baap;

void swap(char &a,char &b)
{ auto tm=a; a=b; b=tm; }
                                   
 
  const int mod=1000000007;
  const int mod2=998244353;
  const int INF=2e18+18;
  const int N=2e6+25;
  const int M=2e4;
  
  vector<int> z_function(string s) {
    int n = (int) s.length();
    vector<int> z(n);
    for (int i = 1, l = 0, r = 0; i < n; ++i) {
        if (i <= r)
            z[i] = min (r - i + 1, z[i - l]);
        while (i + z[i] < n && s[z[i]] == s[i + z[i]])
            ++z[i];
        if (i + z[i] - 1 > r)
            l = i, r = i + z[i] - 1;
    }
    return z;
}

 void fft()           
 { 
   int n; cin>>n; mii m; vi v(n);
   tr(i,v){
     cin>>i; m[i]++;
   }

   int ans=0;
   tr(i,m){
     ans+=(i.S*(i.S-1))/2;
   }

   tr(i,v){
      cout<<ans-(m[i]-1)<<nl;
   }
   
 }     

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

 
   
   int t=1;                         
//   cin>>t;

  rep(i,1,t+1)
  { // cout<<"Case #"<<i<<": ";
   fft();
   if(i<t)
   cout<<nl;
  }

 return 0; 
}

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

int main() {
    int r,g,b,x;
    cin >> r >> g >> b;
    x = r*100 + g*10 + b;
    if (x%4) {
        cout << "NO" << endl;
    } else {
        cout << "YES" << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<bitset>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
constexpr auto INF = 1000000000;
constexpr auto LLINF = 1LL << 62;
constexpr auto mod = 1000000007;
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 n;
    cin >> n;
    string s;
    set<string> set;
    map<string, ll> map;
    FOR(i, 0, n) {
        cin >> s;
        SORT(s);
        map[s]++;
        set.insert(s);
    }

    ll ans = 0;
    auto itr = set.begin();
    FOR(i, 0, set.size()) {
        ans += map[*itr] * (map[*itr] - 1) / 2;
        itr++;
    }

    cout << ans << "\n";
}

Measured memory_bytes: 20608
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60


bool ACGT(char c) {
	if (c == 'A') return true;
	else if (c == 'C') return true;
	else if (c == 'G') return true;
	else if (c == 'T') return true;
	else return false;
}


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

	string S; cin >> S;

	int ans = 0;
	for (int i = 0; i < S.size(); i++) {
		for (int j = i; j < S.size(); j++) {
			bool flag = true;
			for (int k = i; k <= j && flag; k++) {
				if (!ACGT(S[k])) flag = false;
			}

			if (flag) ans = max(ans, j - i + 1);
		}
	}

	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 256
#PDF解説
N = int(input())
Red, Blue = [], []
for n in range(N):
  Red.append([int(ab) for ab in input().split()])
Red.sort(key=lambda x: x[1], reverse=True)
for n in range(N):
  Blue.append([int(cd) for cd in input().split()])
Blue.sort(key=lambda x: x[0])

pairs = 0
for B in Blue:
  c, d = B
  for R in Red:
    a, b = R
    if a < c and b < d:
      pairs += 1
      Red.remove(R)
      break

print(pairs)

Measured memory_bytes: 3064
input_text = input()
input_text = input_text.split(" ")
list_int = []
for _ in input_text:
    list_int.append(int(_))

distance = list_int[2] * list_int[1]
if distance >= list_int[0]:
    reslut = "Yes"        
else:
    reslut = "No"


print(reslut)

Measured memory_bytes: 8976
n = int(input())
s = []
h = []
c = []
d = []
for i in range(n):
    card, num = map(str, input().split())
    if card == 'S':
        s.append(int(num))
    elif card == 'H':
        h.append(int(num))
    elif card == 'C':
        c.append(int(num))
    else:
        d.append(int(num))      
for i in range(1, 14):
    if i not in s:
        print(f'S {i}')
for i in range(1, 14):
    if i not in h:
        print(f'H {i}')
for i in range(1, 14):
    if i not in c:
        print(f'C {i}')
for i in range(1, 14):
    if i not in d:
        print(f'D {i}')


Measured memory_bytes: 5612
sub f{my$r=$u["@_"]=1;$u[$_]||($r+=f($_))for@{$G["@_"]};$r}($n,$m)=glob<>;/ /,push@{$G[$`]},$'+!push@{$G[$']},$`for<>;$a=f 1;$a-=$-=$a- f(2);print$n*~-$n/2-$a*($n-$a)-$m

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
//#define int long long

using namespace std;

//v.push_back(123);
//sort(v.begin(), v.end(),greater<int>());
//for(int x : v) {cout << x << endl;}

//for(int x: v) cout << x << endl;
//vector<vector<char>> v(H, vector<char>(W));
//vector<int> v(1000);

long long mod_pow(long long x,long long y, long long MOD){
	long long ret = 1;
	while(y){
		if (y & 1) ret = ret * x % MOD;
		x = x * x % MOD;
		y>>=1;
	}
	return ret;
}

signed main(){
  string L;
  cin>>L;
  int N = L.length();
  //rep(i, 100010) aiueo[i]=-1;
  //calculation(100009);
  vector<int> v;
  int count = 0;
  int MOD = 1000000007;
  long long result=0;
  rep(i, N){
     if(L[i]=='1'){
       result += (mod_pow(2, count, MOD))%MOD*(mod_pow(3, (long long)(N-i-1), MOD));
       result = result % MOD;
       count++;
     }
  }
  result += mod_pow(2, count, MOD);
  result = result % MOD;

  cout << result << endl;
  
  return 0;
}


Measured memory_bytes: 512