akhauriyash/Code-Regression huggingface dataset:
N, M, X = map(int, input().split())
ca = [list(map(int, input().split())) for _ in range(N)]
ans = 10 ** 18
chk = [0] * N

def dfs(next):
    global ans
    if next == N:
        rikai = [0] * M
        total = 0
        ansF = True
        for i in range(N):
            if chk[i] == 1:
                total += ca[i][0]
                for j in range(M):
                    rikai[j] += ca[i][j + 1]

        for i in rikai:
            if i < X:
                ansF = False
                break
        if ansF:
            ans = min(ans, total)
        return

    for i in range(2):
        chk[next] = i
        dfs(next + 1)
    return

dfs(0)

if ans == 10 ** 18:
    print(-1)
else:
    print(ans)

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

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair

#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)
#define MAX 1000010

long long cost[110][110];
int V;

int dijkstra(int s, int t) {
    long long d[110];
    bool used[110];
    fill(d, d + V, MAX);
    fill(used, used + V, false);
    d[s] = 0;
    while(true) {
        int v = -1;
        for(int u=0; u < V; u++){
            if (!used[u] && (v == -1 || d[u] < d[v])) v = u;
        }
        if (v == -1) break;
        used[v] = true;
        for (int u = 0; u < V; u++) {
            d[u] = min(d[u], d[v] + cost[v][u]);
        }
    }
    return d[t];
}

int main(){
    int k;
    while(cin >> V >> k, V+k){
        rep(i, 110) rep(j, 110) cost[i][j] = MAX;

        rep(p, k){
            int m;
            cin >> m;
            if(m == 1){
                int s, t;
                long long c;
                cin >> s >> t >> c;
                s--; t--;
                cost[s][t] = cost[t][s] = min(cost[s][t], c);
            }
            else if(m == 0){
                int s, t;
                cin >> s >> t;
                s--; t--;
                long long c = dijkstra(s, t);
                if(c == MAX) cout << -1 << endl;
                else cout << c << endl;
            }
        }
    }
}

Measured memory_bytes: 1260
#include <iostream>

int main() {
  int c[3][3];

  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      std::cin >> c[i][j];
    }
  }

  if (
    c[1][0] - c[1][1] == c[0][0] - c[0][1] && c[2][0] - c[2][1] == c[0][0] - c[0][1] &&
    c[1][1] - c[1][2] == c[0][1] - c[0][2] && c[2][1] - c[2][2] == c[0][1] - c[0][2]
  ) {
    std::cout << "Yes" << std::endl;
  } else {
    std::cout << "No" << std::endl;
  }
}

Measured memory_bytes: 256
// C - Vacation
// 参考：https://qiita.com/hkrutknouch/items/eb4c77aa93f9cb9705c2
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;

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

	vi a(N), b(N), c(N);
	for(int n=0; n<N; n++) cin>>a[n]>>b[n]>>c[n];

	vvi dp(N, vi (3));
	dp[0] = {a[0], b[0], c[0]};
	for(int n=1; n<N; n++){
		dp[n] = {
			a[n] + max(            dp[n-1][1], dp[n-1][2]),
			b[n] + max(dp[n-1][0],             dp[n-1][2]),
			c[n] + max(dp[n-1][0], dp[n-1][1])
			};
	}
	cout<< *max_element(dp[N-1].begin(), dp[N-1].end()) <<endl;
}

Measured memory_bytes: 6912
import sys

SIZE = 10
paper = []


def main():
    init()

    for line in sys.stdin:
        data = line.strip().split(',')
        i = int(data[0])
        j = int(data[1])
        size = int(data[2])

        if   size == 1:
            drop_small(i, j)
        elif size == 2:
            drop_medium(i, j)
        elif size == 3:
            drop_large(i, j)

    print count_white()
    print find_max()

def find_max():
    mx = 0
    for i in xrange(SIZE):
        for j in xrange(SIZE):
            mx = max(mx, paper[i][j])

    return mx

def count_white():
    c = 0
    for i in xrange(SIZE):
        for j in xrange(SIZE):
            if paper[i][j] == 0:
                c += 1

    return c

def init():
    global paper
    for i in xrange(SIZE):
        paper.append([0]*SIZE)


def check(i, j):
    if i < 0 or SIZE <= i:
        return False
    if j < 0 or SIZE <= j:
        return False

    return True


def drop(i, j):
    global paper
    if not check(i, j):
        return False

    paper[i][j] += 1
    return True


def drop_small(i, j):
    drop(i, j)
    drop(i - 1, j)
    drop(i + 1, j)
    drop(i, j - 1)
    drop(i, j + 1)


def drop_medium(i, j):
    drop_small(i, j)
    drop(i - 1, j - 1)
    drop(i - 1, j + 1)
    drop(i + 1, j - 1)
    drop(i + 1, j + 1)


def drop_large(i, j):
    drop_medium(i, j)
    drop(i - 2, j)
    drop(i, j - 2)
    drop(i, j + 2)
    drop(i + 2, j)

main()

Measured memory_bytes: 4332
import java.util.*;

//atcoderはScannerクラスのsc.next()で行ける
public class Main{
    public static void main (String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String S = sc.next();
        String ABC = "ABC";
        int cnt = 0;
        // abcabcabc
        for (int i = 0; i < n-2 ; i++){
            if(S.substring(i,i+3).equals(ABC)){
                cnt++;
            }
        }
        System.out.println(cnt);
    }
}

