akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const int INF=1e9;
const ll MX = 1e18;
const ll MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MAX = 1000001;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {fac[0] = fac[1] = 1;finv[0] = finv[1] = 1;inv[1] = 1;for (int i = 2; i < MAX; i++){fac[i] = fac[i - 1] * i % MOD;inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;finv[i] = finv[i - 1] * inv[i] % MOD;}}
long long COM(int n, int k){if (n < k) return 0;if (n < 0 || k < 0) return 0;return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;}

int main() {
  int n;
  cin>>n;
  vi a(n);
  ll ans=0;
  rep(i,n) cin>>a[i];
  rep(i,n-1){
    for(int j=i+1;j<n;j++){
      ans+=a[i]*a[j];
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3612
#include <iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<algorithm>
using namespace std;

int main(void)
{
	string S;
	cin >> S;

	vector<int> cnt(26, 0);
	for(auto it=S.begin(); it!=S.end(); it++)
		cnt[*it-'a']++;

	auto pos = find(cnt.begin(), cnt.end(), 0);
	string ret = "";
	if(pos == cnt.end())
		ret = "None";
	else
	{
		int d = pos - cnt.begin();
		char ch = 'a' + d;
		ret = ch;
	}

	cout << ret << endl;

	return 0;
}


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

ans = 0
for idx in range(len(B)):
    if A[idx] < B[idx]:
        add = B[idx] - A[idx]
        save = A[idx + 1]
        A[idx + 1] -= add
        A[idx + 1] = max(A[idx + 1], 0)
        ans += A[idx] + (save - A[idx + 1])
    else:
        ans += B[idx]

print(ans)


Measured memory_bytes: 18476
#include<bits/stdc++.h>
using namespace std;
 
typedef long long int lli;
typedef unsigned long long int ulli;
typedef pair<int,int> P;
 
#define M 1005
#define MOD 1000000007
#define ep emplace_back
#define mk make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
//	freopen("input.txt","rt",stdin);
	
	int n;
	cin>>n;
	
	string result = "No";
	while(n>0)
	{
		if(n%10==7)
			result = "Yes";
		n/=10;
	}
	
	cout<<result<<"\n";
	
	
}


Measured memory_bytes: 3636
from collections import Counter
import sys

sys.setrecursionlimit(10 ** 6)

mod = 1000000007
inf = int(1e18)

dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]


def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft


def main():
    a, b = input().split()
    a = int(a)
    b = b.split('.')
    if len(b) == 1:
        print(a * int(b[0]))
        return
    k = pow(10, len(b[1]))
    s = a * (int(b[0]) * k + int(b[1])) // k
    print(s)
main()

Measured memory_bytes: 9360
#include <iostream>
#include<stdio.h>//冒泡排序
#include<algorithm>
using namespace std;
void selection_sort(int a[], int len,int &p)
{
    int i,j;

	for (i = 0 ; i < len - 1 ; i++)
    {
		int min = i;
		for (j = i + 1; j < len; j++)     //走訪未排序的元素
		{
			if (a[j] < a[min])    //找到目前最小值
			{
				min = j;    //紀錄最小值
			}
		}
if(i!=min){
	   	 swap(a[i], a[min]);   //就是那种相同的你们居然不算，有点扯
	   	 p++;
}

    }
}
int main()
{
    int n,arr[100],sum=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&arr[i]);
    }
    selection_sort(arr,n,sum);
     for(int i=0;i<n;i++)
    {
        if(i!=n-1)
        {
            printf("%d ",arr[i]);
        }
        else printf("%d\n",arr[i]);
    }
    printf("%d\n",sum);

}




Measured memory_bytes: 3232
#include <iostream>
#define rep(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;
typedef long long LL;

