akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.next());
    int[][] stu = new int[N][2];
    for(int i = 0; i < N; i++){
      int a = Integer.parseInt(sc.next());
      stu[i][0] = a;
      stu[i][1] = i+1;
    }
    Arrays.sort(stu, (a,b)->Integer.compare(a[0], b[0]));
    
    for(int i = 0; i < N; i++){
      System.out.print(stu[i][1]);
      System.out.print(" ");
    }
    System.out.println("");
  }
}

Measured memory_bytes: 54764
def solve(n, x):
    if x == 1:
        if n == 0:
            return 1
        else:
            return 0
    elif 1 < x <= 1 + layer[n-1]:
        return solve(n-1, x-1)
    elif x == 2 + layer[n-1]:
        return patty[n-1] + 1
    elif 2 + layer[n-1] < x <= 2 + 2 * layer[n-1]:
        return solve(n-1, x-layer[n-1]-2) + patty[n-1] + 1
    else:
        return 2 * patty[n-1] + 1


N, X = map(int, input().split())

layer, patty = [1], [1]
for _ in range(N):
    layer.append(layer[-1] * 2 + 3)
    patty.append(patty[-1] * 2 + 1)

print(solve(N, X))

Measured memory_bytes: 61580
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
#define INF 100000000
typedef pair<int, int> P;

int N, M;
int graph[50][50];

int main(){
    cin >> N >> M;
    for(int i=0; i<N; i++){
        for(int j=0; j<N; j++){
            graph[i][j] = INF;
        }
    }

    P edge[M];

    for(int i=0; i<M; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        graph[a][b] = graph[b][a] = 1;
        edge[i] = P(a, b);
    }

    int res = 0;
    for(int i=0; i<M; i++){
        int dist[N][N];
        for(int j=0; j<N; j++){
            for(int k=0; k<N; k++){
                dist[j][k] = graph[j][k];
            }
        }
        int a=edge[i].first, b=edge[i].second;
        dist[a][b] = dist[b][a] = INF;
        for(int z=0; z<N; z++){
            for(int x=0; x<N; x++){
                for(int y=0; y<N; y++){
                    dist[x][y] = min(dist[x][y], dist[x][z]+dist[z][y]);
                }
            }
        }
        if(dist[a][b] == INF){
            res++;
        }
    }

    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
from copy import deepcopy

s = list(input())
t = list(input())
st=[]

for i in range(len(s)-len(t)+1):
    l=deepcopy(s[len(s)-len(t)-i:len(s)-i])
    for j in range(len(t)):
        if l[j] ==  '?':
            l[j]=t[j]
    if l==t:
        u=deepcopy(s)
        u[len(u)-len(t)-i:len(u)-i]=t
        st.append(''.join(u).replace('?','a'))

if len(st) == 1:
    print(st[0])
elif len(st)>1:
    ans = st[0]
    for i in range(1,len(st)):
        if ans > st[i]:
            ans = st[i]
    print(ans)
else:
    print('UNRESTORABLE')

Measured memory_bytes: 3444
#include <stdio.h>

int main(void) {
	int a, b, c, i, count = 0;
	scanf("%d %d %d", &a, &b, &c);
	for (i = a;i <= b; i++) {
		if (c % i == 0) count++;
	}
	printf("%d\n", count);
	return 0;
}

Measured memory_bytes: 596
#include <iostream>

int main()
{
	int N = 0;
	std::cin >> N;

	float ans = 0.0f;
	for (int i = 0; i < N; ++i)
	{
		int temp = 0;
		std::cin >> temp;

		ans += 1.0f / temp;
	}

	std::cout << 1.0f / ans << "\n";

	return 0;
}

Measured memory_bytes: 256
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
s=Counter(a)
res=0
for i in s.values():
    res+=i*(i-1)//2
ans=0
for j in range(n):
    if s[a[j]]==1:
        print(res)
    else:
        ans=res-s[a[j]]+1
        print(ans)

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

int main() {
  int n,k;
  cin >> n >> k;
  
  int c = 1;
  for(int i=0;i<n;i++){
    int a,b;
  a = 2*c;
  b = c + k;
    if(a<b)
      c = a;
    else
      c = b;
  }
  cout << c << endl;
}




Measured memory_bytes: 256
#include <stdio.h>
#define MAX 100000

int A[MAX], n;

int partition(int p, int r) {
  int x, i, j, t;
  x = A[r];
  i = p-1;
  for(j=p; j<r; j++) {
    if(A[j] <= x) {
      i++;
      t=A[i]; A[i]=A[j]; A[j]=t;
    }
  }
  t=A[i+1]; A[i+1]=A[r]; A[r]=t;
  return i+1;
}

int main(void) {
  int i, q;

  scanf("%d", &n);
  for(i=0; i<n; i++) scanf("%d",&A[i]);
  q = partition(0,n-1);

  for(i=0; i<n; i++) {
    if(i) printf(" ");
    if(i==q) printf("[");
    printf("%d",A[i]);
    if(i==q) printf("]");
  }
  printf("\n");

  return 0;
}

Measured memory_bytes: 2164
H, W = map(int, input().split())
s = ['.'+input()+'.' for _ in range(H)]
s.insert(0,'.'*(W+2))
s.append('.'*(W+2))
for i in range(1,H+1):
    for j in range(1,W+1):
        if s[i][j] == '#' and (s[i-1][j] + s[i][j-1:j+2] + s[i+1][j]).count('#') == 1:
            print('No')
            exit()
print('Yes')


Measured memory_bytes: 66336
#include <iostream>
using namespace std;
int main(){
    int i=0;
    int n,x;
    cin>>n>>x;
    while(!(n==0 && x==0)){
        i=0;
        for(int j=2;j<n;j++){
            for(int k=1;k<j;k++){
                for(int l=0;l<k;l++){
                    if(j+k+l+3==x){
                        i++;
                    }
                }
            }
        }
        cout<<i<<endl;
        cin>>n>>x;
    }
}

Measured memory_bytes: 3084
while True:
    s = input()
    if s == '#':
        break
    ans = False
    clauses = s.split('|')
    for cla in clauses:
        clause = cla[1:-1]
        c = clause.split('&')
        tmp = True
        for ele in c:
            tmp &= not ('-' + ele if len(ele) == 1 else ele[-1]) in c
        ans |= tmp
    print("yes" if ans else "no")


Measured memory_bytes: 5572
#include <iostream>

#include <vector>
#include <map>
#include <algorithm>
#include <fstream>
#include<cstdio>
#include<iomanip>

#define REP(i, n) for(int i=0;i<n;i++)
#define REP2(i, s, n) for(int i=s;i<n;i++)
#define REP_1(i, n) for(int i=1;i<n+1;i++)
#define bitSearch(bit, n) for(int bit = 0; bit < (1 << N); bit++)
using namespace std;

void printAns(int a) { cout << a << endl; }

void yesno(bool a) { if (a)cout << "Yes" << endl; else cout << "No" << endl; }

void YESNO(bool a) { if (a)cout << "YES" << endl; else cout << "NO" << endl; }

typedef long long ll;
typedef unsigned long ul;
typedef long double ld;

template<class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

ll INF = 10000000;
ll mod = 1000000007;//10^9+7



//番号ズレ注意！！
int main() {
    int N, K;
    cin >> N >> K;
    vector<double> p(N+1,1.0);
    REP_1(i, N) {
        int tmp = i;
        while (tmp < K) {
            p[i] = p[i] / 2.0;
            tmp *= 2;
        }
    }
    double ans = 0;
    REP_1(i, N) {
        ans += p[i] / N;
    }
    printf("%.12f", ans);

}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <fstream>
#include<cstdio>
#include<iomanip>

#define REP(i, n) for(int i=0;i<n;i++)
#define REP2(i, s, n) for(int i=s;i<n;i++)
#define REP_1(i, n) for(int i=1;i<n+1;i++)
#define bitSearch(bit, n) for(int bit = 0; bit < (1 << N); bit++)
using namespace std;

void printAns(int a) { cout << a << endl; }

void yesno(bool a) { if (a)cout << "Yes" << endl; else cout << "No" << endl; }

void YESNO(bool a) { if (a)cout << "YES" << endl; else cout << "NO" << endl; }

typedef long long ll;
typedef unsigned long ul;
typedef long double ld;

template<class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

ll INF = 10000000;
ll mod = 1000000007;//10^9+7



//番号ズレ注意！！
int main() {
    int X, A;
    cin >> X >> A;
    if (X < A) { cout << '0' << endl; }
    else { cout << "10" << endl; }

}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int a,b,c,k;
  scanf("%d%d%d%d", &a,&b,&c,&k);
  if(a+b>=k)
	if(k>a)printf("%d", a);
	else printf("%d", k);
  else printf("%d", a-(k-(a+b)));
}

