akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

//vector string deque break continue
#define forn(i, s, f) for (int i = (int)s; i < (int)f; i++)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define fs first
#define sc second
#define pf push_front
#define pb push_back
#define pop_f pop_front
#define pop_b pop_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()

template <typename T> istream& operator>>(istream& in, vector <T>& a) {for (auto& i : a) in >> i; return in;}
template <typename T> ostream& operator<<(ostream& out, vector <T>& a)  {for (auto& i : a) out << i << " "; return out;}
template <typename T, typename U> void chkmin(T& a, U b) {if (a > b) a = b;}
template <typename T, typename U> void chkmax(T& a, U b) {if (a < b) a = b;}

vector <int> a;

void compress() {
    vector <int> b = a;
    sort(all(b)), b.erase(unique(all(b)), b.end());
    map <int, int> mp;
    forn (i, 0, sz(b))
        mp[b[i]] = i;
    forn (i, 0, sz(a))
        a[i] = mp[a[i]];
}

vector <vector <int>> gr;

template <typename T>
class Segtree {
private:
    int n;
    vector <T> tr;
    T neutral_tr = 0;

    T merge(T a, T b) {
        return max(a, b);
    }

    template <typename U>
    void build(const vector <U>& a) {
        forn (i, 0, n) 
            tr[i + n] = a[i];
        for (int i = n - 1; i > 0; i--)
            tr[i] = merge(tr[2 * i], tr[2 * i + 1]);
    }
public:
    template <typename U>
    Segtree(const vector <U>& a) : n(sz(a)) {
        tr.resize(2 * n, neutral_tr);
        build(a);
    }

    Segtree(int _n = 0) : n(_n) {
        tr.resize(2 * n, neutral_tr);
    }

    T get(int l, int r) {
        T ans = neutral_tr;
        for (l += n, r += n; l < r; l /= 2, r /= 2) {
            if (l % 2)
                ans = merge(ans, tr[l++]);
            if (r % 2)
                ans = merge(ans, tr[--r]);
        }
        return ans;
    }
    
    void upd(int i, int x) {
        for (i += n, tr[i] = x; i /= 2; i > 0)
            tr[i] = merge(tr[2 * i], tr[2 * i + 1]);
    }
};

vector <int> ans;
Segtree <int> tr;

void dfs(int v, int p = -1) {
    /*cout << v << ": ";
    forn (i, 0, sz(a))
        cout << tr.get(i, i + 1) << " ";
    cout << "\n";*/
    int prev = tr.get(a[v], a[v] + 1);
    tr.upd(a[v], tr.get(0, a[v]) + 1);
    ans[v] = tr.get(0, sz(a));
    for (int u : gr[v])
        if (u != p)
            dfs(u, v);
    tr.upd(a[v], prev);
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n;
    cin >> n;
    a.resize(n);
    cin >> a;
    compress();
    gr.resize(n);
    forn (i, 1, n) {
        int v, u;
        cin >> v >> u, --v, --u;
        gr[v].pb(u), gr[u].pb(v);
    }
    tr = Segtree <int> (n);
    ans.resize(n);
    dfs(0);
    forn (i, 0, n)
        cout << ans[i] << "\n";
    return 0;
}

Measured memory_bytes: 28560
/* AOJ 0066
 *
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0066
 *
 */

#include <stdio.h>


#define DEBUG 0
#define true 1
#define false 0

#define DRAW 'd'
#define OWON 'o'
#define XWON 'x'



int row(int r, char c, char* buf){
    int i;
    for(i=0;i<3;i++){
        if(buf[3*r+i] != c){
            return false;
        }
    }
    return true;
}

int col(int co, char c, char* buf){
    int i;
    for(i=0;i<3;i++){
        if(buf[co+i*3] != c){
            return false;
        }
    }
    return true;
}

int diagonalA(char c, char* buf){
    return ((buf[0]==c)
    && (buf[4]==c)
    && (buf[8]==c));
}

int diagonalB(char c, char* buf){
    return ((buf[2]==c)
    && (buf[4]==c)
    && (buf[6]==c));
}

char judge(char* buf){
    int i;
    for(i=0;i<3;i++){
        if(row(i, 'x', buf))
            return XWON;
        if(col(i, 'x', buf))
            return XWON;
    }
    if(diagonalA('x', buf))
        return XWON;
    if(diagonalB('x', buf))
        return XWON;

    for(i=0;i<3;i++){
        if(row(i, 'o', buf))
            return OWON;
        if(col(i, 'o', buf))
            return OWON;
    }
    if(diagonalA('o', buf))
        return OWON;
    if(diagonalB('o', buf))
        return OWON;

    return DRAW;
}




int main(){
    char buf[10];

    while(scanf("%s", buf)==1){
        if(DEBUG)
            printf("%s\n", buf);

        printf("%c\n", judge(buf));
    }

    return 0;
}

Measured memory_bytes: 0
N = int(input())
A = list(map(int, input().split()))#リスト

cou = 0
ans = 0
for i in A:   
    if i % 2 == 0:
        cou += 1
        if i % 3 == 0 or i % 5 == 0:
            ans += 1

if cou == ans:
    print("APPROVED")
else:
    print("DENIED")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ui unsigned int
