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

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

  // 010101...
  int ans0 = 0;
  for (int i = 0; i < s.size(); i++)
  {
    if (i % 2 == 0 && s[i] == '0') {
      ans0 += 1;
    } else if (i % 2 == 1 && s[i] == '1') {
      ans0 += 1;
    }
  }

  // 1010101...
  int ans1 = 0;
  for (int i = 0; i < s.size(); i++)
  {
    if (i % 2 == 1 && s[i] == '0')
    {
      ans1 += 1;
    }
    else if (i % 2 == 0 && s[i] == '1')
    {
      ans1 += 1;
    }
  }

  cout << min(ans0, ans1) << endl;
  return 0;
}

Measured memory_bytes: 512
import math
N,D = map(int, input().split())
XY = []
for _ in range(N):
    XY.append(list(map(int, input().split())))

ans = 0
for i in range(N):
    if math.sqrt(XY[i][0]**2 + XY[i][1]**2) <= D:
        ans += 1
print(ans)

Measured memory_bytes: 45320
// https://atcoder.jp/contests/caddi2018/tasks/caddi2018_a
//
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, [ next / $t:tt ]) => {
        {
            let len = read_value!($iter, usize);
            (0..len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
        }
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! dvec {
    ($t:expr ; $len:expr) => {
        vec![$t; $len]
    };

    ($t:expr ; $len:expr, $($rest:expr),*) => {
        vec![dvec!($t; $($rest),*); $len]
    };
}

#[allow(unused_macros)]
macro_rules! ifv {
    ($t:expr, $a:expr, $b: expr) => {
        if $t { $a } else { $b }
    }
}

#[allow(unused_macros)]
macro_rules! fill {
    ($t:expr, $v:expr) => {
        for i in 0..$t.len() {
            $t[i] = $v;
        }
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    input! {
        n: i64, m: i64
    };

    if n == 1 {
        println!("{}", m);
        return;
    }

    let mut m = m;
    let mut gcd = 1;
    for x in 2..1000001 {
        let mut cnt = 0i64;
        while m % x == 0 {
            m /= x;
            cnt += 1;
        }
        let mut pw = cnt / n;
        while pw >= 1 {
            gcd *= x;
            pw -= 1;
        }
    }

    println!("{}", gcd);
}


Measured memory_bytes: 4476
mod = 10**9 + 7
base = 10**100 % mod

n,k = map(int,input().split())
A = [base + i for i in range(n+1)]

def isum(l,r):
    return (l+r)*(r - l + 1)//2

res = 0
for i in range(k, n+2):
    res += isum(n+1-i+1, n+1) - isum(1,i) + 1
print(res % mod)


Measured memory_bytes: 16896
#include <stack>
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <array>
#include <iomanip>
#include <string>
using namespace std;
int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}
int mod = 1000000000 + 7;
vector<int> v;
class Calc
{
    // 宣言
    long long a;

    public:
        // 素因数分解
        void decompositPrime(long long a);
};

/*
 * 素因数分解
 */
void Calc::decompositPrime(long long n)
{
    // 割る数の初期値
    a = 2;
    // √n ≧ a ( n ≧ a * a ) の間ループ処理
    while (n >= a * a) {
        // a で割り切れたら、a は素因数
        // そして、割られる数を a で割る
        // a で割り切れなかったら、 a を 1 増加させる
        if (n % a == 0) {
            //printf("%d * ", a);
             v.push_back(a);
            n /= a;
        } else {
            a++;
        }
    }
    // 最後に残った n は素因数
    v.push_back(n);
    //printf("%d\n", n);
}

int main(){
    //std::stack<int> stack;
    int n;
    cin >> n;
    vector<long long> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
        if(a[i] == 0){
            cout << "0" << endl;
            return 0;
        }
    }
    long long k = 1000000000000000000;
    for(int i = 0; i < n; i++){
        if(k >= a[i]){
            k /= a[i];
        }else{
            cout << "-1" << endl;
            return 0;
        }
    }
    long long ans = 1;
    for(int i = 0; i < n; i++){
        ans *= a[i];
    }
    cout << ans << endl;
    return 0;
}





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

int main()
{
  long long int N, M, mon, x=0;
  float min, sum=0;
  cin>>N>>M;
  long long int A[N];
  for(int i=0; i<N; i++)
  {  cin>>A[i];
     sum+=A[i];
  }
  min=sum/(4*M);
  mon=int(ceil(min));
  for(int j=0; j<N; j++)
  {if(A[j]>=mon)
     x+=1;
   else
     continue;
  }
  if(x>=M)
    cout<<"Yes";
  else
    cout<<"No";
  return 0;
}


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

int fr[5];

int main(){
	f(i, 0, 6){
		int t;
		scanf("%d", &t);
		++fr[t];
	}
	int x = 0;
	f(i, 1, 5)x = max(x, fr[i]);
	printf("%s\n", x == 3 ? "NO" : "YES");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n, a, b, x;
bool bol;
int main()
{
	cin>>n;
	for(int i=0; i<n; i++)
	{
		cin>>a>>b;
		if(a==b)
		{
			x++;
		}
		else x=0;
		if(x==3)
		{
			bol=1;
		}
	}
	if(bol==1)
	{
		cout<<"Yes";
	}
	else
	{
		cout<<"No";
	}
	return 0;
}

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

int main()
{
  	char v[3][20] = {"Sunny","Cloudy","Rainy"};
  	string str;
  	cin>>str;
  	for(int i  = 0  ; i < 3 ; i++ )
  	if(str.compare(v[i]) == 0)
    {
      	cout<<v[(i+1)%3];
    }
  	return 0;
}


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

int main()
{
	int H,W;
	while(1){
		cin >> H >> W;
		if(H == 0 && W == 0) break;
		
		for(int i = 0;i < H;i++){
			for(int j = 0;j < W;j++){
				if(i == 0 || j == 0 || j == W - 1 || i == H - 1 ) cout << "#";
				else cout << ".";
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3072
from collections import defaultdict

N = int(input())
A = list(map(int,input().split()))
Q = int(input())


dict = defaultdict(lambda: 0)
sum = 0

for a in A:
    dict[a] += 1
    sum += a

for i in range(Q):
    b,c = map(int,input().split())
    sum = sum + (c - b) * dict[b]
    dict[c] += dict[b]
    dict[b] = 0
    print(sum)


Measured memory_bytes: 24064
/**
 *   Author: Praveen Ojha
 *   Created: 25 March 2019
 *   Time: 00:50:09
**/
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define mod 1000000007
#define PI 3.141592653589793238510
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define __ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

typedef long double ld;
typedef pair<int,int> pii;
int n,m;
char grid[1005][1005];
int dp[1001][1001];
int solve(int i,int j){
	if(i>=n || j>=m)
		return 0;
	if(grid[i][j]=='#')
		return 0;
	if(i==n-1 && j==m-1)
		return 1;
	if(dp[i][j]!=-1)
		return dp[i][j];
	return dp[i][j]=(solve(i+1,j)+solve(i,j+1))%mod;
}
int32_t main(){__
	memset(dp,-1,sizeof dp);
	cin>>n>>m;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin>>grid[i][j];
		}
	}
	cout<<solve(0,0)<<"\n";
return 0;
}

Measured memory_bytes: 5248
#include <iostream>
long long mod=1e9+7,A,d[100][256];
int main(){
  int N;
  std::cin>>N;
  for(int i=0;i<256;i++)d[0][i]=(i/4==0);
  for(int i=1;i<N;i++){
    for(int j=0;j<1024;j++)d[i][j%256]+=d[i-1][j/4]%mod;
    if(i>1)for(int j=0;j<256;j+=64)d[i][j+6]=d[i][j+18]=d[i][j+9]=0;
    if(i>2)d[i][22]=d[i][54]=d[i][30]=0;
  }
  for(int i=0;i<256;i++)A+=d[N-1][i];
  std::cout<<A%mod;
}



Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1000000000
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef long long int ll;

#define ARRAY_MAX 505

void build(vector<ll>& a,vector<ll>& b,vector<ll>& sum){

    REP(i,a.size()){
        REP(j,b.size()){
            sum.push_back(a[i]+b[j]);
        }
    }
}

int main(){

    ll n,v;
    cin >> n >> v;
    vector<ll> a(n),b(n),c(n),d(n);
    REP(i,n){
        cin >> a[i];
    }    
    REP(i,n){
        cin >> b[i];
    }   
    REP(i,n){
        cin >> c[i];
    }   
    REP(i,n){
        cin >> d[i];
    }

    vector<ll> ab,cd;
    build(a,b,ab);
    build(c,d,cd);

    VSORT(cd);

    ll cnt = 0;
    REP(i,ab.size()){

        cnt += upper_bound(cd.begin(),cd.end(),v-ab[i]) - lower_bound(cd.begin(),cd.end(),v-ab[i]);
    }
    cout << cnt << endl;


    return 0;
}


Measured memory_bytes: 23100
import Data.List
import Control.Monad

main = do
    [n, k] <- map read . words <$> getLine
    abss <- replicateM n $ map read . words <$> getLine
    print . getIndex k . map sumSnd $ groupByHead abss

groupByHead = groupBy (\x y -> head x == head y) . sort
sumSnd xs =  [head $ head xs, sum $ map (last) xs]
getIndex k (x:xs) = if last x >= k 
                    then head x
                    else getIndex (k - last x) xs


Measured memory_bytes: 131452
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int main(){
    string s;
    cin>>s;
    if(s[0]==s[s.size()-1]^s.size()%2) cout<<"First";
    else cout<<"Second";
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
long long n,x,a,ans;
void find(long long s,int w){
	if (w==n) return;
	scanf("%d",&a);
	if (a+s>x){
		ans+=a+s-x;
		a-=a+s-x;
		if (a<0){
			s+=a;
			a=0;
		}
	}
	find(a,w+1);
}
int main(){
	scanf("%lld %lld",&n,&x);
	scanf("%lld",&a);
	find(a,1);
	printf("%lld\n",ans);
	return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
using Graph = vector<vector<int>>;
const ll mod=1000000007;
const int MAX_N = 1000;         // n の最大値
 
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
 
int main() {
ll a,b,c;
cin>>a>>b>>c;
if(a==b&&b==c){
cout <<"Yes" << endl;}
else{
cout << "No" << endl;}}

Measured memory_bytes: 3596
N,M = map(int,input().split())
H = list(map(int,input().split()))

bridge = [[] for i in range(N+1)]

for i in range(M):
    A,B = map(int,input().split())
    bridge[A].append(B)
    bridge[B].append(A)

ans = 0

for i in range(1,N+1):
    tmp = bridge[i]
    tmp = list(set(tmp))
    flag = True
    
    if len(tmp) == 0:
        ans +=1
        continue
    for j in range(len(tmp)):
        if H[i-1] <= H[tmp[j]-1]:
            flag = False
    if flag == False:
        continue
    elif flag == True:
        ans += 1

print(ans)

Measured memory_bytes: 31920
//ITP1-10-C: Standard Deviation
//2019.05.20

#include <stdio.h>
#include <math.h>

int main(void){

  int n_stdnt;
  double tmp;
  double m, sig_squares, sig;
  while (1) {
    scanf("%d\n", &n_stdnt);
    if (n_stdnt == 0) break;
    double score[n_stdnt];
    tmp = 0;
    for (int i = 0; i < n_stdnt; i++) {
      scanf("%lf", &score[i]);
      tmp = tmp + score[i];
    }
    m = tmp/n_stdnt;
    tmp = 0;
    for (int i = 0; i < n_stdnt; i++) {
      tmp = tmp + pow(score[i]-m, 2);
    }
    sig_squares = tmp/n_stdnt;
    sig = sqrt(sig_squares);
    printf("%lf\n", sig);
  }

  return 0;
}



Measured memory_bytes: 2040
#include<iostream>
using namespace std;
int main()
{
	char c;
	cin>>c;
	if(c=='A') cout<<'T'<<endl;
	if(c=='T') cout<<'A'<<endl;
	if(c=='C') cout<<'G'<<endl;
	if(c=='G') cout<<'C'<<endl;
} 

Measured memory_bytes: 256
'use strict'
function main(input) {
  input = input.trim().split('\n')
  const num = input[2]
  let text = input[1]
  const char = new RegExp(`[^${text[num-1]}]`, 'g')
  text = text.replace(char, '*');
  console.log(text)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 21064
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a, b) ((a < b) ? a : b)
#define _max(a, b) ((a < b) ? b : a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a) ? 1 : -1)
#define SORT(v) sort(v.begin(), v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380

int main() {
    cout << fixed << setprecision(10);
    double N;
    cin >> N;
    double sum = 0;
    REP(i, N) {
        double in;
        cin >> in;

        sum += 1.0 / in;
    }
    cout << 1 / sum;
    return 0;
}

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

int main() {
    int n, k, q;
    cin >> n >> k >> q;

    int count[n] = {};

    for(int i = 0; i < q; i++) {
        int a;
        cin >> a;
        count[a - 1]++;
    }

    for(int i = 0; i < n; i++) {
        // q - count[i] が参加者i の減点数
        if(q - count[i] < k) cout << "Yes" << endl;
        else cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 1024
use std::io::{self, Stdin};
use std::str::{self, FromStr};
use std::error::Error;
use std::cmp::*;
fn exec() {
    let mut sc = Scanner::new();
    let n: usize = sc.ne();
    let m: usize = sc.ne();
    let mut cnt = vec![0; n];
    for _ in 0..m {
        let u_ = sc.ne::<usize>() - 1;
        let v_ = sc.ne::<usize>() - 1;
        let u = min(u_, v_);
        let v = max(u_, v_);
        if u == 0 {
            cnt[v] += 1;
        } else {
            cnt[u] += 1;
            cnt[v] += 1;
        }
    }
    for &x in &cnt {
        if x % 2 == 1 {
            println!("NO");
            std::process::exit(0);
        }
    }
    println!("YES")
}

fn main() {
    const STACK: usize = 16 * 1024 * 1024;
    let _ = std::thread::Builder::new()
        .stack_size(STACK)
        .spawn(|| { exec(); })
        .unwrap()
        .join()
        .unwrap();
}

#[allow(dead_code)]
struct Scanner {
    stdin: Stdin,
    id: usize,
    buf: Vec<u8>,
}

#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner {
        Scanner {
            stdin: io::stdin(),
            id: 0,
            buf: Vec::new(),
        }
    }
    fn next_line(&mut self) -> Option<String> {
        let mut res = String::new();
        match self.stdin.read_line(&mut res) {
            Ok(0) => None,
            Ok(_) => Some(res),
            Err(why) => panic!("error in read_line: {}", why.description()),
        }
    }
    fn next<T: FromStr>(&mut self) -> Option<T> {
        while self.buf.len() == 0 {
            self.buf = match self.next_line() {
                Some(r) => {
                    self.id = 0;
                    r.trim().as_bytes().to_owned()
                }
                None => return None,
            };
        }
        let l = self.id;
        assert!(self.buf[l] != b' ');
        let n = self.buf.len();
        let mut r = l;
        while r < n && self.buf[r] != b' ' {
            r += 1;
        }
        let res = match str::from_utf8(&self.buf[l..r])
                  .ok()
                  .unwrap()
                  .parse::<T>() {
            Ok(s) => Some(s),
            Err(_) => {
                panic!("parse error, {:?}",
                       String::from_utf8(self.buf[l..r].to_owned()))
            }
        };
        while r < n && self.buf[r] == b' ' {
            r += 1;
        }
        if r == n {
            self.buf.clear();
        } else {
            self.id = r;
        }
        res
    }
    fn ne<T: FromStr>(&mut self) -> T {
        self.next::<T>().unwrap()
    }
}


Measured memory_bytes: 8572
#include <bits/stdc++.h>
using namespace std;
using ld = long double;

const int mod = 0xff;
const ld eps = 1e-10;

int main()
{
	int N;
	while (cin >> N, N) {
		vector<int> I(N);
		for (int i = 0; i < N; i++) {
			cin >> I[i];
		}
		int rS = -1, rA = -1, rC = -1;
		ld mH = 1e20;
		for (int S = 0; S < 16; S++) {
			for (int A = 0; A < 16; A++) {
				for (int C = 0; C < 16; C++) {
					vector<int> R(N + 1), O(N + 1), cnt(256);
					R[0] = S;
					for (int i = 1; i <= N; i++) {
						R[i] = (A * R[i - 1] + C) & mod;
					}
					for (int i = 1; i <= N; i++) {
						O[i] = (I[i - 1] + R[i]) & mod;
						cnt[O[i]]++;
					}
					ld H = 0;
					for (int i = 0; i < 256; i++) {
						if (cnt[i]) {
							ld tmp = (ld)cnt[i] / N;
							H -= tmp * logl(tmp);
						}
					}
					if (H + eps < mH) {
						rS = S;
						rA = A;
						rC = C;
						mH = H;
					}
				}
			}
		}
		cout << rS << ' ' << rA << ' ' << rC << endl;
	}
	return 0;
}

Measured memory_bytes: 3132
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  string p, s;
  cin >> s;
  cin >> p;
  while(s.size() <= 100) s += s;
  if(s.find(p) != string::npos) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3236
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	set:search
# CreatedDate:  2020-06-10 21:03:41 +0900
# LastModified: 2020-06-10 21:13:52 +0900
#


import os
import sys
#import numpy as np
#import pandas as pd


def main():
    q=int(input())
    a=set()
    for _ in range(q):
        command,x=map(int,input().split())
#        print(command,x)
        if command==0:
            a.add(int(x))
            print(len(a))

        else:
            if int(x) in a:
                print(1)
            else:
                print(0)

        


if __name__ == "__main__":
    main()



Measured memory_bytes: 23368
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

const int MOD = 1000000007, INF = 1111111111;
using namespace std;
using lint = long long;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (int i = 0; i < (int)vec.size(); i++) {
		os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	}
	return os;
}

#ifdef _DEBUG
template <class Head>
void dump(const char* str, Head &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + 1, t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;

	vector<int> a(N);
	for (int i = 0; i < N; i++) cin >> a[i];
	sort(a.begin(), a.end());

	cout << a.back() - a[0] << "\n";

	return 0;
}

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

ll mod = 998244353;

int main() {
    int N;
    cin >> N;
    
    vector<int> M(3);
    vector<vector<vector<int>>> edge(3, vector<vector<int>>(N+1));
    for (int i = 0; i < 3; i++) {
        cin >> M[i];
        for (int j = 0; j < M[i]; j++) {
            int a, b;
            cin >> a >> b;
            edge[i][b].push_back(a);
            edge[i][a].push_back(b);
        }
    }
    
    ll q = 1e18;
    q %= mod;
    vector<ll> pow10(N+1, 1);
    for (int i = 1; i <= N; i++) {
        pow10[i] = pow10[i-1] * q % mod;
    }
    
    vector<vector<int>> grundy(3, vector<int>(N+1, 0));
    vector<vector<ll>> gsum(3, vector<ll>(512, 0));
    for (int i = 0; i < 3; i++) {
        for (int j = N; j >= 1; j--) {
            vector<bool> check(N, false);
            for (int nxt : edge[i][j]) {
                if (nxt < j) continue;
                check[grundy[i][nxt]] = true;
            }
            int pos = 0;
            while (check[pos]) pos++;
            grundy[i][j] = pos;
            gsum[i][pos] = (gsum[i][pos] + pow10[j])%mod;
        }
    }
    
    ll ans = 0;
    for (int i = 0; i < 512; i++) {
        for (int j = 0; j < 512; j++) {
            ans += gsum[0][i]*gsum[1][j]%mod*gsum[2][i^j]%mod;
            ans %= mod;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 18008
import java.util.*;

class Main{
	
	public static void main(String args[]){

		Scanner sc = new Scanner(System.in);
		
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();

		int N = sc.nextInt();
		int M = sc.nextInt();

		long min = Integer.MAX_VALUE;

		for(int n=0;n<=Math.max(N,M)*2;n+=2){
			
			int a = N - n/2;
			int b = M - n/2;

			if(a<0) a=0;
			if(b<0) b=0;

			int v = A * a + B * b + C * n;
			if(min>v) min = v;
			
 		}

 		System.out.println(min);

	}
}

Measured memory_bytes: 21716
#include <stdio.h>

#define MAX 100000

int parent(int i){
  return i/2;
}
int left(int i){
  return 2*i;
}
int right(int i){
  return 2*i+1;
}
int main(){
  int n, i, A[MAX+1];
  A[0]=0;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d", &A[i]);
  }
  for(i=1;i<=n;i++){
    printf("node %d: key = %d, ",i,A[i]);
    if(parent(i)>=1) printf("parent key = %d, ",A[parent(i)]);
    if(left(i)<=n) printf("left key = %d, ",A[left(i)]);
    if(right(i)<=n) printf("right key = %d, ",A[right(i)]);
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2048
#include <bits/stdc++.h>
#include<iostream>
#include <algorithm>
#include<stdio.h>
#include<string.h>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include<vector>
using namespace std;
#define fr(i,j,n)   for(int i=j;i<(n);++i)
#define bk(i,j,n)   for(int i=j;i>=n;--i)
#define pb push_back
#define mp make_pair
#define Fs first
#define Sc second
#define endl "\n"
#define MOD 1000000007
#define run ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ordered_set tree<ll , null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
typedef long long lli;

int main()
{
    lli n;
    cin>>n;
    lli arr[n];
    for(int i=0;i<n;++i)
    {
        cin>>arr[i];
    }
    lli cnt=0,last=1,counter=-1;
    for(int i=0;i<n;++i)
    {
        if(arr[i]==last)
        {
            cnt+=i-counter-1;
            counter=i;
            last++;
        }
    }
    cnt+=n-1-counter;
    lli ans;
    if(counter==-1&&cnt>n-1)
    {
        ans=-1;
    }
    else
        ans=cnt;
    cout<<ans<<endl;
    return 0;
}


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

int main(){
  int N,K;
  cin >> N >> K;
  vector<int> d(K);
  vector<vector<int>> vec(K,vector<int>(N));
  for(int i=0; i<K; i++){
    cin >> d[i];
    for(int j=0; j<d[i]; j++){
      cin >> vec.at(i).at(j);
    }
  }
  int counter = 0;
  
  for(int i=1; i<=N; i++){
    bool ans = true;
    for(int j=0; j<K; j++){
      for(int x : vec.at(j)){
        if(x==i){
          ans = false;
        }
      }
    }
    if(ans) counter++;
  }
  
  cout << counter << endl;
}

Measured memory_bytes: 3672
#include <iostream>
using namespace std;
int main()
{
  int m[50],r[50],f[50];
  char ch[50];
  for(int i=0; ;i++)
  {
    cin>>m[i]>>r[i]>>f[i];
    if(m[i]==-1 && r[i]==-1 && f[i]==-1) {ch[i]='i'; break;}
    else if(m[i]==-1 or r[i]==-1)ch[i]='F';
    else if(m[i]+r[i]>=80)ch[i]='A';
    else if(m[i]+r[i]>=65)ch[i]='B';
    else if(m[i]+r[i]>=50)ch[i]='C';
    else if(m[i]+r[i]>=30 && f[i]>=50)ch[i]='C';
    else if(m[i]+r[i]>=30)ch[i]='D';
    else if(m[i]+r[i]<30)ch[i]='F';
  }
   for(int u=0; ;u++){
      if(ch[u]=='i')break;
     else cout<<ch[u]<<endl;}
     return 0;
   }


Measured memory_bytes: 3076
N=int(input())
l=[list(map(int,input().split())) for i in range(N)]
for i,j,k in l:
   if k>0:
      fx,fy,fh=i,j,k
for i in range(0,101):#x
   for j in range(0,101):#y
      sw=0
      cer_h=fh+abs(fx-i)+abs(fy-j)
      for x,y,h in l:
         if max(cer_h-abs(i-x)-abs(j-y),0)!=h:
            sw=1
            break
      if sw==0:
         print(i,j,cer_h)
         exit()

Measured memory_bytes: 9200
H, W, K = map(int, input().split())
S = [list(input()) for _ in range(H)]

ans = [[0] * W for _ in range(H)]
cnt = 0


def xxx(y, x, cnt, d1, d2):
    dy = y + d1
    dx = x + d2
    if 0 <= dy < H and 0 <= dx < W:
        if ans[dy][dx] == 0:
            ans[dy][dx] = cnt
        else:
            return
    else:
        return
    xxx(dy, dx, cnt, d1, d2)


for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            cnt += 1
            ans[i][j] = cnt

for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            cnt = ans[i][j]
            xxx(i, j, cnt, 0, 1)
            xxx(i, j, cnt, 0, -1)

for i in range(H):
    for j in range(W):
        if ans[i][j] != 0:
            cnt = ans[i][j]
            xxx(i, j, cnt, -1, 0)
            xxx(i, j, cnt, 1, 0)

for i in range(H):
    print(" ".join(map(str, ans[i])))

Measured memory_bytes: 7924
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF 1e18L
#define INF 1e9L
#define EPS 1e-9
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define SORT(v) sort(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define pb push_back
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
typedef long long ll;
typedef pair<int, int> intint;

int count_group(vector<int> v){
    int ret = 0;
    int prev = v[0];

    for (int i = 1; i < v.size(); i++) {
        if(v[i] == 0 && prev != 0){
            ret++;
        }
        prev = v[i];
    }
    return ret;
}

int main(void)
{
    int n;
    cin >> n;
    vector<int> h(n);
    int maxv = 0;
    for (int i = 0; i < n; i++) {
        cin >> h[i];
        maxv = max(maxv, h[i]);
    }

    h.pb(0);

    int ans = 0;
    REP(i, maxv){
        ans += count_group(h);
        for (auto& v : h) {
            if(v != 0){
                v--;
            }
        }
    }
    pr(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;

vector<ll> x;
vector<ll> h;
vector<P> pairs;

int main(){
    int n;
    ll d, a;
    cin >> n >> d >> a;
    rep(i, n){
        ll p, q;
        cin >> p >> q;
        pairs.push_back(make_pair(p, q));
    }
    sort(pairs.begin(), pairs.end());
    rep(i, n){
        x.push_back(pairs[i].first);
        h.push_back(pairs[i].second);
    }


    int nxt[200010];
    rep(i, n){
        auto itr = upper_bound(x.begin(), x.end(), x[i] + 2 * d);
        // cout << itr - x.begin() << endl;
        nxt[i] = itr - x.begin();
    }
    ll cnt = 0;
    vector<ll> s(n + 1, 0);
    rep(i, n){
        if (s[i] < h[i]){
            ll diff = ((h[i] - s[i] + a - 1) / a);
            s[i] += diff * a;
            s[nxt[i]] -= diff * a;
            cnt += diff;
        }
        s[i+1] += s[i];
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 11244
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
int main()
{
	int a,b,c;
	while(cin >> a >> b >> c)
	{
		if(a<1868)
		{
			cout << "pre-meiji" << endl;
		}
		else if(a==1868&&b<9)
		{
			cout << "pre-meiji" << endl;
		}
		else if(a==1868&&b==9&&c<8)
		{
			cout << "pre-meiji" << endl;
		}
		else if(a<1912)
		{
			cout << "meiji " << a-1867 <<' '<< b <<' '<< c << endl;
		}
		else if(a==1912&&b<7)
		{
			cout << "meiji " << a-1867 <<' '<< b <<' '<< c << endl;
		}
		else if(a==1912&&b==7&&c<30)
		{
			cout << "meiji " << a-1867 <<' '<< b <<' '<< c << endl;
		}
		else if(a==1912)
		{
			cout << "taisho "<< a-1911 <<' '<< b <<' '<< c << endl;
		}
		else if(a<1926)
		{
			cout << "taisho "<< a-1911 <<' '<< b <<' '<< c << endl;
		}
		else if(a==1926&&b<12)
		{
			cout << "taisho "<< a-1911 <<' '<< b <<' '<< c << endl;
		}
		else if(a==1926&&b==12&&c<25)
		{
			cout << "taisho "<< a-1911 <<' '<< b <<' '<< c <<endl;
		}
		else if(a==1926)
		{
			cout << "showa " << a-1925 <<' '<< b <<' '<< c << endl;
		}
		else if(a<1989)
		{
			cout << "showa " << a-1925 <<' '<< b <<' '<< c << endl;
		}
		else if(a==1989&&b==1&&c<8)
		{
			cout << "showa " << a-1925 <<' '<< b <<' '<< c << endl;
		}
		else
		{
			cout << "heisei "<< a-1988 <<' '<< b <<' '<< c << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950
int main () {
    ll x ;
    cin >> x ;
    ll num500 = 0 ;
    ll num5 = 0;
    while ( x >= 500){
        x -= 500 ;
        num500++ ;
    }
    while (5 <= x){
        x -= 5 ;
        num5++ ;
    }
    cout << num500*1000 + num5*5 << endl;
}

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

using namespace std;
typedef unsigned long ul;
typedef pair<ul, ul> P;

int main(){
    int N, ai[1000];

    cin >> N;
    rep(i, N) cin >> ai[i];

    sort(ai, ai + N);
    cout << ai[N - 1] - ai[0] << endl;
}


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

using namespace std;

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

string ss;
int str_to_i(string ss_) {
    //cout<<ss_<<endl;
    int ret=0;
    istringstream is(ss_);
    is>>ret;
    return ret;
}
string i_to_str(int n_) {
    ostringstream os;
    os<<n_;
    return os.str();
}

void solve() {
    cin>>ss;
    int ans=0;
    while(ss.size()!=1) {
        int maxi=0;
        string tmp = ss;
        for(int i=1;i<ss.size();i++) {
            int t = str_to_i(ss.substr(0,i))*str_to_i(ss.substr(i));
            if(maxi<=t) {
                maxi=t;
                tmp = i_to_str(t);
            }
        }
        //cout<<"tmp: "<<tmp<<endl;
        ss = tmp;
        ans++;
    }

    cout<<ans<<endl;
}

int main() {
    int n;cin>>n;
    rep(i,n) solve();

    return 0;
}

Measured memory_bytes: 1236
#include <stdio.h>
 
// バッファを経ずstdinから数値を得る
#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif
int in()
{
    int n = 0, c = gc();
    do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
    return n;
}
 
int  tr['T'+1];
char f[33554432];
 
int main()
{
    int n, k, c;
 
    tr['A'] = 0, tr['C'] = 1, tr['G'] = 2, tr['T'] = 3;
    n = in();
    while (n--) {
        if (gc() == 'i') {
            k = 7; while (--k) gc();
            k++; while ((c = gc()) >= ' ') k <<= 2, k |= tr[c];
            f[k] = 1;
        } else {
            k = 5; while (--k) gc();
            k++; while ((c = gc()) >= ' ') k <<= 2, k |= tr[c];
            if (f[k]) pc('y'), pc('e'), pc('s');
            else      pc('n'), pc('o');
            pc('\n');
        }
    }
    return 0;
}



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

long long X[55], dp[55][55][2505];

int main() {
    int N, A;
    long long ans = 0;
    scanf("%d %d", &N, &A);
    for (int i = 0; i < N; i++) scanf("%d", &X[i]);
    dp[0][0][0] = 1;
    for (int i = 1; i <= N; i++) {
        for (int j = 0; j <= i; j++) {
            for (int k = 0; k <= j * 50; k++) {
                dp[i][j][k] = dp[i-1][j][k];
                if (k - X[i-1] >= 0 && j > 0) dp[i][j][k] += dp[i-1][j-1][k-X[i-1]];
                if ((i == N) && (k == A * j) && j > 0) ans += dp[i][j][k];
            }
        }
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 53504
import java.io.*;

public class Main{
	public static void main(String[] args) {
		BufferedReader br = new BufferedReader( new InputStreamReader(System.in));
			try {
				String str = br.readLine();
				while(str != null) {
					String[] strSplit = str.split(" ");
					int sum = Integer.parseInt(strSplit[0]) + Integer.parseInt(strSplit[1]);
					System.out.println(String.valueOf(sum).length());
					str = br.readLine();
					
				}
			} catch(IOException e) {
				System.exit(0);
		}
	}
}

Measured memory_bytes: 24124
#include<stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card
{
    char suit;
    int value;
};

struct Card L[MAX / 2 + 2], R[MAX / 2 + 2];

void merge(struct Card A[], int n, int left, int mid, int right)
{
    int i, j, k;
    int n1 = mid - left;
    int n2 = right - mid;
    for (i = 0; i < n1; i++) L[i] = A[left + i];
    for (i = 0; i < n2; i++) R[i] = A[mid + i];
    L[n1].value = R[n2].value = SENTINEL;
    i = j = 0;
    for (k = left; k < right; k++)
    {
        if (L[i].value <= R[j].value)
        {
            A[k] = L[i++];
        }
        else
        {
            A[k] = R[j++];
        }
    }
}

void mergeSort(struct Card A[], int n, int left, int right)
{
    int mid;
    if ( left + 1 < right )
    {
        mid = (left + right) / 2;
        mergeSort(A, n, left, mid);
        mergeSort(A, n, mid, right);
        merge(A, n, left, mid, right);
    }
}

int partition(struct Card A[], int n, int p, int r)
{
    int i, j;
    struct Card t, x;
    x = A[r];
    i = p - 1;
    for (j = p; j < r; j++)
    {
        if (A[j].value <= x.value)
        {
            i++;
            t = A[i];
            A[i] = A[j];
            A[j] = t;
        }
    }
    t = A[i + 1];
    A[i + 1] = A[r];
    A[r] = t;
    return i + 1;
}

void quickSort(struct Card A[], int n, int p, int r)
{
    int q;
    if (p < r)
    {
        q = partition(A, n, p, r);
        quickSort(A, n, p, q - 1);
        quickSort(A, n, q + 1, r);
    }
}

int main()
{
    int n, i, v;
    struct Card A[MAX], B[MAX];
    char S[10];
    int stable = 1;

    scanf("%d", &n);

    for (i = 0; i < n; i++)
    {
        scanf("%s %d", S, &v);
        A[i].suit = B[i].suit = S[0];
        A[i].value = B[i].value = v;
    }

    mergeSort(A, n, 0, n);
    quickSort(B, n, 0, n - 1);

    for ( i = 0; i < n; i++)
    {
        if (A[i].suit != B[i].suit) stable = 0;
    }

    if (stable == 1) printf("Stable\n");
    else printf("Not stable\n");

    for (i = 0; i < n; i++)
    {
        printf("%c %d\n", B[i].suit, B[i].value);
    }

    return 0;
}


Measured memory_bytes: 4040
N = int(input())
P = ''.join([str(v) for v in input().split()])
Q = ''.join([str(v) for v in input().split()])

items = [str(v) for v in range(1,N+1)]
used = [False for _ in range(N+1)]
junretu = list()

def dfs(now):
    if len(now) == N:
        junretu.append(now)
        return
    for i,v in enumerate(items):
        if used[int(v)]:
            continue
        
        used[int(v)] = True
        dfs(now+v)
        used[int(v)] = False
    return

dfs('')
sorted_junretu = sorted(list(junretu))

p_d,q_d = 0,0

for i,s in enumerate(sorted_junretu):
    if s == P:
        p_d = i
    if s == Q:
        q_d = i

print(abs(p_d-q_d))


Measured memory_bytes: 6552
import sys
sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

S = input()
S = S[::-1]
LS = len(S)

MOD = 10 ** 9 + 7


dp = [[0] * 13 for _ in range(LS+1)]
dp[0][0] = 1

for i in range(LS):
    if S[i] != '?':
        d = int(S[i])
        md = (d * pow(10, i, 13)) % 13

        if md == 0:
            dp[i + 1] = dp[i]
        else:
            dp[i + 1][md:] = dp[i][:-md]
            dp[i + 1][:md] = dp[i][-md:]
    else:
        t = pow(10, i, 13)
        for k in range(10):
            md = (k * t) % 13

            for j in range(13):
                nj = (j + md) % 13
                dp[i + 1][nj] += dp[i][j]
                dp[i + 1][nj] %= MOD

print(dp[LS][5])


Measured memory_bytes: 62684
#include <bits/stdc++.h>
using namespace std;
int n, m, u, v, ind[200020], dist[200020], ans = 0;
queue<int> Q;
vector<int> g[200020];
int main() {
	cin >> n >> m;
	for (int i = 0; i < m; i++) cin >> u >> v, g[u].push_back(v), ind[v]++;
	for (int i = 1; i <= n; i++) {
		if (ind[i]==0) Q.push(i);
		dist[i] = 0;
	}
	while (!Q.empty()) {
		int cur = Q.front(); 
		Q.pop();
		for (auto xx: g[cur]) {
			ind[xx]--;
			if (ind[xx] == 0) Q.push(xx), dist[xx] = max(dist[xx], dist[cur]+1);
		}
	}
	for (int i = 1; i <= n; i++) ans = max(ans, dist[i]);
	cout << ans;
}

Measured memory_bytes: 9472
Q, H, S, D = map(int, input().split())
N = int(input())

p025 = Q
p05 = min(H, p025 * 2)
p1 = min(S, p05 * 2)
p2 = min(D, p1 * 2)

ans = 0
if N % 2 != 0:
    N -= 1
    ans += p1
ans += (N // 2) * p2

print(ans)


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

#define FOR(i, a, b) for(int i = a; i < b; i ++)
#define FORS(i, a, b, c) for(int i = a; i < b; i += c)
#define FORN(i, a, b) for(int i = a; i <= b; i ++)
#define FORD(i, a, b) for(int i = a-1; i >= b; i --)
#define FORE(i, b) for(auto &i:b)
#define REP(i, b) FOR(i, 0, b)
#define REPN(i, b) FORN(i, 0, b)
#define SQ(i) (i*i)
#define ALL(a) a.begin(), a.end()
#define ALLA(a,n) a, a+n
#define SORT(a) sort(ALL(a))
#define SORTA(a, n) sort(ALLA(a, n))
#define REV(a) reverse(ALL(a))
#define REVA(a, n) reverse(ALLA(a, n))
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define IN(a, b) (a.find(b) != a.end())
#define BACK(a) a.back(); a.RB()
#define QBACK(a) a.top(); a.pop()
#define PRINT(a) FORE(i, a) cout << i << " "; cout << endl

#define PB  push_back
#define RB  pop_back
#define RF  pop_front
#define INS insert
#define F   first
#define S   second
#define UM  unordered_map
#define US  unordered_set
#define PQ  priority_queue

#define IO ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<ll,ll> pll;
typedef queue<int> qi;
typedef queue<double> qd;
typedef queue<ll> qll;
typedef US<int> si;
typedef US<double> sd;
typedef US<ll> sll;
typedef vector<vi> mi;
typedef vector<vd> md;
typedef vector<vll> mll;
typedef vector<pi> vpi;
typedef vector<pd> vpd;
typedef vector<pll> vpll;

const ll mod = 998244353;

ll pow(ll b, ll p){
  ll r = 1;
  while(p){
    if(p&1) r = b*r%mod;
    p >>= 1;b = b*b%mod;
  }
  return r;
}

int main(){
  IO; ll N, M, K; cin >> N >> M >> K;
  ll ans = 0;
  ll n = 1, d = 1;
  REPN(i,K){
    ll t = M * pow(M-1, N-i-1) % mod;
    t = t * n % mod * pow(d, mod-2) % mod;
    ans = (ans+t) % mod;
    n = n*(N-i-1) % mod;
    d = d*(i+1) % mod;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3648
n=int(input())
l=list(map(int,input().split()))
l1=[]
s=0
for i in l:
  s+=i
  l1.append(s)
c=10000000
for i in range(n):
  c1=abs(l1[n-1]-2*l1[i])
  if c1<c:
    c=c1
print(c)

Measured memory_bytes: 3060
//#include<bits\stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<string>
#include<ctime>
#include<cmath>
#include<cctype>
#include<cstdlib>
#include<queue>
#include<deque>
#include<stack>
#include<vector>
#include<algorithm>	
#include<utility>
#include<bitset>
#include<set>
#include<map>
#define ll long long
#define db double
#define ld long double
#define put(x) printf("%d\n",x)
#define min(x,y) ((x)>(y)?(y):(x))
#define max(x,y) ((x)>(y)?(x):(y))
#define EPS 1e-8
#define mod 1000000007
#define INF 10000000000000000ll
using namespace std;
char buf[1<<15],*fs,*ft;
inline char getc()
{
	return (fs==ft&&(ft=(fs=buf)+fread(buf,1,1<<15,stdin),fs==ft))?0:*fs++;
}
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
const int MAXN=100010;
char a[5];
int b[MAXN],c[MAXN];
int n,m;
int ans,sum;
int main()
{
	//freopen("1.in","r",stdin);
	n=read();m=read();
	for(int i=1;i<=m;++i)
	{
		int x=read();
		scanf("%s",a+1);
		if(a[1]=='W'&&!b[x])++c[x];
		if(a[1]=='A'&&!b[x])++ans,b[x]=1;
	}
	for(int i=1;i<=n;++i)if(b[i])sum+=c[i];
	printf("%d %d\n",ans,sum);
	return 0;
}


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

int t[2000005][26];
int sum(int v, int tl, int tr, int l, int r, int ind) {
    if (l > r) 
        return 0;
    if (l == tl && r == tr) {
        return t[v][ind];
    }
    int tm = (tl + tr) / 2;
    return sum(v*2, tl, tm, l, min(r, tm), ind)
           + sum(v*2+1, tm+1, tr, max(l, tm+1), r, ind);
}

void update(int v, int tl, int tr, int pos, int new_val, int ind) {
    if (tl == tr) {
        t[v][ind] = new_val;
    } else {
        int tm = (tl + tr) / 2;
        if (pos <= tm)
            update(v*2, tl, tm, pos, new_val, ind);
        else
            update(v*2+1, tm+1, tr, pos, new_val, ind);
        t[v][ind] = t[v*2][ind] + t[v*2+1][ind];
    }
}


int main() {
	int n;
	cin>>n;
	string s;
	cin>>s;
	for(int i=0; i<s.size(); i++){
		update(1, 0, n-1, i, 1, int(s[i]-'a'));
	}
	int q;
	cin>>q;
	while(q--){
		int t;
		cin>>t;
		if(t==1){
			int i;
			char c;
			cin>>i>>c;
			i--;
			char la=s[i];
			s[i]=c;
			update(1, 0, n-1, i, 0, int(la-'a'));
			update(1, 0, n-1, i, 1, int(c-'a'));
		}
		else{
			int l, r;
			cin>>l>>r;
			l--;
			r--;
			int num=0;
			for(int i=0; i<26; i++){
				if(sum(1, 0, n-1, l, r, i)>0){
					num++;
				}
			}
			cout<<num<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 110496
#include <math.h>
#include <regex>
#include "bits/stdc++.h"
#define FOR(i, s, e) for (int i = int(s); i < int(e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define INF (INT_MAX / 2)
#define LINF (LLONG_MAX / 2)
#define EPS (1.0e-8)
const int MGN = 10;
const int ARY_SZ_MAX = (int)1e7;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>;
using vb = vector<bool>; using vvb = vector<vb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>; using psl = pair<string, ll>;


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


  int X; cin>>X;

  vi C = {100, 101, 102, 103, 104, 105};
  int N = C.size();
  auto dp = vvb(N, vb(X+1, false));
  // dp[i][j] := [0,i] の品物を買って j 円にできるか
  REP(i,N) {
    for(int j=1; C[i]*j<=X; j++) {
      dp[i][C[i]*j] = true;
    }
  }

  FOR(i,1,N) {
    FOR(j,1,X+1) {
        dp[i][j] = dp[i][j] || dp[i-1][j];
        if (j-C[i] >= 0) dp[i][j] = dp[i][j] || dp[i][j-C[i]];
    }
  }

  int ans = dp[N-1][X] ? 1 : 0;
  cout << ans << endl;


  return 0;
}


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

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

const int INT_INF = 2147483646;
const ll LL_INF = 9223372036854775807;

bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}
 
bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}

ll minll(ll a, ll b){
    if(a >= b)  return b;
    else    return a;
}

ll maxll(ll a, ll b){
    if(a >= b)  return a;
    else    return b;
}

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


const ll SIZE = 1e5+10;
string s,ss;
int wr[210], wr2[210];
ll k;
int main(){
    cin >> s;
    cin >> k;
    ll ans = 0,num1 = 0, num2 = 0,num3 = 0;
    bool fl = false;
 
    ll kab = 1;
    ss = s+s;
    string sss = s+s+s;

    for(int i = 1; i < s.length(); i++){
        if(s[i] == s[i-1]){
            ++num1;
            s[i] = '0';
        }
    }

    for(int i = 1; i < ss.length(); i++){
        if(ss[i] == ss[i-1]){
            ++num2;
            ss[i] = '0';
        }
    }

    for(int i = 1; i < sss.length(); i++){
        if(sss[i] == sss[i-1]){
            ++num3;
            sss[i] = '0';
        }
    }


    num3 -= num2;
    num2 -= num1;
    ans = num1;
    k -= 1;

    ans += num2*(k/2) + num3*(k/2);
    if(k%2 == 1){
        ans += num2;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Text;

namespace Fish.aizu
{
	public static class AizuOnlineJudge
	{
		public static int[] SplitToInts(string line)
		{
			return line.Split(' ').Select(x => int.Parse(x)).ToArray();
		}
		public static double[] SplitToDoubles(string line)
		{
			return line.Split(' ').Select(x => double.Parse(x)).ToArray();
		}
		public static long[] SplitToLongs(string line)
		{
			return line.Split(' ').Select(x => long.Parse(x)).ToArray();
		}
		public static int Main()
		{
			Compute(Console.In, Console.Out);
			return 0;
		}
		
		public static void Compute(TextReader reader, TextWriter writer)
		{
			// ４つの整数b, f, r, vが与えられます。これは、b棟f階のr番目の部屋にv人が追加で入居したことを示します。vが負の値の場合、v人退去したことを示します。 
			
			var table = new int[4,3,10];
			
			reader.ReadLine();
			
			string line = null;
			while (null != (line = reader.ReadLine()))
			{
				var values = SplitToInts(line);
				
				var b = values[0] - 1;
				var f = values[1] - 1;
				var r = values[2] - 1;
				var v = values[3];
				table[b,f,r] += v;
			}
			
			for (int i = 0; i < table.GetLength(0); i++)
			{
				for (int j = 0; j < table.GetLength(1); j++)
				{
					for (int k = 0; k < table.GetLength(2); k++)
					{
						writer.Write(' ');
						writer.Write(table[i,j,k]);
					}
					writer.WriteLine();
				}
				if (i != table.GetLength(0) - 1)
				{
					writer.WriteLine("####################");
				}
			}
		}
	}
}

Measured memory_bytes: 6008