akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
vi G;
inline int root(int x){ return G[x] < 0 ? x : G[x] = root(G[x]); }
inline void uniteSet(int x, int y){
    x = root(x);
    y = root(y);
    if (x == y) return;
    if (G[x] > G[y]) swap(x, y);
    G[y] = x;
}
inline bool findSet(int x, int y){ return root(x) == root(y); }
int main() {
	int n, m; cin >> n >> m;
	G.resize(n, -1);
	int s, t;
	rep(i, 0, m) {
		cin >> s >> t;
		uniteSet(s, t);
	}
	int q; cin >> q;
	rep(i, 0, q) {
		cin >> s >> t;
		P(findSet(s, t) ? "yes" : "no");
	}
	return 0;
}

Measured memory_bytes: 3348
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split())) + [0]
ans = 0
aj = -10 ** 12
for a in A:
    ans += B[a - 1]
    if a - aj == 1:
        ans += cj
    aj = a
    cj = C[a - 1]
print(ans)

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

const ll INF = 1LL << 60;

struct state {
  ll y, x, d;

public:
  bool operator<(const state &s) const {
    return d > s.d;
  }
};

ll dy1[4] = { -1, +0, +1, +0 };
ll dx1[4] = { +0, -1, +0, +1 };

ll dy2[4] = { -1, -1, +1, +1 };
ll dx2[4] = { -1, +1, -1, +1 };

int main(void) {
  ll H, W, A, B;
  cin >> H >> W >> A >> B;
  vector<string> S(H);
  REP(i, 0, H) cin >> S[i];

  ll sy, sx, gy, gx;
  REP(i, 0, H) REP(j, 0, W) {
    if (S[i][j] == 's') {
      sy = i;
      sx = j;
    }
    if (S[i][j] == 'g') {
      gy = i;
      gx = j;
    }
  }

  vector<vector<ll>> dp(H, vector<ll>(W, INF));
  priority_queue<state> q;
  q.push((state) { sy, sx, 0 });

  while (q.size()) {
    ll y = q.top().y, x = q.top().x, d = q.top().d;
    q.pop();

    if (dp[y][x] <= d) continue;
    dp[y][x] = d;

    REP(i, 0, 4) {
      ll ny = y + dy1[i], nx = x + dx1[i];
      if (0 <= ny && ny < H && 0 <= nx && nx < W && S[ny][nx] != '#') {
        q.push((state) { ny, nx, d + A });
      }
    }

    bool ok = true;
    REP(i, -1, 2) REP(j, -1, 2) {
      ll ny = y + i, nx = x + j;
      if (0 <= ny && ny < H && 0 <= nx && nx < W && S[ny][nx] == '*') {
        ok = false;
      }
    }
    if (ok) {
      REP(i, 0, 4) {
        ll ny = y + dy1[i], nx = x + dx1[i];
        if (0 <= ny && ny < H && 0 <= nx && nx < W) {
          q.push((state) { ny, nx, d + A + B });
        }
      }
      REP(i, 0, 4) {
        ll ny = y + dy2[i], nx = x + dx2[i];
        if (0 <= ny && ny < H && 0 <= nx && nx < W) {
          q.push((state) { ny, nx, d + A * 2 + B });
        }
      }
    }
  }

  if (dp[gy][gx] == INF) {
    cout << "INF" << endl;
  } else {
    cout << dp[gy][gx] << endl;
  }
}


Measured memory_bytes: 12436
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
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() {
  ll n,a,b;
  cin >> n >> a >> b;
  ll x[n];
  FOR(i,0,n-1) cin >> x[i];

  ll ans = 0;

  FOR(i,0,n-2){
    if((x[i+1]-x[i])*a>b){
      ans += b;
    }
    else{
      ans += (x[i+1]-x[i])*a;
    }
  }

  cout << ans << endl;

}



Measured memory_bytes: 1024
import java.io.IOException;
import java.util.NoSuchElementException;

import java.io.InputStream;

@SuppressWarnings("unchecked")
public class Main {
    static final int MAX_N = 300001;

    public static void main(String[] args) throws IOException {
        FastScanner fs = new FastScanner();

        final int N = fs.nextInt();
        final String S = fs.next();

        // 東を向いている人の累積和
        int[] E = new int[N];

        if (S.charAt(0) == 'E') E[0] = 1;

        for (int i = 1; i < N; i++) {
            E[i] = E[i - 1];
            if (S.charAt(i) == 'E') E[i]++;
        }

        int min = MAX_N;

        for (int i = 0; i < N; i++) {
            int tmp = E[N - 1] - E[i];

            if (0 < i) tmp += i - E[i - 1];

            min = Math.min(min, tmp);
        }

        System.out.println(min);
    }
}

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


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

class Solution
{
    static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
        a.Insert(0, 0);
        a.Add(0);

        var sum = Enumerable.Range(0, n + 1).Select(i => Math.Abs(a[i + 1] - a[i])).Sum();

        var answer = new StringBuilder();
        for (int i = 1; i <= n; i++)
        {
            var x = sum - (Math.Abs(a[i] - a[i - 1]) + Math.Abs(a[i + 1] - a[i])) + Math.Abs(a[i + 1] - a[i - 1]);
            answer.Append(x);
            answer.Append("\n");
        }

        Console.WriteLine(answer);
    }
}

Measured memory_bytes: 31708
fun main(args: Array<String>) {
    val n = Integer.parseInt(readInputLine())
    val vs = readInputLine().split(" ").map { it -> Integer.parseInt(it) }
    val cs = readInputLine().split(" ").map { it -> Integer.parseInt(it) }
    
    var res = 0
    
    for (i in 0..(n-1)) {
        val value = vs[i] - cs[i]
        if (value > 0) {
            res += value
        }
    }

    println(res)
}
 
fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 37748
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<functional>
#include<vector>
#include<map>
#include<string>
#include<set>
#include<unordered_map>
#include<math.h>
#include<stack>
#include<deque>
using namespace std;

signed main() {
	int ans = 0, n; cin >> n;
	for (int i = 0; i < n; i++) {
		int a, b; cin >> a >> b;
		ans += b - a + 1;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
def makeEmptyMatrix(i, j):
	mat = [[]] * i
	for a in xrange(i):
		mat[a] = [0] * j
	return mat

n, m, l = map(int, raw_input().split())
A = makeEmptyMatrix(n, m)
B = makeEmptyMatrix(l, m)
for i in xrange(n):
 A[i] = map(int, raw_input().split())

for i in xrange(m):
 for j, v in enumerate(map(int, raw_input().split())):
  B[j][i] = v

for a in A:
 for b in B:
  ttl = 0
  for i, j in zip(a, b): ttl += i*j
  print ttl,
 print

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

using namespace std;
#define MOD 1000000007
#define pi 3.1415926535897932384626433832795028841971693993751058209749445923078164062
#define ll long long
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define popb pop_back()
#define popf pop_front()
#define ff first
#define ss second
#define vl vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vll vector< pair<ll,ll> >
#define vii vector< pair<int,int> >
#define viii vector< tuple <int,int,int> >
#define vlll vector< tuple <ll,ll,ll> >
#define vvl vector<vector<ll>>
#define vv vector<vector<int>>
#define all(v) v.begin(),v.end()
#define sqrt sqrtl
#define cbrt cbrtl
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mapcl map<char,ll>
#define mapci map<char,int>
#define mapll map<ll,ll>
#define mapii map<int,int>
#define seti set<int>
ifstream fin("input.txt");
ofstream fout("output.txt");

int gcd(int a,int b){while (a&&b)a>b?a%=b:b%=a;return a+b;}
ll pows(int a , int b){ll res=1;for(int i=0; i<b; ++i){res*=a;}return res;}
ll logx(ll base, ll num){int cnt=0;while(num!=1){num/=base; ++cnt;}return cnt;}

vi vis(100001,0);
vi adj[100001];

int main()
{	
    std::ios::sync_with_stdio(false);
    //cin.tie(NULL);
    //cout.tie(NULL);
    int n,k,cnt=0;cin>>n>>k;
    string s;cin>>s;
    if(n==1)
    	cout<<0<<"\n";
    else
    {
    	for(int i=0; i<n; ++i)
    	{
    		if(s[i]=='R' && (i+1<n) && s[i+1]=='R')
    			++cnt;
    		else if(s[i]=='L' && (i-1>=0) && s[i-1]=='L')
    			++cnt;
    	}
    	//cout<<cnt<<"\n";
    	cout<<min(n-1,cnt+2*k)<<"\n";
    }

}

Measured memory_bytes: 3280
#include <stdio.h>

#define MaxValue 10000
int f[MaxValue+1];

int main(void) {
  int n;
  scanf("%i", &n);
  
  int a[n];
  for (int i = 0; i < n; i++) {
    scanf("%i", &a[i]);
  }
  
  f[0] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = MaxValue; j-a[i] >= 0; j--) {
      f[j] |= f[j-a[i]];
    }
  }
  
  int ans = 0;
  for (int i = MaxValue; i >= 0; i--) {
    if (f[i] && (i % 10 != 0)) {
      ans = i;
      break;
    }
  }
  
  printf("%i\n", ans);
  
  return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from collections import *

def dfs(x, y):
    res = False
    
    for i in range(2, x+1, 2):
        res |= not dfs(x-i, y+i//2)
    
    for i in range(2, y+1, 2):
        res |= not dfs(x+i//2, y-i)
    
    return res

"""
for i in range(5):
    for j in range(5):
        print(dfs(i, j), end=' ')
    print()
"""

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

if abs(X-Y)<=1:
    print('Brown')
else:
    print('Alice')

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define strall(v) (v).cbegin(),(v).cend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
//const long long INF = 1LL << 60;
 int INF = 500000;
 int MAX = 1e5+10;
 ll mod = 1e9+7;


int main(){
  int n,d,cnt=0;
  cin >> n >> d;
  vector<vector<int>> x(n,vector<int>(d,0));
  rep(i,n){
    rep(j,d){
      cin >> x[i][j]; 
    }
  }
  int ans = 0;
  for(int i=0;i<n;++i){
    for(int j=i+1;j<n;++j){
      int norm = 0;
      //距離計算 (i,j) のk番目の距離要素計算
      for(int k=0;k<d;++k){
        int diff = abs(x[i][k] - x[j][k]);
        norm += diff * diff;
      }
      bool flag = false;
      for(int k=0;k <= norm;k++){
        if(k*k == norm) flag = true;
      }
      if(flag) cnt++;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;

    if (e-a > k)
    {
        cout << ":(" << endl;
    }
    else
    {
        cout << "Yay!" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
n = int(input())
A = list(map(int,input().split()))
A.sort()
B = []
if n % 2 == 0:
    i_max = n//2
    for i in range(1,i_max+1):
        B.append(2*i-1)
        B.append(2*i-1)
else:
    i_max = (n-1)//2
    B.append(0)
    for i in range(1,i_max+1):
        B.append(2*i)
        B.append(2*i)
if A == B:
    print((2**i_max)%(10**9+7))
else:
    print(0)


Measured memory_bytes: 14008
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define eb(k,v) emplace_back(k,v)
#define ct(res) cout << res << "\n";
#define vi vector<int>
#define vl vector<ll>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    char a,b; cin >> a >> b;
    string ss;
    for(int i=0; i<max(a-'0', b-'0'); ++i) {
        ss += min(a-'0', b-'0')+'0';
    }
    cout << ss << "\n";
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i, n) for (ll i=0; i<n; ++i)
#define all(obj) (obj).begin(),(obj).end()
using namespace std;
typedef long long ll;
long long GCD(long long x, long long y) { return y ? GCD(y, x%y) : x; }

int main(){
    ll N;
    cin >> N;
    ll su = 0;
    ll p = 0;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    ll p2 = A[0];
    for(ll i=0; i<N; ++i){
        if(p2>A[i]){
            su += p2-A[i];
        }
        else p2 = A[i];
    }
    cout << su << endl;
    return 0;
}


Measured memory_bytes: 4784
#include<bits/stdc++.h>
using namespace std;
int h,w;
char mp[2009][2009];
vector<int>nh[2009];
vector<int>nw[2009];

int main(){
  cin>>h>>w;
  for(int i=0;i<w;i++){
    nh[i].push_back(-1);
    nh[i].push_back(h);
  }
  for(int i=0;i<h;i++){
    nw[i].push_back(-1);
    nw[i].push_back(w);
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin>>mp[i][j];
    }
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(mp[i][j]=='#'){
	nh[j].push_back(i);
	nw[i].push_back(j);
      }
    }
  }
  for(int i=0;i<w;i++){
    sort(nh[i].begin(),nh[i].end());
  }
  for(int i=0;i<h;i++){
    sort(nw[i].begin(),nw[i].end());
  }
  int ans=0;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(mp[i][j]=='.'){
	int sum=1;
	int idx=upper_bound(nw[i].begin(),nw[i].end(),j)-nw[i].begin();
	sum+=(j-nw[i][idx-1]-1)+(nw[i][idx]-j-1);
	idx=upper_bound(nh[j].begin(),nh[j].end(),i)-nh[j].begin();
	sum+=(i-nh[j][idx-1]-1)+(nh[j][idx]-i-1);
	ans=max(ans,sum);
      }
    }
  }
  cout<<ans<<endl;
  return(0);
}


Measured memory_bytes: 38144
s=0
N=int(input())
L=list(map(int,input().split()))
L=sorted(L,reverse=True)
if N%2==0:
  s+=L[0]
  s+=2*sum(L[1:N//2])
else:
  s+=L[0]
  s+=2*sum(L[1:(N+1)//2])-L[((N+1)//2)-1]
print(s)

Measured memory_bytes: 31352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = ll(1e12);
const ll mod = ll(1e9) + 7;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()
#define yes pf("Yes")
#define no pf("No")

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

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

ll factorial(ll n){
    ll t = 1;
    rep1(i, n){
        t *= i;
        t %= mod;
    }
    return t;
}

ll power(ll a, ll b){
    a %= mod;
    if(b == 0){
        return 1;
    }
    ll ans = power(a, b / 2);
    ans = ans * ans % mod;
    if(b % 2 == 1){
        ans = ans * a % mod;
    }
    return ans;
}

ll combination(ll a, ll b){
    if((a == b) || (b == 0)){
        return 1;
    }
    if(a < b) return 0;
    ll ans = 1;
    for(ll i = 0; i < b; i++) {
        ans *= (a - i);
        ans /= (i + 1);
        ans %= mod;
    }
    return ans;
}

int main(){
    ll n;
    cin >> n;
    vector<ll> ans(n + 1,0);
    rep0(i, n - 1){
        ll a;
        cin >> a;
        ++ans[a - 1];
    }
    rep0(i, n)pf(ans[i]);
    return 0;
}



Measured memory_bytes: 4844
// 131_A_Security.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>

using namespace std;

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

	bool bad = false;
	for (int i = 1; i < s.length(); i++)
	{
		if (s[i] == s[i - 1])
		{
			bad = true;
			break;
		}
	}

	if (bad)
	{
		cout << "Bad";
	}
	else
	{
		cout << "Good";
	}

	return 0;
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file


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

int main()
{
  int64_t p, N, n, ans = 0;
  vector<pair<int64_t, int64_t>> vp;
  for (int i = 3; i >= 0; i--)
  {
    cin >> p;
    int64_t x = pow(2, i);
    vp.push_back(make_pair(x * p, 8 / x));
  }
  cin >> N;
  sort(vp.begin(), vp.end());
  n = 4 * N;
  for (int i = 0; i < 4; i++)
  {
    int64_t l = vp.at(i).second;
    int64_t c = vp.at(i).first / (8 / l);
    ans += c * (n / l);
    n %= l;
  }
  cout << ans << endl;
}

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

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

    int n;
    cin>>n;
    string s;
    cin>>s;
    
    string alph = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    for(char c : s){
        cout<<alph[(c-'A'+n)%26];
    }
    cout<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
  int N,X,Z;
  scanf("%d%d",&N,&X);
  Z=(N%500);
  if(Z==0)
  {
    printf("Yes\n");
  }
  else if(Z<=X)
  {
    printf("Yes\n");
  }
  else
  {
  printf("No\n");
  
  }
  return 0;
  }
   
    
   

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

// @@ !! LIM()

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  using Vec1 = vector<ll>;
  using Vec2 = vector<Vec1>;
  using Vec3 = vector<Vec2>;

  string S; cin >> S;
  ll M = S.size();
  ll K; cin >> K;
  Vec3 tbl(M+1, Vec2(K+1, Vec1(2)));
  tbl.at(0).at(0).at(0) = 1;
  for (ll i = 0; i < M; i++) {
    for (ll k = 0; k <= K; k++) {
      tbl.at(i+1).at(k).at(1)   +=     tbl.at(i).at(k).at(1);
      if (k < K) {
	tbl.at(i+1).at(k+1).at(1) += 9 * tbl.at(i).at(k).at(1);
      }
    }
    ll d = S.at(i) - '0';
    if (d == 0) {
      for (ll k = 0; k <= K; k++) { 
	tbl.at(i+1).at(k).at(0) += tbl.at(i).at(k).at(0);
      }
    }else {
      for (ll k = 0; k <= K; k++) { 
	tbl.at(i+1).at(k  ).at(1) +=           tbl.at(i).at(k).at(0);
	if (k < K) {
	  tbl.at(i+1).at(k+1).at(1) += (d - 1) * tbl.at(i).at(k).at(0);
	  tbl.at(i+1).at(k+1).at(0) +=           tbl.at(i).at(k).at(0);
	}
      }
    }
  }
  ll ans = tbl.at(M).at(K).at(1) + tbl.at(M).at(K).at(0);
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 256
string=input()
palindrome=False
palin1=False

def palin(string):
    palindrome=False
    if string==string[::-1]:
        palindrome=True
    return palindrome

palindrome=palin(string)

if palin(string[int((len(string)-1)/2)])==True and palindrome==True:
    palin1=True
if palin(string[int((len(string)+3)/2)-1:len(string)])==True and palin1==True:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9048
#include <bits/stdc++.h>  // This will work only for g++ compiler. 


#define for0(i, n) for (int i = 0; i < (int)(n); ++i) // 0 based indexing
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i) // 1 based indexing
#define forc(i, l, r) for (int i = (int)(l); i <= (int)(r); ++i) // closed interver from l to r r inclusive
#define forr0(i, n) for (int i = (int)(n) - 1; i >= 0; --i) // reverse 0 based.
#define forr1(i, n) for (int i = (int)(n); i >= 1; --i) // reverse 1 based

//short hand for usual tokens
#define pb push_back
#define fi first
#define se second

// to be used with algorithms that processes a container Eg: find(all(c),42)
#define all(x) (x).begin(), (x).end() //Forward traversal
#define rall(x) (x).rbegin, (x).rend() //reverse traversal

// traversal function to avoid long template definition. Now with C++11 auto alleviates the pain.
#define tr(c,i) for(__typeof__((c)).begin() i = (c).begin(); i != (c).end(); i++)

// find if a given value is present in a container. Container version. Runs in log(n) for set and map
#define present(c,x) ((c).find(x) != (c).end())

//find version works for all containers. This is present in std namespace.
#define cpresent(c,x) (find(all(c),x) != (c).end())

// Avoiding wrap around of size()-1 where size is a unsigned int.
#define sz(a) int((a).size())


using namespace std;

// Shorthand for commonly used types
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef double ld;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;
    
    
    
    int n , w ; 
    cin>>n >> w ; 
	pair < int, int > a [n] ; 
	for (int i=0 ; i< n ; i++)
	{
		cin>>a[i].first >> a[i].second ; 
	}
	
	vector < ll > dp(w +1 , 0 ) ; 
	
	for ( int  i = 0 ;i< n; i++) 
	{
		int wight = a[i].first ;
		ll value =  a[i] .second ;  
		
		for ( int j = w - a[i].first ; j >= 0 ; j--)
		{
			dp[wight + j ] = max ( dp[wight +j] , dp[j] + value ) ; 
		}
	}
	
	ll ans  = 0 ; 
	for ( int i = 0 ;i <=w ; i++)
	{
		ans = max ( ans ,dp[i] ) ; 
	}
	cout<< ans << endl; 
    
    
    
    
    
    
    return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

class Main{


	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力

		int n = sc.nextInt();
		int ans = 1;
		for(int i = 0;i < n;i++){
			int tmp = sc.nextInt();
			if(i == 0){
				ans = tmp;
			}
			ans = gcd(ans,tmp);
		}
		System.out.println(ans);
	}
	
	static int gcd(int a,int b){
		if(b == 0){
			return a;
		}
		return gcd(b, a%b);
	}
}



Measured memory_bytes: 46164
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <random>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef deque<ll> dll;
ll mod = 1e9 + 7;


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

	ll a, b, n;
	cin >> n;
	rep(i, n) {
		cin >> a >> b;
		if (a == b) cout << 2 * a - 2 << endl;
		else if (abs(a - b) == 1) cout << 2 * min(a, b) - 2 << endl;
		else {
			ll s = sqrt(a*b);
			if (a*b == s*s) cout << 2 * s - 3 << endl;
			else if (s * (s + 1) >= a*b) cout << 2 * s - 2 << endl;
			else cout << 2 * s - 1 << endl;
		}
	}
	return 0;
}

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

using namespace std;
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };

int N,D;
vector<pair<int, int>> X;
inline void input(){
    fast_io();
    cin >> N >> D;
    for (int i = 0; i < N; i++)
    {
        int x,y; cin >> x >> y;
        X.emplace_back(x,y);
    }
}

#define xx true
#define yy false
#define x first
#define y second

inline int solve(){
    atcoder::two_sat ts(N);
    for (int i = 0; i < N; i++)
    {
        for (int j = i + 1; j < N; j++)
        {
            if(abs(X[i].x-X[j].x)<D) ts.add_clause(i,yy,j,yy);
            if(abs(X[i].x-X[j].y)<D) ts.add_clause(i,yy,j,xx);
            if(abs(X[i].y-X[j].x)<D) ts.add_clause(i,xx,j,yy);
            if(abs(X[i].y-X[j].y)<D) ts.add_clause(i,xx,j,xx);
        }
    }
    cout << (ts.satisfiable() ? "Yes" : "No") << endl;
    if(ts.satisfiable()){
        auto ans_locate = ts.answer();
        for (int i = 0; i < N; i++)
        {
            if(ans_locate[i]) cout << X[i].x << "\n";
            else cout << X[i].y << "\n";
        }
    }
    return 0;
}   

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


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

int main(){
	string s, t;
	int N, K, i, j, k;
	cin >> s;
	scanf("%d", &K);
	N = s.size();
	t = s;
	reverse(t.begin(), t.end());
	char *S = (char *)malloc(sizeof(char) * (N + 1));
	for(i = 1; i <= N; i++){
		S[i] = s[i - 1];
	}
	char *T = (char *)malloc(sizeof(char) * (N + 1));
	for(i = 1; i <= N; i++){
		T[i] = t[i - 1];
	}
	vector<vector<vector<int> > > dp(N + 1, vector<vector<int> >(N + 1, vector<int>(K + 1, 0)));
	for(i = 1; i <= N; i++){
		for(j = 1; j <= N; j++){
			dp[i][j][0] = max(dp[i - 1][j][0], dp[i][j - 1][0]);
			if(S[i] == T[j]){
				dp[i][j][0] = max(dp[i][j][0], dp[i - 1][j - 1][0] + 1);
			}
		}
	}
	for(k = 1; k <= K; k++){
		for(i = 1; i <= N; i++){
			for(j = 1; j <= N; j++){
				dp[i][j][k] = max(max(dp[i - 1][j][k], dp[i][j - 1][k]), dp[i - 1][j - 1][k - 1] + 1);
				if(S[i] == T[j]){
					dp[i][j][k] = max(dp[i][j][k], dp[i - 1][j - 1][k] + 1);
				}
			}
		}
	}
	int ans = 0;
	for(i = 0; i <= N; i++){
		ans = max(ans, 2 * dp[i][N - i][K]);
	}
	for(i = 1; i <= N; i++){
		ans = max(ans, 2 * dp[i - 1][N - i][K] + 1);
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 110336
#include<iostream>
using namespace std;
int p[1<<20],n,q,a,i,j,c;
main(){
	cin>>n>>q;
	for(i=0;i<n;i++){cin>>a;p[a]=1;}
	for(i=0;i<q;i++){
		cin>>a;
		for(j=a-1;j>=0;j--){
			c=j;
			while(1){
				if(p[c]){
					cout<<j<<endl;
					goto E;
				}
				c+=a;
				if(c>300000)break;
			}
		}
	E:;
	}
}

Measured memory_bytes: 2332
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	string s;
	cin>>s;
	bool f=0;
	int n=sz(s);
	for(int i=0;i<sz(s);i++)
	{
		if(s[i]!=s[n-i-1])
			f=1;
	}
	for(int i=0;i<n/2;i++)
	{
		if(s[i]!=s[(n-1)/2-i-1])
			f=1;
	}
	for(int i=0;i<n/2;i++)
	{
		if(s[i+(n+1)/2]!=s[n-i-1])
			f=1;
	}
	if(f)
		cout<<"No\n";
	else
		cout<<"Yes\n";
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef vector<char> vc;
typedef vector<vector<char> > vvc;
typedef vector<double> vd;
typedef vector<vector<double> > vvd;
template<class T> using vv=vector<vector< T > >;
typedef deque<int> di;
typedef deque<deque<int> > ddi;
typedef deque<bool> db;
typedef deque<deque<bool> > ddb;

// cout pair
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {
s << p.first << " " << p.second << "\n"; return s;
}

// cout vector<pair>
template<typename T1, typename T2> ostream& operator<<(ostream& s, const vector<pair<T1, T2> >& vp) {
int len = vp.size(); s << "\n";
for (int i = 0; i < len; ++i) { s << vp[i]; }
  s << "\n"; return s;
}

// cout vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
int len = v.size(); s << "\n";
for (int i = 0; i < len; ++i) {
  s << v[i]; if (i < len - 1) s << "\t";
}
s << "\n"; return s;
}

// cout deque
template<typename T> ostream& operator<<(ostream& s, const deque<T>& v) {
int len = v.size(); s << "\n";
for (int i = 0; i < len; ++i) {
  s << v[i]; if (i < len - 1) s << "\t";
}
s << "\n"; return s;
}

// cout 2-dimentional vector
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
int len = vv.size();
for (int i = 0; i < len; ++i) { s << vv[i]; }
  return s;
}

// cout 2-dimentional deque
template<typename T> ostream& operator<<(ostream& s, const deque< deque<T> >& vv) {
int len = vv.size();
for (int i = 0; i < len; ++i) { s << vv[i]; }
  return s;
}

int main() {
  int n;
  scanf("%d", &n);
  vi r(n);
  rep (i, n) {
    scanf("%d", &r[i]);
  }
  vi mi(n);
  mi[0] = r[0];
  FOR (i, 1, n) {
    mi[i] = min(mi[i-1], r[i]);
  }
  int ans = INT_MIN;
  FOR (i, 1, n) {
    ans = max(ans, r[i] - mi[i-1]);
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 4388
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <cmath>
#include <time.h>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define LINF 0x3f3f3f3f3f3f3f3f
#define INF 0x3f3f3f3f
#define PI 3.14159265
#define RAND (rand()*rand())
#define MAX(x, y) ((x) > (y) ? (x):(y)) 
#define MIN(x, y) ((x) > (y) ? (y):(x))
#define ABS(x) ((x) > 0 ? ((x) : -(x)))
#define CEIL(x, y) (((x) + (y) - 1)/(y))
using namespace std;
const int MAXN = 1e5 + 5;
const ll MOD = 1e9 + 7;
int N, M, Q, T;
char str[MAXN];
vector<int> vec;
int main()
{
	int i, j;
	scanf("%d%d%s", &N, &M, str);
	i = N;
	while (i > 0) {
		int to = -1;
		for (j = i - 1; j >= MAX(0, i - M); --j) {
			if (str[j] == '0') to = j;
		}
		if (to == -1) {
			vec.clear();
			vec.push_back(to);
			break;
		}
		vec.push_back(i - to);
		i = to;
	}
	for (i = vec.size() - 1; i >= 0; --i) {
		printf("%d ", vec[i]);
	}
}

Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define input(n) scanf("%d",&n)
#define llinput(n) scnaf("%lld",&n)

ll p(ll n)
{
  return (ll)pow(n,5);
}
int main()
{
  ll n;
  cin>>n;
  int range = 0;
  for( range = 0;p(range)<=n;range++);
  //cout<<p(range)<<endl;
  for(ll i = -1e3;i<=1e3;i++)
  {
    for(ll j = -1e3;j<=1e3;j++)
      {if(p(i)-p(j)==n) {cout<<i<<" "<<j;return 0;}}
  }
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
int u,v;
int n,m;
 
int fa[100005];
 
void init() {
  for(int i=1;i<=n;i++) {
    fa[i]=i;
  }
}
 
int get(int x) {
  if(fa[x]==x) {
    return x;
  }
  return fa[x]=get(fa[x]);
}
 
int main() {
  scanf("%d %d",&n,&m);
  init();
  for(int i=1;i<=m;i++) {
    scanf("%d %d",&u,&v);
    int x=get(u);
    int y=get(v);
    if(x!=y) {
      fa[y]=x;
    }
  }
  int cnt=0;
  for(int i=1;i<=n;i++) {
    if(fa[i]==i) {
      cnt++;
    }
  }
  printf("%d",cnt-1);
  return 0;
}

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

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

    int res = 0;
    int mi = N + 1;
    rep(i, N) {
        int p;
        cin >> p;
        mi = min(mi, p);
        if(mi == p) res++;
    }
    cout << res << endl;
}


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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 30;

// ===============================================================================

int main() {
  // 出てくる文字の回数を数える
  ll hoge;
  cin >> hoge;
  string s;
  cin >> s;
  map<char, ll> moji;
  for (int i = 0; i < s.size(); i++) {
    moji[s[i]]++;
  }

  ll ans = 1;

  for (auto a : moji) {
    ans = ans * (a.second + 1) % MOD;
  }

  cout << ans - 1 << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define EPS (1e-15)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define bet(x, a, b) (a) <= (x) && (x) < (b)
typedef long long ll;
typedef unsigned long long ull;

int a[10000];

int main()
{
	int n;
	ll sum = 0;

	cin >> n;
	rep(i, n) cin >> a[i];

	sort(a, a + n);
	rep(i, n) sum += a[i];

	cout << a[0] << ' ' << a[n - 1] << ' ' << sum << endl;


	return 0;
}



Measured memory_bytes: 3180
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys,collections,itertools,re,math,fractions,decimal,random,array,bisect,heapq,string

# decimal.getcontext().prec = 50
# sys.setrecursionlimit(10000)
# MOD = 10**9 + 7


def solve(f):
    s = f.read_str()
    n = len(s)
    d = [collections.deque() for _ in xrange(26)]
    p = [-1] * n

    for i, si in enumerate(s):
        d[ord(si)-ord('a')].append(i+1)

    odd = None
    for i in xrange(26):
        if len(d[i])%2 == 1:
            if odd is not None: return -1
            odd = i

    if odd is not None: p[n/2] = d[odd][len(d[odd])/2]

    for i in xrange(1,n/2+1):
        mi = float('inf')
        si = None
        for j in xrange(26):
            if len(d[j]) < 2: continue
            if d[j][0] < mi:
                mi = d[j][0]
                si = j

        p[i-1] = d[si].popleft()
        p[n-i] = d[si].pop()

    return count_inversion(p)


class BinaryIndexedTree(object):
    """Binary Indexed Tree (1-indexed)"""
    def __init__(self, size, default=0):
        self.bit = [default for _ in xrange(size + 1)]
        self.size = size

    def sum(self, i):
        """sum 1 to i"""
        s = 0
        while i > 0:
            s += self.bit[i]
            i -= i & -i
        return s

    def add(self, i, x):
        """add x to bit[i]"""
        while i <= self.size:
            self.bit[i] += x
            i += i & -i


def count_inversion(a):
    n = len(a)
    ans = 0
    bit = BinaryIndexedTree(n)
    for i in xrange(n):
        ans += i - bit.sum(a[i])
        bit.add(a[i], 1)
    return ans


class Reader(object):
    def __init__(self, filename=None):
        self.file = open(filename) if filename is not None else None
        self.case = 1

    def __readline(self):
        return self.file.next().strip() if self.file else raw_input()

    def next_case(self):
        self.file.next()
        self.case += 1

    def read_int(self): return int(self.__readline())
    def read_float(self): return float(self.__readline())
    def read_long(self): return long(self.__readline())
    def read_decimal(self): return decimal.Decimal(self.__readline())
    def read_str(self): return self.__readline()

    def read_int_list(self): return map(int, self.__readline().split())
    def read_float_list(self): return map(float, self.__readline().split())
    def read_long_list(self): return map(long, self.__readline().split())
    def read_decimal_list(self): return map(decimal.Decimal, self.__readline().split())
    def read_str_list(self): return self.__readline().split()

if __name__ == '__main__':
    filename = sys.argv[1] if len(sys.argv) > 1 else None
    f = Reader(filename)
    if f.file:
        while True:
            print "Case #%d\n"%f.case, solve(f)
            try:
                f.next_case()
            except StopIteration:
                break
    else:
        print solve(f)


Measured memory_bytes: 16404
# 2019/08/09
from bisect import bisect_left

n=int(input())
acc=[0]
for i in range(1,n+1):
    acc.append(i+acc[i-1])
    if acc[i]==n:
        print(*range(1,i+1),sep='\n')
        exit()
    elif acc[i]>n:
        idx=i
        break

rem=acc[idx]-n

res=0
for i in range(1,idx+1):
    if i!=rem:
        print(i)

Measured memory_bytes: 3792
#include <iostream>
#include <cctype>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#define rep(i, n) for(int i = 0; i < n; ++i)
using namespace std;

int comp(const void* a, const void* b){
	return *(int*)a - *(int*)b;
}

int main() {
	int n, a[105], x = 0, y = 0;
	cin >> n;
	rep(i, n) cin >> a[i];
	qsort(a, n, sizeof(int), comp);
	rep(i, n){
		if(i % 2 == 0){
			x += a[i];
		}else{
			y += a[i];
		}
	}
	cout << abs(x - y) << endl;
}

Measured memory_bytes: 256
"""
    こんにちは。これはクシャルです
    
    Author : thekushalghosh (クシャル)
    Team   : CodeDiggers
 
    I prefer Python language over the C++ language :p :D
        
    Visit my website : thekushalghosh.github.io
"""
import sys,math,cmath,time
start_time = time.time()
##########################################################################
################# ---- THE ACTUAL CODE STARTS BELOW ---- #################

def qw(n):
    a = "abcdefghijklmnopqrstuvwxyz"
    if n == -1:
        return("")
    return(qw(n // 26 - 1) + a[n % 26])
def solve():
    n = inp()
    a = "abcdefghijklmnopqrstuvwxyz"
    q = qw(n - 1)
    print(q)
            
################## ---- THE ACTUAL CODE ENDS ABOVE ---- ##################
##########################################################################
 
def main():
    global tt
    if not ONLINE_JUDGE:
        sys.stdin = open("input.txt","r")
        sys.stdout = open("output.txt","w")
    t = 1
    for tt in range(t):
        solve()
    if not ONLINE_JUDGE:
        print("Time Elapsed :",time.time() - start_time,"seconds")
        sys.stdout.close()
    
#---------------------- USER DEFINED INPUT FUNCTIONS ----------------------#
def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    return(input().strip())
def invr():
    return(map(int,input().split()))
 
#------------------ USER DEFINED PROGRAMMING FUNCTIONS ------------------#
def counter(a):
    q = [0] * (max(a) + 1)
    for i in range(len(a)):
        q[a[i]] = q[a[i]] + 1
    return(q)
 
def string_counter(a):
    q = [0] * 26
    for i in range(len(a)):
        q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
    return(q)

#-----------------------------------------------------------------------#
        
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
    input = sys.stdin.readline
main()

Measured memory_bytes: 62708
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <tuple>
#include <cassert>

using namespace std;
#define MOD 998244353

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define mp(a,b) make_pair((a), (b))
#define mt(a,b,c) make_tuple((a),(b),(c))

typedef long long ll;

long long int t[301][90605];
long long int u[301][90605];
int main(){
    int n; cin >> n;

    vector<int> a(n);
    for(int i=0;i<n;i++) cin >> a[i];
    int sum = 0; rep(i,n) sum += a[i];
    rep(j,301) rep(i,90600){ t[j][i] = 0; u[j][i] = 0;}
    t[0][0] = 1; u[0][0] = 1;

    for(int i=1; i<=n;i++){
        rep(j,sum){
            t[i][j+a[i-1]] = (t[i][j+a[i-1]] + t[i-1][j]) % MOD;
            t[i][j] = (t[i][j] + 2*t[i-1][j]) % MOD;
        }
    }
    
    if(sum % 2 == 0 && t[n][sum / 2] != 0){
        for(int i=1; i<=n; i++){
            rep(j,sum){
                u[i][j+a[i-1]] = (u[i][j+a[i-1]] + u[i-1][j]) % MOD;
                u[i][j] = (u[i][j] + u[i-1][j]) % MOD;
            }
        }
    }
    long long int ans = 1;
    for(int i=0;i<n;i++) ans = (ans * 3) % MOD;
    if(sum % 2 == 0 && t[n][sum / 2] != 0){
        for(int i= (sum+1) / 2; i <= sum; i++) ans = (ans - 3 *t[n][i] + MOD) % MOD;
        ans = (ans + 3 * u[n][sum / 2] + MOD) % MOD;
    }else{
        for(int i= (sum+1) / 2; i <= sum; i++) ans = (ans - 3 *t[n][i] + MOD) % MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 426368
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;
int n,arr[101];
int cal(int a,int b){return (arr[a]+arr[b])*(abs(a-b));}
void Min(int &a,int b){a=min(a,b);}

int mem[3][101][101][101];
int dfs(int f,int num,int l,int r){
  if(l>r)return 0;
  if(l==r)return (arr[l]==l+1) ? INF:0;
  if(r-l==1)return (arr[l]==l+1||arr[r]==r+1)? cal(l,r):0;
  if(mem[f][num][l][r]!=-1)return mem[f][num][l][r];

  int res=INF;  
  for(int i=l+1;i<r;i++){
    if(f==0||f==1)
      if(arr[i]!=l+1){
	swap(arr[l],arr[i]);
	Min(res,cal(l,i)+dfs(0,0,l+1,i-1)+dfs(1,arr[i],i,r));
	swap(arr[l],arr[i]);
      }

    if(f==0||f==2)
      if(arr[i]!=r+1){
	swap(arr[i],arr[r]);
	Min(res,cal(i,r)+dfs(2,arr[i],l,i)+dfs(0,0,i+1,r-1));
	swap(arr[i],arr[r]);
      }
  }

  for(int i=l;i<r;i++){
    if(f==1)Min(res,dfs(1,num,l,i)+dfs(0,0,i+1,r));
    else if(f==2)Min(res,dfs(0,0,l,i)+dfs(2,num,i+1,r));
    else Min(res,dfs(0,0,l,i)+dfs(0,0,i+1,r));
  }

  return mem[f][num][l][r]=res;
}

int main(){
  cin>>n;
  for(int i=0;i<n;i++)cin>>arr[i];
  memset(mem,-1,sizeof(mem));
  cout<<dfs(0,0,0,n-1)<<endl;
}

Measured memory_bytes: 15184
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define NCLR(a) memset((a), -1 ,sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 1000000007;
static const int INF = 1 << 25;
static const LL LL_INF = 1152921504606846976;
static const int dx[] = { -1, 0, 1, 0, 1, -1, 1, -1 };
static const int dy[] = { 0, -1, 0, 1, 1, 1, -1, -1 };

int n, x, y, Data = 1;
string _array[ 8 ];

void solve( int _x, int _y ) {
	_array[ _y ][ _x ] = '0';
	for ( int i = 0; i < 4; i++ ) {
		for ( int j = 1; j <= 3; j++ ) {
			if ( _y + dy[ i ] * j < 0 || _x + dx[ i ] * j < 0 || _y + dy[ i ] * j >= 8 || _x + dx[ i ] * j >= 8 ) {
				break;
			}
			if ( _array[ _y + dy[ i ] * j ][ _x + dx[ i ] * j ] == '1' ) {
				solve( _x + dx[ i ] * j, _y + dy[ i ] * j );
			}
		}
	}
}

int main() {
	scanf( "%d", &n );
	for ( ; n--; ) {
		for ( int i = 0; i < 8; i++ ) {
			cin >> _array[ i ];
		}
		scanf( "%d %d", &x, &y );
		--x;
		--y;
		solve( x, y );
		printf( "Data %d:\n", Data );
		for ( int i = 0; i < 8; i++ ) {
			printf( "%s\n", _array[ i ].c_str() );
		}
		Data++;
	}
	return 0;
}

Measured memory_bytes: 1240
#include <stdio.h>
//#define scanf scanf_s
typedef long long int lli;

// ITP1_5_A
// H * Wの四角形を'#'で出力、ただし中心部分は'.'を出力
// H=0,W=0で終了
int main()
{
	int iInputH, iInputW;
	int iCnt1, iCnt2;

	scanf("%d %d", &iInputH, &iInputW);

	while (iInputH != 0 || iInputW != 0)
	{

		for (iCnt1 = 0; iCnt1 < iInputH; iCnt1++)
		{
			if (iCnt1 == 0 || iCnt1 == iInputH - 1)	// 一行目と最終行
			{
				for (iCnt2 = 0; iCnt2 < iInputW; iCnt2++)
				{
					printf("#");
				}
				printf("\n");
			}
			else	// 中心部分
			{
				for (iCnt2 = 0; iCnt2 < iInputW; iCnt2++)
				{
					if (iCnt2 == 0 || iCnt2 == iInputW - 1)	// 一つ目と最終列
					{
						printf("#");
					}
					else
					{
						printf(".");
					}
				}
				printf("\n");
			}
		}

		printf("\n");
		scanf("%d %d", &iInputH, &iInputW);
	}

	return 0;
}


Measured memory_bytes: 2032
#include<bits/stdc++.h>
#define rep(i,j,k) for(int i=j;i<=k;i++)
using namespace std;
template<typename T> void read(T &num){
	char c=getchar();T f=1;num=0;
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){num=(num<<3)+(num<<1)+(c^48);c=getchar();}
	num*=f;
}
template<typename T> void qwq(T x){
	if(x>9)qwq(x/10);
	putchar(x%10+'0');
}
template<typename T> void write(T x){
	if(x<0){x=-x;putchar('-');}
	qwq(x);putchar('\n');
}

int main(){
	int n,m;read(n);read(m);
	if(n>m)swap(n,m);
	rep(i,1,m)qwq(n);
	cout<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
  int n;
  cin >> n;
  string a;
  cin >> a;
  int count =0;
  for(int i=2;i<n;++i) {
    if(a[i]=='C'&&a[i-1]=='B'&&a[i-2]=='A') ++count;
  }
  cout << count;
}
    


Measured memory_bytes: 256