akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
using namespace std;

int main() {
	int n; cin >> n;
	string s;
	int r = 0, b = 0;
	cin >> s;
	for (int i = 0; i < n; i++) {
		if (s.at(i) == 'R') r++;
		else b++;
	}

	if (r > b) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
A = list(map(int, input().split()))
L = [0 for _ in range(N+1)]
cnt = 0
while min(A) < N and cnt < K:
    cnt += 1
    for i in range(N):
        L[max(i-A[i], 0)] += 1
        L[min(i+A[i]+1, N)] -= 1
    for i in range(N):
        L[i+1] += L[i]
        A[i] = L[i]
        L[i] = 0
for i in range(N):
    print(A[i], end = ' '*(i!=N-1))

Measured memory_bytes: 109040
import bisect

def find_bisect(a, x):
    i = bisect.bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return True
    return False

val = list(map(int, input().strip().split()))
n = val[0]
m = val[1]
a = []

for i in range(m):
    a.append(int(input().strip()))

pastpast_result = 0
past_result = 1
result = 0

for i in range(n):
    result = 0
    if not find_bisect(a, i):
        result += past_result
    if not find_bisect(a, i-1):
        result += pastpast_result

    if result > 1000000007:
        result = result % 1000000007
    
    if result == 0:
        break
    
    pastpast_result = past_result
    past_result = result

print(result % 1000000007)

Measured memory_bytes: 7080
import java.util.Scanner;
import java.util.Arrays;

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

      int n = scan.nextInt();
      int ls[] = new int[n];
      for(int i = 0;i < n;i++)
        ls[i] = scan.nextInt();
      Arrays.sort(ls);

      int ans = 0;
      for(int i = 0;i < n;i++){
          for(int j = 0;j < i;j++){
              for(int k = 0;k < j;k++){
                //全てが異なる
                if(ls[k] != ls[j] && ls[i] != ls[j])
                    //三角形の成立条件(ソート済みに限り)
                    if(ls[k] + ls[j] > ls[i]){
                        ans++;
                    }
              }
          }
      }

      System.out.println(ans);
    }
}

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

#define ll long long

signed main(){
  int x;
  cin >> x;
  x -= 400;
  if (x < 0){
    cout << -1 << endl;
  }
  else{
    cout << 8 - x / 200 << endl;
  }
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll in()
{
    ll res=0,p=1;
    char c=getchar();
    while(c<'0'||c>'9') {if(c=='-') p=-1; c=getchar();}
    while(c>='0'&&c<='9') res=res*10+c-48,c=getchar();
    return p*res;
}
void out(ll x)
{
    if (x>9) out(x/10);
    putchar(x%10+48);
}

const int maxn = 26 + 5;
const int mod = 7;

int a[maxn], b[maxn];
vector<int> va, vb;

int main()
{
    string sa, sb;
    cin >> sa >> sb;
    for (int i = 0; i < sa.size(); ++i) ++a[sa[i] - 'a'];
    for (int i = 0; i < sb.size(); ++i) ++b[sb[i] - 'a'];
    for (int i = 0; i < maxn; ++i){
        if (a[i]) va.push_back(a[i]);
        if (b[i]) vb.push_back(b[i]);
    }
    sort(va.begin(), va.end()); sort(vb.begin(), vb.end());
    if (va.size() != vb.size()) cout << "No" << endl;
    else{
        bool is = 1;
        for (int i = 0; i < va.size(); ++i){
            if (va[i] != vb[i]){
                is = 0;
                break;
            }
        }
        cout << (is ? "Yes" : "No") << endl;
    }
    return 0;
}


Measured memory_bytes: 776
#include <stdio.h>
int main(){ 
  char s[3];
  int i, count = 0;
  
  scanf("%s",&s);
  for(i = 0; i < 3; i++){
    if(s[i] == 'A'){
      count++;
    }
  }
  if(count == 0 || count == 3){
    printf("No");
  } else {
    printf("Yes");
  }
}


Measured memory_bytes: 128
def selectionSort(A, N): # N個の要素を含む0-オリジンの配列A
    A = list(map(int, A.split(" ")))
    change_count = 0
    for i in range(N):
        minj = i
        for j in range(i,N):
            if A[j] < A[minj]:
                minj = j
        if i != minj:
            #A[i] と A[minj] を交換
            tmp = A[i]
            A[i] = A[minj]
            A[minj] = tmp
            change_count+=1
    
    # 回答
    print(" ".join(map(str,A)))
    print(change_count)
    #return True

# 入力
N = int(input())  # 数列の長さを表す整数（N）
A = input("")   # N個の整数が空白区切り
selectionSort(A,N)



Measured memory_bytes: 5600
/*我是萌新*/
#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include <iomanip>
#include<map>
typedef long long ll;
const int mod = 1e9+7;
using namespace std;
ll gcd(ll a, ll b){
    return b?gcd(b,a%b):a;
}
ll lcm(ll a, ll b){
    return a/gcd(a,b)*b;
}
map<string ,bool>mp;
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    ll t;
    while (cin >> t)
    {
        string s;ll ans=0,n=t;
        while (t--)
        {
           cin>>s;
           if(mp[s]!=0)ans++;
           mp[s]=1;
        }
        cout<<n-ans<<'\n';
        mp.clear();
    }
}

Measured memory_bytes: 19288
#include <bits/stdc++.h>
using namespace std;
 
long long dp[1<<20] = {0};
int h[1<<20];
 
