akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

const int mod = 1e9 + 7;

int N, K;
int R, S, P;
string T;

int len[100000];

int point(char ch) {
    if (ch == 'r')
        return P;
    else if (ch == 's')
        return R;
    else
        return S;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> N >> K;
    cin >> R >> S >> P;
    cin >> T;
    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (i < K) {
            len[i] = 1;
        } else {
            if (T[i] == T[i - K]) {
                len[i % K]++;
            } else {
                ans += point(T[i - K]) * ((len[i % K] + 1) / 2);
                len[i % K] = 1;
            }
        }
    }
    for (int i = N - K; i < N; i++) {
        ans += point(T[i]) * ((len[i % K] + 1) / 2);
    }
    cout << ans << endl;
}

Measured memory_bytes: 848
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long n,j;
    cin>>n;
    long long dp[n+1]={0};
    long long a[n+1];
    for(j=1;j<=n;j++){
        cin>>a[j];
    }dp[1]=0;dp[2]=abs(a[1]-a[2]);
    for(j=3;j<=n;j++){
        dp[j]=min(dp[j-2]+abs(a[j]-a[j-2]),dp[j-1]+abs(a[j]-a[j-1]));
    }cout<<dp[n];
    return 0;
}


Measured memory_bytes: 5132
N,W = map(int,input().split())
wv = [list(map(int,input().split())) for _ in range(N)]
w0 = wv[0][0]
weights = [wv[0][0],wv[0][0]+1,wv[0][0]+2,wv[0][0]+3]
wdict = {}
cnt = 0
for w in weights:
    wdict[w] = cnt
    cnt += 1
values = [[] for _ in range(4)]

for w,v in wv:
    values[wdict[w]].append(v)

sums = 0
for i in range(4):
    values[i].sort(reverse = True)
    sums += sum(values[i])
    
ruisekiwa = [[0]*(N+1) for _ in range(4)]
for i in range(4):
    ruisekiwa[i][0] = 0
    for j in range(1,len(values[i])+1):
        ruisekiwa[i][j] = ruisekiwa[i][j-1] + values[i][j-1] 
    
ans = 0
for i in range(len(values[0])+1):
    for j in range(len(values[1])+1):
        for k in range(len(values[2])+1):
            for l in range(len(values[3])+1):
                w_tmp = w0*i + (w0+1)*j + (w0+2)*k + (w0+3) * l

                if w_tmp <= W:
                    val = ruisekiwa[0][i] + ruisekiwa[1][j] + ruisekiwa[2][k] + ruisekiwa[3][l]
                    ans = max(ans,val)
                    
print(ans)
                
                    
                
    


Measured memory_bytes: 42092
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#define SIZE 100005
#define INF 100000000000000000LL;

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

ll A[SIZE];

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%lld",&A[i]);
	ll ret=INF;
	//はじめ正
	int f=1;
	ll sum=0,now=0;
	for(int i=0;i<n;i++)
	{
		sum+=A[i];
		if(f==1&&sum<=0)
		{
			now+=-sum+1LL;
			sum=1LL;
		}
		else if(f==-1&&sum>=0)
		{
			now+=sum+1LL;
			sum=-1LL;
		}
		f*=-1;
	}
	ret=min(ret,now);
	//はじめ負
	f=-1;
	sum=0,now=0;
	for(int i=0;i<n;i++)
	{
		sum+=A[i];
		if(f==1&&sum<=0)
		{
			now+=-sum+1LL;
			sum=1LL;
		}
		else if(f==-1&&sum>=0)
		{
			now+=sum+1LL;
			sum=-1LL;
		}
		f*=-1;
	}
	ret=min(ret,now);
	printf("%lld\n",ret);
	return 0;
}


Measured memory_bytes: 896
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <complex>

 
using namespace std;
 
#define INF 1000000000
#define EPS 1e-9
#define PI acos(-1)
 
typedef long long ll;
typedef complex<double> vec;

#define MAX_N 300
int N;
double x[MAX_N], y[MAX_N];
vector<int> ans_list;

int par[MAX_N];

int main(){

  while(true){
    cin >> N;
    if(N == 0)
      break;
    for(int i = 0; i < N; i++){
      cin >> x[i] >> y[i];
    }

    int ans = 0;

    for(int i = 0; i < N; i++){
      for(int j = i+1; j < N; j++){
	if(sqrt((x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j])) > 2.0001)
	  continue;
	int tmp = 0;
	vec p1 = vec(x[i], y[i]), p2 = vec(x[j], y[j]);
	vec mid = (p2-p1);
	mid /= 2;
	vec r1 = (mid * vec(0, 1)) / abs(mid);
	vec r2 = (mid * vec(0, -1)) / abs(mid);

	vec R = p1 + mid + r1*sqrt((1-abs(mid)*abs(mid)));
	double rx = R.real();
	double ry = R.imag();
	tmp = 2;
	for(int k = 0; k < N; k++){
	  if(k == i || k == j)
	    continue;
	  if((rx - x[k])*(rx-x[k]) + (ry - y[k])*(ry - y[k]) < 1)
	    tmp++;
	}
	ans = max(ans, tmp);
	R = p1 + mid + r2*sqrt((1-abs(mid)*abs(mid)));
	rx = R.real();
	ry = R.imag();
	tmp = 0;
	for(int k = 0; k < N; k++){
	  if(k == i || k == j)
	    continue;
	  if((rx - x[k])*(rx-x[k]) + (ry - y[k])*(ry - y[k]) < 1)
	    tmp++;
	}
	ans = max(ans, tmp);
      }
    }

    if(ans == 0 && N >= 1)
      ans_list.push_back(1);
    else
      ans_list.push_back(ans);
    
  }
  
  for(int i = 0; i < ans_list.size(); i++){
    cout << ans_list[i] << endl;
  }

  return 0;

}

Measured memory_bytes: 1284
# seishin.py
N, X, Y, Z = map(int, input().split())
m = 2**(X+Y+Z)
S = [0]*m

L = max(X, Y, Z)

ss = set()
tt = set()

Z0 = (1 << (Z-1))
Y0 = (1 << (Z+Y-1))
X0 = (1 << (X+Z+Y-1))