int main(){
  LL A, B;
  cin >> A >> B;
  if(A%2==0){
    if(B%2==1) cout << (B-A+1)/2%2 << endl;
    if(B%2==0) cout << (B-A)/2%2+B << endl;
  }
  if(A%2==1){
    if(B%2==1){
      LL ans=((B-A)/2%2)^A;
      cout << ans << endl;
    }
    if(B%2==0){
      LL ans=A^B^((B-A-1)/2%2);
      cout << ans << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    int cnt = 0;
    for(int i = a; i <= b; i++){
        if(c%i == 0){
            cnt++;
        }
    }
    cout << cnt << endl;
    
}

Measured memory_bytes: 3084
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

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

#define MOD 1000000007

void solve(int test_case) {//239///F.Sugoroku
	int n,k;cin>>n>>k;
	if(n==k)cout<<2*n;
	else cout<<2*max(n,k)-1;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


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

typedef long long ll;
typedef long double ld;
//#define int ll
//#define endl '\n'

// use unique(x) - removec consecutive items, returns vec.begin() + number of items
// for vector: sort(all(vec)); vec.erase(unique(all(vec)), vec.end());
// use iota(all(vec), 0) for filling a vector with 0,1,2...
// use fill(all(vec), 1) for filling a vector with 1,1,1...
// use rotate(vec.begin(), vec.begin() + 1, vec.end()) to rotate a vector | middle arg becomes first
// print number in binary -> cout << bitset<20>(n);

main(){
	cin.tie(0);cin.sync_with_stdio(0);
	int n;cin>>n;
	bool h[101]={};
	for(int i=0;i<n;++i){
		int a,b;cin>>a>>b;
		h[i]=a==b;
	}
	bool pos=false;
	for(int i=0;i<n-2;++i)
		if(h[i]&&h[i+1]&&h[i+2])
			pos=true;
	if(pos)cout<<"Yes\n";
	else cout<<"No\n";
}


Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
#include <sstream>
#include <bitset>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;


int main(){
	ll n, q, sum=0, cnt, b, c;
    cin >> n;
    ll a[n];
    ll li[100005];
    fill(li, li+100005, 0);
    for(ll i=0;i<n;i++)  { 
        cin >> a[i];
        sum += a[i];
        li[a[i]]++;
    }
    cin >> q;
    for(ll i=0;i<q;i++) {
      cin >> b >> c;
      cnt = li[b];
      li[c] += li[b];
      li[b] = 0;
      sum = sum - cnt*b + cnt*c;
      cout << sum << endl;
    }
}


Measured memory_bytes: 5168
#include <iostream>
using namespace std;
 //Compiler version g++ 6.3.0

 int main()
 {
 	int a,b;
 	cin >> a >> b;
 	if(a<9&&b<9){
 		cout << "Yay!" << endl;
 	}else{
 		cout << ":(" << endl;
 	}
 }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
inline ll read() {
    ll x=0,f=1; char ch=getchar();
    for(;ch<'0'||ch>'9';ch=getchar())
        if(ch=='-')f=-f;
    for(;ch>='0'&&ch<='9';ch=getchar())
        x=x*10+ch-'0';
    return x*f;
}
inline void chkmin( int &a,int b ) { if(a>b) a=b; }
inline void chkmax( int &a,int b ) { if(a<b) a=b; }
#define _ read()
int n, a[105],b[105],pos[105],s[105],w[105],res;
inline void dfs( int dep ) {
	if ( dep>n ) {
		memset(s,0,sizeof(s));
		memset(w,0,sizeof(w)); 
		for ( int i = 1; i <= n; i++ ) {
			s[pos[i]] += b[i];
			++w[pos[i]];
		}
		if(s[1]&&s[2]&&s[3]); else return;
		for ( int i=1;i<=3; i++ ) {
			w[i]=10*(w[i]-1);
			w[i]+=abs(a[i] - s[i]);
		}
		chkmin(res,w[1]+w[2]+w[3]);
		return ;
	}
	for ( int i=0; i<=3; i++ ) pos[dep] = i, dfs( dep + 1 );
}
int main() {
	n=_; res=2e9;
	for ( int i=1;i<=3;i++ ) a[i]=_;
	for ( int i=1;i<=n;i++ ) b[i]=_;
	dfs(1);
	cout<<res<<"\n";
	return 0;
}

Measured memory_bytes: 256
INF = 10**10


def partition(ary, p, r):
    x = ary[r][1]
    i = p - 1
    for j in range(p, r):
        if ary[j][1] <= x:
            i += 1
            ary[i], ary[j] = ary[j], ary[i]

    ary[i + 1], ary[r] = ary[r], ary[i + 1]

    return i + 1


def quick_sort(ary, p, r):
    if p < r:
        q = partition(ary, p, r)
        quick_sort(ary, p, q - 1)
        quick_sort(ary, q + 1, r)


def merge(ary, left, mid, right):
    lry = ary[left:mid]
    rry = ary[mid:right]
    lry.append(('INF', INF))
    rry.append(('INF', INF))

    i = 0
    j = 0
    for k in range(left, right):
        if lry[i][1] <= rry[j][1]:
            ary[k] = lry[i]
            i += 1
        else:
            ary[k] = rry[j]
            j += 1

    return right - left


def merge_sort(ary, left, right):
    cnt = 0
    if left + 1 < right:
        mid = (left + right) // 2
        cnt += merge_sort(ary, left, mid)
        cnt += merge_sort(ary, mid, right)
        cnt += merge(ary, left, mid, right)

    return cnt


if __name__ == '__main__':
    import sys
    from copy import deepcopy

    n = int(input())
    # ary = [(lambda x: (x[0], int(x[1])))(line.strip().split()) for line in sys.stdin]
    ary = [(lambda x: (x[0], int(x[1])))(input().split()) for i in range(n)]

    qary = deepcopy(ary)
    mary = deepcopy(ary)
    quick_sort(qary, 0, n - 1)
    merge_sort(mary, 0, n)

    if qary == mary:
        print('Stable')
    else:
        print('Not stable')
    [print(*_) for _ in qary]



Measured memory_bytes: 19292
/*
    Life Before Death, Strength Before Weakness, Journey Before Destination
    ------------------------------------------------------------------------
    You don't become great by trying to be great.
    You become great by wanting to do something,
    and then doing it so hard that you become great in the process.
    */
 
    //#pragma comment(linker, ack:200000000")
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
    #include <bits/stdc++.h>
    using namespace std;
    
    #define TRACE
    
    #ifdef TRACE
    #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
      cerr << name << " : " << arg1 << std::endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
      const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
    #else
    #define trace(...)
    #endif
    
    #define rep(i, n)    for(ll i = 0; i < (n); ++i)
    #define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
    #define repD(i, a, n)  for(ll i = a; i >= (n); --i)
    #define trav(a, x) for(auto& a : x)
    #define all(x) x.begin(), x.end()
    #define sz(x) (int)(x).size()
    #define fill(a)  memset(a, 0, sizeof (a))
    #define fst first
    #define snd second
    //#define mp make_pair
    #define pb push_back
    #define PI           3.141592653589793238462643383279502884197169399  /* pi */
    // #define te    
    typedef long double ld;
    typedef long long ll;
    typedef pair<ll, ll> pii;
    typedef vector<ll> vi;
    const int maxN = 100100;

    void solve() {
        ll n, m, d;
        cin >> n >> m >> d;
        double val = (n-d)*(m-1)*(d==0 ? 1.0:2.0)/(n*n);
        printf("%.15f\n", val);
    }
 
    int main() {
      cin.sync_with_stdio(0); cin.tie(0);
      cin.exceptions(cin.failbit);
       // ll ti;   cin >> ti;  while(ti--)
      solve();
      return 0;
    } 

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


int main()
{
	int a = 4, b = 7;
	int n;
	std::cin >> n;
	bool rslt = false;
	int ai = 0, bi = 0;
	while (true) {
		if (a * ai > n)break;
		for (bi = 0; bi * b + a * ai <= n  ; bi++) {
			if ((a * ai + b * bi) == n) {
				rslt = true;
				break;
			}
		}
		ai++;
	}
	if (rslt) {
		std::cout << "Yes";
	}
	else {
		std::cout << "No";
	}
	return 0;

}

Measured memory_bytes: 256
N = int(input())
wl = list(map(int, input().split()))

ans = 1e8
s1 = 0
s2 = sum(wl)
for i in range(N):
    s1 += wl[i]
    s2 -= wl[i]
    ans = min(ans, abs(s1 - s2))
print(ans)

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

typedef long long ll;
const ll INF = 1010000000000000017LL;
const ll MOD = 1000000007LL;

#define REP(i, n) for(ll i = 0 ; i < n; i++)

//#define DEBUG(fmt, ...)
#define DEBUG(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)

int main(){
    std::cout<<std::fixed<<std::setprecision(10);

    ll A, B;
    cin >> A  >> B;
    REP(i, 2000){
        double eight = i*0.08f;
        double ten = i*0.1f;
        if((int)eight == A && (int)ten == B ){
            cout << i << endl;
            return 0;
        }
    }

    cout << -1 << endl;
}


Measured memory_bytes: 384
#include <stdio.h>
long long p = 1000000007;
long long n, x;
long long rui(long long rui_a, long long rui_b) {
	if (rui_b == 0)return 1;
	if (rui_b == 1)return rui_a % p;
	long long rui_c;
	rui_c = rui(rui_a, rui_b / 2);
	rui_c = rui_c * rui_c % p;
	if (rui_b % 2) {
		return rui_c * rui_a % p;
	}
	return rui_c;
}
int main() {
	scanf("%lld", &n);
	x = rui(10, n);
	x -= 2 * rui(9, n);
	x += rui(8, n);
	printf("%lld\n", (x + 2 * p) % p);
}

Measured memory_bytes: 1732
a = input()
b = input()
c = input()

i = "a"
player = {"a":a,"b":b,"c":c}

while True:
    if len(player[i])==0:
        print(i.upper())
        break
    l = player[i][0]
    player[i] = player[i][1:]
    i = l

Measured memory_bytes: 3064
import java.awt.Point;
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.util.*;

public class Main {	
	Scanner in = new Scanner(System.in);
	public static void main(String[] args){
		new Main();
	}
	public Main(){
		int n = in.nextInt();
		for(int i=0;i<n;i++){
			HashMap<String,Integer> map = new HashMap<String, Integer>();
			String input = in.next();
			int cnt=0;
			int current = 1;//0-current   current+1-input.length
			for(current=1;current<input.length();current++){
				String a = input.substring(0,current);
				String b = input.substring(current);
				String a2 = new StringBuffer(a).reverse().toString();
				String b2 = new StringBuffer(b).reverse().toString();
				map.put(a+b,1);map.put(b+a,1);
				map.put(a+b2,1);map.put(b2+a,1);
				map.put(b+a2,1);map.put(a2+b,1);
				map.put(a2+b2,1);map.put(b2+a2,1);
			}
			System.out.println(map.size());
		}
	}
}

Measured memory_bytes: 54692
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define debug cerr << "-- " << __LINE__ << " --" << endl
#define MOD 1000000007
typedef long long int ll;

using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
template <typename T> string to_string(const vector<T> &xs) {string s="["; for(int i=0;i<xs.size();i++) s += (i>0 ? " " : "") + to_string(xs[i]); return s + "]";}



ll extgcd(ll a, ll b, ll &x, ll &y) {
  ll g = a; x = 1; y = 0;
  if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x;
  return g;
}
ll gcd(ll a, ll b) { ll x, y; return extgcd(a, b, x, y);}

class llm{
	ll n;
public:
	llm(){n = 0;}
	llm(ll n){this->n = (n >= 0) ? (n % MOD) : (MOD - 1 - (-n-1 % MOD));}
	operator ll() const {return n;}
	llm operator+(const llm &y) const{ return llm((ll)*this + (ll)y);}
	llm operator+=(const llm &y) { *this = *this + y; return *this;}
	llm operator-(const llm &y) const{ return llm((ll)*this - (ll)y);}
	llm operator-=(const llm &y) { *this = *this - y; return *this;}
	llm operator-() const{ return llm(0) - *this;}
	llm operator*(const llm &y) const{ return llm((ll)*this * (ll)y);}
	llm operator*=(const llm &y) { *this = *this * y; return *this;}
	llm operator/(const llm &y) const{ return *this * y.inv();}
	llm operator/=(const llm &y) { *this = *this / y; return *this;}
	llm inv() const{
		ll x, y;
		if (extgcd(n, MOD, x, y) == 1) return llm(x);
  		return llm(0); // unsolvable
	}
	friend istream& operator >> (istream& os, llm& x);
	friend ostream& operator << (ostream& os, const llm& x);
};
istream& operator >> (istream& is, llm& x){ll n; is >> n; x = llm(n); return is;}
ostream& operator << (ostream& os, const llm& x){os << (ll)x; return os;}

template<typename T> T comb(ll n, ll k){
	T ret = 1;
	for(ll i=1;i<=k;i++) ret = ret * T(n - k + i) / T(i);
	return ret;
}

template<typename T> vector<ll> argsort(const vector<T> &xs){
	vector<pair<T, ll>> withIdx;
	for(int i=0;i<xs.size();i++) withIdx.push_back(make_pair(xs[i], i));
	sort(withIdx.begin(), withIdx.end());
	vector<ll> ret;
	for(auto p : withIdx) ret.push_back(p.second);
	return ret;
}

ll n, t;
vector<ll> a, b;

vector<vector<ll>> dp;


int main(void){
	cin >> n >> t;
	a = vector<ll>(n);
	b = vector<ll>(n);
	for(int i=0;i<n;i++){
		cin >> a[i] >> b[i];
	}

	auto idx = argsort<ll>(a);
	auto newA = vector<ll>(n); for(int i=0;i<n;i++) newA[i] = a[idx[i]];
	auto newB = vector<ll>(n); for(int i=0;i<n;i++) newB[i] = b[idx[i]];
	a = newA;
	b = newB;


	dp = vector<vector<ll>>(t+1, vector<ll>(n+1));
	
	for(int j=0;j<n;j++){
		for(int i=0;i<t;i++){
			dp[i][j+1] = max(dp[i][j+1], dp[i][j]);
			ll t2 = min(t, i + a[j]);
			dp[t2][j+1] = max(dp[t2][j+1], dp[i][j] + b[j]);
		}
	}
	ll ans = 0;
	for(int i=0;i<=t;i++) ans = max(ans, dp[i][n]);
	for(int j=0;j<=n;j++) ans = max(ans, dp[t][j]);

	/*for(int i=0;i<=t;i++){
		cerr << to_string(dp[i]) << endl;
	}*/

	cout << ans << endl;
	


    return 0;
}









Measured memory_bytes: 70912
S = input()
T = input()
L = len(S)
K = len(T)
ans = S
flag = 0
for i in range(L-1,-1,-1):
    for j in range(K-1,-1,-1):
        a = K-1-j
        if i-a < 0 or (S[i-a] != "?" and S[i-a] != T[j]):
            break
    else:
        ans = ans[:i-K+1] + T + ans[i+1:]
        flag = 1
        break
if flag == 0:
    ans = "UNRESTORABLE"
print(ans.replace("?","a"))

Measured memory_bytes: 3064
#include<iostream>
#include<string>
using namespace std;
int main(void) {
	string s;
	cin >> s;
	if (s == "SUN")cout << 7 << endl;
	else if (s == "MON")cout << 6 << endl;
	else if (s == "TUE")cout << 5 << endl;
	else if (s == "WED")cout << 4 << endl;
	else if (s == "THU")cout << 3 << endl;
	else if (s == "FRI")cout << 2 << endl;
	else if (s == "SAT")cout << 1 << endl;
	return 0;
}

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

int main() {
    int n, m[101][101], p[101];
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> p[i-1] >> p[i];
    }
    
    for (int i = 1; i <= n; i++) m[i][i] = 0;
    for (int l = 2; l <= n; l++) {
        for (int i = 1; i <= n - l + 1; i++) {
            int j = i + l - 1;
            m[i][j] = 200000;
            for (int k = i; k <= j - 1; k++) {
                m[i][j] = min(m[i][j], m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j]);
            }
        }
    }
    cout << m[1][n] << endl;
}


Measured memory_bytes: 3120
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

def main():
    s = input()
    n = len(s)
    l = 0
    r = 0
    for i in range(n):
        if s[i] == 'A':
            l = i
            break
    for i in range(n)[::-1]:
        if s[i] == 'Z':
            r = i
            break
    print(r-l+1)
if __name__ == '__main__':
    main()

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

using namespace std;
using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define rep(i, N) for (ll i = 0; i < (N); i++)
#define For(i, a, b) for (ll i = (a); i < (b); i++)
#define all(A) (A).begin(), (A).end()

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if (b - a == c - b) {
        cout << "YES" << endl;
    }
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
//gauravsinghh
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long int
#define ld long double
#define db double
#define pii pair<int,int>
#define pll pair<long long,long long>
#define sii set<int>
#define sll set<long long>
#define vii vector<int> 
#define vll vector<long long>
#define mii map<int,int>
#define mll map<long long, long long>
#define lob lower_bound
#define upb upper_bound
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define pf pop_front
#define ins insert
#define mp make_pair
#define w(t) cin >> t;while(t--)
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define os cout<<" "
#define bitcount __builtin_popcount
#define gcd __gcd
#define endl "\n"
#define present(s,x) (s.find(x) != s.end()) 
#define cpresent(s,x) (find(all(s),x) != s.end()) 
#define ford(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++) 
#define fors(container, it, a, b) for(__typeof(container.begin()) it = a; it != b; it++) 
#define MOD 1000000007
#define EPSILON 1e-9
#define PI 3.14159265358979323846
#define inf 999999999999999999
#define siz 100005
#define fbo find_by_order
#define ook order_of_key
#define sz(s) (int)s.size()
#define mem(n,m) memset(n,m,sizeof(n))
#define rep(i,n) for(ll i = 0; i < n; i++)
#define ren(i,n) for(ll i = n-1; i >= 0; i--)
#define all(x) x.begin(),x.end()
#define fo(i, a, b) for(int i = a; i <= b; i++)
#define ffo(i, a, b) for(int i = a; i >= b; i--)
#define MAX 100005
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")

void io_set() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

bool comp(const pair < ll, ll >&a, const pair < ll, ll >&b){
    return ((a.ss < b.ss) || (a.ss == b.ss && a.ff < b.ff));
}

ll power(ll a, ll b){
    if(!b){
        return 1;
    }
    if(b&1){
        return (a * power(a*a , b/2));
    }
    return power(a*a , b/2);
}

ll n, m;
unordered_map < ll, ll > mpp;
ll a[100005];

ll func(){
    if(!mpp[1]){
        a[1] = 1;
    }
    if(!mpp[2]){
        a[2] = a[1]+1;
    }
    fo(i, 3, n){
        if(mpp[i]) a[i] = 0;
        else{
            a[i] = (a[i-1]%MOD + a[i-2]%MOD)%MOD;
        }
    }
    return a[n]%MOD;
}


signed main(){ 
    IOS
    //io_set();
    ll y;
    cin >> n >> m;
    rep(i, m){
        cin >> y;
        mpp[y] = 1;
    }
    ll x = func();
    cout << x << endl;
    return 0;
}



Measured memory_bytes: 5156
def getint(): return int(input())
def getints(): return list(map(int, input().split()))

n = getint()
xs = getints()
ys = list(sorted(xs))

mid1 = ys[n//2-1]
mid2 = ys[n//2]

for x in xs:
    y = mid2 if x <= mid1 else mid1
    print(y)


Measured memory_bytes: 25224
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=200005;
int n,fa[N],c[N][2],f[N];ll ans;
struct st{int c0,c1,i;};
inline bool operator<(st a,st b){return 1ll*a.c0*b.c1<1ll*a.c1*b.c0;}
priority_queue<st>Q;
int fnd(int x){return !f[x]?x:f[x]=fnd(f[x]);}
int main()
{
  scanf("%d",&n);
  for(int i=2;i<=n;i++)scanf("%d",&fa[i]);
  for(int i=1,x;i<=n;i++)scanf("%d",&x),c[i][x]=1;
  for(int i=2;i<=n;i++)Q.push((st){c[i][0],c[i][1],i});
  while(!Q.empty())
  {
    st x=Q.top();Q.pop();int u=fnd(x.i);
    if(c[u][0]==x.c0&&c[u][1]==x.c1)
    {
      //printf("!!!! %d\n", u);
      int v=fnd(fa[u]);ans+=1ll*c[v][1]*c[u][0];
      c[v][1]+=c[u][1];c[v][0]+=c[u][0];f[u]=v;
      if(v!=1)Q.push((st){c[v][0],c[v][1],v});
    }
  }
  printf("%lld\n",ans);
  return 0;
}

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

int main(){
	 int a=0,b=0,c=0;
	 cin>>a>>b>>c;
	 if(a<=c&&c<=b){
	 	cout<<"Yes"<<endl;
	 }
	 else{
	 	cout<<"No"<<endl;
	 }
	 return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m,s[15],d[100],dp[101][1<<15];

void minimize(int &a,int b){
  a=min(a,b);
}

int main(){


  int n,m;
  while(cin>>n>>m,n){
    for(int i=0;i<n;i++)cin>>s[i];
    for(int i=0;i<m;i++)cin>>d[i];
    sort(d,d+m);

    int sum[1<<15]={};
    for(int i=0;i<(1<<n);i++)
      for(int j=0;j<n;j++)
	if((1<<j)&i)sum[i]+=s[j];

    for(int j=0;j<=m;j++)
      for(int i=0;i<(1<<n);i++)dp[j][i]=1e9;
    dp[0][0]=0;

    for(int i=0;i<m;i++)
      for(int j=0;j<(1<<n);j++){

	for(int k=0;k<n;k++){
	  if(((1<<k)&j)!=0)continue;
	  
	  //	  minimize( dp[i+1][j+(1<<k)] , dp[i][j]+abs(sum[j+(1<<k)]-d[i]));
	  minimize( dp[i][j+(1<<k)] , dp[i][j]);
	}

	minimize(dp[i+1][j],dp[i][j]+abs(sum[j]-d[i]));
      }



    int mn=1e9;
    for(int i=0;i<(1<<n);i++)mn=min(mn,dp[m][i]);
    cout<<mn<<endl;
  }
  return 0;
}

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

int main(){
    
    string s;
    cin >> s;
    int copm = 0;
    int ans = INT_MAX;
    for(int i=2; i<(int)s.size(); i++){
        int a = (s.at(i-2)-'0')*100 + (s.at(i-1)-'0')*10 + s.at(i)-'0';
        copm = abs(753 - a);
        if(ans > copm){
            ans = copm;
        }
    }
    cout << ans;
}

Measured memory_bytes: 3572
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using INT=mp::cpp_int;
using namespace std;
using ll=long long;
using vec=vector<ll>;
using vect=vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i,n) for(ll i=0;i<n;i++)
#define Loop(i, m, n) for(ll i = m;i < n;i++)
#define pool(i,n) for(ll i=n;i>=0;i--)
#define Pool(i, m, n) for(ll i=n;i>=m;i--)
#define MAX 99999999999ll
#define MIN -99999999999ll
#define setbit bitset<8>
#define flagcount __builtin_popcount
#define flag(x) (1<<x)
#define flagadd(bit,x) bit|=flag(x)
#define flagpop(bit,x) bit&=~flag(x) 
#define flagon(bit,i) bit&flag(i)
#define flagoff(bit,i) !(bit & (1<<i))
#define all(v) v.begin(),v.end()
#define low2way(v,x) lower_bound(all(v),x)
#define high2way(v,x) upper_bound(all(v),x)
#define count2way(v,x) high2way(v,x)-low2way(v,x)
#define lower(v,x) low2way(v,x)-v.begin() //1番左が0、もし見つから無いならｎを出力
#define higher(v,x) high2way(v,x)-v.begin()-1 //1番左が0、もし見つからないならn-1を出力（注意）
#define putout(a) cout<<a<<endl
#define putout2(a,b) putout(a);putout(b)
#define putout3(a,b,c) putout(a);putout(b);putout(c)
#define putout4(a,b,c,d) putout(a);putout(b);putout(c);putout(d)
#define putout5(a,b,c,d,e) putout(a);putout(b);putout(c);putout(d);putout(e)
#define Gput(a,b) G[a].push_back(b)
#define cin1(a) cin>>a
#define cin2(a,b) cin>>a>>b
#define cin3(a,b,c) cin>>a>>b>>c
#define cin4(a,b,c,d) cin>>a>>b>>c>>d
#define cin5(a,b,c,d,e) cin>>a>>b>>c>>d>>e
#define sum(v) accumulate(all(v), 0ll)
#define gcd(x,y) __gcd(x,y)
ll ctoi(char c){
	if(c>='0'&&c<='9'){
		return c-'0';
	}
	return 0;
}
ll lcm(ll x,ll y){
  ll z=gcd(x,y);
  return x*y/z;
}
INT LCM(INT x,INT y){
  INT z=gcd(x,y);
  return x*y/z;
}
ll primejudge(ll n){
  if(n<2)return 0;
  else if(n==2)return 1;
  else if(n%2==0)return 0;
  double sqrtn=sqrt(n);
  Loop(i,3,sqrtn+1){
     if(n%i==0){
        return 0;
     }
     i++;
  }
  return 1;
}
INT modinv(INT a, INT m) {
    INT b = m, u = 1, v = 0;
    while (b) {
        INT t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
int main() {
  cout << fixed << setprecision(30);
  string s,t;
  cin>>s>>t;
  ll n=s.size();
  map<char,char> al;
  map<char,char> la;
  loop(i,n){
    al[s[i]]=t[i];
    la[t[i]]=s[i];
  }
  bool check=true;
  loop(i,n){
    char w=al[s[i]];
    if(w!=t[i])check=false;
  }
  loop(i,n){
    char w=la[t[i]];
    if(w!=s[i])check=false;
  }
  if(check)putout("Yes");
  else putout("No");
}

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

#define MOD 998244353

int X[200005], Y[200005], BIT[400005][2];
long long two[200005];

map<int, int> M;
vector< pair<int, int> > Z;

void update(int i, int j, int val)
{
    for(; i<=400000; i+= (i&(-i)))
        BIT[i][j] += val;
}

int query(int i, int j)
{
    int ans = 0;

    for(; i>0; i-= (i&(-i)))
        ans += BIT[i][j];

    return ans;
}

int main() {

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

    int N;
    cin >> N;

    two[0] = 1;

    for(int i=1; i<=N; i++)
    {
        int x, y;
        cin >> x >> y;

        M[x], M[y];
        Z.push_back({x, y});
        two[i] = two[i-1] * 2 % MOD;
    }

    int k = 0;
    sort(Z.begin(), Z.end());

    for(auto &it : M)
        it.second = ++k;
    
    for(int i=1; i<=N; i++)
    {
        X[i] = M[ Z[i-1].first ], Y[i] = M[ Z[i-1].second ];
        update(Y[i], 1, 1);
    }

    long long ans = 0;

    for(int i=1; i<=N; i++)
    {
        update(Y[i], 1, -1);

        int left = i - 1, right = N - i;
        int left_down = query(Y[i], 0);
        int right_down = query(Y[i], 1);
        int left_up = left - left_down;
        int right_up = right - right_down;

        ans += two[N] - 1;
        ans += MOD - two[left] + 1;
        ans += MOD - two[right] + 1;
        ans += MOD - (two[left_up] - 1) * (two[right_up] - 1) % MOD;
        ans += MOD - (two[left_down] - 1) * (two[right_down] - 1) % MOD;

        update(Y[i], 0, 1);
    }

    cout << ans % MOD << "\n";
    return 0;
}


Measured memory_bytes: 26864
"use strict";

process.stdin.resume();
process.stdin.setEncoding('utf8');

var g_input = '';
process.stdin.on('data', function(chunk) {
    g_input += chunk;
});

process.stdin.on('end', function() {
    Main(g_input.split(/\r?\n/));
});

function Main(input) {

    const ab = input[0].split(' ').map(function(value) { return parseInt(value, 10); });
    const a = ab[0];
    const b = ab[1];

    let ans = '';
    if (a + b === 15) {
        ans = '+';
    } else if (a * b === 15) {
        ans = '*';
    } else {
        ans = 'x';
    }

    console.log(ans);

    return 0;
}


Measured memory_bytes: 21192
n = int(input())
h = [int(i) for i in input().split()]

dp = [0,abs(h[1]-h[0])]
for i in range(2,n):
    dp.append(min(dp[-2] + abs(h[i] - h[i-2]),dp[-1] + abs(h[i] - h[i-1])))
print(dp[n-1])


Measured memory_bytes: 13928
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;

int main()
{
    string s;
    cin >> s;
    int a = 0, b = 0, c = 0;
    rep(i, s.length())
    {
        if (s[i] == 'a')
            a++;
        else if (s[i] == 'b')
            b++;
        else
            c++;
    }
    if (abs(a - b) <= 1 && abs(b - c) <= 1 && abs(c - a) <= 1)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 512
from itertools import permutations

A = [int(input()) for i in range(5)]
ans = 1e10 
for a in permutations(A):
    tmp = 0
    for x in a:
        if tmp % 10 != 0:
            tmp += 10 - (tmp % 10)
        tmp += x
    ans = min(ans, tmp)
print(ans)


Measured memory_bytes: 3060
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define rando mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define fi first
#define se second
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define debugii(x) cerr << " - " << #x << ": " << x.fi<<","<<x.se << endl;
#define sep() cerr << "--------------------" << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ld long double
#define ll long long
#define int ll
#define ii pair<int,int>
#define v vector<int>
#define vii vector<ii>
#define vv vector<vector<int> >
#define mp make_pair
#define INF 1000000000
#define pb push_back
#define EPS 1e-9
const int MOD = 1000000007; // 998244353
int A[200005];
int h[200005],g[200005];
map<int,int> mymap;
int32_t main(){
	boost;
	//freopen(".in","r",stdin);
	int n;
	cin>>n;
	for (int i = 1; i <= n; ++i){
		cin>>A[i];
		h[i]=i-A[i];
		mymap[h[i]]++;
		g[i]=A[i]+i;
	}
	int ans=0;
	for (int i = 1; i <= n; ++i)
	{
		mymap[h[i]]--;
		ans+=mymap[g[i]];
	}
	cout<<ans<<"\n";
	return 0;
}
//long long
//array bounds
//special cases
//binary search

Measured memory_bytes: 31004
//                             ¯\_(ツ)_/¯   
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mma,ava,tune=native")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define sz(a) ((int)(a).size())
#define all(a) (a).begin(),(a).end()
#define ll long long
 
 
void file(){
	#ifndef ONLINE_JUDGE
    	freopen("in.txt", "r", stdin);
	#endif
}
int tc;
 
const int N=2e5+5,M=2e6+5,MOD=1e9+7,OO=1e9;


int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	//file();

	int n;

	scanf("%d",&n);
	std::vector<int> a(n),freq(n+1);
	for(int i=0;i<n;i++)scanf("%d",&a[i]),freq[a[i]]++;
	ll ans = 0;
	for(int i=1;i<=n;i++)ans+=(ll)freq[i]*(freq[i]-1)/2;
	for(int i=0;i<n;i++){
		printf("%lld\n",ans-freq[a[i]]+1 );
	}
}

Measured memory_bytes: 4860
#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> A(N);
    rep(i,N) cin >> A[i]; 
    sort(A.begin(),A.end());
    cout << A[N-1] << " ";
    for(int i=0;i<N;i++){
        if(A[i] > A[N-1]/2){
            cout << (abs(A[N-1] - A[i] * 2) < abs(A[N-1] - A[i-1] * 2) ?  A[i] : A[i-1]) << endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
bool comp(pair<long long int,long long int>a,pair<long long int,long long int>b)
{
    if(a.first==b.first)
    {
        if(a.second<=b.second)
        return true;
        else
        return false;
    }
    if(a.first>b.first)
    return true;
    else return false;
}
bool rev(long long int a,long long int b)
{
    if(a>b)return true;
    else return false;
}
bool compa(pair<string,pair<int,int>>a,pair<string,pair<int,int>>b)
{
    if(a.first==b.first)
    {
        if(a.second.first>b.second.first)
        return true;
        else
        return false;
    }
    if(a.first<b.first)
    return true;
    else 
    return false;
}
long long int gcd(long long int bdda,long long int chota)
{
    if(chota==0)
        return bdda;
    return gcd(chota,bdda%chota);
}
void solve()
{
    long long int n;
    cin>>n;
    long long int a[n],l[n],r[n],sum=0,sumr=0;
    for(long long int i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
        l[i]=sum;
    }
    for(long long int i=0;i<n;i++)
    {
        if(i>=0)
        sumr+=a[i];
        r[i]=sum-sumr;
    }
    long long int d=0,m=INT_MAX;
    for(long long int i=0;i<n-1;i++)
    {
        //cout<<l[i]<<" "<<r[i]<<endl;
        d=abs(l[i]-r[i]);
        m=min(d,m);
    }
    cout<<m;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;    
    t=1;

    //cin>>t;
    while(t--)
    {
        solve();
    }
}


Measured memory_bytes: 8328
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define reps(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define ALL(v) (v).begin(), (v).end()
#define PUTS(x) cout << (x) << endl;
const int MOD = 1000000007;

int main() {
    Int n, K;
    cin >> n >> K;

    Int ans = 0;
    for (Int k = K; k <= n + 1; k++) {
        ans += ((k * (2 * n - k + 1) - k * (k - 1)) / 2 + 1) % MOD;
        ans %= MOD;
    }
    PUTS(ans % MOD)
}


Measured memory_bytes: 3636
#include <iostream>
#include <string.h>
#include <algorithm>
#include <array>
#include <vector>
#include <cmath>

using namespace std;

int hoge(int hoge) {
    
    int ans = 0;

    while ( hoge > 0 ) {
        ans += hoge % 10;
        hoge /= 10;
    }

    return ans;
}

int main( void ) {

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

    pans = 1LL<<60;

    for ( long long i = 1; i < N; i++ ) {
        
        int j = N - i;
        long long ans = hoge(i) + hoge(j);
        
        pans = min(pans, ans);
    }

    cout << pans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int K;
  vector<int> a = {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};
  cin >> K;
  cout << a.at(K-1);
}

Measured memory_bytes: 256
classes = {}

while line = gets
  name, *v = line.chomp.split
  v.map!(&:to_i)
  classes[name] ||= [0, 0]
  classes[name][0] += v[0]
  classes[name][1] += v[1]
end

classes.each do |key, value|
  puts "#{key} #{value[0] + value[1]} #{value[0] * 200 + value[1] * 300}"
end

Measured memory_bytes: 8620
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
void solve(std::string S){
    bool s1 = S[0] == 'R';
    bool s2 = S[1] == 'R';
    bool s3 = S[2] == 'R';
	if( s1 && s2 && s3){
      cout << 3 << endl;
    } else if(!( s1 || s2 || s3)){
      cout << 0 << endl;
    } else if(s2 && (s1 || s3)){
      cout << 2 << endl;
    } else {
      cout << 1 << endl;
    }
}
 
int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <utility>
#include <climits>
#include <bitset>

using namespace std;
#define li long long int
#define FOR(i, a, b) for (int i = a ; i < b ; ++i)
#define REP(i, n) for (int i = 0 ; i < n ; ++i)

li gcd(li a,li b) {
    return a % b == 0 ? b : gcd(b, a % b);
}

int main(void) {
    li N;
    cin >> N;
    li A[N], B[N];
    FOR(i, 0, N) {
        cin >> A[i] >> B[i];
    }

    li count = 0;
    FOR(i, 0, N) {
        li left = (A[N - i -1] + count) % B[N - i - 1];
        if (left == 0) {
            continue;
        } else {
            count += B[N - i - 1] - left;
        }
    }
    cout << count;
    cout << endl;
    return 0;
}


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

const int MOD = 998244353;

long long fact[200005], mmi[200005];

long long power(long long n, long long expo)
{
    long long ans = 1;

    while (expo)
    {
        if (expo % 2)
            ans = ans * n % MOD;
        
        n = n * n % MOD;
        expo /= 2;
    }

    return ans;
}

long long nCr(int n, int r)
{
    return fact[n] * mmi[r] % MOD * mmi[n-r] % MOD;
}

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

    fact[0] = mmi[0] = 1;

    for (int i=1; i<=n; i++)
    {
        fact[i] = fact[i-1] * i % MOD;
        mmi[i] = power(fact[i], MOD - 2);
    }

    long long ans = 0;

    for (int i=0; i<=k; i++)
        ans += power(m-1, n-1-i) * nCr(n-1, i) % MOD;

    cout << ans % MOD * m % MOD << "\n";

    return 0;
}


Measured memory_bytes: 6688
n = int(input())
s = input()

r = [0 for i in range(n)]
l = [0 for i in range(n)]

for i in range(1,n):
    l[i]+=l[i-1]
    r[n-i-1]+=r[n-i]

    if s[i-1]=='W':
        l[i]+=1
    if s[n-i]=='E':
        r[n-i-1]+=1
ans=n
for i in range(n):
    if r[i]+l[i]<ans:
        ans=r[i]+l[i]

print(ans)


Measured memory_bytes: 67300
N = int(input())
A = list(map(int, input().split()))
S = [0]

for i in range(N):
    S.append(S[-1] + A[i])

res = 10**18

for i in range(2, N - 1):
    hi = i
    lo = 0
    while hi - lo > 1:
        mid = (hi + lo) // 2
        if S[mid] - S[0] >= S[i] - S[mid]:
            hi = mid
        else:
            lo = mid
    p = S[hi] - S[0]
    q = S[i] - S[hi]
    if p - q > (q + A[hi - 1]) - (p - A[hi - 1]):
        p -= A[hi - 1]
        q += A[hi - 1]

    hi = N
    lo = i
    while hi - lo > 1:
        mid = (hi + lo) // 2
        if S[mid] - S[i] >= S[N] - S[mid]:
            hi = mid
        else:
            lo = mid
    s = S[hi] - S[i]
    t = S[N] - S[hi]
    if s - t > (t + A[hi - 1]) - (s - A[hi - 1]):
        s -= A[hi - 1]
        t += A[hi - 1]

    res = min(res, max(p, q, s, t) - min(p, q, s, t))

print(res)

Measured memory_bytes: 115752
#pragma GCC optimize("O3")
#pragma GCC target("avx")
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

typedef unsigned long long parallel_type;
const int bit_width=8*sizeof(parallel_type);

int main(){
	int H,W;
	for(;~scanf("%d%d",&H,&W)&&H&&W;){
		vector<string>m(H);
		for(int h=0;h<H;h++)cin>>m[h];
		if(H<=20){
			vector<vector<parallel_type> >l(H);
			int parallel_width=(W+bit_width-1)/bit_width;
			for(int h=0;h<H;h++){
				l[h].resize(parallel_width);
				for(int w=0;w<W;w++)l[h][w/bit_width]|=parallel_type(m[h][w]=='1')<<(w%bit_width);
			}
			int R=0;
			for(int i=0;i<1<<H;i++){
				vector<parallel_type> v(parallel_width);
				int r=0;
				for(int j=0;j<H;j++)if(i>>j&1){
					r++;
					for(int k=0;k<parallel_width;k++)v[k]^=l[j][k];
				}
				if(none_of(v.begin(),v.end(),[](parallel_type e){return e;}))R=max(R,r);
			}
			cout<<R<<endl;
		}else{
			vector<int>b(H);
			for(int h=0;h<H;h++){
				for(int w=0;w<W;w++)b[h]=(b[h]<<1)|(m[h][w]=='1');
			}
			vector<short>s(1<<W),t(1<<W);
			for(int w=1;w<1<<W;w++)s[w]=-1;
			for(int h=0;h<H;h++){
				for(int w=0;w<1<<W;w++){
					t[w]=max(s[w],short(s[w^b[h]]>=0 ? 1+s[w^b[h]] : -1));
				}
				swap(s,t);
			}
			cout<<s[0]<<endl;
		}
	}
}

Measured memory_bytes: 43872
/*  
    Through the fish-eyed lens of tear stained eyes
    I can barely define the shape of this moment in time
    And far from flying high in clear blue skies
    I'm spiralling down to the hole in the ground where I hide
    _________________________
    _________________________
    1008 Hours of Solitude
    Quarantine_Day : 42
*/

#include<bits/stdc++.h>

using namespace std;

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

#define pb(n)           push_back(n)
#define GSORT(v)        sort(v.begin(), v.end(), greater<ll>())
#define SORT(v)         sort(v.begin(), v.end());
#define REV(v)          reverse(v.begin(), v.end());
#define db(a)           cout<<#a<<" = "<<a<<endl;
#define FIN             freopen("in.txt","r",stdin);
#define FOUT            freopen("out.txt","w",stdout);
#define REP(i,n)        for(int i = (int)(0); i < (int)(n); i++)
#define FOR(i, a, b)    for(int i = (int)a; i <= (int)b; i++)    

#define MAX 1000

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

    string s, t; cin>>s>>t;
    
    if(s == t){
        cout<<"Yes\n";
        return 0;
    }
    REP(i, s.size()){
        string x, y, temp;
        x = s.substr(0, s.size() - 1);
        y = s.substr(s.size() - 1);
        temp = y + x;
        s = temp;
        if(s == t){
            cout<<"Yes\n";
            return 0;
        }
    }
    cout<<"No\n";

    return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)

	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	m := getNextInt(scanner)

	var g Graph

	g.n = n

	aa := make([]int, m)
	bb := make([]int, m)
	for i := 0; i < m; i++ {
		a := getNextInt(scanner) - 1
		b := getNextInt(scanner) - 1
		aa[i] = a
		bb[i] = b
		g.matrix[a][b] = 1
		g.matrix[b][a] = 1
	}
	ans := 0

	for i := 0; i < m; i++ {
		g.matrix[aa[i]][bb[i]] = 0
		g.matrix[bb[i]][aa[i]] = 0
		if g.separated() {
			ans++
		}
		g.matrix[aa[i]][bb[i]] = 1
		g.matrix[bb[i]][aa[i]] = 1
	}

	fmt.Fprintln(writer, ans)
	writer.Flush()
}

type Graph struct {
	n      int
	matrix [50][50]int
}

func (g *Graph) separated() bool {
	color := make([]int, g.n)
	g.dfs(0, color)
	for i := 0; i < g.n; i++ {
		if color[i] == 0 {
			return true
		}
	}
	return false
}

func (g *Graph) dfs(r int, color []int) {
	for i := 0; i < g.n; i++ {
		if g.matrix[r][i] == 0 {
			continue
		}
		if color[i] != 0 {
			continue
		}
		color[i] = 1
		g.dfs(i, color)
	}
}


Measured memory_bytes: 640
use std::str::FromStr;

fn get_one<T : FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s.trim().parse().ok().unwrap();
}

fn get_vec<T : FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect();
}

fn main() {
    let s : String = get_one();
    if s.chars().nth(0).unwrap() == s.chars().nth(2).unwrap() {
        println!("Yes");
    }
    else {
        println!("No");
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define ll long long
#define N 200010
using namespace std;
template <typename T> void read(T &x){
	x=0;char ch=getchar();int fh=1;
	while (!isdigit(ch)){if (ch=='-')fh=-1;ch=getchar();}
	while (isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	x=x*fh;
}
ll n,k,p,ansn=1;
int main(){
	read(n);read(k);
	for (ll i=2;i*i<=k;i++){
		if (k%i==0){
			p=0;
			while (k%i==0){
				p++;if (p%n==0)ansn*=i;
				k/=i;
			}
		}
	}
	if (n==1) ansn*=k;
	cout<<ansn<<endl;
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	r := bufio.NewReader(os.Stdin)
	var n int
	var s string
	fmt.Fscan(r, &n, &s)
	ans := 1
	for i := 1; i < n; i++ {
		if s[i] != s[i-1] {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1280
from operator import itemgetter
n=int(input())
s=[input() for i in range(n)]
d=dict()
for i in range(n):
  if s[i] not in d:
    d[s[i]]=1
  else:
    d[s[i]]+=1
d=list(d.items())
d.sort()
d.sort(key=itemgetter(1),reverse=True)
maxi=d[0][1]
for i in range(len(d)):
  if d[i][1]==maxi:
    print(d[i][0])
  else:
    exit()

Measured memory_bytes: 43164
while True:
    a,op,b=input().split()
    a=int(a)
    b=int(b)
    if op=="+":
        print(a+b)
    elif op=="-":
        print(a-b)
    elif op=="*":
        print(a*b)
    elif op=="/":
        print(a//b)
    elif op=="?":
        break

Measured memory_bytes: 5596
#include<stdio.h>

void inverse(char str[],char inv[]);

int main(){
	char str[21],inv[21];
	while(scanf("%s",str)!=-1){
		inverse(str,inv);
		printf("%s\n",inv);
	}
	return 0;
}

void inverse(char str[],char inv[]){
	int i,j;
	for(i=0;str[i]!='\0';i++);
	for(j=0;j<i;j++){
		inv[j]=str[i-j-1];
	}
	inv[j]='\0';
}

Measured memory_bytes: 524