akhauriyash/Code-Regression huggingface dataset:
n = int(input())
s = input()
l = 0
r = 0
count = 0
need = 0
for i in range(n):
    if s[i] == "(":
        l += 1
        count += 1
    else:
        r += 1
        if count > 0:
            count -= 1
        else:
            need += 1
print("(" * need + s + ")" * (l + need - r))

Measured memory_bytes: 3060
/*
[ ( ^ _ ^ ) ]
*/

import java.io.*;
import java.util.*;


public class Main {
    int INF = (int)1e9;
    long MOD = 1000000007;


    void solve(InputReader in, PrintWriter out) throws IOException {
        int n = in.nextInt();
        int k = in.nextInt();
        int[] a = new int[n];
        for(int i=0; i<n; i++) {
            a[i] = in.nextInt();
        }
        int[] dp = new int[k+1];
        dp[0] = 1;
        for(int i=1; i<=k; i++) {
            boolean f = false;
            for(int j=0; j<n; j++) {
                if(i-a[j]>=0) {
                    if(dp[i-a[j]]==1) {
                        f = true;
                        break;
                    }
                }
            }
            if(f) {
                dp[i] = 0;
            } else dp[i] = 1;
        }
        // show("", dp);
        if(dp[k]==1) {
            out.println("Second");
        } else {
            out.println("First");
        }
    }
    

    public static void main(String[] args) throws IOException {
        if(args.length>0 && args[0].equalsIgnoreCase("d")) {
            DEBUG_FLAG = true;
        }
        InputReader in = new InputReader();
        PrintWriter out = new PrintWriter(System.out);
        int t = 1;//in.nextInt();
        long start = System.nanoTime();
        while(t-- >0) {
            new Main().solve(in, out);
        }
        long end = System.nanoTime();
        debug("\nTime: " + (end-start)/1e6 + " \n\n");
        out.close();
    }
    
    static boolean DEBUG_FLAG = false;
    static void debug(String s) {
        if(DEBUG_FLAG) System.out.print(s);
    }
    
    public static void show(Object... o) {
        System.out.println(Arrays.deepToString(o));
    }
    
    static class InputReader {
        static BufferedReader br;
        static StringTokenizer st;
    
        public InputReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        
        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        
        int nextInt() {
            return Integer.parseInt(next());
        }
        
        long nextLong() {
            return Long.parseLong(next());
        }
        
        double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}

Measured memory_bytes: 21972
/*
t.me/ivanesipovvpered
*/
#pragma ARCENIY_KIRILLOV_POVELITEL_KROKODILOV
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("no-stack-protector")
//#pragma GCC push_options
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC pop_options
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define rng(a) a.begin(), a.end()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define rep(i, n) for (int i = 0; i < n; i++)
#define per(i, n) for (int i = n - 1; i > -1; i--)
#define rer(i, x, n) for (int i = x; i < n; i++)
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef long double ld;

const double EPS = 1e-5;
const int mod = 1e9 + 7;
const ll INFLL = 1e18;
const int INF = 1e9;
const int maxn = 2e3 + 3;

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

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

bool is_prime(ll a){
    if (a == 2 || a == 3 || a == 5 || a == 7) return true;
    if (a % 2 == 0 || a%3 == 0 || a%5 == 0 || a%7 == 0)
        return false;
    for (ll i = 11; i * i <= a; i += 2){
        if (a % i == 0)
            return false;
    }
    return true;
}

ll binpow(ll a, int n){
    if (a == 0)
        return 1;
    if (a % 2 == 0){
        ll q = binpow(a, n / 2);
        return (q * q)  ;
    }else return (a * binpow(a, n - 1) ) ;
}


istream& operator>>(istream &in, pair<int, int> &p) {
    in >> p.fi >> p.se;
    return in;
}

ostream& operator<<(ostream &out, pair<int, int> &p) {
    out << p.fi << " " << p.se << endl;
    return out;
}


















main(){
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++){
        for (int j = i + 1; j <= n; j++){
            int q = i^j;
            for (int fle = 0; fle < 30; fle++){
                if (q & (1 << fle)){
                    cout << fle + 1 << ' ';
                    break;
                }
            }
        }
        cout << endl;
    }


}


Measured memory_bytes: 512
from collections import defaultdict
H,W,N = map(int,input().split())
ab = [tuple(map(int,input().split())) for _ in range(N)]

d = defaultdict(lambda:0)
def count(a,b):
    for dx1 in [-1,0,1]:
        for dy1 in [-1,0,1]:
            x,y = a+dx1,b+dy1
            if 2<=x<H and 2<=y<W:
                d[(x,y)] += 1

for i in range(N):
    count(*ab[i])

ans = defaultdict(lambda:0)
for x,y in d:
    ans[d[(x,y)]] += 1

ans[0] = (H-2)*(W-2)
for i in range(1,10):
    ans[0] -= ans[i]

for i in range(10):
    print(ans[i])

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