for i in range(m):
    if i & Z0 and i & Y0 and i & X0:
        ss.add(i)

MASK = 2**(X+Y+Z)-1
MOD = 10**9 + 7

S[0] = 1
for i in range(N):
    T = [0]*m
    for s in range(m):
        if s in ss:
            # XYZが成立
            continue
        b = (s << 1) | 1
        for k in range(1, L+1):
            t = (b << (k-1)) & MASK
            T[t] = (T[t] + S[s]) % MOD
        for k in range(L+1, 11):
            T[0] = (T[0] + S[s]) % MOD
    S = T
ans = 0
for s in range(m):
    if s in ss:
        continue
    ans = (ans + S[s]) % MOD
ans = (pow(10, N, MOD) + MOD - ans) % MOD
print(ans)

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

using namespace std;

int main() {
  int n;
  cin >> n;
  if(n % 10 == 3) cout << "bon" << endl;
  else if(n % 10 == 0 or n % 10 == 6 or n % 10 == 8 or n % 10 == 1) cout << "pon" << endl;
  else cout << "hon" << endl;
  return 0;
}

Measured memory_bytes: 3596
#include <iostream>

using namespace std;

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

    int apples[N];
    int minVal;
    int sum = 0;
    for(int i = 0; i < N; i++){
        apples[i] = L + i;
        if(i == 0){
            minVal = apples[0];
        }
        if(abs(minVal) > abs(apples[i])){
            minVal = apples[i];
        }
        sum += apples[i];
    }

    cout << sum - minVal << endl;

}

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

int main() {
	int n, x;
	cin >> n >> x;
	
	if (x == 1 || x == 2 * n - 1) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
		if (n == 2) {
			cout << 1 << endl << 2 << endl << 3 << endl;
		}
		else {
			static int val[200001] = {0};
			static bool used[200001] = {false};
			int i, j;
			
			//x + 2, x - 1, [x], x + 1, x - 2
			if (x + 2 <= 2 * n - 1) {
				val[n - 2] = x + 2; used[x + 2] = true;
			}
			else {
				val[n + 2] = x - 2; used[x - 2] = true;
			}
			val[n - 1] = x - 1; used[x - 1] = true;
			val[n] = x; 		used[x] = true;
			val[n + 1] = x + 1; used[x + 1] = true;
			
			j = 1;
			for (i = 1; i <= 2 * n - 1; i++) {
				if (val[i] != 0) { continue; }
				for (; used[j]; j++);
				val[i] = j;
				used[j] = true;
			}
			
			for (i = 1; i <= 2 * n - 1; i++) {
				cout << val[i] << endl;
			}
		}
	}
	return 0;
}

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

using namespace std;
using ll = long long;

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

const int MAX_N = 301;
const ll INF = 3e9;
ll dist[MAX_N][MAX_N];