int main () {
  ios_base::sync_with_stdio(false); cin.tie(0);
  int n; cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> h[i];
  }
  dp[0] = 0;
  for (int i = 1; i < n; ++i) {
    dp[i] = LLONG_MAX; 
    for (int j = max(0, i - 2); j < i; ++j) {
      dp[i] = min(dp[i], dp[j] + abs(h[j] - h[i]));
    }
  }
  cout << dp[n - 1] << '\n';
}


Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
using lint = long long;


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

  int N, M;
  cin >> N >> M;
  vector<int> H(N), S(N);
  for (int i = 0; i < N; i++) {
    cin >> H[i];
  }
  for (int i = 0; i < M; i++) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    S[u] = max(S[u], H[v]);
    S[v] = max(S[v], H[u]);
  }

  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (H[i] > S[i]) {
      ans++;
    }
  }

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


Measured memory_bytes: 3988
# include <iostream>
# include <string>
# include <algorithm>
# include <vector>
# include <cstring>
# include <stdio.h>
# include <map>
# include <queue>

# define ll long long
# define pii pair<int,int>
# define FOR(a,b) for(int a=1; a<=b; a++)
# define REP(a,b) for(int a=0; a<b; a++)
# define FORU(a,b,c) for(int a=b; a<=c; a++)
# define FORD(a,b,c) for(int a=b; a>=c; a--)

using namespace std;

bool cmp(int a, int b){
    return a > b;
}

int main(){

    ios :: sync_with_stdio(false);
    
    int N, H;
    cin >> N >> H;
    vector<int> a,b;

    FOR(i,N){
        int x,y;
        cin >> x >> y;
        a.push_back(x);
        b.push_back(y);
    }

    sort(a.begin(), a.end(), cmp);
    sort(b.begin(), b.end(), cmp);

    int amax = a[0];

    int ans = 0;
    REP(i,b.size()){
        if(b[i] <= amax) break;
        ans++;
        H -= b[i];
        if(H <= 0){
            cout << ans << endl;
            return 0;
        }
    }

    ans += H/amax + ((H%amax)!=0);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1276
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
#include<math.h>
using namespace std;
#define ll long long
int main(){
    ll x,y,z;
    cin >> x >> y >> z;
    cout << z <<" "<< x <<" "<< y;
    return 0;
}


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

using namespace std;
using ll = long long;
using IP = pair<int, int>;

const ll linf = 1LL << 62;
const int inf = 99999999;
const int dx[4] = { 1,0,-1,0 };
const int dy[4] = { 0,1,0,-1 };
const ll atcoder = 1e9 + 7;

#define Endl endl
#define mp make_pair
#define all(v) v.begin(),v.end()
#define pb push_back
#define pr(x) cout << x << endl
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define rep(i,n) for(int i= 0;i<n;i++)

template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}

ll gcd(ll a, ll b) {//最大公約数
	if (a < b)swap(a, b);
	if (a%b == 0)return b;
	else gcd(b, a%b);
}

ll lcm(ll a, ll b) {//最小公倍数
	if (a < b)swap(a, b);
	return (a / gcd(a, b))*b;
}

int main() {

	int n, a;
	cin >> n >> a;
	if (n % 500 <=a)pr("Yes");
	else pr("No");

	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vvi vector<vi >
#define pi pair<ll,ll>
#define vvpi vector<vector<pi > >
#define vpi vector<pi >
#define vppi vector<pair<ll,pi > >
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define fs first
#define se second
ll gcd(ll a, ll b); 
  
// To compute x raised to power y under modulo m 
ll power(ll x,ll y, ll m); 
  
// Function to find modular inverse of a under modulo m 
// Assumption: m is prime 
ll modInverse(ll a, ll m) 
{ 
    return power(a, m-2, m);  
} 
  
// To compute x^y under modulo m 
ll power(ll x, ll y, ll m) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2, m) % m; 
    p = (p * p) % m; 
  
    return (y%2 == 0)? p : (x * p) % m; 
} 
  
// Function to return gcd of a and b 
ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b%a, a); 
} 
int main()
{
	ll a,b,ans;
	cin>>a>>b;
	if(a%b!=0)
	ans=1;
	else
	ans=0;
	ans=ans+a/b;
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define cmin(a,b) (a>(b)?a=(b),1:0)
#define cmax(a,b) (a<(b)?a=(b),1:0)
#define dmin(a,b) ((a)<(b)?(a):(b))
#define dmax(a,b) ((a)>(b)?(a):(b))
namespace io
{
	int F()
	{
		 int F=1,n=0;
		 char ch;
		 while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		 ch=='-'?F=0:n=ch-'0';
		 while((ch=getchar())>='0'&&ch<='9')n=n*10+ch-'0';
		 return F?n:-n;
	}
	long long G()
	{
		 long long F=1,n=0;
		 char ch;
		 while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		 ch=='-'?F=0:n=ch-'0';
		 while((ch=getchar())>='0'&&ch<='9')n=n*10+ch-'0';
		 return F?n:-n;
	}
}
int R(int l,int r)
{
	return (rand()<<15|rand())%(r-l+1)+l;
}
std::bitset<333> a[333]; 
int ex[666];
const int M=998244353;
int main()
{
	int n=io::F(),m=io::F();
	for(register int i=1;i<=n;++i)
		for(register int j=1;j<=m;++j)
			a[i][j]=io::F();
	int up=1;
	for(register int i=1;i<=m;++i)
	{
		int pl=0;
		for(register int j=up;j<=n;++j)
			if(a[j].test(i)){pl=j;break;}
		if(pl==0)continue;
		if(pl!=up)std::swap(a[up],a[pl]);
		for(register int j=up+1;j<=n;++j)
			if(a[j].test(i))a[j]^=a[up];
		++up;
	}
	int cnt=n-up+1;
	ex[0]=1;
	for(register int i=1;i<=n+m;++i)ex[i]=ex[i-1]*2%M;
	printf("%lld\n",(ex[n]-ex[cnt]+M)*1ll*ex[m-1]%M);
	return 0;
}


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

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

  char s;
  for (int i = 0; i < n; i++) {
    cin >> s;
    if (s == 'Y') {
      cout << "Four" << endl;
      return 0;
    }
  }
  cout << "Three" << endl;
}