Measured memory_bytes: 1708
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/rope>
using namespace std;
using namespace chrono;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
mt19937 rng(high_resolution_clock::now().time_since_epoch().count());
mt19937_64 rngll(high_resolution_clock::now().time_since_epoch().count());
template<typename T> T ctmax(T &x, const T &y){ return x = max(x, y); }
template<typename T> T ctmin(T &x, const T &y){ return x = min(x, y); }
template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;



int main(){
	cin.tie(0)->sync_with_stdio(0);
	cout << fixed << setprecision(15);
	int n;
	cin >> n;
	vector<double> a(n);
	for(auto i = 0; i < n; ++ i){
		cin >> a[i];
	}
	vector<vector<double>> dp(n + 1, vector<double>(n + 1));
	dp[0][0] = 1;
	for(auto i = 0; i < n; ++ i){
		for(auto j = 0; j <= i; ++ j){
			dp[i + 1][j + 1] += dp[i][j] * a[i];
			dp[i + 1][j] += dp[i][j] * (1 - a[i]);
		}
	}
	cout << accumulate(dp[n].begin() + n / 2 + 1, dp[n].end(), 0.0);
	return 0;
}

/*

*/

////////////////////////////////////////////////////////////////////////////////////////
//                                                                                    //
//                                   Coded by Aeren                                   //
//                                                                                    //
////////////////////////////////////////////////////////////////////////////////////////

Measured memory_bytes: 70784
package main

import (
	"fmt"
)