int main(){
    int n;
    cin >> n;
    ll a[MAX_N][MAX_N];
    rep(i,n){
        rep(j,n){
            cin >> a[i][j];
        }
    }


    rep(i,n){
        rep(j,n){
            rep(k,n){
                if(a[i][k] + a[k][j] < a[i][j]){
                    cout << -1 << endl;
                    return 0;
                }
            }
        }
    }

    ll ans = 0;
    bool flag = false;
    rep(i,n){
        rep(j,n){
            flag = false;
            rep(k,n){
                if(a[i][k] + a[k][j] == a[i][j] && i != j && i != k && j != k){
                    flag = true;
                }
            }
            if(!flag){
                ans += (a[i][j]);
            }
        }
    }


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

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

int a[100005];
int main() {
	int k;
	string s; cin>>s;
	int n=s.size();
	for (int i=0; i<n; i++)
		if(s[i]=='R') k=i;
		else a[k+(i-k)%2]++;
	for (int i=n-1; i>=0; i--)
		if(s[i]=='L') k=i;
		else a[k-(k-i)%2]++;
	for (int i=0; i<n; i++)
		printf("%d ", a[i]);
	cout<<"\n";
	return 0;
}

Measured memory_bytes: 1024
import sys
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

SA,SB,SC = LS2(),LS2(),LS2()
a,b,c = 0,0,0
turn = 'a'
while a <= len(SA) and b <= len(SB) and c <= len(SC):
    if turn == 'a':
        if a == len(SA):
            print('A')
            break
        else:
            turn = SA[a]
            a += 1
    elif turn == 'b':
        if b == len(SB):
            print('B')
            break
        else:
            turn = SB[b]
            b += 1
    else:
        if c == len(SC):
            print('C')
            break
        else:
            turn = SC[c]
            c += 1


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

int main()
{
	int H, W;
	bool f, res = true;
	int tmp = 0, g;
	cin >> H >> W;
	vector<vector<char>> A(H, vector<char>(W));
	for (int i = 0; i < H;i++) {
		f = true, g = -1;
		for (int j = 0; j < W;j++) {
			cin >> A[i][j];
			if (A[i][j] == '#') {
				if (g == 1)
					res = false;
				else
					g = 0;
				if (f) {
					if (tmp > j)
						res = false;
					else
						tmp = j;
				}
				else {
					res = false;
				}
			}
			else {
				if (g == 0) {
					f = false;
					g = 1;
				}
			}
		}
	}
	cout << (res ? "Possible" : "Impossible") << endl;
	return 0;
}


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

int main() {
  int n; cin >> n;
  int lo = n + 1, ans = 0;
  for (int i = 0; i < n; i++) {
    int x; cin >> x;
    lo = min(lo, x);
    if (lo >= x) ans++;
  }
  cout << ans << endl;
  return 0;
}

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

int main()
{
	int A,B,C,D,E,F;
	cin >> A >> B >> C >> D >> E >> F;

	for (int i = 0; 100 * A * i <= F; ++i)
	{
		for (int j = 0; 100 * B * j <= F; ++j)
		{
			w[100*(A*i+B*j)] = true;
		}
	}
	for (int i = 0; C * i <= F; ++i)
	{
		for (int j = 0; D* j <= F; ++j)
		{
			s[C*i+D*j] = true;
		}
	}
	double ans = 0.0;
	int answ = A*100, anss = 0;
	for (int i = 0; i <= F; i+=100)
	{
		for (int j = 0; j <= F; ++j)
		{
			if (i == 0 && j == 0) continue;
			if (w[i] && s[j] && j<=i/100*E && i+j<=F)
			{
				if (double(j) / double(i) > ans)
				{
					ans = double(j) / double(i);
					answ = i; anss = j;
				}
			}
		}
	}
	cout << answ+anss << " " << anss << endl;
	return 0;
}

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

ans = 0
if X == 3:
    ans += 100000
if X == 2:
    ans += 200000
if X == 1:
    ans += 300000
if Y == 3:
    ans += 100000
if Y == 2:
    ans += 200000
if Y == 1:
    ans += 300000
if X ==1 and Y == 1:
    ans += 400000

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<ll,ll> P;
typedef pair<ll,ll> Pll;
//小数点以下　cout << fixed << setprecision(10) << num << endl;
//桁数はlog10(mid)でやれ　log(mid)/log(10)はWA
//long*long<0で判定するな
//開区間と閉区間
//アルファベットが何番目かは x=s[i]-'a'
//bfsはmain()内で　rep(i,h)rep(j,w)rep(i,4)でバグ
//切り上げ：(a+(b-1))/b
//32bit以上は 1ull<<j
// map 初期値0 for(auto itr=mp.begin();itr!=mp.end();++itr) itr->fi itr->se で全探索
// for(auto u:mp) u.fi u.se も可能
//n個のgcd,lcmは一つずつみて更新していく
//大きな数を扱うときは素因数分解した形で持っておく
// (l/a[i]) = l*powmod(a[i],MOD-2)%MOD;
//auto itr=lower_bound(ALL(a),key) a[itr-a.begin()]

int main(){
    int n,z,w; cin >> n >> z >> w;
    if(n==1){
        int a; cin >> a;
        cout << abs(a-w) << endl;
        return 0;
    }
    int b,c;
    rep(i,n){
        int a; cin >> a;
        if(i==n-2) b=a;
        if(i==n-1) c=a;
    }
    cout << max(abs(c-w),abs(c-b)) << endl;
    
}


Measured memory_bytes: 256
import java.util.*;
import java .io.*;
public class Main {
    static int size;
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st;
        st = new StringTokenizer(br.readLine());
        int n = Integer.parseInt(st.nextToken());
        int array[] = new int[n + 1];
        st = new StringTokenizer(br.readLine());
        for (int i = 1; i <= n; i++) {
            array[i] = Integer.parseInt(st.nextToken());
        }
        st = new StringTokenizer(br.readLine());
        int cnt[] = new int[n + 2];
        for(int i = 1;i <= n;i++){
            cnt[i] = Integer.parseInt(st.nextToken());
        }
        boolean mark[] = new boolean[n + 1];
        mark[1] = true;
        for(int i = 2;i <= n;i++)
            if(array[i] > array[i - 1])mark[i] = true;

        for(int i = n;i >= 1;i--) {
            //System.out.println(i + " " + mark[i] + " " + cnt[i] + " " + array[i]);
            if(mark[i]){
                if(cnt[i] < array[i]){
                    System.out.print("0");
                    return;
                }
            }
            if (cnt[i] > cnt[i + 1]) {
                //System.out.println("1");
                mark[i] = true;
                if(array[i] < cnt[i]){
                    System.out.print("0");
                    return;
                }
            }
        }
        long ans = 1;
        int mod = 1000_000_000 + 7;
        for(int i = 1;i <= n;i++){
            if(mark[i])continue;
            ans *= Math.min(cnt[i],array[i]);
            ans %= mod;
        }
        System.out.print(ans);
    }
}

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

int main() {
    ll n, a, b;
    while  (cin >> n >> a >> b) {
        if ((a ^ b) % 2 == 0) {
            cout << abs(a - b) / 2 << '\n';
        }
        else {
            ll g1 = min(a, b);
            ll left = abs(a - b) / 2;
            ll g2 = min(n - a + 1, n - b + 1);
            cout << min(g1, g2) + left << '\n';
        }
    }
}

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

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

typedef long long ll;

const int mod = 1e9 + 7;

using namespace std;


int main(void) {
	ll K; cin >> K;

	ll n = 1;
	ll S = 7%K;
	ll d = 7%K;

	auto start = clock();

	while (S % K != 0) {
		n++;
		d = (d * 10) % K;
		S = (S + d) % K;

		if (((double)clock() - (double)start) / (double)CLOCKS_PER_SEC >= 1.9) {
			cout << -1 << endl;
			return 0;
		}
	}

	cout << n << endl;

	return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int N,P;
    cin >> N >> P;
    int g=0,k=0;
    int a[N];
    rep(i,N){
        cin >> a[i];
        if(a[i]%2==0) g++;
        else k++;
    }
    long long ans=1;
    if(k<1 && P==1) ans=0;
    else if(k<1 && P==0) ans=2;

    rep(i,N-1){
        ans*=2;
    }

    cout << ans << endl;



}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define ll long long

using namespace std;

ll dp[105][105];
vector<pair<ll,ll> >v;


ll mcm(int left,int right)
{

    if(left>=right) return 0;
    if(dp[left][right]!=INT_MAX) return dp[left][right];
//cout<<"ok"<<endl;
    ll ans=INT_MAX;

    for(int i=left;i<right;i++)
    {
        ll res_left= mcm(left,i);
        ll res_right= mcm(i+1,right);
        ll res=v[left].first*v[i].second*v[right].second;
        ans=min(ans, res+res_left+res_right);
        //cout<<ans<<endl;
    }
    return dp[left][right]=ans;
}



int main()
{
    for(int i=0;i<104;i++) for(int j=0;j<104;j++) dp[i][j]=INT_MAX;

    int n,temp; cin>>n;
    temp=n;
    while(temp--)
    {
        int a,b; cin>>a>>b;
        v.pb({a,b});
    }

    cout<<mcm(0,n-1)<<endl;

}



Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
#define all(x) x.begin(), x.end()
using ll = long long;
using pii = pair<int, int>;
const int mod = 1e9+7;