Measured memory_bytes: 256
//
//  atcoder.cpp
//
//
///
#include <bits/stdc++.h>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/bimap/bimap.hpp>
#include <boost/bimap/multiset_of.hpp>
#include <boost/multi_array.hpp>
#include <boost/math/common_factor.hpp>
#include <boost/algorithm/string.hpp>

#define REP(i, N) for(int i=0; i<(N); i++)
#define REC(f, ...) (void)0; const auto f = [&](const auto f, __VA_ARGS__)
using namespace std;
using namespace boost::math;

using ll = long long;
namespace bst = boost;
template<typename T> class in {
    T value;
public:
    in() { cin >> value; }
    operator const T&() const { return value; }
    operator T&() { return value; }
    in& operator=(T source) { value = source; return *this; }
};
template<> class in<string> : public string {
public:
    in() { cin >> *this; }
};
template<class T> class inseq : public T {
public:
    template<typename... Arg> inseq(Arg... arg) : T(forward<Arg>(arg)...) { for (auto&& i : *this) cin >> i; }
};
template<class T> using invec = inseq<vector<T>>;

auto solve() {
  invec<int> A[3](invec<int>(3));
  in<int> N;
  invec<int> B(N);
  
  for (auto i : B)
    REP(j, 3) REP(k, 3) {
    if (A[j][k] == i)
      A[j][k] = -1;
  }
  
  string r = "No";
  REP (i,3) {
    int m = -2;
    REP(j,3)
      m = max(m, A[i][j]);
    if (m == -1)
      r = "Yes";
  }
  REP (i,3) {
    int m = -2;
    REP(j,3)
      m = max(m, A[j][i]);
    if (m == -1)
      r = "Yes";
  }
  if (A[0][0] == -1 && A[1][1] == -1 && A[2][2])
      r = "Yes";
  if (A[2][0] == -1 && A[1][1] == -1 && A[0][2])
      r = "Yes";





  return r;
}

template<typename T> void plot(const T& func) { cout << func() << endl; }
template<> void plot<void()>(void(&func)()) { func(); }
template<> void plot<double()>(double(&func)()) { cout << setprecision(9) << func() << endl; }

int main() {
  plot(solve);

  return 0;
}



Measured memory_bytes: 256
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
#include <map>
 
#include <algorithm>
#include <queue>
#include <cctype>
 
using namespace std;
 
#define rep(i, n) for (int i = 0; i < n; i++)
 
long long X,Y;
 
