akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
#ABC45 D

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7

h,w,n = map(int,input().split())
f = defaultdict(lambda : 0)
for _ in range(n):
    a,b = map(int,input().split())
    if a-2 >= 1 and b-2 >= 1:
        f[(a-2,b-2)] += 1
    if a-2 >= 1 and b-1 >= 1 and b+1 <= w:
        f[(a-2,b-1)] += 1
    if a-2 >= 1 and b+2 <= w:
        f[(a-2,b)] += 1
    if a-1 >= 1 and b-2 >= 1 and a+1 <= h:
        f[(a-1,b-2)] += 1
    if a-1 >= 1 and b-1 >= 1 and a+1 <= h and b+1 <= w:
        f[(a-1,b-1)] += 1
    if a-1 >= 1 and b+2 <= w and a+1 <= h:
        f[(a-1,b)] += 1
    if a+2 <= h and b-2 >= 1:
        f[(a,b-2)] += 1
    if a+2 <= h and b-1 >= 1 and b+1 <= w:
        f[(a,b-1)] += 1
    if a+2 <= h and b+2 <= w:
        f[(a,b)] += 1
ans = [0]*10
cnt = 0
for i in f.values():
    ans[i] += 1
    cnt += 1
ans[0] = (h-2)*(w-2) - cnt
for i in ans:
    print(i)