int main() {
    ll x;
    cin >> x;
    ll ans;
    if (x % 11 == 0) {
        ans = x / 11 * 2;
    } else {
        if (x % 11 <= 6) {
            ans = x / 11 * 2 + 1;
        } else {
            ans = x / 11 * 2 + 2;
        }
    }
    cout << ans << endl;
}

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

int main() {
    int N, W; cin >> N >> W;
    vector<pair<int, int>> wv(N);
    REP(i, 0, N) cin >> wv[i].first >> wv[i].second;

    ll dp[N + 1][W + 1];
    REP(i, 0, W + 1) dp[0][i] = 0;

    REP(i, 0, N) {
        REP(j, 0, W + 1) {
            if (j >= wv[i].first) {
                dp[i + 1][j] = max(dp[i][j], dp[i][j - wv[i].first] + wv[i].second);
            } else {
                dp[i + 1][j] = dp[i][j];
            }
        }
    }
    cout << dp[N][W] << endl;
    return 0;
}

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

int main() {
  int a,b,k;
  vector<int> vec;
  cin >> a >> b >> k;
  for(int i = 1; i <= min(a,b); i++) {
    if(a%i == 0) {
      if(b%i == 0) vec.push_back(i);
    }
  }
  reverse(vec.begin(),vec.end());
  cout << vec[k-1] << endl;
}

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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

int main() {
    int A, B;
    cin >> A >> B;
    int c = 0;
    FOR(i, A, B + 1) {
        bool loop = true;
        REP(j, 3) {
            LL p = pow(10, j);
            LL q = pow(10, 4 - j);
            loop = loop && (i/p)%10 == (i/q)%10;
        }
        if(loop) {
            c++;
        }
    }
    cout << c << endl;
    return 0;
}


Measured memory_bytes: 512
#if loc||local
#define _GLIBCXX_DEBUG
#endif

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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = int_fast64_t;
using pll = pair<ll,ll>;
constexpr ll INF = 1LL<<60;
constexpr ll MOD = 1e9+7;
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
#if loc||local
template<class T>void dump(T&& t){cerr<<t<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
void dump(){}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T,class U> ostream &operator<<(ostream& os,pair<T,U>const& p){os<<p.first<<","<<p.second;return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}

signed main(){

  int n;
  cin>>n;
  cout<<(n>=30?"Yes":"No")<<endl;

}

Measured memory_bytes: 3544
class ModInt:
    def __init__(self, x, MOD):
        self.x = x % MOD
        self.m = MOD

    def __add__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x + other.x, self.m)
        else:
            return ModInt(self.x + other, self.m)

    __radd__ = __add__

    def __sub__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x - other.x, self.m)
        else:
            return ModInt(self.x - other, self.m)

    def __rsub__(self, other):
        if isinstance(other, ModInt):
            return ModInt(other.x - self.x, self.m)
        else:
            return ModInt(other - self.x, self.m)

    def __pow__(self, other):
        if isinstance(other, ModInt):
            return ModInt(pow(self.x, other.x, self.m), self.m)
        else:
            ModInt(pow(self.x, other, self.m), self.m)

    def __rpow__(self, other):
        if isinstance(other, ModInt):
            return ModInt(pow(other.x, self.x, self.m), self.m)
        else:
            ModInt(pow(other, self.x, self.m), self.m)

N = int(input())
X = list(map(int, input()))
Xc = sum(X)

if Xc == 0:
    [print(1) for i in range(N)]
elif Xc == 1:
    ans1 = ModInt(0, Xc+1)
    for j in range(N):
        if X[j]:
            ans1 += pow(2,N-1-j,Xc+1)

    for j in range(N):
        if X[j]:
            print(0)
        else:
            print(2) if X[N-1] or j == N-1 else print(1)
else:
    ans1 = ModInt(0, Xc+1)
    ans2 = ModInt(0, Xc-1)
    for j in range(N):
        if X[j]:
            ans1 += pow(2,N-1-j,Xc+1)
            ans2 += pow(2,N-1-j,Xc-1)

    for i in range(N):
        if X[i]:# 1->0
            ans = ans2 - pow(2,N-1-i,Xc-1)
        else:# 0->1
            ans = ans1 + pow(2,N-1-i,Xc+1)
        count = 1
        while ans.x > 0:
            tmp = str(bin(ans.x)).count('1')
            ans.x %= tmp
            count += 1
        print(count)

Measured memory_bytes: 10972
#include <iostream>
#include <string> 
#include <algorithm>
#include <numeric>
#include <cmath>
using namespace std;
 
int main() {
 
	long res = 0;
    long N; cin >> N;
    long A[300000]; for(int i = 1; i <= N; i++) cin >> A[i] ;
    
    long S[300000];S[0] = 0; for(int i = 1; i <= N; i++) S[i] = S[i - 1] + A[i];
    
    sort(S, S + N + 1);
    
    long mys = 0 , mycount = 0;
 
	for (int i = 0; i <= N; i++) { //S[i]の等しい二つ組は何通りか
		if (S[i] == mys) mycount++; else { mys = S[i]; res += max((long)0,( mycount * (mycount - 1) / 2)); mycount = 1; }
 
        if(i == N){ mys = S[i]; res += max((long)0, mycount * (mycount - 1) / 2); mycount = 0; }
	}
    cout << res << endl;
}

Measured memory_bytes: 4864
#include <stdio.h>