Measured memory_bytes: 35700
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll a,b,c,d,e,k;
  cin >> a >> b >> c >> d >> e >> k;
  if(e - a > k)cout << ":(" << endl;
  else cout << "Yay!" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <map>
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define IREP(i,j,n) for(int (i)=(j);(i)<(n);(i)++)
#define INF numeric_limits<double>::infinity()
constexpr long MOD = 1e9 + 7;
using namespace std;

int main() {
    long x, y;
    cin >> x >> y;
    
    int ans = 0;
    for (long c = x; c <= y; c *= 2) {
        ans++;
    }
    
    cout << ans << endl;
}


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

typedef long long ll;

int main (){

    vector<ll> a(3);
    for(ll i = 0; i < 3 ; i++){
      cin >> a[i];
    }
    sort(a.begin(),a.end());
    cout << (a[0]+a[1]==a[2]? "Yes":"No") << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define vi vector<int>
#define pb push_back
using namespace std;
const int N=1e5+5;
bool can[N];
int n,ans,dp[N];
vi v;
int main()
{
	for(int i=1;i<=1e5;i*=6)can[i]=true;
	for(int i=1;i<=1e5;i*=9)can[i]=true;
	for(int i=1;i<=1e5;i++)if(can[i])v.pb(i);
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		dp[i]=1e9;
		for(int j=0;j<v.size();j++)
		{
			if(v[j]>i)break;
			dp[i]=min(dp[i],dp[i-v[j]]+1);
		}
	}
	cout<<dp[n]<<endl;
	return 0;
}

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

struct Query{
  int c, x, y;
  Query(int c, int x, int y) : c(c), x(x), y(y){}
};

vector<Query> query;

#define SEG_LEN (1 << 18) 

int seg[SEG_LEN * 2];

void  add(int i, int x){
  i += SEG_LEN;
  seg[i] += x;
  while(true){
    i /= 2; 
    if(i == 0)break; 
    seg[i] = seg[i * 2] + seg[i * 2 + 1]; // ノードiの左右の子ノードの番号はそれぞれ 2i, 2i + 1
  }
}

int getSum(int l, int r){
  l += SEG_LEN;
  r += SEG_LEN;
  int ans = 0;
  while(l < r){ 
    if(l % 2){
      ans += seg[l];
      ++l; 
    }
    l /= 2;
    if(r % 2){
      ans += seg[r - 1];
      r--;
    }
    r /= 2;
  }
  return ans;
}

int main(){
  int n, q;
  cin >> n >> q;
  for(int i = 0; i < q; ++i){
    int c, x, y;
    cin >> c >> x >> y;
    query.push_back(Query(c, x, y));
  }

  for(auto qry : query){
    if(qry.c == 0)add(qry.x, qry.y);
    else cout << getSum(qry.x, qry.y + 1) << endl;
  }

  return 0;
}



Measured memory_bytes: 4972
#include <array>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;


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

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define PB push


#define MOD 1000000007LL
#define EPS 1e-10

LL memo[100005];
LL Factorial(LL n)
{
    if (memo[n] != 0) return memo[n];
    if (n == 1) return memo[n] = 1;
    return memo[n] = (n * Factorial(n - 1)) % MOD;
}

int main()
{
    LL N, M;
    cin >> N >> M;
    if (abs(N - M) >= 2)
    {
        cout << 0 << endl;
        return 0;
    }
    LL dog = Factorial(N);
    LL monkey = Factorial(M);
    LL ans = (dog * monkey) % MOD;
    if (N == M)
    {
        ans = (ans * 2) % MOD;
    }
    cout << ans << endl;
    return 0;
}


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

int main()
{
  int N; cin >> N;
  vector<vector<long>> UVW(N, vector<long>(3));
  for (int i = 0; i < N - 1; i++)
  {
    cin >> UVW[i][0] >> UVW[i][1] >> UVW[i][2];
  }
  
  vector<vector<long>> conn(N + 5, vector<long>());
  map<string, long> mp{};
  for (auto uvw : UVW)
  {
    long u = uvw[0], v = uvw[1], w = uvw[2];
    conn[u].push_back(v);
    conn[v].push_back(u);
    string su = to_string(u), sv = to_string(v);
    string suv = su + "," + sv;
    mp[suv] = w % 2;
  }
  
  bool exists[100005] = {};
  long D[100005] = {};
  vector<long> NW{1}, N_N{}, NXT{};
  exists[1] = 1;
  int cnt = 1;
  
  while (cnt < N)
  {
    for (int nw : NW)
    {
      NXT = conn[nw];
      for (int nxt : NXT)
      {
        if (exists[nxt] == false)
        {
          exists[nxt] = true;
          cnt++;
          string s_nn = to_string(min(nw, nxt)) + "," + to_string(max(nw, nxt));
          D[nxt] = (D[nw] + mp[s_nn]) % 2;
          N_N.push_back(nxt);
        }
      }
    }
    NW = N_N;
    N_N.clear();
  }
  
  for (int k = 1; k <= N; k++)
  {
    cout << D[k] % 2 << endl;
  }
  
  return 0;
}

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