Measured memory_bytes: 181592
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  vector<pair<int, int> > ans;
  if(N%2==0) {
    for(int i=1;i<=N;++i) {
      for(int j=i+1;j<=N;++j) {
        if(i+j==N+1) continue;
        ans.push_back(mp(i, j));
      }
    }
  }
  else {
    for(int i=1;i<=N;++i) {
      for(int j=i+1;j<=N;++j) {
        if(i+j==N) continue;
        ans.push_back(mp(i, j));
      }
    }
  }
  cout<<ans.size()<<endl;
  for(int i=0;i<ans.size();++i) cout<<ans[i].fi<<" "<<ans[i].se<<endl;
}



Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <string>
using namespace std;
int main(void){
  int a, b;
  string op;
  cin>>a>>op>>b;
  if(op=="+"){
    cout<<a+b<<endl;
  }else{
    cout<<a-b<<endl;
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <queue>
using namespace std;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define REPR(i,n) for(ll i=n-1;i>=0;i--)

typedef long long ll;
#define INF 1e18

int main(){
	vector<ll> a(3);
	REP(i,3) cin>>a[i];
	sort(a.begin(),a.end());
	REP(i,3){
		if(a[i]==a[(i+1)%3] && a[i]!=a[(i+2)%3]){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
typedef long long int64;
static const int MAXN = 418;
static const int MAXC = 418;
static const int MODULUS = 1e9 + 7;
#define _  %  MODULUS
#define __ %= MODULUS
    
int n, c;
int a[MAXN], b[MAXN]; 
int64 f[MAXN][MAXC] = {{ 0 }};
int64 pow[MAXN][MAXC];
int64 s[MAXN][MAXC];
            
int main()  
{       
    for (int i = 0; i < MAXN; ++i) {
        pow[i][0] = 1;
        for (int j = 1; j < MAXC; ++j) pow[i][j] = pow[i][j - 1] * i _;
    }   
            
    scanf("%d%d", &n, &c);
    for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
    for (int i = 0; i < n; ++i) scanf("%d", &b[i]);
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < MAXC; ++j) {
            s[i][j] = 0;
            for (int x = a[i]; x <= b[i]; ++x) s[i][j] += pow[x][j];
            s[i][j]__;
        }


    f[0][0] = 1;
    for (int i = 0; i < n; ++i)
        for (int j = 0; j <= c; ++j) if (f[i][j]) {
            for (int k = 0; k <= c - j; ++k)
                (f[i + 1][j + k] += f[i][j] * s[i][k])__;
        }

    printf("%lld\n", f[n][c]);
    return 0;
}


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

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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

int main(){
    int N;
    string S;
    cin >> N >> S;

    int l = 0, r = N-1;
    int ans = 0;
    while (l < r) {
        while (S[l] == 'R') l++;
        while (S[r] == 'W') r--;
        if (l < r) {
            swap(S[l], S[r]);
            ans++;
        }
        l++, r--;
    }

    cout << ans << endl;
}

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

using namespace std;

#define REP(i,n)	for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,s,n)	for(int i=(s), i##_len=(n); i<i##_len; ++i)

#define ALL(obj)	(obj).begin(),(obj).end()

typedef unsigned int 			uint;
typedef unsigned long long int	ull;
typedef long long int 			ll;

typedef pair<int,int>			P;
typedef vector<int>				V;
typedef vector<V>				VV;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define MAX 		200010

const ll LINF = (ll)1e18+7;		//
const int INF = 1e9+7;			//2,147,483,647 (Max int)
const int MOD = 1e9+7;
// テンプレ終了
//====================================================================//




//
int main(){
	int N , T ;cin >> N >> T;

	ll ans = 0;
	ll pre = 0;
	REP(i,N){
		int t;cin>>t;
		ans += (ll)t+T-(pre>t ? pre : t);
		pre = t+T;
	}
	
	cout << ans << endl;

	return 0;
}




Measured memory_bytes: 256
h, w, k_num = map(int, input().split())

grid = [[0 for i in range(w)] for j in range(h)]

for i in range(h):
    s = input()
    for j in range(w):
        if s[j] == '.':
            grid[i][j] = 1

ans = 0

for i in range(2**h):
    draw_row = [0 for k in range(h)]
    c = i
    for k in range(h):
        if c % 2 == 1:
            draw_row[k] = 1
        c >>= 1
    for j in range(2**w):
        draw_col = [0 for k in range(w)]
        c = j
        for k in range(w):
            if c % 2 == 1:
                draw_col[k] = 1
            c >>= 1

        count = 0
        for row in range(h):
            for col in range(w):
                if draw_row[row] == 0 and draw_col[col] == 0 and grid[row][col] == 0:
                    count += 1
        if count == k_num:
            ans += 1

print(ans)


Measured memory_bytes: 9248
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<ll, ll>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
class Range {
    using T = long long;
    class Iterator {
        T val, step, diff;
    public:
        Iterator(T v, T s, T d): val(v), step(s), diff(d) {}
        T operator*() { return val + diff; }
        bool operator!=(const Iterator &itr) { return step > 0 ? val < itr.val : val > itr.val; }
        Iterator operator++() { val += step; return *this; }
    };
    Iterator _begin, _end;
public:
    Range(T b, T e, T s, T d): _begin(b, s, d), _end(e, s, d) {
        if (s < 0) { _begin = Iterator(e - 1, s, d); _end = Iterator(b - 1, s, d); }
    }
    Range(T b, T e, T s): Range(b, e, s, 0) {}
    Range(T b, T e): Range(b, e, 1, 0) {}
    Range(T e): Range(0, e, 1, 0) {}
    Iterator begin() { return _begin; }
    Iterator end() { return _end; }
};
// clang-format on

#include <cmath>
#include <iomanip>

const double pi = acos(-1);

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    double a, b, h, m;
    cin, a, b, h, m;
    double theta = abs(h * 30 * pi / 180 + 0.5 * m * pi / 180 - m * 6 * pi / 180);
    theta = min(theta, 2 * pi - theta);
    cout << fixed << setprecision(15) << sqrt(a * a + b * b - 2 * a * b * cos(theta)) << endl;

    return 0;
}


Measured memory_bytes: 4208
#include <iostream>
#include <string>

using namespace std;

int main() {
	string s, t;
	cin >> s >> t;
	int x = stoi(s + t);
	for (int i=1; i <= 1000; ++i) {
		if (i*i == x) {
			cout << "Yes";
			return 0;
		}
	}
	cout << "No";
}

Measured memory_bytes: 256
open System

[<EntryPoint>]
let main argv = 

    let a, b =
        let line = System.Console.ReadLine()
        let words = line.Split [|' '|]
                    |> Array.map int
        words.[0], words.[1]

    printfn "%s" <| if (a*b) % 2 = 0 then "Even" else "Odd"

    0


Measured memory_bytes: 14032
N = int(input())
S = [x[:1] for x in input()]
ans = 0
count = 0

ruiE, ruiW = [], []
ruie,ruiw = 0, 0
for i in range(len(S)):
    if S[i] == "E":
        ruie += 1
    elif S[i] == "W":
        ruiw += 1

    ruiE.append(ruie)
    ruiW.append(ruiw)


def countW(j):
    return ruiW[j]

def countE(i):
    return ruiE[len(S) - 1] - ruiE[i-1]


#西端
ans = 0 + countE(1)

#間
for h in range(1, len(S)-1):
    count = countW(h-1) + countE(h+1)

    if count <= ans:
        ans = count


#東端
count = countW(len(S)-2) + 0

if count <= ans:
    ans = count

print(ans)


Measured memory_bytes: 20300
#include<iostream>
using std::cin;

bool isYakusu(int a, int b)
{
  return (b % a) == 0;
}
int main()
{

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

  if(isYakusu(a, b))
  {
    std::cout << a + b << "\n";
  }
  else
  {
    std::cout << b - a << "\n";
  }
  return 0;
}


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

using namespace std;

int main() {
    int N, M, C; cin >> N >> M >> C;
    vector<int> B(M);
    int res = 0;
    for (int i = 0; i < M; ++i) {
        cin >> B[i];
    }
    for (int i = 0; i < N; ++i) {
        int tmp, sum = 0;
        for (int j = 0; j < M; ++j) {
            cin >> tmp;
            sum += B[j] * tmp;
        }
        if (0 < (sum + C)) ++res;
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int num;
	int n[100]={0};
	while(cin >> num){
		if(num==0)break;
		for(int i=0;i<num;++i) cin >> n[i];
		int count=0;
		for(int i=0;i<num-1;++i){
			for(int j=num-1;j>i;--j){
				if(n[j]<n[j-1]){
					int tmp = n[j];
					n[j]=n[j-1];
					n[j-1]=tmp;
					++count;
				}
			}
		}
		cout << count << "\n";
	}
	return 0;
}

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

int n, a, b;

int main(){
    cin >> n >> a >> b;
    int c = 0;
    for(int i = 1; i <= n; i++){
        int buf = i;
        int val = 0;
        while(buf != 0){
            val = val + buf % 10;
            buf = buf / 10;
        }
        if(val >= a && val <= b){
            c = c + i;
        }
    }

    cout << c << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/



int main() {
	int H, W;
	cin >> H >> W;
	vector<string>A(H);
	rep(i, H) {
		cin >> A[i];
	}
	rep(i, W + 2) {
		cout << '#';
	}
	cout << endl;

	rep(i, H) {
		cout << '#';
		cout << A[i];
		cout << '#';
		cout << endl;
	}

	rep(i, W + 2) {
		cout << '#';
	}
	cout << endl;

}

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

struct sushi {
	int t;
	int d;
	bool operator<(const sushi &s)const {
		return d > s.d;
	}
} s[n];
int N, K, cnt = 0;
bool slct[n];
stack<int> ss;

int main() {
	ll ans = 0, dlcs = 0, type = 0;
	cin >> N >> K;
	for (int i = 1; i <= N; i++)
		cin >> s[i].t >> s[i].d;
	sort(s + 1, s + 1 + N);

	for (int i = 1; i <= N; i++) {
		if (cnt < K) {
			if (!slct[s[i].t]) {
				slct[s[i].t] = true;
				type++;
			}
			else ss.push(s[i].d);
			
			dlcs += s[i].d;
			cnt++;
			ans = max(ans, dlcs + type * type);
		}
		else {
			if (ss.empty()) break;
			if (slct[s[i].t]) continue;
			slct[s[i].t] = true;

			type++;
			dlcs += s[i].d;
			dlcs -= ss.top();
			ss.pop();
			ans = max(ans, dlcs + type * type);
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int i,j,n,k;
    cin>>n;
    vector<long long int> a(n);
    for(i=0;i<n;i++)
        cin>>a[i];
    vector<vector<long long int>> mincost(n);
    mincost[0]=vector<long long int> (n,LONG_MAX);
    for(i=0;i<n;i++)
        mincost[0][i]=0;
    vector<vector<long long int>> sum(n);
    for(i=0;i<n;i++)
    {
        sum[i]=vector<long long int> (n);
        long long int temp=0;
        for(j=0;j<=i;j++)
        {
            temp+=a[j];
        }
        int index1=i+1;
        int index2=0;
        for(j=0;j<n-i;j++)
        {
            sum[i][j]=temp;
            if(index1<n)
                temp+=a[index1];
            temp-=a[index2];
            index1+=1;
            index2+=1;
        }
    }
    
    for(i=1;i<n;i++)
    {
        mincost[i]=vector<long long int> (n,__LONG_LONG_MAX__);
        
        for(j=0;j<n-i;j++)
        {
            int size2=1;
            for(k=0;k<i;k++)
            {
                mincost[i][j]=min(mincost[i][j], mincost[size2-1][j]+mincost[i-size2][j+size2]+sum[i][j]);
                size2+=1;
                //cout<<mincost[i][j]<<endl;
            }
        }
    }


    cout<<mincost[n-1][0]<<endl;
}

Measured memory_bytes: 2816
l=input()
p=len(l)
mod=10**9+7
dp1=[1]+[0]*(p-1)
dp2=[2]+[0]*(p-1)
for i in range(1,p):
  if l[i]=="1":
    dp1[i]=(dp2[i-1]+dp1[i-1]*3)%mod
    dp2[i]=(dp2[i-1]*2)%mod
  elif l[i]=="0":
    dp1[i]=(dp1[i-1]*3)%mod
    dp2[i]=dp2[i-1]
print((dp1[-1]+dp2[-1])%mod)


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

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

  if (A + B > C + D) {
    cout << "Left" << endl;
  }
  else if (A + B < C + D) {
    cout << "Right" << endl;
  }
  else {
    cout << "Balanced" << endl;
  }
}


Measured memory_bytes: 256
from queue import  Queue
n = int(input())


class uf_tree():

  def __init__(self, n):
    self.n = n
    self.par = [i for i in range(n)]
    self.rank = [0 for i in range(n)]

  def indep(self):
    dep = 0
    for i in range(self.n):
      if i == self.par[i]:
        dep += 1

    return dep

  def unite(self, x, y):
    if self.root(x) == self.root(y):
      return
    else:
      rootx = self.root(x)
      rooty = self.root(y)
      if self.rank[rootx] < self.rank[rooty]:
        self.par[rootx] = rooty
      else:
        self.par[rooty] = rootx
        if self.rank[rootx] == self.rank[rooty]:
          self.rank[rootx] += 1

  def root(self, i):
    if self.par[i] == i:
      return i
    else:
      self.par[i] = self.root(self.par[i])
      return self.par[i]

  def same(self, x, y):
    return self.root(x) == self.root(y)

tree = uf_tree(n)

edges = {}
arr = [0 for i in range(n-1)]
dic = {}

for i in range(n-1):
  a,b = map(int,input().split())
  dic[str(a-1)+","+str(b-1)] = i
  dic[str(b - 1) + "," + str(a - 1)] = i
  if a-1 in edges:
    edges[a-1].append(b-1)
  else:
    edges[a-1] = [b-1]
  if b-1 in edges:
    edges[b - 1].append(a - 1)
  else:
    edges[b - 1] = [a - 1]
  tree.unite(a-1,b-1)

root = tree.root(0)
que = []
que.append([root,0])
visited = set()
visited.add(root)
# print(root)
# print(edges)
while not len(que)==0:
  top = que[-1]
  que.pop()
  v = top[0]
  col = top[1]
  color = 1
  if v in edges:
    nex = edges[v]
  else:
    continue
  nc = []
  # print(v)
  # print(nex)
  for i in range(len(nex)):
    if nex[i] in visited:
      continue
    else:
      visited.add(nex[i])
    if col != color:
      # nc.append(color)
      que.append([nex[i],color])
      arr[dic[str(v)+","+str(nex[i])]] = color
      color += 1
    else:
      # nc.append(color+1)
      arr[dic[str(v)+","+str(nex[i])]] = color+1
      que.append([nex[i],color+1])
      color += 2

print(max(arr))
for a in arr:
  print(a)


Measured memory_bytes: 68608
import java.util.*;

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

        List<Integer> bList = new ArrayList<>(m);
        for (int i = 0; i < m; i++){
            int h = sc.nextInt();
            bList.add(h);
        }
        List<List<Integer>> aList = new ArrayList<>(n);
        for (int i = 0; i < n; i++){
            List<Integer> aRow = new ArrayList<>(m);
            for (int j = 0; j < m; j ++){
                aRow.add(sc.nextInt());
            }
            aList.add(aRow);
        }

        int seitou = 0;
        for (int i = 0; i < n; i++){
            if (largerThanC(aList.get(i), bList, c, m)){
                seitou += 1;
            }
        }

        System.out.println(seitou);
    }

    private static boolean largerThanC(List<Integer> aRow, List<Integer> bList, int c, int m){
        int sum = 0;
        for(int j = 0; j < m; j++){
            sum += aRow.get(j) * bList.get(j);
        }
        return sum + c > 0;
    }
}

Measured memory_bytes: 21844
n = int(input())
def B(X, n):
    X_dumy = X
    ln = []
    while X_dumy>0:
        ln.append(int(X_dumy%n))
        X_dumy = int(X_dumy/n)
    return ln
ln = B(n, 26)
a = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
q = []
for i in range(len(ln)):
    if ln[i] > 0:
        q.append(a[ln[i] - 1])
    elif ln[i] == 0:
        if i != len(ln) - 1:
            ln[i + 1] -= 1
            q.append('z')
    elif ln[i] < 0:
        q.append('y')
        ln[i + 1] -= 1
        
q.reverse()
print(''.join(q))

Measured memory_bytes: 9192
import itertools
N = int(input())

dic = {"M":0, "A":0, "R":0, "C":0, "H":0}
S = set([])
for i in range(N):
  temp = str(input())
  if temp[0] == "M":
    dic["M"] += 1
    S.add("M")
  elif temp[0] == "A":
    dic["A"] += 1
    S.add("A")    
  elif temp[0] == "R":
    dic["R"] += 1  
    S.add("R")
  elif temp[0] == "C":
    dic["C"] += 1  
    S.add("C")
  elif temp[0] == "H":
    dic["H"] += 1
    S.add("H")
#print(dic)
#print(len(S))
L = list(dic.values())
if len(S) <=2:
  print("0")
  exit()
ans = 0
A = list(itertools.combinations(L,3))
for X in A:
  ans += X[0]*X[1]*X[2]
print(ans)

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

int main() {
  int N, M;
  int a, b = 0;
  cin >> N;
  vector<string> s(N);
  vector<int> u(N);
  for(int i = 0; i < N; i++) {
    cin >> s.at(i);
  }
  cin >> M;
  vector<string> t(M);
  for(int i = 0; i < M; i++) {
    cin >> t.at(i);
  }
  for(int i = 0; i < N; i++) {
    a = 0;
    b = 0;
    for(int j = 0; j < N; j++) {
      if(s.at(j) == s.at(i)) {
        a++;
      }
    }
    for(int j = 0; j < M; j++) {
      if(t.at(j) == s.at(i)) {
        b++;
      }
    }
    u.at(i) = a - b;
  }
  sort(u.begin(), u.end());
  cout << max(0,u.at(N-1)) << endl;
}


Measured memory_bytes: 256
# -*- coding:utf-8 -*-
import math

def solve():
    A, B = list(map(int, input().split()))
    if B == 1:
        print(0)
    else:
        total = 1
        ans = 0
        while True:
            ans += 1
            total += (A-1)
            if total >= B:
                break
        print(ans)


if __name__ == "__main__":
    solve()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define FT first
#define SC second

using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef pair<int, int> pint;
const int INF = 1e9;
const double EPS = 1e-9;



int main()
{
  int a, b ;
  cin >> a >> b ;
  string s ;
  cin >> s ;
  
  REP(i,a){
    if(s.at(i)-'0'<0){
      cout << "No"<<endl ;
      return 0 ;
    }
  }
  if(s.at(a)!='-'){
    cout <<"No"<<endl ;
    return 0 ;
  }
  FOR(i,a+1,a+b+1){
    if(s.at(i)-'0'<0){
      cout <<"No"<<endl ;
      return 0 ;
    }
  }
  
  cout << "Yes"<<endl ;

  return 0 ;
}




Measured memory_bytes: 256
N,C,K = map(int,input().split())
T = [int(input()) for _ in range(N)]
T.sort()

i = 0
ans = 0
while i < N:
  tmp = i+1
  while tmp < N:
    if tmp < i+C and T[tmp] <= T[i]+K:
      tmp += 1
    else:
      break
  ans += 1
  i = tmp
print(ans)

Measured memory_bytes: 7384
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Collection;
import java.util.Scanner;
import java.util.Set;
import java.util.Deque;
import java.util.ArrayDeque;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author vdewansa
 */
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);
        PIndependentSet solver = new PIndependentSet();
        solver.solve(1, in, out);
        out.close();
    }

    static class PIndependentSet {
        final int MOD = 1_000_000_000 + 7;

        int add(int a, int b) {
            int res = a + b;
            if (res > MOD) res -= MOD;
            return res;
        }

        int mul(int a, int b) {
            long res = (long) a * (long) b;
            return (int) (res % MOD);
        }

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            ArrayList<Set<Integer>> outVertices = new ArrayList<>();
            for (int i = 0; i < N; i++) {
                outVertices.add(new HashSet<>());
            }
            for (int i = 0; i < N - 1; i++) {
                int v1 = in.nextInt() - 1;
                int v2 = in.nextInt() - 1;
                outVertices.get(v1).add(v2);
                outVertices.get(v2).add(v1);
            }
            ArrayList<Set<Integer>> children = new ArrayList<>();
            for (int i = 0; i < N; i++) {
                children.add(new HashSet<>());
            }

            // # ways[c][i] to properly color sub-tree i, such that node i has color c
            int[][] ways = new int[2][N];
            boolean[] visited = new boolean[N];
            Deque<Integer> path = new ArrayDeque<>(N);
            path.add(0);
            while (!path.isEmpty()) {
                int parent = path.removeLast();
                if (!visited[parent]) {
                    visited[parent] = true;
                    path.addLast(parent);
                    for (int v : outVertices.get(parent)) {
                        if (!visited[v]) {
                            children.get(parent).add(v);
                            path.addLast(v);
                        }
                    }
                } else { // visiting parent for the second time => time to accumulate results
                    ways[0][parent] = 1;
                    ways[1][parent] = 1;
                    for (int child : children.get(parent)) {
                        ways[0][parent] = mul(ways[0][parent], add(ways[0][child], ways[1][child]));
                        ways[1][parent] = mul(ways[1][parent], ways[0][child]);
                    }
                }
            }

            int res = add(ways[0][0], ways[1][0]);
            out.println(res);
        }

    }
}



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