int main(){

  //initialization
  string s;
  int price = 700;

  //input
  cin >> s;
  
  //solver
  for(int i=0; i < s.size(); i++) if(s[i] == 'o') price += 100;

  //output
  cout << price << "\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
using namespace std;

int N,M;
vector<vector<int>> G(100010);
int n[100001];
int main(){
	cin >> N >> M;
	for(int i=0;i<M;i++){
		int x,y;
		cin >> x >> y;
		G[x].push_back(y);
		G[y].push_back(x);		
	}
	for(int i=1;i<=N;i++)n[i] = -1;
	n[1] = 0;
	queue<int> q;
	q.push(1);
	while(q.size()){
		int x = q.front();
		q.pop();
		for(int i=0;i<G[x].size();i++){
			int u = G[x][i];
			if(n[u] != -1)continue;
			n[u] = x;
			q.push(u);
		}
	}
	for(int i=1;i<=N;i++)if(n[i] == -1){cout << "No" << endl; return 0;}
	cout << "Yes" << endl;
	for(int i=2;i<=N;i++)cout << n[i] << endl;
	return 0;	
}


Measured memory_bytes: 10168
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<int, pair<int, int>> PP;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const ll mod = 1e+9 + 7;
const int INF = 1001001001;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

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

    int n;
    cin >> n;
    int sz = 1;
    for(int i = 0; i < n; ++i)  sz *= 2;
    vector<int> a(sz);
    for(int i = 0; i < sz; ++i) cin >> a[i];
    
    int res = 0;
    for(int k = 1; k < sz; ++k){
        int firstmax = max(a[k], a[0]), secondmax = min(a[k], a[0]);
        int subset = (k - 1) & k;
        while(subset){      // 部分集合列挙
            int hoge = a[subset];
            if(hoge > firstmax)     swap(hoge, firstmax);
            if(hoge > secondmax)    swap(hoge, secondmax);
            subset = (subset - 1) & k;
        }
        chmax(res, firstmax + secondmax);
        cout << res << "\n";
    }
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

vector<int>E[300000];
int a[300000],b[300000];

int deg1[300000],deg2[300000];

signed main(){
	int n,m;string s;cin>>n>>m>>s;
	rep(i,m){
		scanf("%d%d",&a[i],&b[i]);a[i]--;b[i]--;
		E[a[i]].push_back(b[i]);
		E[b[i]].push_back(a[i]);
		if(s[a[i]]==s[b[i]]){
			deg1[a[i]]++;deg1[b[i]]++;
		}
		else{
			deg2[a[i]]++;deg2[b[i]]++;
		}
	}
	set<int>a,b;
	rep(i,n){
		if(s[i]=='A')a.insert(i);
		else b.insert(i);
	}
	queue<int>que;
	rep(i,n){
		if(!deg1[i]||!deg2[i]){
			que.push(i);			
		}
	}
	while(!que.empty()){
		int p=que.front();que.pop();
		if(!a.count(p)&&!b.count(p))continue;
		if(s[p]=='A')a.erase(p);
		else b.erase(p);
		for(int u:E[p]){
			if(s[p]==s[u]){
				deg1[u]--;
				if(!deg1[u])que.push(u);
			}
			else{
				deg2[u]--;
				if(!deg2[u])que.push(u);
			}
		}
	}
	if(a.size()&&b.size()){
		puts("Yes");
	}
	else{
		puts("No");
	}
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

void Main(){
	string s;
	cin >> s;
	s[1] = 'B'^'R'^s[1];
	cout << s << endl;
	return;
}

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

Measured memory_bytes: 3616
x, n = list(map(int, input().split()))

p = list(map(int, input().split()))

def func(x, p):
    d = {}

    for i in range(len(p)):
        if p[i] not in d.keys():
            d[p[i]] = 1

    if x not in d.keys():
        return x

    p1 = x-1
    p2 = x+1

    odd = 1
    ans = 0

    while True:
        if odd == 1:
            if p1 not in d.keys():
                ans = p1
                break
            
            p1 -= 1
        else:
            if p2 not in d.keys():
                ans = p2
                break
            
            p2 += 1
        
        odd *= -1

    return ans

ans = func(x, p)
print(ans)

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

typedef long long ll;
typedef long double ld;
using namespace std;
//mt19937_64 mrand(chrono::steady_clock::now().time_since_epoch().count());
#define ii for(int i=1;i<=n;++i)
#define ji for(int j=1;j<=n;++j)
#define jj for(int j=1;j<=m;++j)
#define ij for(int i=1;i<=m;++i)
#define sz(x) ((ll)x.size())
#define all(x) x.begin(),x.end()
#define al(x) x+1,x+1+n
#define asd cout<<"ok"<<endl;
#define asdd cout<<"okok"<<endl;
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define pr(v) for(auto i:v) cout<<i<<" ";cout<<endl
#define prt(a, l, r) for(auto i=l;i<=r;++i) cout<<a[i]<<" ";cout<<endl;
#define pc(x) __builtin_popcount(x)
#define pb push_back

int main() {
    char c;
    cin>>c;
    if('A'<=c && c<='Z') cout<<'A';
    else cout<<'a';
}


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

const string YES = "Yes";
const string NO = "No";

void solve(long long N, std::vector<long long> L){
    ll sum = accumulate(L.begin(), L.end(),0);
    ll max = *max_element(L.begin(),L.end());
    string ans;
    if (max < sum - max) ans = YES;
    else ans = NO;
    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> L(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&L[i]);
    }
    solve(N, std::move(L));
    return 0;
}


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


int main() {
    string s;
    cin>>s;
    int n = s.size();
    long long ans = 0;
    int bk = n - 1;
    for(int i = n-1; i >= 0; --i) {
        if(s[i] == 'B') {
            ans += abs(i - bk);
            s[i+1] = 'B';
            bk--;
        }
    }                                   
    cout<<ans<<endl;
    return 0;
}   

                                        

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
    set<string>st;
    string str;
    int n;
    cin>>n;
    while(n--)
    {
        cin>>str;
        st.insert(str);
    }
    cout<<st.size()<<endl;
    return 0;
}