func main() {

	var n, m, l int

	fmt.Scan(&n, &m, &l)
	var a [][]int
	var b [][]int
	var c [][]int

	for i := 0; i < n; i++ {
		a = append(a, make([]int, m))
	}

	for i := 0; i < m; i++ {
		b = append(b, make([]int, l))
	}

	for i := 0; i < n; i++ {
		c = append(c, make([]int, l))
	}

	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			fmt.Scan(&a[i][j])
		}
	}

	for i := 0; i < m; i++ {
		for j := 0; j < l; j++ {
			fmt.Scan(&b[i][j])
		}
	}

	for i := 0; i < n; i++ {
		for j := 0; j < l; j++ {
			for k := 0; k < m; k++ {
				c[i][j] += a[i][k] * b[k][j]
			}
		}
	}
	for i := 0; i < n; i++ {
		for j := 0; j < l; j++ {
			if j != 0 {
				fmt.Print(" ")
			}
			fmt.Print(c[i][j])
		}
		fmt.Println()
	}
}



Measured memory_bytes: 2580
//D
//Author : Sidiq Tri Pratikto
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(v) v.begin(), v.end()

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set;
//order_of_key(x) = number of elements stricly smaller than x
//find_by_order(x) = return x-th largest element
typedef long long LL;
const LL MOD = 1e9 + 7;
const double PI = 2 * acos(0);

int main() {
	LL A, B, N;
	scanf("%lld%lld%lld", &A, &B, &N);
	if (N < B) {
		LL ans = (A * N) / B - A * (N / B);
		printf("%lld\n", ans);
	} else {
		LL ans = (A * (B - 1)) / B;
		printf("%lld\n", ans);
	}
}

Measured memory_bytes: 3768
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for ( int i=1; i<=int(n); i++ )  
#define MP make_pair
#define PB push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()
#define X first
#define Y second
template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

typedef long long LL;
typedef pair<int, int> pii;
typedef long double LD;
const int INF = 0x3f3f3f3f;

template <class T>  
inline bool RD(T &ret) {  
        char c; int sgn;  
        if (c = getchar(), c == EOF) return 0;  
        while (c != '-' && (c<'0' || c>'9')) c = getchar();  
        sgn = (c == '-') ? -1 : 1 , ret = (c == '-') ? 0 : (c - '0');  
        while (c = getchar(), c >= '0'&&c <= '9') ret = ret * 10 + (c - '0');  
        ret *= sgn;  
        return 1;  
}  
template <class T>  
inline void PT(T x) {  
        if (x < 0) putchar('-') ,x = -x;  
        if (x > 9) PT(x / 10);  
        putchar(x % 10 + '0');  
}

const int N = 1e4 + 10;
int a[N], b[N];

int main() {
    int n;
    cin >> n;
    for(int i = 1; i <= n; i ++) {
        scanf("%d", &a[i]);
    }


    LL tot = 0, nd = 0;
    for(int i = 1; i <= n; i ++) {
        scanf("%d", &b[i]);
        if(a[i] <= b[i]) {
            tot += (b[i] - a[i]) / 2;
        } else {
            nd += a[i] - b[i];
        }
    }

    if(tot >= nd) puts("Yes");
    else puts("No");
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
using lint = long long;

int sum(int k, int s){
	int ans = 0;
	for(int i=0; i<=k; i++){
		for(int j=0; j<=k; j++){
			int c = s - i - j;
			if(c >= 0 && c <= k) ans++;
		}
	}
	return ans;
}

int main(){
	int k, s;
	cin >> k >> s;
	cout << sum(k, s) << endl;
}

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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    int N, H, W;
    cin >> N >> H >> W;
    cout << (N - H + 1) * (N - W + 1) << endl;
    return 0;
}

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

int main() {
  ll N;
  cin >> N;

  bool clr = true;
  for(ll i = 0; i < N; i++){
    int a; cin >> a;
    if(a % 2 == 0){
      if(a % 3 != 0 && a % 5 != 0){
        clr = false;
      }
    }
  }

  cout << (clr ? "APPROVED" : "DENIED") << endl;
}

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

int main(){
    ll n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    ll f = b - a;
    bool can = false;
    rep(m,n-1){
        ll l = -d*m + (n-1-m)*c;
        ll r = -c*m + (n-1-m)*d;
        if(l <= f && f <= r) can = true;
    }
    cout << (can? "YES" : "NO") << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
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;
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n,k,p,a,i,c,x[1000];
	c=0;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d %d",&k,&p);
		if(k%p==0){
			x[i]=p;
		}
		else{
			a=k%p;
			x[i]=a;
		}
	}
	for(i=0;i<n;i++){
		printf("%d\n",x[i]);
	}
	return 0;
}
		


Measured memory_bytes: 2028
/*
Author : Xinyuan
*/
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef long long int  ll;
const int INF = 1e9 + 7;
const int mod = 1e9 + 7;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int nxt() {int x;scanf("%d", &x);return x;}


int main(){
    ll points, distance;
    ll counter = 0;
    cin >> points >> distance;
    pair<ll, ll> coord;
    for (int i = 0; i < points; i++) {
        cin >> coord.first >> coord.second;
        if (sqrt(pow(coord.first, 2) + pow(coord.second, 2)) <= distance) {
            counter++;
        }
    }
    cout << counter;
    return 0;
}


