akhauriyash/Code-Regression huggingface dataset:
// khodaya khodet komak kon
#include <bits/stdc++.h>
#define pb push_back
#define ers erase
#define ins insert
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x)  cerr << #x << " = " << x << endl
#define kill(x) return cout << x, 0;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#pragma GCC optimize ("Ofast")
using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<pll> vpl;

const ld Pi = 3.14159265359;
const ll MOD = 1000 * 1000 * 1000 + 7;
const ll N = 2e5 + 10;
const ll INF = 1e18;
const ll LOG = 20;

ll n;

int main(){
	IOS;
	cin >> n;
	cout << (n - 2) * 180;
	
	
	
	
	
	
	
	return 0;
}






/*
     ,---,           ___                 ,--,
    '  .' \        ,--.'|_             ,--.'|                             ,--,
   /  ;    '.      |  | :,'            |  | :                           ,--.'|    ,---.        ,---,
  :  :       \     :  : ' :            :  : '                 .--.--.   |  |,    '   ,'\   ,-+-. /  |
  :  |   /\   \  .;__,'  /    ,--.--.  |  ' |     ,--.--.    /  /    '  `--'_   /   /   | ,--.'|'   |
  |  :  ' ;.   : |  |   |    /       \ '  | |    /       \  |  :  /`./  ,' ,'| .   ; ,. :|   |  ,"' |
  |  |  ;/  \   \:__,'| :   .--.  .-. ||  | :   .--.  .-. | |  :  ;_    '  | | '   | |: :|   | /  | |
  '  :  | \  \ ,'  '  : |__  \__\/: . .'  : |__  \__\/: . .  \  \    `. |  | : '   | .; :|   | |  | |
  |  |  '  '--'    |  | '.'| ," .--.; ||  | '.'| ," .--.; |   `----.   \'  : |_|   :    ||   | |  |/
  |  :  :          ;  :    ;/  /  ,.  |;  :    ;/  /  ,.  |  /  /`--'  /|  | '.'\   \  / |   | |--'
  |  | ,'          |  ,   /;  :   .'   \  ,   /;  :   .'   \'--'.     / ;  :    ;`----'  |   |/
  `--''             ---`-' |  ,     .-./---`-' |  ,     .-./  `--'---'  |  ,   /         '---'
                            `--`---'            `--`---'                 ---`-'
*/




Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<iomanip>
#include<vector>
#define rep(i,a,b) for(ll i=a;i<b;i++)
using namespace std;
using ll = long long;
const int M = 100000;


int main() {
	string s;
	ll ans=0,sum;

	cin>>s;

	rep(i, 0, 1 << s.size()-1) {
		sum = 0;
		rep(j, 0, s.size()) {
			if (1 & i >> j)sum = sum*10 + (int)(s[j] - '0');
			else ans += sum * 10 + (int)(s[j] - '0'),sum=0;
		}
	}
	cout<<ans<<endl;
}

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

