akhauriyash/Code-Regression huggingface dataset:
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;
const int N = 2e5 + 5;
int arr[N];

int main() {
    //  freopen("test.in", "r", stdin);
    //  freopen("ac.txt", "w", stdout);
    int n, k;
    scanf("%d %d", &n, &k);
    int s = 1, e = 1;
    for (int i = 0; i < n; ++i) {
        scanf("%d", arr + i);
        e = max(e, arr[i]);
    }
    while (s < e) {
        int mid = s + (e - s) / 2;
        int c = 0;
        for (int i = 0; i < n; ++i) {
            c += (arr[i] / mid);
            if (arr[i] % mid == 0) --c;
        }
        if (c <= k) e = mid;
        else s = mid + 1;
    }
    printf("%d", s);
}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    mp[a[i]]++;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    bool pos = true;
    mp[a[i]]--;
    for (int j = 1; j * j <= a[i]; j++) {
      if (a[i] % j == 0) {
        if (mp[j] > 0 || mp[a[i] / j] > 0) {
          pos = false;
          break;
        }
      }
    }
    mp[a[i]]++;
    if (pos) {
      ans++;
    }
  }
  cout << ans << '\n';
  return 0;
}

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

int main(){

  int a, b, c; cin >> a >> b >> c;
  int cnt = 0;

  while(a <= b){
    if(c % a == 0) cnt++;
    a++;
  }

  cout << cnt << endl;
  return 0;
}



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

int main() {
  long int N;
  cin >> N;
  vector<string> s(N);
  for(int i = 0; i < N; i++){
    cin >> s.at(i);
  }
  for(int i = 0; i < N; i++){
    sort(s.at(i).begin(), s.at(i).end());
  }
  sort(s.begin(), s.end());
  long int sum = 0, flag = 0;
  for(int i = 0; i < N - 1; i++){
    if(s.at(i) == s.at(i + 1)){
      sum++;
      flag++;
    }else if(flag != 0){ 
      sum = sum + ((flag * (flag + 1)) / 2) - flag;
      flag = 0;
    }
    if(i == N - 2 && flag != 0){
      sum = sum + ((flag * (flag + 1)) / 2) - flag;
      flag = 0;
    }
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 7296
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define erep(i,N) for(int i = N; i >= 0; i--)
const ll INF = 1000000000000000000;
//input
int N;
int A1[105];
int A2[105];

//processing
int ans,cnt;


//dpTable
//int dp[100050];

int main(){
    cin >> N;
    rep (i,N){
        cin >> A1[i];
    }
    rep (i,N){
        cin >> A2[i];
    }
    for (int i = 0; i <= N - 1; i++){
        for (int j = 0; j <= i; j++){
            cnt += A1[j];
        }
        for (int k = i; k <= N - 1; k++){
            cnt += A2[k];
        }
        ans = max(ans,cnt);
        cnt = 0;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

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

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;

    ll ans = INF;
    for (ll i = 0; i <= max(X, Y); i++) {
        if (X-i < 0) {
            ans = min(ans, C*2*i+B*(Y-i));
        } else if (Y-i < 0) {
            ans = min(ans, C*2*i+A*(X-i));
        } else {
            ans = min(ans, C*2*i+A*(X-i)+B*(Y-i));
        }
    }

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

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int a[2][1000005],b[1000005];
char s[105];
int main()
{
	int i,n,len,j,p=0,q=1,k,x,y,m,z;
	while(scanf("%d",&n)&&n!=0)
	{
	cin>>s;
	len=strlen(s);
	memset(a,0,sizeof(a));
	p=0,q=1;
	for(i=1;i<=len;i++)a[0][i]=s[i-1]-'0';
	for(i=1;i<=n;i++)
	{
		k=1;
		x=0;
		for(j=1;j<=len;j++)
		{
			if(a[p][j]==a[p][j+1]&&j+1<=len)k++;
			else 
			{
				if(k<10)
				{
					x++;
				    a[q][x]=k;
				}
				else 
				{
					m=0;
					while(k>=10)
					{
						m++;
						b[m]=k%10;
						k/=10;
					}
					x++;
					a[q][x]=k;
					for(z=m;z>=1;z--)
					{
						x++;
						a[q][x]=b[z];
					}
				}
				x++;
				a[q][x]=a[p][j];
				k=1;
			}
	    }
	    len=x;
	    y=q,q=p,p=y;
	}
	for(i=1;i<=len;i++)
	{
		cout<<a[p][i];
	}
	cout<<endl;
    }
	return 0;
}


Measured memory_bytes: 10984
/* cerberus97 - Hanit Banga */

#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 5e3 + 10;

int wt[N];
ll dp[N][N];

int main() {
	fast_cin();
	int n, mod;
	cin >> n >> mod;
	int k = (n - 1) / 2;
	for (int i = 2; i <= n; ++i) {
		if (i < n - k + 1) {
			wt[i] = i - 1;
		} else {
			wt[i] = n + 2 - i;
		}
	}
	dp[1][n] = 1;
	for (int i = 1; i < n; ++i) {
		for (int val = n; val >= 1; --val) {
			dp[i][val] %= mod;
			dp[i + 1][val] += dp[i][val];
			if (val > wt[i + 1]) {
				dp[i][val - wt[i + 1]] += dp[i][val];
			}
			// dp[i][val] %= mod;
			// int max_x = val / wt[i + 1];
			// for (int x = 0; x <= max_x; ++x) {
			// 	dp[i + 1][val - x * wt[i + 1]] += dp[i][val];
			// }
		}
	}
	ll ans = 0;
	for (int val = 1; val <= n; ++val) {
		dp[n][val] %= mod;
		ans += val * dp[n][val];
		ans %= mod;
	}
	cout << ans << endl;
}

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

int main(){
	int n,number;
	long long a,b;
	bool flag;
	map<int,long long> info;
	vector<int> seq;
	
	while(cin >> n && n){
		info.clear();
		seq.clear();
		while(n--){
			cin >> number >> a >> b;
			if(!info[number])seq.push_back(number); // ツ甘ケツ出ツつセツづつスツづァツ表ツ篠ヲツ渉記ツ録ツ配ツ療アツづ可禿シツづェツづ按つ「ツ。ツ単ツ可ソ0ツ円ツケツーツスツづーツ考ツ猟カツつオツづづ慊つケツづアツ。
			info[number] += a*b;
		}
		flag = true;
		for(int i=0;i<seq.size();i++){
			if(info[seq[i]]>=1000000){
				flag = false;
				cout << seq[i] << endl;
			}
		}
		if(flag)cout << "NA" << endl;
	}
}

Measured memory_bytes: 0
n,m=map(int,input().split())
l=[]
for i in range(n):
  l.append(list(map(int,input().split())))
ans=[]
for i in range(n):
  for j in range(m-1):
    if l[i][j]%2==1:
      ans.append([str(i+1),str(j+1),str(i+1),str(j+2)])
      l[i][j]=2
      l[i][j+1]+=1
for i in range(n-1):
  if l[i][-1]%2==1:
    ans.append([str(i+1),str(m),str(i+2),str(m)])
    l[i][-1]=2
    l[i+1][-1]+=1
print(len(ans))
for i in range(len(ans)):
  print(" ".join(ans[i]))

Measured memory_bytes: 51700
import java.util.*;
import static java.lang.System.*;
import java.io.*;
import java.math.*;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		if (sc.nextInt() == sc.nextInt())
			out.println("Yes")
		;
		else
			out.println("No");

		out.close();
	}

static class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}
}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    long double a[205];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    for(int i=1;i<n;i++)
    {
        a[i]=(a[i]+a[i-1])/2;
    }
    cout<<fixed<<setprecision(10)<<a[n-1];
}


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