Measured memory_bytes: 3676
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		int A = int.Parse(Console.ReadLine());
		int B = int.Parse(Console.ReadLine());
		int C = int.Parse(Console.ReadLine());
		int D = int.Parse(Console.ReadLine());
		Console.WriteLine(Math.Min(A,B)+Math.Min(C,D));
	}
}

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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,d;
  cin >> n >> d;
  VVI x(n,VI(d));
  rep(i,n) rep(j,d) cin >> x[i][j];
  int cnt = 0;
  rep(i,n){
    FOR(j,i+1,n){
      double sum = 0;
      rep(k,d) sum += (x[i][k] - x[j][k])*(x[i][k] - x[j][k]);
      ll tmp = sqrt(sum);
      if( tmp*tmp == sum ) cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <map>
#include <string>
#include <stdio.h>

using namespace std;

map<string, int> ans;

void bfs()
{
    int dx[4] = {-1, 4, 1, -4};
    string sunxu = "01234567";
    queue<string> que;
    que.push(sunxu);
    ans[sunxu] = 0;
    ans.clear();

    while(que.size())
    {
        sunxu = que.front();
        que.pop();

        int x;
        for (int i = 0; i < 8; i++)
        {
            if (sunxu[i] == '0')
                x = i;
        }
        for (int i = 0; i < 4; i++)
        {
            int nx = x + dx[i];
            if ((x == 4 && i == 0) || (x == 3 && i == 2))
                continue;
            if (nx >= 0 && nx < 8)
            {
                string s = sunxu;
                swap(s[nx], s[x]);
                if (ans[s] == 0  && s != "01234567")
                {
                    que.push(s);
                    ans[s] = ans[sunxu] + 1; 
                }
            }

        }
    }
}

int main()
{
    bfs();

    int num;
    string sunxu;

    while(~scanf("%d", &num))
    {
        sunxu.clear();
        sunxu += num + '0';
        for (int i = 1; i < 8; i++)
        {
            scanf("%d", &num);
            sunxu += num + '0';
        }

        printf("%d\n", ans[sunxu]);
    }
}

Measured memory_bytes: 5456
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
#define all(in) in.begin(), in.end()
map<Int,Int>factors;
template<typename T>
vector<T> factorize(T n) {
    vector<T> v;
    T i = 2;
    while (i * i <= n) {
        if (n % i == 0) {
            v.push_back(i);
            n /= i;
        } else {
            i++;
        }
    }
    if(n != 1)v.push_back(n);
    return v;
};
template<typename T>
set<T> primeFactors( const vector<T>& vec){
    /* vecotor must be factolized*/
    set<T> res;
    for(auto e : vec){
        res.insert(e);
    }
    return res;
}
map<Int,Int>compress(vector<Int>v){
    map<Int,Int>res;
    for(auto e : v) res[e]++;
    return res;
}
constexpr Int mod = 1e9 + 7;
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// a^{-1} mod を計算する
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}
int main(){
    Int N; cin >> N;
    vector<Int>v(N);
    vector<map<Int,Int>>subfa;
    for(auto& e : v) cin >> e;
    for(auto e : v){
        auto f = factorize(e);
        auto u = compress(f);
        subfa.push_back(u);
        for(auto itr : u){
            Int key,cnt;
            tie(key,cnt) = itr;
            if(factors[key] < cnt)
                factors[key] = cnt;
        }
    }
    Int rcomp = accumulate(all(factors), 1LL, [&](Int res, pair<Int,Int>itr){
        return ((res * (Int)pow(itr.first,itr.second)) % mod);
    });
    vector<Int>res;
    for(auto &mp : subfa){
        Int tcomp = rcomp;
        for(auto p : mp){
            Int key,value;
            tie(key,value) = p;
            tcomp *= modinv(pow(key,value),mod);
            tcomp %= mod;
        }
        res.push_back(tcomp);
    }
    cout << accumulate(all(res),0LL,[](Int res, Int b){return (res + b) % mod;})
    <<endl;
}


Measured memory_bytes: 4152
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<unordered_map>
#include<unordered_set>
using namespace std;
typedef long long ll;
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod;
#define mul(a,b) a=a*b%mod;
#define N 300010
#define M 100010
namespace bit{
    ll dat[N];
    void init(){
        for(int i=0;i<N;i++)dat[i]=0;
    }
    void add(ll i){
        for(;i<N;i+=i&-i){
            dat[i]++;
        }
    }
    ll sum(ll i){
        ll res=0;
        for(;i>0;i-=i&-i){
            res+=dat[i];
        }
        return res;
    }
}
vector<ll> v[2*M];
ll n,m;
ll ans[2*M];
int main(){
  cin>>n>>m;
  for(int i=0;i<n;i++){
      ll l,r; cin>>l>>r;
      v[r].push_back(l);
  }
  bit::init();
  for(int i=1;i<=2*m;i++){
      vector<ll> di;
      for(ll j=1;j*j<=i;j++){
          if(i%j==0){
              di.push_back(j);
              if(j*j!=i){
                  di.push_back(i/j);
              }
          }
      }
      for(auto d:di){
          ans[d]+=bit::sum(i-1)-bit::sum(i-d);
          //cout<<"---"<<d<<" "<<ans[d]<<endl;
      }
      for(auto l:v[i]){
          bit::add(l);
      }
      //for(int j=1;j<=m;j++)cout<<bit::sum(j)<<" "; cout<<endl;
  }
  for(int i=1;i<=m;i++){
      cout<<n-ans[i]<<endl;
  }
  return 0;
}


Measured memory_bytes: 13824
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#define initdp(a, b)  for (int i = 0; i <= a; i++)   for (int j = 0; j <= b; j++) dp[i][j] = -1;
#define pb push_back
#define mpr make_pair
#define pii pair<int, int>
#define ll long long
#define pll pair<ll, ll>
#define all(arr) arr.begin(), arr.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repd(i, n) for (int i = n - 1; i >= 0; i--)
#define fo(i, l, r) for (int i = l; i <= r; i++)
#define inf 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846264338327950L
#define N 1000005
#define mid(l, r) l + (r - l) / 2
#define vec vector<int>
#define vecl vector<ll>
#define umap unordered_map<int,int>
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define endl "\n"
using namespace std;


void solve(){
    
  string s,t;
  cin>>s>>t;

  int n = s.size();
  int m = t.size();
  
  if(n!= m-1) {
    cout<<"No";
    return ;
  }

  if(t.substr(0,n) == s) {
    cout<<"Yes";
    return;
  }

  cout<<"No";
 
}
 
 
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout<<fixed<<setprecision(20);
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
}