int main(){
    int n,m;
    cin >> n >> m;
    vector<vector<int> > v(n+1);
    vector<pair<int,int> > py;
    map<pair<int,int>, int > mp;
    rep(i,m){
        int p,y;
        cin >> p >> y;
        py.push_back(make_pair(p,y));
        v[p].push_back(y);
    }
    rep(i,n){
        if(v[i+1].size())sort(v[i+1].begin(),v[i+1].end());
    }
    rep(i,n){
        if(v[i+1].size()){
            rep(j,v[i+1].size()){
                mp[make_pair(i+1,v[i+1][j])]=j+1;
            }
        }
    }
    rep(i,m){
        int a=mp[make_pair(py[i].first,py[i].second)];
        cout << setfill('0') << right << setw(6) << py[i].first;
        cout << setfill('0') << right << setw(6) << a << endl;
    }
}

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

#define int long long
#define INT int
#define MOD 1000000007

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
template <typename T>
void print(T x)
{
    std::cout << x << '\n';
}
typedef long long ll;

/* nの約数を求める関数*/
vector<int> enum_div(int n) //nの約数を列挙
{
    vector<int> divisor;
    for (int i = 1; i * i <= n; ++i)
    {
        if (n % i == 0)
        {
            divisor.push_back(i);
            if (i != 1 && i * i != n)
            {
                divisor.push_back(n / i);
            }
        }
    }
    return divisor;
}

int x;

bool fun(int A, int B)
{
    return A * A * A * A * A - B * B * B * B * B == x;
}

int fun2(int B, int P)
{

    int temp = ((B + P) * (B + P) + B * B) - (B + P + B) * (B + P + P);
    int temp2 = (B + P) * B * ((B + P) * (B + P) + (B + P) * B + B * B);
    return temp - temp2;
}

