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

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 3.1415926535897932;
const ll INF = LLONG_MAX;
/****** define constant end ********/
/****** define variable start ******/
ll n;
/******* define variable end *******/
int solve() {
	cin >> n;
	if(n == 3){
		cout << 0 << endl;
		string tmp;
		cin >> tmp;
		if(tmp == "Vacant"){
			return 0;
		}
		cout << 1 << endl;
		string tmp2;
		cin >> tmp2;
		if(tmp2 == "Vacant"){
			return 0;
		}
		cout << 2 << endl;
		string tmp3;
		cin >> tmp3;
		if(tmp3 == "Vacant"){
			return 0;
		}
	}
	cout << 0 << endl;
	vector<string> ret;
	string tmp;
	cin >> tmp;
	ret.push_back(tmp);
	if(tmp == "Vacant"){
		return 0;
	}
	ll i = 0;
	ll j = n-1;
	for(ll k = 0;; k++){
		bool flag = true;
		if(i > j){
			return 0;
		}
		ll m = floor((long double)(i+j)/2);
		if(m % 2 == 1){
			flag = false;
		}
		cout << m << endl;
		string tmp;
		cin >> tmp;
		if(tmp == "Vacant"){
			return 0;
		}
		if(flag){
			ret.push_back(tmp);
			if(tmp == ret[0]){
				i = m+1;
			}else{
				j = m-1;
			}
		}else{
			ret.push_back(tmp);
			if(tmp != ret[0]){
				i = m+1;
			}else{
				j = m-1;
			}
		}
	}
	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: 852
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
 
using namespace std;
 
#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
 
const int INF = 10000000;
const double EPS = 1e-9;
const int mod = 1e9 + 7;

int main(){
	string s;
	cin>>s;
	map<char,char> mp;
	mp['2']='k';
	mp['3']='s';
	mp['4']='t';
	mp['5']='n';
	mp['6']='h';
	mp['7']='m';
	mp['8']='y';
	mp['9']='r';
	map<char,char> mp2;
	mp2['T']='a';
	mp2['L']='i';
	mp2['U']='u';
	mp2['R']='e';
	mp2['D']='o';

	string ans;
	for(int i = 0; i < s.size(); i+=2){
		if(s[i]=='0'){
			if(s[i+1]=='T') ans+="wa";
			else if(s[i+1]=='U') ans+="nn";
			else ans+="wo";
		}
		else{
			if(s[i]!='1') ans+=mp[s[i]];
			ans+=mp2[s[i+1]];
		}
	}
	cout<<ans<<endl;
}

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

using namespace std;

using ll = long long;

int main() {
    std::string S;
    ll K;

    cin >> S >> K;

    ll num_one = 0;
    for (ll i = 0; i < S.size(); ++i) {
        if (S[i] == '1') {
            ++num_one;
        } else {
            break;
        }
    }

    cout << (num_one >= K ? '1' : S[num_one]) << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define SIZE 13

int M,W;
int small,big,num_small,num_big;
int POW[SIZE];
int table[2][SIZE];
int dp[SIZE][1 << SIZE];

int calc(int a,int b){

	return abs(a-b)*(abs(a-b)-30)*(abs(a-b)-30);
}

void func(){

	for(int i = 0; i < M; i++){

		scanf("%d",&table[0][i]);
	}
	for(int i = 0; i < W; i++){

		scanf("%d",&table[1][i]);
	}

	small = 0;
	num_small = M;
	big = 1;
	num_big = W;

	if(M > W){

		swap(small,big);
		swap(num_small,num_big);
	}

	for(int i = 0; i <= num_small; i++){
		for(int state = 0; state < POW[num_big]; state++){
			dp[i][state] = -BIG_NUM;
		}
	}

	dp[0][0] = 0;

	int ans = 0;
	int next_state,next_value;

	for(int i = 0; i < num_small; i++){
		for(int state = 0; state < POW[num_big]; state++){
			if(dp[i][state] == -BIG_NUM)continue;

			for(int k = 0; k < num_big; k++){
				if(state & POW[k])continue;

				next_state = state+POW[k];
				next_value = dp[i][state]+calc(table[small][i],table[big][k]);

				ans = max(ans,next_value);
				dp[i+1][next_state] = max(dp[i+1][next_state],next_value);
			}
		}
	}

	printf("%d\n",ans);
}

int main(){

	POW[0] = 1;
	for(int i = 1; i < SIZE; i++){

		POW[i] = POW[i-1]*2;
	}

	while(true){
		scanf("%d %d",&M,&W);
		if(M == 0 && W == 0)break;

		func();
	}

	return 0;
}



Measured memory_bytes: 3360
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
  int h,w;
  cin >> h >> w;
  string s;
  for(int i=0; i<h; i++) {
    for(int j=0; j<w; j++) {
      cin >> s;
      if(s=="snuke") {
        cout << (char)('A'+j) << i+1 << endl;
      }
    }
  }
}

Measured memory_bytes: 256
#!/usr/bin/env python3

s = list(str(input()))
k = int(input())

count = [[s[0], 1]]


for i in range(1, len(s)):
    if count[-1][0] == s[i]:
        count[-1][1] += 1
    else:
        count.append([s[i], 1])
# print(count)

ans = 0
if len(count) == 1:
    ans += (count[0][1]*k)//2

elif count[0][0] != count[-1][0]:
    for i in range(0, len(count)):
        letter, num = count[i]
        ans += (num//2)*k
else:
    for i in range(1, len(count)-1):
        letter, num = count[i]
        ans += (num//2)*k

    letter, num = count[0][0], count[0][1]+count[-1][1]
    ans += (num//2)*(k-1)

    ans += count[0][1]//2
    ans += count[-1][1]//2

print(ans)


Measured memory_bytes: 3188
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

const int N = (int)3e5;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
ll nCr(ll n, ll r){
  if(n < r || r < 0) return 0;
  ll ret = 1;
  ret *= kaijo(n); ret %= MOD;
  ret *= mpow(kaijo(r), MOD-2); ret %= MOD;
  ret *= mpow(kaijo(n-r), MOD-2); ret %= MOD;
  return ret;
}

int main(void){
  ll n,a,b;
  cin>>n>>a>>b;
  if(a*b < n){
    cout<<-1<<endl;return 0;
  }
  if(a+b-1 > n){
    cout<<-1<<endl;return 0;
  }
  ll over = n-a;
  int now = 0;
  int next = 0;
  int prev = 0;
  while(prev < n){
    now = next + min(b, over+1);
    next = now;
    while(now > prev){
      cout<<now<<" ";
      now--;
      over--;
    }
    over++;
    prev = next;
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 2176
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef long long LL;

int main() {
	int n; cin >> n;
	VI x(n); rep(i, n)cin >> x[i];
	VI y = x;
	SORT(y);
	rep(i, n) {
		if (x[i] < y[n / 2])cout << y[n / 2];
		else cout << y[n / 2 - 1];
		puts("");
	}
}

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

int main() {
  int N, K;
  cin >> N >> K;
  
  vector<double> P(N+1);
  
  for (int i = 1; i < N+1; i++) {
    P.at(i) = 1.0;
    int count = 0;
    int me = i;
    if(i < K) {
      while(me < K) {
        me *= 2;
        count++;
      }
      for(int j = 0; j < count; j++) {
        P.at(i) *= 0.5;
      }
    }
  }
  
  double P_all = 0;
  for(int i = 1; i < N+1; i++) {
    P_all += P.at(i);
  }
  
  cout << std::setprecision(15) << P_all / N << endl;
      
}

Measured memory_bytes: 1024
use std::io;

#[derive(PartialEq, Eq, Copy, Clone)]
enum S {
    WA,
    AC,
}

struct Point {
    i: usize,
    a: S,
}

fn parse_first(line: &str) -> [usize; 2] {
    let mut it = line.split_whitespace().map(|a| a.parse().unwrap());
    let n = it.next().unwrap();
    let m = it.next().unwrap();

    debug_assert_eq!(it.next(), None);

    [n, m]
}

fn parse(line: &str) -> Point {
    let mut it = line.split_whitespace();

    let i: usize = it.next().unwrap().parse().unwrap();
    let a = match it.next().unwrap() {
        "AC" => S::AC,
        "WA" => S::WA,
        _ => panic!(""),
    };

    debug_assert_eq!(it.next(), None);

    Point { i: i - 1, a: a }
}

fn main() {
    let mut buf = String::new();
    let stdin = io::stdin();

    stdin.read_line(&mut buf).unwrap();
    let line = parse_first(&buf);
    let n = line[0];
    let m = line[1];

    let mut trials = Vec::<i64>::new();
    trials.resize(n, -1);

    let mut ac: usize = 0;

    for _ in 0..m {
        buf.clear();
        stdin.read_line(&mut buf).unwrap();
        let point = parse(&buf);
        let current = &mut trials[point.i];

        if 0 <= *current {
            continue;
        }

        if point.a == S::AC {
            *current = -(*current + 1);
            ac += 1;
        } else {
            *current -= 1;
        }
    }

    let wa = trials
        .iter()
        .fold(0, |sum, &a| if 0 < a { sum + a } else { sum });

    println!("{} {}", ac, wa);
}


Measured memory_bytes: 4352
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    if(s[2] == s[3] && s[4] == s[5]) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
	string s, s1 = "apple", s2 = "peach";
	vector<int> applePos, peachPos;
	getline(cin, s);
	int pos = 0;
	while(s.find(s1, pos) != -1) {
		pos = s.find(s1, pos);
		applePos.push_back(pos);
		pos += s1.length();
	}
	pos = 0; 
	while(s.find(s2, pos) != -1) {
		pos = s.find(s2, pos);
		peachPos.push_back(pos);
		pos += s2.length();
	} 
	for (int i = 0; i < applePos.size(); i++) {
		s.replace(applePos[i], s1.length(), s2);
	}
	for (int i = 0; i < peachPos.size(); i++) {
		s.replace(peachPos[i], s2.length(), s1);
	}
	cout << s << endl;
	return 0;
}


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

    vector<int> r(n);
    rep(i, n){
        cin >> r[i];
    }

    int ans = INT_MIN;
    int min_n = r[0];
    for(int i= 1; i<n; ++i){
        ans = max(ans, r[i]-min_n);
        min_n = min(min_n, r[i]);
    }
    cout << ans << endl;

    return 0;
}


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

int main()
{
    string s,t,u;
    int a,b;
    cin>>s>>t;
    cin>>a>>b;
    cin>>u;
    if(u==s) --a;
    else --b;
    cout<<a<<" "<<b<<endl;
    return 0;
}


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

int main()
{
    int N, A = 0;
    int B[100];

    cin >> N;
    for (int i = 0; i < N-1; i++) 
        cin >> B[i];

    A += B[0];

    for (int i = 1; i < N-1; i++){
        if(B[i-1] > B[i])
            A += B[i];
        else
            A += B[i-1];
    }
    A += B[N-2];

    cout << A << endl;

    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FALSE 0
#define TRUE 1

int main(){
    // int A, B, C;
    int N;
    // vector<int>     vA(100010, 0);
    // map<int64_t, int>   mP;
    int res;

    cin >> N;
    // for (int i=0; i<N; i++){
    //     int Ai;
    //     cin >> Ai;
    //     vA.at(Ai)++;
    //     AiMax = max(AiMax, Ai);
    // }

    res = 0;

    if (N < 100)
        res = min(N, 9);
    else if (N < 1000)
        res = 9 + N - 99;
    else if (N < 10000)
        res = 909;
    else if (N < 100000)
        res = 909 + N - 9999;
    else
        res = 90909;


    // for (int i=0; i<N; i++){
        // res = max(res, count3);
    // }

    cout << res << endl;
    return 0;
}


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

using namespace std;
                                                                          	
#define forn(i, x, n) for (int i = int(x); i <= int(n); ++i)
#define for1(i, n, x) for (int i = int(n); i >= int(x); --i)
#define file ""     
#define F first                       
#define S second 
#define pb push_back   

typedef long long ll; 
typedef pair <ll, ll> PII;
typedef double ld;
                                                                                          
const int N = 2e6 + 1; 
const int INF = 1e9 + 9;
const int B = 1e9 + 7;

int a[N], sz, st[N], l[N], r[N];
           
int main () {
#ifdef machine42
	freopen (file"in", "r", stdin);
	freopen (file"out", "w", stdout);
#endif		
	ios_base :: sync_with_stdio (0);
	cin.tie(0);

	int n;
	cin >> n;
	st[sz = 0] = 0;
	forn(i, 1, n) {
		cin >> a[i];
		while (sz && a[st[sz]] > a[i]) --sz;
		l[i] = st[sz] + 1;
		st[++sz] = i;
	}
	st[sz = 0] = n + 1;
	for1(i, n, 1) {
		while (sz && a[st[sz]] > a[i]) --sz;
		r[i] = st[sz] - 1;
		st[++sz] = i;
	}

	ll ans = 0;
	forn(i, 1, n)
		ans += 1ll * a[i] * (r[i] - i + 1) * (i - l[i] + 1);
	cout << ans << "\n";

	return 0;         	
}


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

int main(void){
    int a,b,c,d,e;
    cin>>a>>b>>c>>d>>e;
    if(a==0)cout<<1;
    else if(b==0)cout<<2;
    else if(c==0)cout<<3;
    else if(d==0)cout<<4;
    else if(e==0)cout<<5;
    return 0;
}


Measured memory_bytes: 3580
#include "bits/stdc++.h"
#define LF '\n'
#define ALL(x) x.begin(), x.end()
#define LEN(x) (int)x.size()
#define iostreamBooster() do{ cin.tie(nullptr); ios_base::sync_with_stdio(false); }while(0)
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;
template<class Itr>void dump(Itr begin, Itr end) {
  for(;begin != end; ++begin) clog << ' ' << *begin;
  clog << LF;
}

int H, W;
char mat[405][405];
bool vist[405][405];
constexpr int dx[] = {1, 0, -1, 0,  1, 1, -1, -1};
constexpr int dy[] = {0, 1, 0, -1,  -1, 1, 1, -1};

inline int getID(int y, int x) { return y*W + x; }

void slv(int y, int x, pii &cnt)
{
  if (vist[y][x]) return;
  vist[y][x] = true;
  if (mat[y][x] == '.') cnt.first++;  else cnt.second++;

  for(int i = 0; i < 4; ++i) {
    const int nx = x + dx[i];
    const int ny = y + dy[i];
    if (nx < 0 || ny < 0 || nx >= W || ny >= H) continue;
    if (mat[ny][nx] == mat[y][x]) continue;
    slv(ny, nx, cnt);
  }

  return;
}

signed main()
{
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    cin >> mat[i];
  }

  memset(vist, false, sizeof(vist));

  i64 ans = 0;
  for (int i = 0; i < H; ++i) {
    for(int j = 0; j < W; ++j) {
      pii hoge(0,0);
      slv(i, j, hoge);
      ans += (i64)hoge.first * hoge.second;
    }
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 13056
use std::env;
use std::io::*;
use std::str::*;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let s = stdin.bytes().map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok().unwrap()
}

fn main() {
    // main の引数
    /*
        引数なしのときargs.len() = 1;
    */
    let args: Vec<String> = env::args().collect();

    let n = read::<i32>();
    let m = read::<i32>();

    println!("{}", (n-1)*(m-1));
}


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

#define sc second
#define fr first

#define ll long long
#define pi pair<int,int>
#define ppi pair<pi,pi>
#define mp make_pair
using namespace std;


string s;
bool ispal(int i,int j)
{
    while(i < j)
    {
        if(s[i] != s[j])
            return 0;
        i++,j--;
    }
    return 1;
}
int main(){

    ios::sync_with_stdio(0);
    cin .tie(0),cout.tie(0);

     cin >> s;

    int n = s.size();
    s = "#" + s;

    if (ispal(1 , n) && ispal(1 , (n - 1) / 2) && ispal((n + 3) / 2 , n))
        cout << "Yes\n";
    else cout << "No\n";


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

int main(int argc, const char * argv[]) {

  int N, Q;
  string s;
  cin >> N >> Q >> s;
  vector<char> t(Q), d(Q);
  for (int i=Q-1; i>=0; i--) {
    cin >> t[i] >> d[i];
  }
  
  int li, ri;
  li = 0;
  ri = N-1;
  for (int i=0; i<Q; i++) {
    if (d[i] == 'L'){
      if (s[li] == t[i])
        li++;
      if (ri<N-1 && s[ri+1] == t[i])
        ri++;
    }else{
      if (s[ri] == t[i])
        ri--;
      if (li>0 && s[li-1] == t[i])
        li--;
    }
  }
  cout << max(ri - li + 1, 0) << endl;
  
  return 0;
}

Measured memory_bytes: 900
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  int ans=0;
  cin >> a >> b >> c;
  for(int i=a ; i<=b ; i++){
      if(c%i==0){
          ans++;
      }
  }
  cout << ans << endl;
}


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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  string s = "ACL";
  cin >> n;
  string ans = "";
  for (int i = 0; i < n; ++i) ans += s;
  cout << ans << '\n';
}

Measured memory_bytes: 3640
import java.util.Scanner;

class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int num[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    System.out.print(num[sc.nextInt()-1]);
  }
}

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

int main(){
    int N;
    long long c[5] = {0}; //M, A, R, C, H
    cin >> N;
    for(int i=0; i<N; i++){
        string tmps;
        cin >> tmps;
        if(tmps[0]=='M')c[0]++;
        if(tmps[0]=='A')c[1]++;
        if(tmps[0]=='R')c[2]++;
        if(tmps[0]=='C')c[3]++;
        if(tmps[0]=='H')c[4]++;
    }
    long long ret = 0;
    for(int i=0; i<5; i++){
        for(int j=i+1; j<5; j++){
            for(int k=j+1; k<5; k++){
                ret += c[i] * c[j] * c[k];
            }
        }
    }
    cout << ret;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

int n;
vector<char> c;

void solve() {
  auto cnt = vector<int>(26, 0);
  for (int i = 0; i < n; ++i) {
    ++cnt[c[i] - 'A'];
    if (i < n / 2) continue;

    auto inv = vector<P>(26);
    for (int x = 0; x < 26; ++x) inv[x] = {cnt[x], x};
    sort(begin(inv), end(inv), greater<P>());

    if (inv[0].first > inv[1].first + n - i - 1) {
      cout << (char)('A' + inv[0].second) << ' ' << i + 1 << endl;
      return;
    }
  }
  cout << "TIE" << endl;
}

int main() {
  while (cin >> n, n) {
    c = vector<char>(n);
    for (int i = 0; i < n; ++i) cin >> c[i];
    solve();
  }
  return 0;
}



Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N;
    cin >> N;
    vector<int> L(N);
    for(int i = 0;i < N;i++) {
        cin >> L.at(i);
    }
    long long int count = 0;
    sort(L.begin(),L.end(),greater<int>());
    for(int i = 0;i < N - 2;i++) {
        for(int j = i + 1;j < N - 1;j++) {
            int k = j + 1;
            while(k < N && L.at(i) < L.at(j) + L.at(k)) {
                    count++;
                    k++;
            }
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    // Your code here!
    int n;
    int a[200001];
    int b[200001]={};
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    
    for(int i=n;i>0;i--){
        int sum=0;
        for(int j=n/i;j>1;j--){
            sum+=b[j*i];
        }
        b[i]=(sum+a[i])%2;
    }
    int co=0;
    for(int i=1;i<=n;i++){
        if(b[i]==1)co++;
    }
    printf("%d\n",co);
    int ini=1;
    for(int i=1;i<=n;i++){
        if(b[i]==1 && ini)printf("%d",i),ini--;
        else if(b[i]==1)printf(" %d",i);
    }
    printf("\n");
    return 0;
}

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

#define ll long long int
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mod 1000000007

int main() 
{
    FIO;
    int a,b,t,n,k,i,j;
    cin >> a >> b;
    
    n=max(a,b);
    j=min(a,b);
    
    a=j;
    b=n;
    
    k=a+(b-a)/2;
    
    if(k-a==b-k)
        cout << k ;
    else
        cout << "IMPOSSIBLE";
    
    
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<tuple>


#define MOD 1000000007
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back

typedef long long ll;

using namespace std;

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

int main(){
    char c;
    cin>>c;
    cout<<char(int(c)+int(1));

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <climits>

#define X first
#define Y second
#define vsort(v) sort((v).begin(), (v).end())
#define vrev(v) reverse((v).begin(), (v).end())


//INT_MAX
//INT_MIN
//LLONG_MAX
//LLONG_MIN
//DBL_MIN
//DBL_MAX
//LDBL_MIN
//LDBL_MAX

using namespace std;
using ll = long long;

int main(int argc, const char * argv[]) {
    int n;
    cin >> n;
    int ans = 0, cnt;
    for (int i = 1; i <= n; i++) {
        if (i % 2 != 0) {
            cnt = 0;
            for (int j = 1; j <= i; j++) {
                if (i % j == 0) {
                    cnt++;
                }
            }
            if (cnt == 8) {
                ans++;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
    // template start ---8<-----------8<---
	FastScanner sc = new FastScanner(System.in);
	static PrintWriter out;

	public static void main(String[] args) throws IOException {
		out = new PrintWriter(System.out);
		new Main().solve();
		out.flush();
	}
	// template end ---8<-----------8<---

	void solve() {
		int a = sc.nextInt();
		int b = sc.nextInt();
		if ((a * b) % 2 == 0)
		    out.println("Even");
		else
			out.println("Odd");
	}

    // template start ---8<-----------8<---
	class FastScanner {
		private final InputStream in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;

		FastScanner(InputStream in) {
			this.in = in;
		}

		private boolean hasNextByte() {
			if (ptr < buflen) {
				return true;
			} else {
				ptr = 0;
				try {
					buflen = in.read(buffer);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (buflen <= 0) {
					return false;
				}
			}
			return true;
		}

		private int readByte() {
			if (hasNextByte())
				return buffer[ptr++];
			else
				return -1;
		}

		private boolean isPrintableChar(int c) {
			return 33 <= c && c <= 126;
		}

		public boolean hasNext() {
			while (hasNextByte() && !isPrintableChar(buffer[ptr]))
				ptr++;
			return hasNextByte();
		}

		public String next() {
			if (!hasNext())
				throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (isPrintableChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			long n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while (true) {
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				} else if (b == -1 || !isPrintableChar(b)) {
					return minus ? -n : n;
				} else {
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}

		public int nextInt() {
			long nl = nextLong();
			if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
				throw new NumberFormatException();
			return (int) nl;
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}
	}

	class Random {
		private long seed;
		private final long multiplier = 0x5DEECE66DL, addend = 0xBL, mask = (1L << 48) - 1;
		int bits, val;

		Random(long seed) {
			this.seed = seed;
		}

		int nextInt(int n) {
			do {
				bits = (int) ((seed = (seed * multiplier + addend) & mask) >>> 17);
				val = bits % n;
			} while (bits - val + (n - 1) < 0);
			return val;
		}

		double nextDouble() {
			return nextInt(10000000) / 10000000.0;
		}
	}

	//final double TEMP = 0.1;
	final double TEMP = 10;
	static final long TL = 5850;
	static boolean submit = true;
    // template end ---8<-----------8<---

}



Measured memory_bytes: 21076
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<N;i++)
#define p(S) cout<<(S)<<endl
#define ck(a,b) (0<=(a)&&(a)<b)
using namespace std;

int main(){
	int n,d,x;
	cin>>n>>d>>x;
	int p[11][11];
	int dp[100010];
	int mx=x;

	REP(i,0,d) REP(j,0,n){
		cin>>p[i][j];
	}
	REP(i,0,d-1){
		memset(dp,0,sizeof(dp));
		REP(j,1,mx+1) dp[j]=j;
		int tmp=mx;
		REP(j,0,n){
			REP(k,p[i][j],mx+1){
				dp[k]=max(dp[k],dp[k-p[i][j]]+p[i+1][j]);
				tmp=max(mx,dp[k]);
			}
		}
		mx=tmp;
	}
	p(mx);
	return 0;
}

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

int main(void){
	int a,b;
	cin >>a>>b;
	
	if(a<b){
		for(int i=0; i<b; i++){
			cout<< a;
		}
	}else{
		for(int i=0; i<a; i++){
			cout << b;
		}
	}
}


Measured memory_bytes: 256
use proconio::{input, fastout};
use std::collections::HashMap;

const MAX: usize = 1_000_000;

#[fastout]
fn main() {
    input! {
        n: usize,
        aa: [usize; n],
    }

    let mut is_pairwise = true;
    let mut g = aa[0];

    let mut num = vec![0; MAX+1];

    for &a in aa.iter() {
        g = gcd(g, a);
        num[a] += 1;
    }

    for i in 2..=MAX {
        let mut x = 0;
        for j in (i..=MAX).step_by(i) {
            x += num[j];
        }
        if x >= 2 {
            is_pairwise = false;
            break;
        }
    }

    if g != 1 {
        println!("not coprime");
    } else if is_pairwise {
        println!("pairwise coprime");
    } else {
        println!("setwise coprime");
    }
}

fn gcd(a: usize, b: usize) -> usize {
    if a % b == 0 {
        b
    } else {
        gcd(b, a % b)
    }
}


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

int main()
{
  ll L,R;
  cin >> L >> R;
  R = min(R,L + 2019);
  int ans = 2019;
  for(ll i=L;i < R;i++){
    for(ll j=i+1;j <= R;j++){
      int r = i * j % 2019;
      ans = min(ans,r);
    }
  }
  cout << ans << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a;i<(int)b;++i)
int main(){
    int n,k;cin>>n>>k;
    ll r,s,p;cin>>r>>s>>p;
    string t;cin>>t;
    vector<bool> v(t.size(),true);
    ll ans=0;
    rep(i,t.size()){
        if(i<k||(i>=k&&(t[i-k]!=t[i]||v[i-k]==false))){
            v[i]=true;
            if(t[i]=='r')ans+=p;
            else if(t[i]=='s')ans+=r;
            else if(t[i]=='p')ans+=s;
        }
        else{
            v[i]=false;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 512
N = int(input())
a_arr = list(map(int, input().split()))

def main(arr):
    sum_sunuke = 0
    sum_arai      = sum(arr)
    min_val = 10**10
    
#     if N == 2:
#         return abs(arr[0]- arr[1])
    
    for i in range(N-1):
        sum_sunuke += arr[i]
        sum_arai      -= arr[i]
        val = abs(sum_sunuke - sum_arai)
#         print("sunuke: {}".format(sum_sunuke))
#         print("arai: {}".format(sum_arai))
        if min_val > val:
            min_val = val
#             print("min val: {}".format(min_val))
#         print("*************")
    return min_val

print(main(a_arr))

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

#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define SIZE(array) (sizeof(array) / sizeof(array[0]))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define MAX_V 100000

#define MOD 1000000007L
#define INF 100000000000

signed main() {
	int a, b;
	cin >> a >> b;
	vector<int> k = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 1 };
	string res = "Draw";
	if (a != b) {
		res = find(k.begin(), k.end(), a) > find(k.begin(), k.end(), b) ? "Alice" : "Bob";
	}
	cout << res << endl;
}


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

int main(){
  string S, str1, str2;
  ll i, N, count = 0;
  cin >> S;
  N = S.size();
  if(N%2 == 0){
    N /= 2;
    str1 = S.substr(0, N);
    str2 = S.substr(N, N);
    reverse(str2.begin(), str2.end());
  } else {
    N /= 2;
    str1 = S.substr(0, N);
    str2 = S.substr(N + 1, N);
    reverse(str2.begin(), str2.end());
  }
  rep(i, N){
    if(str1[i] != str2[i]){
      count++;
    }
  }

  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
/*  ex4_3
    potter0723sw  */

#include <stdio.h>

int add (int factorial);
int dif (int minuend,int subtrahend);

int main(void) {
    int diff, heighta, heightb, ans, addition;
    scanf("%d %d", &heighta, &heightb);
    diff = dif(heightb,heighta);//塔の差を計算
    addition = add(diff);//東の塔の高さを出す
    ans = dif(addition,heightb);//積雪の高さを本来の塔の高さと見えてる高さの差で出す
    printf("%d\n", ans);
    return 0;
}

int add (int factorial){//1から入力された値までをすべて足した和を返す関数
    if(factorial>1){
        factorial = factorial + add (factorial - 1);
    }else if(factorial == 1){
        factorial = 1;
    }
    return factorial;
}

int dif (int minuend,int subtrahend){//ただの引き算
    return (minuend - subtrahend);
}


Measured memory_bytes: 128
/// Bismillahir Rahmanir Rahim

#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define f0(n) for(int i=0;i<n;i++)
#define ms(x) memset(x,0,sizeof(x))
#define ins insert
#define ALL(v) v.begin(),v.end()
#define highest(x) numeric_limits<x>::max()
#define lowest(x) numeric_limits<x>::min()
#define Inf INFINITY
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define PI acos(-1)
#define IOS ios::sync_with_stdio(false);
using namespace std;
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const long long MOD = 1000000007;
template<typename T>inline T Bigmod(T base, T power, T MOD){
    T ret=1;
    while(power)
    {
        if(power & 1)ret=(ret*base)%MOD;
        base=(base*base)%MOD;
        power>>=1;
    }
    return ret;
}

bool sortinrev(const pair<int,int> &a,
               const pair<int,int> &b)
{
       return (a.first > b.first);
}
int main()
{
    IOS
    int n;
    while(cin>>n){
    double x = (double)2*1.0*PI*n*1.0 ;
    cout <<fixed<<setprecision(5)<<x<< endl;
    }
    return 0;
}
///Alhamdulillah


Measured memory_bytes: 3788
import java.io.*; 
import java.util.*; 

public class Main{ 
	
	static class FastReader{ 
		BufferedReader br; 
		StringTokenizer st; 

		public FastReader() 
		{ 
			br = new BufferedReader(new
					InputStreamReader(System.in)); 
		} 

		String next() 
		{ 
			while (st == null || !st.hasMoreElements()) 
			{ 
				try
				{ 
					st = new StringTokenizer(br.readLine()); 
				} 
				catch (IOException e) 
				{ 
					e.printStackTrace(); 
				} 
			} 
			return st.nextToken(); 
		} 

		int nextInt() 
		{ 
			return Integer.parseInt(next()); 
		} 

		long nextLong() 
		{ 
			return Long.parseLong(next()); 
		} 

		double nextDouble() 
		{ 
			return Double.parseDouble(next()); 
		} 

		String nextLine() 
		{ 
			String str = ""; 
			try
			{ 
				str = br.readLine(); 
			} 
			catch (IOException e) 
			{ 
				e.printStackTrace(); 
			} 
			return str; 
		} 
	}

	public static void main(String[] args) 
	{ 
        FastReader sc = new FastReader(); 
        //PrintWriter out = new PrintWriter(System.out); 

        int n = sc.nextInt();
        long w = sc.nextLong();
        int maxv = 0;
        long[][] arr = new long[n+1][2];
        
        for(int i=1;i<=n;i++){
        	for(int j=0;j<2;j++){
        		arr[i][j] = sc.nextLong();	
        		if(j!=0)
        			maxv+=(int)arr[i][j];
        	}
        }

        long[][] dp = new long[n+1][maxv+1];
        for(int i=0;i<=n;i++)
        	for(int v=0;v<=maxv;v++)
        		if(v!=0)
        			dp[i][v] = -1;

        for(int i=1;i<=n;i++){
        	for(int v=0;v<=maxv;v++){
            	if(arr[i][1]<=v && dp[i-1][v-(int)arr[i][1]] != -1){
            		if(dp[i-1][v]!=-1)
            			dp[i][v] = Math.min( dp[i-1][v], dp[i-1][v-(int)arr[i][1]] + arr[i][0] );
            		else
            			dp[i][v] = dp[i-1][v-(int)arr[i][1]] + arr[i][0];
            	}
            	else{
            		dp[i][v] = dp[i-1][v];
            	}
        	}
        }

        long ans = 0L;
        for(int v=maxv;v>=0;v--)
        	if(dp[n][v]<=w && dp[n][v]!=-1){
        		ans = v;
        		break;
        	}

        System.out.println(ans);
        //out.close();
	}
}


Measured memory_bytes: 125232
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <map>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
    string s;
    cin >> s;
    for(int i=0,sz=s.length(); i<sz; ++i){
        if(s[i]!='D'&&s[i]!='P') s[i]='D';
    }
    cout << s << endl;
    return 0;
}


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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;

int a[16];
int x[16][16];
int y[16][16];

int count(int v, int n) {
  int ret = 0;
  for (int i = 0; i < n; i++) {
    if ((v >> i) & 0x1) {
      ret++;
    }
  }
  return ret;
}

bool solve(int v, int n) {
  // cout << "v=" << v << endl;
  bool ret = true;
  for (int i = 0; i < n; i++) {
    if ((v >> i) & 0x1) {
      for (int j = 0; j < a[i]; j++) {
        // cout << "x=" << x[i][j] << ",y=" << y[i][j] << endl;
        int p = x[i][j] - 1;
        if (((v >> p) & 0x1) != y[i][j]) {
          return false;
        }
      }
    }
  }
  return ret;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    // int a;
    // cin >> a;
    cin >> a[i];
    for (int j = 0; j < a[i]; j++) {
      // int xi, yi;
      // cin >> xi >> yi;
      // x[i].push_back(xi);
      // y[i].push_back(yi);
      cin >> x[i][j] >> y[i][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < (int)pow(2, n); i++) {
    // cout << i << endl;
    // cout << count(i, n) << endl;
    if (count(i, n) != 0 && solve(i, n)) {
      ans = max(ans, count(i, n));
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
judge = [10, 20, 30, 40, 50, 60, 121]

while True:

    input_count = int(input())

    if input_count == 0:
        break

    data = [int(input()) for _ in range(input_count)]
    counter = [0] * 7

    for item in data:

        for index, j in enumerate(judge):
            if item < j:
                counter[index] += 1
                break

    counter = [str(item) for item in counter]
    print("\n".join(counter))



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

using namespace std;
using int64 = long long int;

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

	vector<int> digit(n, -1);

	for (int _ = 0; _ < m; _++)
	{
		int s, c;
		cin >> s >> c;

		s--;
		if ((digit[s] != -1 && digit[s] != c) || (s == 0 && c == 0 && n != 1))
		{
			cout << -1 << endl;
			return 0;
		}

		digit[s] = c;
	}

	for (size_t i = 0; i < digit.size(); i++)
	{
		int value = 0;
		if (i == 0 && n != 1)
		{
			value = 1;
		}
		value = max(value, digit[i]);
		cout << value;
	}

	cout << endl;
}

Measured memory_bytes: 256
#include<functional>
#include <algorithm>
#include <iostream>
#include <memory.h>
#include <string.h>
#include <string>
#include <math.h>
#include <time.h>
#include <vector>
#include <queue>
#include<stack>
#include <map>
#include <set>
#include <list>
#include <deque>
#include <bitset>
#include <limits>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long long ll;
const int M = 1e9 + 7;
const int N = 1e4 + 1;
const int oo = 1e9;
const double pi = acos(-1);
int main() {
	//freopen("input.txt", "r", stdin);
	int m, d;
	cin >> m >> d;
	int ans = 0;
	int d1, d2;
	while (d > 0) {
		d1 = d % 10;
		d /= 10;
		swap(d1, d2);
	}
	for (int i = 2; i <= d2; ++i) {
		for (int j = 2; j < 10; ++j) {
			if (i == d2 && j > d1)
				i = j = 10;
			if (i*j <= m)
				++ans;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int k,s;
	cin>>k>>s;
	int ans=0;
	for(int i=0;i<=k;i++){
		for(int j=0;j<=k;j++){
			if(i+j<=s&&s<=i+j+k)ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
int f[100010];
int main(){
	int N;scanf("%d",&N);
	for(int i=1;i<=N;i++)f[i]=f[i/10]+i%10;
	int ans=1<<30;
	for(int i=1;i<N;i++)if(f[i]+f[N-i]<ans)ans=f[i]+f[N-i];
	printf("%d\n",ans);
} 

Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <math.h>

typedef long long ll;
typedef long double ld;
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define PRECISION std::cout << std::fixed << std::setprecision(20);
  
using namespace std;
 
const ll inf = 1e18+1;
const int N = 4e5+1;
const ll mod = 998244353;
const int bits = 19;

ll fact[N];

ll power(ll x, ll n){
    // cout<<x<<" "<<n<<"\n";
    ll res = 1;
    x%=mod;
    while(n){
        if(n&1) res = (res*x)%mod;
        x = (x*x)%mod;
        n>>=1;
    }
    return res;
}

ll modInv(ll n){
    return power(n,mod-2);
}

ll ncr(ll n,ll r){
    if(r>n || r<0 || n<0) return 0;

    ll num = fact[n];
    ll denom = (fact[n-r]*fact[r])%mod;

    return (num*modInv(denom))%mod;
}

int main(){
    FASTIO;
    PRECISION;
    
    ll n,m,k;
    cin>>n>>m>>k;

    fact[0] = 1;
    for(int i=1;i<=n;i++){
        fact[i] = (i*fact[i-1])%mod; 
    }

    ll ans = 0;

    for(int i=0;i<=k;i++){
        ans += (((m*power(m-1,n-i-1))%mod)*ncr(n-1,i))%mod;
        
        // cout<<power(m-1,n-i-1)<<"\n";
        ans%=mod;
    }

    cout<<ans<<"\n";

    

}


Measured memory_bytes: 5144
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <map>
#include <numeric>
#include <functional>
#include <math.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)

class mod {
public:
    mod() {m_n = 0;}
    mod(ll n) {if (n >= 0) m_n = n % MOD; else m_n = n % MOD + MOD;}
    friend bool operator== (const mod& a, const mod& b) {return a.m_n == b.m_n;}
    friend bool operator!= (const mod& a, const mod& b) {return !(a == b);}
    friend mod operator+ (const mod& a, const mod& b) {return (a.m_n + b.m_n) % MOD;}
    friend mod& operator+= (mod& a, const mod& b) {return a = a + b;}
    friend mod operator- (const mod& a) {return -a.m_n;}
    friend mod operator- (const mod& a, const mod& b) {return (a.m_n + (-b.m_n)) % MOD;}
    friend mod& operator-= (mod& a, const mod& b) {return a = a - b;}
    friend mod operator* (const mod& a, const mod& b) {return (a.m_n * b.m_n) % MOD;}
    friend mod& operator*= (mod& a, const mod& b) {return a = a * b;}
    friend mod mod_pow(const mod& n, ll r) {
        if (r == 0) {
            return 1;
        } else if (r < 0) {
            return mod_pow(n, (MOD - 2) * (-r));
        } else if (r % 2 == 0) {
            mod tmp = mod_pow(n, r / 2);
            return tmp * tmp;
        } else {
            return n * mod_pow(n, r - 1);
        }
    }
    friend mod operator/ (const mod& a, const mod& b) {return a * mod_pow(b, -1);}
    friend mod& operator/= (mod& a, const mod& b) {return a = a / b;}
    friend ostream& operator<< (ostream& os, const mod& n) {os << n.m_n; return os;}
    friend istream& operator>> (istream& is, mod& n) {ll tmp; is >> tmp; n = mod(tmp); return is;}
private:
    ll m_n;
};

#define FACT_MAX 600000
mod fact[FACT_MAX], fact_inv[FACT_MAX];
void prep_fact(int N)
{
    fact[0] = 1;
    for (int n = 1; n <= N; ++n) {
        fact[n] = n * fact[n-1];
    }
}
void prep_fact_inv(int N)
{
    for (int n = 0; n <= N; ++n) {
        fact_inv[n] = mod_pow(fact[n], -1);
    }
}
void prep(int N)
{
    prep_fact(N);
    prep_fact_inv(N);
}
mod comb(int n, int k) {if (n < 0 || k < 0 || k > n) return 0; else return fact[n] * fact_inv[n-k] * fact_inv[k];}
mod multi_choose(int n, int k) {return comb(n + k - 1, k);}

int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    prep(M);
    
    mod Ans = 0;
    for (int n = 0; n <= N; ++n) {
        mod Tmp = fact[M-n] / fact[M-N];
        Tmp = Tmp * Tmp;
        Tmp *= fact[M] / fact[M-n];
        if (n&1) Tmp *= -1;
        Tmp *= comb(N, n);
        Ans += Tmp;
    }
    
    cout << Ans << endl;
    
    return 0;
}


Measured memory_bytes: 12940
import sys
import itertools

input = sys.stdin.readline

def my_index_multi(l, x):
    return [k for k, _x in enumerate(l) if _x == x]

h,w,m = map(int,input().split())
l_h = [0]*(h+1)
l_w = [0]*(w+1)
l_b = set()

for _ in range(m):
    h,w = map(int,input().split())
    l_h[h] += 1
    l_w[w] += 1
    l_b.add((h,w))

m_h = max(l_h)
m_w = max(l_w)

l_h_2 = []
for i, x in enumerate(l_h):
    if x == m_h:
        l_h_2.append(i)

l_w_2 = []
for i, x in enumerate(l_w):
    if x == m_w:
        l_w_2.append(i)

ans = m_h + m_w

for i,j in itertools.product(l_h_2,l_w_2):
    if (i,j) not in l_b:
        break
else:
    ans -= 1

print(ans)

Measured memory_bytes: 169112
#!/usr/bin/env python3
# coding=utf-8

import sys

a = int(sys.stdin.readline().strip())
b = int(sys.stdin.readline().strip())
c = int(sys.stdin.readline().strip())
x = int(sys.stdin.readline().strip())
ans = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if i * 500 + j * 100 + k * 50 == x:
                ans += 1
print(ans)


Measured memory_bytes: 3316
#include <cstdio>
#include <map>
#include <algorithm>
using namespace std;

map<int, int> create_map() {
    map<int, int> m;
    for (int i = 1; i <= 6; i++) m.insert({i, 0});
    return m;
}



int main()  {
    double a;
    bool flag;
    map<int, int> m = create_map();
    int n, idx;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%lf", &a);
        idx = 6; flag = false;
        for (double i = 185; i >= 165; i-=5) {
            if (a >= i) { m[idx]++; flag = true; break; }
            idx--;
        }
        if (!flag) m[1]++;
    }
    for (int i = 1; i <= 6; i++) {
        printf("%d:", i);
        for (int j = 0; j < m[i]; j++) printf("*");
        printf("\n");
    }


    return 0;
}



Measured memory_bytes: 2744
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 998244353;
const ll MAX = 4000001;
const long double eps = 1E-14;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

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

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

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

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

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

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

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

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


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

	vvmint dp(C + 1, vmint(D + 1, 0));

	for (ll i = A; i <= C; i++) {
		for (ll j = B; j <= D; j++) {
			if (i == A && j == B) { dp[A][B] = 1; continue; }

			dp[i][j] = dp[i - 1][j] * j + dp[i][j - 1] * i - dp[i - 1][j - 1] * (i - 1) * (j - 1);
		}
	}

	cout << dp[C][D] << endl;
}

Measured memory_bytes: 73648