#define ll long long
#define db double
#define ld long double
#define ull unsigned long long
#define ft first
#define sd second
#define pb(a) push_back(a)
#define PII std::pair<int,int>
#define PLL std::pair<ll,ll>
#define mp(a,b) std::make_pair(a,b)
#define ITR(a,b) for(auto a:b)
#define REP(a,b,c) for(register int a=(b),a##end=(c);a<=a##end;++a)
#define DEP(a,b,c) for(register int a=(b),a##end=(c);a>=a##end;--a)
const int MAXN=2000000+10,inf=0x3f3f3f3f,Mod=1e9+7;
int n,m;
ll f[MAXN];
struct node{
	int x,v,id;
	inline bool operator < (const node &A) const {
		return x<A.x;
	};
};
node p[MAXN];
struct inter{
	int l,r;
	inline bool operator < (const inter &A) const {
		return r<A.r||(r==A.r&&l<A.l);
	};
};
inter line[MAXN];
template<typename T> inline void read(T &x)
{
	T data=0,w=1;
	char ch=0;
	while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
	if(ch=='-')w=-1,ch=getchar();
	while(ch>='0'&&ch<='9')data=((T)data<<3)+((T)data<<1)+(ch^'0'),ch=getchar();
	x=data*w;
}
template<typename T> inline void write(T x,char ch='\0')
{
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);
	putchar(x%10+'0');
	if(ch!='\0')putchar(ch);
}
template<typename T> inline bool chkmin(T &x,T y){return y<x?(x=y,true):false;}
template<typename T> inline bool chkmax(T &x,T y){return y>x?(x=y,true):false;}
template<typename T> inline T min(T x,T y){return x<y?x:y;}
template<typename T> inline T max(T x,T y){return x>y?x:y;}
inline bool cmp(node a,node b)
{
	return a.v<b.v;
}
inline void init()
{
	std::sort(p+1,p+n+1,cmp);
	REP(i,1,n)p[i].id=i;
	std::sort(p+1,p+n+1);
	int mx=0,mn=inf,ps;
	REP(i,1,n)
	{
		if(chkmax(mx,p[i].v))ps=p[i].id;
		line[i].r=ps;
	}
	DEP(i,n,1)
	{
		if(chkmin(mn,p[i].v))ps=p[i].id;
		line[i].l=ps;
	}
	std::sort(line+1,line+n+1);
}
int main()
{
	read(n);
	REP(i,1,n)read(p[i].x),read(p[i].v);
	init(),f[0]=1;
	int j=1;
	REP(i,1,n)
	{
		f[i]=f[i-1];
		while(j<=n&&line[j].r==i)
			f[i]=(f[i]+f[i]-(line[j].l>1?f[line[j].l-2]:0)+Mod)%Mod,++j;
	}
	write((f[n]-f[n-1]+Mod)%Mod,'\n');
	return 0;
}


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

