akhauriyash/Code-Regression huggingface dataset:
H, W = map(int,input().split())
A = [input() for _ in range(H)]
mod = 10**9+7

dp = [[0 for j in range(W+1)] for i in range(H+1)]
dp[0][1] = 1

for i in range(H):
    for j in range(W):
        if A[i][j] == '.':
            dp[i+1][j+1] = dp[i][j+1] + dp[i+1][j]

print(dp[-1][-1]%mod)

Measured memory_bytes: 158440
#include<bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
typedef long long ll;

void maxScore(vector<vector<int>> &v, int n, int m, int prev, vector<int> &vec, int &ans){
    if(n == (int)vec.size()){
        int num = 0;
        for(int i = 0; i < (int)v.size(); ++i){
            if(vec[v[i][1]] - vec[v[i][0]] == v[i][2]) num += v[i][3];
        }
        ans = max(ans, num);
        return;
    }
    for(int i = prev; i <= m; ++i){
        vec.push_back(i);
        maxScore(v, n, m, i, vec, ans);
        vec.pop_back();
    }
}

int main(){
    fastio;
    int n, m, q;
    cin >> n >> m >> q;
    vector<vector<int>> v(q);
    for(int i = 0; i < q; ++i){
        vector<int> a(4);
        for(int j = 0; j < 4; ++j){
            cin >> a[j];
        }
        a[0]--, a[1]--;
        v[i] = a;
    }
    int ans = 0;
    vector<int> vec;
    maxScore(v, n, m, 1, vec, ans);
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int t;
	t=1;
	while(t--)
	{
	    long long a,b,c;
	    int k;
	    cin>>a>>b>>c>>k;
	    while(k>0&&b<=a){
	        b*=2;
	        k--;
	    }
	    while(k>0&&c<=b){
	        c*=2;
	        k--;
	    }
	    if(a<b&&b<c)cout<<"Yes"<<endl;
	    else cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
  int ba[100][100];
  int h;
  for(h=0; cin>>ba[h][0]; h++)
    for(int i=1; scanf(",%d", &ba[h][i]); i++)
      ;
  int w = h/2+1;
  int dp[h][w];

  dp[0][0] = ba[0][0];
  for(int i=1; i<w; i++) {
    dp[i][0] = ba[i][0] + dp[i-1][0];
    for (int j=1; j<i; j++)
      dp[i][j] = ba[i][j] + max(dp[i-1][j-1], dp[i-1][j]);
    dp[i][i] = ba[i][i] + dp[i-1][i-1];
  }
  for(int i=w; i<h; i++)
    for (int j=0; j<h-i; j++)
      dp[i][j] = ba[i][j] + max(dp[i-1][j], dp[i-1][j+1]);

  cout << dp[h-1][0] << endl;
}

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

public class Main {

	public static void main(String[] args) {

		 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		 try{

			 int x = Integer.parseInt(br.readLine());

			 System.out.printf("%d\n", x*x*x);

		 }catch(IOException e){
			 e.printStackTrace();
		 }
	}
}



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

int A[100];
int main(void) {

    int N,P;
    cin >> N >> P;
    int odd_num=0;
    for (int i=0; i<N; ++i)
    {
        cin >> A[i];
        if (A[i]%2==1) odd_num++; 
    }

    if (odd_num==0) 
    {
        if (P==1) cout << 0 << endl;
        if (P==0) cout << (2LL<<(N-1)) << endl;
    }
    else
    {
        cout << (2LL<<(N-2)) << endl;
    }

    return 0;
}


Measured memory_bytes: 256
//Author: Fuadul Hasan(fuadul202@gmail.com)
//BSMRSTU,Gopalganj
#include<bits/stdc++.h>
using namespace std;int tc = 1;
#define happy ios::sync_with_stdio(false);
#define coding  cin.tie(0);
#define mp make_pair
#define ll long long
#define Pi atan(1)*4
#define pb  push_back
#define vpr vector<pr> 
#define pr pair<int, int> 
#define vi std::vector<int>
#define vll std::vector<ll>
#define YES printf("YES\n");
#define NO printf("NO\n");
#define Yes printf("Yes\n");
#define No printf("No\n");
#define all(n) n.begin(),n.end()
#define point(x) setprecision(x)
#define Test printf("Case %d: ",tc++);
#define Unique(c) (c).resize(unique(all(c))-(c).begin())

const int M = 1e9 + 7;
const ll  Inf = (ll)2e18 + 5;
const int N   = 2e5 + 5;

string lcs(string a,string b){
	int n = a.size();
	int m = b.size();
	//cout<<n<<" "<<m<<endl;

	int l[n+1][m+1];

	for(int i=0;i<=n;i++){
		for(int j=0;j<=m;j++){
			if(i==0 or j==0) l[i][j] = 0;
			else  if(a[i-1]==b[j-1])l[i][j] = l[i-1][j-1]+1;
			else l[i][j] = max(l[i-1][j],l[i][j-1]); 
		}
	}
	//cout<<l[n][m]<<endl;

	int index = l[n][m];
	char str[index+1];
	str[index] = '\0';
	int i = n,j = m;
	while(i>0&&j>0){
		if(a[i-1]==b[j-1]){
			str[index-1] = a[i-1];
			i--;j--;index --;
		}else if(l[i-1][j]>l[i][j-1]){
			i--;
		}else j--;
	}
	return str;

}

int solve() 
{
	//happy coding

	string a,b;
	cin>>a>>b;
	cout<<lcs(a,b)<<endl;;
	
	return 0;
}
int main(){
	int test = 1;
	//scanf("%d", &test);
	while (test--)solve();return 0;
}

Measured memory_bytes: 35456
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 105
#define INF 100000000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 100005;
const int MOD = 1000000007;
int main(){
    int n,q;
    cin>>n>>q;
    string s;
    cin>>s;
    vector<int>r(n+1);
    for(int i=1;i<n;i++){
        r[i+1]=r[i];
        if(s[i-1]=='A'&&s[i]=='C'){
            r[i+1]++;
        }
    }
    vector<P>a(q);
    REP(i,q){
        int l,r;
        cin>>l>>r;
        a[i]={l,r};
    }
    REP(i,q){
        OUT(r[a[i].second]-r[a[i].first]);
    }
    return 0;
}

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

int main() {
	int n;
	cin >> n;
	bool f = false;
	for(int i=0;i<26;i++) {
		for(int j=0;j<15;j++) {
			if(4*i+7*j== n) {
				f = true;
				break;
			}
		}
	}
	if(f)cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main( void ){
    int S;
    int h,m,s;
    scanf( "%d",&S );
    h = S /3600;
    m = ( S - h * 3600 ) / 60;
    s = S - m * 60 - h * 3600;
    printf( "%d:%d:%d\n",h,m,s ); 
    return 0;
}

Measured memory_bytes: 1816
#include <bits/stdc++.h>
#define plskz ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
using namespace std;

int main() {
    plskz   

    int n;
    cin >> n;
    while (n >= 10) {
        n%=10;
    }
    
    if(n == 2 || n == 4 || n == 5 || n == 7 || n == 9)
        cout << "hon";
    else if(n == 0 || n == 1 || n == 6 || n == 8)
        cout << "pon";
    else 
        cout << "bon";
}   

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;

int main()
 {
 	long long int n,i,m=0,j,s=0;
 	cin>>n;
 	int a[n];
 	for(i=0;i<n;i++)
 		cin>>a[i];
 	for(i=0;i<n-1;i++)
 		{
 			
 			for(j=i+1;j<n;j++)
 				{
 					m=m+a[i]*a[j];
				 }
				 
		 }
	cout<<m<<endl;
}

Measured memory_bytes: 3588
X,Y = list(map(int,input().split()))

n = (-X+2*Y)//3
m = (2*X-Y)//3
MOD = 10**9+7
    
def comb(n,r,MOD):
    x = n+1
    y = min(r,n-r)
    
    numer = 1
    denom = 1
    
    for i in range(1,r+1):
        numer = numer*(x-i)%MOD
        denom = denom*(i)%MOD
    
    return numer * pow(denom,MOD-2,MOD) % MOD
  
import sys

if n < 0 or m < 0:
    print(0)
    sys.exit()
if (X+Y)%3 != 0:
    print(0)
    sys.exit()
    
print(comb(n+m,n,MOD))

Measured memory_bytes: 3064
S = input()

from collections import deque
S = deque(S)

Q = int(input())
rev = False

for i in range(Q):
  q = input().split()
  if q[0] == "1":
    rev ^= True
  else:
    F = q[1]
    if (F == "1" and (not rev)) or (F == "2" and rev):
      S.appendleft(q[2])
    else:
      S.append(q[2])

S = "".join(list(S))
if rev:
  S = S[::-1]
  
print(S)

Measured memory_bytes: 14168
#include<bits/stdc++.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<algorithm>
using namespace std;

int main() {
    int n;
    stack<int> l;
    while (scanf("%d",&n)!=EOF) {
        if (n==0) {
            printf("%d\n",l.top());
            l.pop();
        } else {
            l.push(n);
        }
    }
    return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e18;
//const int INF=(1<<30);


int main(){
  int h,w;
  cin >> h >> w;
  string hh(w+2, '#');

  cout << hh << endl;
  REP(i,h){
    string a;
    cin >> a;
    cout << "#" << a << "#" << endl;
  }
  cout << hh << endl;

}





Measured memory_bytes: 256
//													\[T]/ Praise
//													 (*)  The
//													 / \  Sun



#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double dbl;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<long long> vl;
typedef vector< pair<int, int> > vii;
#define mp make_pair
#define pb push_back
#define invec(a, n) for(ll i = 0; i < n; i++) {cin >> a[i];}
#define rep(n) for(ll i = 0; i < n; i++)
#define fr(i,j,k) for(ll i = j; i < k; i++)
#define FR(i,j,k) for(ll i = j; i >= 0; i--)
#define MOD 1000000007
#define all(v) v.begin(), v.end()
#define INF 1000000
#define xx first
#define yy second

void fast()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}

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

	vector<dbl> a(n);

	invec(a,n);

	dbl dp[n+1][n+1];

	fr(i,0,n)
		fr(j,0,n+1)
			dp[i][j] = 0;

	dp[0][0] = 1;
	
	fr(i,1,n+1)
		dp[i][0] = dp[i-1][0] * (dbl)(1 - a[i-1]);

	fr(i,1,n+1)
		dp[i][i] = dp[i-1][i-1] * a[i-1];

	fr(i,1,n+1)
	{
		fr(j,1,n+1)
		{
			if(j >= i)
				continue;

			dp[i][j] = dp[i-1][j-1] * a[i-1];

			dp[i][j] += dp[i-1][j] * (1 - a[i-1]);
		}
	}

	// fr(i,0,n+1)
	// {
	// 	fr(j,0,n+1)
	// 		cout << fixed << setprecision(5) << dp[i][j] << "\t\t";
	// 	cout << "\n";
	// }

	int m = (n / 2) + 1;

	dbl res = 0.0;

	fr(i,m,n+1)
		res += dp[n][i];

	cout << setprecision(10) << res;
}

Measured memory_bytes: 140928
import java.util.*;
import java.io.*;

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

        Scanner scan = new Scanner(System.in);
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        
		int h = scan.nextInt();
		int a = scan.nextInt();
        
        out.println(h % a == 0 ? (h / a) : (h / a + 1));
        out.close();
        
    }
}

