akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main()
{
  int H, W;
  cin >> H >> W;
  vector<string> S(H);
  for (int i = 0; i < H; i++)
  {
    cin >> S[i];
  }

  vector<vector<int>> visited(H, vector<int>(W, -1));
  int ans = 0;
  const vector<int> dy = {1, 0, -1, 0};
  const vector<int> dx = {0, 1, 0, -1};

  for (int sy = 0; sy < H; sy++)
  {
    for (int sx = 0; sx < W; sx++)
    {
      for (int gy = 0; gy < H; gy++)
      {
        for (int gx = 0; gx < W; gx++)
        {
          if (!(0 <= sy && sy < H && 0 <= sx && sx < W))
            continue;
          if (visited[sy][sx] != -1)
            continue;
          if (S[sy][sx] == '#')
            continue;

          queue<pair<int, int>> Q;
          Q.push(make_pair(sy, sx));
          visited[sy][sx] = 0;
          while (!Q.empty())
          {
            int y = Q.front().first, x = Q.front().second;
            Q.pop();

            for (int i = 0; i < 4; i++)
            {
              int ny = y + dy[i], nx = x + dx[i];

              if (!(0 <= ny && ny < H && 0 <= nx && nx < W))
                continue;
              if (S[ny][nx] == '#')
                continue;
              if (visited[ny][nx] != -1)
                continue;

              Q.push(make_pair(ny, nx));
              visited[ny][nx] = visited[y][x] + 1;
              ans = max(ans, visited[ny][nx]);
            }
          }

          fill(visited.begin(), visited.end(), vector<int>(W, -1));

          //cerr << sy << sx << gy << gx << ans << endl;
        }
      }
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BitStringReordering solver = new BitStringReordering();
        solver.solve(1, in, out);
        out.close();
    }

    static class BitStringReordering {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            int M = in.nextInt();
            int[] b = new int[N];
            int[] p = new int[M];
            for (int i = 0; i < N; i++) {
                b[i] = in.nextInt();
            }
            for (int i = 0; i < M; i++) {
                p[i] = in.nextInt();
            }
            out.println(Math.min(calc(b.clone(), p, 0, 1), calc(b.clone(), p, 1, 0)));
        }

        public int calc(int[] bit, int[] num, int a, int b) {
            int[] d = {a, b};
            final int L = bit.length;
            int[] result = new int[L];
            int idx = 0, cnt = 0;
            for (int el : num) {
                for (int i = 0; i < el; i++) {
                    result[idx++] = d[cnt];
                }
                cnt = (cnt + 1) % 2;
            }
            assert idx == L;
            if (Arrays.stream(bit).sum() != Arrays.stream(result).sum()) {
                return (int) 1e9;
            }
            int res = 0;
            for (int i = 0; i < L; i++) {
                if (bit[i] != result[i]) {
                    for (int j = i + 1; j < L; j++) {
                        if (result[i] == bit[j]) {
                            for (int k = j; k > i; k--) {
                                swap(bit, k, k - 1);
                            }
                            res += j - i;
                            break;
                        }
                    }
                }
            }
            return res;
        }

        public void swap(int[] ar, int i1, int i2) {
            int buf = ar[i1];
            ar[i1] = ar[i2];
            ar[i2] = buf;
        }

    }
}

Measured memory_bytes: 32388
#include<bits/stdc++.h>
using namespace std ;
#define int long long
#define ld long double
#define fast ios_base::sync_with_stdio(false) ;cin.tie(NULL);cout.tie(NULL)
#define F(i,a,b) for(int i= (int)(a); i<(int)(b);i++)
#define FI(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define RF(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define what_is(x) cerr << #x << " is " << x << endl;
#define ms(x,a) memset(x,(int)(a),sizeof(x))
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pii pair<int,int>
#define vi vector<int >
#define pb push_back
#define endl '\n'
#define mp make_pair
#define ff first
#define ss second
#define MOD 1000000007
int n , m ;
const int N = 1e5 + 7 ;
int par[N] ;
int siz[N] ;
int rnk[N] ;
void init(){
	for(int i = 0 ; i < n ; i++){
		par[i] = i ;
		siz[i] = 1 ;
		rnk[i] = 0 ;
	}
}
int fnd(int x){
	if(x == par[x])
		return x ;
	return par[x] = fnd(par[x]) ;
}

void unite(int x,int y){
// rank optimization
	if(x == y)
		return ;
		 
	x = fnd(x) ;
	y = fnd(y) ;
	if(rnk[x] > rnk[y]) // y is bap
		swap(x,y) ;
	par[x] = y ;
	siz[y] += siz[x] ;
	if(rnk[x] == rnk[y]){
		rnk[y]++ ;
	}
		
}
int32_t main(){fast ;
	cin >> n >> m ;
	init() ;
	vector<pii> p(m) ;
	vector<int> ans(m+1,0) ;
	for(int i = 0 ; i < m ; i++)
		cin >> p[i].ff >> p[i].ss ;
	ans[m] = n*(n-1)/2 ;
	for(int i = m-1 ; i >= 0 ; i--){
		int u = p[i].ff ;
		int v = p[i].ss ;
		--u ; --v ;
		if(fnd(u) == fnd(v))
			ans[i] = ans[i+1] ;
		else{
			ans[i] = ans[i+1] - (siz[par[u]] * siz[par[v]]) ;
			unite(u,v) ; 
		}
	}
	for(int i = 1 ; i <= m ; i++)
		cout << ans[i] << ' ' ;
	cout << endl ;
}

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