int main(int argc, char *argv[])
{
	int i, N, list[100000], v = 1, idx;
	scanf("%d", &N);
	for ( i = 0; i < N; i++ ){
		scanf("%d", &list[i]);
	}
	for ( i = 0; i < N; i++ ){
		idx = v - 1;
		if ( list[idx] == 0 ){
			printf("-1\n");
			return 0;
		}
		v = list[idx];
		if ( v == 2 ){
			printf("%d\n", i+1);
			return 0;
		}
		list[idx] = 0;
	}
	printf("-1\n");

	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n=200005;
int n,k,p[max_n];
bool vis[max_n];
int main(){
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)scanf("%d",p+i);
    for(int i=1;i<=n;i++){
        int j=i+1;
        while(j<=n&&p[j]>p[j-1])j++;
        for(int l=i;l+k-1<j;l++)vis[l]=true;
        i=j-1;
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        if(vis[i]){
            ans++;
            break;
        }
    }
    set<int> s;
    for(int i=1;i<=k;i++)s.insert(p[i]);
    for(int i=1;i+k-1<=n;i++){
        int j=i+1;
        if(!vis[i]){
            while(j+k-1<=n){
                s.erase(p[j-1]);
                int lx=*s.begin(),rx=*s.rbegin();
                s.insert(p[j+k-1]);
                if(p[j-1]<lx&&rx<p[j+k-1])j++;
                else{
                    s.insert(p[j-1]);
                    s.erase(p[j+k-1]);
                    break;
                }
            }
            ans++;
        }
        i=j-1;
        s.erase(p[i]);s.insert(p[i+k]);
    }
    printf("%d\n",ans);
    return 0;
}

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

int main() {
	int h, w;
	while (true) {
		cin >> h >> w;
		if (h == 0 && w == 0) break;

		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if ((i + j) % 2 == 0) cout << "#";
				else cout << ".";
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3076
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		String s=sc.next();
		int ans=1;
		char last=s.charAt(0);
		for(int i=1; i<N; i++) {
			if(last==s.charAt(i)) {
				//none
			}
			else {
				last=s.charAt(i);
				ans++;
			}
		}
		p(ans);
	}
	public static void p(Object o) {
		System.out.println(o);
	}
}

Measured memory_bytes: 24404
# -*- coding: utf-8 -*-

N = int(input())
sN = [int(input()) for i in range(N)]

# dpでやってみる版

# [どこまでのsNを使うか][合計として取りうる値かどうか]
# 範囲は0を含むNまでのN+1個と0～10000までの10001個
dp = [[False] * 10001 for j in range(N+1)]

# 初期値設定(s1～sNを何も使わない時、合計値0は取りうるか→True)
dp[0][0] = True

for i in range(N):
    for j in range(10001):
        # 前回までの設定値でここがTrueになっていたら
        if dp[i][j] == True:
            # sN合計の一つ先で、今までの値はTrue
            dp[i+1][j] = True
            # sN合計の一つ先で、今までの値+今回のsNもTrue
            dp[i+1][j+sN[i]] = True

# 高い値から順に見ていく
for i in range(10000, -1, -1):
    if dp[N][i]:
        if i % 10 != 0:
            print(i)
            exit()
print(0)

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


int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i=0; i<N; ++i) {
    cin >> A.at(i);
  }
  int ans=0;
  for (int i=0; i<N; ++i) {
    ans += A.at(i) -1;
  }
  cout << ans << endl;
}




Measured memory_bytes: 256
H, W = map(int,input().split())
N = int(input())
a = list(map(int,input().split()))
c = [[None for _ in range(W)] for _ in range(H)]
cur = 1
for i in range(H):
    if i % 2 == 0:
        for j in range(W):
            a[cur-1] -= 1
            c[i][j] = cur
            if a[cur-1] == 0:
                cur += 1
    else:
        for j in range(W-1, -1, -1):
            a[cur-1] -= 1
            c[i][j] = cur
            if a[cur-1] == 0:
                cur += 1
for i in range(H):
    print(" ".join(map(str, c[i])))

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

using namespace std;
using llint = long long;
using pint = pair<int,int>;

#define LOG(x) cout << "# " << #x <<" => "<< (x) <<endl

int n, ans=0;

vector<int> c;
vector<int> ans_c;
vector<vector<int> > d;
queue<int> que;

vector<pint> info;
vector<int> wa;

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

    d.resize(n);
    for (int i = 1; i <= n-1; ++i)
    {
        int u, v;
        cin >> u >> v;
        d.at(u-1).push_back(v-1);
        d.at(v-1).push_back(u-1);
    }

    c.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> c.at(i);
    }

    // info.resize(n);
    // for (int i = 0; i < n; ++i)
    // {
    //     info.at(i).first = d.at(i).size();
    //     info.at(i).second = i;
    // }

    wa.resize(n);
    ans_c.resize(n);

    // Solve
    // sort(info.begin(), info.end());
    sort(c.begin(), c.end(), greater<int>());

    // for (int i = 0; i < n; ++i)
    // {
    //     int loc = info.at(i).second;
    //     int num = c.at(i);

    //     ans_c.at(loc) = num;
    // }


    // BFS
    int cn = 0;
    que.push(0);
    while(!que.empty()) {
        auto cur = que.front();
        wa.at(cur) = 1;
        que.pop();
    
        // search
        ans_c.at(cur) = c.at(cn);
        cn++;

        for (auto node : d.at(cur)) {
            if (wa.at(node)!= 1)
            {
                que.push(node);
            }
         }
    }

    for (int i = 0; i < n; ++i)
    {
        for (auto node : d.at(i)) {
            ans += min(ans_c.at(i), ans_c.at(node));
         }
    }

    ans /= 2;

    // Output
    cout << ans << endl;
    for (int i = 0; i < n; ++i)
    {
        cout << ans_c.at(i) << " ";
    }
    cout << endl;
    return 0;
}

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

int main(void) {
  while(1) {
    int a, b;
    char op;
    cin >> a >> op >> b;

    if (op == '+') {cout << a+b << endl;}
    else if (op == '-') {cout << a-b << endl;}
    else if (op == '*') {cout << a*b << endl;}
    else if (op == '/') {cout << a/b << endl;}
    else break;
  }
  return 0;
}


Measured memory_bytes: 3088
import java.util.Scanner;

public class Main {
	static int n;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		if(n == 0) {
			System.out.println(2);
			return;
		}
		if(n == 1) {
			System.out.println(1);
			return;
		}
		solve(2,1,2);
	}
	static void solve(long l1, long l2, int w) {
		if(w == n) {
			System.out.println(l2 + l1);
			return;
		}
		long li = l2 + l1;
		solve(l2, li, w+1);
	}
}