Measured memory_bytes: 19116
#include <bits/stdc++.h>
using namespace std;
#define N 100005
long long n,a,b;
int main() {
	//freopen("a.inp", "r", stdin);
	scanf("%lld %lld %lld", &n, &a, &b);
	long long ans = (n-2) * (b-a) + 1;
	if (ans < 0 ) printf("0");
	else printf("%lld",ans);
}

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

int main(){
    long int N,K;
    cin>>N>>K;
    long int A[N];
    rep(i,N) cin>>A[i];
    rep(i,N-K){
        if (A[i]<A[i+K]) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
 return 0;
}

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

class Main {
    public static void main(String[] args) throws IOException {
        Scan sc = new Scan();
        int k = sc.scanInt();
        int n = sc.scanInt();
        int[] dists = new int[n];
        int max = 0;
        int prev = 0;
        for(int i = 0; i < n; ++i){
            int curr = sc.scanInt();
            if(i == n-1)
                dists[0] = k-(curr-dists[0]);
            if(i > 0){
                dists[i] = curr - prev;
            }
            else
                dists[i] = curr;
            max = Math.max(max, dists[i]);
            prev = curr;
        }
        max = Math.max(max, dists[0]);
        System.out.println(k-max);
    }
}

class Scan
{
    private byte[] buf=new byte[1024];
    private int index;
    private InputStream in;
    private int total;
    public Scan()
    {
        in=System.in;
    }
    public int scan()throws IOException
    {
        if(total<0)
        throw new InputMismatchException();
        if(index>=total)
        {
            index=0;
            total=in.read(buf);
            if(total<=0)
            return -1;
        }
        return buf[index++];
    }
    public int scanInt()throws IOException
    {
        int integer=0;
        int n=scan();
        while(isWhiteSpace(n))
        n=scan();
        int neg=1;
        if(n=='-')
        {
            neg=-1;
            n=scan();
        }
        while(!isWhiteSpace(n))
        {
            if(n>='0'&&n<='9')
            {
                integer*=10;
                integer+=n-'0';
                n=scan();
            }
            else throw new InputMismatchException();
        }
        return neg*integer;
    }
    public double scanDouble()throws IOException
    {
        double doub=0;
        int n=scan();
        while(isWhiteSpace(n))
        n=scan();
        int neg=1;
        if(n=='-')
        {
            neg=-1;
            n=scan();
        }
        while(!isWhiteSpace(n)&&n!='.')
        {
            if(n>='0'&&n<='9')
            {
                doub*=10;
                doub+=n-'0';
                n=scan();
            }
            else throw new InputMismatchException();
        }
        if(n=='.')
        {
            n=scan();
            double temp=1;
            while(!isWhiteSpace(n))
            {
                if(n>='0'&&n<='9')
                {
                    temp/=10;
                    doub+=(n-'0')*temp;
                    n=scan();
                }
                else throw new InputMismatchException();
            }
        }
        return doub*neg;
    }
    public String scanString()throws IOException
    {
        StringBuilder sb=new StringBuilder();
        int n=scan();
        while(isWhiteSpace(n))
        n=scan();
        while(!isWhiteSpace(n))
        {
            sb.append((char)n);
            n=scan();
        }
        return sb.toString();
    }
    private boolean isWhiteSpace(int n)
    {
        if(n==' '||n=='\n'||n=='\r'||n=='\t'||n==-1)
        return true;
        return false;
    }
}

Measured memory_bytes: 23508
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
int n,m,a,b,p[200005],s[200005],ans=-1;
int find(int x){
   if(x!=p[x]) p[x]=find(p[x]);
   return p[x];
}
void u(int x, int y){
   x=find(x);
   y=find(y);
   if(x==y) return;
   if(s[x]<s[y]) swap(x,y);
   p[y]=x;
   s[x]+=s[y];
}
int main(){
   cin>>n>>m;
   for(int i=1;i<=n;i++){
      p[i]=i;
      s[i]=1;
   }
   while(m--){
      cin>>a>>b;
      if(find(a)!=find(b)) u(a,b);
   }
   for(int i=1;i<=n;i++) ans=max(ans,s[i]);
   cout<<ans;
   return 0;
}

Measured memory_bytes: 5124
#include <iostream>
#include <vector>
using namespace std;
#define MAP_SIZE 10

class Pos {
  public:
    Pos(int x, int y) : x(x), y(y) {}
    int x;
    int y;
    void display() { cout << '[' << this->x << ',' << this->y << ']' << endl; }
    bool alive(Pos p) {
      if (p.x - 1 <= this->x && this->x <= p.x + 1 && p.y - 1 <= this->y && this->y <= p.y + 1) return true;
      return false;
    } 
};

bool move(Pos p, vector<Pos> sc, int n) {
  if (p.x < 0 || MAP_SIZE <= p.x || p.y < 0 || MAP_SIZE <= p.y) return false;
  if (n == -1) return true;
  if (!p.alive(sc[n--])) return false;
  sc.pop_back();
  return (
      move(Pos(p.x - 2, p.y - 1), sc, n) ||
      move(Pos(p.x - 2, p.y), sc, n) ||
      move(Pos(p.x - 2, p.y + 1), sc, n) ||
      move(Pos(p.x + 2, p.y - 1), sc, n) ||
      move(Pos(p.x + 2, p.y), sc, n) ||
      move(Pos(p.x + 2, p.y + 1), sc, n) ||
      move(Pos(p.x - 1, p.y - 2), sc, n) ||
      move(Pos(p.x, p.y - 2), sc, n) ||
      move(Pos(p.x + 1, p.y - 2), sc, n) ||
      move(Pos(p.x - 1, p.y + 2), sc, n) ||
      move(Pos(p.x, p.y + 2), sc, n) ||
      move(Pos(p.x + 1, p.y + 2), sc, n)
      );
}

int main() {
  int x, y;
  while (cin >> x >> y) {
    if (x == 0 && y == 0) break;
    Pos p = Pos(x, y);

    int n;
    cin >> n;
    vector<Pos> sc;
    sc.insert(sc.begin(), p);
    for (int i = 0; i < n; i++) {
      int scX, scY;
      cin >> scX >> scY;
      Pos s = Pos(scX, scY);
      sc.insert(sc.begin(), s);
    }
    cout << (move(p, sc, n) ? "OK" : "NA") << endl;
  }
  return 0;
}

Measured memory_bytes: 2976
n = int(input())
v = [int(x) for x in map(int, input().split())]
c = [int(x) for x in map(int, input().split())]

diff = []
for i in range(n):
    if v[i] - c[i] > 0:
        diff.append(v[i] - c[i])

print(sum(diff))

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

using namespace std;

typedef long long ll;
typedef long double ld;

#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(v) v.begin(),v.end()

const int maxn = 2e5 + 100, maxlg = 20;
const ll inf = 2e18, mod = 1e9 + 7;

int n, v, vols[maxlg], volCount, nxt[maxlg][maxn], dp[(1 << maxlg)];
ll x[maxn], a[maxn];
bool ans[maxn];
set<int> counter;

void printAnsAndExit() {
	for (int i = 0; i < n; i++) {
		cout << (ans[i] ? "Possible" : "Impossible") << endl;
	}
	exit(0);
}

void solve(int l, int r) {
	memset(dp, 0, sizeof(dp));
	if (l == 0) {
		dp[0] = r + 1;
	}
	for (int mask = 0; mask < (1 << (volCount - 1)); mask++) {
		for (int bit = 0; bit < volCount - 1; bit++) {
			if (!((mask >> bit) & 1)) {
				int val = nxt[bit][dp[mask]] + 1;
				if (l <= val && val <= r) {
					val = r + 1;
				}
				dp[mask | (1 << bit)] = max(dp[mask | (1 << bit)], val);
			}
		}
	}

	int mx = *max_element(dp, dp + (1 << maxlg));
	if (mx == n) {
		for (int i = l; i <= r; i++) {
			ans[i] = true;
		}
	}
}

void solveAll() {
	for (int i = 0; i < n; i++) {
		counter.insert(nxt[volCount - 1][i]);
	}
	if (counter.size() > volCount) {
		printAnsAndExit();
	}
	
	int l = 0, r = 0;
	for (int i = 1; i < n; i++) {
		if (nxt[volCount - 1][r] == nxt[volCount - 1][i]) {
			r++;
		}
		else {
			solve(l, r);
			r++;
			l = r;
		}
	}
	solve(l, r);
}


void calcVols(int v) {
	int count = 0, tmp = v;
	while (tmp) {
		tmp /= 2;
		count++;
	}
	volCount = ++count;
	while (count) {
		vols[--count] = v;
		v /= 2;
	}
}

void calcNxt() {
	for (int vol = 0; vol < volCount; vol++) {
		int l = 0, r = 0;
		while (r < n - 1) {
			if (x[r + 1] - x[r] <= vols[vol]) {
				r++;
			}
			else {
				while (l <= r) {
					nxt[vol][l] = r;
					l++;
				}
				r++;
			}
		}
		while (l <= r) {
			nxt[vol][l] = r;
			l++;
		}
	}
}

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

	cin >> n >> v;
	for (int i = 0; i < n; i++) {
		cin >> x[i];
		a[i] = x[i];
	}

	calcVols(v);
	calcNxt();
	solveAll();
	printAnsAndExit();
}