int main(){
    int n, m, i, j, ans = 0;
    cin >> n >> m;
    vector<int> a(m+1, 0);
    for(i = 0; i < n; i++){
        int k;
        cin >> k;
        for(j = 0; j < k; j++){
            int num;
            cin >> num;
            a[num-1]++;
        }
    }

    for(i = 0; i < m; i++){
        // cout << a[i] << endl;
        if(n == a[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
# 貪欲+山登り(2点交換+1点更新)
import time
import random

d = int(input())
dd = d * (d + 1) // 2
*C, = map(int, input().split())
S = [list(map(int, input().split())) for i in range(d)]

# 貪欲法による初期解の構築
T = []
L = [-1 for j in range(26)]
for i in range(d):
    max_diff = -10**7
    arg_max = 0
    for j in range(26):
        memo = L[j]
        L[j] = i
        diff = S[i][j] - sum([C[k] * (i - L[k]) for k in range(26)])
        if diff > max_diff:
            max_diff = diff
            arg_max = j
        L[j] = memo
    T.append(arg_max)
    L[arg_max] = i


def calc_score(T):
    L = [-1 for j in range(26)]
    X = [0 for j in range(26)]
    score = 0
    for i in range(d):
        score += S[i][T[i]]
        X[T[i]] += (d - i) * (i - L[T[i]])
        L[T[i]] = i
    for j in range(26):
        score -= C[j] * (dd - X[j])
    return score


score = calc_score(T)
start = time.time()
while True:
    now = time.time()
    if now - start > 1.8:
        break
    # 1点更新
    i = random.choice(range(d))
    j = random.choice(range(26))
    memo = T[i]
    T[i] = j
    new_score = calc_score(T)
    T[i] = memo
    if new_score > score:
        T[i] = j
        score = new_score
    # 2点交換
    i0 = random.choice(range(d))
    z = random.choice(range(10))
    i1 = i0 - z if i0 > z else i0 + z
    T[i0], T[i1] = T[i1], T[i0]
    new_score = calc_score(T)
    T[i0], T[i1] = T[i1], T[i0]
    if new_score > score:
        T[i0], T[i1] = T[i1], T[i0]
        score = new_score
for t in T:
    print(t + 1)


Measured memory_bytes: 95964
#include<iostream>
#include<map>
#include<cctype>
using namespace std;

int dec(string s){
    map<char,int> m;
    m['m'] = 1000;
    m['c'] = 100;
    m['x'] = 10;
    m['i'] = 1;
    int ret = 0;
    for(int i = 0; i < s.length(); i++){
        int bias = 1;
        if(isdigit(s[i]))   bias = (s[i]-'0'), i++;
        ret += bias * m[s[i]];
    }
    return ret;
}

string enc(int i){
    string ret = "";
    if(i/1000){
        if(i/1000 > 1)  ret.push_back('0'+i/1000);
        ret.push_back('m');
        i %= 1000;
    }
    if(i/100){
        if(i/100 > 1)  ret.push_back('0'+i/100);
        ret.push_back('c');
        i %= 100;
    }
    if(i/10){
        if(i/10 > 1)  ret.push_back('0'+i/10);
        ret.push_back('x');
        i %= 10;
    }
    if(i>0){
        if(i > 1)  ret.push_back('0'+i);
        ret.push_back('i');
    }
    return ret;
}

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

    string s, t;
    for(int i = 0; i < n; i++){
        cin >> s >> t;
        cout << enc(dec(s)+dec(t)) << endl;
    }

    return 0;
}


Measured memory_bytes: 3164
#include <stdio.h>

int main(void){
    int H, W, i, j;
    //scan H and W until 0 0
    while(1){
        scanf("%d %d", &H, &W);
        if (H == 0 && W == 0 )
        break;

        for (i = 1; i <= H; i++){
            for (j = 1; j <= W; j++){
                printf("#");
            }
            printf("\n");
        };
        printf("\n");
    }
}

    


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

# AtCoder Beginner Contest
# Problem B

if __name__ == '__main__':
    from math import floor

    n, x = list(map(int, input().split()))
    m = [int(input()) for _ in range(n)]
    at_least_g = sum(m)
    diff = x - at_least_g

    if diff == 0:
        print(len(m))
    else:
        print(len(m) + floor(diff / min(m)))


Measured memory_bytes: 3060
#include <iostream>
#include <string>

using namespace std;

int pal(string s, int a, int n)
{
	int ans = 1, i;
	for(i = a - 1; i<n/2; i++)
	{
		if(s[i] != s[n - i - 1])
		{
			ans = 0;
			break;
		}
	}
	return ans;
}

int main()
{
	string s;
	int ans1, ans2, ans3, ans;
	cin>>s;
	ans1 = pal(s, 1, s.length());
	ans2 = pal(s, 1, (s.length() - 1)/2);
	s = s.substr((s.length() + 3)/2 - 1);
	ans3 = pal(s, 1, s.length());
	ans = ans1 + ans2 + ans3;
	if(ans == 3)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

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

 int main()
{
    long long int N, A, B, C, s, t;
    cin >> N >> A >> B;
    C = A + B;
    if(C != 0){
    s = N/C;
    t = N%C;}
    if(C == 0){
        cout << 0 << endl;
    }
    else if(t>=A){
        cout << (s+1)*A << endl;
    }
    else{
        cout << s*A + t << endl;
    }
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int int64_t
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define REPP(i, n) for (int i = 1; (i) < (int)(n+1); ++ (i))
#define REPR(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i=(m)-1; i>=(n); i--)
#define ALL(v) v.begin(), v.end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define SORTR(c) sort((c).begin(),(c).end(),greater<int>());
#define BIT(n) (1LL<<(n))
#define PCNT(x) __builtin_popcountll(x)
#define GCD(x,y) __gcd(x,y)
#define LCM(x,y) x/__gcd(x,y)*y
#define PB push_back
#define MP make_pair
#define endl "\n"
#define pa cout << ans << endl
#define p(x) cout << x << endl
#define pall(x) for(auto iter : x) p(iter)
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define yn(x) cout << (x ? "Yes" : "No") << endl
using namespace std;
using Graph = vector<vector<int> >;
using WeightedGraph = vector<vector<pair<int, int> > >;
typedef long double LD;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
const int MOD = 1000000007;
const int INF = 2000000000;
const long double PI = acosl(-1);
void print() {cout << endl;}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head; if (sizeof...(tail) != 0) cout << " ";print(forward<Tail>(tail)...);}
template <class T> void print(vector<T> &vec) {for (auto& a : vec) {cout << a; if (&a != &vec.back()) cout << " ";} cout << endl;}
template <class T> void print(vector<vector<T>> &df) { for (auto& vec : df) { print(vec);}}
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 power(int N, int M) {return M ? power(N * N, M / 2) * (M % 2 ? N : 1) : 1;}

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int N, K, S;
    cin >> N >> K >> S;

    int ans = 0;
    REP(i,K) cout << S << (i != N-1 ? " " : "");
    if (S == power(10,9)) {REP(i,N-K) cout << 1 << (i != N-1 ? " " : "");}
    else {REP(i,N-K) cout << S+1 << (i != N-1 ? " " : "");}
    print();
    return 0;
}

/*
cd ~/Desktop/Programming/AtCoder/contest/keyence2020/keyence2020_c && sh test.sh
cd ~/Desktop/Programming/AtCoder/contest/keyence2020/keyence2020_c && sh etest.sh
cd ~/Desktop/Programming/AtCoder/contest/keyence2020/keyence2020_c && sh submit.sh
*/


Measured memory_bytes: 1280
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int W = sc.nextInt();
		long[][] dp = new long[N + 1][W + 1];
		int[] weight = new int[N];
		int[] value = new int[N];

		for(int i = 0; i < N; i++) {
			weight[i] = sc.nextInt();
			value[i] = sc.nextInt();
		}

		for(int i = 0; i < N; i++) {
			for(int j = 0; j <= W; j++) {
				if(weight[i] <= j) {
					dp[i + 1][j] = Math.max(dp[i][j], dp[i][j - weight[i]] + value[i]);
				}else {
					dp[i + 1][j] = Math.max(dp[i][j], dp[i][j]);
				}
			}
		}

		System.out.println(dp[N][W]);

		sc.close();
	}
}


Measured memory_bytes: 127056
#include <bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include<cmath>
#include<string>
#define pb push_back
#define ll long long
#define ull unsigned long long
#define deb(x) cerr<<#x<<" "<<x<<"\n"
#define debi cerr<<"hey sparky\n"
#define x first
#define y second
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define newline cout<<"\n"
#define yes cout<<"YES"<<"\n"
#define no cout<<"NO"<<"\n"
#define nax (int)1e6+3
#define eps (double)1e-9
#define all(x) x.begin(),x.end()
#define int long long
using namespace std;
using namespace __gnu_pbds; 
typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> pdbs;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
//void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

// look for  all edge cases
//search for a pattern
		



signed main(){
	int n;
	cin >> n;
	vector<int> v(n);
	
	map<int,int> freq;
	int sum = 0;
	for(int i =0 ; i< n;i++){
		cin >> v[i];
		freq[v[i]]++;
		sum += v[i];
	}
	
	int q;
	cin >> q;
	while(q--){
		int b,c;
		cin >> b >> c;
		//debug(sum);
		sum -= freq[b]*b;
		freq[c] += freq[b];
		sum += freq[b]*c;
		freq[b] = 0;
		cout<<sum<<"\n";
	}
	
	return 0;
}

	



Measured memory_bytes: 9916
#!/usr/bin/python

from pprint import pprint
import sys

def solve(m1, d1, m2, d2):
    if m1 != m2:
        print(1)
    else:
        print(0)


if __name__ == "__main__":
    m1, d1 = map(int, sys.stdin.readline().strip().split(" "))
    m2, d2 = map(int, sys.stdin.readline().strip().split(" "))
    solve(m1, d1, m2, d2)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

using P = pair<int, int>;
using Event = pair<int, P>;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, q;
    cin >> n >> q;
    vector<Event> event;
    for(int i = 0; i < n; i++) {
        int s, t, x;
        cin >> s >> t >> x;
        event.emplace_back(Event(s - x, P(-1, x)));
        event.emplace_back(Event(t - x, P(0, x)));
    }
    for(int i = 0; i < q; i++) {
        int d;
        cin >> d;
        event.emplace_back(Event(d, P(1, i)));
    }
    sort(ALL(event));
    vector<int> ans(q);
    multiset<int> se;
    for(int i = 0; i < event.size(); i++) {
        int time = event[i].first;
        int query = event[i].second.first;
        int x = event[i].second.second;
        if(query == -1) {
            se.insert(x);
        } else if(query == 0) {
            se.erase(se.lower_bound(x));
        } else {
            ans[x] = (se.empty() ? -1 : *se.begin());
        }
    }

    for(int i = 0; i < q; i++) {
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 20200
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        char[] board = str.toCharArray();
        
        char current = board[0];
        int count = 0;
        for (int i = 0; i < board.length; i++) {
            if (board[i] != current) {
                count++;
                current = board[i];
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 24660
#include<bits/stdc++.h>
int main(void){
    int n,k,a,AK,h;
    std::cin>>n>>k>>a;
    h=a;
    for(int i=2;i<=n;++i) {
        scanf("%d",&AK);
        a=std::__gcd(a,AK);
        h=std::max(AK,h);
    }
    if(k%a==0&&k<=h) std::cout<<"POSSIBLE\r\n";
    else puts("IMPOSSIBLE");
}

Measured memory_bytes: 256
N, K = map(int, input().split())
A = list(map(int, input().split()))
A = sorted(A)

def ncr(n, r, p):
  num = den = 1
  for i in range(r):
    num = (num * (n - i)) % p
    den = (den * (i + 1)) % p
  return (num * pow(den, p - 2, p)) % p

Mod = 10**9+7
fac = [1, 1]
finv = [1, 1]
inv = [0, 1]
def COMinit():
  #N_C_kのN
  for i in range(2, N+10):
    fac.append(fac[-1]*i%Mod)
    inv.append((-inv[Mod%i] * (Mod//i)) % Mod)
    finv.append(finv[-1] * inv[-1] % Mod)


def COM(n, k):
  if n < 0 or k < 0 or n < k:
    return 0
  return fac[n] * (finv[k] * finv[n-k] % Mod) % Mod


COMinit()
p=10**9+7

ans = 0
for i in range(N-K+1):
  j = N-1-i
  #ans += A[j] * ncr(j, K-1, p)
  ans += A[j] * COM(j, K-1)
  ans %= p

for i in range(N-K+1):
  #ans -= A[i] * ncr(N-i-1, K-1, p)
  ans -= A[i] * COM(N-i-1, K-1)
  ans %= p

print(ans)

Measured memory_bytes: 104924
/*

                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                    prayer
*/

// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#include<numeric>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

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

    int n;
    cin>>n;
    string s;
    cin>>s;
    rep(i,s.size()){
        s[i]+=n;
        if(s[i]>'Z')s[i]-=26;
    }
    cout<<s<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MAX_N 10000
#define INF 1e9

using namespace std;

typedef int long long ll;
typedef int long l;
typedef pair<int, int> Pii;
const ll MOD = 1000000007;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, q;
    vector<int> a, m;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int tmp;
        cin >> tmp;
        a.push_back(tmp);
    }
    cin >> q;
    for (int i = 0; i < q; i++) {
        int tmp;
        cin >> tmp;
        m.push_back(tmp);
    }
    for (int i = 0; i < 1 << n; i++) {
        int ans = 0;
        for (int j = 0; j < n; j++) {
            if (i >> j & 1)
                ans += a[j];
        }
        for (int j = 0; j < q; j++) {
            if (ans == m[j]) {
                m[j] = -1;
            }
        }
    }
    for (int i = 0; i < q; i++) {
        if (m[i] == -1) {
            cout << "yes" << endl;
        } else {
            cout << "no" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3136
using System;

public class Hello
{
    public static void Main()
    {
        var s = Console.ReadLine().Trim();
        var sL = s.Length;
        var wsum = 0L;
        for (int i = 0; i < sL; i++)
            if (s[i] == 'W') wsum += i;
        long w = sL - s.Replace("W", "").Length;
        var ans = wsum - w * (w - 1) / 2L;
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 16220
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>

string s;
int dp[200100];

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

  dp[1]=1;
  dp[2]=1;

  cin>>s;
  rep(i,s.size()+1){
    if(i-3>=0)
      dp[i]=max(dp[i],dp[i-3]+2);
    FOR(j,1,3){
      if(i-j*2>=0&&s.substr(i-j*2,j)!=s.substr(i-j,j))
        dp[i]=max(dp[i],dp[i-j]+1);
    }
  }

  cout<<dp[s.size()]<<endl;

}

Measured memory_bytes: 2196
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 1000100;
int main() {
  vector<vector<int>> fac(MAXN);
  for (int i = 1; i < MAXN; ++i) {
    for (int j = i; j < MAXN; j += i) {
      fac[j].push_back(i);
    }
  }
  vector<int> cnts(MAXN);
  int n;
  cin >> n;
  vector<int> v(n);
  for (int &i: v) cin >> i;
  for (int i: v) {
    ++cnts[i];
  }

  int ans = 0;
  for (int i: v) {
    int cnt = 0;
    for (int j: fac[i]) {
      cnt += cnts[j];
    }
    if (cnt == 1) ++ans;
  }
  cout << ans << "\n";

}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using edge = pair<ll, P>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
using Graph = vector<vector<ll>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N;
    cin >> N;
    cout << N*(N-1)/2 << endl;

}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}


Measured memory_bytes: 256
n, m = map(int, input().split())

like = {}

for i in range(n):
  ancket = list(map(int,input().split()))
  for j in range(1, ancket[0]+1):
    if ancket[j] in like:
      like[ancket[j]] += 1
    else:
      like[ancket[j]] =1
sum = 0
#print(like)
for i in range(0,m):
  if (i + 1) in like:
    if like[(i+1)] == n:
      sum += 1
  
print(sum)
    


Measured memory_bytes: 3064
#include <iostream>
#include <stdio.h>
using namespace std;

int main()
{
    int d[10];
    for (int i = 0; i < 3; i++)
        scanf("%d", &d[i]);
    bool chk = true;
    int v = d[0];
    if (v != d[1])
    {
        if (v != d[2])
        {
            if (d[1] == d[2])
                chk = true;
            else
                chk = false;
        }
        else
        {
            chk = true;
        }
    }
    else
    {
        if (d[1] == d[2])
            chk = false;
        else
            chk = true;
    }

    if (chk)
    {
        printf("Yes");
    }
    else
    {
        printf("No");
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int gcd(int x,int y){
    if(y==0)return x;

    return gcd(y,x%y);
}
int lcm(int x,int y){
    return x*y/gcd(x,y);
}

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){

    long long N,A,B;
    cin>>N>>A>>B;

    long long ans=0;

    if((B-1-A)%2==1){
        ans=((B-1-A)+2-1)/2;
    }else{
        long long x,y,xa,xb,ya,yb;
        xa=A;
        ya=A;
        xb=B;
        yb=B;
        
        

        x=xa;
        xa=1;
        xb-=(x-1);
        if(xa!=xb){
        x+=((xb-1-xa)+2-1)/2;
        }

        y=(N-yb)+1;
        yb=N;
        ya+=ya+ans;
        if(ya!=yb){
            y+=((B-1-A)+2-1)/2;
        }

        ans=min(x,y);
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
ans=1
for i in range(int((m**0.5))+1, 0, -1):
    if m%i==0:
        a=i
        b=m//i
        if a*n<=m:
            ans=max(ans, a)
        if b*n<=m:
            ans=max(ans, b)
        
print(ans)

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

int main() {
  int ans=0, ct=0;
  char s;
  for(int i=0; i<3; i++){
    cin >> s;
    if(s=='R') {
      ct++;
      if(ans<ct) ans=ct;
    }
    else{
      ct=0;
    }
  }
  cout << ans;
  return 0;
}


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

using namespace std;

int main()
{
    string s; cin >> s;
    int Ans = 0;
    for(int i = 0;i<s.size()/2;i++){
        if(s[i] != s[s.size() - 1 - i])  Ans++;
    }
    cout << Ans;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int w, h, x, y;
  cin >> w >> h >> x >> y;
  double ans = double(w) * double(h) / 2;
  int ans2 = 2*x == w && 2*y == h;
  printf("%f %d\n", ans, ans2);
}

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

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


#define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++)
#define frep(i,m,n) for(ll (i)=(m); (i)<=(ll)(n); (i)++)
#define rrep(i,n) for(ll (i)=(n)-1; (i)>-1; (i)--)
#define frrep(i,m,n) for(ll (i)=(n); (i)>(ll)(m); (i)--)
#define ALL(x) (x).begin(), (x).end()

const ll INF = 100100100100100100;
const ll MOD = 1000000007;

// a^n
ll a_n(ll a, ll n);
// a^(-1) % MOD 
ll inv(ll a);
// (a+b+c)%MOD
ll madd(ll a, ll b, ll c);
// (a-b)%MOD
ll msub(ll a, ll b);
// (a*b*c)%MOD
ll mtime(ll a, ll b, ll c);
void factorial_map(vector<ll> &n, vector<ll> &ninv);


int main() {
    ll n, m; cin >> n >> m;
    vector<ll> nfac(m+5, 0), ninv(m+5, 0);
    factorial_map(nfac, ninv);

    ll ans = 0, bit = -1;

    rep(i, n+1) {
        bit *= -1;
        ll tmp = mtime(nfac[n], ninv[i], ninv[n-i]);
        tmp = mtime(tmp, nfac[m], ninv[m-i]);
        tmp = mtime(tmp, nfac[m-i], ninv[m-n]);
        tmp = mtime(tmp, nfac[m-i], ninv[m-n]);
        tmp *= bit;
        if(ans + tmp < 0) {
            ans = ans + tmp + MOD;
        }
        else {
            ans = madd(ans, tmp, 0);
        }
    }

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

ll a_n(ll a, ll n) { 
    if(n == 0) return 1;
    
    ll ret = a, count = 1;
    while(count * 2 < n) {
        ret *= ret;
        ret %= MOD;
        count *= 2;
    }
    if(count == n) return ret;
    else return (ret * a_n(a, n-count))%MOD;
}
ll inv(ll a) {
    return a_n(a, MOD-2);
}

void factorial_map(vector<ll> &n, vector<ll> &ninv) {
    n[0] = 1;
    for(ll i = 1; i < n.size(); i++) n[i] = (n[i-1] * i) % MOD;
    ninv[n.size()-1] = inv(n[n.size()-1]);
    for(ll i = n.size() - 2; i > -1; i--) ninv[i] = (ninv[i+1] * (i+1)) % MOD;
}

ll madd(ll a, ll b, ll c) {
    ll ret = (a+b) % MOD;
    return (ret+c) % MOD;
}

ll msub(ll a, ll b) {
    if(a < b) return (a-b+MOD) % MOD;
    else return (a-b) % MOD;
}

ll mtime(ll a, ll b, ll c) {
    ll ret = (a*b) % MOD;
    return (ret*c) % MOD;
}


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

using namespace std;
typedef long long ll;

int a[100001];
ll maxsum[100001], nsum[100001];

int main(void) {
    int N, K;
    scanf("%d%d", &N, &K);
    for(int i=1; i<=N; i++) {
        scanf("%d", a+i);
        nsum[i] = nsum[i-1] + a[i];
        maxsum[i]  = maxsum[i-1];
        maxsum[i] += (a[i] > 0) ? a[i] : 0;
    }

    ll ans = LLONG_MIN;
    for(int i=0; i<=N-K; i++) {
        ll tmp1 = maxsum[N] - (maxsum[K+i] - maxsum[i]);
        ll tmp2 = ((nsum[K+i] - nsum[i]) > 0) ? (nsum[K+i] - nsum[i]) : 0;
        ans = max(ans, tmp1 + tmp2);
    }

    return !printf("%lld\n", ans);
}

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

typedef long long ll;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	ll x, k, d;
	cin >> x >> k >> d;
	ll step = abs(x)/d;
	if (k <= step) {
		cout << abs(x) - k * d << endl;
	} else {
		if ((step % 2) == (k % 2)) {
			cout << abs(x) - step * d << endl;
		} else cout << d - (abs(x) - step * d) << endl;
	}
}


Measured memory_bytes: 3648
n = int(input())
judge_list = [input() for i in range(n)]

judge_dict = {"AC": 0, "WA": 0, "TLE": 0, "RE": 0}

for i in judge_list:
    judge_dict[i] = judge_dict[i] + 1

for k, v in judge_dict.items():
    print(k + " x " + str(v))

Measured memory_bytes: 16336
#include<iostream>
using namespace std;
#define MAX 100000
typedef long long llong;

int n, k;
llong T[MAX];

int check(llong P){
  int i = 0;
  for (int j=0; j<k; j++){
    int sum = 0;
    while (sum+T[i] <= P){
      sum += T[i];
      i++;
      if (i == n) return n;
    }
  }
  return i;
}

llong solve(){
  llong left = 0;
  llong right = 100000 * 10000;
  llong mid;
  while ( right - left > 1){
    mid = (left + right) / 2;
    int v = check(mid);
    if (v >= n) right = mid;
    else left = mid;
  }
  return right;
}

int main(){
  cin >> n >> k;
  for (int i=0; i<n; i++){
    cin >> T[i];
  }
  llong ans = solve();
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 3876
using System.Linq;
using System.Collections.Generic;
using System;

public class Hello
{
    public static void Main()
    {
        var sd = Console.ReadLine().Trim();
        var t = Console.ReadLine().Trim();
        var a = sd.ToCharArray();
        var tL = t.Length;
        var aL = sd.Length;
        var ss = new List<string>();
        for (int i = 0; i <= aL - tL; i++)
        {
            for (int j = 0; j < tL; j++)
                if (sd[i + j] != '?' && sd[i + j] != t[j]) goto next;
            ss.Add(createS(sd, t, i));
            next:;
        }
        Console.WriteLine(ss.Count() == 0 ? "UNRESTORABLE" : ss.OrderBy(x => x).First());
    }
    public static string createS(string sd, string t, int d)
    {
        var a1 = sd.Substring(0, d);
        var a3 = sd.Substring( d +  t.Length);
        return (a1 + t + a3).Replace('?', 'a');
    }
}

Measured memory_bytes: 13652
#include<iostream>

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

  if((a+b) == 15)
    {
      std::cout << '+' << std::endl;
    }
  else if((a*b) == 15)
    {
      std::cout << '*' << std::endl;
    }
  else
    {
      std::cout << 'x' << std::endl;
    }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=220,p=1000000007;
int read(){
	int f=1,g=0;
	char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-1;
	for (;isdigit(ch);ch=getchar()) g=g*10+ch-'0';
	return f*g;
}
int qpow(int x,int k){
	int t=1;
	for (;k;k>>=1){
		if (k&1) t=(ll)t*x%p;
		x=(ll)x*x%p;
	}
	return t;
}
int n,m,ans,a[N],s[N],pos[N],C[N][N],po[N],inv[N];
char ch[N];bool h[N];
int get_nex(char c,int i){
	for (;(i<=m)&&(h[i]||(ch[i]!=c));i++);
	return i;
}
int get_n(int i){
	for (;(i<=m)&&h[i];i++);
	return i;
}
bool check(int dep){
	memset(h,0,m+1);
	for (int i=1;i<=dep;i++){
		pos[i]=get_nex('r',1);
		if (pos[i]>m) return false;
		h[pos[i]]=1;
	}
	for (int i=1;i<=dep;i++)
	if (a[i]>1){
		pos[i]=get_nex('b',pos[i]+1);
		if (pos[i]>m) return false;
		h[pos[i]]=1;
	}
	for (int i=1;i<=dep;i++)
	for (int j=3;j<=a[i];j++){
		pos[i]=get_n(pos[i]+1);
		if (pos[i]>m) return false;
		h[pos[i]]=1;
	}
	return true;
}
void calc(int res,int r,int dep){
	int t=po[dep-1],s1=n+1,s2=0;
	for (int i=1;i<=min(n+1,m);i++){
		t=(ll)t*inv[s[i]]%p;
		s1+=(i>1)*2*s[i];
		s2+=2*s[i]*i;
	}
	if ((s1<s2)||(!check(dep-1))) return;
	ans=(ans+(ll)t*C[s1][s2])%p;
	for (int i=1;i<=r;i++){
		a[dep]=i;s[i]++;
		calc(res-i,min(i,res-i),dep+1);
		s[i]--;
	}
	a[dep]=0;
}
int main(){
	n=read();m=read();
	scanf(" %s",ch+1);
	C[0][0]=po[0]=inv[0]=1;
	for (int i=1;i<=214;i++){
		C[i][0]=1;po[i]=(ll)po[i-1]*i%p;
		inv[i]=qpow(po[i],p-2);
		for (int j=1;j<=i;j++) C[i][j]=(C[i-1][j]+C[i-1][j-1])%p;
	}
	calc(min(n+1,m),min(n+1,m),1);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 384
#include <cassert>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <memory>
#include <utility>
#include <limits>
#include "limits.h"
 
#define rep(i, a, b) for (long long (i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug " <<"LINE:"<<__LINE__<<"  "<< #i <<":"<< i << std::endl

 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if(b==0)return 1;

  if ((a == 0)||(mod!=-1&&(a+mod)%mod==0)) {
    return 0;
  }
 
  long long x = 1;
 
  while (b > 0) {
    if (b & 1) {
      x = (mod!=-1)?(x * a) % mod:x*a;
    }
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}
 
const long long MOD = 998244353;
// const long long MOD = 1e9 + 7;

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

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

  std::string s;
  std::cin>>s;

  ll n=s.size();

  std::vector<ll> len(n+1,0);

  len[1]=1;
  if(n>=2)len[2]=(s[0]==s[1])?1:2;

  rep(i,2,n){
    if(s[i]!=s[i-1])len[i+1]=len[i]+1;
    else len[i+1]=len[i-2]+2;
  }

  std::cout<<len[n]<<"\n";

  return 0;
}

Measured memory_bytes: 2196
#[allow(unused_imports)]
use std::{cmp::Reverse, collections::*};

#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Chars, Usize1},
};

#[allow(unused_imports)]
use itertools::Itertools;

#[allow(unused_imports)]
use num::Integer;

#[fastout]
pub fn main() {
    input! {
        l: usize,
        r: usize,
        d: usize,
    }

    println!("{}", r / d - (l - 1) / d);
}


Measured memory_bytes: 2172
N = int(input())
W =list(map(int, input().split()))

L=[]
R=[]
sum_l =0
sum_r =0
for i in range(N):
    sum_l+=W[i]
    sum_r+=W[N-i-1]
    L.append(sum_l)
    R.append(sum_r)

R.reverse()
ans = L[N-1]
for i in range(N-1):
    ans = min(ans,abs(L[i]-R[i+1]))
print(ans)


Measured memory_bytes: 3064
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<string.h>
using namespace std;
int dx[]={0,1,0,-1,0};
int dy[]={1,0,-1,0,0};
char m[30][30];
char str[30];
int bfs[30][30];
int main(){
	int a,b;
	while(scanf("%d%d",&a,&b),a){
		for(int i=0;i<a;i++)scanf("%s",m[i]);
		scanf("%s",str);
		for(int i=0;i<a;i++)for(int j=0;j<b;j++)bfs[i][j]=-1;
		queue<pair<int,int> > Q;
		for(int i=0;i<a;i++)for(int j=0;j<b;j++)if(m[i][j]=='A'){
			Q.push(make_pair(i,j));
			bfs[i][j]=0;
		}
		while(Q.size()){
			int row=Q.front().first;
			int col=Q.front().second;
			Q.pop();
			for(int i=0;i<4;i++){
				if(0<=row+dx[i]&&row+dx[i]<a&&0<=col+dy[i]&&col+dy[i]<b&&m[row+dx[i]][col+dy[i]]!='#'&&!~bfs[row+dx[i]][col+dy[i]]){
					bfs[row+dx[i]][col+dy[i]]=bfs[row][col]+1;
					Q.push(make_pair(row+dx[i],col+dy[i]));
				}
			}
		}
		int row,col;
		for(int i=0;i<a;i++)for(int j=0;j<b;j++)if(m[i][j]=='B'){
			row=i;col=j;
		}
		int len=strlen(str);
		bool ok=false;
		for(int i=0;i<500;i++){
			if(~bfs[row][col]&&bfs[row][col]<=i){
				printf("%d %d %d\n",i,row,col);ok=true;break;
			}
			if(str[i%len]=='2')row=min(row+1,a-1);
			if(str[i%len]=='4')col=max(col-1,0);
			if(str[i%len]=='6')col=min(col+1,b-1);
			if(str[i%len]=='8')row=max(row-1,0);
		}
		if(!ok)printf("impossible\n");
	}
}

Measured memory_bytes: 1072
from collections import Counter
while True:
    N,Q = map(int,input().split())
    if N == 0: break
    ctr = Counter()
    for i in range(N):
        src = list(map(int,input().split()))
        ctr.update(src[1:])
    ans_n = 0
    ans_d = -1
    for d,n in sorted(ctr.items()):
        if n > ans_n:
            ans_n = n
            ans_d = d
    if ans_n >= Q:
        print(ans_d)
    else:
        print(0)

Measured memory_bytes: 5996
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <set>
using namespace std;

int main(){
    char b; cin >> b;
    if(b == 'A'){
        cout << 'T';
    }
    else if (b == 'T')
    {
        cout << 'A';
    }
    
    else if (b == 'G')
    {
        cout << 'C';
    }

    else if (b == 'C')
    {
        cout << 'G';
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    //*
    int a, b;
    cin >> a >> b ;
    //*/
    
    /*
    vector<int> a(3);
    cin >> a.at(0) >> a.at(1) >> a.at(2) ;
    
    sort(a.begin(), a.end());
    */
    
    /*
    if( a % 3 == 0 || b % 3 == 0 || ( a + b ) % 3 == 0  ){
        cout << "Possible" << endl;
    } else {
        cout << "Impossible" << endl;
    }
    */
    
    cout << ( a - 1 ) * ( b - 1 ) << endl;

    return 0; 
}


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> TUP;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define mp(a,b) make_pair(a,b)
const ll MOD=1000000007;

ll maxx(ll x,ll y,ll z){
	return max(max(x,y),z);
}
ll minn(ll x,ll y,ll z){
	return min(min(x,y),z);
}
ll gcd(ll x,ll y){
	if(x%y==0) return y;
    else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
	return x*y/gcd(x,y);
}

int main(){
	ll N; cin>>N;
    ll cnt=0;
    vector<ll> a(N+1);
    rep1(i,N) cin>>a[i];
    ll i=1;
    while(i<N){
        if(i==a[i]){
            ll tmp=a[i];
            a[i]=a[i+1];
            a[i+1]=tmp;
            cnt++;
            i+=2;
          continue;
        }
        i++;
    }
  if(N==a[N]) cnt++;
  
	printf("%lld",cnt);
}

Measured memory_bytes: 1024
/**********************************************************************/
/********                                                      ********/
/********                     Writer:孙~~                      ********/
/********                       Lang:C++                       ********/
/********                     Status:Unknow                    ********/
/********                                                      ********/
/**********************************************************************/
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <queue>
#include <list>
#include <cstdlib>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <cstring>
#include <cmath>
//#include<bits/stdc++.h>
using namespace std;

const int INF=0x3f3f3f3f;

char s[20];

int main(){
	scanf("%s",s);
	int sum=0,ans=0;
	int n=strlen(s);
	for(int i=0;i<n;i++){
		sum+=s[i]-'0';
		int tmp;
		if(i==n-1) tmp=sum; else tmp=sum-1+(n-i-1)*9;
		ans=max(ans,tmp);
	}
	printf("%d",ans);
	return 0;
}




Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <iomanip>
#include <numeric>
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(c) c.begin(),c.end()

using namespace std;
typedef long long ll;

int main()
{
  ll N; cin >> N;
  for (ll h = 1; h <= 3500; h++) {
    for (ll n = 1; n <= 3500; n++) {
      ll numer = N*h*n;
      ll denom = 4*h*n - N*h - N*n;
      if (denom > 0 && numer % denom == 0) {
        cout << h << ' ' << n << ' ' << numer / denom << endl;
        return 0;
      }
    }
  }
  return 0;
}

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

int main()
{
  int N ;
  cin>>N ;
  int a[N] ;
  for(int i=0;i<N;i++) cin>>a[i] ;
  
  int button=1 ;
  for(int i=0;i<N;i++){
    button=a[button-1] ;
    if(button==2){
      cout<<i+1 ;
      return 0 ;
    }
  }cout<<-1<<endl ;
  
  return 0 ;
} 


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

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

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];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

ll f(string X) {
}

signed main() {
  string n;
  cin >> n;
  int K;
  cin >> K;

  int keta = len(n);

  int N = n.size();
  vector<vector<vector<ll>>> dp(N + 1,
                                vector<vector<ll>>(2, vector<ll>(K + 1)));
  dp[0][0][0] = 1;  // [桁][未満][K] = 個数
  rep(i, N) {
    int num = n[i] - '0';
    rep(j, 2) {
      rep(k, K + 1) {
        repp(d, 0, j ? 9 : num) {
          if (d != 0) {
            if (k + 1 > K)
              continue;
            else
              dp[i + 1][j | d < num][k + 1] += dp[i][j][k];
          } else
            dp[i + 1][j | d < num][k] += dp[i][j][k];
        }
      }
    }
  }
  ll ans = dp[N][1][K] + dp[N][0][K];
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

struct Combination{
    vector<long long> _fac,_finv,_inv;
    const int m = MOD;

    Combination(int sz) : _fac(sz),_finv(sz),_inv(sz){
        _fac[0] = _fac[1] = 1;
        _finv[0] = _finv[1] = 1;
        _inv[1] = 1;
        for(int i = 2; i <= sz; i++){
            _fac[i] = _fac[i-1]*i%m;
            _inv[i] = m-_inv[m%i]*(m/i)%m;
            _finv[i] = _finv[i-1]*_inv[i]%m;
        }
    }

    inline long long fac(int n){return _fac[n];}
    inline long long inv(int n){return _inv[n];}
    inline long long finv(int n){return _finv[n];}

    long long comb(int n,int k){
        if(n < k) return 0;
        if(n < 0 || k < 0) return 0;
        return _fac[n]*(_finv[k]*_finv[n-k]%m)%m;
    }
};


int main(){
    int N,K; cin >> N >> K;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];
    sort(A.begin(),A.end());
    Combination C(100010);
    ll ans = 0;
    rep(i,N){
        ans += (C.comb(i,K-1)*A[i]%MOD-C.comb(N-i-1,K-1)*A[i]%MOD+MOD)%MOD;
        ans %= MOD;
    }
    cout << ans << endl;
}



Measured memory_bytes: 3328
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Collection;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.stream.Stream;
import java.util.StringTokenizer;
import java.util.Optional;
import java.io.BufferedReader;
import java.util.Comparator;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        long a;
        long b;
        long c;
        long d;

        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            a = in.Int();
            b = in.Int();
            c = in.Int();
            d = in.Int();
            long max = Arrays.asList(a * c, b * c, a * d, b * d).stream().max(Comparator.naturalOrder()).get();
            out.println(max);
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    return null;
                }
            }
            return st.nextToken();
        }

        public int Int() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 34016
#include"bits/stdc++.h"
using namespace std;

//#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main()
{
    string S;
    cin >> S;
    int SLEN = S.length();

    int WORDS_LEN = 4;
    string WORDS[4] = {
        "dreamer",
        "eraser",
        "erase",
        "dream"
    };

    queue<string> matches;
    for (int i = 0; i < WORDS_LEN; i++) {
        if (S.find(WORDS[i]) == 0) matches.push(WORDS[i]);
    }

    while(!matches.empty()) {
        string matched = matches.front();
        matches.pop();

        if (matched == S) {
            cout << "YES" << endl;
            return 0;
        }

        int mlen = matched.length();
        string comp = S.substr(matched.length(), SLEN - mlen);
        for (int i = 0; i < WORDS_LEN; i++) {
            if (comp.find(WORDS[i]) == 0) matches.push(matched + WORDS[i]);
        }
    }

    cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 1196
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define rep(i,n) for(int i = 0;i < n;i++)
#define NIL = -1;

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

ll lcm(ll a,ll b){
    a / gcd(a,b) * b;
}
const ll mod = 1e9 + 7;

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

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

int main(){
    int n,r;
    cin >> n >> r;
    if (n >= 10) cout << r << endl;
    else cout << r + (100 * (10 - n)) << endl;
}   


Measured memory_bytes: 256