int main()
{
    cin >> X >> Y;
    int count = 0;
    while(X <= Y) {
        X = X*2;
        count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 256
N = int(input())
H = list(map(int, input().split()))

if N == 1:
  ans = 0
else:
  temp = 0
  ans = 0
  for n in range(N-1):
    l, r = H[n], H[n+1]
    if r > l:
      temp = 0
    else:
      temp += 1
    ans = max(ans, temp)
    
print(ans)
  


Measured memory_bytes: 14252
#include <iostream>

using namespace std;

int unit[4] = {10, 50, 100, 500};

int coins(int n){
	int ret=0;
	ret+=n/500,n%=500;
	ret+=n/100,n%=100;
	ret+=n/50,n%=50;
	ret+=n/10,n%10;
	return ret;
}

int main(){
	int n;
	for(int i=0;cin >> n,n;i++){
		int d[4],min=160000;
		int ret[4] = {20,20,20,20};
		if(i != 0) cout << endl;
		for(int i=0;i<4;i++) cin >> d[i];
		for(int i=0;i<=d[0];i++){
			for(int j=0;j<=d[1];j++){
				for(int k=0;k<=d[2];k++){
					for(int l=0;l<=d[3];l++){
						if(i*10 + j*50 + k*100 + l*500 < n) continue;
						int res = d[0] - i + d[1] - j + d[2] - k + d[3] - l + coins(i*10 + j*50 + k*100 + l*500 - n);
						if(res < min){
							ret[0] = i,ret[1] = j,ret[2] = k,ret[3] = l;
							min = res;
						}
					}
				}
			}
		}
		for(int i=0;i<4;i++){
			if(ret[i] == 0) continue;
			cout << unit[i] << " " << ret[i] << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>
#define SIZE 100

const int inf = 10000000;

enum status {
	EMPTY,
	AVAILABLE,
	FULL
};

typedef struct {
	int data[SIZE];
	int head;
	int tail;
	int flag;
}queue_t;

/*void printQueue(queue_t* pQueue) {
	for (int i = 0; i < SIZE; i++) {
		printf("%d",pQueue->data[i]);
	}
	printf("\n");
}*/

void initQueue(queue_t* pQueue) {
	for (int i = 0; i < SIZE; i++) pQueue->data[i] = 0;
	pQueue->head = 0;
	pQueue->tail = 0;
	pQueue->flag = EMPTY;
	//printQueue(pQueue);
}

void enqueue(queue_t* pQueue, int value) {
	//printf("enQ(%d)\n", value);
	if (pQueue->flag == FULL) {
		//printf("FULL\n");
		return;
	}
	pQueue->data[pQueue->tail] = value;
	if (pQueue->tail == SIZE - 1) pQueue->tail = 0;
	else pQueue->tail++;
	if (pQueue->tail == pQueue->head) pQueue->flag = FULL;
	else pQueue->flag = AVAILABLE;
	//printQueue(pQueue);
}

int dequeue(queue_t* pQueue) {
	//printf("deQ\n");
	if (pQueue->flag == EMPTY) {
		//printf("EMPTY\n");
		return 0;
	}
	int t = pQueue->data[pQueue->head];
	pQueue->data[pQueue->head] = 0;
	if (pQueue->head == SIZE - 1) pQueue->head = 0;
	else pQueue->head++;
	if (pQueue->tail == pQueue->head) pQueue->flag = EMPTY;
	else pQueue->flag = AVAILABLE;
	//printQueue(pQueue);
	return t;
}

int main() {
	queue_t queue;
	queue_t* pQueue = &queue;
	initQueue(pQueue);

	int N, X, Y, d[2010], dd[2] = { 1,-1 }, ans[2010] = {0};
	scanf("%d%d%d", &N, &X, &Y);

	for (int i = 1; i <= N; i++) {
		for (int h = 1; h <= N; h++) d[h] = inf;
		enqueue(pQueue, i);
		d[i] = 0;
		while (pQueue->flag != EMPTY) {
			int p = dequeue(pQueue);
			if (p == X) {
            	if (Y <= N && d[Y] == inf) {
					enqueue(pQueue, Y);
					d[Y] = d[p] + 1;
					ans[d[Y]]++;
            		//printf("%d %d\n",Y,d[Y]);
                }
			}
			for (int u = 0; u < 2; u++) {
				int j = p + dd[u];
				if (j <= N && d[j] == inf) {
					enqueue(pQueue, j);
					d[j] = d[p] + 1;
                	//printf("%d %d\n",j,d[j]);
					if (j > i) {
						ans[d[j]]++;
						//printf("%d %d\n", j, d[j]);
					}
				}
			}
		}
	}

	for (int i = 1; i <= N-1; i++) printf("%d\n", ans[i]);
	
	return 0;
}

Measured memory_bytes: 128
// D.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include<vector>
#include<map>

using namespace std;
typedef long long ll;

//
//void decompositPrime(long long n)
//{
//    // 割る数の初期値
//    long long  a = 2;
//    int cnt = 0;
//    // √n ≧ a ( n ≧ a * a ) の間ループ処理
//    while (n >= a * a) {
//        // a で割り切れたら、a は素因数
//        // そして、割られる数を a で割る
//        // a で割り切れなかったら、 a を 1 増加させる
//        if (n % a == 0) {
//          //  printf("%d * ", a);
//            cnt++;
//            n /= a;
//            if (cnt == 1) { v.push_back(1); }
//            else {
//                auto itr= v.end();
//                *itr++;
//
//            }
//
//            if (n == a) {
//                //cnt++;
//                //v.push_back(cnt);
//                auto itr = v.end();
//                *itr++;
//            }
//        }
//        else {
//            cnt = 0;
//            a++;
//        }
//    }
//    // 最後に残った n は素因数
//    if (n != a)v.push_back(1);
//}

int main()
{
    ll n;
    cin >> n;
    
    vector<pair<ll, int>> fs;
    for (ll i = 2; i * i <= n; i++) {
        int x = 0;
        while (n % i == 0) {
            n /= i;
            ++x;
        }
        fs.emplace_back(i, x);
    }
    if (n != 1)fs.emplace_back(n,1);

    int  ans=0;
    for (auto p : fs) {
        int x = p.second;
        int b = 1;
        while (b <= x) {
            x -= b;
            b++;
            ++ans;
        }
    }
    cout << ans << endl;


}



Measured memory_bytes: 19772
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author rahdirigs
 */

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

template <typename T> void s_max(T& a, T b) {
	if (a < b) {
		a = b;
	}
}
template <typename T> T vec_max(vector<T>& a) {
	return *(max_element(a.begin(), a.end()));
}

class TaskC {
public:
	void solve(std::istream& in, std::ostream& out) {
		int n;
		in >> n;
		vector<vector<int>> a(n, vector<int> (3));
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < 3; j++) {
				in >> a[i][j];
			}
		}
		vector<vector<ll>> dp(n, vector<ll> (3, 0));
		for (int i = 0; i < 3; i++) dp[0][i] = a[0][i];
		for (int i = 1; i < n; i++) {
			for (int j = 0; j < 3; j++) {
				for (int k = 0; k < 3; k++) {
					if (k == j) continue;
					s_max(dp[i][j], dp[i - 1][k] + a[i][j]);
				}
			}
		}
		out << vec_max(dp[n - 1]);
	}
};


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
	TaskC solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 14200
H, W = map(int, input().split())
S = []
for i in range(H):
    S.append([c for c in input()])

l = [[-1, -1], [-1, 0], [-1, 1], [0, -1], [0, 1], [1, -1], [1, 0], [1, 1]]

for i in range(H):
    for j in range(W):
        c = 0
        if S[i][j] == "#":
            continue
        for k in range(8):
            x = j + l[k][0]
            y = i + l[k][1]
            if x < 0 or x >= W or y < 0 or y >= H:
                continue
            #print(x,y,S[y][x])
            if S[y][x] == '#':
                c += 1
        S[i][j] = str(c)
        
for i in range(H):
    print(''.join(S[i]))

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

#define int    long long

void fast()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
}
//a^n O(log(n))

int power(int a, int n)
{
	int result = 1;
	while (n > 0)
	{
		if (n & 1)
		{
			result = result * a;
		}
		a = a * a;
		n = n >> 1;

	}
	return result;
}


bool compare(string &s1, string &s2)
{
	return s1.size() < s2.size();
}

char b[7][7];
char a[7][7];
int n, m, k;


void copy_matrix()
{
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < m; ++j)
		{
			b[i][j] = a[i][j];
		}
	}
	return;
}

void color(int i, int j)
{
	for (int x = 0; x < n; ++x)
	{
		if (i & (1 << x))
		{
			for (int y = 0; y < m; ++y)
			{
				b[x][y] = '$';
			}
		}
	}
	for (int x = 0; x < m; ++x)
	{
		if (j & (1 << x))
		{
			for (int y = 0; y < n; ++y)
			{
				b[y][x] = '$';
			}
		}
	}

	return;
}

bool check()
{
	int total = 0;
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < m; ++j)
		{
			if (b[i][j] == '#')
				total++;
		}
	}

	if (total == k)
		return true;
	else
		return false;
}

