akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1000000007LL;
const int INF = LLONG_MAX;

signed main(){
    
    while(1){
        int n, m; cin >> n >> m;
        if(n == 0) break;
        vector<int> a(n);
        for(int i = 0; i < n; i++) cin >> a[i];
        vector<int> b(m);
        for(int i = 0; i < m; i++) cin >> b[i];

        int cur = 0;
        for(int i = 0; i < m; i++){
            cur += b[i];
            if(a[cur] != 0) cur += a[cur];

            if(cur >= n - 1){
                cout << i + 1 << endl;
                break;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3112
#include<stdio.h>

#define MAX 300
#define MIN 1

int main()
{
	int i, j, H, W;
	while (1)
	{
		scanf("%d %d", &H, &W);
		if (H == 0 && W == 0)
			break;
		else if (MIN<=H,W&&H, W <= MAX)
		{
			for (i = 1; i <= H; i++){
				for (j = 1; j <= W; j++){
					if (i % 2 == 1){
						if (j % 2 == 1)
							putchar('#');
						else
							putchar('.');
					}
					else{
						if (j % 2 == 1)
							putchar('.');
						else
							putchar('#');
					}
				}
				printf("\n");
			}
			printf("\n");
		}
	}
	return 0;
}

Measured memory_bytes: 576
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Transformataion
{
    class Program
    {
        static void Main(string[] args)
        {
            String str = Console.ReadLine();
            int num = int.Parse(Console.ReadLine());

            //Console.WriteLine("?????????={0}", str.Length);

            for (int i = 0; i < num; ++i)
            {
                var input = Console.ReadLine().Split(' ');
                int a = int.Parse(input[1]);
                int b = int.Parse(input[2]);
                if (input[0] == "replace")
                {
                    String work = input[3];
                    str = str.Substring(0, a) + work + str.Substring(b + 1);
                }
                else if (input[0] == "print")
                {
                    Console.WriteLine(str.Substring(a, b - a + 1));
                }
                else if (input[0] == "reverse")
                {
                    char[] work = str.Substring(a, b - a + 1).ToCharArray();
                    Array.Reverse(work);
                    String ngo = new String(work);
                    str = str.Substring(0, a) + ngo + str.Substring(b + 1);
                }
            }
        }
    }
}


Measured memory_bytes: 9052
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

int H, W;
char board[60][60];
int used[60][60];

signed main() {
    while(cin >> W >> H, H || W) {
        for(int i=0; i<H; i++) {
            string s; cin >> s;
            for(int j=0; j<W; j++) {
                board[i][j] = s[j];
            }
        }

        int ansB = 0, ansW = 0;
        for(int i=0; i<H; i++) {
            for(int j=0; j<W; j++) {
                memset(used, 0, sizeof(used));
                if(board[i][j] != '.') continue;

                bool lookB = false, lookW = false;
                queue< pair<int, int> > que;
                que.emplace(i, j);

                while(que.size()) {
                    int x, y; tie(x, y) = que.front(); que.pop();
                    for(int k=0; k<4; k++) {
                        int nx = x + dx[k], ny = y + dy[k];
                        if(nx < 0 or nx >= H or ny < 0 or ny >= W) continue;
                        if(used[nx][ny]) continue;
                        used[nx][ny] = true;

                        if(board[nx][ny] == 'B') lookB = true;
                        if(board[nx][ny] == 'W') lookW = true;
                        if(board[nx][ny] == '.') que.emplace(nx, ny);
                    }
                }

                if(!lookB and  lookW) ansW++;
                if( lookB and !lookW) ansB++;
            }
        }
        cout << ansB << " " << ansW << endl;
    }
    return 0;
}



Measured memory_bytes: 3184
/*input
4
BWBBWWWB
*/
#include <bits/stdc++.h>
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define x first
#define y second
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
const int maxn = 2e5 + 100;
const int mod = 1e9 + 7;
int n, seq[maxn];
string s;
void zero()
{
	cout << "0\n";
	exit(0);
}
int main()
{
	ios_base::sync_with_stdio(false), cin.tie(0);
	cin >> n >> s;
	if(s[0] == 'W' || s.back() == 'W')
		zero();
	// 0 - open, 1 - close
	seq[0] = 0;
	for(int i = 1; i < 2 * n; i++)
	{
		if(s[i] == s[i - 1])
			seq[i] = seq[i - 1] ^ 1;
		else
			seq[i] = seq[i - 1];
	}
	ll open = 0, ans = 1;
	for(int i = 0; i < 2 * n; i++)
	{
		if(seq[i] == 0)
			++open;
		if(open % 2 != s[i] == 'B')
			zero();
		if(seq[i] == 1)
		{
			if(open == 0)
				zero();
			ans = ans * open % mod;
			--open;
		}
	}
	if(open != 0)
		zero();
	for(ll i = 1; i <= n; i++)
		ans = ans * i % mod;
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 1360
using System;
using System.Collections.Generic;

public class S
{
    public static void Main()
    {

        var N = int.Parse(Console.ReadLine());
        double sum = 0;

        string[] x = new string[2];

        for(int i = 0; i < N; i++){
            x = Console.ReadLine().Split(' ');
            sum += double.Parse(x[0]) * (x[1] == "JPY" ? 1 : 380000.0);

        }

        Console.WriteLine(sum);

    }
}

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

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



Measured memory_bytes: 3080
def solve():
    M, K = map(int, input().split())
    if K>=1<<M:
        return [-1]
    if M==1:
        if K==0:
            return [1,0,0,1]
        return [-1]
    ans = [K]
    for i in range(1<<M):
        if i!=K:
            ans.append(i)
    ans.append(K)
    for i in range((1<<M)-1,-1,-1):
        if i!=K:
            ans.append(i)
    return ans
print(*solve())

Measured memory_bytes: 21444
#import sys
MOD = 10 ** 9 + 7
#input = sys.stdin.readline
import math

import itertools

#import bisect

import copy


def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]
def main():
    h,a=map(int,input().split())
    print(-(-h//a))

if __name__ == "__main__":
    main()

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
using I=long;
using V=vector<I>;
#define R(n,i) for(I i=0; i<n; ++i)
I M=1e9+7,X=3e5,Z=20,T=0;
V P(X),S(X),D(X),B(X);
vector<V> C(X),Q(Z);
I inv(I x){
	I a=1;
	for(I n=M-2; n; n>>=1){if(n&1) a=a*x%M; x=x*x%M;}
	return a;
}

void s(I i){
	I x=1,d=0;
	for(I j:C[i]){
		s(j);
		x+=S[j];
		d=max(d,1+D[j]);
	}
	S[i]=x; D[i]=d;
}

I pyon(I i,I v){
	if(!v){++T; return 1;}
	if(v>D[i]) return 0;
	I k=0;
	while(Q[k+1][i]&&v>=1<<k+1) ++k;
	if(k) return pyon(Q[k][i],v-(1<<k));
	I j=C[i].size(),a=1,b=0;
	V z(j),p(j);
	R(j,k){
		I t=T; T=0;
		z[k]=pyon(C[i][k],v-1);
		p[k]=(B[T]-z[k]+M)%M;
		a=a*p[k]%M;
		T+=t;
	}
	R(j,k) b=(b+a*z[k]%M*inv(p[k]))%M;
	return b;
}

int main(){
	I N; cin>>N;
	R(N,i){
		cin>>P[i+1]; C[P[i+1]].push_back(i+1);
	}
	s(0);
	B[0]=1;
	R(N,i) B[i+1]=B[i]*2%M;
	Q[0].resize(N+1);
	R(N+1,i) if(C[i].size()==1) Q[0][i]=C[i][0];
	R(Z-1,k){
		Q[k+1].resize(N+1);
		R(N+1,i){
			I g=Q[k][i],h=Q[k][g];
			if(g&&h) Q[k+1][i]=h;
		}
	}
	I y=0;
	R(D[0]+1,v){
		T=0;
		I a=pyon(0,v);
		y=(y+a*B[N+1-T])%M;
	}
	cout<<y;
	return 0;
}


Measured memory_bytes: 66688
#include <bits/stdc++.h>
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define sort(a) sort((a).begin(),(a).end())
#define rev(a) reverse((a).begin(),(a).end())
using db = double;
using namespace std;
typedef long long ll;


int main() {
  set<int> s;
  int n;
  cin >> n;
  rep(i,n) {
    int d;
    cin >> d;
    s.insert(d);
  }
  cout << s.size() << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
using vs = vector<string>;
using vb = vector<bool>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
template<class T> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    string s, t;
    cin >> s >> t;
    int n = sz(s);
    int m = sz(t);
    int ans = INF;
    REP(i, n - m + 1) {
        int c = 0;
        REP(j, m) {
            if (s[i + j] != t[j]) c++;
        }
        chmin(ans, c);
    }
    cout << ans << endl;
}


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

liA = [0]
liB = [0]

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

for i in range(M):
    liB.append(liB[-1]+B[i])

# print(liA)
# print(liB)

ans = 0
for i in range(N+1):
    mm = K - liA[i]
    if mm<0:
        break
    fst = 0
    lst = M

    while(lst-fst>0):
        mid = ((fst+lst)//2)+1
        if mm >= liB[mid]:
            fst = mid
        elif mm<liB[mid]:
            lst = mid-1
        # print(fst,lst)
    ans = max(ans, i+fst)

print(ans)




Measured memory_bytes: 126512
// https://atcoder.jp/contests/agc006/tasks/agc006_b

#include <algorithm>
#include <iostream>
#include <numeric>
#include <set>
#include <vector>
using namespace std;

int main() {
    int n, x, len;
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> x;
    len = 2 * n - 1;
    set<int> st;
    for (int i = 1; i <= len; i++) {
        if (i < x - 1 || i > x + 1) {
            st.insert(i);
        }
    }

    if (x == 1 || x == len) {
        cout << "No\n";
    } else {
        cout << "Yes\n";
        int cnt = 0;
        for (auto i : st) {
            cout << i << '\n';
            cnt++;
            if (cnt == len / 2 - 1) {
                cout << x - 1 << '\n' << x << '\n' << x + 1 << '\n';
            }
        }
        if (st.size() == 0) {
            cout << x - 1 << '\n' << x << '\n' << x + 1 << '\n';
        }
    }

    return 0;
}


Measured memory_bytes: 11264
/*input
snuke
snekee
*/

//code author: iamxlr8

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define endl "\n"
#define pb push_back
#define all(c) c.begin(),c.end()
#define hell 1000000007
#define inf 100000000000001
#define F first
#define S second
#define off ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

void solve()
{
	string s,t;
	cin>>s>>t;
	t.pop_back();
	if(s==t)
		cout<<"Yes";
	else
		cout<<"No";
}

int main() 
{
    off;
    ll tests=1;
    // cin>>tests;
    while(tests--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3656
/*  ex7_3
    hangan2020 */

#include <stdio.h>
#include <stdlib.h>
#define IS 101

int main(void){
    int H, W; // Matrix's height and width
    int i, j;
    char **pmatrix;

    scanf("%d %d", &H, &W);

    // Allocate memory for pointer to matrix's rows (one extra row for later use)
    pmatrix = (char**)calloc(H + 1, sizeof(char*));
    if(pmatrix == NULL){
        exit(1);
    }

    // Allocate memory for matrix's elements (through rows with size = width + 1 ; one extra width for later use) 
    for( i = 0; i < H + 1; i++){
        pmatrix[i] = (char*)calloc(W + 1, sizeof(char));
        if(pmatrix[i] == NULL){
            exit(1);
        }
    }

    //Input by loop
    for (i = 0; i < H ; i++){
        for(j = 0; j < W ; j++){
            scanf(" %c", &pmatrix[i][j]);
        }
    }

    // Scanning for '.' only rows
    for (i = 0; i < H ; i++){
        for(j = 0; j < W ; j++){
            if(pmatrix[i][j] != '.'){
                break;
            }
            else if((j == W-1)&&(pmatrix[i][j] == '.')){
                pmatrix[i][W] = 'n';// Mark n(for none) at end of row
            }
        }
    }
    // Scanning for '.' only columns
    for (j = 0; j < W ; j++){
        for(i = 0; i < H ; i++){
            if(pmatrix[i][j] != '.'){
                break;
            }
            else if((i == H-1)&&(pmatrix[i][j] == '.')){
                pmatrix[H][j] = 'n';// Mark n(for none) at end of column
            }
        }
    }

    //Printing out by loop ( except for rows or columns that starts with 'n')
    for (i = 0; i < H ; i++){
        if(pmatrix[i][W] != 'n'){
            for(j = 0; j < W ; j++){
                if(pmatrix[H][j] != 'n'){
                    printf("%c", pmatrix[i][j]);
                }
            }
        printf("\n");
        }
    }

    //Free allocated memories for elements
    for(i = 0; i < H; i++){
        free(pmatrix[i]);
    }
    //Free allocated memoties for row's pointers
    free(pmatrix);

    return 0;
}


Measured memory_bytes: 1676
x,y=list(map(int, input().split()))
z=list(map(int, input().split()))
ans=0
if z[0]>=y:
	ans=ans+z[1]
	z[1]=0
	ans=ans+(z[0]-y)
	z[0]=y

for i in range(x-1):
	if z[i]+z[i+1]>y:
		ans=ans+(z[i]+z[i+1])-y
		z[i+1]=z[i+1]-((z[i]+z[i+1])-y)

print(ans)

Measured memory_bytes: 14060
#include <bits/stdc++.h>
using namespace std;
  queue <char> a;
  queue <char> b;
  queue <char> c;
int main(){
  string sa,sb,sc;
  cin>>sa>>sb>>sc;
  for(int i=0;i<sa.length();i++){
    a.push(sa.at(i));
  }
  for(int i=0;i<sb.length();i++){
    b.push(sb.at(i));
  } 
  for(int i=0;i<sc.length();i++){
    c.push(sc.at(i));
  }    
  char temp='a';
  bool flag=1; 
  
  while(flag){
    if(temp=='a'){
      if(a.size()==0){
       cout<<"A"<<endl;
        return 0;
      }
      else if(a.front()=='a'){
        a.pop();
        temp='a';
      }
      else if(a.front()=='b'){
       a.pop();
      temp='b';
        }
      else if(a.front()=='c'){
      a.pop(); 
      temp='c';
      }
    }
    
    else if(temp=='b'){
      if(b.size()==0){
       cout<<"B"<<endl;
        return 0;
      }
      else if(b.front()=='a'){
        b.pop();
        temp='a';
      }
      else if(b.front()=='b'){
       b.pop();
      temp='b';

        }
      else if(b.front()=='c'){
      b.pop();
      temp='c';
      }
    }    
    else if(temp=='c'){
      if(c.size()==0){
       cout<<"C"<<endl;
        return 0;
      }
      else if(c.front()=='a'){
        c.pop();
        temp='a';
      }
      else if(c.front()=='b'){
       c.pop();
      temp='b';
      }
      else if(c.front()=='c'){
      c.pop();
      temp='c';
      }
    }
  }

  return 0; 
}

  

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

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)

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; }

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);
}

int main() {
	ll a,b,c,d;
	cin >> a >> b >> c >> d;
	ll lcmcd = lcm(c,d);

	ll pa,qa,ra;
	pa = (a-1)/c;
	qa = (a-1)/d;
	ra = (a-1)/lcmcd;
	ll ansa = pa+qa-ra;

	ll pb,qb,rb;
	pb = b/c;
	qb = b/d;
	rb = b/lcmcd;
	ll ansb = pb+qb-rb;
	cout << (b-a+1) - (ansb - ansa) << endl;

  return 0;
}


Measured memory_bytes: 256
import sys
from collections import Counter

H, W = map(int, sys.stdin.readline().split())

string = ""
for _ in range(H):
    string += sys.stdin.readline().strip()

counter = Counter(string)
e_one = 0
e_two = 0
e_four = 0
for key, count in counter.items():
    tmp = count // 4
    e_four += tmp
    count -= 4 * tmp
    tmp = count // 2
    e_two += tmp
    count -= 2 * tmp
    e_one += count

four = (H//2) * (W//2)
two = (H%2) * (W//2) + (H//2) * (W%2)
one = (H%2) * (W%2)

# print("exists", e_four, e_two, e_one)
# print("needs", four, two, one)

if four > e_four:
    print("No")
else:
    e_four -= four
    e_two += e_four * 2
    if two > e_two:
        print("No")
    else:
        e_two -= two
        e_one += e_two * 2
        if e_one == one:
            print("Yes")
        else:
            print("No")

Measured memory_bytes: 9404
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k;
	cin>>n>>k;
	int a[100010],ans=0;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		if(a[i]>=k)
		{
			ans++;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <cmath>
#define REP(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll = long long;
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
template<class T> inline void chmax(T &a,T b){if(a<b)a=b;}
template<class T> inline void chmin(T &a,T b){if(a>b)a=b;}

int digit(int n){
    int ret = 0;
    while(n){
        ret += n%10;
        n /= 10;
    }
    return ret;
}

int main(){
    cin.tie(0); ios_base::sync_with_stdio(false);
    int n,a,b;cin >> n >> a >> b;
    int ans = 0;
    for(int i=1;i<=n;++i){
        int sum = digit(i);
        if(a<= sum && sum <= b) ans += i;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use {
    proconio::{fastout, input, marker::*},
    std::cmp::*,
    std::collections::*,
    std::ops::*,
};

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

#[fastout]
fn main() {
    input! {
        n: usize,
        a: [usize; n]
    }
    let mut x = a[0];
    for i in 1..n {
        x = gcd(x, a[i]);
    }

    if x != 1 {
        println!("not coprime");
        return;
    }

    let mut set = BTreeSet::<usize>::new();
    for i in 0..n {
        if set.contains(&a[i]) && a[i] != 1 {
            println!("setwise coprime");
            return;
        }
        set.insert(a[i]);
    }

    let mut yet = vec![true; 1000001];
    for i in 2..=1000000 {
        if !yet[i] {
            continue;
        }
        let mut count = 0;
        for j in 1..=1000000 / i {
            yet[i * j] = false;
            if set.contains(&(i * j)) {
                count += 1;
                if count == 2 {
                    println!("setwise coprime");
                    return;
                }
            }
        }
    }
    println!("pairwise coprime");
}


Measured memory_bytes: 33980
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;

bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}

int main(){
  
  int n;
  cin>>n;
  string s;
  cin>>s;
  
  int l = 0, r = 0;
  int d;
  REP(i,n){
    if(s[i]=='('){
      l++;
    }else{
      r++;
    }
    d = l - r;
    if(d<0){
      s = '(' + s;
      l++;
      n++;
      i++;
    }
  }
  
  while(d>0){
    s += ')';
    d--;
  }
  cout<<s<<endl;
    
  return 0;
}


Measured memory_bytes: 256
using System;
using CompLib.Util;

public class Program
{
    public void Solve()
    {
        var sc = new Scanner();
        int h = sc.NextInt();
        int w = sc.NextInt();
        char[][] s = new char[h][];
        for (int i = 0; i < h; i++)
        {
            s[i] = sc.Next().ToCharArray();
        }

        int[] dy = new int[8] {1, 1, 1, 0, 0, -1, -1, -1};
        int[] dx = new int[8] {-1, 0, 1, -1, 1, -1, 0, 1};
        for (int i = 0; i < h; i++)
        {
            for (int j = 0; j < w; j++)
            {
                if (s[i][j] == '#') continue;
                int cnt = 0;
                for (int k = 0; k < 8; k++)
                {
                    int yy = i + dy[k];
                    int xx = j + dx[k];
                    if (yy < 0 || yy >= h) continue;
                    if (xx < 0 || xx >= w) continue;
                    if (s[yy][xx] == '#') cnt++;
                }

                s[i][j] = (char) ('0' + cnt);
            }
        }

        for (int i = 0; i < h; i++)
        {
            Console.WriteLine(new string(s[i]));
        }
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

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

class Program
{
	static void Main(string[] args)
	{
		//文字列を読み込む
		int N = int.Parse(Console.ReadLine());
		int[] Xn = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();

		int sum = Xn.Sum();

		int point = sum/N;

		double pointP = 1.0 * sum / N;

        if(pointP - (double)point > 0.5)
		{
			point++;
		}

		int answer = 0;

        for(int i=0; i<Xn.Length; i++)
		{
			answer += (Xn[i] - point) * (Xn[i] - point);
		}
		
		Console.WriteLine(answer);
	}
}

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

class Dise:
    def __init__(self,a):
        self.dise = [0 for i in range(len(a))]
        for i in range(len(a)):
            self.dise[i] = a[i]

    def roll(self,dir):
        for self.pop_str in dir:
            if self.pop_str == "N":
                self.dise[0],self.dise[1],self.dise[4],self.dise[5] = self.dise[1],self.dise[5],self.dise[0],self.dise[4]
            elif self.pop_str == "S":
                self.dise[0],self.dise[1],self.dise[4],self.dise[5] = self.dise[4],self.dise[0],self.dise[5],self.dise[1]
            elif self.pop_str == "E":
                self.dise[0],self.dise[2],self.dise[3],self.dise[5] = self.dise[3],self.dise[0],self.dise[5],self.dise[2]
            elif self.pop_str == "W":
                self.dise[0],self.dise[2],self.dise[3],self.dise[5] = self.dise[2],self.dise[5],self.dise[0],self.dise[3]

    def N(self):
        self.dise[0],self.dise[1],self.dise[4],self.dise[5] = self.dise[1],self.dise[5],self.dise[0],self.dise[4]

    def S(self):
        self.dise[0],self.dise[1],self.dise[4],self.dise[5] = self.dise[4],self.dise[0],self.dise[5],self.dise[1]

    def E(self):
        self.dise[0],self.dise[2],self.dise[3],self.dise[5] = self.dise[3],self.dise[0],self.dise[5],self.dise[2]

    def W(self):
        self.dise[0],self.dise[2],self.dise[3],self.dise[5] = self.dise[2],self.dise[5],self.dise[0],self.dise[3]

    def R(self):
        self.dise[1],self.dise[2],self.dise[3],self.dise[4] = self.dise[3],self.dise[1],self.dise[4],self.dise[2]

    def L(self):
        self.dise[1],self.dise[2],self.dise[3],self.dise[4] = self.dise[2],self.dise[4],self.dise[1],self.dise[3]

    #確認用
    def output(self):
        print(self.dise[2])


for i in range(n):
    X = Dise(a)
    count = 0
    top,front = [int(i) for i in input().split()]

    while X.dise[0] != top and X.dise[1] != front:
        X.N()
        count += 1
        if count >= 4:
            X.E()
            count += 1
            if count >= 8:
                X.R()

    if X.dise[0] == top:
        while X.dise[1] != front:
            X.R()
    elif X.dise[1] == front:
        while X.dise[0] != top:
            X.E()
    X.output()



Measured memory_bytes: 5628
#include<stdio.h>
int main()
{
    int A,B,K,y,z;
    scanf("%d%d",&A,&B);
    K=(A+B)/2;
    y=A-K;
    z=B-K;
    if(y<0)
        y=-y;
    if(z<0)
        z=-z;
    if(y==z)
        printf("%d\n",K);
    else
        printf("IMPOSSIBLE\n");
    return 0;
}

Measured memory_bytes: 128
// IN THE NAME OF GOD
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define ff first
#define ss second
using namespace std;
const int MAXN = 1e5 + 15;
int n, a[MAXN], ans;
map <int, int> pos;
vector <int> vect;
int main(){
  //ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  for(int i = 0; i < n; i++) cin >> a[i], vect.pb(a[i]);
  sort(vect.begin(), vect.end());
  for(int i = 0; i < (int)vect.size(); i++) pos[vect[i]] = i;
  for(int i = 0; i < n; i++) if(abs(i - pos[a[i]]) % 2) ans++;
  cout << ans / 2 << endl;
}


Measured memory_bytes: 5752
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

string binRep(ll n){
    string s = "";
    while(n != 0){
        ll m = n%2;
        (m == 0) ? s="0"+s : s="1"+s;
        n /= 2;
    }
    return s;
}

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

    // 0の場合は0を出力
    if(n == 0){ cout << 0 << endl; return 0; }

    // 出力用
    string ans = "";

    // 0以外の場合は-2で割って各桁の表記を決めていく
    while(n != 0){
        m = abs(n%(-2));
        ans += (char)('0'+m);
        n = (n-m)/(-2);
    }

    // 反転して出力
    reverse(all(ans));
    cout << ans << endl;
}

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

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

    vector<string> res = {};

    int n = 0;
    int pow = 1;
    while (pow <= l) {
        pow *= 2;
        n++;
    }

    for (int i = 0; i < (n - 1); i++) {
        string xx = to_string(i + 1);
        string yy = to_string(i + 2);
        res.push_back(xx + " " + yy + " 0");
        res.push_back(xx + " " + yy + " " + to_string(1<<i));
    }

    int path = 2 * (n - 1);

    int x = 1<<(n - 1);
    for (int i = n - 2; i >= 0; i--) {
        // 作ることのできるパス
        if (l & 1<<i) {
            path++;
            res.push_back(to_string(i + 1) + " " + to_string(n) + " " + to_string(x));
            x += 1<<i;
        }
    }

    cout << n << " " << path << endl;
    for (string s : res) {
        cout << s << endl;
    }
}

Measured memory_bytes: 3680
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <algorithm>
using namespace std;

set< vector<string> > S;

int func[2][8] = {
    {4, 5, 1, 0, 7, 6, 2, 3},
    {1, 2, 3, 0, 5, 6, 7, 4}
};

void rot(vector<string> s) {
    for(int i=0; i<2; i++) {
        vector<string> nxt(8);
        for(int k=0; k<8; k++) {
            nxt[ func[i][k] ] = s[k];
        }
        if(S.count(nxt)) continue;

        S.insert(nxt);
        rot(nxt);
    }
}

int main() {
    string s;
    while(cin >> s) {
        vector<string> vs;
        vs.push_back(s);
        for(int i=0; i<7; i++) {
            cin >> s;
            vs.push_back(s);
        }
        S.clear();
        sort(vs.begin(), vs.end());

        int ans = 0;
        do {
            if(S.count(vs)) continue;
            ans++;

            S.insert(vs);
            rot(vs);
        }while(next_permutation(vs.begin(), vs.end()));
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 8832
N, M = map(int, input().split())
A = list(map(int, input().split()))

a = [A[0] % M]
for i in range(1, N):
    a.append((a[-1] + A[i]) % M)
# print (a)
from collections import Counter
C = Counter(a)
# print (C)

ans = 0
for i in C:
    ans += C[i] * (C[i] - 1)

ans //= 2
# print (ans)
ans += C[0] #+ (C[0] * (C[0] - 1))//2
print (ans)



Measured memory_bytes: 16552
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            while (true) {
            int n = sc.nextInt();
            if (n == 0) { 
                break; 
            }

            int[] scores = new int[n];
            for (int i = 0; i < scores.length; i++) {
            scores[i] = sc.nextInt();
            }

            int sum = 0;
            double average = 0, variance = 0;

            for (int i = 0; i < scores.length; i++) {
                sum = sum + scores[i];
            }
            average = (double)sum/scores.length;

            double hensa=0;
            for (int i = 0; i < scores.length; i++) {
                hensa = hensa + (scores[i] - average)*(scores[i] - average);
            }

            variance = hensa/scores.length;
            // … 平均値averageと，分散varianceを計算しよう …
            System.out.println(Math.sqrt(variance));
            }
            }
        
    }
}


Measured memory_bytes: 31660
def main():
    import sys
    read = sys.stdin.buffer.read
    readline = sys.stdin.buffer.readline
    readlines = sys.stdin.buffer.readlines
    sys.setrecursionlimit(10 ** 7)

    n, k = map(int, readline().split())
    a = list(map(int, readline().split()))
    for i in range(k):
        memo = [0] * (n + 1)
        for j, aa in enumerate(a):
            memo[max(0, j - aa)] += 1
            memo[min(n, j + aa + 1)] -= 1
        for j in range(n):
            memo[j + 1] += memo[j]
        a = memo[:-1]
        if a == [n] * n:
            break
    print(*a)


if __name__ == '__main__':
    main()


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

using namespace std;
struct node{
    node(int i){label = i;}
    int label;
    vector< node* > adj;
};
vector<int> visited;
vector<int> dp;
void dfs(node* crr){
    //cout<<crr->label<<endl;
    if(visited[crr->label])return;
    if(crr->adj.size()==0){dp[crr->label]=1;return;}
    int mxx=INT_MIN;
    for(node* nd: crr->adj){
        if(nd==NULL)continue;
        //cout<<crr->label<<"->"<<nd->label<<endl;
        dfs(nd);
        mxx=max(mxx,dp[nd->label]);
    }
    dp[crr->label]=mxx+1;
    visited[crr->label]=1;
}
int main(){
    int N, M, n1, n2;
    cin>>N>>M;
    visited.assign(N+1,0);
    dp.assign(N+1,0);
    vector< node* > nodes;
    for(int i=0;i<N+1;i++)nodes.push_back(new node(i));
    for(int i= 0;i<M;i++){
        cin>>n1>>n2;
        nodes[n1]->adj.push_back(nodes[n2]);
    }
    for(node* nd:nodes)dfs(nd);
    int ans=INT_MIN;
    for(int i=1; i<=N; i++){
        //cout<<dp[i]<<endl;
        ans=max(ans, dp[i]);
    }
    cout<<ans-1<<endl;
    return 0;
}

Measured memory_bytes: 12404
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<class T>using numr=std::numeric_limits<T>;
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; }
const int INF = 1e9;
const ll LLINF = 1e16;
const int MOD = 1000000007;
const int MOD2 = 998244353;

int main() {
    cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    double ret = 0;
    for(int i = 1; i <= N; i++) {
        int now = i;
        double add = 1.0;
        while(now < K) {
        now *= 2;
        add *= 0.5;
        }
        ret += (1.0 / N) * add;
    }
    cout << ret << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

int n;

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    int ans = n/2;
    if (n%2 == 0) ans--;
    cout << ans << E;
    //system("pause");
    return 0;
}

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

int main() {
  int money;
  int p = 0;  // 嬉しさ
  std::cin >> money;
  
  p += (money / 500 * 1000); // 500円の嬉しさ
  money %= 500;   // 残金の更新
  p += (money / 5 * 5); // 5円の嬉しさ

  std::cout << p;

  return 0;

}

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

int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    int start = max(A, C);
    int end = min(B, D);
    int ans = end - start;
    if (ans > 0) {
        cout << ans << endl;
    } else {
        cout << 0 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<numeric>
#include<stack>
#include<map>
#include<queue>
#include<unordered_map>
#include<cmath>
#include<utility>

using ULL = unsigned long long;
using LL = long long;
using String = std::string;
using Ints = std::vector<int>;
using Doubles = std::vector<double>;
using Bools = std::vector<bool>;
using Strings = std::vector<std::string>;
using ULLs = std::vector<ULL>;
using LLs = std::vector<LL>;

// pythonのdictionary相当
template <typename T1, typename T2>
using Dict = std::unordered_map<T1,T2>;



int main(void) {
    int N;
    std::cin >> N;
    Ints a;
    int res=0;

    for(int i=0;i<N;i++){
        int _a;
        std::cin >> _a;
        if(_a%2==1 && (i+1)%2==1)res++;
    }

    std::cout << res << std::endl;

    return 0;
}

Measured memory_bytes: 3632
"""
author : halo2halo
date : 4, Feb, 2020
"""

import sys

# import itertools
# import math

# import numpy as np

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

H, A = map(int, readline().split())
print((H-1)//A+1)

Measured memory_bytes: 2940
// Organize Your Train part II
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1142&lang=jp

#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>
#include<set>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;

string reverse(string train) {
    string res = "";
    for (int i = train.size() - 1; i >= 0; --i) {
        res += train[i];
    }
    return res;
}

int main() {
    int M;
    cin >> M;
    for (int nth = 0; nth < M; ++nth) {
        set<string> result;
        string train;
        cin >> train;

        for (int i = 0; i < train.size(); ++i) {
            string t1 = train.substr(0, i);
            string t2 = train.substr(i);
            result.insert(t1 + t2);
            result.insert(reverse(t1) + t2);
            result.insert(t1 + reverse(t2));
            result.insert(reverse(t1) + reverse(t2));
            result.insert(t2 + t1);
            result.insert(reverse(t2) + t1);
            result.insert(t2 + reverse(t1));
            result.insert(reverse(t2) + reverse(t1));
        }
        cout << result.size() << endl;
    }
	return 0;
}

Measured memory_bytes: 3220
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <set>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

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

signed main(){
  string s; cin>>s;
  int n = s.size();
  if(s=="zyxwvutsrqponmlkjihgfedcba"){
    cout << -1 << endl;
    return 0;
  }
  bool used[26]; rep(i,26) used[i]=false;
  rep(i,n) used[s[i]-'a'] = true;
  string ans = "";
  if(n==26){
    string t = s;
    next_permutation(ALL(s));
    rep(i,n){
      ans.PB(s[i]);
      if(s[i]>t[i]) break;
    }
    cout << ans << endl;
  }else{
    ans = s;
    cout<<ans;
    rep(i,26){
      if(!used[i]){
        char p = 'a'+i;
        return cout<<p<<endl,0;
      }
    }
  }

  return 0;
}


Measured memory_bytes: 256
/*input
60522 114575 7559
*/
/*

**************************
*						 *
* AUTHOR :: knight_coder *
*						 *
**************************

*/
#include<bits/stdc++.h>
#define lld          long long int
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<lld,lld>
#define msi         map<string,lld>
#define mis         map<lld, string>
#define mpi         map<pair<lld ,lld >,lld >
#define pii         pair<lld,lld>
#define vi          vector<lld>
#define vpi 		vector<pii>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (lld)x.size()
#define hell        998244353
#define rrep(i,m,n)	for(lld i=m;i>=n;i--)
#define rep(i,m,n)	for(lld i=m;i<n;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
#define pr(x) 		cout<< x << " ";
#define pre(x)		cout<< x << endl ;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; 
//change null_type to get ordered_map
#define M  500005
#define DEC(M)	cout << std::fixed; cout << setprecision(N);
lld f[M],inv[M];
lld expo(lld base,lld exponent,lld mod){
    lld ans=1;
    while(exponent!=0){
        if(exponent&1) ans=(1LL*ans*base)%mod;
        base=(1LL*base*base)%mod;
        exponent>>=1;
    }
    return ans%mod;
}
void compute(){
	f[0]=1;
	rep(i,1,M){
		f[i]=(1LL*i*f[i-1])%hell;
	}
	inv[M-1]=expo(f[M-1],hell-2,hell);
	for(lld i=M-2;i>=0;i--){
		inv[i]=(1LL*(i+1)*inv[i+1])%hell;
	}
}
lld C(lld n,lld r){
	return (1LL*((1LL*f[n]*inv[r])%hell)*inv[n-r])%hell;
}
void solve()
{
	lld n,m,k;
	cin >> n >> m >> k;
	lld ans=0;
	compute();
	rep(i,0,k+1){
		lld p=(m*expo(m-1,n-i-1,hell))%hell;
		p=(p*C(n-1,i))%hell;
		ans+=p;
		ans%=hell;
	} 
	cout << ans << endl;
}
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tests=1;
	//cin>>tests;
	while(tests--)
	{
		solve();
	}
}

Measured memory_bytes: 11480
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#include <cstdlib> 
#include <math.h>
#include<cstdio>
#include<cstring>
#define FOR(I, A, B) for (int I = (A); I <= (B); I++)
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fo(i,n) for(int i=0;i<n;i++)
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define dbg(x) cout << #x << " = " << x << endl
#define dbg2(x,y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define dbg3(x,y,z) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl
#define dbg4(x,y,z,q) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << ", " << #q << " = " << q << endl
#define scan(char_array) scanf("%[^\n]s",&char_array)
#define inin freopen("input2.txt", "r", stdin)


int main(){
	//inin;
    IOS
	ll n,c;
	cin>>n>>c;
	ll a[n+1][n+1];
	ll d[c+1][c+1];
	FOR(i,1,c){
		FOR(j,1,c){
			cin>>d[i][j];
		}
	}
	FOR(i,1,n){
		FOR(j,1,n){
			cin>>a[i][j];
		}
	}

	map<ll,ll> zer;

     map<ll,ll> one;	
     map<ll,ll> two;
     FOR(i,1,n){
		FOR(j,1,n){
			if((i+j)%3==0){
				zer[a[i][j]]++;
			}
			if((i+j)%3==1){
				one[a[i][j]]++;
			}
			if((i+j)%3==2){
				two[a[i][j]]++;
			}
		}
	}
	ll tmp;
	ll ans=10000000000000;
	FOR(i,1,c){
		FOR(j,1,c){
			FOR(k,1,c){
				if(j!=i&&k!=j&&k!=i){
					tmp=0;
					for(auto oo:zer){
						if(oo.first!= i) tmp+=(oo.second*d[oo.first][i]);
					}
					for(auto oo:one){
						if(oo.first!= j) tmp+=(oo.second*d[oo.first][j]);
					}
					for(auto oo:two){
						if(oo.first!= k) tmp+=(oo.second*d[oo.first][k]);
					}
					ans=min(ans,tmp);
				}
			}
		}
	}
	cout<<ans<<endl;

}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define endl "\n"
const int MAX= 100005 ;
const long long mod = 1.0e9+7;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
        cin>>n;
        cout<<3*n*n<<endl;
    return 0;
}

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

string s, t;
int main(){
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end(), greater<void>());
  
  if( s < t) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    for i in range(k, n):
        if a[i] > a[i-k]:
            print('Yes')
        else:
            print('No')
                    
if __name__ == '__main__':
    main()

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T> void operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) cin >> e; }

typedef long long ll;
int const inf = 1<<29;

int main() {

  int N; cin >> N;
  vector<int> vs(3 * N);
  rep(i, 3 * N) {
    cin >> vs[i];
  }

  sort(all(vs));

  bool skip = true;
  int n = N;
  ll ans = 0;
  for (int i=vs.size() - 1; i>=0; i--) {
    if (!skip) {
      ans += vs[i];
      n--;
      if (n == 0) break;
    }
    skip = !skip;
  }

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

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

void solve(long long A, long long B)
{
    cout << max(0LL, A - 2 * B) << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long A;
    scanf("%lld", &A);
    long long B;
    scanf("%lld", &B);
    solve(A, B);
    return 0;
}


Measured memory_bytes: 256