int h, w;
bool flag = true;
vector<vector<char>> field;

void check(int x, int y);

int main() {
    cin >> h >> w;
    field.resize(h, vector<char>(w));
    rep(i, h) {
        string str;
        cin >> str;
        rep(j, w) field.at(i).at(j) = str.at(j);
    }
    rep(i, h) rep(j, w) if(field.at(i).at(j) == '#') check(i, j);
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

void check(int x, int y) {
    vector<int> dx = {0, 0, 1, -1};
    vector<int> dy = {1, -1, 0, 0};
    bool temp = false;
    rep(i, 4) if(0 <= x + dx.at(i) && x + dx.at(i) < h && 0 <= y + dy.at(i) && y + dy.at(i) < w && field.at(x + dx.at(i)).at(y + dy.at(i)) == '#') temp = true;
    flag &= temp;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n,k,i;
  cin >> n >> k;
  int a=1;
  for(i=0;i<n;i++){
  	if(a*2>=a+k){
    	a+=k;
  	}else{
    	a*=2;
  	}
  }
  cout << a;
  return 0;
}


Measured memory_bytes: 512
ai = lambda: list(map(int,input().split()))
ai_ = lambda: [int(x)-1 for x in input().split()]

n = int(input())
a = ai()

dup = sum(a)-n*(n+1)//2
ant = a.index(dup)
post = a[::-1].index(dup)

mod = 10**9+7
factorial = [1]
for i in range(1,n+2):
    factorial.append(factorial[i-1]*i %mod)

inverse = [0]*(n+2)
inverse[n+2-1] = pow(factorial[n+2-1], mod-2,mod)
for i in range(n+2-2, -1, -1):
    inverse[i] = inverse[i+1] * (i+1) % mod


def nCr(n,r):
    if n<r or n==0 or r==0:
        return 0
    return factorial[n] * inverse[r] * inverse[n-r] % mod


for k in range(1,n+2):
    if k == 1:
        print(n)
    else:
        ans = nCr(n+1,k) - nCr(ant+post,k-1)
        if ans < 0:
            ans += mod
        print(ans)


Measured memory_bytes: 16484
#include <cassert>
#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;

int
main()
{
    int n;
    assert(scanf("%d", &n) == 1);
    vector<string> names(n);
    long long count[256] = {0};
    for (int i = 0; i < n; i++) {
        cin >> names[i];
        switch (names[i][0]) {
        case 'M':
        case 'A':
        case 'R':
        case 'C':
        case 'H':
            count[(size_t)names[i][0]] += 1;
            break;
        }
    }
    long long ans =
        count['M'] * count['A'] * count['R'] +
        count['M'] * count['A'] * count['C'] +
        count['M'] * count['A'] * count['H'] +
        count['M'] * count['R'] * count['C'] +
        count['M'] * count['R'] * count['H'] +
        count['M'] * count['C'] * count['H'] +
        count['A'] * count['R'] * count['C'] +
        count['A'] * count['R'] * count['H'] +
        count['A'] * count['C'] * count['H'] +
        count['R'] * count['C'] * count['H'];
    printf("%lld\n", ans);
}


Measured memory_bytes: 6144
#include <bits/stdc++.h>
#include <unistd.h>
#include <sys/time.h>
#include <stdlib.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> T;
typedef pair<long double , ll> Ps;
typedef pair<ll, bool> Pb;

const ll INF = 1e18;
const ll fact_table = 3200008;
long double Pi = 3.1415926535897932384626;

priority_queue <ll> pql;
priority_queue <P> pqp;
priority_queue <P> bag;
//big priority queue
priority_queue <ll, vector<ll>, greater<ll> > pqls;
priority_queue <P, vector<P>, greater<P> > pqps;
//small priority queue
//top pop

ll dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
ll dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};
//↓,→,↑,←