void solve()
{
	cin >> n >> m >> k;

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

	int total = 0;

	for (int i = 0; i < (1 << n); ++i)
	{
		for (int j = 0; j < (1 << m); ++j)
		{
			copy_matrix();

			color(i, j);

			if (check())
				total++;
		}
	}
	cout << total << '\n';
	return;
}

int32_t main()
{
	fast();

	solve();

	return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE

class UF{
public:
  int V;
  vector<int> par,rnk,sz;
  UF(){}
  UF(int V):V(V),par(V),rnk(V,0),sz(V,1){for(int i=0;i<V;i++)par[i]=i;}
  
  int find(int x){
    assert(x < V);
    if(par[x]==x)return x;
    return par[x]=find(par[x]);
  }
  
  void unite(int x,int y){
    x=find(x), y=find(y);
    if(x==y)return;
    if(rnk[x]<rnk[y])par[x]=y, sz[y] += sz[x];
    else{
      par[y]=x;
      sz[x] += sz[y];
      if(rnk[x]==rnk[y])rnk[x]++;
    }
  }

  bool same(int x,int y){return find(x)==find(y);}

  int size(int x){return sz[find(x)];}
};

signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N;
  cin>>N;

  UF uf(N);

  
  vector<vector<P> > tmp(N);
  for(int i=0;i<N-1;i++){
    int a, b, c;
    cin>>a>>b>>c; a--, b--, c%=2;
    tmp[a].push_back(P(b, c));
    tmp[b].push_back(P(a, c));
    if(c==0) uf.unite(a, b);
  }

  map<int,int> idx;
  int cnt = 0;
  for(int i=0;i<N;i++) if(i == uf.find(i)) idx[i] = cnt++;
  
  vector<vector<int> > G(cnt);
  for(int i=0;i<N;i++)
    for(auto p:tmp[i]){
      int to, c;
      tie(to,c) = p;
      if(c == 0) continue;
      G[idx[uf.find(i)]].push_back(idx[uf.find(to)]);
    }

  vector<int> Col(cnt, -1);
  function<void(int,int,int)> dfs =[&](int pos, int pre, int col){
    Col[pos] = col;
    for(int to:G[pos]){
      if(to != pre) dfs(to, pos, !col);
    }    
  };

  dfs(0, 0, 0);
  
  for(int i=0;i<N;i++){
    cout<<Col[ idx[uf.find(i)] ]<<endl;
  }
    
  
return 0;
}


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

namespace AtCoder2 {
	class Program {
		static void Main(string[] args) {
			var inputArray = retreiveLongArray();
			var inputCount = 2;

			// 不正な入力は処理しない
			if (inputArray.Length != inputCount) {
				Console.WriteLine("invalid input");
				return;
			}
			long N = inputArray[0];
			long M = inputArray[1];

			var hightArray = retreiveLongArray();

			var badTenboudais = new HashSet<long>();

			for (int i = 0; i < M; i++) {

				var AB = retreiveLongArray();
				var A = AB[0];
				var B = AB[1];

				var heightA = hightArray[A - 1];
				var heightB = hightArray[B - 1];

				if(heightA >= heightB) {
					if (!badTenboudais.Contains(B)) {
						badTenboudais.Add(B);
					}
				}
				if (heightB >= heightA) {
					if (!badTenboudais.Contains(A)) {
						badTenboudais.Add(A);
					}
				}
			}

			//答えの出力
			var ans = N-badTenboudais.Count();
			Console.WriteLine(ans);

		}

		/// <summary>
		/// スペースで区切られた文字列配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static string[] retreiveStringArray() {
			var inputArray = Console.ReadLine().Split(' ');
			return inputArray;
		}

		/// <summary>
		/// スペースで区切られた整数配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static long[] retreiveLongArray() {
			var inputArray = Console.ReadLine().Split(' ');
			var longArray = inputArray.Select(s => long.Parse(s));
			return longArray.ToArray();
		}
	}
}


Measured memory_bytes: 49628
n = int(input())
from collections import defaultdict
sl = []
tl = []
for i in range(n):
  s, t = input().split()
  t = int(t)
  sl.append(s)
  tl.append(t)
x = input()
ans = 0
for i in range(sl.index(x) + 1, n):
  ans += tl[i]
print(ans)

Measured memory_bytes: 3436
#include<bits/stdc++.h>
using namespace std;
int koszta[1000006][3];//koszty kwiatkow
int tab[1000006][3];//koszt do rabatki dal koloru a kazym numerze na koncu
int n,best;

void dp(){
	for(int i=2;i<=n;i++){//przejdz po domach
		tab[i][0]=max(tab[i-1][1],tab[i-1][2])+koszta[i][0];
		tab[i][1]=max(tab[i-1][0],tab[i-1][2])+koszta[i][1];
		tab[i][2]=max(tab[i-1][0],tab[i-1][1])+koszta[i][2];
	}
}

void prubuj(){
	tab[1][1]=koszta[1][1];
	tab[1][0]=koszta[1][0];
	tab[1][2]=koszta[1][2];
	dp();
	best=max(max(tab[n][0],tab[n][1]),tab[n][2]);
}

void wczyt(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>koszta[i][0]>>koszta[i][1]>>koszta[i][2];
	}
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	wczyt();
	prubuj();
	cout<<best;
	return 0;
}

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