int main(void){
    string S;
    cin>>S;
    bool ans = true;
    sort(S.begin(),S.end());
    for (int i=1;i<S.size();i++) {
        if (S[i]==S[i-1]) {
            ans = false;
            break;
        }
    }
    cout<<((ans)?"yes":"no")<<endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
a.sort()
a.append(a[-1] + 1)

b = [a[0]]
c = [1]
ans = 0
for i in range(1, n+1):
    if a[i] == b[-1]:
        c[-1] += 1
    else:
        cand = c[-1]
        if len(b) >= 2 and b[-2] == b[-1] - 1:
            cand += c[-2]
        if len(b) >= 3 and b[-3] == b[-1] - 2:
            cand += c[-3]
        ans = max(ans, cand)
        b.append(a[i])
        c.append(1)

print(ans)


Measured memory_bytes: 13964
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7;
constexpr long long INF = numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourd; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Mfor(i,mf) for(LL i=mf-1;i>=0;i--)
double h, w, n, m, k, t, s, p, q, last, first, cnt, sum, d[2000], a[600000], b[60000];
double ans;
string str, ss;
bool f[202000];
char c,ch[100][100];
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
struct Edge { LL to, cost; };
vector<Edge>vec[200000];
vector<LL>v;
map<LL, LL>ma;
multiset<LL>st;
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

int main() {
	cin >> n >> m;
	rep(i, n) {
		double x, y;
		cin >> x >> y;
		double cur = y / x;
		ans = max(cur*m, ans);
	}
	printf("%.15f\n", ans);
	return 0;
}



Measured memory_bytes: 7992
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
#define ll long long 
const int maxn = 2e5 + 5;
int a[maxn], b[maxn];
int p[1000010];
int main()
{
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)cin >> a[i];
	sort(a + 1, a + 1 + n);
	int ans = 0;
	for (int i = 1; i <= n; i++)
	{
		int t = a[i];
		if (p[t] == 0)
		{
			if (a[i] != a[i + 1])ans++;
			for (int j = 1; t * j <= 1000000; j++)
			{
				p[t * j] = 1;
			}
		}
	}cout << ans << endl;
}

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

int main() {
  int R;
  cin >> R;
  cout << (double)2*R*3.14159265358979 << endl;
  return 0;
}

Measured memory_bytes: 3772
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

ll lcm(ll a,ll b){
  return (a*b)/gcd(a,b);
}


int main(){
  ll n; cin >> n;
  
  vl pow8(n+1); vl pow9(n+1); vl pow10(n+1);
  
  pow8[0] = 1; pow9[0] = 1; pow10[0] = 1;
  
  rep(i,n){
    pow8[i+1] = mod(8*pow8[i]);
    pow9[i+1] = mod(9*pow9[i]);
    pow10[i+1] = mod(10*pow10[i]);
  }
  
  ll ans = pow10[n]-mod(2*pow9[n])+pow8[n];
  if(ans < 0) cout << abs(1000000007+ans) << endl;
  else cout << ans << endl;
  
  
}