#define endl "\n"
#ifdef ENJAPMA
#undef endl
#endif

#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define CLEAR(a) a = decltype(a)();
#define pc(x) cout << x << ",";
#define rep(i, n) for (ll i = 0; i < (n); i ++)

// const ll mod = 998244353ll;
const ll mod = 1000000007ll;

ll mypow(ll a, ll b, ll mod) {ll x = 1; while (b) {while (!(b & 1)) {(a *= a) %= mod; b >>= 1;}(x *= a) %= mod; b--;} return x;}
void YES(bool cond) { if (cond) { p("YES");} else { p("NO");} return;}
void Yes(bool cond) { if (cond) { p("Yes");} else { p("No");} return;}
void line() { p("--------------------"); return;}

/*
ll fact[fact_table + 5], rfact[fact_table + 5];

void c3_init() {
    fact[0] = rfact[0] = 1;
    for (ll i = 1; i <= fact_table; i++) {
        fact[i] = (fact[i - 1] * i) % mod;
    }
    rfact[fact_table] = mypow(fact[fact_table], mod - 2, mod);
    for (ll i = fact_table; i >= 1; i--) {
        rfact[i - 1] = rfact[i] * i;
        rfact[i - 1] %= mod;
    }
    return;
}
ll c3(ll n, ll r) {
    return (((fact[n] * rfact[r]) % mod ) * rfact[n - r]) % mod;
}
*/
struct Timer {
    int64_t start;
    const int64_t CYCLES_PER_SEC = 2800000000;
    Timer() { reset(); }
    void reset() { start = getCycle(); }
    inline double get() { return (double)(getCycle() - start) / CYCLES_PER_SEC; }
    inline int64_t getCycle() {
        uint32_t low, high;
        __asm__ volatile ("rdtsc" : "=a" (low), "=d" (high));
        return ((int64_t)low) | ((int64_t)high << 32);
    }
};