Measured memory_bytes: 3596
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class B
{
	public static void Main() => (new Solver()).Solve();
}

public class Solver
{
	public void Solve()
	{
		int N = GetInt();
		var S = new HashSet<int>();
		for(int i = 0; i < N; i++)
			S.Add(GetInt());

		int Q = GetInt();
		var T = GetInts(Q);
		WriteLine(T.Count(x => S.Contains(x)));
	}
}

public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => Enumerable.Range(0, (int)N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(long N) => Enumerable.Range(0, (int)N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDouble()).ToArray();
	public static decimal[] GetDecimals(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDecimal()).ToArray();
	public static string[] GetStrings(long N) => Enumerable.Range(0, (int)N).Select(_ => GetString()).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) < 0)
			x = y;
	}

	public static void chmin<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) > 0)
			x = y;
	}

	public static void swap<T>(ref T x, ref T y)
	{
		T tmp = x;
		x = y;
		y = tmp;
	}
}


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

using namespace std;

typedef vector<int> vec;

struct node
{
	int fa,ls,rs,dep,deg,hgt,sib;
	node()
	{
		fa=ls=rs=sib=-1;
		dep=hgt=0;
		deg=2;
	}
}T[100100];

int main()
{ 
	//freopen("out.txt","w",stdout);
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		int id,ls,rs;
		scanf("%d%d%d",&id,&ls,&rs);
		if(ls==-1) T[id].deg--;
		else
		{
			T[id].ls=ls;
			T[ls].fa=id;
			T[ls].sib=rs;
		}
		if(rs==-1) T[id].deg--;
		else
		{
			T[id].rs=rs;
			T[rs].fa=id;
			T[rs].sib=ls;
		}
	}
	stack<int> st;
	for(int i=0;i<n;i++)
		if(T[i].fa==-1)
		{
			st.push(i);
			break; 
		}
	while(!st.empty())
	{
		int t=st.top();
		if(T[t].fa==-1) T[t].dep=0;
		else T[t].dep=T[T[t].fa].dep+1;
		//printf("%d %d %d\n",t,T[t].ls,T[t].rs);
		if(T[t].ls!=-1&&T[T[t].ls].dep==0) st.push(T[t].ls);
		if(T[t].rs!=-1&&T[T[t].rs].dep==0) st.push(T[t].rs);
		if((T[t].ls==-1||T[T[t].ls].dep>0)&&(T[t].rs==-1||T[T[t].rs].dep>0))
		{
			T[t].hgt=max(T[t].ls==-1?-1:T[T[t].ls].hgt,T[t].rs==-1?-1:T[T[t].rs].hgt)+1;
			st.pop();
		}
	}
	for(int i=0;i<n;i++)
	{
		printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",i,T[i].fa,T[i].sib,T[i].deg,T[i].dep,T[i].hgt);
		if(T[i].fa==-1)
			printf("root\n");
		else if(T[i].ls==-1&&T[i].rs==-1)
			printf("leaf\n");
		else printf("internal node\n");
	}
	return 0;
}