Measured memory_bytes: 35740
#include <bits/stdc++.h>
#define FOR(i, n) for(int i = 0; i < (n); ++i)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define TRAV(i, a) for(auto & i : (a))
#define SZ(x) ((int)(x).size())
#define PR std::pair
#define MP std::make_pair
#define X first
#define Y second
typedef long long ll;
typedef std::pair<int, int> PII;
typedef std::vector<int> VI;

int main(){
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(0);
	int n;
	std::cin >> n;
	std::map<int, int> map;
	VI A(n);
	FOR(i, n){
		std::cin >> A[i];
		map[A[i]]++;
	}
	ll ans = 0;
	TRAV(pr, map) ans += 1ll*pr.Y*(pr.Y-1)/2;
	FOR(i, n){
		int ile = map[A[i]];
		ll cur = ans - 1ll*ile*(ile-1)/2;
		ile--;
		cur += 1ll*ile*(ile-1)/2;
		std::cout << cur << "\n";
	}

	return 0;
}

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

using namespace std;

#define el				'\n'
#define sz(v)			((int)((v).size()))
#define all(v)          ((v).begin()),((v).end())
#define clr(v, d)		memset(v, d, sizeof(v))

double const EPS = 1e-8, PI = acos(-1);
const int N = 1e5 + 9, M = 2000 + 9, OO = (int) 1e9 + 1;
const long long MOD = 1e9 + 7;