Measured memory_bytes: 26752
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
constexpr int MOD=1000000007;
//constexpr int MOD=998244353;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;

int main(void){
    int N;
    cin >> N;
    int A[N];
    rep(i,N) cin >> A[i];
    sort(A,A+N);
    if(A[N-1]-A[0]>1) cout << "No" << endl;
    else if(A[N-1]-A[0]==1){
        int lo=A[0];
        int cnt=0;
        rep(i,N) if(A[i]==lo) cnt++;
        if(cnt<=lo && lo+1<=cnt+(N-cnt)/2) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    else{
        if(A[0]<=N/2 ||A[0]==N-1) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <cmath>

int main() {
	std::string s;
	std::cin >> s;
	long k;
	std::cin >> k;
	for (long k_i=0;k_i<k;++k_i) {
		if (s[k_i] != '1') {
			std::cout << s[k_i] << "\n";
			return 0;
		}
	}
	std::cout << '1' << "\n";


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる


int main() {
  ll n,h;
  cin >> n >> h;

  vector<ll> p(n);
  vector<ll> q(n);
  rep(i,n){
    cin>>p[i]>>q[i];
  }

  sort(all(p));
  reverse(all(p));
  sort(all(q));
  reverse(all(q));

  ll now=0;
  ll nage=n;
  rep(i,n){
    if(p[0]>=q[i]) {
      nage=i;
      break;
    }
    now+=q[i];
    if(now>=h){
      cout << i+1 << endl;
      return 0;
    }
  }

  cout << nage+(h-now+p[0]-1)/p[0] << endl;

}


Measured memory_bytes: 1792
n = int(input())
area = [[0 for _ in range(n)] for _ in range(2)]
dist = [[0 for _ in range(n)] for _ in range(2)]

for i in range(2):
    for j, a in zip(range(n), map(int, input().split())):
        area[i][j] = a

for i in range(2):
    for j in range(n):
        m = 0
        if i-1 >= 0:
            if dist[i-1][j] > m:
                m = dist[i-1][j]
            if j-1 > 0:
                if dist[i-1][j-1] > m:
                    m = dist[i-1][j-1]
        if j-1 >= 0:
            if dist[i][j-1] > m:
                m = dist[i][j-1]
        dist[i][j] = area[i][j] + m

print(dist[1][n-1])

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

int main(){
	string S; int X,Y; cin>>S>>X>>Y;

	vector<int> dx,dy;
	bool isX = true;
	if(*--S.end() == 'F') S += "T";
	int d = 0;
	for(auto s:S)
		if(s=='F') d++;
		else{
			if(isX) dx.push_back(d); else  dy.push_back(d);
			isX = !isX;
			d = 0;
		}

	set<int> dp;

	bool fst = true;
	dp.insert(0);
	for(int d:dx){
		set<int> t; swap(t,dp);
		for(auto j:t){ if(!fst) dp.insert(j-d); dp.insert(j+d); }
		fst = false;
	}
	bool x = dp.count(X)!=0;

	dp.clear();

	dp.insert(0);
	for(int d:dy){
		set<int> t; swap(t,dp);
		for(auto j:t){ dp.insert(j-d); dp.insert(j+d); }
	}
	bool y = dp.count(Y)!=0;

	cout<< (x & y? "Yes":"No") <<endl;
}

Measured memory_bytes: 640
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 + 1][3];
		for (int i = 1; i <= n; i++) {
			for (int j = 0; j < 3; j++) a[i][j] = sc.nextInt();
		}
		int DP[][] = new int[n + 1][3];
		for (int i = 1; i <= n; i++) {
			for (int j = 0; j < 3; j++) {
				for (int k = 0; k < 3; k++) {
					if (j != k) DP[i][j] = Math.max(DP[i - 1][k] + a[i][j],DP[i][j]);
				}
			}
		}
		int Res = 0;
		for (int i = 0; i < 3; i++) Res = Math.max(DP[n][i], Res);
		System.out.print(Res);
	}

}


Measured memory_bytes: 99276
n,m = map(int,input().split())
num_ball =[1]*n
possible = [False]*n
possible[0]= True

for i in range(m):
  here,next = map(int,input().split())
  next -=1
  here -=1
  
  if possible[here]:
    possible[next]=True
    if num_ball[here] == 1:
      possible[here]=False
  else:
    if num_ball[here] == 1:
      possible[here]=False
      
  num_ball[here] -=1
  num_ball[next] +=1
  
print(possible.count(True))

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

using namespace std;
#define chmax(a,b) a=max(a,b)
#define mod 1000000007
#define N 3010
double f[N],cop[N];
int main(){
    for(int i=0;i<N;i++)f[i]=0; f[0]=1;
    ll n;cin>>n;
    for(int u=0;u<n;u++){
     double p; cin>>p;
     for(int i=N-1;i>=0;i--){
      f[i]*=(1-p);
      if(i)f[i]+=p*f[i-1];
     }
    }
    double ans=0;
    for(int i=0;i<=n;i++){
     if(i>n-i)ans+=f[i];   
    }
    cout<<fixed<<setprecision(9)<<ans<<endl;
 return 0;   
}

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

int main()
{  
  int n;
  cin >> n;
  for(int i=1;i<10;++i){
    for(int j=i;j<10;++j){
      if(i*j==n){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)     for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = m; i <= (int)(n); i++)
#define MOD 1000000007
#define Graph vector<vector<int>>
#define lint int64_t
typedef pair<int, int> PII;
#define INF 10000

int main(){
  int H,W;
  cin >> H >> W;

  //迷路情報を代入
  char C[H][W];
  rep(i,H){
    rep(j,W){
      char tmp;
      cin >> tmp;
      C[i][j] = tmp;
    }
  }


  int distance[H][W];
  queue<PII> q;
  int dy[4] = {1,0,-1,0};
  int dx[4] = {0,1,0,-1};

  int MAXdis = 0;
  rep(sx,H){
    rep(sy,W){
      if(C[sx][sy] == '#') continue;
      rep(gx,H){
        rep(gy,W){
          if(C[gx][gy] == '#') continue;
          if((sx == gx) && (sy == gy)) continue;
          int dismax = 0;
          fill(distance[0], distance[H], INF);
          q.emplace(sx,sy);
          distance[sx][sy] = 0;
          /////////////////
          while(!q.empty()){
            PII now = q.front();//現在地
            q.pop();
            //移動4方向をループ
            rep( i, 4 ){
   
              int ny = now.first + dy[i], nx = now.second + dx[i];
              //移動が可能かの判断と既に訪れた事があるかの判定
              if( 0 <= ny && ny < H && 0 <= nx && nx < W && C[ny][nx] != '#' && distance[ny][nx] == INF)
              {
                q.emplace( ny, nx );
                distance[ny][nx] = distance[now.first][now.second] + 1;                
                dismax = distance[ny][nx];
              }   
		        }
        	}
          MAXdis = max(MAXdis,dismax);
          ////////////////
        }
      }
    }
  }

	cout << MAXdis << endl;
  return 0;
}


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

#define L 1000000007l
#define PROD(a, b) ((((a) % L) * ((b) % L)) % L)

int factorial(long long N){
  if(N <= 1) return 1;
  else return PROD(N, factorial(N - 1));
}

long long solve(long long N, long long M){
  switch(N-M){
    case 1: case -1: return PROD(factorial(N), factorial(M));
    case 0: return PROD(PROD(factorial(N), factorial(M)), 2);
    default: return 0;
  }
}

int main(){
  long long N, M;
  cin >> N >> M;
  cout << solve(N, M) << endl;
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define per(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define INF 2e9
typedef long long ll;
typedef pair<int, int> P;

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

    cout << n*n*n << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


signed main() {
  string s; 
  cin >> s;

  int ans = 0;
  int N = s.size();
  REP(i, N) if(s[i] == 'o') ans++;
  ans += 15-N;

  if(ans < 8) NO;
  else YES;

  return 0;
}

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

const int maxn = 1e5+7;
int a[maxn];
int c1[maxn],c2[maxn];
int v1[maxn],v2[maxn];
int cmp(int a,int b)
{
    return a>b;
}

int main()
{
    int n;
    memset(c1,0,sizeof(c1));
    memset(c2,0,sizeof(c2));
    memset(v1,0,sizeof(v1));
    memset(v1,0,sizeof(v2));
    scanf("%d",&n);
    for(int i = 1; i <= n; i++)
        scanf("%d",&a[i]);
    for(int i = 1,j = 2; i <= n && j <= n; i+=2,j+=2)
    {
        c1[a[i]]++;
        v1[a[i]]++;
        c2[a[j]]++;
        v2[a[j]]++;
    }
    sort(c1,c1+maxn,cmp);
    sort(c2,c2+maxn,cmp);
    if(c1[0] == n/2 && c2[0] == n/2)
    {
        if(a[1] != a[2])
            printf("0\n");
        else printf("%d\n",n/2);
    }
    else if(c1[0] != n/2 && c2[0] == n/2)
    {
        if(a[1] != a[2])
            printf("%d\n",n/2-c1[0]);
        else printf("%d\n",n/2-c1[1]);
    }
    else if(c1[0] == n/2 && c2[0] != n/2)
    {
        if(a[1] != a[2])
            printf("%d\n",n/2-c2[0]);
        else printf("%d\n",n/2-c2[1]);
    }
    else if(c1[0] != n/2 && c1[0] != n/2)
    {
        for(int i = 1,j = 2; i <= n && j <= n; i+=2,j+=2)
        {
            if(c1[0] == v1[a[i]] && c2[0] == v2[a[j]])
            {
                if(a[i] != a[j])
                {
                    printf("%d\n",n-c1[0]-c2[0]);
                    return 0;
                }
            }
        }
        for(int i = 1,j = 2; i <= n && j <= n; i+=2,j+=2)
        {
            if(c1[1] == v1[a[i]] && c2[1] == v2[a[j]])
            {
                printf("%d\n",n-c1[0]-max(c1[1],c2[1]));
                return 0;
            }
        }
    }
    return 0;
}



Measured memory_bytes: 2176
import itertools
n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
num = [1, 2, 3, 4, 5, 6, 7, 8]
num = num[:n]
list = list(itertools.permutations(num))
for i in range(len(list)):
    if ''.join(map(str, p)) == ''.join(map(str, list[i])):
        pi = i

for i in range(len(list)):
    if ''.join(map(str, q)) == ''.join(map(str, list[i])):
        qi = i

print(abs(pi-qi))

Measured memory_bytes: 8052
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

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

        final List<Pair> pairs = new ArrayList<>();
        for (int i = 1; i <= n; i++) {
            pairs.add(new Pair(i, scanner.nextInt()));
        }

        pairs.sort(Comparator.comparingInt(pair -> pair.timing));
        final String answer = pairs.stream()
                .map(pair -> Integer.toString(pair.number))
                .collect(Collectors.joining(" "));

        System.out.println(answer);
    }

    static class Pair {
        int number;
        int timing;

        public Pair(final int number, final int timing) {
            this.number = number;
            this.timing = timing;
        }
    }
}


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

int main(){
  int N, K ,Q;
  cin >> N >> K >> Q;
  vector<int> Point(N);
  rep(i, Q){
    int a;
    cin >> a;
    a--;
    Point.at(a)++;
  } 
  
  rep(i, N){
    if(K - Q + Point.at(i) > 0) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  
}

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

int main() {
  int n, m;
  std::cin >> n >> m;
  int odd = (m + 1) / 2;
  int even = m / 2;
  std::vector<int> a(m), b(m);
  int p = 1;
  for (int i = 0; i < odd; ++i)
    a[i] = p++;
  for (int i = odd; i-- > 0;)
    b[i] = p++;
  for (int i = 0; i < even; ++i)
    a[odd + i] = p++;
  ++p;
  for (int i = even; i-- > 0;)
    b[odd + i] = p++;
  for (int i = 0; i < m; ++i)
    std::cout << a[i] << " " << b[i] << "\n";
}


Measured memory_bytes: 3964
n = int(input())
l = [tuple(map(int, input().split())) for _ in range(n)]
ans = 10**5
dist = lambda p,q: ((p[0]-q[0])**2 + (p[1]-q[1])**2)**.5
check = lambda c,d: all(dist(c,p)<=d for p in l)

def S(p1,p2,p3):
  a,b = p1; c,d = p2; e,f = p3
  return abs((d-b)*(e-a) - (f-b)*(c-a))

def disk(p1,p2,p3):
  x1,y1 = p1; x2,y2 = p2; x3,y3 = p3
  a2 = (x2 - x3) **2 + (y2 -y3) ** 2 
  b2 = (x1 - x3) **2 + (y1 -y3) ** 2
  c2 = (x2 - x1) **2 + (y2 -y1) ** 2
  area = ((x2 - x1) * (y3 -y1) - (x3 -x1) * (y2- y1)) / 2
  if area == 0:
    return (0,0),10**5
  x = (a2*(b2+c2-a2)*x1 + b2*(c2+a2-b2)*x2 +c2*(a2+b2-c2)*x3) / (16*area*area)
  y = (a2*(b2+c2-a2)*y1 + b2*(c2+a2-b2)*y2 +c2*(a2+b2-c2)*y3) / (16*area*area) 
  r = ((x1 - x ) ** 2 + (y1 - y) ** 2)**.5
  return (x,y), r

for i in range(n-1):
  for j in range(i+1,n):
    c = ((l[i][0]+l[j][0])/2, (l[i][1]+l[j][1])/2)
    d = dist(l[i],l[j])/2
    if check(c,d) and d < ans:
      ans = d
    
for i in range(n-2):
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      c,d = disk(l[i],l[j],l[k])
      if check(c,d) and d < ans:
        ans = d
        
print(ans)


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

int main(){
  char N[200001];
  scanf("%s",N);
  int S=0;
  
  int k=0;
  
  int L=strlen(N);
  
  while(k<L){
    S=S+N[k]-'0';
    k++;
  }
  
  if(S%9==0) printf("Yes\n");
  else printf("No\n");
  
  return 0;
}

Measured memory_bytes: 1856
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <numeric>
#include <algorithm>
//#include <iomanip> : 表示桁数, ex) cout << fixed << setprecision(15) << ...

#define pi 3.14159265358979323846
#define rep(i, n) for (int i = 0; i < n; i++)
using  ll = long long;
using ld = long double;
using Byte = unsigned char;
using namespace std;

//string ans = "Yes";

void SetAns() {
	int N;
	cin >> N;
	vector<ll> a(N);

	ll sunukeSum = 0;
	ll tmp;
	rep(i, N) {
		cin >> a[i];
		sunukeSum = sunukeSum ^ a[i];
	}


	rep(i, N) {
		cout << (a[i] ^ sunukeSum) << " ";
	}

	return;
}

int main() {
	SetAns();
//	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4464
#include <algorithm>
#include <iostream>
#include <map>
using namespace std;
typedef pair<int, int> P;

int main()
{
    int h, w, m;
    cin >> h >> w >> m;
    int x[300005]{0}, y[300005]{0};
    map<P, int> mp;
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        x[a]++;
        y[b]++;
        mp[P(a, b)]++;
    }
    P px[300005], py[300005];
    for(int i = 0; i < h; i++) px[i] = P(x[i], i);
    for(int i = 0; i < w; i++) py[i] = P(y[i], i);
    sort(px, px + h, greater<P>());
    sort(py, py + w, greater<P>());
    bool f = false;
    for(int i = 0; px[i].first == px[0].first; i++){
        for(int j = 0; py[j].first == py[0].first; j++){
            if(!mp[P(px[i].second, py[j].second)]){
                f = true;
                break;
            }
        }
        if(f) break;
    }
    if(f) cout << px[0].first + py[0].first << endl;
    else cout << px[0].first + py[0].first - 1 << endl;
}


Measured memory_bytes: 29356
#include <cassert>
#include <cstdio>
#include <cstdlib>

int
main()
{
    int n;
    assert(scanf("%d", &n) == 1);
    int *a = new int[n];
    int *b = new int[n];
    long long suma = 0, sumb = 0;
    for (int i = 0; i < n; i++) {
        assert(scanf("%d", &a[i]) == 1);
        suma += a[i];
    }
    for (int i = 0; i < n; i++) {
        assert(scanf("%d", &b[i]) == 1);
        sumb += b[i];
    }
    if (suma > sumb) {
        printf("No\n");
        exit(0);
    }
    long long diff = sumb - suma;

    long long need = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] > b[i])
            need += a[i] - b[i];
        else if (a[i] < b[i] && (b[i] - a[i]) % 2 == 1)
            need += 1;
    }
    if (need <= diff)
        printf("Yes\n");
    else
        printf("No\n");
    exit(0);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define IFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define RPT(i,a,b) for(int i=(a);i<((a)+(b));++i)
#define IRPT(i,a,b) for(int i=((a)+(b)-1);i>=(a);--i)
#define ALL(x) x.begin(),x.end()

template<class T> using V = vector<T>;
template<class T> using V2 = V<V<T>>;



void solve(){
  int n; cin >> n;
  V<ll> h(n);
  FOR(i,0,n) cin >> h[i];
  bool psbl = true;
  IFOR(i,0,n-1) {
    if(h[i]-h[i+1]>1) {psbl=false; break;}
    if(h[i]-h[i+1]==1) {
      --h[i];
    }
  }
  if(psbl) cout << "Yes" << endl;
  else cout << "No" << endl;
}

int main(){
  solve();
  return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) *b;
}

struct edge {
	ll ind;
	ll to;
	ll d;
};


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


int main() {
	ll a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a + 3);

	if (a[0] + a[1] == a[2]) { cout << "Yes"; }
	else { cout << "No"; }




	system("PAUSE");
}

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