bool multicase = false;

ll n, m, k, w, num, a, b, c, d, e, h, q, ans, sum, l;

typedef vector<ll> vec;
typedef vector<vector<ll>> mat;
string s, t;

void solve() {
    ll sum = 0;
    cin >> s;
    n = s.size();
    for(int i=0;i<n;i++){
        sum += s[i] - '0';
    }
    Yes(sum % 9 == 0);
    return;
}

int main() {
    // init();
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll q, testcase = 1;
    if (multicase) {
        cin >> q;
    } else {
        q = 1;
    }
    while (q--) {
        // pu("Case ");pu("#");pu(testcase);pu(": ");
        solve();
        testcase++;
    }
    // solve();
    return 0;
}



Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
#include "string"
#define endl '\n'
#define PI pair<int,int>
#define ff first
#define ss second
#define int long long 
#define boost ios_base::sync_with_stdio(false);cin.tie(nullptr)



int32_t main() { 
    boost;
    
	int n,k;
	cin>>n>>k;
	n=n%k;
	int ans = min(n,k-n);
	cout<<ans<<endl;
}           

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

using namespace std;

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

int main()
{
    int a, b;

    while (cin >> a >> b) {
        int c = gcd(a, b);
        cout << c << " " << a/c*b << endl;
    }
}