signed main()
{
    cin >> x;
    vector<int> y = enum_div(x);

    int a, b;

    for (auto p : y)
    {
        rep(i, 1e6)
        {
            int _x = i;
            int _y = _x - p;
            if (fun(_x, _y))
            {
                cout << _x << " " << _y << endl;
                break;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 3592
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const ll MOD = 1000000007;
const double EPS = 1e-9;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;


ll calc(int l, int r, int n){
    int ans=0;
    for(int i=1;i<=n;i++){
        int tmp=i;
        bool ch=true;
        if(i%10!=r)ch=false;
        while(tmp/10>0){
            tmp/=10;
        }
        if(tmp==l&&ch)ans++;
    }
    return ans;
}

int main(void) {

    itn n;
    cin>>n;

    ll ans=0;
    
    for(int l=1;l<10;l++){
        for(int r=1;r<10;r++){
            // cout<<l<<" "<<r<<" "<<calc(l,r,n)<<endl;
            ans+=calc(l,r,n)*calc(r,l,n);
        }
    }
    fin(ans);
}


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

public class Main {
	public static void main (String[] args) throws IOException
	{
		BufferedReader input = new BufferedReader (new InputStreamReader (System.in));

		String str = input.readLine();

		String want = input.readLine();

		boolean judge = false;

		if(want.length() == 1)
		{
			//入力した文字があるか判定
			for(int num = 0; num < str.length(); num++)
			{
				if(str.charAt(num) == want.charAt(0))
				{
					judge = true;
					break;
				}
			}
		}

		else
		{
			//入力した文字列が作れるか判定
			for(int start = 0; start < str.length(); start++)
			{
				if(str.charAt(start) == want.charAt(0))
				{
					//2文字以降の判定
					for(int next = 1; next < want.length(); next++)
					{
						//繋ぎ目を越える前
						if(next + start < str.length())
						{
							if(str.charAt(next + start) != want.charAt(next))
								break;
						}

						//繋ぎ目を超えた後
						else if(next + start >= str.length())
						{
							if(str.charAt(next + start - str.length()) != want.charAt(next))
								break;
						}

						//入力した文字列が作れた場合
						if(next + 1 == want.length())
							judge = true;
					}
				}
			}
		}

		if(judge)
			System.out.println("Yes");

		else
			System.out.println("No");
	}
}



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

typedef long long ll;

int main(){
	int N;
	cin >> N;
	ll ans = 0;
	rep(i,N){
		int a = i+1;
		if(a%3!=0 && a%5!=0) ans += a;
	}

	cout << ans << endl;
}


Measured memory_bytes: 3636
N,M=gets.split.map(&:to_i)

balls = Array.new(N,1)
reds = Array.new(N, false)
reds[0]=true

M.times{
    x,y=gets.split.map(&:to_i)
    x,y=x-1,y-1
    if reds[x]
        reds[y]=true
    end
    balls[x]-=1
    balls[y]+=1
    if balls[x]==0
        reds[x] = false
    end
}
puts reds.count(true)


Measured memory_bytes: 3324
n=int(input())
b=[int(i) for i in input().split()]
ans=[]
result=True
while len(b):
    for i,j in enumerate(b[::-1]):
        if len(b)-i==j:
            ans.append(j)
            b.pop(len(b)-(i+1))
            break
    else:
        result=False
        break
if result:
    for i in ans[::-1]:
        print(i)
else:
    print(-1)

Measured memory_bytes: 3064
def main():
    H, W = map(int, input().split())
    s_h, s_w = map(int, input().split())
    all_m = H * W
    del_h = s_h * W
    del_w = s_w * H
    zyu_huku = s_h * s_w
    nuri = (del_h + del_w) - zyu_huku
    remain = all_m - nuri
    print(remain)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
N, K = map(int, input().split())
x = list(map(int, input().split()))

ans = abs(x[-1] - x[0])*2
for i in range(N-K+1):
    l = x[i]
    r = x[i+K-1]
    if r < 0:
        ans = min(ans, -l)
    elif l > 0:
        ans = min(ans, r)
    else:
        ans = min(ans, -2*l + r)
        ans = min(ans, 2*r - l)
print(ans)

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

int main()
{
    int a, b;
    cin >> a >> b;

    int plug_count = 1;
    int tap_count = 0;
    while (plug_count < b)
    {
        plug_count += (a - 1);
        tap_count++;
    }

    cout << tap_count << endl;
    return 0;
}


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

int main(){
    long N,M;
    cin >> N >> M;
    
    if((N == 2) || (M == 2)){
        cout << 0 << endl;
        return 0;
    }
    if(N == 1){
        if(M == 1){
            cout << 1 << endl;
            return 0;
        }
        else{  
            cout << M-2 << endl;
            return 0;
        }
    }

    if(M == 1){
        if(N == 1){
            cout << 1 << endl;
            return 0;
        }
        else{  
            cout << N-2 << endl;
            return 0;
        }
    }

    if((N >= 3) && (M >= 3)){
        cout << (N-2) * (M-2) << endl;
        return 0;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <queue>
#include <math.h>
#include <assert.h>
#include <set>
#include <map>
#include <bitset>
#include <ctime>
#include <time.h>
#include <algorithm>
#include <cstdio>
#include <fstream>
#include <stack>
#include <ctype.h>
#include <numeric>
#include <sstream>
#include <unistd.h>
#include <unordered_map>
#include <unordered_set>
#include <limits>
#include <random>
#include <chrono>
#include <iomanip>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
#define endl '\n'
#define debug(name) DEBUG(#name, (name))
template<typename T>
void DEBUG(string label, T value) {
    cerr << "[" << label << " = " << value << "]\n";
}

void solve(){
    ll n;
    cin >> n;
    if(n == 2){
        cout  << 1 << endl;
        return;
    }
    ll ans = 1;
    for(ll i = 2; i * i <= n - 1; ++i){
        if((n-1) % i == 0){
            ans += 2;
            if((n-1)/i == i)
                ans--;
        }
    }
    ans++;
    for(ll i = 2; i * i <= n; ++i){
        if(n % i == 0){
            ll copy = n;
            while(copy % i == 0){
                copy /= i;
            }
            ans += (copy % i == 1);
        }
    }
    cout << ans << endl;
}


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

    int t;
    t = 1;
    while(t--)
        solve();

}


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

int main(){
     string s;
     cin >> s;
     int i=0;
     while(s[i] != 'A'){
          i++;
     }
     int a=i;
     int z;
     int count=0;
     while(s[i] != '\0'){
          if(s[i]== 'Z')
               z=i;
          i++;
     }
     cout << z-a+1 << "\n";
     return 0;
}


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

int main(){
  int N, a[4][110] = {}, b[4][110] = {};
  cin>>N;
  for(int i = 1; i <= 2; i++){
    for(int j = 1; j <= N; j++){
      cin>>a[i][j];
    }
  }

  b[1][1] = a[1][1];

  while(1){
    int f = 0;
    for(int i = 1; i <= 2; i++){
      for(int j = 1; j <= N; j++){//cout<<b[i][j]<<" ";
		if(b[i][j] + a[i][j+1] > b[i][j+1]) {b[i][j+1] = a[i][j+1] + b[i][j];f =1;}
		//	if(b[i][j] + a[i][j-1]  > b[i][j-1]) {b[i][j-1] = a[i][j-1] + b[i][j];f = 1;}
	if(b[i][j] + a[i+1][j]  > b[i+1][j]) {b[i+1][j] = a[i+1][j] + b[i][j];f = 1;}
	//	if(b[i][j] + a[i-1][j]  > b[i-1][j]) {b[i-1][j] = a[i-1][j] + b[i][j];f = 1;}
	/*	if(b[i][j] + a[i][j+1] > b[i][j+1]) {b[i][j+1]  += b[i][j];f =1;}
	if(b[i][j] + a[i][j-1]  > b[i][j-1]) {b[i][j-1] += b[i][j];f = 1;}
	if(b[i][j] + a[i+1][j]  > b[i+1][j]) {b[i+1][j] +=  b[i][j];f = 1;}
	if(b[i][j] + a[i-1][j]  > b[i-1][j]) {b[i-1][j] += b[i][j];f = 1;}*/
      }//cout<<endl;
    }//cout<<endl;int temp;cin>>temp;
    if(f == 0) break;
  }

  cout<<b[2][N]<<endl;
  
  return 0;
}


Measured memory_bytes: 256
N, D = map(int, input().split())
X = []

def is_integer_num(n):
    if isinstance(n, int):
        return True
    if isinstance(n, float):
        return n.is_integer()
    return False

final_ans=0

for i in range(0,N,1):
    X.append(list(map(int, input().split())))

for i in range(0,N-1,1):
    for j in range(i+1,N,1):
        res = 0
        for k in range(0,D,1):
            res = res + (X[i][k] - X[j][k]) ** 2
        res = res ** 0.5
        if is_integer_num(res):
            final_ans = final_ans+1
print(final_ans)


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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
struct Edge {
	ll to;
	ll cost;
};
using Graph = vector<vector<Edge>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 2.0 * asin(1.0);
const ll INF = 1L<<60;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ll MAX = 10000000;
/****** define constant end ********/
/****** define variable start ******/
string s, t;
/******* define variable end *******/
int solve() {
	cin >> s >> t;
	ll ans = 0;
	REP(i, s.size()){
		if(s.substr(i, 1) != t.substr(i, 1)){
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

int main() {
	//clock_t start = clock();
	cout << std::fixed << std::setprecision(10);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int end_solve = solve();
	/*
	clock_t end = clock();
	const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
	1000.0; printf("time %lf[ms]\n", time);
	*/

	return end_solve;
}


Measured memory_bytes: 3808
#include <bits/stdc++.h>
using namespace std;
#define SZ(v) int((v).size())
#define fi first
#define se second
#define em emplace_back
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define mk make_pair
typedef long long ll;
using pii = pair<int,int>;

template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
  stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
string to_string(char c) { return "'" + string(1, c) + "'";}
string to_string(string s) { return '"' + s + '"';}
string to_string(const char* s) { return to_string((string) s);}
template<typename A> string to_string(A);
template<typename A, typename B> string to_string(pair<A, B> p){
  return "(" + to_string(p.first) + ": " + to_string(p.second) + ")";}
template<typename A> string to_string(A v) {bool f = false; string r = "{"; 
  for (auto x: v) {if (f) r += ", "; r += to_string(x); f = true;} return r += "}";}
template<typename A> string to_string(vector<vector<A>> v) {string r; 
  for (auto x: v) r += "\n" + to_string(x); return r;}
void err(istream_iterator<string>) { cerr << endl; }
template<typename T,typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " =: " << to_string(a) << "; "; err(++it, args...); }
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
/*----------------------------------------------------------------------------------*/
int  mod = 1e9 + 7;
int const N = 200100;
typedef long long i64;
i64 INF = 1e18, NIN = -1 * INF;

/******************************/

int add(int a, int b){
  if(a + b >= mod)return a+ b - mod;
  return a + b;
}
int mul(int a, int b){
  return 1LL * a * b  % mod;
}
int power(int a, int b){
  int re = 1;
  while(b){
    if(b&1)re= mul(re, a);
    a = mul(a, a);
    b>>=1;
  }
  return re;
}

int fact[N], inv[N];

int ncr(int a, int b){
  if(a < 0 || b < 0 || a < b)return 0;
  return mul(fact[a], mul(inv[a-b], inv[b]));
}
int ncr(pii a){
  return ncr(a.fi, a.se);
}
void fac(){
  fact[1] = fact[0] = 1;
  for(int x =2; x<N; x++){
    fact[x] = mul(x, fact[x-1]);
  }
  inv[N-1] = power(fact[N-1], mod - 2);
  for(int x = N-2; x>= 0; x--){
    inv[x] = mul(x+1, inv[x+1]);
  }
}

void solve(){
  int x;
  cin >> x;
  int ans = (x/500) * 1000 + 5 * ((x  % 500)/5);
  cout << ans;
}

int32_t main() {
 
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);  int test = 1;
  // cin >> test;
  while(test--)solve();
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace V0022 {
    public class Program {
        public static void Main(string[] args) {
            while(true) {
                var n = int.Parse(Console.ReadLine());
                if(n == 0) break;

                var dp = new int[n][];
                for(var i = 0; i < n; i++){
                    dp[i] = new int[n];
                    for(var j = 0; j < n; j++) {
                        dp[i][j] = int.MinValue;
                    }
                }

                for(var i = 0; i < n; i++) {
                    dp[0][i] = int.Parse(Console.ReadLine());
                }

                for(var i = 1; i < n; i++) {
                    dp[1][i] = dp[0][i - 1] + dp[0][i];
                }

                for(var i = 2; i <= n; i++) {
                    for(var j = i; j < n; j++) {
                        dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j] - dp[i - 2][j - 1];
                    }
                }

                Console.WriteLine(dp.Max(a => a.Max()));
            }
        }
    }
}

Measured memory_bytes: 46212
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_5_A&lang=jp>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */
const ll MOD = 1e9+7;
ll solve(){
    ll res = 0;
    ll n,k; cin >> n >> k;
    res = 1;
    while(n--){
        (res *= k)%=MOD;
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    cout << solve() << endl;
    return 0;
}



Measured memory_bytes: 3212
s = str(input())
t= str(input())

sdict = {}
for i in range(len(s)):
    if s[i] not in sdict:
        sdict[s[i]]=[]
    sdict[s[i]].append(i+1)
    
#print(sdict)

#二分木探索
def search(list_,mark_,sta,gol):
    if  sta == gol:
            return list_[sta]
    else:
            mid = (gol+sta)//2
            if list_[mid]>mark_:
                return search(list_,mark_,sta,mid)
            else:
                return search(list_,mark_,mid+1,gol)

ans = 0
mark = 0
for _ in range(len(t)):
    target = t[_]
    if target not in sdict:
        ans = -1
        break
    else:
        if sdict[target][-1]<=mark:
            mark = sdict[target][0]
            ans += len(s)
        else:
            posi = search(sdict[target],mark,0,len(sdict[target])-1)
            mark = posi
        
if ans != -1:
    ans += mark
print(ans)


Measured memory_bytes: 7668
#include<bits/stdc++.h>
using namespace std;
int f[13]={0,1,2,1,3,1,3,1,1,3,1,3,1};
int main(){
	int a,b;
	cin>>a>>b;
	if(f[a]==f[b])cout<<"Yes"<<"\n";
	else cout<<"No"<<"\n";
	return 0;
}

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

int main(void){
  int n, count = 0;
  cin >> n;

  vector<int> a(200);

  for(int i = 0; i < n; i ++)
    cin >> a.at(i);

  while(true){
    bool flag = true;
    int i = 0;
    for(i = 0; i < n; i ++)
      if(a.at(i) % 2){
        flag = false;
        break;
      }
    
    if(flag == false) break;

    if(flag == true){
      for(int i = 0; i < n; i ++)
        a.at(i) /= 2;
      count ++;
    }
  }

  cout << count << endl;

  return 0;
}


Measured memory_bytes: 256
from decimal import Decimal

n1 = int(input())

r1 = Decimal(0)
for i1 in range(n1):
    t1 = [i for i in input().split()]
    if t1[1] == "JPY":
        r1 += Decimal(t1[0])
    else:
        r1 += Decimal(t1[0]) * Decimal(380000.0)

print(r1)

Measured memory_bytes: 5076
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) REV(SORT(V)) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define Vd vector<double>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b?gcd(b,a%b):a;} //最小公倍数

// デフォルト変数定義
int n,m,a,b,c,x,y,z;
double d,e,f;
string s,t;
//

signed main() {
  RAPID;
  IN2(a,b);
  if((a+b)%2==0) {
    OUT((a+b)/2);
  } else {
    OUT("IMPOSSIBLE");
  }
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::{min,max};
#[allow(unused_imports)]
use std::collections::BTreeMap;

fn main() {
    let n = read_i64() as usize;
    let xs = {
        let mut xs = vec![];
        for _ in 0..n {
            let x = read_i64();
            xs.push(x);
        }
        xs
    };
    if xs[0] != 0 {
        println!("-1");
        return;
    }
    let mut res = 0;
    for i in 0..n {
        if i != n-1 && xs[i+1] - xs[i] >= 2 {
            println!("-1");
            return;
        }
        if i == n-1 || xs[i] + 1 != xs[i+1] {
            res += xs[i];
        }
    }
    println!("{}", res);
}

#[allow(dead_code)]
fn read_line() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok();
    ret.pop();
    return ret;
}

#[allow(dead_code)]
fn read_i64() -> i64 {
    let ss = read_line();
    return ss.parse::<i64>().unwrap();
}

#[allow(dead_code)]
fn read_vec_i64() -> Vec<i64> {
    let mut res = vec![];
    let ss = read_line();
    for ts in ss.split_whitespace() {
        let x = ts.parse::<i64>().unwrap();
        res.push(x);
    }
    return res;
}

use std::fmt::Display;
#[allow(dead_code)]
fn write_vec_i64<T: Display>(xs: &Vec<T>) {
    if xs.len() == 0 {
        println!("");
        return;
    }
    print!("{}", xs[0]);
    for i in 1..xs.len() {
        print!(" {}", xs[i]);
    }
    println!("");
}


Measured memory_bytes: 6396
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

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

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;

const int INF = 1 << 30;
const long long INFL = 1LL << 60;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100;

int c[MAX];

int main() {
	int n;cin>>n;
	rep(i,MAX) c[i]=0;
	rep(i,n) {int a;cin>>a;c[a]++;}
	int ans=0, s=c[0], max_s=0;
	rep(i,MAX) {
		if(i>=2) s-=c[i-2];
		if(i<=MAX-2) s+=c[i+1];
		max_s=max(max_s,s);
	}
	cout<<max_s<<endl;
}


Measured memory_bytes: 640
import java.util.*;
import java.util.stream.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder(sc.next());

		int[] ai = { 0, 4, 6, 8 };
		Arrays.stream(ai)
			.filter(i -> i < sb.length() && sb.charAt(i) != 'A' || i == sb.length())
			.forEach(i -> sb.insert(i, "A"));
		System.out.println(sb.toString().equals("AKIHABARA") ? "YES" : "NO");
	}
}


Measured memory_bytes: 27092
fun main(args:Array<String>){
    val (N,K) = readLine()!!.split(" ").map{it.toInt()}
    var hp = readLine()!!.split(" ").map(String::toLong).sortedDescending()

    var total = 0L
    if(N <= K){
        print(0)
    }else{
        for(i in K..(N-1)){
           total  += hp[i]
        }
        print(total)
    }
    
}


Measured memory_bytes: 83528
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<ctime>
#include<deque>
#include<stack>
#include<functional>
#include<sstream>
//#include<cctype>
//#pragma GCC optimize(2)
using namespace std;
#define maxn 2000005
#define inf 0x7fffffff
//#define INF 1e18
#define rdint(x) scanf("%d",&x)
#define rdllt(x) scanf("%lld",&x)
#define rdult(x) scanf("%lu",&x)
#define rdlf(x) scanf("%lf",&x)
#define rdstr(x) scanf("%s",x)
typedef long long  ll;
typedef unsigned long long ull;
typedef unsigned int U;
#define ms(x) memset((x),0,sizeof(x))
const long long int mod = 1e9 + 7;
#define Mod 1000000000
#define sq(x) (x)*(x)
#define eps 1e-4
typedef pair<int, int> pii;
#define pi acos(-1.0)
//const int N = 1005;
#define REP(i,n) for(int i=0;i<(n);i++)
typedef pair<int, int> pii;
inline ll rd() {
	ll x = 0;
	char c = getchar();
	bool f = false;
	while (!isdigit(c)) {
		if (c == '-') f = true;
		c = getchar();
	}
	while (isdigit(c)) {
		x = (x << 1) + (x << 3) + (c ^ 48);
		c = getchar();
	}
	return f ? -x : x;
}

ll gcd(ll a, ll b) {
	return b == 0 ? a : gcd(b, a%b);
}
int sqr(int x) { return x * x; }


/*ll ans;
ll exgcd(ll a, ll b, ll &x, ll &y) {
	if (!b) {
		x = 1; y = 0; return a;
	}
	ans = exgcd(b, a%b, x, y);
	ll t = x; x = y; y = t - a / b * y;
	return ans;
}
*/


ll n, k;
ll s[maxn];
ll c[maxn<<2];
vector<ll>vc;
void add(ll  x) {
	while (x <maxn) {
		c[x]++; x += x & -x;
	}
}

ll query(ll x) {
	ll res = 0;
	while (x > 0) {
		res += c[x]; x -= x & -x;
	}
	return res;
}


int main() {
//	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> k;
	for (int i = 1; i <= n; i++) {
		ll x;
		rdllt(x);
		x -= k;
		s[i] = s[i - 1] + x;
	}
	for (int i = 0; i <= n; i++)vc.push_back(s[i]);
	sort(vc.begin(), vc.end());
	vc.resize(unique(vc.begin(), vc.end()) - vc.begin());
	for (int i = 0; i <= n; i++)s[i] = lower_bound(vc.begin(), vc.end(), s[i]) - vc.begin() + 1;
	ll res = 0;
	for (int i = 0; i <= n; i++) {
		res += query(s[i]); add(s[i]);
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 13808
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e18;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

ll sum[410];
ll dp[410][410];

ll cost(ll l, ll r){
    if(l+1 == r) return 0;
    if(dp[l][r] != -1) return dp[l][r];
    
    ll ans = LINF;
    FOR(c, l+1, r){
        ans = min(ans, cost(l, c) + cost(c, r) + sum[r] - sum[l]);
    }
    return (dp[l][r] = ans);
}

int main(){
    ll N; cin >> N;
    vl a(N); REP(i, N) cin >> a[i];
    REP(i, N) sum[i+1] = sum[i] + a[i];
    REP(i, 410) REP(j, 410) dp[i][j] = -1;
    
    cout << cost(0, N) << endl;
    return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
using ll = long long;
using namespace std;
int main(){
    int n,k,ans=0;
    cin>>n>>k;
    vector<int> p(n);
    rep(i,n){
        cin>>p[i];
    }
    sort(p.begin(),p.end());
    rep(i,k){
        ans+=p[i];
    }
    cout<<ans;
}


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

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){ 
  int n, k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  sort(a.begin(), a.end(), greater<ll>());

  ll res = 0;

  COMinit();

  for (int i = 0; i < n; i++) {
    (res += a[i]*COM(n-i-1, k-1)%MOD) %= MOD;
  }

  reverse(a.begin(), a.end());
  
  for (int i = 0; i < n; i++) {
    (res += MOD - a[i]*COM(n-i-1, k-1)%MOD ) %= MOD;
  }
  cout << res << endl;
  return 0;
} 

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

int main()
{
	int H;
	int N;
	string answer = "No" ;
	
	cin >> H >> N;

	vector<int> vec(N);

	for (int i = 0; i < N; i++) {
		cin >> vec.at(i);
	}

	sort(vec.begin(), vec.end(), greater<int>());

	int i=0;

	while (i < N ) {

		H -= vec.at(i);

		if (H <= 0) {
			answer = "Yes";
			break;
		}
		i++;
	}

	cout << answer << endl;

	return 0;

}

Measured memory_bytes: 640
x,n=[int(x) for x in input().split()]
if n!=0:
    p=[int(x) for x in input().split()]
    l=list(range(110))
    for i in p:
        l.remove(i)
    L=[]
    for i in l:
        L.append(abs(i-x))
    m=min(L)
    print(l[L.index(m)])
else:
    print(x)

Measured memory_bytes: 9140
n,m =map(int,input().split())
a =[]*m
b =[]*m
for i in range(m):
        l,r =map(int,input().split())
        a.append(l)
        b.append(r)

if max(a) <=min(b):
        print(min(b)-max(a)+1)
else:
        print(0)


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

int main(){ 
    int d;
  cin>>d;
    if(d==25){
       cout<< "Christmas";
    }else if(d==24){
 cout<< "Christmas Eve";
    }else if(d==23){
 cout<< "Christmas Eve Eve";
    }else{
 cout<< "Christmas Eve Eve Eve";
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using ll = long long;
using namespace std;

int main() {
  int w, a, b;
  cin >> w >> a >> b;
  if (a <= b) cout << max(0, b-a-w) << endl;
  else cout << max(0, a-b-w) << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
char t[11], s[11];
int a, b, x, y;
char u[11];
int main() {
	scanf(" %s %s", s, t);
	scanf("%d%d", &a, &b);
	scanf(" %s", u);
	x = 1; y = 1;
	for (int i = 0; i < 10; i++) {
		if (s[i] != u[i])x = 0;
		if (t[i] != u[i])y = 0;
	}
	if (x)a--;
	if (y)b--;
	printf("%d %d\n", a, b);
}

Measured memory_bytes: 128
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>
 
 
#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LINF 1000000000000000000 //9000000000000000000
#define DINF 100000000.0
#define PI 3.14159265358979
#define MAXI 7500000
 
using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;

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


 
int main(void){

	while(1){
		long long int n,m,p,a,b;

		cin>>n>>m>>p>>a>>b;
		
		if(n==0){
			break;
		}

		double d[31][31];

		LFOR(i,0,30){
			LFOR(j,0,30){
				d[i][j]=DINF;
			}
		}
		
		vector<double> t(n);
		long long int x,y;
		double z;

		vector<vector<double> > dp(m+1,vector<double>(1<<n,DINF));

		LFOR(i,0,n-1){
			cin>>t[i];
		}

		LFOR(i,1,p){
			cin>>x>>y>>z;
			d[x][y]=z;
			d[y][x]=z;
		}

		dp[a][0]=0.0;

		LFOR(i,0,(1<<n)-1){
			LFOR(j,1,m){
				LFOR(k,1,m){
					LFOR(l,0,n-1){
						if(!(i&(1<<l))){
							if(d[j][k]!=DINF){
								//cout<<k<<" "<<j<<" "<<l<<" "<<i<<" "<<(i&~(1<<l))<<" "<<d[k][j]<<endl;
								dp[k][i|(1<<l)]=min(dp[k][i|(1<<l)],(d[j][k]/t[l])+dp[j][i]);
								//cout<<d[j][k]/t[l]<<" "<<dp[j][i]<<endl;
								//cout<<dp[k][i|(1<<l)]<<endl;
							}
							
						}
						
					}
				}
			}
		}
		
		double mini=DINF;

		FOR(i,0,(1<<n)-1){
			mini=min(mini,dp[b][i]);
		}
		
		if(mini==DINF){
			cout<<"Impossible"<<endl;
		}else{
			printf("%.8lf\n",mini);
		}
	}

}



Measured memory_bytes: 3248
#include <stdio.h>

int main(void)
{
  char s[99];
  int i, n, ans=0;

  scanf("%s", s);
  for(n=0;s[n]!='\0';n++);
  for(i=0;i<n/2;i++){
    if(s[i]!=s[n-1-i]){
      ans=1;
      break;
    }
  }
  if(ans==0){
  for(i=0;i<(n-1)/2/2;i++){
    if(s[i]!=s[(n-1)/2-1-i]){
	ans=1;
	break;
    }
  }
  }
  if(ans==0){
  for(i=(n+3)/2-1;i<((n+3)/2+n)/2;i++){
    if(s[i]!=s[n-1-i]){
      ans=1;
      break;
    }
  }
  }

  if(ans==0)
  printf("Yes\n");
  if(ans==1)
    printf("No\n");

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()

constexpr int MOD = 1000000007;

class mint {
  int n;
public:
  mint(int n_ = 0) : n(n_) {}
  explicit operator int() { return n; }
  friend mint operator-(mint a) { return -a.n + MOD * (a.n != 0); }
  friend mint operator+(mint a, mint b) { int x = a.n + b.n; return x - (x >= MOD) * MOD; }
  friend mint operator-(mint a, mint b) { int x = a.n - b.n; return x + (x < 0) * MOD; }
  friend mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
  friend mint &operator+=(mint &a, mint b) { return a = a + b; }
  friend mint &operator-=(mint &a, mint b) { return a = a - b; }
  friend mint &operator*=(mint &a, mint b) { return a = a * b; }
  friend bool operator==(mint a, mint b) { return a.n == b.n; }
  friend bool operator!=(mint a, mint b) { return a.n != b.n; }
  friend istream &operator>>(istream &i, mint &a) { return i >> a.n; }
  friend ostream &operator<<(ostream &o, mint a) { return o << a.n; }
};

// c[gcd(i, j)] += a[i] * b[j]
vector<mint> zeta(vector<mint> f) {
  const int n = f.size();
  for (int i = 1; i < n; i++) {
    for (int j = i * 2; j < n; j += i) {
      f[i] += f[j];
    }
  }
  return f;
}

vector<mint> moebius(vector<mint> f) {
  const int n = f.size();
  for (int i = n - 1; i >= 1; i--) {
    for (int j = i * 2; j < n; j += i) {
      f[i] -= f[j];
    }
  }
  return f;
}

mint modpow(mint a, long long b) {
  mint res = 1;
  while (b > 0) {
    if (b & 1) res *= a;
    a *= a;
    b >>= 1;
  }
  return res;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N, K; cin >> N >> K;
  vector<mint> F(K + 1, 1);
  F[0] = 0;
  F = zeta(F);
  rep(i, K + 1) F[i] = modpow(F[i], N);
  F = moebius(F);
  mint ans;
  rep(i, K + 1) {
    ans += F[i] * i;
  }
  cout << ans << endl;
}

Measured memory_bytes: 4004