Measured memory_bytes: 23252
import java.io.*;
import java.util.Arrays;
import java.util.Scanner;

public class Main{
	public static void main(String[] args) throws IOException{ 
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line1 = br.readLine();
		String line2 = br.readLine();
		line1 = line1 + line1;
		if (line1.indexOf(line2) != -1) {
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 24356
kMax = 100000
def calc_primes():
    is_prime = [True] * (kMax+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, kMax+1):
        if not is_prime[i]:
            continue
        for k in range(2*i, kMax+1, i):
            is_prime[k] = False
    ans = []
    for i in range(2, kMax+1):
        if is_prime[i]:
            ans.append(i)
    return ans

a = [0] * (kMax+1)

primes = set(calc_primes())

acc = 0
for i in range(1, kMax+1, 2):
    ii = (i+1)//2
    if i in primes and ii in primes:
        acc += 1
    a[i] = acc

Q = int(input())

for _ in range(Q):
    l, r = map(int, input().split())
    ra = a[r]
    la = a[l-2] if l >= 3 else 0
    print(ra-la)

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

typedef struct proces{
  char name[10];
  int count;
  int time;
}def;

int head,n,tail;
def c[100000];

void aaa(def s){
  c[tail]=s;
  tail=(tail+1)%100000;
}

def deq(){
  def sd=c[head];
  head=(head+1)%100000;
  return sd;
}

int min(int k,int l){
  if(k>l) return l;
  else return k;
}

int main(){
  int tasu,i,q,b,sum=0;
  def type;
  scanf("%d %d",&b,&q);
  for(i=1;i<=b;i++){
    scanf("%s",c[i].name);
    scanf("%d",&c[i].time);
    c[i].count=1;
  }
  head=1;
  tail=b+1;
  while(tail != head){
    type=deq();
    tasu=min(q,type.time);
    type.time=type.time-tasu;
    sum=sum+tasu;
    if(type.time>0){
      aaa(type);
    }
    else if(type.count==1){
      printf("%s %d\n",type.name,sum);
      type.count=0;
    }
  }
  return 0;
}


      



Measured memory_bytes: 3732
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  string s;
  int q;
  cin >> s >> q;
  string sen="",matu="";
  vector<pair<int,pair<int,char>>> Q(q);
  rep(i,q){
    cin >> Q[i].fi;
    if(Q[i].fi==2){
      cin >> Q[i].se.fi >> Q[i].se.se;
    }
  }
  bool reverse=false;

  rep(i,q){
    if(Q[i].fi==1){//反転
      reverse= !reverse;
    }
    else{
      if((reverse==false && Q[i].se.fi==1) || (reverse==true && Q[i].se.fi==2)) sen=Q[i].se.se+sen;
      else matu+=Q[i].se.se;
    }
  }
  s=sen+s+matu;
  if(!reverse)cout << s << endl;
  else{
    for(int i=sz(s)-1; i>=0; i--) cout << s[i];
    cout  << endl;
  }
  return 0;
}


Measured memory_bytes: 3792
#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 A,B,K;
  cin>>A>>B>>K;
  if(B-A+1<=K*2){
    REP(i,A,B)
      cout<<i<<endl;
    }
  else{
    rep(i,A,A+K)
      cout<<i<<endl;
    REP(i,B-K+1,B)
      cout<<i<<endl;
    }
  }


Measured memory_bytes: 256
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
s = [ns() for _ in range(n)]

ans = 0

x = y = z = 0

for si in s:
    # 内部のABカウント
    ans += si.count('AB')

    # 右端A かつ 左端B ... Z
    if si[:1] == 'B' and si[-1:] == 'A':
        z += 1

    # 右端A ... X
    elif si[-1:] == 'A':
        x += 1

    # 左端B ... Y
    elif si[:1] == 'B':
        y += 1

if z <= x and z <= y:
    ans += 2*z
    ans += min(x,y) - z

else:
    ans += min(z, x)
    ans += min(z, y)