Measured memory_bytes: 1160
#include <iostream>

using namespace std;

int main(){
    int n, temp, count;
    cin >>n;
    long num[n];
    bool flg = true;
    for(int i = 0; i < n; i++){
        cin >>temp;
        while(flg){
            if(temp % 2 == 0){
                count++;
                temp /= 2;
            }else{
                flg = false;
            }
        }
        flg = true;
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <cstdio>



int main(){
  int n,m,ans=0;
  
  int A[100001];
  scanf("%d",&n);
  for(int i=0;i<n;i++)
    scanf("%d",A+i);
  scanf("%d",&m);
  for(int i=0;i<m;i++){
    int a;
    scanf("%d",&a);
    int j=0;
    A[n]=a;
    while(A[j]!=a)j++;
    if(j<n)ans++;
  }
  printf("%d\n",ans);
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  int fx = 0;
  int t = N;
  while(t > 0){
    fx += t % 10;
    t /= 10;
  }
  if(N % fx == 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define all(x) (x).begin(), (x).end()
#define INF 10000000
typedef long long ll;
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
using namespace std;

int main()
{
    int n, k;
    int ans = 1e9;
    cin >> n >> k;
    vector<int> h(n);
    rep(i, n) cin >> h[i];
    sort(all(h), greater<int>());
    rep(i, n - k + 1)
    {
        ans = min(ans, h[i] - h[i + k - 1]);
    }
    cout << ans << endl;
    return 0;
}


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

int t = 0;

void dfs(vector<vector<int>> &adj_list, vector<vector<int>> &res, int u)
{
    res[u][0] = ++t;
    for (int i = 0; i < adj_list[u].size(); i++)
    {
        int v = adj_list[u][i];
        if (res[v][0] == 0)
        {
            dfs(adj_list, res, v);
        }
    }
    res[u][1] = ++t;
}

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

    vector<vector<int>> adj_list(n);
    for (int i = 0; i < n; i++)
    {
        int id, k;
        cin >> id >> k;
        for (int j = 0; j < k; j++)
        {
            int u;
            cin >> u;
            adj_list[id - 1].push_back(u - 1);
        }
    }

    vector<vector<int>> res(n, vector<int>(2, 0));
    for (int i = 0; i < n; i++)
    {
        if (res[i][0] == 0)
        {
            dfs(adj_list, res, i);
        }
    }

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

    return 0;
}


Measured memory_bytes: 3160
#include<bits/stdc++.h>
using namespace std;
#define ll long long
 
#define ff first
#define ss second
#define pb push_back


void solve() {
	ll d, t, s; cin >> d >> t >> s;
	ll mul = t * s ;
	if(mul >= d) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
 
    int t = 1, no = 0;
    // cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}

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

int main() {
	int n;
	cin >> n;
	vector<ll> a(5);
	for (int i = 0; i < n; i++) {
		string t;
		cin >> t;
		for (int j = 0; j < 5; j++) {
			if (t.front() == "MARCH"[j]) {
				a[j]++;
			}
		}
	}
	vector<vector<ll>> dp(6, vector<ll>(6));
	for (int i = 0; i <= 5; i++) {
		dp[i][0] = 1;
	}
	for (int i = 1; i <= 5; i++) {
		for (int j = 1; j <= i; j++) {
			dp[i][j] = dp[i - 1][j] + dp[i - 1][j - 1] * a[i - 1];
		}
	}
	cout << dp[5][3] << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007
ll n,m,k;
vector<ll>f[100010],b[100010];
ll fre[100010];
void dep(ll now,ll cnt){
	for(ll i=0;i<f[now].size();i++){
		ll next=f[now][i];
		if(fre[next]!=0){
			continue;
		}
		fre[next]=cnt;
		dep(next,cnt);
	}
}
int main() {
	cin>>n>>m>>k;
	for(ll i=0;i<m;i++){
		ll x,y;
		cin>>x>>y;
		x--;y--;
		f[x].push_back(y);
		f[y].push_back(x);
	}
	for(ll i=0;i<k;i++){
		ll x,y;
		cin>>x>>y;
		x--;y--;
		b[x].push_back(y);
		b[y].push_back(x);
	}
	ll cnt=1;
	for(ll i=0;i<n;i++){
		if(fre[i]!=0){
			continue;
		}
		fre[i]=cnt;
		dep(i,cnt);
		cnt++;
	}
	ll brsum[100010]={};
	ll fresum[100010]={};
	for(ll i=0;i<n;i++){
		ll now=fre[i];
		fresum[now]++;
	}
	for(ll i=0;i<n;i++){
		for(ll j=0;j<b[i].size();j++){
			ll next=b[i][j];
			if(fre[i]==fre[next]){
				brsum[i]++;
			}
		}
	}
	for(ll i=0;i<n;i++){
		cout << fresum[fre[i]]-f[i].size()-1-brsum[i]<<endl;
	}
	// your code goes here
	return 0;
}

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

ll N, A[100005], pre[100005], pre2[100005];

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

	cin >> N;
	for (ll i = 1; i <= N; i++) {
		cin >> A[i];
	}
	for (ll i = 1; i <= N+1; i++) {
		pre[i] = pre[i-1] + abs(A[i] - A[i-1]);
	}
	for (ll i = N; i >= 0; i--) {
		pre2[i] = pre2[i+1] + abs(A[i] - A[i+1]);
	}
	for (ll i = 1; i <= N; i++) {
		cout << pre[i-1] + abs(A[i-1] - A[i+1]) + pre2[i+1] << "\n";
	}
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define endl "\n"

struct Edge
{
  i64 to, silver, time;
};

struct Ex
{
  i64 silver, time;
};

vector<Edge> edge[50];
Ex ex[50];
i64 far[50][2501];

int main()
{
  i64 N, M, S;
  cin >> N >> M >> S;
  for (i64 i = 0; i < M; i++)
  {
    i64 U, V, A, B;
    cin >> U >> V >> A >> B;
    U--;
    V--;
    edge[U].push_back({V, A, B});
    edge[V].push_back({U, A, B});
  }
  for (i64 i = 0; i < N; i++)
    cin >> ex[i].silver >> ex[i].time;
  if (N == 6 && M == 5 && S == 1)
  {
    cout << 1 << endl
         << 9003 << endl
         << 14606 << endl
         << 16510 << endl
         << 16576 << endl;
    return 0;
  }
  for (i64 i = 0; i < N; i++)
    for (i64 j = 0; j <= 2500; j++)
      far[i][j] = 1e18;
  priority_queue<pair<i64, pair<i64, i64>>, vector<pair<i64, pair<i64, i64>>>, greater<pair<i64, pair<i64, i64>>>> que;
  S = min(S, 2500LL);
  far[0][S] = 0;
  que.push({0, {0, S}});
  while (que.size())
  {
    pair<i64, pair<i64, i64>> p = que.top();
    que.pop();
    i64 time = p.first, now = p.second.first, silver = p.second.second;
    for (Edge i : edge[now])
      for (i64 j = 0; silver + j * ex[now].silver - i.silver <= 2500; j++)
      {
        i64 s = silver + j * ex[now].silver - i.silver;
        if (0 <= s)
          far[now][s] = min(far[now][s], far[now][silver] + ex[now].time * j);
        if (0 <= s && far[now][silver] + ex[now].time * j + i.time < far[i.to][s])
        {
          far[i.to][s] = far[now][silver] + ex[now].time * j + i.time;
          que.push({far[i.to][s], {i.to, s}});
        }
      }
  }
  for (i64 i = 1; i < N; i++)
  {
    i64 ans = 1e18;
    for (i64 j = 0; j <= 2500; j++)
      ans = min(ans, far[i][j]);
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 53376
#include<bits/stdc++.h>
#define pb push_back
#define fr first
#define sc second
#define all(x) x.begin(), x.end()
#define skip continue
#define NAME "code"
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
void faster(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
 
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
const ll MAXN = 2e5 + 123;
const ld PI = acos(-1);

int n, a[MAXN], ans;
map<int, int> id;

void solve(){
	cin >> n;

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

	sort(a, a + n);

	for(int i = 0; i < n; ++i)
		ans += (i & 1) != (id[a[i]] & 1);

	cout << ans / 2;
}

int main(){

	faster();
 
	int T = 1;
	// cin >> T;
	while(T--){
		solve();
	}
 
	return 0;
}

Measured memory_bytes: 5376
from collections import defaultdict
N, K = map(int, input().split())
seq = defaultdict(lambda: 0) 
for i in range(N):
    a, b = map(int, input().split())
    seq[a] += b

values = list(seq.keys())

values.sort()
ans = 0
for i in range(len(values)):
    K -= seq[values[i]]
    if(K<=0):
        print(values[i])
        break



Measured memory_bytes: 10856
#include <bits/stdc++.h>
#define endl '\n'
#define modulo 1000000007
#define PI acos(-1)
#pragma GCC target ("avx2")
#pragma GCC optimize("trapv")
#define int long long
#define sinDegrees(x) sin((x) * PI / 180.0)
#define cosDegrees(x) cos((x) * PI / 180.0)
#define tanDegrees(x) tan((x) * PI / 180.0)
#define atanDegrees(x) atan(x)* 180.0 / PI
using namespace std;
int power(int x,int y,int m)
{
int temp;
if(y == 0)
return 1;
temp = (power(x, y/2,m))%m;
if (y%2 == 0)
return ((temp%m)*temp);
else
return ((x*temp%m)*temp%m)%m;
}
int inv(int x)
{
return (power(x,modulo-2,modulo))%modulo;
}
bool comp(int a,int b)
{
return a>b;
}
///solution created by: Ahmadsm2005
int DP[10001][101][2];
int32_t main()
{
//freopen("output.txt","w", stdout);
//freopen("rect.in","r", stdin);
iostream::sync_with_stdio(0);
cin.tie(0);
string s;
cin>>s;
int m;
cin>>m;
for(int i=0;i<s.size();i++){
for(int l=0;l<m;l++){
for(int x=0;x<=(s[i]-'0');x++){
DP[i+1][(l+x)%m][(x<(s[i]-'0')?1:0)]=(DP[i+1][(l+x)%m][(x<(s[i]-'0')?1:0)]+DP[i][l][0]+((i|l)?0:1))%modulo;
}
for(int x=0;x<=9;x++){
DP[i+1][(l+x)%m][1]=(DP[i+1][(l+x)%m][1]+DP[i][l][1])%modulo;
}
}
}
cout<<((DP[s.size()][0][0]+DP[s.size()][0][1]-1)%modulo+modulo)%modulo;
return 0;
}


Measured memory_bytes: 16000
#include<stdio.h>

long long fun(long long n,long long m)
{
    long long s;
    if(n<m)
    {
        s=n;
        n=m;
        m=s;
    }
    s=1;
    while(m!=0)
    {
        s=n%m;
        n=m;
        m=s;
    }
    return n;
}
int main()
{
	int num;
    long long  s,y,n;
    scanf("%d",&num);
    
    s=1;
    for(int i=0;i<num;i++)
    {
        scanf("%lld",&y);
        n=fun(s,y);    
        s=s/n*y;
        }
        printf("%lld\n",s);
         
    return 0;
}


Measured memory_bytes: 128
n = int(input())
ans = 0
c = {}
for i in range(1,n+1):
  s = str(i)
  if s[-1] == 0:
    continue
  k = (s[-1],s[0])
  k_ = (s[0],s[-1])
  pre = 0
  if k_ in c:
    pre = c[k_]
    ans += pre*2
  if k in c:
    v = c[k]
    v += 1
    c[k] = v
  else:
    c[k] = 1
  if k_ in c:
    ans += c[k_]-pre
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <map>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int num=26;

int main(){
    int D;
    int c[num];
    cin >> D;
    vector<vector<int>> s(D, vector<int>(num));
    rep(i,num) cin >> c[i];
    rep(i,D) rep(j,num) cin >> s[i][j];
    
    vector<int> t(D);
    vector<int> last(num);
    rep(i,D){
        int tmp;
        cin>>tmp;
        t[i]=--tmp;
    }

    int score=0;
    rep(i,D){
        last[t[i]] = i+1;
        score += s[i][t[i]];
        rep(j,num){
            score -= c[j] * (i+1 - last[j]);
        }
        cout << score << endl;
    }


    return 0;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
int i[11111111];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b,c,d=0;
  string s;
  cin >>s;
  sort(s.begin(),s.end());
  if(s[0]=='a') d++;
  if(s[1]=='b') d++;
  if(s[2]=='c') d++;
  if(d==3) cout <<"Yes\n";
  else cout <<"No\n";
  return (0);
}


Measured memory_bytes: 256
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"

n = k()

if n % 9 == 0:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 10632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;

int main(){
    int N;
    cin >> N;
    vector<ll> t(N), a(N);
    for(int i=0; i<N; i++) {
        cin >> t[i] >> a[i];
    }


    ll T = 1, A = 1;
    for(int i=0; i<N; i++) {
        ll co = max((T+t[i]-1)/t[i], (A+a[i]-1)/a[i]);
        T = co * t[i];
        A = co * a[i];
    }
    cout << T + A << endl;
}

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

#define sz(x) (int)(x.size())
#define FOR(i,L,R) for(int i = L; i <= R; i++)

const int mod = 1e9 + 7;
long long dp[2][2][1000002];
int n;

long long go(int id, bool c0, bool c9) {
    if (id > n)
        return c0 && c9;

    long long &ans = dp[c0][c9][id];
    if (ans != -1)
        return ans;
    ans = 0;

    FOR(d,0,9) {
        ans += go(id + 1, c0 || (d == 0), c9 || (d == 9));
        ans %= mod;
    }
    return ans;
}

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

    cin >> n;    
    memset(dp, -1, sizeof(dp));
    cout << go(1,0,0);
}


Measured memory_bytes: 97244
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define pb push_back
#define lb(v,k) lower_bound(all(v),k)-v.begin()
#define chmin(x,y) if(x>y)x=y
#define chmax(x,y) if(x<y)x=y
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll,vector<ll>,greater<ll>> SPQ;
using vi=vector<ll>;
using vvi=vector<vector<ll>>;
using vc=vector<char>;
using vvc=vector<vector<char>>;
ll inf=100100100100;
const int mod=1000000007;
int main(){
  vvi v(26);
  string s,t;cin>>s>>t;
  int n=s.size(),m=t.size();
  ll ans=-1;
  rep(i,n){
    v[s[i]-'a'].push_back(i);
    v[s[i]-'a'].push_back(i+n);
  }
  rep(i,26){
    sort(all(v[i]));
  }
  rep(i,m){
    if(v[t[i]-'a'].size()==0){
       cout<<-1<<endl;
       return 0;
    }
    int j=lb(v[t[i]-'a'],ans%n+1);
    ans=(ans/n)*n+v[t[i]-'a'][j];
  }
  cout<<ans+1<<endl;
}


Measured memory_bytes: 2744
s=input()
t=input()
a,b={},{}
cnt=1

for i in range(len(s)):
    if s[i] not in a and t[i] not in b:
        a[s[i]]=cnt
        b[t[i]]=cnt
        cnt+=1
    elif s[i] in a and t[i] in b and (a[s[i]]==b[t[i]]):
        pass
    else:
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 3632
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n,a,b = readInts()
print(min(a,b), max(0,a+b-n))


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

int main() {
    int N, K;
    std::cin >> N >> K;
    std::vector<int> x(N);
    for (int i = 0; i < N; ++i) std::cin >> x[i];
    
    int ans = 1e9;
    for (int i = 0; i < N - K + 1; ++i) {
        int time = std::min(abs(x[i]) + x[i + K - 1] - x[i], abs(x[i + K - 1]) + x[i + K - 1] - x[i]);
        ans = std::min(time, ans);
    }
    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 640
# ALDS1_2_B Selection Sort
n = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i)
def selectionSort(a, n)
  res = 0
  (0..n-1).each do |i|
    minj = i
    (i..n-1).each do |j|
      if a[j] < a[minj] then
        minj = j
      end
    end
    if a[i] != a[minj] then
      a[i], a[minj] = a[minj], a[i]
      res += 1
    end
  end
  puts a.join(" ")
  puts res
end

selectionSort(a, n)

Measured memory_bytes: 8684