bool u[1000001];
int pr[500000];

int main()
{
  int i,j;
  int l=0;
  memset(u,true,sizeof(u));
  for (i=2;i<=1000000;i++)
  {
    if (u[i]) {
      l++;
      pr[l]=i;
    }
    for (j=1;j<=l&&pr[j]<=1000000/i;j++)
    {
      u[i*pr[j]]=false;
      if (i%pr[j]==0) break;
    }
  }
  long long n,p;
  scanf("%lld%lld",&n,&p);
  if (n==1) printf("%lld\n",p);
  else {
  long long res=1;
  for (i=1;i<=l&&p>1;i++) {
    int cur=0;
    while (p%pr[i]==0) {
      cur++;
      p=p/pr[i];
    }
    for (j=1;j<=cur/n;j++)
      res=res*pr[i];
  }
  printf("%lld\n",res);
  }
  return 0;
}

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

using namespace std;

int main() {
  long long a;
  string b;
  cin >> a >> b;
  long long c = (b.at(0) - '0') * 100 + (b.at(2) - '0') * 10 + b.at(3) - '0';
  c = c * a;
  c /= 100;
  cout << c;
  return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main(void){

    string s;
    cin >> s;
    
    int count = 0;
    for(int i=1; i<3; i++) {
        if(s.substr(i,1) == s.substr(0,1)) {
            count++;
        }
    }

    if(count == 2) {
        cout << "No" << endl;
    }
    else {
        cout << "Yes" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const double pi=acos(-1.0);
const double eps=1e-8;
typedef long long ll;
#define equ(a,b) ((fabs((a)-(b)))<(eps))
#define more(a,b) (((a)-(b))>(eps))
#define less(a,b) (((a)-(b))<(-eps))
#define inf 0x3f3f3f3f

int main(){
    int n,k;
    int a[1005];
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    int s=0;
    for(int i=0;i<k;i++){
        s+=a[i];
    }
    cout<<s;
    return 0;
}

Measured memory_bytes: 3600
#include <cstdio>
#include <vector>
using namespace std;

const int MAXN = 200005;

int a[MAXN];
vector <int> sol;

int main() {
	int N, X;
	scanf("%d%d", &N, &X);
	
	if (X == 1 || X == 2 * N - 1) {
		puts("No");
		return 0;
	}
	
	sol.push_back(X);
	for (int i = 1; i < 2 * N; i++)
		if (i != X)
			sol.push_back(i);
			
	for (int i = 0; i < 2 * N - 1; i++)
		a[(N - 1 + i) % (2 * N - 1)] = sol[i];
	
	puts("Yes");
	for (int i = 0; i < 2 * N - 1; i++)
		printf("%d\n", a[i]);
		
	return 0;
}

Measured memory_bytes: 3188
#include <stdio.h>
#include <stdlib.h>
int cmp(const void *a,const void *b){
	return *(int *)a-*(int *)b;
}
int main(void){
	int n,c,k,t[100000],i,ans=0,tmp,cnt;
	scanf("%d %d %d",&n,&c,&k);
	for(i=0;i<n;i++){
		scanf("%d",&t[i]);
	}
	qsort(t,n,sizeof(int),cmp);
	for(i=0;i<n;){
		ans++;
		cnt=1;
		tmp=t[i]+k;
		for(i++;cnt<c&&t[i]<=tmp&&i<n;cnt++,i++){
			;
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 892
package main

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

var dp []int64

func getNextWord(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextWord(scanner))
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
  scanner.Buffer(make([]byte, 500001), 500000)
	n := getNextInt(scanner)
	aList := make([]int, n)
	hList := make([]int, n)
	for i := 0; i < n; i++ {
		hList[i]=getNextInt(scanner)
	}
	for i := 0; i < n; i++ {
		aList[i]=getNextInt(scanner)
	}

	segSize := 1
	for segSize < n {
		segSize = segSize << 1
	}
	dp = make([]int64, segSize*2)
	for i := 0; i < n; i++ {
		dp[segSize-1+hList[i]-1] = int64(aList[i]) + query(0, hList[i]-1, 0, 0, segSize)
		update(segSize - 1 + hList[i] - 1)
	}
	fmt.Println(query(0, n, 0, 0, n))
}

func query(a int, b int, k int, l int, r int) int64 {
	if b <= l || r <= a {
		return int64(0)
	}
	if a <= l && r <= b {
		return dp[k]
	}
	vl := query(a, b, k*2+1, l, (l+r)/2)
	vr := query(a, b, k*2+2, (l+r)/2, r)
	if vl < vr {
		return vr
	}
	return vl
}

func update(i int) {
	for i > 0 {
		i = (i - 1) / 2
		dp[i] = dp[i*2+1]
		if dp[i] < dp[i*2+2] {
			dp[i] = dp[i*2+2]
		}
	}
}


Measured memory_bytes: 12928
import sys

H,W=map(int,input().split())
L=[[x for x in input()] for _ in range(H)]
ans='Yes'

for i in range(H):
  for j in range(W):
    if L[i][j]=='.':
      continue
    else:
      try:
        if L[i][j+1]=='#':
          continue
      except:
        pass
      try:
        if L[i][j-1]=='#':
          continue
      except:
        pass
      try:
        if L[i-1][j]=='#':
          continue
      except:
        pass
      try:
        if L[i+1][j]=='#':
          continue
      except:
        pass
      print('No')
      sys.exit()
      
print('Yes')

Measured memory_bytes: 9132
n, y = gets.split.map(&:to_i)

n.downto(0) do |a|
  a_yen = a * 10000

  next if a_yen > y
  (n-a).downto(0) do |b|
    b_yen = b * 5000
    c = n - a - b
    c_yen = c * 1000

    if (a_yen + b_yen + c_yen) == y
      puts "#{a} #{b} #{c}"
      exit
    end
  end
end

puts "-1 -1 -1"


Measured memory_bytes: 14316
using System;

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

		int sum = A + B;
		int mul = A * B;
		int sub = A - B;

      	int max = Max(sum, mul);
		max = Max(max, sub);

		Console.WriteLine(max);      	
	}
  
    static int Max(int a, int b)
    {
      if (a > b)
      {
        return a;
      }
      else
      {
        return b;
      }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
 
using namespace std;
 
string S;
string T;
string finalAns;
int cnt = 0;
int isPossible;
int ans;
int pos = -1;
 
int main()
{
	cin >> S;
	cin >> T;
 
	for(int i = 0; i < S.size() - T.size() + 1; i++)
	{
		isPossible = 1;
		for(int j = 0; j < T.size(); j++)
		{
			if(S[i + j] == T[j] || S[i + j] == '?')
			{
				continue;
			}
			else
			{
				isPossible = 0;
			}
		
		}
			// cout << isPossible;
		if(isPossible)
		{
			pos = i;
		}
	}
	if(pos >= 0)
	{
		for(int i = 0; i < T.size(); i++)
		{
		
			S[pos + i] = T[i];
 
		}
		for(int i = 0; i < S.size(); i++)
		{
			if(S[i] == '?')
			{
				S[i] = 'a';
			}
		}
		cout << S;
	}
	else
	{
		cout << "UNRESTORABLE";
	}
 
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
constexpr int kMax = 1e4 + 1;
typedef long long LL;

int f(int x, int y, int z) {
  return x*x + y*y + z*z + x*y + y*z + z*x;
}

int dp[kMax] = {};
int main() {
  int N; cin >> N;

  for (int x = 1; f(x, 1, 1) <= N; ++x) {
    for (int y = 1; f(x, y, 1) <= N; ++y) {
      for (int z = 1; f(x, y, z) <= N; ++z) {
        int a = f(x, y, z); dp[a]++;
      }
    }
  }
  for (int i = 1; i <= N; ++i) cout << dp[i] << endl;
}


Measured memory_bytes: 3440
n = gets.chomp.to_i
hs = gets.chomp.split.map(&:to_i)

min_h = hs[0] - 1
(1...n).each do |i|
    h = hs[i]
    if h - 1 >= min_h
        min_h = h - 1
    elsif h >= min_h
        min_h = h
    else
        puts 'No'
        exit
    end
end

puts 'Yes'


Measured memory_bytes: 9604
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int N, K;
    cin >> N >> K;
    int res = 0;
    while(N > 0) {
        N /= K;
        res++;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n, ans;
int len[2010];
int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; i ++) {
		scanf("%d", &len[i]);
	}
	sort(len + 1, len + n + 1);
	for(int i = 1; i <= n; i ++) {
		for(int j = i + 1; j <= n; j ++) {
			int k = len[i] + len[j];
			int pos = lower_bound(len + 1, len + n + 1, k) - len - 1;
			if(pos > j) {
				ans += pos - j;
			}
		}
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
n=int(input())
d=[int(i) for i in input().split()]
mod = 998244353

if d[0]!=0:
    print(0)    
    exit()
for i in d[1:]:
    if i==0:
        print(0)
        exit()
    
    
d=sorted(d)
ans = 1
    
dic = defaultdict(int)
dic[0] = 1
for i in d[1:]:
    ans *= dic[i-1]
    ans = ans % mod
    dic[i] += 1
print(ans)
    
    

Measured memory_bytes: 20688
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

ll n, k, p[6000], c[6000];
bool use[6000];

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    
    cin >> n >> k;
    zep(i, 0, n){cin >> p[i]; p[i]--;}
    zep(i, 0, n)cin >> c[i];
    
    bool ng = true;
    zep(i, 0, n)if(c[i] >= 0)ng = false;
    if(ng){
        ll ansn = -INF;
        zep(i, 0, n)ansn = max(ansn, c[i]);
        print(ansn) return 0;
    }

    ll ans = 0;
    
    zep(i, 0, n){
    	if(!use[i]){
    		ll at = i, sm = 0, pe = 0;
    		
    		while(pe == 0 || at != i){
    			use[at] = true;
    			at = p[at];
    			sm += c[at];
    			pe++;
    		}
    		
    		ll res = 0;
    		if(sm > 0)res += (k / pe) * sm;
    		ll rk = k % pe;
    		
    		vector<ll> v;
    		at = i;
            ll cur = 0;
    		zep(j, 0, pe + rk){
    			at = p[at];
    			cur += c[at];
    			v.push_back(cur);
    		}
    		
    		ll resr = 0;
    		priority_queue<P> q;
		    zep(j, 0, pe + rk){
		    	q.push(P(-v[j], j));
		    	while(!q.empty() && j - q.top().second > rk)q.pop();
		    	
		    	resr = max(resr, v[j] + q.top().first);
		    }
		    
		    ans = max(ans, res + resr);
            
            if(k >= pe){
                res = 0;
                if(sm > 0)res += ((k - pe) / pe) * sm;
                rk = pe;

                while(!v.empty())v.pop_back();
                at = i, cur = 0;
                zep(j, 0, pe + rk){
                    at = p[at];
                    cur += c[at];
                    v.push_back(cur);
                }
                
                resr = 0;
                while(!q.empty())q.pop();
                
                zep(j, 0, pe + rk){
                    q.push(P(-v[j], j));
                    while(!q.empty() && j - q.top().second > rk)q.pop();
                    
                    //if(resr < v[j] + q.top().first)cout << j - q.top().second << " " << pe << endl;
                    resr = max(resr, v[j] + q.top().first);
                    
                }
                
                ans = max(ans, res + resr);
            }
            //cout << ans << " " << i << endl;
    	}
    }
    
    print(ans)
    
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    deque<int> a(n), b(0);

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

    int num=0;
    if(n%2==0) num++;

    for(int i=0; i<n; i++){
        if(i%2==num){
           b.push_front(a[i]); 
        }
        else b.push_back(a[i]);
    }

    for(int i=0; i<n; i++){
        cout << b[i] << " ";
    }
    cout << endl;

}

Measured memory_bytes: 3840
#include <stdio.h>

#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[N][N];
int color[N], d[N], f[N], tt;

void dfs_visit(int u) {
   int v;

   color[u] = GRAY;
   d[u] = ++tt;
   for (v = 0; v < n; v++) {
      if (M[u][v] == 0) {
         continue;
      }
      if (color[v] == WHITE) {
         dfs_visit(v);
      }
   }

   color[u] = BLACK;
   f[u] = ++tt;
}

void dfs() {
   int u;

   for (u = 0; u < n; u++) {
      color[u] = WHITE;
   }
   tt = 0;

   for (u = 0; u < n; u++) {
      if (color[u] == WHITE) {
         dfs_visit(u);
      }
   }
   for (u = 0; u < n; u++) {
      printf("%d %d %d\n", u + 1, d[u], f[u]);
   }
}

int main() {
   int u, v, k, i, j;

   scanf("%d", &n);
   for (i = 0; i < n; i++) {
      for ( j = 0; j < n; j++) {
         M[i][j] = 0;
      }
   }

   for (i = 0; i < n; i++) {
      scanf("%d %d", &u, &k);
      u--;
      for (j = 0; j < k; j++) {
         scanf("%d", &v);
         v--;
         M[u][v] = 1;
      }
   }

   dfs();

   return 0;
}

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

int main() {
  string n;
  bool ans = false;
  cin >> n;
  rep(i,3){
    if (n.at(i) == '7'){
      ans = true;
    }
  }
  if (ans){
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }  
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,ans;
  cin >> n;
  ans = 0;
  vector<int>a(n);
  for(int i = 0; i < n; i++){
    cin >> a.at(i);
  }
  for(int i = 0; i < n-2; i++){
    if((a.at(i+1)<a.at(i+2))&&(a.at(i)<a.at(i+1))||(a.at(i+1)<a.at(i))&&(a.at(i+2)<a.at(i+1))){
      ans += 1;
    }
        }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
using namespace std;
int f[111000];
int p[111000],m,n,a,b,c;
int find(int p)
{
	if(p!=f[p])
	{
		return f[p]=find(f[p]);
	}
	return p;
}
int main()
{
	cin>>n>>m;
	for(int x=1;x<=n;x++)
	{
		f[x]=x;
	}
	for(int x=0;x<m;x++)
	{
		cin>>a>>b>>c;
		int ax=find(a),bx=find(b);
		if(ax!=bx)
		{
			f[bx]=ax;
		}
	}	
	int ans=0;
	for(int x=1;x<=n;x++)
	{int q=find(x);
	
	if(x==q)
	{
		ans++; 
	} 
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 768
s = input()[::-1]
m = 2019
ans = 0
x = 1
tot = 0
cnt = [0] * m
cnt[0] = 1
for s in s:
    tot += int(s) * x
    tot %= m
    #ans += cnt[tot]
    x *= 10
    x %= m
    cnt[tot] += 1

print(sum(i*(i-1)//2 for i in cnt))


Measured memory_bytes: 9352
module Main where

import Control.Applicative
import Control.Monad
import Data.List

check :: [[Int]] -> Bool
check (xs:xss) = all (f xs) xss
  where
    f xs ys = any (== xs) [fmap (+ n) ys | n <- [-100 .. 100]]

main :: IO ()
main = do
    css <- replicateM 3 $ fmap read . words <$> getLine :: IO [[Int]]
    if check css
        then putStrLn "Yes"
        else putStrLn "No"

Measured memory_bytes: 636
def judge(m,i):
    if m==1:
        return 1
    elif m>0:
        if m%(2**i)==0:
            return 0
        else:
            return 1
    else:
        m = -m
        if m%(2**i)==0:
            return 0
        else:
            return 1

def examC():
    n = I()
    N = copy.deepcopy(n)
    i = 0
    ans = []
    while(N!=0):
        cur = judge(N,i+1)
#        print(cur,N)
#        input()
        N -=((-2)**i)*cur
        ans.append(cur)
        i +=1
    if not ans:
        ans = [0]
    print("".join(map(str,ans[::-1])))

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()

Measured memory_bytes: 38256
#G
import sys
sys.setrecursionlimit(10**9)

N,M = map(int, input().split())
x = [0] * M
y = [0] * M
edge=[[] for j in range(N+1)]
for i in range(M):
    x[i], y[i] = map(int, input().split())
    edge[x[i]]+=[y[i]]

dp=[0]*(N+1)

def f(x):
    if dp[x]!=0:
        return dp[x]
    num=0
    for i in edge[x]:
        if i==[]:
            num=max(num,0)
        else:
            num=max(num,f(i)+1)
    dp[x]=num
    return dp[x]

for i in range(1,N+1):
    f(i)
print(max(dp))

Measured memory_bytes: 120620
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author anand.oza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BBounding solver = new BBounding();
        solver.solve(1, in, out);
        out.close();
    }

    static class BBounding {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt(), x = in.nextInt();
            int answer = 1;
            int coord = 0;
            for (int i = 0; i < n; i++) {
                coord += in.nextInt();
                if (coord <= x)
                    answer++;
            }

            out.println(answer);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 21460
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
int a[200005];
int main()
{
    ios::sync_with_stdio(false);
    int n,c;cin>>n;
    for(int i=0;i<n-1;i++)
    {
        cin>>c;
        a[c]++;
    }
    for(int i=1;i<=n;i++)
        cout<<a[i]<<endl;
}



Measured memory_bytes: 4396
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/tag_and_trait.hpp>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0)
#define END return EXIT_SUCCESS
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR(I,0,N)
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) std::cin>>(P)
#define IN2(P1,P2) std::cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) std::cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP(I,N) std::cin>>V[I]
#define OUT(P) std::cout<<P<<std::endl
#define OUT2(P1,P2) std::cout<<P1<<" "<<P2<<std::endl
#define OUT3(P1,P2,P3) std::cout<<P1<<" "<<P2<<" "<<P3<<std::endl
#define OUTS(I,N,V) REP(I,N) std::cout<<V[i]<<std::endl
#define ALL(C) (C).begin(),(C).end()
using namespace std;
using namespace __gnu_pbds;
int s;
vector<int> v;
unsigned long i;
int t;
int size;
void f(int n){
  REP(i,v.size()){
    if(v[i]==n){
      OUT(v.size()+1);
      return;
    }
  }
  v.push_back(n);
  if(n%2){
    t=n*3+1;
    f(t);
  }else{
    t=n/2;
    f(t);
  }
}
inline void solve(){
  IN(s);
  f(s);
}

int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 256
package main

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

func main() {
	var (
		Input = ReadLineInt()
		A, B  = Input[0], Input[1]
		C, D  = Input[2], Input[3]
		X, Y  = C - A, D - B

		P, Q = C - Y, D + X
		R, S = A - Y, B + X
	)

	fln("%d %d %d %d", P, Q, R, S)
}

/////////////////////////////////////////

func fln(format string, elements ...interface{}) {
	fmt.Printf(format+"\n", elements...)
}

var BufReader = bufio.NewReaderSize(os.Stdin, 1e6)

func ReadLine() string {
	a, _, _ := BufReader.ReadLine()
	return string(a)
}

func ReadLineInt() (result []int) {
	in := strings.Split(ReadLine(), " ")
	result = make([]int, 0, 2)
	for _, v := range in {
		t, _ := strconv.Atoi(v)
		result = append(result, t)
	}
	return
}


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

#define pb push_back

using ll = long long;
using pii = pair<int, int>;

const ll inf = 1e15;

int main() {
    ios::sync_with_stdio(false);cin.tie(nullptr);
    int n, m;
    ll l; cin >> n >> m >> l;
    vector<vector<ll>> adj(n, vector<ll>(n));
    for (int i = 0; i < n; ++i) {
    	for (int j = 0; j < n; ++j) {
    		if (i != j) adj[i][j] = inf;
    	}
    }
    for (int i = 0; i < m; ++i) {
    	int a, b;
    	ll c;
    	cin >> a >> b >> c;
    	--a, --b;
    	adj[a][b] = adj[b][a] = c;
    }
    for (int k = 0; k < n; ++k) {
    	for (int i = 0; i < n; ++i) {
    		for (int j = 0; j < n; ++j) {
    			adj[i][j] = min(adj[i][j], adj[i][k] + adj[k][j]);
    		}
    	}
    }
    auto padj = adj;
    for (int i = 0; i < n; ++i) {
    	for (int j = 0; j < n; ++j) {
    		adj[i][j] = padj[i][j] <= l ? 1 : inf;
    		if (i == j) adj[i][j] = 0;
    	}
    }
    for (int k = 0; k < n; ++k) {
    	for (int i = 0; i < n; ++i) {
    		for (int j = 0; j < n; ++j) {
    			adj[i][j] = min(adj[i][j], adj[i][k] + adj[k][j]);
    		}
    	}
    }
    int Q; cin >> Q;
    while (Q--) {
    	int s, t; cin >> s >> t;
    	--s, --t;
    	if (adj[s][t] >= inf) cout << -1;
    	else cout << adj[s][t] - 1;
    	cout << "\n";
    }
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define endl "\n"
#define sz(x) (int)(x).size()
using namespace std;
typedef long long int lli;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
    int n, m;
    cin >> n >> m;
    cout << n*(n-1)/2 + m*(m-1)/2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int n;
    cin >> n;
    bool ret = false;
    for (int i = 1; i < 10; i++) {
        for (int j = 1; j < 10; j++) {
            if (n == i * j)ret = true;
        }
    }

    cout << (ret ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

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

		try {
			String[] data = in.readLine().split(" ");
			double a = Double.parseDouble(data[0]);
			double b = Double.parseDouble(data[1]);
			double c = Math.toRadians(Double.parseDouble(data[2]));

			System.out.println((a * b * Math.sin(c)) / 2);
			System.out.println(Math.sqrt((b * Math.sin(c)) * (b * Math.sin(c))
					+ (b * Math.cos(c) - a) * (b * Math.cos(c) - a)) + a + b);
			System.out.println(b * Math.sin(c));
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 24316
import sys
sys.setrecursionlimit(10**6)
n,m = map(int,input().split())
graph = [[] for _ in range(n)]
for i in range(m):
    x,y = map(lambda z:z-1,map(int,input().split()))
    graph[x].append(y)


dp = [-1]*n #dp[i]はiからスタートした有向pathのうち最長のものの長さ
#print(graph)
def solve(i):
    if dp[i] != -1:#既に計算済み
        return dp[i]
    if len(graph[i]) == 0:#iが葉であるとき
        dp[i] = 0
        return 0
    max_length = 0
    for next_node in graph[i]:
        dp[next_node] = solve(next_node)
        max_length = max(max_length,dp[next_node])

    dp[i] = max_length + 1
    return dp[i]

ans = 0
for i in range(n):
    ans = max(ans,solve(i))


print(ans)

Measured memory_bytes: 59056
import java.io.*;
 
class Main{
    public static void main(String[] args){
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        try {
                int W, H, x, y, r;
 
                String line = reader.readLine();
                String[] strAry = line.split(" ");
 
                W = Integer.parseInt(strAry[0]);
                H = Integer.parseInt(strAry[1]);
                x = Integer.parseInt(strAry[2]);
                y = Integer.parseInt(strAry[3]);
                r = Integer.parseInt(strAry[4]);
 
                if((x + r) <= W && (y + r) <= H && (x - r) >= 0 && (y - r) >= 0 ){
                    System.out.println("Yes");
                }else{
                    System.out.println("No");
                }
 
                 
        } catch (IOException e) {
            //TODO: handle exception
            System.out.println(e);
        }
    }
}

Measured memory_bytes: 24428
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <functional>
//#include <math.h>
using namespace std;
typedef long long LL;

int main()
{
	int A, B, C;
	cin >> A >> B >> C;

	int ma = (A > B) ? (A > C ? A : C) : (B > C ? B : C);
	int su = 3 * ma - (A + B + C);
	if (su & 1)
		su += 3;

	cout << su / 2 << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,r,n) for(ll i=(ll)(r);i<(ll)(n);++i)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define PB(n) push_back(n)
#define endl '\n'
#define DOUT(x) cout << #x << " = " << (x) << endl
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c
#define VIN(V) for(ll ii = 0; ii < (ll)(V).size(); ii++) {cin >> (V).at(ii);}
#define OUT(n) cout << n << endl
#define OUT2(n1,n2) cout << n1 << " " << n2 << endl
#define OUT3(n1,n2,n3) cout << n1 << " " << n2 << " " << n3 << endl
#define VOUT(V) REP(ii,(V).size()){cout << (V)[ii] << " ";} cout<<endl;
#define VOUT2(V) REP(jj,(V).size()){VOUT(V[jj])}
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<vi > vvi;
typedef vector<pair<ll, ll> > vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
const long long INF = numeric_limits<ll>::max();
constexpr long long MOD = 1000000007;
constexpr long double PI = 3.1415926;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
ll n, m, k, ans, sum, cnt = 0; string s; char c; bool flg;

int main(){
  cin.tie(0);ios::sync_with_stdio(false);
  // cout << fixed << setprecision(numeric_limits<double>::max_digits10);
  ll a,b,c,d;
  IN2(a,b);
  IN2(c,d);

  if (a+b>c+d) OUT("Left");
  else if (a+b<c+d) OUT("Right");
  else OUT("Balanced");
}


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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    string s;
    cin >> s;
    int n = sz(s);
    vi ans(n);
    int cnt = 0;
    rep(t, 2) {
        rep(i, n) {
            if (s[i]=='R') ++cnt;
            else if (i-1>=0 && s[i-1]=='R') {
                ans[i-1] += (cnt + 1) / 2;
                ans[i] += cnt / 2;
                cnt = 0;
            }
        }
        reverse(all(s));
        reverse(all(ans));
        rep(i, n) {
            if (s[i] == 'R') s[i] = 'L';
            else s[i] = 'R';
        }
    }
    rep(i, n) printf("%d%c", ans[i], (i<n-1?' ':'\n'));
    return 0;
}


Measured memory_bytes: 3856
n = int(input())
a = list(map(int, input().split()))

command = []

s = min(a)
si = a.index(s)
t = max(a)
ti = a.index(t)

def positive(a):
    for i in range(n-1):
        if a[i] > a[i+1]:
            a[i+1] += a[i]
            command.append([i+1,i+2])
        
def negative(a):
    for i in range(n-1,0,-1):
        if a[i] < a[i-1]:
            a[i-1] += a[i]
            command.append([i+1,i])

if s > 0:
    positive(a)
elif t < 0:
    negative(a)
elif -s < t:
    #positivise
    for i in range(n):
        if a[i] <= 0:
            a[i] += t
            command.append([ti+1,i+1])
    positive(a)
else:
    #negativise
    for i in range(n):
        if a[i] >= 0:
            a[i] += s
            command.append([si+1,i+1])
    negative(a)

# fin
print(len(command))
for c in command:
    print(*c)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define FAST ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define dofloat cout<<fixed<<setprecision(8)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bitcount _builtin_popcount
#define all(vec) vec.begin(),vec.end()
#define rall(vec) vec.rbegin(),vec.rend()
using namespace __gnu_pbds;
using namespace std;
//typedef
typedef long long ll;
typedef long double ld;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vll;
typedef vector<pair<int,int> > vii;
typedef vector<int> vi;
typedef pair<int,int> ii;
//constants
const long long MOD=1000000007;
const long long MAX=100005;
const long double PI=3.14159265359;
const long double G=9.807;
const long long INF=1e18;
const long double EPS=1e-6;
//
#define forn(i, n)for(ll i=0;i<n;i++)
// gcd of a and b
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
// distance between (a,b) and (c,d)
long double dis(long long a,long long b,long long c,long long d){return sqrt( ((a)-(c))*((a)-(c))+((b)-(d))*((b)-(d)) );}
// simple prime check
bool isprime(long long a){
if(a==2)return 1;
if(!(a&1))return 0;
for(ll i=3;i*i<=a;i+=2){
	if(a%i==0)return 0;
}
return 1;
}
// fast expo
long long mpow(long long base,long long exponent,long long modulus){
if(modulus==1)return 0;
long long result = 1;
base=base%modulus;
while(exponent){
		if(exponent%2 == 1)
			result=(result*base)%modulus;
		exponent=exponent>>1;
		base=(base*base)%modulus;
	}
return result;
}
// modular inverse
ll minv(ll a,ll mod){
	ll _gcd=gcd(a,mod);
	assert(_gcd==1);
	return mpow(a,mod-2,mod);
}

/*
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/

/*
ll dx[]={1,0,-1,0,1,1,-1,-1};
ll dy[]={0,-1,0,1,1,-1,-1,1};
*/

/*
void sieve(int N){
	for(int i=0;i<=N;i++){
		spf[i]=i;
	}
	for(int i=2;i*i<=N;i++){
		if(spf[i]==i){
			for(int j=i*i;j<=N;j+=i){
				spf[j]=min(spf[j],i);
			}
		}
	}
	return;
}
*/

/*
void nCr(ll n,ll k){
	ll i,j;
	for(i=0;i<=n;i++){
		for(j=0;j<=min(i,k);j++){

			if(j==0 or j==i)C[i][j]=1LL;
			else  C[i][j]=(C[i-1][j-1]+C[i-1][j])%MOD;

		}
	}
	return;
}
*/
/*
ll ncr(ll N,ll K){
	if(N<K)return 0;
	if(K==0)return 1;
	if(N==0)return 0;

	ll den=1;
	for(ll i=1;i<=K;i++)den*=i;
	ll num=1;
	while(K--){
		num*=N;
		if(num%den==0){
			num/=den;
			den=1;
		}
		N--;
	}

	return num;
}
*/
ll a,p;
int main(){FAST;
cin>>a>>p;
cout<<(3*a+p)/2;
return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
const int maxn = 1e9 + 5;
#define INF 1000000000
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;

string s;

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fastio
	cin >> s;
	int n=s.size();
	int cnt = 0;
	int l = 0;
	int h = n-1;
	while(h > l){
		 if (s[l++] != s[h--]){
		 	cnt++;
		 } 
	}
	cout << cnt << endl;
	return 0;
} 
//^-^

Measured memory_bytes: 3604
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#define ll long long

using namespace std;

int a[108];

int main() {
	int N; cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	int cnt = 0;

	bool flag = 1;
	while (flag) {
		flag = 0;
		for (int i = N - 1; i > 0; i--) {
			if (a[i] < a[i - 1]) {
				flag = 1;
				int tmp = a[i];
				a[i] = a[i - 1];
				a[i - 1] = tmp;
				cnt++;
			}
		}
	}

	for (int i = 0; i < N; i++) {
		if (i > 0)cout << " ";
		cout << a[i];
	}
	cout << endl << cnt << endl;



}




Measured memory_bytes: 3116
import java.util.*;
public class Main {
    public static void main(String[] args) {
      Scanner scan = new Scanner(System.in);
      String name1 = scan.next();
      String name2 = scan.next();
      String name3 = scan.next();
          System.out.print(name1.charAt(0));
          System.out.print(name2.charAt(0));
          System.out.print(name3.charAt(0));
    }
}

Measured memory_bytes: 21844
$s=<>;
chomp($s);
$count=0;
$flg=0;
%hash=();
while($flg==0){
    $hash{$s}++;
	if($s%2==0){
    	$s/=2;
    }else{
    	$s=$s*3+1;
    }
    $count++;
    foreach $name (keys %hash)  {
    	if($hash{$name}==2){
        	$flg=1;
        }
	}
}
if($s==4 or $s==2 or $s==1){
	print $count;
}else{
	print $count+1;
}

Measured memory_bytes: 512
while True:
    H, W = [int(i) for i in input().split()]
    if W == 0 and H == 0:
        break
    for i in range(0, H):
        if i == 0:
            print('#' * W)
        elif i == (H - 1):
            print('#' * W)
        elif H == 1:
            break
        else:
            print('#', '.' * (W - 2), '#', sep='')
    print()

Measured memory_bytes: 7620
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
                
#define speedio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pretime float(clock()-clk)/CLOCKS_PER_SEC
#define max2(a,b) ((a)>(b) ? (a) : (b))   
#define min2(a,b) ((a)<(b) ? (a) : (b)) 
#define rep(i,a,b) for(i=a;i<=b;++i)
#define rev(i,a,b) for(i=a;i>=b;--i) 
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define ll long long int 
#define ins insert
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define PI 3.14159265
#define mod 1000000007
#define inf 1000000000000000

using namespace std;
typedef vector<ll>   vll;
typedef vector<int>   vi;
typedef set<ll>      sll;
typedef set<int>      si;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
clock_t clk=clock();       

ll i,j;
void solve(void);

int main()
{
  speedio;
   int t=1;  
  // cin>>t;
   while(t--)
     solve();

  return 0;
}
//
void solve()
{
	string s; cin>>s; ll k=0;

	ll cnta=0; ll n=sz(s);
	rep(i,0,n-2)
	 if(s[i]=='A')
	 	++cnta;
	 else if(s[i]=='B' && s[i+1]=='C')
	 	{
	     	k+=cnta; ++i;
	    }
	 else
	 	cnta=0;

	 cout<<k<<'\n';
}

Measured memory_bytes: 720
n=int(input())
k=int(input())

b=2**n
ans=999999999999999999
for i in range(b):
    bit_b=bin(i)[2:].zfill(n)
    ans_i=1
    for j in range(len(bit_b)):
        if(bit_b[j]=='0'):
            ans_i*=2
        elif(bit_b[j]=='1'):
            ans_i+=k

    if(ans>ans_i):
        ans=ans_i

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h> 
#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vd = vector<double>;
using vs = vector<string>;
using vb = vector<bool>;
using vp = vector<P>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using vvb = vector<vb>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll  INFL = 1e18;


signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    
    int N; cin >> N;
    vi b(N); REP(i, N) cin >> b[i];
    vi ans;
    while(b.size() > 0)
    {
        bool ok = false;
        for(int i = b.size()-1; i >= 0; i--)
        {
            if(b[i] == i+1)
            {
                b.erase(b.begin()+i);
                ans.push_back(i+1);
                ok = true;
                break;
            }
        }
        if(!ok)
        {
            cout << -1 << endl;
            return 0;
        }
    }
    for(int i = ans.size()-1; i >= 0; i--) cout << ans[i] << endl;
}

Measured memory_bytes: 256
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7

n=int(input())
x=list(map(int,input().split()))
ans=float('inf')
for i in range(100):
    tmp=0
    for j in range(n):
        tmp+=(x[j]-i-1)**2
    ans=min(ans,tmp)
print(ans)

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

int main(){
  int i;
  string a,b;
  cin>>a>>b;
  for(i=0;i<a.size()-1;i++){
    cout<<a[i]<<b[i];
  }
  if(a.size()==b.size()){
    cout<<a[a.size()-1]<<b[b.size()-1];
  }else{
    cout<<a[a.size()-1];
  }
  cout<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <cmath>
#include <list>
#include <chrono>
#include <thread>

using namespace std;

//template<typename T>
//using Matrix2D = std::vector<vector<T>>;

const bool debug = false;

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

#define y1 roman_kaban
#define rank oryshych_konb
#define ull unsigned long long
//#define ll long long
//const int mod = int(1e9) + 7;
const int inf = 1e9;
//const long long infLL = 1e11;
//const int MX2 = 10100500; //  e7
//const long long INF = 1e18 + 0.5;
const int MX = 100500; //       e5
const int SZ = 1100;
//const int delta = 1 << 19;

vector<long long> x[4];

int main()
{
    ios_base::sync_with_stdio(false);
    //if(debug)
  //  freopen("/Users/ozzy/Documents/in.txt","r", stdin);
    int n, w;
    cin >> n >> w;
    long long a0, b0;
    cin >> a0 >> b0;
    x[0].push_back(b0);
    for(int i = 1; i < n; i++){
        int a, b;
        cin >> a >> b;
        x[a - a0].push_back(b);
    }
    for(int i = 0; i < 4; i++){
        sort(x[i].begin(), x[i].end());
        reverse(x[i].begin(), x[i].end());
        for(int j = 1; j < x[i].size(); j++){
            x[i][j] += x[i][j - 1];
        }
    }
    long long ans = 0;

    for(int i = 0; i <= x[0].size(); i++){
        for(int j = 0; j <= x[1].size(); j++){
            for(int k = 0; k <= x[2].size(); k++){
                long long s = (i + j + k) * a0 + j + k + k;
                s = w - s;
                if(s < 0) break;
                int p = s / (a0 + 3);
                if(p > x[3].size()) p = x[3].size();
                long long s2 = 0;
                if(i) s2 += x[0][i - 1];
                if(j) s2 += x[1][j - 1];
                if(k) s2 += x[2][k - 1];
                if(p) s2 += x[3][p - 1];
                if(s <= w && ans < s2){
                    ans = s2;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 1000000000; 

int main(){
  ll h;
  cin >> h;
  ll cnt = 0;
  while(h != 1){
    h /= 2;
    cnt++;
  }
  ll ans = 2*pow(2,cnt)-1;
  cout << ans << endl;  
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# A

import sys
from collections import defaultdict, deque
from heapq import heappush, heappop
import math
import bisect
input = sys.stdin.readline

# 再起回数上限変更
# sys.setrecursionlimit(1000000)


s = input()[:-1]

if s == 'Sunny':
    print('Cloudy')
elif s == 'Cloudy':
    print('Rainy')
else:
    print('Sunny')


Measured memory_bytes: 38256
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

int main(void) {
    int N;
    cin >> N;
    VI p(N);
    REP(i, N) cin >> p[i];
    int cnt = 0;
    FOR(i, 1, N - 1) {
        VI v;
        REP(j, 3) v.EB(p[i - 1 + j]);
        SORT(v);
        if (p[i] == v[1]) cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256