Measured memory_bytes: 25600
#include<bits/stdc++.h>
using namespace std;
#define file {freopen("i.txt","r",stdin);freopen("o.txt","w",stdout);}
#define ios {ios_base::sync_with_stdio(false);cin.tie(NULL);}
typedef long long ll;
typedef long double ld;
typedef pair<long ,long> pll; 	
const ll mod=1e9+7;

int main(){
	ios;
  ll a; cin>>a;
  ll b,ans=0;
  for(ll i=1; i<=a; i++){
    cin>>b;
    if(i%2==1 || i==1){
      if(b%2==1 || b==1){
        ans++;
      }
    }
  }
	
  cout<<ans;

	return 0;
} 


Measured memory_bytes: 3604
#pragma GCC optimize "03"
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
 
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
 
signed main() {
	#ifdef LOCAL
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	IOS;
	int n, k;
	cin >> k >> n;
	for(int i = max(n-k+1, -1000000); i <= min(n+k-1, 1000000); i++)
		cout << i << " ";	
	return 0;
}

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

#define ull unsigned long long
#define ul unsigned long
#define ll long long
#define size_t unsigned long long

using namespace std;

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

  int n;
  std::cin >> n;
  int height[n+1];
  height[n] = -1;

  for (int i = 0; i < n; i++) {
    std::cin >> height[i];
  }

  int ans = 0;
  for (int i = 100; i > 0; i--) {
    bool flag = false;
    int index = 0;
    for(int j = 0; j < n+1; j++){
      if(height[j] == i && flag == false){
        flag = true;
        height[j]--;
        continue;
      }
      if(height[j] == i && flag == true){
        height[j]--;
        continue;
      }
      if(height[j] != i && flag == true){
        flag = false;
        ans++;
        continue;
      }
      if(height[j] != i && flag == false){
        continue;
      }
    }
    // for(int k = 0; k < n; k++){
    //   std::cout << height[k] << " " ;
    // }
    // std::cout << "" << '\n';
  }

  std::cout << ans << '\n';

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
typedef pair<ll,ll> pll;
void read(int& x){ scanf("%d",&x); }
void read(ll& x){ scanf("%lld",&x); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
#define x first
#define y second

int n, k;
int nxt[100010];
vector<int> edge[100010];
int dep[100010];
int par[20][100010];
int tin[100010];
int tout[100010];
int tn;

int ans;

priority_queue<pp> pq;

void dfs(int x){
	tin[x] = ++tn;
	for(int y:edge[x]){
		dep[y]=dep[x]+1;
		par[0][y]=x;
		dfs(y);
	}
	tout[x] = tn;
	if(dep[x] > k) pq.emplace(dep[x], x);
}

int P(int x){
	int df = k-1;
	for(int i=19; 0<=i; --i) if(1&(df>>i)) x=par[i][x];
	return x;
}

struct SEG {
	const static int M = 131072;
	int tree[M<<1];
	void mark(int x){
		int l=tin[x], r=tout[x];
		l+=M; r+=M;
		while(l<=r){
			if(l%2==1) tree[l++]=1;
			if(r%2==0) tree[r--]=1;
			l>>=1; r>>=1;
		}
	}
	int get(int p){
		for(p=M+tin[p]; p; p/=2) if(tree[p]) return 1;
		return 0;
	}
} seg;

int main()
{
	read(n, k);
	for(int i=1; i<=n; ++i){
		read(nxt[i]);
		if(i != 1) edge[nxt[i]].pb(i);
	}
	ans = (nxt[1] != 1);
	dfs(1);
	for(int i=1; i<20; ++i) for(int j=1; j<=n; ++j) par[i][j] = par[i-1][par[i-1][j]];
	while(pq.size()){
		int p=pq.top().second; pq.pop();
		if(seg.get(p)) continue;
		++ans;
		seg.mark(P(p));
	}
	printf("%d\n", ans);
	return 0;
}


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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

int main(void) {
    int h, w, d;
    cin >> h >> w >> d;

    vector<pint> a(h*w+1);
    vector<int> s(h*w+1);
    int atmp = 0;
    for(int ih=0;ih<h;ih++) {
        for(int iw=0;iw<w;iw++) {
            cin >> atmp;
            a.at(atmp) = make_pair(ih+1, iw+1);
        }
    }

    int q;
    cin >> q;

    for(int id=d+1;id<=h*w;id++) {
        s.at(id) = s.at(id-d) + abs(a.at(id).first-a.at(id-d).first) + abs(a.at(id).second-a.at(id-d).second);
    }

    int l, r;
    for(int iq=0;iq<q;iq++) {
        cin >> l >> r;
        cout << s.at(r)-s.at(l) << endl;
    }
    return 0;
}


Measured memory_bytes: 2176
answer = []

while True:
    H, W = list(map(int, input().split()))

    if H == W == 0:
        break
    else:
        for i in range(H):
            if i % 2 == 0:
                line = "#"
            else:
                line = "."

            for i in range(1, W):
                if line[i - 1] == "#":
                    line += "."
                else:
                    line += "#"

            answer.append(line)

    answer.append("")

[print(answer[i]) for i in range(len(answer))]


Measured memory_bytes: 5640
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"
long long modPow(long long a, long long x, long long p) {
    long long res = 1;
    while(x > 0) {
        if( x % 2 != 0) {
            res = (res * a) % p;
        }
        a = (a * a) % p;
        x /= 2;
    }
    return res;
}

long long modInverse(long long a, long long p) {
    //calculates the modular multiplicative of a mod m.
    //(assuming p is prime).
    return modPow(a, p-2, p);
}
long long combination(long long n, long long k, long long p) {
// calculates C(n,k) mod p (assuming p is prime).

    long long numerator = 1; // n * (n-1) * ... * (n-k+1)
    for (int i=0; i<k; i++) {
        numerator = (numerator * (n-i) ) % p;
    }

    long long denominator = 1; // k!
    for (int i=1; i<=k; i++) {
        denominator = (denominator * i) % p;
    }

    // numerator / denominator mod p.
    return ( numerator* modInverse(denominator,p) ) % p;
}


#define REP(i,x,y) for(int i=(x);i<(y);i++)
#define RREP(i,x,y) for(int i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
//#define int long long

using namespace std;

// conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

typedef long long ll;

const ll MOD = 1e9 + 7;

class ECellDistance {
public:
	void solve(std::istream& in, std::ostream& out) {
	    int N, M, K;
	    in >> N >> M >> K;

	    ll answer = 0;
	    answer += calcSumOfX(N, M, K);
	    answer += calcSumOfX(M, N, K);
	    answer %= MOD;
	    out << answer << "\n";
	}

private:
    ll calcSumOfX(const int X, const int Y, const int K) {
	    ll sum = 0;
	    const ll combinationOfOthers = combination(X * Y - 2, K - 2, MOD);
        REP(d,1,X) {
            ll combinationOfPair = (ll)(X-d) * Y * Y % MOD;
            sum += (d * combinationOfOthers % MOD) * combinationOfPair % MOD;
            sum %= MOD;
        }
        return sum;
	}
};


int main() {
	ECellDistance solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    int n;
    cin >> n;
    vector<ll> v(n);
    for (auto &&i : v) scanf("%lli", &i);
    vector<ll> d(n-1);
    vector<int> x(n-1);
    for (int i = 0; i < n-1; ++i) {
        x[i] = i;
        d[i] = v[i+1]-v[i];
    }
    ll m, k;
    cin >> m >> k;
    for (int i = 0; i < m; ++i) {
        int a;
        cin >> a;
        swap(x[a-2], x[a-1]);
    }
    vector<int> visited(n-1);
    vector<vector<int>> cycle;
    int cnt = 0;
    for (int i = 0; i < n-1; ++i) {
        if(visited[i]) continue;
        visited[i] = 1;
        int p = x[i];
        cycle.emplace_back(0);
        cycle[cnt].emplace_back(i);
        while(p != i){
            visited[p] = 1;
            cycle[cnt].emplace_back(p);
            p = x[p];
        }
        cnt++;
    }
    vector<int> ans(n-1);
    for (auto &&c : cycle) {
        for (int i = 0; i < c.size(); ++i) {
            ans[c[i]] = c[(k+i)%((int)c.size())];
        }
    }
    ll s = v[0];
    printf("%lli\n", s);
    for (int i = 0; i < n-1; ++i) {
        s += d[ans[i]];
        printf("%lli\n", s);
    }
    return 0;
}


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int x, t;

int main() {
	cin >> x >> t;
	
	cout << max(0, x - t) << endl;
	
	return 0;
}


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


signed main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    #ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    //  freopen("output.txt", "w", stdout);
    #endif

    int n, k, x;
    cin>>n>>k;
    std::vector<int> a;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        a.push_back(x);
    }
    bool dp[k+10]={false};
    for(int stones=0;stones<=k;stones++){
        for(int i=0;i<a.size();i++){
            if(stones-a[i]>=0&&!dp[stones-a[i]])
                dp[stones]=true;
        }
    }
    if(dp[k]==true)
        cout<<"First"<<endl;
    else
        cout<<"Second"<<endl;
    
}


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