typedef long long ll;

void OUTPUT() {
	cout << fixed << setprecision(12);
	ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
}

void INPUT() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	cout << fixed << setprecision(0);
//	ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
}

ll n, s, q, x, cnt[N];

int main() {
	OUTPUT();
//	INPUT();
	cin >> n >> s >> q;
	for (int i = 0; i < q; i++) {
		cin >> x;
		cnt[x - 1]++;
	}
	for (int i = 0; i < n; i++) {
		if (s - q + cnt[i] > 0)
			cout << "Yes\n";
		else
			cout << "No\n";
	}

	return 0;

}


Measured memory_bytes: 1408
def d_Connectivity(N, K, L, R, T):  # 都市数、道路数、鉄道数、都市の道路/鉄道による結び
    class UnionFind:
        def __init__(self, N):
            self.p = list(range(N))  # 初期状態ではi番の頂点の根(parent)はi番である
            self.rank = [0] * N  # 初期状態ではどの頂点もランクが0とする(何もつながっていない)
            self.size = [1] * N  # 初期状態ではどの頂点も連結成分の大きさは1

        def find(self, x):
            # 頂点xが属する連結成分の代表(根の番号)を求める
            if self.p[x] != x:
                # 頂点xの根は他の頂点だった
                self.p[x] = self.find(self.p[x])  # 経路圧縮
            return self.p[x]

        def is_same(self, x, y):
            # 頂点x,yは同じ連結成分に属するか？
            return self.find(x) == self.find(y)

        def union(self, x, y):
            # x,yを同じ連結成分に属させる
            u = self.find(x)
            v = self.find(y)
            if u == v:
                # 同じ連結成分に既に属していた
                return
            if self.rank[u] < self.rank[v]:
                self.p[u] = v  # ランクの大きな方につなげる
                self.size[v] += self.size[u]  # つながっている要素数だけ足す
                self.size[u] = 0  # ランクが小さかった連結成分は「解散」
            else:
                # 上と同様にやる
                self.p[v] = u
                self.size[u] += self.size[v]
                self.size[v] = 0
                if self.rank[u] == self.rank[v]:
                    # 根の分だけ1個「ずれる」
                    self.rank[u] += 1

        def get_size(self, x):
            # 頂点xが属する連結成分の大きさ
            return self.size[self.find(x)]

        def show(self):
            return self.p

    road = UnionFind(N)  # 道路による町のつながり
    train = UnionFind(N)  # 鉄道による町のつながり
    for p, q in R:
        road.union(p - 1, q - 1)
    for r, s in T:
        train.union(r - 1, s - 1)

    from collections import defaultdict
    d = defaultdict(int)
    for i in range(N):
        d[road.find(i), train.find(i)] += 1  # 道路も鉄道もつながっている
    ans = (d[road.find(i), train.find(i)] for i in range(N))
    return ' '.join(str(i) for i in ans)

N,K,L = [int(i) for i in input().split()]
R = [[int(i) for i in input().split()] for j in range(K)]
T = [[int(i) for i in input().split()] for j in range(L)]
print(d_Connectivity(N, K, L, R, T))

Measured memory_bytes: 93728
#include<stdio.h>
#include<math.h>
#define MAX 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define INFTY -1
//float inf=INFINITY;
int inf=(1<<21);
int n,a[MAX][MAX];

int prim(){
  int i,u,v,mincost,sum=0;
  int color[MAX],d[MAX];
  for(i=0;i<n;i++){
    d[i]=inf;
    color[i]=WHITE;
  }
  d[0]=0;
  color[0]=GRAY;
  while(1){
    mincost=inf;
    u=-1;
    for(i=0;i<n;i++){
      if(color[i]!=BLACK && d[i]<mincost){	
	mincost=d[i];
	u=i;
      }
    }
    if(mincost==inf)break;
    color[u]=BLACK;
    for(v=0;v<n;v++){
      if(color[v]!=BLACK && a[u][v]!=inf){
	if(d[v]>(d[u]+a[u][v])){
	  d[v]=a[u][v]+d[u];
	  color[v]=GRAY;
	}
      }
    }
  }
  for(i=0;i<n;i++){
    printf("%d ",i);
    if(d[i]==INFTY)printf("-1\n");
    else printf("%d\n",d[i]);
  }
  return sum;
}

int main(){
  int i,j,u,k,v,c;
  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      a[i][j]=inf;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d%d",&v,&c);
      a[u][v]=c;
    }
  }
  prim();
  return 0;
}



Measured memory_bytes: 2108
import java.io.*;
import java.math.*;
import java.util.*;
public class Main { 
 