#define ll long long

using namespace std;

int main(void){
    int N;
    cin >> N;
    vector<int> H(N);
    for(int i = 0; i < N; i++) cin >> H[i];
    for(int i = 0; i < N - 1; i++){
        if(H[i] < H[i + 1]) H[i + 1]--;
        if(H[i] > H[i + 1]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 640
import java.io.*
import java.util.*

fun solve(N: Int){
    val ds = listOf(111, 222, 333, 444, 555, 666, 777, 888, 999)
    val i = ds.map{ it - N }.withIndex().indexOfFirst{ it.value >= 0 }
    println(ds[i])
    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toInt()
    solve(N)
}



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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set
#define l_l pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);

int main() {
  // std::cout << std::fixed << std::setprecision(10);
  string s;
  cin >> s;

  string o;

  for (ll i = 0; i < s.size(); i++) {
    if (s[i] == '1') {
      o += "9";
    }
    if (s[i] == '9') {
      o += "1";
    }
  }

  cout << o << endl;
}


Measured memory_bytes: 3540
A,B,C = map(int, input().split())
K = int(input())
count = 0
a = 0
while K >= 0:

    if (A < B * 2 ** K) and (B * 2 ** K < C * 2 ** a):
        count +=1
    K -=1
    a +=1

if count >= 1:
    print("Yes")
else: print("No")

Measured memory_bytes: 9132
#include<stdio.h>
int main() {
    char i, h, len, j, l, k;
    scanf(" %c", &h);
    if(h=='a'||h=='e'||h=='i'||h=='o'||h=='u'){
        printf("vowel\n");
    }
else{
    printf("consonant\n");
}

    return 0;
}

Measured memory_bytes: 128
n,k = map(int,input().split())
r,s,p = map(int,input().split())
x=0
t = list(input())
for i in range(k):
  temp=t[i::k]
  for j in range(1,len(temp)):
    if temp[j-1]==temp[j]:
      temp[j]='x'
      t[j*k+i]='x'
point=0
for i in t:
  if i == 'r':
    point+=p
  if i == 's':
    point+=r
  if i == 'p':
    point+=s
print(point)

Measured memory_bytes: 4792
#include <bits/stdc++.h>
using namespace std;
typedef long long int lint;

int main(){
    lint n;
    cin >> n;
    lint arr[n];
    for(int i=0; i<n; i++) cin >> arr[i];
    lint cntr = 0;
    vector <lint> v;
    for(int i=0; i<n-1; i++){
        if(arr[i] >= arr[i+1]){
            cntr++;
        }else{
            
            v.push_back(cntr);
            cntr = 0;
        }
    }
    v.push_back(cntr);
    sort(v.begin(), v.end());
    cout << v[v.size() -1];
    
    return 0;
}

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define cinv(n,vec) VL vec(n);for(auto&v:vec)cin>>v;
#define int long long
#define itn int
#define pb push_back
#define eb emplace_back
#define m_p make_pair
#define m_t make_tuple
#define p_p(a,b) pb(m_p(a,b))
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(all(a),greater<>())
#define UNIQUE(a) a.erase(unique(all(a)),a.end())
#define SZ(a) (signed)(a.size())
#define debg(a) cout<<#a<<" "<<a<<endl;
#define debgp(a) cout<<#a<<" "<<a.fi<<" : "<<a.se<<endl
#define call(a) for(auto i:a)cout<<i<<" ";cout<<endl
#define callp(a) for(auto [k,v]:a)cout<<k<<":"<<v<<endl
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define out(a) cout<<(a)<<endl
#define ENDL cout<<endl
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define fi first
#define se second
#define V vector
#define P pair
#define T tuple
#define PQ priority_queue
#define cont const auto
#define VV(type,name,y,x,a) vector<vector<type>> name = vector<vector<type>>(y,vector<type>(x,a))
typedef long long ll;
typedef double D;
typedef long double LD;
typedef string str;
typedef vector<ll> VL;
typedef pair<ll,ll> PL;
typedef vector<pair<ll,ll>> VP;
typedef tuple<ll,ll,ll> T3;
typedef tuple<ll,ll,ll,ll> T4;
typedef struct{ll to;ll cost;} Graphs;
typedef V<V<Graphs>> AdjList;
const signed INF = (1LL<<30);
const long long MOD = (1e9+7);
const long long LINF = (1LL<<60);
const long long LMAX = LLONG_MAX;
void YN(bool b){cout<<(b?"Yes":"No")<<endl;}
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(10);
  
  str s;
  cin>>s;

  ll n = SZ(s);
  VV(ll,dp,n+10,4,0);
  dp[0][0]=1;
  rep(i,n){
    rep(j,4){
      (dp[i+1][j]+=dp[i][j])%=MOD;
      if(s[i]=='?')(dp[i+1][j]*=3)%=MOD;
    }
    if(s[i]=='A'||s[i]=='?')(dp[i+1][1]+=dp[i][0])%=MOD;
    if(s[i]=='B'||s[i]=='?')(dp[i+1][2]+=dp[i][1])%=MOD;
    if(s[i]=='C'||s[i]=='?')(dp[i+1][3]+=dp[i][2])%=MOD;
  }
  out(dp[n][3]);
  
  
  return 0;
}


Measured memory_bytes: 7376
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
    int ans = 0;
    int tmp;
    
	//n頂点m枝に対して隣接リストをつくる。
    int n, q;
    cin >> n >> q;
    int u, v;
    vector< vector <int> > ls(n+1);
    REP(i, n-1){ 
        cin >> u >> v; 
        ls[u].push_back(v); 
        ls[v].push_back(u);
    }
    //
	bool ch[n+1] = {};
	int rt[n+1] = {};
	int p, x;
	REP(i, q){
		cin >> p >> x;
		rt[p] += x;
	} 
	queue< pair <int, int> >qu;
	qu.push(make_pair(1, 0));
	while (qu.size() > 0)
	{
		int now = qu.front().first;
		int nx = qu.front().second;
		qu.pop();
		ch[now] = true;
		rt[now] += nx;
		REP(i, ls[now].size()){
			if(ch[ls[now][i]]) continue;
			qu.push(make_pair(ls[now][i], rt[now]));
		}
	}
	REP1(i, n) cout << rt[i] << " ";
	cout << endl;
}

Measured memory_bytes: 16500
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return map(int,input().split())
def LI(): return list(map(int,input().split()))

def main():
    M = INT()

    SUM = 0
    keta = 0
    for _ in range(M):
        d,c = MAP()
        SUM += c*d
        keta += c
    
    print(keta-1+(SUM-1)//9)
    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
ll mod = 1000000007;
int main(){
  int S, W;
  cin >> S >> W;
  if(S<=W){
    cout << "unsafe" <<endl;
    return 0;
  }
  cout << "safe" <<endl;
    
  return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    cin>>n;
    long long int a,b;
    std::multimap<long long int, long long int> map;
    std::deque<long long int> deq;
    for (int i=0;i<n;i++) {
        cin>>a>>b;
        map.emplace(b,a);
        deq.emplace_back(b);
    }
    sort(deq.begin(),deq.end());
    long long int now=0,dead=0,tmp=0;
    for (int i=0;i<n;i++) {
        if (tmp!=deq[i]) {
            auto p=map.equal_range(deq[i]);
            for (auto itr=p.first;itr!=p.second;itr++) {
                now+=itr->second;
                dead=max(dead,deq[i]);
                //cout<<"now="<<now<<" "<<"dead="<<dead<<endl;
                if (now>dead) {
                    cout<<"No"<<endl;
                    return 0;
                }
            }
            tmp=deq[i];
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
struct man {
	int a, b, c;
	bool operator < (const man &A) {return a-b<A.a-A.b;}
};

int x, y, z, n;
man arr[100100];
ll lef[100100];
ll res, bas, sum;

int main() {
	int i;

	scanf("%d%d%d",&x,&y,&z); n = x+y+z;
	for (i=0;i<n;i++) scanf("%d%d%d",&arr[i].a,&arr[i].b,&arr[i].c);
	for (i=0;i<n;i++) bas += arr[i].c;
	sort(arr,arr+n);
	priority_queue<ll,vector<ll>,greater<ll>> pq;
	for (i=0;i<y;i++) {pq.push(arr[i].b-arr[i].c);sum+=arr[i].b-arr[i].c;}
	for (i=y;i<=n-x;i++) {
		lef[i] = sum;
		sum += arr[i].b-arr[i].c; pq.push(arr[i].b-arr[i].c); sum -= pq.top(); pq.pop();
	}
	while(!pq.empty()) pq.pop();
	sum = 0;
	for (i=n-1;i>n-x;i--) {pq.push(arr[i].a-arr[i].c);sum+=arr[i].a-arr[i].c;}
	for (i=n-x;i>=y;i--) {
		sum += arr[i].a-arr[i].c; pq.push(arr[i].a-arr[i].c);
		res = max(res,bas+lef[i]+sum);
		sum -= pq.top(); pq.pop();
	}
	printf("%lld\n",res);

    return 0;
}


Measured memory_bytes: 2680
import sys
from collections import deque
K = int(input())
q = deque([])
for i in range(1, 10):
    q.append(str(i))
ans = 0
while ans != K:
    l = q.popleft()
    ans += 1
    if ans == K:
        print(l)
        sys.exit()
    if l[-1] == '0':
        q.append(l + '0')
        q.append(l + '1')
    elif l[-1] == '9':
        q.append(l + '8')
        q.append(l + '9')
    else:
        q.append(l + str(int(l[-1]) - 1))
        q.append(l + str(int(l[-1])))
        q.append(l + str(int(l[-1]) + 1))

Measured memory_bytes: 22628
a=input()
m=[a[i] for i in range(len(a))]
b=input()
n=[b[i] for i in range(len(b))]
m.sort()
n.sort(reverse=1)
i=0
while 1>0:
  if i==len(b):
    print("No")
    break
  if i==len(a):
    print("Yes")
    break
  if m[i]<n[i]:
    print("Yes")
    break
  if m[i]>n[i]:
    print("No")
    break
  i+=1

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void){
    long long int n, k, x, y, i, ans1=0, ans2=0, ans=0;
    char s[100001];
    memset(s, '\0', 100001);
    scanf("%s", s);
    for(i=0; s[i] != '\0'; i++){
        if(i%2 == 0 && s[i] == '0') ans1++;
        if(i%2 == 1 && s[i] == '1') ans1++;
    }
    for(i=0; s[i] != '\0'; i++){
        if(i%2 == 0 && s[i] == '1') ans2++;
        if(i%2 == 1 && s[i] == '0') ans2++;
    }
    if(ans1<ans2) ans = ans1;
    else ans = ans2;
    printf("%lld", ans);
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int i,a[10],b[10],tmp,j;
  for(i=0;i<10;i++)scanf("%d",&a[i]);
  for(i=0;i<10;i++)scanf("%d",&b[i]);
  for(i=0;i<9;i++){
    for(j=9;j>i;j--){
      if(a[j]>a[j-1]){
	tmp=a[j];
	a[j]=a[j-1];
	a[j-1]=tmp;
      }
    }
  }
  for(i=0;i<9;i++){
    for(j=9;j>i;j--){
      if(b[j]>b[j-1]){
	tmp=b[j];
	b[j]=b[j-1];
	b[j-1]=tmp;
      }
    }
  }
  printf("%d %d\n",a[0]+a[1]+a[2],b[0]+b[1]+b[2]);
  return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep_lr(i,l,r) for(int i=(l);i<(r);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<int, int, int> T;
constexpr int INF = INT_MAX >> 1;
constexpr ll LINF = 5000000000000000LL;
constexpr int MOD = 1000000007;

int main() {

	int n;
	cin >> n;
	ll mx0 = -LINF, mn0 = LINF;
	ll mx1 = -LINF, mn1 = LINF;
	
	rep(i, n) {
		ll a, b;
		cin >> a >> b;
		mx0 = max(mx0,a - b);
		mx1 = max(mx1,a + b);
		mn0 = min(mn0,a - b);
		mn1 = min(mn1,a + b);
	}
	
	cout << max(mx0 - mn0, mx1 - mn1) << endl;

}

Measured memory_bytes: 3624
#include <stdio.h>
#include <math.h>


int isPrime(int x)
{
	int i;
	
	if(x == 2){						//２は素数
		return 1;
	}

	if(x < 2 || x % 2 == 0){		//2以下と2以外の偶数は素数ではない
		return 0;
	}

	for(i = 3; i <= sqrt(x); i++){	//平方根を使って半分が割れるか調べれば十分
		if( x % i == 0){
			return 0;
		}
	}
	
	return 1;
}

int main(void)
{
  int n, x, count = 0, i;

  scanf("%d", &n);

  for(i = 0; i < n; i++){
    scanf("%d", &x);
  	count+=isPrime(x);
  }

	printf("%d\n", count);

  return 0;
}



Measured memory_bytes: 2044
<?php
//error_reporting(0);
$S = trim(fgets(STDIN));
//list($A,$B,$M) = explode(" ",trim(fgets(STDIN)));
//$a = array_map('intval',explode(" ",trim(fgets(STDIN))));

$a=explode(",","1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51");

printf("%d\n",$a[$S-1]);


Measured memory_bytes: 4856
n=input()
s=input()

cnt=0
for i in range(0,1000):
  pos=0
  t="{0:03d}".format(i)
  for j in range(int(n)):
    if s[j] == t[pos]:
      pos+=1
    if pos == 3:
      cnt+=1
      break

print(cnt)

Measured memory_bytes: 41052
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long n,x,a[105],ans=0;
    cin>>n>>x;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    for(int i=0;i<n;i++){
        if(x>a[i] && i!=n-1){
            ans++;
            x-=a[i];
        }
        else if(a[i]==x){
            ans++;
            x-=a[i];
        }
    }
    cout<<ans<<endl;
    return(0);
}

Measured memory_bytes: 3616