int main(){
	int h,w;
	cin >> h >> w;
	int a[h][w];
	for(int i=0;i<h;i++)
		for(int j=0;j<w;j++)
			cin >> a[i][j];	
	
	int n=0;
	vector<int> y1,x1,y2,x2;
	for(int i=0;i<h;i++){
		int j = i%2==0 ? 0:w-1;
		int sign = j==0 ? 1:-1;
		int count=0;
		for(j;count<w;j+=sign,count++){
			if(count<w-1 && a[i][j]%2!=0){
				a[i][j]--;
				a[i][j+sign]++;
				y1.push_back(i+1);
				x1.push_back(j+1);
				y2.push_back(i+1);
				x2.push_back(j+sign+1);
				n++;
			}
			else if(count==w-1 && a[i][j]%2!=0 && i<h-1){
				a[i][j]--;
				a[i+1][j]++;
				y1.push_back(i+1);
				x1.push_back(j+1);
				y2.push_back(i+1+1);
				x2.push_back(j+1);
				n++;
			}
		}
	}

	cout << n << endl;
	for(int i=0;i<n;i++)
			cout << y1[i] << ' ' << x1[i] << ' ' << y2[i] << ' ' << x2[i] << endl;
	
}


Measured memory_bytes: 5220
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;

using P = pair<int, int>;

int main() {
    int N, C;
    cin >> N >> C;

    vector<P> seg[30];
    for (int i = 0; i < N; i++) {
        int s, t, c;
        cin >> s >> t >> c;
        c--;
        seg[c].emplace_back(s, t);
    }
    for (int i = 0; i < 30; i++) {
        sort(seg[i].begin(), seg[i].end());
        reverse(seg[i].begin(), seg[i].end());
    }

    vector<P> segments;
    for (int i = 0; i < 30; i++) {
        while (!seg[i].empty()) {
            P s = seg[i].back();
            seg[i].pop_back();
            while (!seg[i].empty() and seg[i].back().first == s.second) {
                s.second = seg[i].back().second;
                seg[i].pop_back();
            }
            segments.push_back(s);
        }
    }
    static int imos[200000];
    for (auto seg : segments) {
        imos[seg.first]++;
        imos[seg.second + 1]--;
    }
    int ans = imos[0];
    for (int i = 1; i < 200000; i++) {
        imos[i] += imos[i - 1];
        ans = max(ans, imos[i]);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3060
import java.util.Scanner;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.HashSet;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N=sc.nextInt();
    int K=sc.nextInt();
    int count=0;
    List<Integer> As = new ArrayList<>();
    List<Integer> Bs = new ArrayList<>();
    for (int i=1;i<=N ;i++ ) {
       As.add(i);
    }
    for(int i=0;i<K;i++){
      int d=sc.nextInt();
      for (int j=0;j<d ;j++ ) {
         Bs.add(sc.nextInt());
      }
    }
    List<Integer> Cs = new ArrayList<Integer>(new HashSet<>(Bs));
       for(int i=1;i<=N;i++){
         if(!(Cs.contains(i))){
            count++;
         }
       }
       System.out.println(count);



  }
}


Measured memory_bytes: 46432
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;

string changestr(string,string::size_type);

int main(){
  int n;
  string str="";
  string::size_type st;

  cin>>n;
  for(int i=0;i<n;i++){
	 for(;;){
		getline(cin,str);
		if(str!="") break;
	 }

	 st=str.find("Hoshino");
	 while(st!=string::npos){
		str=changestr(str,st);
		st=str.find("Hoshino");
	 }
	 cout<<str<<endl;
  }
  return 0;
}

string changestr(string str,string::size_type st){
  string name="Hoshina";
  for(int i=0;i<7;i++) str[st+i]=name[i];

  return str;
}

Measured memory_bytes: 1220
# coding: utf-8
def II(): return int(input())
def ILI(): return list(map(int, input().split()))


def read():
    N = II()
    return (N,)


def solve(N):
    ans = []
    for h in range(1, 3501):
        flag = False
        for n in range(1, 3501):
            if 4 * h * n - N * h - N * n == 0:
                continue
            div, mod = divmod(N * h * n, 4 * h * n - N * h - N * n)
            if mod == 0 and div > 0:
                ans = [h, n, div]
                flag = True
                break
        if flag:
            break
    ans = " ".join(map(str, ans))
    return ans


def main():
    params = read()
    print(solve(*params))


if __name__ == "__main__":
    main()


Measured memory_bytes: 39792
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
r#"2 3 5"# => r#"Yes"#,
r#"5 2 5"# => r#"No"#,
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        a: usize,
        b: usize,
        c: usize,
    }

    if a + b == c || b + c == a || a + c == b {
        "Yes"
    } else {
        "No"
    }.to_string()
}

Measured memory_bytes: 4352
S = input()
S = list(S)

N = len(S)

gusu = S[1::2]
kisu = S[::2]

g = 1
for i in range(len(gusu)):
    if gusu[i] == "L" or gusu[i] == "U" or gusu[i] == "D":
        g = g*1
    else:
        g = 0

k = 1
for i in range(len(kisu)):
    if kisu[i] == "R" or kisu[i] == "U" or kisu[i] == "D":
        k = k*1
    else:
        k = 0

if g*k == 1:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
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);
        ABC115_D solver = new ABC115_D();
        solver.solve(1, in, out);
        out.close();
    }

    static class ABC115_D {
        static private long[] paties = new long[51];
        static private long[] height = new long[51];

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            long x = in.nextLong();
            paties(n, paties);
            height(n, height);
            long ans = answer(n, x);

            out.print(ans);


        }

        private long answer(int n, long x) {
            if (n == 0) {
                if (x <= 0) {
                    return 0;
                } else {
                    return 1;
                }
            }

            if (x <= 1 + height[n - 1]) {
                return answer(n - 1, x - 1);
            } else {
                return paties[n - 1] + 1 + answer(n - 1, x - 2 - height[n - 1]);
            }
        }

        private long paties(int n, long[] paties) {
            if (n == 0) {
                paties[n] = 1;
                return 1;
            } else {
                long p = paties(n - 1, paties);
                paties[n] = 2 * p + 1;
                return 2 * p + 1;
            }
        }

        private long height(int n, long[] height) {
            if (n == 0) {
                height[n] = 1;
                return 1;
            } else {
                long h = height(n - 1, height);
                height[n] = 2 * h + 3;
                return 2 * h + 3;
            }

        }

    }
}