	public static void main(String[] args) { 
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		long[] arr = new long[N];
		for (int i = 0; i < N; i++) {
			arr[i] = input.nextLong();
		} 
		long ans = Long.MAX_VALUE;
		for (long test = -100; test <= 100; test++) {
			long curans = 0;
			for (int i = 0; i < N; i++) {
				long diff = test-arr[i];
				curans+=diff*diff;
			}
			ans=Math.min(ans, curans);
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAX_S = 1e9;

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

  vector<ll> ans(N);
  ll cnt = 0;
  for (int i=0; i<N; i++) {
    if (cnt < K) {
      ans[i] = S;
      cnt++;
    } else {
      if (S == MAX_S) ans[i] = S-1;
      else ans[i] = S+1;
    }
  }
  for (int i=0; i<N; i++) {
    if (i==0) cout << ans[i];
    else cout << " " << ans[i];
  }
  cout << endl;

  return 0;
}


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

int main()
{
    string str1;
    cin >> str1;

    string str2 = "a";

    int comp = str1.compare(str2);
    if (comp < 0)
    {
        cout << "A" << endl;
    }
    else
    {
        cout << "a" << endl;
    }

    return 0;
}

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

#define ll long long
#define all(x) (x).begin(), (x).end()
const long long INF = 1LL << 60;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //(i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    // cout << fixed << setprecision(5);

    // 入力
    int x, y;
    cin >> x >> y;

    // 処理
    // 出力
    cout << x + y / 2 << endl;

    return 0;
}


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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

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

struct edge {
	int to, cost;
	edge(int t,int c):to(t),cost(c) {}
};

int dx[]={1,-1,0,0},dy[]={0,0,1,-1};
int ddx[]={1,1,1,0,-1,-1,-1,0},ddy[]={1,0,-1,-1,-1,0,1,1};

ll mypow(ll x,ll n,ll m) {	//xのn乗をmで割った余り
	if(n==0) return 1;
	if(n%2==0) return mypow(x*x%m,n/2,m);
	else return x*mypow(x,n-1,m)%m;
}

//-----------------------------------------------------------------------------

int n,a,b;

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