    if z >= x and z >= y:
        if x == 0 and y == 0:
            ans += z-1
        else:
            ans += z - max(x,y)

print(ans)

Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
const int N=2e5+10;
typedef long long ll;
ll a[N],c[N];
ll n;
int main() {
	ll i,x,cnt=0,ans=0;
	scanf("%lld",&n);
	for (i=1;i<=n;i++) {
		scanf("%lld",&x);
		a[x]++;
		c[i]=x;
	}
	ans=0;
	for (i=1;i<=n;i++)
		if (a[i]>0) ans+=a[i]*(a[i]-1)/2;
//	cout<<ans<<endl;
	for (i=1;i<=n;i++) 
		printf("%lld\n",ans-(a[c[i]]-1));
	return 0;
} 

Measured memory_bytes: 4736
Q, H, S, D = map(int, input().split())
N = int(input())*4
arr = [[Q, Q, 1], [H/2, H, 2], [S/4, S, 4], [D/8, D, 8]]
arr.sort()
ans = 0
for _, cost, size in arr:
    ans += (N//size)*cost
    N %= size
    if N == 0: break
print(ans)


Measured memory_bytes: 3064
#include<iostream>		
 
int main(){
  int s;
		int g[3];
		int a = 0;
		std::cin >> s;
		g[0] = s / 100;
		g[1] = (s - g[0] * 100) / 10;
		g[2] = s - (g[0] * 100) - (g[1] * 10);
		for (int lp = 0; lp < 3; lp++) {
			a += g[lp] == 1 ? 1 : 0;
		}
		std::cout << a << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#include<vector>
struct UF{
	int n;
	vector<int>parent,rank;
	UF(int n_=0):n(n_),parent(n_),rank(n_,0)
	{
		for(int i=0;i<n_;i++)parent[i]=i;
	}
	int find(int a)
	{
		return parent[a]!=a?parent[a]=find(parent[a]):a;
	}
	bool same(int a,int b)
	{
		return find(a)==find(b);
	}
	bool unite(int a,int b)
	{
		a=find(a),b=find(b);
		if(a==b)return false;
		if(rank[a]<rank[b])
		{
			parent[a]=b;
		}
		else
		{
			parent[b]=a;
			if(rank[a]==rank[b])rank[a]++;
		}
		return true;
	}
};

main()
{
	int n,q;cin>>n>>q;
	UF uf(n);
	for(;q--;)
	{
		int p,a,b;cin>>p>>a>>b;
		if(p)cout<<uf.same(a,b)<<endl;
		else uf.unite(a,b);
	}
}



Measured memory_bytes: 3176
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
vector<ll> adj[200005];
ll cnt=0;
bool status[200005];
void dfs(int s)
{
    cnt++;
    status[s]=true;
    for(auto it:adj[s])
    {
        if(!status[it])
        {
            dfs(it);
        }
    }
}
void solve()
{
    ll n,m;
    cin>>n>>m;
    ll a,b;
    for(ll i=0;i<m;i++)
    {
        cin>>a>>b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    memset(status,false,sizeof(status));
    ll maxx=-1;
    for(int i=1;i<=n;i++)
    {
        if(!status[i])
        {
            cnt=0;
            dfs(i);
            maxx=max(maxx,cnt);
        }
    }
    cout<<maxx<<endl;
}
int main()
{
      solve();
}


Measured memory_bytes: 20816
#include<stdio.h>

int sosuu(int so){
  int i=0;
  if(so==1)
    return 0;
  
  for(i=2;i*i<=so;i++){
    if(so%i==0)
      return 0;
  }
    return 1;
}

int main(void){
  int i=0;
  int j=0;
  int so[10000];
  int a=0;
  int d=0;
  int v=0;
  int c=0;
  int s=0;
  int count=0;
  int n=0;
  int ans[1000];

   while(1){
     scanf("%d %d %d", &a, &d, &v);
     count=0;
     s=0;
     n=0;
     c++;
     if(d==0)
       break;

     while(count<v){
       s=a+d*n;
       if(sosuu(s)==1)
	 count++;
       n++;
       if(count==v){
	 ans[j]=s;
	 j++;
    }
   }
  }

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

  return 0;
}
  

  



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

using namespace std;

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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int N, K; cin >> N >> K;
	vector<int> A(N, 0);
	rep (i,N) cin >> A[i];

	map<int,int> cnt; cnt.clear();
	rep (i, N) ++cnt[A[i]];

	vector<P> cnt2; cnt2.clear();
	map<int,int>::iterator it = cnt.begin();
	for (; it != cnt.end(); ++it){
		int n = (*it).first;
		int c = (*it).second;
		cnt2.push_back(P(-c,n));
	} // end for

	sort(ALL(cnt2));
	
	int res = 0;
	for (int i = K; i < (int)cnt2.size(); ++i){
		res += -cnt2[i].first;
	} // end for
	
	cout << res << endl;
	
	return 0;
}

Measured memory_bytes: 12660
N,A,B=map(int,input().split(' '))
S=input()
apass,bpass=0,0
for i in range(N):
	if S[i]=='a' and apass+bpass<A+B:
			print('Yes')
			apass+=1
	elif S[i]=='b' and apass+bpass<A+B and bpass<B:
			print('Yes')
			bpass+=1
	else:
			print('No')

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

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

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

    rep(i, h) {
        rep(j, w) {
            int num = 0;
            if(s[i][j] == '#') continue;
            rep(k, 8) {
                int y = i + dy[k], x = j + dx[k];
                if(0 <= y && y < h && 0 <= x && x < w && s[y][x] == '#') num++;
            }
            s[i][j] = num + '0';
        }
    }
    

    rep(i, h) cout << s[i] << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int a[4][1005];

int main(){
	int n;
	scanf("%d",&n);
	for (int i = 0;i < 2;++i){
		for (int j = 0;j < n;++j){
			scanf("%d",&a[i][j]);
		}	
	}
	long long maxm=0,now;
	for (int i = 0;i < n;++i){
		now=0;
		for (int j = 0;j <= i;++j){
			now+=a[0][j];
		}
		for (int j = i;j < n;++j){
			now+=a[1][j];
		}
		if (maxm < now) maxm=now;
	}
	printf("%lld\n",maxm);
	return 0;
}

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

int main(){
    int h, w;
    cin >> h >> w;

    vector<string> s(h);
    for (auto i = 0; i < h; i++) cin >> s[i];

    int count;
    for (auto i = 0; i < h; i++) {
        for (auto j = 0; j < w; j++) {
            if(s[i][j] == '.') {
                count = 0;
                for (auto k = 0; k < 3; k++) {
                    for (auto l = 0; l < 3; l++) {
                        if(i - 1 + k < 0 or i - 1 + k >= h) continue;
                        if(j - 1 + l < 0 or j - 1 + l >= w) continue;
                        if (s[i - 1 + k][j - 1 + l] == '#') count++;
                    }
                }
                s[i][j] = count + '0';
            }
        }
        cout << s[i] << endl;
    }
    return 0;
}

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

public class Main {

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

		int a = getInt(sc);
		int b = getInt(sc);

		String[] strs = { "", "" };

		for (int i = 0; i < a; i++) {
			strs[0] += b;
		}

		for (int i = 0; i < b; i++) {
			strs[1] += a;
		}

		Arrays.sort(strs);
		System.out.println(strs[0]);

	}

	/**
	 * *汎用メソッド<br>
	 * 入力した配列に対する順列を取得
	 *
	 * @param numArray
	 * @return
	 */
	private static List<Integer[]> getPermutation(int[] numArray) {
		List<Integer[]> permutation = new ArrayList<>();
		Integer[] ans = new Integer[numArray.length];
		boolean[] used = new boolean[numArray.length];

		return buildPermutaion(permutation, numArray, ans, used, 0);
	}

	/**
	 * *汎用メソッド(内部)<br>
	 * 入力した配列に対する順列を作成
	 *
	 * @param list
	 * @param numArray
	 * @param ans
	 * @param used
	 * @param depth
	 * @return
	 */
	private static List<Integer[]> buildPermutaion(List<Integer[]> list, int[] numArray, Integer[] ans, boolean[] used,
			int depth) {

		// 全部使い切った時=>できた順列を返す
		if (depth == numArray.length) {
			list.add(ans.clone());
			return list;
		}
		// 使い切っていない場合

		for (int i = 0; i < numArray.length; i++) {
			if (used[i]) {
				continue;
			}
			ans[depth] = numArray[i];
			used[i] = true;
			list = buildPermutaion(list, numArray, ans, used, depth + 1);

			used[i] = false;
		}

		return list;
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をlongで返却
	 *
	 * @return
	 */
	public static long getLong(Scanner sc) {

		return Long.parseLong(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をintで返却
	 *
	 * @return
	 */
	public static int getInt(Scanner sc) {

		return Integer.parseInt(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をStringで返却
	 *
	 * @return
	 */
	public static String getString(Scanner sc) {

		return sc.next();
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をint配列で返却
	 *
	 * @return
	 */
	public static int[] getIntArray(Scanner sc) {
		String line = "";
		// 直前にnext()を実行していると改行コードだけ取ってしまうのでその対策
		while (line.equals("")) {
			line = sc.nextLine();
		}

		String[] strArray = line.split(" ");
		int[] intArray = new int[strArray.length];
		for (int i = 0; i < strArray.length; i++) {
			intArray[i] = Integer.parseInt(strArray[i]);
		}
		return intArray;
	}

}

class Status {
	long x;
	long tmpCoins;

	public Status(long x, long tmpCoins) {
		this.x = x;
		this.tmpCoins = tmpCoins;
	}
}


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

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using P = pair<ll, ll>;

constexpr double PI = 3.14159265358979323846;
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

class CClosedRooms {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      int h, w, k; cin >> h >> w >> k;
      char mat[h][w];
      vector<vector<int>> cost(h, vector<int>(w, INT_MAX/2));
      int start = -1;
      deque<P> que;
      rep(i, h) rep(j, w) {
        cin >> mat[i][j];
        if (mat[i][j] == 'S') {
          que.emplace_back(i*w+j, 0);
          cost[i][j] = 0;
        }
      }
      while(!que.empty()) {
        auto p = que.front(); que.pop_front();
        int i = p.first/w;
        int j = p.first%w;
        int c = p.second;
        if (c > cost[i][j]) continue;

        if (i>0 && mat[i-1][j] == '.') {
          if (cost[i-1][j] > c+1) {
            cost[i-1][j] = c+1;
            que.emplace_back((i-1)*w+j, c+1);
          }
        }
        if (i<h-1 && mat[i+1][j] == '.') {
          if (cost[i+1][j] > c+1) {
            cost[i+1][j] = c+1;
            que.emplace_back((i+1)*w+j, c+1);
          }
        }
        if (j>0 && mat[i][j-1] == '.') {
          if (cost[i][j-1] > c+1) {
            cost[i][j-1] = c+1;
            que.emplace_back(i*w+j-1, c+1);
          }
        }
        if (j<w-1 && mat[i][j+1] == '.') {
          if (cost[i][j+1] > c+1) {
            cost[i][j+1] = c+1;
            que.emplace_back(i*w+j+1, c+1);
          }
        }
      }

      int distance = INT_MAX;
      rep(i, h) rep(j, w) {
        if (cost[i][j] <= k) {
          auto imin = min(i, h-1-i);
          auto jmin = min(j, w-1-j);
          chmin(distance, min(imin, jmin));
        }
      }

      cout << (distance+k-1)/k + 1 << endl;

    }
};

signed main() {
  CClosedRooms solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

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

using ll = long long;

constexpr ll mod = 1e9 + 7;

int main() {
    int n; cin >> n;
    string s; cin >> s;
    vector<ll> cnt(26);
    for(int i = 0; i < n; ++i) {
        cnt[s[i] - 'a'] += 1;
    }
    ll ans = 0;
    for(int i = 0; i < 26; ++i) {
        if(cnt[i] == 0) continue;
        (ans = ans + cnt[i] + ans * cnt[i]) %= mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
////////////////////////////////////////////
///                                      ///
///         Template ver. 1 rapel        ///
/// Fear is Temporary, Regret is Forever ///
///          Must Try and Get AC         ///
///                                      ///
////////////////////////////////////////////
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <iomanip>

#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>

#include <math.h>
#include <complex>

#include <assert.h>
#include <time.h>
//#include <chrono>
//#include <random>

#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <bitset>

#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define endl '\n'
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

void desperate_optimization(int precision){
  	ios_base::sync_with_stdio(false);
  	cin.tie(0);
  	cout.tie(0);
  	cout.setf(ios::fixed);
  	cout.setf(ios::showpoint);
  	cout.precision(precision);
}

const LL MOD = 1e9 + 7;
const int N = 2e5 + 5;
LL fct[N + 5], inv[N + 5];

LL fast(LL A,LL B){
	LL res = 1;
	while(B) {
		if(B&1) res = res * A % MOD;
		B /= 2;
		A = A * A % MOD;
	}
	return res;
}

void pre() {
	fct[0] = 1;
	for(int i = 1;i <= N;i++) fct[i] = fct[i-1] * i %  MOD;
	inv[N] = fast(fct[N], MOD - 2);
	for(int i = N - 1;i >= 0;i--) inv[i] = inv[i + 1] * (i + 1) % MOD;
}

LL combin(int n, int r) {
	if(n < r) return 0;
	return fct[n] * inv[r] % MOD * inv[n - r] % MOD;
}

void hora(int tc) {
	int h,w,a,b;
	cin>>h>>w>>a>>b;
	LL ways = combin(h - 1 + w - 1, h - 1);
	LL red = combin(h - a + b - 1, b - 1) * combin(a - 1 + w - b, w - b) % MOD;
	for(int i = b - 1;i >= 1;i--) {
		if(a != 1) red = (red + combin(h - a + i - 1, i - 1) * combin(a - 2 + w - i, w - i))% MOD;
	}
	cout<<(ways + MOD - red) % MOD<<endl;
}

int main(){
	desperate_optimization(10);
	pre();
	int ntc = 1;
	//cin>>ntc;
	for(int tc = 1;tc <= ntc;tc++) hora(tc);
	return 0;
}




Measured memory_bytes: 3328