Measured memory_bytes: 21844
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int k = scanner.nextInt();
        Queue<Long> queue = new ArrayDeque<>();
        for (int i = 1; i <10 ; i++) {
            queue.add((long)i);
        }
        while (true){
            Long poll = queue.poll();
            k--;
            if(k==0){
                System.out.println(poll);
                return;
            }else{
                Long d = poll % 10;
                if(d>0){
                    queue.add(poll*10 + d - 1);
                }
                queue.add(poll*10+d);
                if(d<9){
                    queue.add(poll*10 + d + 1);
                }
            }
        }
    }
}


Measured memory_bytes: 29396
N, M = map(int,input().split())
P = [list(map(int,input().split())) for i in range(M)]

ans = [0 for i in range(N+1)]

for i in range(M) :
    ans[P[i][0]] += 1
    ans[P[i][1]] += 1

for i in range(1,N+1) :
    print(ans[i])

Measured memory_bytes: 3060
from itertools import permutations

N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))

iP = -1
iQ = -1
for idx, perm in enumerate(permutations(range(1, N+1))):
    lp = list(perm)
    if lp == P:
        iP = idx
    if lp == Q:
        iQ = idx
print(abs(iP - iQ))

Measured memory_bytes: 40300
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = (a); i >= (b); --i)
#define pb push_back
#define mp make_pair
#define x first
#define y second
using namespace std;

template<typename T>
void read(T& n){
	char ch; int sign = 1;
	while (!isdigit(ch = getchar())) if (ch == '-') sign = -1;
	n = ch - '0';
	while (isdigit(ch = getchar())) n = n * 10 + ch - '0';
	n *= sign;
}
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9 + 7;
const int N = 333;
int n;
int okay[N][N];
char a[N][N];