using ll =  long long;
using pint =  pair<int,int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vpint = vector<pint>;

#define repi(i,start,end) for(int (i)=(start),TemPNuM=(int)(end);(i)<TemPNuM;++(i))
#define rep(i,end) repi((i),0,(end))
#define rfor(x,v) for(auto& (x) : (v))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fsort(v,lambda) sort(all((v)),(lambda))
#define vin(v) rep(i,(v).size())cin >> (v)[i];
#define vpin(v) rep(i,(v).size())cin>>v[i].first>>v[i].second
//#define int long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>void println(T a){if(cout.precision()!=12)cout<<setprecision(12);cout<<a<<endl;}
//lambda: [](int x, int y){return x<y;}

signed main(void){
    int x, y, z; 
    cin >> x >> y >> z;
    printf("%d %d %d\n", z, x, y);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using piii = pair<int, pair<int, int>>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;

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

    int N;
    string S;
    cin >> N >> S;

    vector<vector<int>> pos(N + 1, vector<int>(10, N));
    for (int i = N - 1; i >= 0; --i) {
        pos[i] = pos[i + 1];
        pos[i][S[i] - '0'] = i;
    }

    int ans = 0;
    for (int i = 0; i <= 9; ++i) {
        int idx1 = pos[0][i];
        if (idx1 >= N)
            continue;
        for (int j = 0; j <= 9; ++j) {
            int idx2 = pos[idx1 + 1][j];
            if (idx2 >= N)
                continue;
            for (int k = 0; k <= 9; ++k) {
                int idx3 = pos[idx2 + 1][k];
                if (idx3 >= N)
                    continue;
                ans++;
            }
        }
    }

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


Measured memory_bytes: 2432
struct Scanner {
	handle: std::io::Stdin,
	buffer: std::collections::VecDeque<String>
}

impl Scanner {
	fn new() -> Scanner {
		Scanner {
			handle: std::io::stdin(),
			buffer: std::collections::VecDeque::new()
		}
	}
	fn next<T: std::str::FromStr>(&mut self) -> Result<T, T::Err> {
		if self.buffer.len() == 0 {
			loop {
				let mut available = String::new();
				self.handle.read_line(&mut available).unwrap();
				self.buffer = available.split_whitespace().map(String::from).collect();
				if self.buffer.len() > 0 {
					break;
				}
			}
		}
		T::from_str(&self.buffer.pop_front().unwrap())
	}
}

fn main() {
	let mut scanner = Scanner::new();
	let n: usize = scanner.next().unwrap();
	let limit:i64 = 1__000_000_000__000_000_000;
	let mut ans: i64 = 1;
	let mut reached = false;
	for _ in 0..n {
		let a: i64 = scanner.next().unwrap();
		if a == 0 {
			println!("0");
			return;
		}
		if limit / ans < a {
			reached = true;
			ans = -1;
		}
		if !reached {
			ans *= a;
		}
	}
	println!("{}", ans);
}


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

using namespace std;
int main() {
    string s, t;
    cin >> s;
    int i=s.length();
    while(i!=0) {
        if(i>=7 && s.substr(i-7, 7)=="dreamer") {
            i-=7;
        } else if(i>=6 && s.substr(i-6, 6)=="eraser") {
            i-=6;
        } else if(i>=5 && (s.substr(i-5, 5)=="dream" || s.substr(i-5, 5)=="erase")) {
            i-=5;
        } else {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;

    return 0;
}

Measured memory_bytes: 512
N = int(input())
src = [tuple(map(int,input().split())) for i in range(N)]

nt = nx = ny = 0
for t,x,y in src:
    dist = abs(x-nx) + abs(y-ny)
    if t - nt < dist or (t-nt)%2 != dist%2:
        print('No')
        exit()
    nt,nx,ny = t,x,y
print('Yes')

Measured memory_bytes: 17312
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
#define itn int
#define fi first
#define se second
const int INF=2147483647;
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int x;
  cin>>x;
  cout<<(x^1)<<"\n";
  return 0;
}


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

int main(){
    string s;
    cin >> s;
    int n = s.size();

    int cnt = 0;
    for(int i = 0;i < n;i++){
        if(s[i] == 'o'){
            cnt++;
        }
    }

    if(cnt + 15-n >= 8){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
// Begin Header {{{
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i,n) for(ll i=0; i<n; i++)
#define loop(i, j, n) for(ll i=j; i<n; i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
const long double PI = acos(-1);
// }}} End Header

ll f(ll t){
	ll cnt = 0;
	while(t%2 == 0){
		t/=2;
		cnt++;
	}
	return cnt;
}
int main() {
	ll n, ans = 0;
	cin >> n;
	rep(i,n){
		ll k; cin >> k;
		if(k%2 == 0) ans+=f(k);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3632
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
#define db double
#define LL long long
#define inf 0x3f3f3f3f
#define N 200005
using namespace std;
int gi()
{
    int res=0,s=1; char ch;
    for(ch=getchar();(ch<'0'||ch>'9')&&ch!='-';ch=getchar());
    if(ch=='-') s=-1,ch=getchar();
    for(;ch>='0'&&ch<='9';ch=getchar()) res=res*10+ch-48;
    return res*s;
}
int n,a[N],dp[N],ans;
int main()
{
    n=gi();
    for(int i=1;i<=n;++i) {
	a[i]=gi();
	dp[a[i]]=dp[a[i]-1]+1;
	ans=max(ans,dp[a[i]]);
    }
    printf("%d\n",n-ans);
    return 0;
}


Measured memory_bytes: 1920
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <map>
#include <algorithm>
#include <stdio.h>
#include <set>
#include <cmath>

typedef long long ll;

using namespace std;


int main(){
    ll mod = pow(10, 9) + 7;
    ll n, k;
    cin >> n >> k;

    ll max = 0;
    ll min = 0;
    ll ans = 0;

    for(ll i = k; i <= n; i++){
        min = i * (0 + i - 1) / 2;
        max = i * (n + (n - i + 1)) / 2;
        ans += (max - min + 1);
        ans %= mod;
    }
    cout << ans + 1 << endl;
}



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

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

    vector<int> xn(N+1);
    vector<int> ym(M+1);
    cin >> xn.at(0);
    cin >> ym.at(0);
    for (int i = 1; i < N+1;i++){
        cin >> xn.at(i);
    }
    for (int i = 1; i < M+1; i++){
        cin >> ym.at(i);
    }
    sort(xn.begin(), xn.end());
    sort(ym.begin(), ym.end());

    if(ym.at(0)-xn.at(N)<=0){
        cout << "War" << endl;
    }
    else{
        cout << "No War" << endl;
    }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll              long long
#define pb              push_back
#define ppb             pop_back
#define endl            '\n'
#define mii             map<ll,ll>
#define pii             pair<ll,ll>
#define vi              vector<ll>
#define vs              vector<string>
#define all(a)          (a).begin(),(a).end()
#define F               first
#define S               second
#define sz(x)           ((ll)x.size())
#define hell            (998244353)
#define inf             ((ll)5e18 + 5)
#define PI              ((double)3.14159265358979323844)
#define DECIMAL(n)      cout << fixed << setprecision(n);
#define rep(i,a,b)      for (ll i=a;i<b;i++)
#define repr(i,a,b)     for (ll i=a-1;i>=b;i--)
#define bitcount(a)     (ll)__builtin_popcount(a)
#define lbnd            lower_bound
#define ubnd            upper_bound
#define mp              make_pair
#define ios             ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ordered_set     tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define trace(...)      __f(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

using namespace std;
using namespace __gnu_pbds;

/*----------------------Graph Moves----------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*------------------------------------------------*/

//primes for hashing 937,991,1013,1409,1741
#define N  200005

ll expo(ll base,ll exponent){
    ll ans=1;
    while(exponent!=0){
        if(exponent&1) ans=(1LL*ans*base)%hell;
        base=(1LL*base*base)%hell;
        exponent>>=1;
    }
    return ans%hell;
}

ll fac[N];

ll ncr(ll n,ll r) {
	if (r==0) {
		return 1;
	}
	if (r>n) {
		return 0;
	}
	ll ans=fac[n];
	ans=(ans*expo(fac[r],hell-2))%hell;
	ans=(ans*expo(fac[n-r],hell-2))%hell;
	return ans;
}

void init() {
	fac[0]=1;
	for(ll i=1;i<N;i++) {
		fac[i]=(fac[i-1]*i)%hell;
	}
}

ll add(ll a,ll b) {
	return ((a%hell)+(b%hell))%hell;
}
ll sub(ll a,ll b) {
	return ((a%hell)-(b%hell)+hell)%hell;
}
ll mul(ll a,ll b) {
	return ((a%hell)*(b%hell))%hell;
}

void solve() {
    ll n,m,k;
    cin>>n>>m>>k;
    ll ans=0;
    rep(i,n-k,n+1){
    	ans=add(ans,mul(ncr(n-1,i-1),mul(m,expo(m-1,i-1))));
    }
    cout<<ans<<endl;
}

signed main() {
    ios
    ll test=1;
    init();
    //cin>>test;
    while (test--) solve();
    return 0;
}

Measured memory_bytes: 5148
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String args[]) throws Exception{
        BufferedReader stdR = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(stdR.readLine()) + 1;
        int[] t = new int[N];
        int[] x = new int[N];
        int[] y = new int[N];
        t[0] = 0;
        x[0] = 0;
        y[0] = 0;
        for(int i = 1 ; i < N ; i++) {
            String[] str = stdR.readLine().split(" ");
            t[i] = Integer.parseInt(str[0]);
            x[i] = Integer.parseInt(str[1]);
            y[i] = Integer.parseInt(str[2]);
        }
        boolean isok = true;
        for(int i = 0 ; i < N - 1 ; i++) {
            int time = t[i + 1] - t[i];
            int distance = Math.abs(x[i + 1] - x[i]) + Math.abs(y[i + 1] - y[i]);
            if(!(time >= distance && time % 2 == distance % 2)) {
                isok = false;
                break;
            }
        }
        if(isok) {
            System.out.println("Yes");
        }else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 50732
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>

int main()
{
    long long sum = 0, n, k, tmp;
    std::vector<double> m(1001);
    double a = 1.2345;
    //std::cout << a << std::endl;
    for (int i = 0; i < 1000; i++)
    {
        m[i + 1] = (double)(sum += i + 1) / (i + 1);
    }
    std::cin >> n >> k;
    std::vector<int> p(n);
    int max_pos = 0;
    long long ans = 0, max = 0;
    for (int i = 0; i < n; i++)
    {
        std::cin >> p[i];
        ans += p[i];
        if (i >= k)
        {
            ans -= p[i - k];
        }
        if (max < ans)
        {
            max = ans;
            max_pos = i;
        }
        //std::cout << max << std::endl;
    }
    double res = 0;
    for (int i = 0; i < k; i++)
    {
        res += m[p[max_pos - i]];
    }
    std::cout << std::fixed << std::setprecision(12) << res << std::endl;
}

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

int main()
{
  int a,b,c;
    
  cin >> a >> b;
  c=a+b;

  if(a%3==0){
  cout << "Possible" << endl;
  }else if(b%3==0){
  cout << "Possible" << endl;
  }else if(c%3==0){
  cout << "Possible" << endl;
  }else{
  cout << "Impossible" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
n,T = map(int,input().split())
t = list(map(int,input().split()))
pushtime = 0
ans = 0
for i in range(n):
    if n== 0:continue
    if pushtime+T > t[i]:
        ans+=t[i] - pushtime
        pushtime = t[i]
        
    
    else:
        ans +=T
        pushtime = t[i]
ans+=T
print(ans)

Measured memory_bytes: 26708
#include<bits/stdc++.h>
using namespace std;
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> p2;
#define sz(a) ll(a.size())
ll a[105];
void solve(){
	ll n;
	cin>>n;
	for(ll i=1;i<=n;i++){
		ll x,y;
		cin>>x>>y;
		if(x==y)
			a[i]=1;
	}
	for(ll i=1;i<=n;i++)
		if(a[i]==1&&a[i+1]==1&&a[i+2]==1){
			cout<<"Yes";
			return;
		}
	cout<<"No";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w", stdout);
    #endif
    clock_t z=clock();
    ll qc=1;
    //cin>>qc;
    for(ll i=1;i<=qc;i++){
        solve();
    }
    debug("Total Time:%.4Lf\n",(ld)(clock()-z)/CLOCKS_PER_SEC);
}


Measured memory_bytes: 3776
def cul(low, high):
    high = high[::-1]
    lists = []
    if len(low) > len(high):
        low.insert(0, low[-1])
        low = low[:-1]
        lists.append(low[0])
        for _l, _h in zip(low[1:], high):
            lists.append(_h)
            lists.append(_l)
    elif len(low) < len(high):
        high.insert(0, high[-1])
        high = high[:-1]
        lists.append(high[0])
        for _l, _h in zip(low, high[1:]):
            lists.append(_l)
            lists.append(_h)
    else:
        low.insert(0, low[-1])
        low = low[:-1]
        for _l, _h in zip(low, high):
            lists.append(_l)
            lists.append(_h)
    ans = 0
    for _p, _n in zip(lists, lists[1:]):
        ans += abs(_n - _p)
    return ans


n = int(input())
a = sorted([int(input()) for _ in range(n)])
if len(a) % 2 == 1:
    lower = a[:len(a) // 2 + 1]
    higher = a[len(a) // 2 + 1:]
    first = cul(lower, higher)
    lower = a[:len(a) // 2]
    higher = a[len(a) // 2:]
    second = cul(lower, higher)
    print(max(first, second))
else:
    lower = a[:len(a) // 2]
    higher = a[len(a) // 2:]
    print(cul(lower, higher))


Measured memory_bytes: 10540