	cin>>n>>a>>b;
	int sum=0;
	FOR(i,1,n+1) {
		int c=0,d=i;
		while(d>0) c+=d%10,d/=10;
		if(c>=a&&c<=b) sum+=i;
	}
	cout<<sum<<endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
signed main(){
  string s;
  cin>>s;
  const Int MOD = 1e9+7;
  Int n=s.size();
  Int x=0,y=0,z=0,r=1;
  Int inv=(1+MOD)/3;
  for(Int i=0;i<n;i++){
    if(s[i]=='C'||s[i]=='?') z+=y*(s[i]=='?'?inv:1);
    if(s[i]=='B'||s[i]=='?') y+=x*(s[i]=='?'?inv:1);
    if(s[i]=='A'||s[i]=='?') x+=1*(s[i]=='?'?inv:1);
    if(s[i]=='?') r*=3;
    x%=MOD;y%=MOD;z%=MOD;r%=MOD;
  }
  z*=r;
  z%=MOD;
  cout<<z<<endl;
  return 0;
}

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

int main() {
  int n;
  int a[21];
  int b[51];
  int c[51];

  cin >> n;

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

  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans += b[a[i] - 1];
    if (a[i] + 1 == a[i + 1]) {
      ans += c[a[i] - 1];
    }
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

void _main() {
  string S;
  cin >> S;

  if (S[5] == '1') {
    cout << "TBD" << "\n";
    return;
  }
  if (S[6] > '4') {
    cout << "TBD" << "\n";
    return;
  }
  cout << "Heisei" << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N,M,C;
  cin >> N >> M >> C;
  
  vector<int> B(M);
  for(int i=0;i<M;i++){
    cin >> B.at(i);
  }
  
  vector<vector<int>> A(N,vector<int>(M));
  for(int j=0;j<N;j++){
    for(int k=0;k<M;k++){
      cin >> A.at(j).at(k);
    }
  }
  
  vector<int> S(N);
  int ans=0;
  
  for(int l=0;l<N;l++){
    for(int m=0;m<M;m++){
      S.at(l) +=A.at(l).at(m)*B.at(m);
    }
    if(S.at(l)+C>0){
      ans++;
    }
  }
  
  cout << ans << endl;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  if(max(a,b) % min(a,b) == 0) {
    cout << min(a,b) << endl;
    return 0;
  }
  for(int j = 2; j <= min(a,b); ++j) {
    int i = min(a,b)/j;
    if(a % i == 0 && b % i == 0) {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<cstdio>
#include<map>
#include<vector>
#include<set>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#define Max zhi5968
typedef long long ll;
using namespace std;

int main ()
{
	ll n,nn,sn=0;
	cin>>n;
	nn=n;
	while(n)
	{
		sn=sn+n%10;
		n=n/10;
	}
	if(nn%sn==0)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl; 
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n;
  int i,j;
  scanf("%d", &n);
  float a[n];
  for (i = 0; i < n; i++) {
    scanf("%f", &a[i]);
  }
  float r = 0;
  for (j = 0; j < n; j++) {
    r += (1/a[j]); 
  }
  
  printf("%f", 1/r);
}

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

int main(){
  int n;
  cin >> n;
  vi a(n);
  rep(i,n) cin >> a[i];
  sort(a.rbegin(),a.rend());
  int len = a[0]+1;
  vi cnt(len+1);
  rep(i,n){
    for(int j=a[i]; j<=len; j+=a[i]) cnt[j]++;
  }
  int ans = 0;
  rep(i,n){
    if(cnt[a[i]] == 1) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 7980
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    string s;
    cin >> s;
 
    long int N = s.size();
 
    long int m1ve = 0;
    long int m2ve = 0;
 
    for(long int n=0; n<N; n++)
    {
        if(n % 2)
        {
            if(s[n] == '1')
            {
                m1ve++;
            }
 
            else
            {
                m2ve++;
            }
        }
 
        else
        {
            if(s[n] == '1')
            {
                m2ve++;
            }
 
            else
            {
                m1ve++;
            }
        }
    }
 
    cout << min(m1ve,m2ve);
    return 0;
}

Measured memory_bytes: 3764
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PGC
{
	class Program
	{
		static void Main(string[] args)
		{
			var N = int.Parse(Console.ReadLine());

			var min = int.MaxValue;
			var benefit = int.MinValue;
			for (int i = 0; i < N; i++)
			{
				var val = int.Parse(Console.ReadLine());
				benefit = Math.Max(benefit, val - min);
				min = Math.Min(min, val);
			}

			System.Console.WriteLine(benefit);
		}
	}
}



Measured memory_bytes: 20032
N, x = map(int, input().split(' '))
a = list(map(int, input().split(' ')))

sums = [a[0]]
for i in range(len(a) - 1):
    sums.append(a[i] + a[i + 1])
sums.append(a[-1])
# print(a)
# print(sums)

cnt = 0
for i in range(len(sums)):
    if sums[i] > x:
        diff = sums[i] - x
        sums[i] -= diff
        sums[i + 1] -= diff
        cnt += diff
print (cnt)

Measured memory_bytes: 14540
import Control.Monad
import Data.Maybe (fromJust)
import Data.List as List

solve :: Int -> Int -> Int -> Int -> Int
solve a b c d = max (a*b) (c*d)


main :: IO()
main = do
    [a, b, c, d] <- map read . words <$> getLine :: IO [Int]
    print $ solve a b c d


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

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

    set<int> num;
    for(int i=0; i<n; i++){
        int a;
        cin >> a;
        num.insert(a);
    }

    if(num.size() == n) cout << "YES" << endl;
    if(num.size() != n) cout << "NO" << endl;
    return 0;
}

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

#define MOD (1000000007LL);

using namespace std;


int main(void){
    long long N;
    cin >> N;
    map<long long, long long> ht;
    for(long long n = 1; n <= N; n++){
        long long nn = n;
        long long t = nn % 10;
        while(nn >= 10) nn /= 10;
        long long h = nn;
        ht[h * 10 + t]++;
    }
    long long ans = 0;
    for(int i = 1; i <= 9; i++){
        for(int j = 1; j <= 9; j++){
            ans += ht[10 * i + j] * ht[10 * j + i];
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

struct UnionFind {
  vector<int> par;
  
  UnionFind(int N) : par(N){
    for(int i = 0; i < N; i++) par[i] = i;
  }
  
  int root(int x){
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }
  
  bool unite(int x, int y){
    int rx = root(x);
    int ry = root(y);
    if (rx == ry) return false;
    par[rx] = ry;
    return true;
  }
  
  bool same(int x, int y){
    return root(x) == root(y);
  }
};

int main(){
  int n, q;
  cin >> n >> q;
  UnionFind tree(n);
  int com, x, y;
  rep(i, q){
    cin >> com >> x >> y;
    if (com == 0) tree.unite(x, y);
    else {
      if (tree.same(x, y)) cout << 1 << endl;
      else cout << 0 << endl;
    }
  }
  
  return 0;
}


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

#include <vector>
#include <iostream>
#include <unordered_map>
#include <map>
#include <iomanip>
#include <set>
#include <functional>
#include <fstream>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <string>
#include <sstream>
#include <queue>
using namespace std;

#define x first
#define y second
constexpr int MOD = 1000000007;

typedef std::pair<int,int> pii;
typedef long long ll;
typedef unsigned int ui;

template<typename T>std::istream&operator>>(std::istream&i,vector<T>&t) {for(auto&v:t){i>>v;}return i;}
template<typename T>std::ostream&operator<<(std::ostream&o,const vector<T>&t) {for(size_t i=0;i<t.size();++i){o<<t[i]<<" \n"[i == t.size()-1];}return o;}
template <typename T, typename U> std::istream&operator>>(std::istream&i, pair<T,U>&p) {i >> p.x >> p.y; return i;}
template<typename T> using minheap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using maxheap = priority_queue<T, vector<T>, less<T>>;
auto fraclt = [](const pii&a,const pii&b) { return (ll)a.x * b.y < (ll)b.x * a.y; };
struct cmpfrac { bool operator()(const pii&a,const pii&b)const { return (ll)a.x * b.y < (ll)b.x * a.y; }};
template <typename T> bool in(T a, T b, T c) { return a <= b && b < c; }
int logceil(ll x) {int b=0;while(x){x>>=1;++b;}return b;}

namespace std {
    template<typename T,typename U>struct hash<pair<T,U>>{hash<T>t;hash<U>u;size_t operator()(const pair<T,U>&p)const{return t(p.x)^(u(p.y)<<7);}};
}
template<typename T,typename F>T bsh(T l,T h,const F&f){T r=-1,m;while(l<=h){m=(l+h)/2;if(f(m)){l=m+1;r=m;}else{h=m-1;}}return r;}
template<typename T,typename F>T bsl(T l,T h,const F&f){T r=-1,m;while(l<=h){m=(l+h)/2;if(f(m)){h=m-1;r=m;}else{l=m+1;}}return r;}
template<typename T> T gcd(T a,T b) { if (a<b) swap(a,b); return b?gcd(b,a%b):a; }

template<typename T>class vector2:public vector<vector<T>>{public:vector2(){} vector2(size_t a,size_t b,T t=T()):vector<vector<T>>(a,vector<T>(b,t)){}};
template<typename T>class vector3:public vector<vector<vector<T>>>{public:vector3(){} vector3(size_t a,size_t b,size_t c,T t=T()):vector<vector<vector<T>>>(a,vector<vector<T>>(b,vector<T>(c,t))){}};

// #include "../l/mod.h"

class A {
public:
    void solve(istream& cin, ostream& cout) {
		ll N, A, B; cin >> N >> A >> B;
		if (N == 1) {
			if (A == B) cout << 1 << endl;
			else cout << 0 << endl;
		} else if (A > B) {
			cout << 0 << endl;
		} else
		cout << ((N-1)*B + A - ((N-1)*A + B) + 1) << endl;
    }
};


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



Measured memory_bytes: 256
#include<bits/stdc++.h>
 using namespace std;
 #define ll long long int
 int main()
  {   ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   
       
       ll a,b,c,x;
        cin>>a>>b>>c;
         x=ceil(float (a)/float (c)); 
         if(x<=b)
             cout<<"Yes"<<endl;
         else
            cout<<"No"<<endl;
  }



Measured memory_bytes: 3660
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		int N2 = N * 2;
		
		int[] cnt0 = new int[26];
		for(int i=0;i<N;i++) cnt0[S[i] - 'a']++;
		
		int[] cnt1 = new int[26];
		for(int i=N;i<N2;i++) cnt1[S[i] - 'a']++;
		
		for(int j=0;j<26;j++){
			if(cnt0[j] != cnt1[j]){
				Console.WriteLine(0);
				return;
			}
		}
		
		var di1 = new Dictionary<Pair,long>();
		for(int i=0;i<1<<N;i++){
			var ca0 = new List<char>();
			var ca1 = new List<char>();
			for(int j=0;j<N;j++){
				if(((i >> j) & 1) == 0){
					ca0.Add(S[j]);
				} else {
					ca1.Add(S[j]);
				}
			}
			var s = new String(ca0.ToArray());
			var t = new String(ca1.ToArray());
			var p = new Pair(s, t);
			if(di1.ContainsKey(p) == false) di1.Add(p, 0);
			di1[p]++;
		}
//Console.WriteLine("ok");		
		
		var di2 = new Dictionary<Pair,long>();
		for(int i=0;i<1<<N;i++){
			var ca0 = new List<char>();
			var ca1 = new List<char>();
			for(int j=0;j<N;j++){
				if(((i >> j) & 1) == 0){
					ca0.Add(S[N2 - 1 - j]);
				} else {
					ca1.Add(S[N2 - 1 - j]);
				}
			}
			var s = new String(ca0.ToArray());
			var t = new String(ca1.ToArray());
			var p = new Pair(s, t);
			if(di2.ContainsKey(p) == false) di2.Add(p, 0);
			di2[p]++;
		}
		
		long ans = 0;
		foreach(var p in di1.Keys){
			if(di2.ContainsKey(p)){
//Console.WriteLine("p;{0} di1:{1}, di2:{2}",p.ToString(), di1[p], di2[p]);
				ans += di1[p] * di2[p];
			}
		}
		
		Console.WriteLine(ans);
		
		
		
		
		
		
	}
	
	struct Pair{
		public String S,T;
		public Pair(String s, String t){
			S = s; T = t;
		}
		public override String ToString(){
			return S + "," + T;
		}
	}
	
	
	int N;
	String S;
	public Sol(){
		N = ri();
		S = rs();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 90992
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
ll n;
int a[3][3];
int main(){
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++) cin>>a[i][j];
    }
    cin>>n;
    for(int k=0;k<n;k++){
        int b;
        cin>>b;
        for(int i=0;i<3;i++){
            for(int j=0;j<3;j++){
                if(a[i][j]==b) a[i][j]=0;
            }
        }
    }
    bool ok=0;
    for(int i=0;i<3;i++){
        if(a[i][0]==0 && a[i][1]==0 && a[i][2]==0) ok=1;
    }
    for(int j=0;j<3;j++){
        if(a[0][j]==0 && a[1][j]==0 && a[2][j]==0) ok=1;
    }
    if(a[0][0]==0 && a[1][1]==0 && a[2][2]==0) ok=1;
    if(a[0][2]==0 && a[1][1]==0 && a[2][0]==0) ok=1;
    if(ok) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define mp make_pair
#define inf 1000000007
#define int long long
using namespace std;
int dp[514514];
ll dp2[25114515];
signed main(){
	int n;
	cin>>n;
	int ga,sa,ba,gb,sb,bb;
	cin>>ga>>sa>>ba>>gb>>sb>>bb;
	for(int i=1;i<=50000;i++){
		dp[i] = dp[i-1]+1;
		if(i>=ga)dp[i]=max(dp[i],dp[i-ga]+gb);
		if(i>=sa)dp[i]=max(dp[i],dp[i-sa]+sb);
		if(i>=ba)dp[i]=max(dp[i],dp[i-ba]+bb);
		//cout<<i<<" "<<dp[i]<<endl;
	}
	for(int i=1;i<=25114514;i++){
		dp2[i] = dp2[i-1]+1;
		if(i>=gb)dp2[i]=max(dp2[i],dp2[i-gb]+ga);
		if(i>=sb)dp2[i]=max(dp2[i],dp2[i-sb]+sa);
		if(i>=bb)dp2[i]=max(dp2[i],dp2[i-bb]+ba);
		//cout<<i<<" "<<dp2[i]<<endl;
	}
	cout<<dp2[dp[n]]<<endl;
	return 0;
}

Measured memory_bytes: 196864
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	int n;
	cin>>n;
	int t[n+1],x[n+1],y[n+1];
	for (int i=1; i<=n; i++)
	{
		cin>>t[i]>>x[i]>>y[i];
	}
	int k=0;
	for (int i=1; i<=n; i++)
	{
		if (x[i]+y[i]<=t[i] && (x[i]+y[i]-t[i])%2==0)
			k++;
	}
	if (k==n)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<ll,ll> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const double PI=3.141592653589;
const int INF=1000000007;
const ll LMAX=1000000000000001;
int gcd(int a,int b){if(a<b)swap(a,b);int c=a%b;while(c!=0){a=b;b=c;c=a%b;}return b;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};

int main(){
  ll a, b, n; cin >> a >> b >> n;
  ll ans;
  if(n < b){
    ans = (a * n) / b;
  }else{
    if(n >= 2 * b - 1) ans = (b - 1) * a / b;
    else ans = max((n - b), b - 1) * a / b;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    if(s=="SUN")cout<< 7;
    if(s=="MON")cout<< 6;
    if(s=="TUE")cout<< 5;
    if(s=="WED")cout<< 4;
    if(s=="THU")cout<< 3;
    if(s=="FRI")cout<< 2;
    if(s=="SAT") cout<< 1;
    return 0;
}


Measured memory_bytes: 256
n,m = map(int, input().split())
connect_1 = set()
connect_n = set()
for i in range(m):
    a, b = map(int, input().split())
    if a  == 1:
        connect_1.add(b)
    if b == n:
        connect_n.add(a)
if connect_1 & connect_n:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

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

#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int main()
{
    int n;
    cin >> n;
    if(n/10 == 9 || n%10 == 9) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < (n); i++)
#define Rep(i, n) for(int i = 1; i < n; i++)

const int mod = 1000000007;
const int inf = (1 << 21);
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;

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 GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
int round_int(int a, int b) { return (a + (b - 1)) / b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

int main() {
	char ctoi[256];
	ctoi['S'] = 0;
	ctoi['H'] = 1;
	ctoi['C'] = 2;
	ctoi['D'] = 3;

	vvb kards(4, vb(14, false));

	int n;
	cin >> n;

	rep(i, n) {
		char u;
		int v;
		cin >> u >> v;

		kards[ctoi[u]][v] = true;
	}

	string s = "SHCD";
	rep(i, 4) {
		for (int j = 1; j <= 13; ++j) {
			if (!kards[i][j]) {
				cout << s[i] << " " << j << endl;
			}
		}
	}
}


Measured memory_bytes: 3216
#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() // 昇順ソート
#define rall(v)(v).rbegin(), (v).rend() // 降順ソート
#define INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair < ll, ll >
#define F first
#define S second
const int MOD = 1000000007;
template < class T > bool chmax(T & a,const T & b) { if (a < b) { a = b; return true; } return false; }
template < class T > bool chmin(T & a,const T & b) { if (a > b) { a = b; return true; } return false; }
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main() {
    string S;cin >> S;
    string ans = "";
    bool ok = false;

    rep(i,S.size()){
        ans = "";
        for(int x = 0;x < i;x++){
            ans += S[x];
        }
        
        for(int j = i;j < S.size();j++){
            string tmp = "";
            for(int y = j;y < S.size();y++){
                tmp += S[y];
            }
            if(ans + tmp == "keyence")ok = true;
        }
    }
    
    if(ok)cout << "YES" << endl;
    else cout << "NO" << endl;
}

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

int main()
{
	int N, C, K;
	cin >> N >> C >> K;
	vector<int> T(N);
	for (int i = 0; i < N; i++)
		cin >> T[i];

	sort(T.begin(), T.end());

	int buses = 0;

	for (int i = 0; i < N;)
	{
		buses++;
		int mintime = T[i++];
		int passengers = 1;
		while (i < N && passengers < C && mintime + K >= T[i])
		{
			passengers++;
			i++;
		}
	}

	cout << buses;
}

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

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

    ll b = 7, pos = 1;
    for (ll i = 0; i <= k; i++) {
        if (b % k == 0) {
            cout << pos << endl;
            return 0;
        } else {
            b = (b * 10 + 7) % k;
            pos++;
        }
    }

    cout << -1 << endl;
}

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

int p[200010], guru[200010], gid[200010]={}, grundy[200010]={}, grcand[200010]={}, verif[200010];
bool cycle[200010]={};
vector<vector<int>> G, vg;

void dfs(int key){
    for(int i=0; i<G[key].size(); ++i){
        if(!cycle[G[key][i]]){
            dfs(G[key][i]);
            vg[key].emplace_back(grundy[G[key][i]]);
        }
    }
    sort(vg[key].begin(), vg[key].end());
    vg[key].emplace_back(1e9);
    int d=0;
    while(grundy[key]==vg[key][d]){
        while(grundy[key]==vg[key][d]) ++d;
        ++grundy[key];
    }
    if(cycle[key]){
        grcand[key]=grundy[key]+1;
        while(grcand[key]==vg[key][d]){
            while(grcand[key]==vg[key][d]) ++d;
            ++grcand[key];
        }
    }
}

int main(void){
    int N;
    cin >> N;
    G.resize(N+1);
    for(int i=1; i<=N; ++i){
        cin >> p[i];
        G[p[i]].emplace_back(i);
    }
    int now=1, lkg;
    for(lkg=1; gid[now]==0; ++lkg){
        guru[lkg]=now;
        gid[now]=lkg;
        now=p[now];
    }
    for(int i=gid[now]; i<lkg; ++i){
        cycle[guru[i]]=1;
    }
    vg.resize(N+1);
    for(int i=gid[now]; i<lkg; ++i){
        dfs(guru[i]);
    }
    verif[gid[now]]=grundy[now];
    for(int i=gid[now]+1; i<lkg; ++i){
        if(verif[i-1]==grundy[guru[i]]) verif[i]=grcand[guru[i]];
        else verif[i]=grundy[guru[i]];
    }
    if(verif[lkg-1]!=grundy[now]){
        cout << "POSSIBLE" << endl;
        return 0;
    }
    verif[gid[now]]=grcand[now];
    for(int i=gid[now]+1; i<lkg; ++i){
        if(verif[i-1]==grundy[guru[i]]) verif[i]=grcand[guru[i]];
        else verif[i]=grundy[guru[i]];
    }
    if(verif[lkg-1]==grundy[now]){
        cout << "POSSIBLE" << endl;
        return 0;
    }
    cout << "IMPOSSIBLE" << endl;
    return 0;
}


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

int main() {
	long long a[10000], Min, Max, Sum;
	int n;
	cin >> n;
	Min = 1000000;
	Max = -1000000;
	Sum = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] < Min) {
			Min = a[i];
		}
		if (a[i] > Max) {
			Max = a[i];
		}
		Sum = Sum + a[i];
	}

	cout << Min << " " << Max << " " << Sum << endl;

	return 0;
}

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
long double EPS=1E-8;
////////////////////////////////////////

struct people{
    ll h,p,s;
    bool operator<(const people b)const{
        return s<b.s;
    }
};

int main(){
    ll n;cin>>n;
    people a[n];
    rep(i,0,n-1){
        cin>>a[i].h>>a[i].p;
        a[i].s=a[i].h+a[i].p;
    }
    sort(a,a+n);
    ll dp[n+1][n+1];rep(i,0,n)rep(j,0,n)dp[i][j]=inf;
    rep(i,0,n)dp[i][0]=0;
    rep(i,1,n){
        rep(j,1,n){
            dp[i][j]=dp[i-1][j];
            ll pow=dp[i-1][j-1]+a[i-1].p;
            if(dp[i-1][j-1]<=a[i-1].h)Min(dp[i][j],pow);
        }
    }
    /*rep(i,0,n){
        rep(j,0,n){
            cout<<dp[i][j]<<" ";
        }cout<<endl;
    }*/
    rep(j,1,n){
        if(dp[n][j]==inf){
            cout<<j-1<<endl;return 0;
        }
    }cout<<n<<endl;
    
    return 0;
}



Measured memory_bytes: 195712
import sys
sys.setrecursionlimit(10000000)
G = None
ans = None

def dfs(v, parent_c=-1, parent_id=-1):
    global G, ans
    k = 1
    for i in range(len(G[v])):
        edge_id, to = G[v][i]['edge_id'], G[v][i]['to']
        if to == parent_id: continue
        if k == parent_c: k+=1
        ans[edge_id] = k
        k += 1
        dfs(to, parent_c=ans[edge_id], parent_id=v)

def main():
    global G, ans
    N = int(input())
    G = [[] for _ in range(N)]
    ans = [0 for _ in range(N-1)]
    for edge_id in range(N-1):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        G[a].append({'to': b, 'edge_id': edge_id})
        G[b].append({'to': a, 'edge_id': edge_id})
    
    dfs(0)
    print(max(ans))
    for a in ans:
        print(a)

main()

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

using namespace std;
using ll = long long;

int main() {
  int n, m;
  cin >> n >> m;
  priority_queue<int> que;
  rep(i, n) {
    int a;
    cin >> a;
    que.push(a);
  }
  rep(i, m) {
    int a = que.top();
    que.pop();
    que.push(a / 2);
  }
  ll ans = 0;
  rep(i, n) {
    ans += que.top();
    que.pop();
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3912
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin>>a.at(i);
  }
  sort(a.begin(),a.end());
  cout<<a.at(n-1)-a.at(0)<<endl;
  return 0;
}


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

#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define INPUT1(n, a) for(int i##n = 0; i##n < n; i##n++) {cin >> a[i##n]; } //n = count, a = vector 

using namespace std;

int main()
{
    int n, ans = 0;
        cin >> n;
    vector<int> a(n);
       rep(i, n) a[i] = i+1;
    vector<int> p(n), q(n);
        INPUT1(n, p);
        INPUT1(n, q);
    map<vector<int>, int> mp; 
    
   do{
        mp[a] =  mp.size();
    }while(next_permutation(a.begin(), a.end()));
    
    ans = abs(mp[p] - mp[q]);
    cout << ans << endl;
    
 return 0;
}

Measured memory_bytes: 5248
// 難さんすう すーぱーさんすうと呼ぼう
// Mを素因数分解しといて例えばM=12としてM=(2^2) * (3^1)なるが、それぞれの因数をそれぞれの乗数ぶん振り分ける感じにした組み合わせが答え
// N = 3なら [1, 1, 1]の3つのどれかに振り分ける つまり以下
// 因数2を2つ,因数3を1つ を振り分けて、
//			[2^1, 2^1, 2^0], [3^1, 3^0, 3^0]
// 				-> [1*(2^1 * 3^1)] * [1*(2^1 * 3^0)] * [1*(2^0 * 3^0)] = 6*2*1 = 12
// あるいは
//			[2^2, 2^0, 2^0], [3^0, 3^0, 3^1] ならば
//				-> [1*(2^2 * 3^0)] * [1*(2^0 * 3^0)] * [1*(2^0 * 3^1)] = 4*1*3 = 12
// あるいは
//			[2^1, 2^1, 2^0], [3^0, 3^0, 3^1] ならば
//				-> [1*(2^1 * 3^0)] * [1*(2^1 * 3^0)] * [1*(2^0 * 3^1)] = 2*2*3 = 12
//
// 解説の""計算量はNに依らない""が意味不明だけど、説明してくれないので無視
// すーぱーさんすうの世界ではこれを重複組合せと呼ばうらしい 漢字だね 画数が多い
// n種類のものから重複を許してr個選ぶ場合の数 = nHr = (n+r-1)Cr に帰着できるらしい

// nCr mod Pなので気をつける
package main

import (
	"fmt"
	"math"
)

var MOD int

func main() {
	var N, M int
	fmt.Scan(&N, &M)
	arr := primeFactorization(M)
	ans := 1
	MOD = int(math.Pow10(9)) + 7
	for _, v := range arr {
		ans = ans * combMod(v+N-1, v, MOD) % MOD
	}
	fmt.Println(ans)
}

func primeFactorization(x int) map[int]int {
	ret := make(map[int]int)
	for i := 2; i*i <= x; i++ {
		for x%i == 0 {
			x /= i
			ret[i] += 1
		}
	}
	if x > 1 {
		ret[x] += 1
	}
	return ret
}

func combMod(n, m, MOD int) int {
	return factorial(n, n-m+1, MOD) * pow(factorial(m, 2, MOD), MOD-2, MOD) % MOD
}

func pow(x, n, MOD int) int {
	r := 1
	for ; n > 0; n /= 2 {
		if n%2 == 1 {
			r = r * x % MOD
		}
		x = x * x % MOD
	}
	return r
}

func factorial(n, m, MOD int) int {
	r := 1
	for i := m; i <= n; i++ {
		r = r * i % MOD
	}
	return r
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>

int main()
{
    int N;
    std::cin >> N;
    std::vector<int> H(N), X(N);
    for (int i = 0; i < N; i++)
    {
        X[i] = 0;
        std::cin >> H[i];
    }

    int cnt = 0;
    while (true)
    {
        bool e = false;
        bool s = false;
        int a = 0;
        for (int i = 0; i < N; i++)
        {
            int x = X[i];
            if (x < H[i])
            {
                s = true;
            }
            else if (x == H[i])
            {
                a++;
                if (s) cnt++;
                s = false;
            }
            if (s)
            {
                X[i]++;
            }
        }
        if (s)cnt++;
        if (a == N)break;
    }

    std::cout << cnt << std::endl;


    return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	// Code for B - K-th Common Divisor
	var A, B, K int
	fmt.Scanf("%d %d %d", &A, &B, &K)

	answer := make([]int, 100)
	var count int = 0
	for i := 1; i <= 100; i++ {
		if A%i == 0 && B%i == 0 {
			answer[count] = i
			count++
		}
	}

	fmt.Println(answer[count-K])
}


Measured memory_bytes: 1836