Measured memory_bytes: 5912
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

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

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
ll H, W;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> H >> W;

  ll ans = LLINF;
  ll size[3];

  if(H % 3 == 0 || W % 3 == 0) ans = 0;
  if(H >= 3) ans = min(ans, H);
  if(W >= 3) ans = min(ans, W);

  FOR(i, 1, H) {
    ll h = H - i;

    size[0] = W * i;
    size[1] = (W / 2) * h;
    size[2] = h * W - size[1];
    sort(size, size + 3);
    ans = min(ans, size[2] - size[0]);
  }

  FOR(i, 1, W) {
    ll w = W - i;

    size[0] = H * i;
    size[1] = (H / 2) * w;
    size[2] = H * w - size[1];
    sort(size, size + 3);
    ans = min(ans, size[2] - size[0]);
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#define USE_MATH_DEFINES 1
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define MOD 998244353ll
#define INF 1000000000000000000ll
#define EPS 1e-9
#define getchar_unlocked _getchar_nolock
#define putchar_unlocked _putchar_nolock

typedef long long         ll;
typedef long double       ld;
typedef pair <ll,ll>      pl;
typedef tuple <ll,ll,ll>  tl;

ll A, B, C, K, S;

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin >> A >> B >> C >> K;
	
	S = min(A, K);
	K -= min(A, K);
	K -= min(B, K);
	S -= K;
	
	cout << S;
	
    return 0;
}

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

int main(void){
  int n;
  int ans;
  
  cin >> n;
  ans = 1;
  for (int i=0; i<n; i++){
    int t; cin >> t;
    ans &= t%2==1||t%3==0||t%5==0;
  }
  cout << (ans?"APPROVED":"DENIED") << endl;
  return 0;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input!{
    d: usize,
    n: usize
    }
    let mut ans = 100usize.pow(d as u32) * n;
    if n == 100 {
        ans += 100usize.pow(d as u32)
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
#pragma GCC optimize("02")
#define ll long long
#define _inline __inline__ __attribute__((always_inline))
using namespace std;
struct ios{
    inline char gc(){
        static const int IN_LEN=1<<18|1;
        static char buf[IN_LEN],*s,*t;
        return (s==t)&&(t=(s=buf)+fread(buf,1,IN_LEN,stdin)),s==t?-1:*s++;
    }
    template <typename _Tp> _inline ios & operator >> (_Tp &x){
        static char ch,sgn; ch=gc(),sgn=0;
        for(;!isdigit(ch);ch=gc()){if(ch==-1)return *this;sgn|=ch=='-';}
        for(x=0;isdigit(ch);ch=gc())x=x*10+(ch^'0');
        sgn&&(x=-x); return *this;
    }
}inc;
template<typename T> inline void print(T x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) print(x/10);
    putchar(x%10+'0');
}
int n,m;
int main(){
	cin>>n>>m;
	char ch;
	int cnt=0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>ch;
			if(ch=='#') cnt++;
		}
	}
	puts(cnt==n+m-1?"Possible":"Impossible");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
int main(){
    string s;
    cin >> s;
    bool v1 = true;
    bool v2 = true;
    int n = s.size();
    rep(i,n)if(s[i]!=s[n-i-1])v1=false;
    rep(i,(n-1)/2)if(s[i]!=s[((n-1)/2)-i-1])v2=false;
    if(v1 and v2)cout << "Yes";
    else cout << "No";
	return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double lld;
ll MOD = (1e9)+7;
const int dr[] = {+1, -1, +0, +0, +1, -1, +1, -1};
const int dc[] = {+0, +0, +1, -1, +1, -1, -1, +1};
const int kx[] = {+1, +2, -1, -2, +1, +2, -1, -2};
const int ky[] = {+2, +1, +2, +1, -2, -1, -2, -1};
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
inline void fastIO(){
  ios_base::sync_with_stdio(0);cin.tie(0);
}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void debug_out() { cerr << endl; }
template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...); }

#ifdef LOCAL
#define debug(...) cerr << "(" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__)
#else
#define debug(...) 47
#endif

int main(){
  fastIO();
  ll ans=0;
  ll n,c=100;
  vector<ll>factors(10101010);
  cin>>n;
  for(ll i=1;i<=1e7+c;i++){
    for(ll j=i;j<=1e7+c;j+=i){
      factors[j]++;
    }
  }
  for(ll i=1;i<=n;i++){
    ans+=i*factors[i];
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 82052
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define Return(ans) { cout << (ans) << endl; return 0; }
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }
 
using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;
 
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};
 
const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod


#include <bits/stdc++.h>
using namespace std;
signed main(){
    int N; cin>>N;
    vec A1(N,0),A2(N,0);
    REP(i,N) cin>>A1[i];
    REP(i,N) cin>>A2[i];
    int ans = 0;
    REP(i,N){
    int now = 0;
    REP(j,i+1) now += A1[j];
    FOR(j,i,N) now += A2[j];
      ans = max(now,ans);
    }
    Out(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll=long long;
using namespace std;
ll a[110000];
main(){
    ll n,ans=0;
    cin>>n;
    for(ll i=1;i<n+1;i++)cin>>a[i];//1を先頭にする(1-indexed)
    ll pos=1;//今光っているボタン
    while(ans<n){
      ll st=a[pos];//次に光るボタン
      pos=st; //次に光っていて押すボタンを更新
      ans++;  //ボタンを押した回数を+1
      if(pos==2)break;//次に光っているボタンが2なら終了
    }
    if(ans==n)cout<<-1;//n回ボタンを押したなら2に到達できなかった
    else cout<<ans;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int a, b;
  cin >> a >> b;
  if (a > b)
  {
    cout << a + a - 1;
  }
  else if (a == b)
  {
    cout << a + b;
  }
  else
  {
    cout << b + b - 1;
  }
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
long long a[87],n;
int main()
{
	cin>>n;
	a[0]=2;a[1]=1;
	for(int i=2;i<=n;i++)
		a[i]=a[i-1]+a[i-2];
	cout<<a[n]<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		int i;
		
		for (i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		for (i = n - 1; i >= 0; i--) {
			System.out.print(a[i]);
			if (i > 0) {
				System.out.print(" ");
			}
		}
		System.out.println();
		
		sc.close();
	}

}


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

using namespace std;

typedef long long ll;

const int N = 2e5+10;
const ll mod = 1e9+7;

ll f[N];

void calc() {
	f[0] = 1;
	for(int i = 1; i < N; i++) f[i] = (f[i-1]*i)%mod;
}

ll binPow(ll x, int p) {
	if(p==0) return 1;
	else {
		if(p%2) {
			ll b = binPow(x, p-1);
			return (b*x)%mod;
		} else {
			ll b = binPow(x, p/2);
			return (b*b)%mod;
		}
	}
}

int main() {
	calc();
	int n, m, a, b;
	cin >> n >> m >> a >> b;

	ll ans = 0;
	for(int i = b+1; i <= m; i++) {
		int y = n-a;
		ll ff = (((f[y+i-2]*binPow(f[y-1], mod-2))%mod)*binPow(f[i-1], mod-2))%mod;
		int x = m-i+1;
		ll q = (((f[x+a-2]*binPow(f[x-1], mod-2))%mod)*binPow(f[a-1], mod-2))%mod;
		ll NON = (ff*q)%mod;
		ans = (ans+NON)%mod;
	}
	cout << ans;
	//ll f1 = ((((f[n+m-2]*binPow(f[n-1], mod-2))%mod)*binPow(f[m-1], mod-2))%mod);
	//ll f2 = ((((f[a+b-2]*binPow(f[a-1], mod-2))%mod)*binPow(f[b-1], mod-2))%mod);
	//f2 = max((ll)1, f2);
	//cout << (f1*f2)%mod;
	//cout << ((((((f[n+m-2]*binPow(f[n-1], mod-2))%mod)*binPow(f[m-1], mod-2)%mod)*f[a-1]%mod)*f[b-1]%mod)*binPow(f[a+b-2], mod-2)%mod);
	//cout << ((((f[n+m-2]*f[a-1])%mod)*f[b-1])%mod)*((binPow(f[n-1], mod-2)*binPow(f[m-1], mod-2))%mod)%mod*binPow(f[a+b-2], mod-2)%mod;
}

Measured memory_bytes: 5188
import java.util.Scanner;

public class Main {
    public static void main(String args[]) throws Exception {
        Scanner s = new Scanner(System.in);
        String str = s.next();
        int count = 0;
        if (str.charAt(0) == '1') count++;
        if (str.charAt(1) == '1') count++;
        if (str.charAt(2) == '1') count++;

        System.out.println(count);
    }
}

Measured memory_bytes: 22868
using Yorukatsu037.Questions;
using Yorukatsu037.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Yorukatsu037.Questions
{
    /// <summary>
    /// ABC115 C
    /// </summary>
    public class QuestionB : AtCoderQuestionBase
    {
        public override IEnumerable<object> Solve(TextReader inputStream)
        {
            var nk = inputStream.ReadIntArray();
            var treeCount = nk[0];
            var illuminations = nk[1];
            var height = new int[treeCount];
            for (int i = 0; i < treeCount; i++)
            {
                height[i] = inputStream.ReadInt();
            }

            Array.Sort(height);

            var min = int.MaxValue;
            for (int i = 0; i + illuminations - 1 < height.Length; i++)
            {
                var diff = height[i + illuminations - 1] - height[i];
                min = Math.Min(min, diff);
            }

            yield return min;
        }
    }
}


namespace Yorukatsu037
{
    class Program
    {
        static void Main(string[] args)
        {
            IAtCoderQuestion question = new QuestionB();    // 問題に合わせて書き換え
            var answers = question.Solve(Console.In);
            foreach (var answer in answers)
            {
                Console.WriteLine(answer);
            }
        }
    }
}

#region Base Classes

namespace Yorukatsu037.Questions
{

    public interface IAtCoderQuestion
    {
        IEnumerable<object> Solve(string input);
        IEnumerable<object> Solve(TextReader inputStream);
    }

    public abstract class AtCoderQuestionBase : IAtCoderQuestion
    {
        public IEnumerable<object> Solve(string input)
        {
            var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
            var reader = new StreamReader(stream, Encoding.Unicode);

            return Solve(reader);
        }

        public abstract IEnumerable<object> Solve(TextReader inputStream);
    }

}

#endregion

#region Extensions

namespace Yorukatsu037.Extensions
{
    internal static class TextReaderExtensions
    {
        internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
        internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
        internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
        internal static string ReadString(this TextReader reader) => reader.ReadLine();

        internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray();
        internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray();
        internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray();
        internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator);
    }
}

#endregion

Measured memory_bytes: 17632
type tree = Nil | Node of int * tree * tree

let create () = Nil

let insert x t =
  let rec doit t id = match t with
    | Nil -> id (Node (x, Nil, Nil))
    | Node (y, l, r) ->
      if x < y then doit l (fun a -> id (Node (y, a, r)))
      else doit r (fun b -> id (Node (y, l, b))) in
  doit t (fun i -> i)

let preorder f t =
  let rec doit = function
    | Nil -> ()
    | Node (x, l, r) -> f x; doit l; doit r in
  doit t

let inorder f t =
  let rec doit = function
    | Nil -> ()
    | Node (x, l, r) -> doit l; f x; doit r in
  doit t

let print t =
  inorder (fun e -> print_string " "; print_int e) t;
  print_newline ();
  preorder (fun e -> print_string " "; print_int e) t;
  print_newline ()

let find x t =
  let rec doit = function
    | Nil -> false
    | Node (y, _, _) when x = y -> true
    | Node (y, l, _) when x < y -> doit l
    | Node (_, _, r) -> doit r in
  doit t

let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let () =
  let m = read_int () in
  let t = ref (create ()) in
  for _ = 0 to m - 1 do
    match read_line () |> split_on_char ' ' with
    | ["insert"; n] -> t := insert (int_of_string n) !t
    | ["find"; n] -> print_endline (if find (int_of_string n) !t then "yes" else "no")
    | _ -> print !t
  done

Measured memory_bytes: 25168
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 998244353;
const ll INF = 1e18;
#define REP(i,n) for(int i=0;i<n;i++)
#define ALL(v) v.begin(),v.end()

const int mx=100000;
int n, m;

int id(int x, int y){
	return x*m+y;
}

int main(){
	cin >> n >> m;
	mcf_graph<int,int> G(n*m+2);
	int ss=n*m, gg=n*m+1;
	vector<string> s(n);
	REP(i,n) cin >> s[i];
	ll ans=0;
	REP(i,n)REP(j,m){
		G.add_edge(id(i,j),gg,1,mx-i-j);
		if(s[i][j]=='o'){
			ans+=mx-i-j;
			G.add_edge(ss,id(i,j),1,0);
			vector<vector<bool>> f(n,vector<bool>(m,0));
			queue<P> q; q.push({i,j});
			while(!q.empty()){
				int x=q.front().first;
				int y=q.front().second;
				q.pop();
				G.add_edge(id(i,j),id(x,y),1,0);
				if(x+1<n){
					if(s[x+1][y]!='#'&&!f[x+1][y]){
						f[x+1][y]=1;
						q.push({x+1,y});
					}
				}
				if(y+1<m){
					if(s[x][y+1]!='#'&&!f[x][y+1]){
						f[x][y+1]=1;
						q.push({x,y+1});
					}
				}
			}
		}
	}
	ans-=G.flow(ss,gg).second;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 7336
#include<stdio.h>
#define MAX 100005
#define NIL -1
 
typedef struct{
  int p,l,r,h,flag;
}Node;
Node T[MAX];
 
int depth(int);
int sub(int);
int deg(int);
int height(int);
 
int main(){
 
  int n,i,j,node,degree,child,left;
 
  scanf("%d",&n);
  for(i = 0; i < n; i++){
    T[i].p = NIL;
    T[i].l = NIL;
    T[i].r = NIL;
    T[i].h = 0;
    T[i].flag = 0;
  }
  for(i = 0; i < n; i++){
    scanf("%d",&node);
    for(j = 0; j < 2; j++){
      scanf("%d",&child);
      if(child != -1){
        T[child].p = node;
        if(j == 0)
          T[node].l = child;
        else
          T[node].r = child;
 
 
      }
    }
  }
 
  for(i = 0; i < n; i++){
    printf("node %d: parent = %d, sibling = %d, degree = %d, depth\
 = %d, height = %d, ",i,T[i].p,sib(i),deg(i),depth(i),height(i));
    if(T[i].p == NIL)
      printf("root\n");
    else if(T[i].l == NIL && T[i].r == NIL)
      printf("leaf\n");
    else
      printf("internal node\n");
    //    print_degree(T[i].l);
  }
  return 0;
}
 
int depth(int node){
 
  int count=0;
 
  while(T[node].p != NIL){
    count++;
    node = T[node].p;
  }
  return count;
}
 
int sib(int i){
 
  int parent,right,left;
 
  parent = T[i].p;
  left = T[parent].l;
  right = T[parent].r;
 
  if(parent == -1)
    return -1;
  if(i == left)
    return right;
  else
    return left;
}
 
int deg(int i){
 
  int parent,count=0;
 
  if(T[i].l != NIL)
    count++;
  if(T[i].r != NIL)
    count++;
  return count;
}
 
int height(int i){
 
  int left = 0,right = 0;
 
  if(T[i].l != NIL){
    left = height(T[i].l) + 1;
  }
  if(T[i].r != NIL){
    right = height(T[i].r) + 1;
  }
  if(right > left)
    return right;
  else
    return left;
}

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

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

using namespace std;

using ll = long long int;

const int MOD_NUM = 1e9 + 7;

int main() {
    // Input
    int X, Y;
    cin >> X >> Y;

    // Process
    bool judge = false;
    rep(i, X + 1) {
        if (i * 2 + (X - i) * 4 == Y) judge = true;
    }

    string ans = (judge ? "Yes" : "No");

    // Output
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3596