int main(){
	read(n);
	rep(i, 1, n) rep(j, 1, n)
		scanf(" %c", &a[i][j]);
	rep(i, 1, n) rep(j, 1, n){
		okay[i][j] = 1;
		rep(k, 0, n - 1){
			int x = (i + k - 1) % n + 1, y = (j + k - 1) % n + 1;
			okay[i][j] &= a[x][j] == a[i][y];
		}
	}
	int ans = 0;
	rep(i, 1, n) rep(j, 1, n){
		bool flg = true;
		rep(k, 0, n - 1){
			int x = (i + k - 1) % n + 1, y = (j + k - 1) % n + 1;
			flg &= okay[x][y];
		}
		ans += flg;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 768
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int N;
    cin >> N;

    string S;
    cin >> S;

    ll cnt = 0;
    char cur = 'A';
    REP(i, S.size()) {
        if (cur == S[i]) cnt++;
        cur = S[i];
    }

    print(S.size() - cnt);
    
}


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

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

Measured memory_bytes: 256
class GCD:

    def __init__(self, N, K, MOD):
        self.N = N
        self.K = K
        self.MOD = MOD
        self.gcd_count_list = []
        self.gcd_count_list2 = [0]*self.K
        for d in range(1,self.K+1):
            self.gcd_count_list.append(self.gcd_count(d))
        self.gcd_count2()

    def gcd_count(self, d):
        """  d, 2d, 3d,... の最大公約数を持つ K 以下の整数 N 個の組の数　"""
        return pow(self.K//d,self.N,self.MOD)

    def gcd_count2(self):
        """  dの最大公約数を持つ K 以下の整数 N 個の組の数　"""
        res = []
        i = 1
        while K//i > 0:
            for j in range(K//(i+1)+1,K//i+1):
                self.gcd_count_list2[j-1] = self.gcd_count_list[j-1] \
                - sum(self.gcd_count_list2[j*k-1] for k in range(2, i+1))
            i += 1

    def solve(self):
        return sum(d*self.gcd_count_list2[d-1] for d in range(1,K+1))%MOD

N, K = map(int, input().split())
MOD = 10**9 + 7
g = GCD(N, K, MOD)
print(g.solve())

Measured memory_bytes: 80160
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int t = 0;
vector<vector<int>> graph(110);
vector<ip> ans(110,make_pair(-1,-1));

void dfs(int index){
	if(ans[index].first==-1)ans[index].first = ++t;
	else return ;
	if(graph[index].size()==0){
		if(ans[index].second == -1){
			ans[index].second = ++t;
		}
		return;
	}
	rep(i,graph[index].size()){
		dfs(graph[index][i]);
	}
	if(ans[index].second == -1){
		ans[index].second = ++t;
	}
	return ;
}

int main(){
	int n;
	cin>>n;
	REP(i,n){
		int cnt;
		cin>>cnt>>cnt;
		vector<int> pp(cnt);
		rep(j,cnt){
			cin>>pp[j];
		}
		graph[i] = pp;
	}
	REP(i,n){
		if(ans[i].first==-1)dfs(i);
	}
	REP(i,n){
		cout<<i<<' '<<ans[i].first<<' '<<ans[i].second<<endl;
	}
	return 0;
}


Measured memory_bytes: 3140
#include<vector>
#include<iostream>
#include<algorithm>
#include<functional>
#include<string>
#include<limits.h>
#include<cmath>
#include<queue>
#include<map>
#define rep(i,n) for (int i=0; i<n; i++)
using namespace std;
typedef long long ll;

ll gcd(ll a,ll b){
  ll r;
  while ((r=a%b)){a=b;b=r;}
  return b;
}

int main(){

  string s; cin >> s;
  int n=s.size();
  vector<int> a(n,0);

  int repR=0;

  rep(i,n){
    if (s[i]=='R'){repR++;}
    else {
      a[i-1]+=ceil(repR/2.0);
      a[i]+=floor(repR/2.0);
      repR=0;
    }
  }

  int repL=0;

  rep(i,n){
    if (s[i]=='L'){repL++;}
    else {
      a[i-repL-1]+=floor(repL/2.0);
      a[i-repL]+=ceil(repL/2.0);
      repL=0;
    }
  }

  a[n-repL-1]+=floor(repL/2.0);
  a[n-repL]+=ceil(repL/2.0);

  rep(i,n){
    cout << a[i] << " ";
  }

  return 0;
}


Measured memory_bytes: 1024
#include<cstdio>

int main(){
    int r,g,b,n;
    scanf("%d%d%d%d",&r,&g,&b,&n);
    int m1 = n/r;
    int m2 = n/g;
    int ans = 0;
    for(int i = 0; i <= m1; i++){
        for(int j = 0; j <= m2; j++){
            int left = n - i*r-j*g;
            if(left>=0 && left%b==0) ans++;
        }
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define int ll
typedef pair<int, int> pii;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n)   FOR(i,0,n)
#define RREP(i,n)   RFOR(i,0,n)
const int INF = 1e9;
const int MOD = 1e9+7;

signed main() {
    ios::sync_with_stdio(false);cin.tie(0);
    int N; cin >> N;
    int M; cin >> M;
    int k[M];
    int s[M][N];
    int p[M];
    int light[N+1];
    REP(i, M) {
        cin >> k[i];
        REP(j, k[i]) {
            cin >> s[i][j];
            s[i][j]--;
        }
    }
    REP(i, M) {
        cin >> p[i];
    }

    int ans = 0;

    REP(bit, 1<<N) {
        bool can = true;
        REP(i, M) {
            int cnt = 0;
            REP(j, k[i]) {
                if(bit & (1<<s[i][j])) {
                    cnt++;
                }
            }
            if(cnt%2 != p[i]) {
                can = false;
                break;
            }
        }
        if(can) {
            ans += 1;
        }
    }
    cout << ans << endl;
}

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

int main(){
  int N;
  cin >> N;
  vector<string> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  set<string> S;
  for (int i = 0; i < N; i++) {
    S.insert(vec.at(i));
  }
  cout << S.size() << endl;
  
}


Measured memory_bytes: 25172
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define N 100005
#define LL long long
int a[N],n;
LL ans,sum[N];
LL check(int mid)
{
	ans=0;LL cnt=0;
	for(int i=n,j=1;i>=1;i--){
		while(j<=n&&a[i]+a[j]<mid)
			j++;
		ans+=sum[j]+1ll*a[i]*(n-j+1);
		cnt+=1ll*(n-j+1);
	}
	return cnt;
}
int main()
{
	int i,l,r,mid;long long m,tmp=0;
	scanf("%d%lld",&n,&m);
	for(i=1;i<=n;i++)
		scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	for(i=n;i>=1;i--)
		sum[i]=1ll*a[i]+sum[i+1];
	l=0;r=2000000;
	while(l<r){
		mid=(l+r)>>1;
		if(check(mid)>=m){
			tmp=ans;
			l=mid+1;
		}
		else
			r=mid;
	}
	tmp-=1ll*(check(l-1)-m)*(l-1);
	printf("%lld",tmp);
}

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

#define ll long long
#define pb push_back
#define mp make_pair
#define mo 1000000007
#define MAX 1000004
#define fast_io ios::sync_with_stdio(false)
map<int, int> m1;
int a[MAX];
int main()
{
	fast_io;
	int n;
	cin >> n;
	for(int i=1;i<=n;i++)
	{
		cin >> a[i];
		m1[a[i]]++;
	}
	int ans = 0;
	for(auto it: m1)
	{
		if(it.first > it.second)
			ans += it.second;
		else
			ans += it.second - it.first;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 5120
ans = 0
num = list(map(int,input().split()))
for i in range(2):
    if num[i] == 1:
        ans += 300000
    elif num[i] == 2:
        ans += 200000
    elif num[i] == 3:
            ans += 100000
if num[1] == num[0] == 1:
    ans += 400000
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
int main()
{
   int x;
   cin >> x;
   if (x < 1200)
   {
      cout << "ABC" << endl;
   }
   else
   {
      cout << "ARC" << endl;
   }
   return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define F first
#define S second
#define pi acos(-1)
using ll = long long;
using namespace std;
using namespace __gnu_pbds;
using vl = vector<ll>;
using pll =  pair<ll,ll>;
const ll mod = 1000000007;
const ll infi = 1000000000000000;
const ll md = 998244353;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;


ll power(ll x,ll y){
    ll res = 1;
    while(y){
        if(y&1)
            res = (res*x)%md;
        x = (x*x)%md;
        y = y/2;
    }
    return res;
}


void solve(){
    string s;
    cin>>s;
    cout<<s[0]<<s[1]<<s[2];
}
 
int main()
{
 

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //int n; cin>>n; for (int i = 0; i < n; ++i)
    solve();
    return 0;
}


Measured memory_bytes: 3648
import java.util.*;
class Main{
	public static void main(String args[]){
    	Scanner s = new Scanner(System.in);
      	int health = s.nextInt();
      	int attack = s.nextInt();
      	int numAttack = 0;
      	do{
        	health-=attack;
          	numAttack++;
        }while(health>0);
      	System.out.println(numAttack);
    }
}

Measured memory_bytes: 22740
#include <cstdio>
#include <vector>
#include <string>

using namespace std;

int a[50];
char s[101];

int main() {
    int n, ans = 0, i;
    string x;
    vector <string> v;
    
    scanf("%d", &n);
    
    for (i = 0; i < n; i++) {
        scanf("%s %d", s, &a[i]);
        
        v.push_back(s);
    }
    
    scanf("%s", s);
    x = s;
    
    for (i = 0; i < n; i++) {
        if (v[i] == x) break;
    }
    
    for (i++; i < n; i++) ans += a[i];
    
    printf("%d\n", ans);
    
    return 0;
}


Measured memory_bytes: 256