int main(){
	ios::sync_with_stdio(0);
	long long n,m,ans=0,summ=0;
	cin>>n>>m;
	vector<long long> a1,a2,b1,b2,c1,c2,sum;
	for(long long i=0;i<n;i++){
		long long a,b,c;
		cin>>a>>b>>c;
		a1.push_back(a);
		b1.push_back(b);
		c1.push_back(c);
		a2.push_back(-a);
		b2.push_back(-b);
		c2.push_back(-c);
		sum.push_back(0);
	}
	for(int i=0;i<2;i++){
		vector<long long> a;
		if(i)a=a2;
		else a=a1;
		for(int j=0;j<2;j++){
			vector<long long> b;
			if(j) b=b2;
			else b=b1;
			for(int k=0;k<2;k++){
				vector<long long>c;
				if(k)c=c2;
				else c=c1;
				for(int l=0;l<n;++l){
					sum[l]=a[l]+b[l]+c[l];
				}
				sort(sum.begin(),sum.end());
				summ=0;
				for(int i=0;i<m;i++)summ+=sum[n-1-i];
				ans=max(ans,summ);
			}
		}
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ll long long
using namespace std;
string s, t, ans;
int n, m, pd[3001][3001], lin[3001][3001], col[3001][3001];
int main()
{
    cin>>s;
    cin>>t;
    n=s.size()-1;
    m=t.size()-1;
    for(int i=0; i<=n; i++)
        for(int j=0; j<=m; j++)
            if(s[i]==t[j])
                pd[i][j]=(i && j) * pd[i-1][j-1]+1, lin[i][j]=i-1, col[i][j]=j-1;
            else
                {
                    lin[i][j]=i-1;
                    col[i][j]=j;
                    pd[i][j]=(i>0) * pd[i-1][j];
                    if((j>0) * pd[i][j-1]>pd[i][j])
                        pd[i][j]=(j>0) * (pd[i][j-1]), lin[i][j]=i, col[i][j]=j-1;
                }
    int i=n;
    int j=m;
    while(i>=0)
    {
        if(lin[i][j]==i-1 && col[i][j]==j-1)
        {
            ans.push_back(s[i]);
            i--;
            j--;
        }
        else if(col[i][j]==j-1)
            j--;
        else
            i--;
    }
    for(int i=ans.size()-1; i>=0; i--)
        cout<<ans[i];
    return 0;
}


Measured memory_bytes: 105856
#include <iostream>

int main()
{
	int N, M = 0;

	std::cin >> N >> M;

	int answer = 0;
	for (int i = 1; i < N; ++i)
	{
		answer += i;
	}
	for (int i = 1; i < M; ++i)
	{
		answer += i;
	}

	std::cout << answer << std::endl;


	return 0;
}

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

int main(){
    int n,d,x,y=0;cin>>n>>d>>x;y=x;
    for(int i=0;i<n;i++){
        int z;cin>>z;
        y+=(d-1)/z+1;
    }
    cout<<y<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isIn(x,y,h,w) (x >= 0 && x < h && y >= 0 && y < w)

#define int long long
//using ll = long long;
using P = pair<int,int>;

ostream &operator<<(ostream &os,const P &p){ return os << "(" << p.first << "," << p.second << ")"; }

template<class T> T &chmin(T &a,const T &b){ return a = min(a,b); }
template<class T> T &chmax(T &a,const T &b){ return a = max(a,b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	int n,l[1010];
	char d[1010];
	cin >> n;
	for(int i = 1;i <= n;i++) cin >> d[i] >> l[i];
	d[0] = d[n + 1] = 'n';
	l[0] = l[n + 1] = INF;
	vector<P> vec;
	for(int i = 1;i <= n;i++){
		if(d[i] == 'y') vec.emplace_back(l[i],i);
	}
	sort(all(vec));
	bool used[1010] = {};
	int ans = 0;
	for(P p : vec){
		int v = p.second;
		if(used[v]) continue;
		int x = v - 1,y = v + 1;
		while(d[x] == 'y' || l[v] > l[x]) x--;
		while(d[y] == 'y' || l[v] > l[y]) y++;
		for(int j = x + 1;j <= y - 1;j++) used[j] = true;
		ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3144
K=int(input())
L=len(input())
from numba import*
@njit(cache=1)
def f():
    m=10**9+7
    max_n=2*10**6
    fac=[1]*(max_n+1)
    inv=[1]*(max_n+1)
    ifac=[1]*(max_n+1)
    for n in range(2,max_n+1):
        fac[n]=(fac[n-1]*n)%m
        inv[n]=m-inv[m%n]*(m//n)%m
        ifac[n]=(ifac[n-1]*inv[n])%m
    d=[1]*(K+1)
    d2=[1]*(K+1)
    for i in range(K):
        d[i+1]=d[i]*25%m
        d2[i+1]=d2[i]*26%m
    a=0
    for i in range(K+1):
        a=(a+fac[L+i-1]*ifac[i]%m*ifac[L-1]%m*d[i]%m*d2[K-i]%m)%m
    return a
print(f())

Measured memory_bytes: 169568
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int q = sc.nextInt();
		Set<Integer> set = new HashSet<>(q);
		int count = 0;  //setの要素数

		for(int i = 0; i < q; i++) {
			int query = sc.nextInt();
			int x = sc.nextInt();

			if(query == 0) {
				if(set.add(x)) count++;
				System.out.println(count);
			}
			else if(query == 1) {
				if(set.contains(x)) System.out.println(1);
				else System.out.println(0);
			}
			else {
				if(set.remove(x)) count--;
			}
		}
	}

}



Measured memory_bytes: 160652
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
signed main(){
  int N,Q; cin>>N>>Q;
  vii A(N);
  rep(_,0,N-1){
    int X,Y; cin>>X>>Y;
    A[X-1].push_back(Y-1);
    A[Y-1].push_back(X-1);
    }
  vi plus(N);
  rep(i,0,Q){
    int X,Y; cin>>X>>Y;
    plus[X-1]+=Y;
    }
  vi ans(N,-1);
  queue<int> q;
  q.push(0);
  while(q.size()>0){
    int K=q.front();
    q.pop();
    ans[K]=plus[K];
    rep(i,0,A[K].size()){
      if(ans[A[K][i]]==-1)
        q.push(A[K][i]);
      else
        ans[K]+=ans[A[K][i]];
      }
    }
  rep(i,0,N) cout<<ans[i]<<" ";
  cout<<endl;
  }


Measured memory_bytes: 19440
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<queue>
#include<map>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef pair<int,int> P;

const int dy[4] = {-1,0,1,0};
const int dx[4] = {0,-1,0,1};

int main(){
    int h,w;
    cin >> h >> w;
    vector<string> board(h);
    rep(i,h) cin >> board[i];

    int ans=0;

    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(board[i][j]=='#') continue;
            vector<vector<int> > dist(h,vector<int>(w, -1));
            queue<P> que;

            int sy=i,sx=j;
            dist[sy][sx]=0;
            que.push(make_pair(sy,sx));

            while(!que.empty()){
                P current_pos=que.front();
                int y=current_pos.first;
                int x=current_pos.second;
                que.pop();
                for(int i=0;i<4;i++){
                    int ny = y+dy[i];
                    int nx = x+dx[i];
                    if(ny<0 || ny>=h || nx<0 || nx>=w) continue;
                    if(board[ny][nx]=='#') continue;
                    if(dist[ny][nx]!=-1) continue;
                    dist[ny][nx] = dist[y][x]+1;
                    que.push(make_pair(ny,nx));
                }
            }

            for(int k=0;k<h;k++){
                for(int l=0;l<w;l++){
                    ans = max(ans,dist[k][l]);
                }
            }
        }
    }

    cout << ans << endl;

}

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

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  int64_t n, m;
  std::cin >> n >> m;
  std::vector<int64_t> s(n), t(m);
  std::cin >> s >> t;

  std::vector<std::set<int64_t>> p(n);
  for (int64_t i = 0; i < n; i++) {
    for (int64_t j = 0; j < m; j++) {
      if (s[i] == t[j]) {
        p[i].insert(j);
      }
    }
  }

  std::vector<int64_t> ans(m, 0), ans_sum(m + 1, 1);

  constexpr int64_t mod = 1000000007;
  for (int64_t i = 0; i < n; i++) {
    for (const auto j : p[i]) {
      ans[j] += ans_sum[j];
      ans[j] %= mod;
    }
    ans_sum[0] = 1;
    for (int64_t k = 1; k <= m; k++) {
      ans_sum[k] = ans_sum[k - 1] + ans[k - 1];
      ans_sum[k] %= mod;
    }
  }

  std::cout << ans_sum.back() << std::endl;
  return 0;
}


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

int main(void){
    long int a = 100;
    long int X;
    long int i = 0;

    cin >> X;

    while(1){
        a *= 1.01;
        i++;
        if(a >= X){
            break;
        }

    }

    cout << i << endl;


}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
const int N=100005;
int n,k,r,s,p,win[N],ans;
string a;
int main()
{
	scanf("%d%d%d%d%d",&n,&k,&r,&s,&p);
	cin>>a;
	for(int i=0;i<n;i++)
	{
		if(i>=k&&a[i]==a[i-k]&&win[i-k])
			continue;
		if(a[i]=='r')
			ans+=p;
		if(a[i]=='s')
			ans+=r;
		if(a[i]=='p')
			ans+=s;
		win[i]=1;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define all(in) in.begin(), in.end()
#define FIO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef pair<int, int> PII;

int main(){
    FIO;
    ll n;
    cin >> n;
    ll start = 1, ans = 0;
    while(start <= n){
        ans += (min(start * 10, n+1) - start);
        start *= 100;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#define pb push_back 
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define INF (1<<30)
#define MOD 998244353
using namespace std;

int main() {
    int n;
    cin >> n;
    if (1000 <= n)cout << "ABD"<<endl;
    else
    {
        cout << "ABC" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
frac = [1]
p = 10**9 + 7
for i in range(max(n, m)):
    frac.append(frac[i]*(i+1)%p)

#フェルマーの小定理を用いてcombの計算を行う
def comb(n, k, mod):
    a=frac[n]
    b=frac[k]
    c=frac[n-k]
    return (a * pow(b, mod-2, mod) * pow(c, mod-2, mod)) % mod
if n >= 2:
  a = comb(n, 2, p)
else:
  a = 0
if m >= 2:
  b = comb(m, 2, p)
else:
  b = 0
print(a + b)

Measured memory_bytes: 3064
#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>
#include<complex>
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 = 4000001;
const long double eps = 1E-14;

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 fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b >> 1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

//////////////////////////////////////
vmint f, finv, inv;

void finit(ll N) {
	f.assign(N + 1, 1);
	finv.assign(N + 1, 1);
	inv.assign(N + 1, 1);
	inv[1] = 1;

	repn(i, N) {
		f[i] = f[i - 1] * i;
		if (i > 1)inv[i] = -inv[MOD % i] * (MOD / i);
		finv[i] = finv[i - 1] * inv[i];
	}
}

mint com(ll a, ll b) {
	if (a < 0 || b < 0 || a < b) { return 0; }
	return f[a] * finv[b] * finv[a - b];
}

int main() {
	ll N, M;
	cin >> N >> M;
	vmint hou(N + 1, 0);

	hou[N] = 1;
	for (ll i = N-1; i >= 0; i--) {
		hou[i] = hou[i + 1] * (M - i);
	}

	finit(N + 1);

	mint ans = 0;
	rep(i, N + 1) {
		mint c = com(N, i) * hou[i];

		//cout << hou[i] << endl;
		if (i % 2 == 0) { ans += c; }
		else { ans -= c; }
	}
	
	repn(i, N)ans *= (M - i + 1);

	cout << ans << endl;

}

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

int main() {
  int n,m;
  cin>>n;
  int t[n],i;
  for(i=0;i<n;i++)
    cin>>t[i];
  cin>>m;
  int p[m],x[m];
  for(i=0;i<m;i++)
    cin>>p[i]>>x[i];
  
  int ans;
  for(i=0;i<m;i++){
    ans=0;
    for(int j=0;j<n;j++){
      if(p[i]==j+1)
        ans+=x[i];
      else ans+=t[j];
    }
    cout<<ans<<endl;
  }
  
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    map<char, ll> m;
    string S;
    cin >> S;
    iter(c, S) {
        m[c]++;
    }
    if(m.size() == 2 && m.begin()->second == 2) cout << "Yes";
    else cout << "No";
    cout << endl;
    return 0;
}


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

map<char, char> win;

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

  ll ans = 0;
  int S = s.length();

  bool same = true;
  for (int i = 0; i < S; i++) {
    if (s[0] != s[i]) same = false;
  }
  if (same) {
    cout << S * k / 2 << endl;
    return 0;
  }

  s += "+-*/";
  for (int i = 0; i < S; i++) {
    if (s[i] == s[i + 1]) {
      auto j = i;
      while (s[j] == s[i]) j++;
      ans += (j - i) / 2;
      i = j - 1;
    }
  }
  ans *= k;

  int l(1), r(1);
  for (int i = 0; i < S - 1; i++) {
    if (s[i] != s[i + 1]) break;
    l++;
  }
  for (int i = S - 1; i > 0; i--) {
    if (s[i] != s[i - 1]) break;
    r++;
  }

  if (s[0] == s[S - 1] && ((r * l) % 2 != 0)) {
    ans += k - 1;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define ll          long long int
#define uu          first
#define vv          second
#define pii         pair<int,int>
#define pll         pair<ll,ll>
#define INF         1e9
#define fastRead    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;

const int MAX = 1e6 + 6;

int n;

int main()
{
    fastRead;
    int n;
    cin>>n;
    
    vector<ll>vec(n+1) ;
    ll ans = 0;
    for(int i = 0 ; i < n ; i++ ) {
        cin>>vec[i];
    }
    
    ll sum = 0;
    
    for(int i =0 ; i <=n ; i++ ) {
        
        if(vec[i] == 0 ) {
            ans += sum/2;
            sum = 0;
        }
        else sum += vec[i];
    }
    
    cout<<ans<<'\n';
    return 0;
    
}

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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,n) for(int i=1;i<=(int)(n);i++)
#define rep3(i,n) for(int i=0;i<=(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define repll(i,n) for(ll i=0;i<(ll)(n);i++)
#define repll2(i,n) for(ll i=1;i<=(ll)(n);i++)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define INF (int)1e9  //
#define LINF (ll)4e18  //
#define MOD (int)(1e9)+7
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define yes(n) cout << ((n) ? "yes" : "no"  ) << endl
#define PI 3.1415926535898

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

int main() {
    int n, k;
    cin >> n >> k;
    int a = 1;

    rep(i, n) {
        a = min(2 * a, a + k);
    }

    cout << a << endl;

    return 0;
}



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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> ac(n), pena(n);
  
  for(int i = 0; i < m; i++){
    int p;
    string s;
    cin >> p >> s;
    p--;
    if(ac.at(p)) continue;
    if(s == "AC"){
      ac.at(p) = 1;
    } else {
      pena.at(p)++;
    }
  }
  int AC = 0, PENA = 0;
  for(int i = 0; i < n; i++){
    AC += ac.at(i);
    if (ac.at(i)) PENA += pena.at(i);
  }
  printf("%d %d\n", AC, PENA);
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>
#include <bitset>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(ll)(n);++i)

long long ruijo(long long  k,long long m, ll mod){
	if(m==0)return 1;
	if(m==1)return k%mod;
	long long s = ruijo(k,m/2,mod);
	if(m%2==0){
		return (s*s)%mod;
	}else{
		long long ans;
		ans = (s*s)%mod;
		return (k*ans)%mod;
	}
}


int main(){
    map<pair<ll,ll>,ll>mp;
    ll n;
    cin >> n;
    string s;
    cin >> s;
    ll b[2]={4731,238973};
    ll m[2]={inf,998244353};
    ll inv[2]={ruijo(b[0],m[0]-2,m[0]),ruijo(b[1],m[1]-2,m[1])};
    ll x[2]={};
    ll q[2]={1,1};
    rep(i,n){
        rep(j,2){
            if(s[i]=='+'){
                x[j] += q[j];
                x[j] %= m[j];
            }else if(s[i]=='-'){
                x[j] += (m[j]-q[j]);
                x[j] %= m[j];
            }else if(s[i]=='>'){
                q[j] *=b[j];
                q[j] %=m[j];
            }else{
                q[j] *=inv[j];
                q[j] %=m[j];
            }
        }
        // cerr << x[0] << " " << x[1] << endl;
        mp[MP(x[0],x[1])]++;
    }
    ll ans = 0;
    ans += mp[MP(x[0],x[1])];
    //cerr << ans << endl;
    q[0] =1;
    q[1] =1;
    ll c[2]={0,0};
    ll d[2]={1,1};
    rep(i,n){
        rep(j,2){
            if(s[i]=='+'){
                c[j] += d[j];
                c[j] %= m[j];
            }else if(s[i]=='-'){
                c[j] += (m[j]-d[j]);
                c[j] %= m[j];
            }else if(s[i]=='>'){
                d[j] *=b[j];
                d[j] %=m[j];
            }else{
                d[j] *=inv[j];
                d[j] %=m[j];
            }
        }
        ll aaa = (x[0]*d[0]+c[0])%m[0];
        ll bbb = (x[1]*d[1]+c[1])%m[1];
        //cerr << aaa << " " << bbb << endl;
        mp[MP(c[0],c[1])]--;
        if(mp.find(MP(aaa,bbb))!=mp.end()){
            ans += mp[MP(aaa,bbb)];
        }
        
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 16132
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e9;
const ll INF = 1e18;
const ld EPS = 1e-10;

struct Union_Find_Tree{
    vector<int> par, rank, num;
    //要素数n(0〜n-1)の初期化されたUnion-Find木を構築
    Union_Find_Tree(int N){
        par.assign(N, -1);
        rank.assign(N, 0);
        num.assign(N, 1);
    }
    //ノードxの根を取得
    int root(int x){
        if(par[x] < 0 || par[x] == x) return x;
        return par[x] = root(par[x]);
    }
    //xとyの属する集合を併合
    void unite(int x, int y){
        x = root(x), y = root(y);
        if(x == y) return;
        elif(rank[x] < rank[y]) par[x] = y, num[y] += num[x];
        else{
            par[y] = x, num[x] += num[y];
            if(rank[x] == rank[y]) rank[x]++;
        }
    }
    //xの属する集合の要素数を取得
    int size(int x){
        return num[root(x)];
    }
    //xとyが同じ集合に属するか判定
    bool same(int x, int y){
        return root(x) == root(y);
    }
    //初期化する
    void clear(){
        fill(par.begin(), par.end(), -1);
        fill(rank.begin(), rank.end(), 0);
        fill(num.begin(), num.end(), 1);
    }
};

struct edge{int to, id;};

int main(){
    int N, M;
    cin >> N >> M;
    int D[N];
    rep(i, N) cin >> D[i];
    vector<edge> es[N];
    rep(i, M){
        int u, v; cin >> u >> v; u--, v--;
        es[u].emplace_back((edge){v, i});
        es[v].emplace_back((edge){u, i});
    }
    Union_Find_Tree uft(2*N);
    vector<int> cost(M, inf);
    vector<bool> used(N, false);
    rep(i, N){
        int m = inf;
        for(auto &e: es[i]){
            m = min(m, D[e.to]);
            if(D[e.to] == D[i]){
                used[i] = true;
                if(uft.same(i, e.to)) continue;
                else{
                    uft.unite(i, N+e.to), uft.unite(N+i, e.to);
                    cost[e.id] = D[e.to];
                }
            }
        }
        if(m > D[i]){
            cout << -1 << endl;
            return 0;
        }
    }
    rep(i, N){
        if(used[i]) continue;
        for(auto &e: es[i]){
            if(D[e.to] > D[i]) continue;
            else{
                if(uft.same(i, N+e.to)) continue;
                uft.unite(i, e.to), uft.unite(N+i, N+e.to);
                cost[e.id] = D[i]-D[e.to];
                break;
            }
        }
    }
    rep(i, N){
        for(auto &e: es[i]){
            if(!uft.same(i, N+e.to) && !uft.same(i, e.to)){
                uft.unite(i, e.to), uft.unite(N+i, N+e.to); 
            }
        }
    }
    rep(i, N){
        if(uft.same(0, i)) cout << 'B';
        else cout << 'W';
    }
    cout << endl;
    rep(i, M){
        cout << cost[i] << endl;
    }
}

Measured memory_bytes: 15232
import java.util.*;

class Main {
    static long powerMod(long x, long exponent) {
	long prod = 1;
	for (int i = 63; i >= 0; --i) {
	    prod = (prod * prod) % MOD;
	    if ((exponent & 1L << i) != 0) {
		prod = (prod * x) % MOD;
	    }
	}
	return prod;
    }
    static int f(int n, int k) {
        int t=0;
        for(int i=n;i>=1;--i){
            t+=(t+i)/i;
        }
        return t;
    }
    static final long MOD=1000000007;
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n=scan.nextInt();
        int k=scan.nextInt();
        int x=0;
        int l=f(n,k);
        long[][]dp=new long[n+1][l+1];
        for(int i=1;i<=n;++i){
            long m=powerMod(k+1,i-1);
            for(int u=0;u<=l;++u){
                long t=0;
                for(int j=0;j<=Math.min(i,k);++j)
                    if(u+(u+j)/i<=l){
                        t+=dp[i-1][u+(u+j)/i];
                        t+=((u+j)%i)*m%MOD;
                        t%=MOD;
                    }
                for(int j=Math.min(i,k)+1;j<=k;++j)
                    t=(t+dp[i-1][u]+(j+u)*m)%MOD;
                dp[i][u]=t;
            }
        }
        System.out.println(dp[n][0]);
    }
}


Measured memory_bytes: 24148
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	N := nextInt()
	A := make([]int, N)
	max1 := 0
	max2 := 0

	for i := 0; i < N; i++ {
		a := nextInt()
		A[i] = a

		if a >= max1 {
			max2 = max1
			max1 = a
		} else if a >= max2 {
			max2 = a
		}
	}

	for i := 0; i < N; i++ {
		if A[i] == max1 {
			fmt.Println(max2)
		} else {
			fmt.Println(max1)
		}
	}
}

var stdin = initStdin()

func min(n, m int) int {
	if n < m {
		return n
	}
	return m
}

func initStdin() *bufio.Scanner {
	bufsize := 1 * 1024 * 1024 // 1 MB
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Buffer(make([]byte, bufsize), bufsize)
	stdin.Split(bufio.ScanWords)
	return stdin
}

func nextString() string {
	stdin.Scan()
	return stdin.Text()
}

func nextBytes() []byte {
	stdin.Scan()
	return stdin.Bytes()
}

func nextInt() int {
	i, _ := strconv.Atoi(nextString())
	return i
}

func nextInt64() int64 {
	i, _ := strconv.ParseInt(nextString(), 10, 64)

	return i
}


Measured memory_bytes: 7700
/**
 *    Coded by : lucky_21
 *               --------Lokesh Singh
**/

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

#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define     F           first
#define     S           second
#define     pb          push_back
#define     lb          lower_bound
#define     ub          upper_bound
#define     pii         pair<int,int>
#define     all(x)      x.begin(),x.end()
#define     fix         fixed<<setprecision(10)
#define     rep(i,a,b)  for(int i=int(a);i<=int(b);i++)
#define     repb(i,b,a) for(int i=int(b);i>=int(a);i--)
#define     FastIO      ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)

typedef double d;
typedef long long ll;

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

signed main(){
    FastIO;
    int n,ans=0,minni=1e9;
    cin>>n;
    rep(i,1,n){
        int b;
        cin>>b;
        ans+=(b<=minni);
        minni=min(minni,b);
    }
    cout<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.ArrayList;
import java.util.List;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.nextLine();
    while (!(s.equals("."))) {
      //初期入力・処理
      List<Character> list = new ArrayList<Character>();
      boolean flag = true;

      //判別処理
      for (int i = 0; i < s.length(); i++) {
        char c = s.charAt(i);
        int r = list.size() - 1;
        if (c == '(' || c == '[') {
          list.add(c);
        } else if (c == ')' || c == ']') {
          if (r < 0) {// list長が0のとき
            flag = false;
            break;
          }
          if ((list.get(r) == '(' && c == ')') || (list.get(r) == '[' && c == ']')) {// 同じ括弧
            list.remove(r);
          } else if ((list.get(r) == '[' && c == ')') || (list.get(r) == '(' && c == ']')) {// 異なる括弧
            flag = false;
            break;
          }
        }
      }
      if (list.size() != 0) flag = false;

      //出力処理
      if (flag) {// バランスが成り立ってるか出力
        System.out.println("yes");
      } else {
        System.out.println("no");
      }

      s = sc.nextLine();
    }
  }
}



Measured memory_bytes: 45560
a,b,x=$<.read.split.map(&:to_f)

if a*a*b/2 < x
  c = 2*x/a/a - b
  rad = Math.atan((b-c)/a)
else
  c = a - 2*x/a/b
  rad = Math.atan(b/(a-c))
end
ret = rad * 180 / Math::PI
p ret


Measured memory_bytes: 1788
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int n = sc.nextInt();
			if(n==0)break;
			int sum = 0;
			for(int i=0;i<(n*(n-1)/2);i++) sum += sc.nextInt();
			System.out.println(sum/(n-1));
		}
	}	
}

Measured memory_bytes: 61920
s = input()
t = input()
ans = 'UNRESTORABLE'
for i in range(len(s)-len(t)+1):
    ok = True
    for j in range(len(t)):
        if s[i+j]!='?' and s[i+j]!=t[j]:
            ok = False
    if ok:
        ans = s[:i]+t+s[i+len(t):]
        ans = ans.replace('?','a')
print(ans)

Measured memory_bytes: 3060
import java.util.Arrays;
import java.util.BitSet;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] s = sc.next().toCharArray();
        int[] n = new int[s.length];
        for (int i = 0; i < s.length; i++) {
            n[i] = Character.digit(s[i], 10);
        }
        int N = n.length - 1;
        long ans = 0;
        for (int i = 0; i < Math.pow(2, N); i++) {
            long tmp = n[0];
            for (int j = 0; j < N; j++) {
                if ((i >> j & 1) == 1) {
                    ans += tmp;
                    tmp = 0;
                }
                tmp *= 10;
                tmp += n[j + 1];
            }
            ans += tmp;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 9424
#include<bits/stdc++.h>
using namespace std;
long long int   knap( int w, int n , vector<int> &weigh,vector<int>&value)
{
   long long int  dp[n+1][w+1];
 
   for(int i=0;i<=n;i++)
   {
    for(int j=0;j<=w;j++)
    {
      if(i==0 || j==0)
        dp[i][j]=0;
      else if(j-weigh[i-1]>=0)
      dp[i][j]=max(dp[i-1][j], dp[i-1][j-weigh[i-1]]+value[i-1]) ;
      else{
        dp[i][j]=dp[i-1][j];
      }
    }


   }

return dp[n][w];
}
int main(){
 int n,w;
 cin>>n>>w;
 vector<int> weigh(n); vector<int> value(n);
 for(int i=0;i<n;i++)
 {
  int x,y;
  cin>>x>>y;
  weigh[i]=x;
  value[i]=y;
 }
cout<<knap(w,n,weigh,value);
 


  return 0;
}

Measured memory_bytes: 79104
#include <iostream>
#include <vector>
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
using namespace std;

vector<vector<long long>> comb(int n, int r)
{
  vector<vector<long long>> v(n + 1, vector<long long>(n + 1, 0));
  for (int i = 0; i < v.size(); i++)
  {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int j = 1; j < v.size(); j++)
  {
    for (int k = 1; k < j; k++)
    {
      v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
    }
  }
  return v;
}

int main()
{
  vector<vector<long long>> v;
  vector<vector<long long>> v1;
  long long ans = 0;
  string n;
  int k;
  cin >> n;
  cin >> k;
  int num = n.length();
  int max = n[0] - '0';
  if (k == 1)
  {
    ans = (num - 1) * 9 + max;
  }
  else if (k == 2)
  {
    v = comb(num, k);
    ans = v[num][k] * 81 - 9 * (num - 1) * (9 - max);
    if (num > 1)
    {
      rep(i, 1, num)
      {
        int m = n[i] - '0';
        if (m == 0)
        {
          ans -= 9;
          continue;
        }
        ans -= (9 - m);
        break;
      }
    }
  }
  else
  {
    int count = 0;

    v = comb(num, k);
    v1 = comb(num - 1, k - 1);
    ans = v[num][k] * 729 - v1[num - 1][k - 1] * 81 * (9 - max);
    if (num > 2)
    {
      rep(i, 1, num)
      {
        int m = n[i] - '0';
        if (count == 0)
        {
          if (m == 0)
          {
            ans -= 9 * (num - i - 1) * 9;
            continue;
          }
          ans -= 9 * (num - i - 1) * (9 - m);
          ++count;
        }
        else
        {
          if (m == 0)
          {
            ans -= 9;
            continue;
          }
          ans -= (9 - m);
          break;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
    static final Scanner     sc = new Scanner(System.in);
    static final PrintStream so = System.out;
    
    public static void main(String[] args) {
        int n = ni();
        int x = ni();
        int d = 0;
        int count = 1;
        for (int i = 0; i < n; i++) {
            d += ni();
            if (d <= x) {
                count++;
            } else {
                break;
            }
        }
        so.println(count);
    }

    private static int ni() {
        return sc.nextInt();
    }

    private static long nl() {
        return sc.nextLong();
    }

    private static String ns() {
        return sc.next();
    }

    private static char[] nsToChars() {
        return sc.next().toCharArray();
    }

    private static long[] nlongs(int n) {
        return nlongs(n, 0);
    }

    private static long[] nlongs(int n, int padding) {
        long[] a = new long[padding + n];
        for (int i = 0; i < n; i++)
            a[padding + i] = ni();
        return a;
    }
}


Measured memory_bytes: 23892
a=[]

while True:
    n,k=map(int,input().split())
    
    if n==0 and k==0:
        break
    
    maxa=0
    suma=0
    
    for i in range(n):
        a.append(int(input()))
        if i<k:
            suma +=a[i]
        else:
            suma +=a[i]-a[i-k]
        if i>k-1 and maxa<suma:
            maxa=suma
            
    print(maxa)
    


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

int main() {
  int ptn;
  long long allPtn = 0;
  cin >> ptn;
  vector<long long> vec(ptn);
  vector<long long> cntNum(ptn);
  vector<long long> numPtn(ptn);
  
  // vecの中に値をセット
  for(int i = 0; i < ptn; i++){
   cin >> vec.at(i); 
  }
  
  // 同じ値の数求める
  for(int i = 0; i < ptn; i++){
    cntNum.at(vec.at(i)-1) += 1;
  }
  
  // 各値のパターンを求める
  long long n;
  for(int i = 0; i < ptn; i++){
    n = cntNum.at(i);
    numPtn.at(i) = (n * (n-1)) / 2;
    allPtn += numPtn.at(i);
  }
  
  // 1つ消去したパターンを求める    
  // 全体 - Aiの消去前 + Aiの消去後  ※消去前を引いて一旦なかったことにする
  long long aft;
  long long ans;
  for(int i = 0; i < ptn; i++){
    aft = cntNum.at(vec.at(i)-1) - 1;// Ai消去後
    ans = allPtn - numPtn.at(vec.at(i)-1) + (aft * (aft-1) / 2); // 全体 - Aiの消去前 + Aiの消去後
    cout << ans << endl;
  } 
}


Measured memory_bytes: 7296
from sys import stdin
N,A,B = [int(x) for x in stdin.readline().rstrip().split()]
S = stdin.readline().rstrip()
#print(N,A,B)
#print(S)
n=0 #予選通過者人数
n_f=0 #海外学生通過者人数
for i in S:
  if i == "a":
    if n < A+B:
      print("Yes")
      n+=1
    else:
      print("No")
    continue
    
  if i == "b":
    if n < A+B and n_f < B:
      print("Yes")
      n+=1
      n_f+=1
    else:
      print("No")
    continue
    
  if i =="c":
    print("No")

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

int main() {
  int N;
  cin >> N;
  
  int a = N % 10;
  int b = (N/10) % 10;
  int c = (N/100) % 10;
  int d = (N/1000) % 10;
  
  if(a == b && b == c){
    cout << "Yes" << endl;
  }
  
  else if( b == c && c == d ){
    cout << "Yes" << endl;
  }
  
  else{
    cout << "No" << endl;
  }
}
  


Measured memory_bytes: 256
object Main extends App {

  import scala.io.StdIn._
  import scala.math._

  val n = readLine.trim.toInt
  val numbers = readLine.trim.split(' ').map(_.toInt)
  val sorted = numbers.zipWithIndex.map{case (v, i) ⇒ ValueWithIndex(v, i)}.sorted
  val canMake = Array.tabulate(n){_ ⇒ 0}
  for (number ← numbers.distinct){
    val indices = (lowerBound(sorted, ValueWithIndex(number, 0)) until upperBound(sorted, ValueWithIndex(number, n))).map{i ⇒ sorted(i).index}
    for (k ← indices.indices){
      val left = indices(k) // (0 to left) にnumberがk
      val right = n - 1 - indices(indices.length - 1 - k) //(n - 1 - right until n) にnumberがk個含まれる最小インデックス
      if (right < left){
        canMake(right) -= 1
        canMake(left) += 1
      }else {
        canMake(left) -= 1
        canMake(right) += 1
      }
    }
  }
  for (i ← 1 until n){
    canMake(i) += canMake(i - 1)
  }
  println(
    canMake.zipWithIndex.filter{case (n, i) ⇒ n == 0}.map{case (_, i) ⇒ i + 1}.mkString(" ")
  )


  def lowerBound[T](array: Array[T], target: T)(implicit ordering: Ordering[T]): Int = {
    var left = 0
    var right = array.length
    while (left < right){
      val mid = (left + right) / 2
      if (ordering.compare(array(mid), target) < 0){
        left = mid + 1
      }else {
        right = mid
      }
    }
    right
  }
  def upperBound[T](array: Array[T], target: T)(implicit ordering: Ordering[T]): Int = {
    var left = 0
    var right = array.length
    while (left < right){
      val mid = (left + right) / 2
      if (ordering.compare(array(mid), target) <= 0){
        left = mid + 1
      }else {
        right = mid
      }
    }
    right
  }

  case class ValueWithIndex(value: Int, index: Int) extends Ordered[ValueWithIndex] {
    override def compare(that: ValueWithIndex): Int = if (value == that.value) index.compare(that.index) else value.compare(that.value)
  }

  implicit class Extension[T](val value :T){
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
    def let[R](func: T ⇒ R): R = func(value)
  }
}


Measured memory_bytes: 227136
n, k =  map(int,input().split())
a_list = list(map(int,input().split()))
total = sum(a_list)

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort(reverse=True)
    return divisors

div_list = make_divisors(total)
for div in div_list:
    b_list = [a%div for a in a_list]
    b_list.sort()
    change = sum(b_list[:(-sum(b_list)//div)])
    if change <=k:
        print(div)
        break

Measured memory_bytes: 3188
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String in[], bin[];
        int row, col, c, res, ret;
        in = scanner.nextLine().split(" ");
        row = Integer.parseInt(in[0]);
        col = Integer.parseInt(in[1]);
        c = Integer.parseInt(in[2]);

        bin = scanner.nextLine().split(" ");
        ret = 0;
        for (int i = 0; i < row; i++) {
            in = scanner.nextLine().split(" ");
            res = c;
            for (int j = 0; j < col; j++) {
                res += Integer.parseInt(in[j]) * Integer.parseInt(bin[j]);
            }
            if (res > 0) {
                ret++;
            }
        }
        System.out.println(ret);
    }
}

Measured memory_bytes: 23508