akhauriyash/Code-Regression huggingface dataset:
using System;

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            var NM = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var N = NM[0]; var M = NM[1];
            var sc = new int[M, 2];
            for (int i = 0; i < M; i++)
            {
                var read = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
                sc[i, 0] = read[0];
                sc[i, 1] = read[1];
            }
            var check1 = false;
            int min;
            int max;
            if (N == 1)
            {
                min = 0; max = 9;
            }
            else if (N == 2)
            {
                min = 10; max = 99;
            }
            else
            {
                min = 100; max = 999;
            }
            for (int i = min; i <= max; i++)
            {
                var check = true;
                var str = i.ToString();
                for (int j = 0; j < M; j++)
                {
                    if (str[sc[j, 0] - 1] != sc[j, 1].ToString()[0])
                    {
                        check = false;
                        break;
                    }
                }
                if (check)
                {
                    Console.WriteLine(i);
                    check1 = true;
                    break;
                }
            }
            if (!check1) Console.WriteLine(-1);
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
int H, W;
const int MAX_K = 85 * 85 * 2 + 1;
bool dp[80][80][MAX_K] = {};

int main() {
    cin >> H >> W;
    vector<vector<int>> A(H, vector<int>(W)), B(H, vector<int>(W));
    for(int i=0; i<H; ++i) {
        for(int j=0; j<W; ++j) {
            cin >> A[i][j];
        }
    }
    for(int i=0; i<H; ++i) {
        for(int j=0; j<W; ++j) {
            cin >> B[i][j];
        }
    }

    dp[0][0][abs(A[0][0] - B[0][0])] = true;
    for(int i=0; i<H; ++i) {
        for(int j=0; j<W; ++j) {
            for(int k=0; k<MAX_K; ++k) {
                if(i + 1 < H) {
                    if(abs(k + A[i + 1][j] - B[i + 1][j]) <= MAX_K) dp[i + 1][j][abs(k + A[i + 1][j] - B[i + 1][j])] |= dp[i][j][k];
                    if(abs(k - A[i + 1][j] + B[i + 1][j]) <= MAX_K) dp[i + 1][j][abs(k - A[i + 1][j] + B[i + 1][j])] |= dp[i][j][k];
                }
                if(j + 1 < W) {
                    if(abs(k + A[i][j + 1] - B[i][j + 1]) <= MAX_K) dp[i][j + 1][abs(k + A[i][j + 1] - B[i][j + 1])] |= dp[i][j][k];
                    if(abs(k - A[i][j + 1] + B[i][j + 1]) <= MAX_K) dp[i][j + 1][abs(k - A[i][j + 1] + B[i][j + 1])] |= dp[i][j][k];
                }
            }
        }
    }

    for(int k=0; k<MAX_K; ++k) {
        if(dp[H - 1][W - 1][k]) {
            cout << k << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 90624
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", ans);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

    
    for (int j = 0; ; j++) {
        bool ok = true;
        if (s.size() % 2) ok = false;
        rep (i, s.size() / 2) {
            if (!ok) break;
            if (s[i] != s[i + s.size() / 2]) ok = false;
        }
        if (ok && j) {
            cout << s.size() << endl;
            return 0;
        }
        else s.pop_back();
    }

    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main
{
  static long x = 0;
  static long y = 0;

  static long m[][] = new long[64][2];

  public static void main(String[] args) throws IOException
  {
    BufferedReader r = new BufferedReader(new InputStreamReader(System.in), 1);
    String s = r.readLine();
    String[] sl = s.split(" ");
    x = Long.parseLong(sl[0]);
    y = Long.parseLong(sl[1]);

    if((x + y) % 3 != 0 || y > 2 * x || x > 2 * y)
    {
      System.out.println(0);
      System.exit(0);
    }

    long n = (x + y) / 3;
    long k = 2 * n - y;
    long u = n - k;

    //System.out.println(n);
    //System.out.println(k);
    //System.out.println(u);

    long a = 1;
    RemRing rr = new RemRing(1000000007L);
    for(int i = 1; i <= n; i++)
    {
      a = rr.prod(a, i);
    }
    for(int i = 1; i <= k; i++)
    {
      a = rr.div(a, i);
    }
    for(int i = 1; i <= u; i++)
    {
      a = rr.div(a, i);
    }

    System.out.println(a);

  }

}

class RemRing
{
 long module;
 public RemRing(long module)
 {
   this.module = module;
 }

 public long sum(long a, long b)
 {
   return (a + b + module) % module;
 }

 public long sub(long a, long b)
 {
   return (a - b + module) % module;
 }

 public long prod(long a, long b)
 {
   return (a * b) % module;
 }

 public long div(long a, long b)
 {
   return (a * inv(b)) % module;
 }

 public long inv(long a)
 {
   long b = this.module;
   long u = 1;
   long v = 0;
   while(b > 0)
   {
     long t = a / b;
     a -= t * b;
     u -= t * v;
     long z = a;
     a = b;
     b = z;
     z = u;
     u = v;
     v = z;
   }
   u %= this.module;
   if(u < 0) u += this.module;
   return u;
 }

}


Measured memory_bytes: 24788
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	const int64_t INF = 1e18;
	int64_t n; cin >> n;
	int64_t a[n]; rep(i,n) cin >> a[i];
	sort(a, a + n);
	int64_t ans = 1;
	rep(i,n) {
		if(a[i] == 0) {
			ans = 0;
			break;
		}
		if(ans > INF / a[i]) {
			ans = -1;
			break;
		}
		ans *= a[i];
		if(ans > INF) {
			ans = -1;
			break;
		}
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 4420
S=input()
N=len(S)
 
a=False
 
for i in range(N):
    if S[i]!=S[N-1-i]:
        print("No")
        a=False
        break
    else:
        a=True
 
if a==True:
    for j in range(int((N-3)/2)+1):
        if S[j]!=S[int((N-3)/2)-j]:
            a=False
            print("No")
            break
if a==True:
    for k in range(int((N-3)/2)+1):
        if S[int((N+1)/2)+k]!=S[N-1-k]:
            a=False
            print("No")
            break
if a==True:
    print("Yes")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define pb push_back
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
using namespace std;
int main(){
  int n;
  cin >> n;
  cout << 1110 - n << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define llint long long
using namespace std;
llint n;
string s;
llint sum[3][4005];
int main(void)
{
	cin >> n;
	cin >> s;
	s = "#" + s;
	
	llint ans = 0;
	for(int i = 1; i <= n; i++){
		if(s[i] == 'R') s[i] = '0';
		if(s[i] == 'G') s[i] = '1';
		if(s[i] == 'B') s[i] = '2';
	}
	for(int i = 1; i <= n; i++){
		for(int j = 0; j < 3; j++) sum[j][i] = sum[j][i-1];
		sum[s[i]-'0'][i]++;
	}
	
	for(int i = 1; i <= n; i++){
		llint c = s[i]-'0';
		ans += sum[(c+1)%3][i-1] * (sum[(c+2)%3][n] - sum[(c+2)%3][i]);
		ans += sum[(c+2)%3][i-1] * (sum[(c+1)%3][n] - sum[(c+1)%3][i]);
		for(int j = 1; j <= n; j++){
			if(i-j <= 0 || i+j > n) break;
			if(s[i-j] != s[i] && s[i] != s[i+j] && s[i+j] != s[i-j]) ans--;
		}
	}
	cout << ans << endl;
	
	
	return 0;
}

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

int N;
vector<int> A;
vector<int> m;

int main(){
  cin >> N;
  A.resize(N);
  m.resize(N);

  int v; int sum = 0;
  for(int i = 0; i < N; i++){
    cin >> v; A[i] = v;
    sum += v;
  }


  sum /= 2;   //x1 + x2 + ... + xnの値
  
  for(int i = 0; i < (N-1)/2; i++)
    sum -= A[2 * i];

  m[N-1] = sum;        //Xnの値   山Nに降ったのは2*Xn

  for(int i = N-2; i >= 0; i--)
    m[i] = A[i] - m[i+1];

  for(int i = 0; i < N; i++)
    cout << 2 * m[i] << " ";
  return 0;
}




Measured memory_bytes: 2048
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head




const int N = 1e6+50;


int n,m,v[N],d[N],c[N];
vector<int> g[N];
int vis[N], ans[N];

void dfs(int x, int d, int c) {
	if (vis[x]>=d) return;
	if (!ans[x]) ans[x] = c;
	vis[x] = d;
	for (int y:g[x]) dfs(y,d-1,c);
}
int main() {
	scanf("%d%d",&n,&m);
	REP(i,1,m) {
		int u=rd(),v=rd();
		g[u].pb(v),g[v].pb(u);
	}
	int q=rd();
	REP(i,1,q) v[i]=rd(),d[i]=rd(),c[i]=rd();
	PER(i,1,q) {
		dfs(v[i],d[i]+1,c[i]);
	}
	REP(i,1,n) printf("%d\n", ans[i]);
}


Measured memory_bytes: 39416
#include <bits/stdc++.h>
 
#define PAUSE system("pause")
#define LLI long long int
#define LD long double
#define PB push_back
#define PF push_front
#define MP make_pair
#define FORi(i, a, b) for(int i = a; i < b ; ++i)
#define FORd(i, a, b) for(int i = a; i > b ; --i)
 
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> v(n);
	vector<LLI> pref(n+1, 0);
	FORi(i,0,n){
		cin >> v[i];
		pref[i+1] = pref[i] + v[i];
	}
	LLI ans = 1e18;
	FORi(i,0,n-1){
		ans = min(ans, abs(pref[n] - 2 * pref[i+1] + pref[0]));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef ll Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<double,int,double> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf=sizeof(Def)==sizeof(long long)?2e18:1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	ll n,m;
	cin>>n>>m;
	ll out=0,MOD=1000000007;
	if(n==1){
		cout<<(m+1)%MOD<<endl;
		return 0;
	}
	ll t=m/(n-1);
	t%=MOD;
	out=((m%(n-1)%MOD)+1)*t%MOD+t*(t-1)/2%MOD*(n-1)%MOD;
//	cout<<out<<endl;
	out=out%MOD;
	out*=2;
	out=out%MOD;
	out+=m+1;
	out=out%MOD;
	cout<<out<<endl;
	
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  int n;
  cin >> n;
  vector<int> l(2*n);
  REP(i,2*n) cin >> l[i];
  sort(ALL(l));
  int res = 0;
  REP(i,n){
    res += min(l[2*i], l[2*i+1]);
  }
  cout << res << endl;
  return 0;
}


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

#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)
int main()
{
	ll N; cin >> N;
	if (N >= 64)cout << 64;
	else if (N >= 32)cout << 32;
	else if (N >= 16)cout << 16;
	else if (N >= 8)cout << 8;
	else if (N >= 4)cout << 4;
	else if (N >= 2)cout << 2;
	else if (N >= 1)cout << 1;

	cout << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args)throws Exception{
		Scanner stdIn=new Scanner(System.in);
		int n=stdIn.nextInt();
		int i=2,a=1,b=1;
		if(n==0){
			System.out.println(1);
			System.exit(0);
		}
		if(n==1){
			System.out.println(1);
			System.exit(0);
		}
		dfs(i,a,b,n);
	}
	public static void dfs(int i,int a,int b,int n){
		if(i==n){
			System.out.println(b+a);
			System.exit(0);
		}
		i++;
		dfs(i,b,a+b,n);
	}
}



Measured memory_bytes: 26200
#import<iostream>
#import<map>
#import<queue>
#import<cstdlib>
#import<cstring>
using namespace std;struct B{int z[2];char s[14];bool operator<(const B&r)const{return strcmp(s,r.s)<0;}};main(){int a[13][5]={{2,-1},{2,5,-1},{0,1,3,6,-1},{2,7,-1},{5,-1},{1,4,6,9,-1},{2,5,7,10,-1},{3,6,8,11,-1},{7,-1},{5,10,-1},{6,9,11,12,-1},{7,10,-1},{10,-1}},X[]={2,1,2,3,0,1,2,3,4,1,2,3,2},Y[]={0,1,1,1,2,2,2,2,2,3,3,3,4},v,d,s,i,j,t,u;B g={0,0,"0123456789:;0"};for(;;){map<B,int>m;queue<B>q;B b={i=-1,-1};for(;++i<13;!v?b.z[*b.z>=0]=i:0){cin>>v;if(v<0)return 0;b.s[i]=48+v;}b.s[13]=0;m[b]=1;for(q.push(b);!q.empty();q.pop()){B&b=q.front();if(!strcmp(b.s,g.s))break;d=0;for(i=13;i--;v?d+=abs(X[v]-X[i])+abs(Y[v]-Y[i]):0)v=b.s[i]-48;s=m[b];if(s+d<22)for(j=2;j--;)for(i=0;~a[u=b.z[j]][i];i++){B n=b;t=n.z[j]=a[u][i];if(t-n.z[1-j]){swap(n.s[u],n.s[t]);int&r=m[n];if(!r)r=s+1,q.push(n);}}}printf(m[g]?"%d\n":"NA\n",m[g]-1);}}

Measured memory_bytes: 1484
# region
import sys
import itertools

DEBUG = True if (len(sys.argv) > 1 and sys.argv[1] == "DEBUG") else False


def dp(value):
    if DEBUG:
        print(value)
    return


def input_text(split=" "):
    # 入力
    result = []
    while True:
        try:
            row = list(
                map(lambda x: int(x) if x.isdecimal() else x, input().split(split))
            )
            result.append(row)
        except EOFError:
            break
    return result


# endregion
it = input_text()
a = int(str(it[0][0])[-1])

if a in (2, 4, 5, 7, 9):
    print("hon")

if a in (0, 1, 6, 8):
    print("pon")

if a == 3:
    print("bon")


Measured memory_bytes: 62116
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int cost[50][50],grid[505][505],n,c;
int box[3][50],dp[50][3];
vector<pair<int,int> >v[4];
int recur(int pos,int taken,int used[])
{
    if(taken==3)
        return 0;
    if(pos>c)
        return 1e9;
    int &ret=dp[pos][taken];
    ret=INT_MAX;
    for(int i=0; i<3; i++)
    {
        if(!used[i])
        {
            used[i]=1;
            ret=min(recur(pos+1,taken+1,used)+box[i][pos],ret);
            used[i]=0;
        }
    }
    ret=min(ret,recur(pos+1,taken,used));
    return ret;
}
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    cin>>n>>c;
    for(int i=1; i<=c; i++)
        for(int j=1; j<=c; j++)
            cin>>cost[i][j];
    for(int i=1; i<=n; i++)
        for(int j=1; j<=n; j++)
            cin>>grid[i][j];
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=n; j++)
        {
            int m=(i+j)%3;
            v[m].push_back({i,j});
        }
    }
    int mn=INT_MAX,sz0=v[0].size(),sz1=v[1].size(),sz2=v[2].size();
    for(int i=1; i<=c; i++)
    {
        ll cur=0;
        for(int j=0; j<sz0; j++)
        {
            int x=v[0][j].first;
            int y=v[0][j].second;
            if(grid[x][y]!=i)
            {
                cur+=cost[grid[x][y]][i];
            }
        }
        box[0][i]=cur;

        cur=0;
        for(int j=0; j<sz1; j++)
        {
            int x=v[1][j].first;
            int y=v[1][j].second;
            if(grid[x][y]!=i)
            {
                cur+=cost[grid[x][y]][i];
            }
        }
        box[1][i]=cur;
        cur=0;
        for(int j=0; j<sz2; j++)
        {
            int x=v[2][j].first;
            int y=v[2][j].second;
            if(grid[x][y]!=i)
            {
                cur+=cost[grid[x][y]][i];
            }
        }
        box[2][i]=cur;
    }
   /* for(int i=0;i<3;i++){
        for(int j=1;j<=c;j++)
            cout<<box[i][j]<<" ";
        cout<<endl;
    }*/
    int used[5]= {0};
    cout<<recur(1,0,used)<<endl;


    return 0;
}


Measured memory_bytes: 6300
import sys
input=sys.stdin.readline
h,w=map(int,input().split())
field=[0]+["#"+input()+"#" for i in range(h)]+[0]
field[0],field[-1]="#"*(w+2),"#"*(w+2)
l,r,u,d=[[0 for i in range(w+2)] for i in range(h+2)],[[0 for i in range(w+2)] for i in range(h+2)],[[0 for i in range(w+2)] for i in range(h+2)],[[0 for i in range(w+2)] for i in range(h+2)]
for i in range(1,h+1):
  for j in range(1,w+1):
    if field[i][j]=="#":continue
    l[i][j]=l[i][j-1]+1
    u[i][j]=u[i-1][j]+1
for i in range(1,h+1)[::-1]:
  for j in range(1,w+1)[::-1]:
    if field[i][j]=="#":continue
    r[i][j]=r[i][j+1]+1
    d[i][j]=d[i+1][j]+1
ans=0
for i in range(h+2):
  for j in range(w+2):
    c=l[i][j]+r[i][j]+u[i][j]+d[i][j]-3
    if c>ans:ans=c
print(ans)


Measured memory_bytes: 180744
using System;
using System.Linq;

namespace ConsoleApp13
{
    class Program
    {
        static void Main(string[] args)
        {
            B();

        }

        static void A()
        {
            var A = int.Parse(Console.ReadLine());
            var B = int.Parse(Console.ReadLine());
            Console.WriteLine(6 - A - B);
        }

        static void B()
        {
            var N = int.Parse(Console.ReadLine());
            var ST = Console.ReadLine().Split();

            for (var i = 0; i < N; i++)
            {
                Console.Write(ST[0][i]);
                Console.Write(ST[1][i]);

            }

            Console.WriteLine();

        }
    }
}


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

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;

int main() {
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    int N; string S;
    cin >> N >> S;
    vector<int> whsum(N+1, 0);
    vector<int> blsum(N+1, 0);
    for (int i = 0; i < N; ++i) {
        whsum[i+1] = whsum[i] + (S[i] == '.' ? 1 : 0);
        blsum[i+1] = blsum[i] + (S[i] == '#' ? 1 : 0);
    }

    ll res = 1LL<<60;
    for (int left = 0; left <= N; ++left) {
        long long tmp = 0;
        // left を全部白に
        tmp += blsum[left] - blsum[0];

        // right を全部黒に
        tmp += whsum[N] - whsum[left];

        res = min(res, tmp);
    }
    cout << res << endl;
    return 0;
}



Measured memory_bytes: 2180
#!/bin/python

import os
import sys

def solution(N, A):
    res = 0
    sumTemp = -1
    while sumTemp != 0:
        sumTemp = 0
        for i in range(N):
            if A[i]%2 == 0:
                A[i] /= 2
                sumTemp += 1
        res += sumTemp
    return res

if __name__ == '__main__':
    N = int(raw_input())
    A = raw_input().split()
    for i in range(N):
        A[i] = int(A[i])
    result = solution(N,A)

    print str(result)

Measured memory_bytes: 3588
//大文字->小文字 tolower(),逆はtoupper()
//int a = stoi(c); 文字列をintへ
//途中の出力をそのまま残さない
//数値計算 基本はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map全探索　for (auto i = p.begin(); i != p.end();i++){}
//mapの要素 keyはp->first valueはp->second  
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// Nの桁数
ll dig(ll N) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= 10;
	}
	return dig;
}
// x,yの最大公約数
ll gcd(ll x, ll y) {
	ll r;
	while (x%y) {
		r = x % y;
		x = y;
		y = r;
	}
	return y;
}   // 


int main() {
	ll N; cin >> N;
	vector<double> X(N);
	rep(i, N) cin >> X[i];

	int mi = 1000;
	rep(i, N - 1)mi = min(X[i], X[i + 1]);
	int mx = 0;
	rep(i, N - 1)mx = max(X[i], X[i + 1]);

	ll ans = 100000000000000;
	for (int P = -200; P <= 200; P++) {
		ll tmp = 0;
		rep(i, N) { tmp += pow(X[i] - P, 2); }
		ans = min(ans, tmp);
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:16777216")
#include <string>
#include <vector>
#include <map>
#include <list>
#include <iterator>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <cmath>  
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>
#include <time.h>
#include <bitset>
using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ITER(it, a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(A,value) memset(A,value,sizeof(A))

#define ALL(V) V.begin(), V.end()
#define SZ(V) (int)V.size()
#define PB push_back
#define MP make_pair
const double PI=acos(-1.0);

typedef long long Int;
typedef long long LL;
typedef unsigned long long UINT;
typedef vector <int> VI;
typedef pair <int, int> PII;
typedef pair <double, double> PDD;

const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;

const int MAX = 1024;
const int MAX1 = 2007;
const int MAX2 = 24000000;
const int LEN = 21;
const int BASE = 1000000000;

const int MOD = 1000000007;

double x, y, xx, yy;
int n;
double X[MAX], Y[MAX], R[MAX];
double D[MAX][MAX];
double W[MAX];
int U[MAX];

double dist(int x, int y, int xx, int yy)
{
  return sqrt((long double)(x-xx)*(x-xx) + (long double)(y-yy)*(y-yy));
}

int main()
{
  cin >> x >> y >> xx >> yy;
  cin >> n;
  FOR (i,0,n)
  {
    cin >> X[i] >> Y[i] >> R[i];
  }

  X[n] = x;
  Y[n] = y;
  R[n] = 0;

  X[n+1] = xx;
  Y[n+1] = yy;
  R[n+1] = 0;

  n += 2;

  FOR (i,0,n)
    FOR (j,0,n)
    {
      double t = dist(X[i], Y[i], X[j], Y[j]);
      double d = t-R[i]-R[j];
      d = max(d, 0.0);

      D[i][j] = d;
    }

  FOR (i,0,n) 
    W[i] = 1e+10;
  W[n-2] = 0;

  FOR (it,0,n)
  {
    int id = -1;
    double mn = 1e+10;
  
    FOR (i,0,n)
      if (U[i] == 0 && W[i] < mn)
      {
        mn = W[i];
        id = i;
      }

    U[id] = 1;

    FOR (i,0,n)
      W[i] = min(W[i], W[id] + D[id][i]);
  }

  printf("%0.10f\n", W[n-1]);






  
  return 0;
}


Measured memory_bytes: 8448
// /*
// power code taken from geeks for geeks
// */

#include <bits/stdc++.h>
#define MODD 1000000007LL
#define MAX_SIZE 100000000
#define MAX_N 200001
using namespace std;
typedef long long ll;
typedef long double ld;

ll max(ll a,ll b){return a>b?a:b;}
ll min(ll a,ll b){return a<b?a:b;}
double max(double a,double b){return a>b?a:b;}
double min(double a,double b){return a<b?a:b;}

ll modd(ll a){if(a<0LL) return a*-1LL;return a;}
double modd(double a){if(a<0.0) return a*-1.0;return a;}

ll modulo(ll a){return a % MODD; }

ll power(ll k, ll p){
    if (p == 0)
        return 1LL;
 
    ll P = power(k, p/2LL);
    P = (P * P) % MODD;
 
    if (p % 2 == 1)
        P = (P * k) % MODD;
 
    return P;
}


struct p_str{
    char s;
    ll m;
};

void swap(ll& s1, ll &s2){
    ll temp=s1;
    s1=s2;
    s2=temp;
}

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

bool comp(ll a, ll b){
    return a>b;
}


void solve(){
    ll a, b;
    cin>>a>>b;
    cout<<a*b<<endl;
}



int main(){



    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll t=1;

    ll i=1;

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

        solve();
    }
    return 0;
}


Measured memory_bytes: 3644
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

int main(){
  ll N; cin >> N;
  vector<ll> a(N + 1); rep(i,N + 1) cin >> a[i];
  vector<ll> sum(N + 5);
  for(ll i = N + 1 ; i > 0 ; i --){
    sum[i - 1] = sum[i] + a[i - 1];
  }
  // 1こ上の深さでの葉でない頂点の個数の2倍
  vector<ll> v(N + 5 , 1e18); v[0] = 1;
  if(a[0] > 1){
    cout << -1 << endl;
    return 0;
  }
  rep(i,N){
    v[i + 1] = 2 * (v[i] - a[i]);
    if(v[i + 1] > 1e16) break;
    if( ( i + 1 < N and v[i + 1] < 1 ) or v[i + 1] < a[i + 1] ){
      cout << -1 << endl;
      return 0;
    }
  }

  ll ans = 0;
  rep(i,N + 1){
    ans += min(v[i] , sum[i]);
    // cout << i << " " << min(v[i]  , sum[i]) << " " << a[i] << endl;
  }
  cout << ans << endl;
}


Measured memory_bytes: 5616
# coding:utf-8

N, A, B = map(int, input().split(' '))

if A == 0:
    print(0)
else:
    if N <= A:
        print(N)
    else:
        ans, rem = divmod(N, A+B)
        ans *= A
        if rem >= A:
            ans += A
        else:
            ans += rem
        print(ans)


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair

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<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


int main() {
    i64 N, M; cin >> N >> M;
    if (N > M) swap(N, M);

    if (N == 1 && M == 1) cout << 1 << endl;
    else if (N == 1) cout << M - 2 << endl;
    else if (N == 2) cout << 0 << endl;
    else cout << (N - 2) * (M - 2) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
        return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

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

        for (char c : s) {
                cout << "x";
        }
        cout << endl;

        return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define LB(c, x) lower_bound(c.begin(), c.end(), x)
#define UB(c, x) upper_bound(c.begin(), c.end(), x)
#define LI(c, x) distance(c.begin(), LB(c, x))
#define UI(c, x) distance(c.begin(), UB(c, x))

// functions
template <class T> T ceil(T a, T b) {
    return (a + b - 1) / b;
}
template <class T> T round(T a, T b) {
    return (a + b / 2) / b;
}
template <class T> T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}
template <class T> T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}
template <class T> bool amax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M, s[10][10], p[10];
    cin >> N >> M;
    vector<vector<bool>> X(M, vector<bool>(N, false));
    REP(i, M) {
        int k;
        cin >> k;
        REP(j, k) {
            int s;
            cin >> s;
            X[i][s - 1] = true;
        }
    }
    REP(i, M) {
        cin >> p[i];
    }
    int res = 0;
    REP(i, 1 << N) {
        vector<int> cnt(M, 0);
        REP(j, 10) {
            if (((i >> j) & 1) == 0) {
                continue;
            }
            REP(k, M) {
                if (X[k][j]) {
                    cnt[k]++;
                }
            }
        }
        bool f = true;
        REP(k, M) {
            f &= cnt[k] % 2 == p[k];
        }
        if (f) {
            res++;
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
x=input().split()
x=[int(x[i]) for i in range(len(x))]
if x[0]+x[1]<=2*x[2]:
    print(x[0]*x[3]+x[1]*x[4])
else:
    if x[3]>x[4]:
        ans=x[4]*2*x[2]+(x[3]-x[4])*x[0]
        ans=min(ans,x[3]*2*x[2])
    else:
        ans=x[3]*2*x[2]+(x[4]-x[3])*x[1]
        ans=min(ans,x[4]*2*x[2])
    print(ans)

Measured memory_bytes: 9052
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

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

  int N;
  while(cin >> N, N){
	vector< pair<double,string> > k;
	REP(i,N){
	  string L; int P, A, B, C, D, E, F, S, M;
	  cin >> L >> P >> A >> B >> C >> D >> E >> F >> S >> M;
	  int tot = A + B + C + D + E + (M - 1)*(D + E);
	  int pr = F * S * M - P;
	  k.PB(MP(pr*1.0/tot, L));
	}
	sort(ALL(k), [](const pair<double,string>& p1, const pair<double,string>& p2)->bool{
		return p1.first > p2.first || (abs(p1.first-p2.first) < EPS
									   && p1.second < p2.second);
	  });
	REP(i,N)
	  cout << k[i].second << endl;
	cout << "#" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1224
/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/
#include <iostream>
using namespace std;

int main()
{
    long n,k,sum=0;
    cin>>n;
    cin>>k;
    long a[n],i;
    for(i=0;i<n;i++)
      cin>>a[i];
      int p = sizeof(a)/sizeof(a[0]);
    sort(a, a+p);
    for(i=0;i<n-k;i++)
    sum=sum+a[i];
    cout<<sum;
    
}


Measured memory_bytes: 2168
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <string>

using namespace std;
#define loop(i,n) for(int i = 0; i < (n); i++)
#define loops(i,f,n) for(int i = (f); i < (n); i++)
#define VEC vector<int>
#define INF 9999999999
#define inta long long
typedef pair<int, int>pii;
typedef pair<int, bool>pib;
// vector<VEC> v (n, VEC(n))
//loop(i,n)loop(j,n)dp[i][j]=-1;
//printf("%d\n", n);
int main()
{
	cin.tie(0);
	cin.sync_with_stdio(0);
	long long int n, m;
	cin >> n >> m;
	int d[1005];
	loops(i, 1, n + 1)cin >> d[i];
	int w[1505];
	loops(i, 1, m+1)cin >> w[i];
	int dp[1005][1005];
	loop(i, 1005)loop(j, 1005)dp[i][j] = INF;
	dp[0][0] = 0;
	loops(i, 1, m + 1)
	{
		loop(j, n + 1)
		{
			if (j - 1 < 0)dp[i][j] = dp[i - 1][j];
			else dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - 1] + d[j] * w[i]);
		}
	}
	long long int ans = INF;
	loop(i, m + 1)
	{
		if (ans < dp[i][n])continue;
		else ans = dp[i][n];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 7124
#include <iostream>
#include <vector>
#include <cmath>
#include <typeinfo>
#include <set>
#include <bitset>
#include <string>
#include <map>
#include <algorithm>
using namespace std;
typedef long long ll;



int main(){
  int h, a;
  cin >> h >> a;
  if(500*h>=a){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define re return
#define ll long long
#define ld long double
#define f first
#define s second
#define pi acos(-1)
#define oo (int)1e9
#define OO (ll)1e18
#define EPS 1e-7
#define FX(n) fixed<<setprecision(n)
#define mm(o,k) memset(o,k,sizeof o)
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int maxn=105;
int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};
int n,m;
char a[maxn][maxn];
map<pair<int,int>,pair<int,int> >p;
map<pair<int,int>,bool >vis;
bool valid(int i,int j){
    re(i>=0&&i<n&&j>=0&&j<m&&a[i][j]=='.');
}
int bfs(){
    int ans=0;
    queue<pair<int,int> >q;
    q.push({0,0});
    p[{0,0}]={-1,-1};
    bool done=false;
    while(q.size()){
        int x=q.front().f;
        int y=q.front().s;
        q.pop();
        if(x==n-1&&y==m-1){done=true;break;}
        for(int i=0;i<4;++i){
            int xx=x+dx[i],yy=y+dy[i];
            if(vis[{xx,yy}]||!valid(xx,yy))continue;
            vis[{xx,yy}]=true;
            p[{xx,yy}]={x,y};
            q.push({xx,yy});
        }
    }
    if(!done)re -1;
    pair<int,int> temp={n-1,m-1},hna={0,0};
    while(true){
        a[temp.f][temp.s]='#';
        if(temp==hna)break;
        temp=p[temp];
    }
    for(int i=0;i<n;++i)
        for(int j=0;j<m;++j)
            ans+=a[i][j]=='.';
    re ans;
}
int main()
{
    IO;
    cin >> n >> m;
    for(int i=0;i<n;++i)
        for(int j=0;j<m;++j)
            cin >> a[i][j];
    cout<<bfs()<<endl;
    re 0;
}

Measured memory_bytes: 640
N = int(input())
list_x = []
list_u = []
for i in range(N) :
    x, u = input().split()
    list_x.append(x)
    list_u.append(u)

ans = 0
for i in range(N) :
    if list_u[i] == "JPY" :
        ans += int(list_x[i])
    else :
        ans += float(list_x[i]) * 380000.0

print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <algorithm> 
#include <cstring>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
using namespace std;
#define int long long
#define N 666666

signed main(){
	int n,m;cin>>n>>m;if(n>m) cout<<"safe";else cout<<"unsafe"; 
	
	return 0;
}

Measured memory_bytes: 3632
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] count = new int[n+1];
        long ans = 1;
        for(int i=2; i<=n; i++) {
            int x = i;
            for(int j=2; j<=i; j++) {
                if(x == 1) break;
                while(true) {
                    if(x % j == 0) {
                        x /= j;
                        count[j]++;
                    }else {
                        break;
                    }
                }
            }
            if(i == x) count[i]++;
            
        }
        
        
        for(int i=2; i<n+1; i++) {
            if(count[i] > 0) {
                ans *= (count[i]+1);
                ans = ans % 1000000007;
            }
        }
        System.out.println(ans);
        
    }   
}

Measured memory_bytes: 24020
import copy

n = int(input())
T=list(map(int,input().split()))
m = int(input())
ans = []

for i in range(m):
    S = copy.copy(T)
    a,b = map(int, input().split())
    S[a-1] = b
    ans.append(sum(S))

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

Measured memory_bytes: 3444
/*jai_ganeshdeva*/

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pu push  //  adds the value to the last of the queue 
#define lld long long int
#define ins insert /// used in set to insert the values 
#define adv advance  /// used to increment the iterator
#define mp make_pair
#define fi first
#define se second
#define all(c) c.begin(),c.end()
#define PI 3.1415926
#define INF (lld)1e18
#define vl  vector<long long int >
#define vpl vector< pair<lld ,lld> >
#define vvl vector<vector<lld> > 
#define pll pair <lld,lld>
#define modA(cccc,bbbb ,p) (((cccc+bbbb)%p+p)%p)
#define modS(cccc,bbbb ,p) (((cccc-bbbb)%p+p)%p)
#define modM(cccc,bbbb ,p) ((((cccc%p)*(bbbb%p))%p+p)%p)

long long int modp(lld a,lld p,lld n)
{
    lld d[100];
    lld i,j,k,l;
    if(n==0) return 1;
    for(i=0;n>=1;i++)
    {
        d[i]=n%2;
        n/=2;
    }
    l=i;
    long long int e=1;
    if(d[0]==1) e*=(a%p);
    for(i=1;i<l;i++)
    {
        a*=a;
        a=a%p;
        if(d[i]==1) 
        {
            e*=a;
            e=e%p;
        }
    }
    return e%p;
}
lld modInverse(lld n, lld p) 
{ 
    return modp(n, p, p-2); 
}

lld fac[200001]; 

void getfac(lld p)
{
    fac[0] = 1; 
    for (lld i=1 ; i<=200000; i++) 
        fac[i] = fac[i-1]*i%p; 
}    

long long int nCrmodp(lld n, lld r,lld p) 
{ 
   // Base case 
   if (r==0) 
      return 1; 
     
    return (fac[n]* modInverse(fac[r], p) % p * 
            modInverse(fac[n-r], p) % p) % p; 
}


long long int gcd(lld b,lld a)
{
    if(a<b) return gcd(a,b);
    if(a%b==0) return b;
    return gcd(a%b , b);
}

//vector< vector <lld > > v(100001);
lld p1=1000000007,p2=998244353;
lld l,r,mid,ans;
lld n,m,i,j,k;
lld x,y,n1,a,b,n2,h,z,c;
queue<lld> q;
lld d,p=1000000000;

void solve()
{
    cin>>n>>m>>k;
    ans=0;
    x=m;
    for(i=1;i<n-k;i++)
    {
        x=modM(x,m-1,p2);
    }    
    ans=0;
    for(i=k;i>=0;i--)
    {
        ans+=((x)*(nCrmodp(n-1,i,p2)))%p2;
        x = modM(x,m-1,p2);
        ans = ans%p2;
    }
    cout<<ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lld t=1;
    
    //cin>>t;
    //cout<<t;
    getfac(p2);
    for(int i=0;i<t;i++)
    {
   //     cout<<"Case #"<<i+1<<": ";
            solve();
        cout<<"\n";
    }

    return 0;
}

Measured memory_bytes: 5216
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i==n-1];};
typedef struct {
    ll lv;
    ll rv;
} Q;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    scanf("%lld", &N);
    ll P[100010] = {};
    rep(i,0,N) scanf("%lld", &P[i]);
    vector<Q> arr(100010);
    arr[0] = (Q){-1, 1};
    arr[1] = (Q){0, 2};
    ll pos[100010] = {};
    rep(i,0,N){
        arr[i+2] = (Q){i+1, i+3};
        pos[P[i]] = i+2;
    }
    arr[N+2] = (Q){N+1, N+3};
    arr[N+3] = (Q){N+2, N+4};

    ll ans = 0;
    rep(n,1,N){
        ll p = pos[n];
        ll lv = arr[p].lv;
        ll rv = arr[p].rv;
        if(lv != 1){
            ans += n * (lv - arr[lv].lv) * (rv - p);
        }
        if(rv != N+2){
            ans += n * (arr[rv].rv - rv) * (p - lv);
        }

        arr[lv].rv = arr[p].rv;
        arr[rv].lv = arr[p].lv;
    }
    print(ans);



    
}

Measured memory_bytes: 3456
from math import sqrt

n,d = map(int, input().split())
points = []
for i in range(n):
    points.append(list(map(int, input().split())))

count = 0

for j in range(1, n):
    for i in range(j):
        ds = 0
        for k in range(d):
            ds += (points[i][k] - points[j][k])**2
        if sqrt(ds) == int(sqrt(ds)):
            count += 1

print(count)


Measured memory_bytes: 38480
//
// Created by Rea1 on 2020/2/22.
//
#pragma comment(linker, "/STACK:1024000000,1024000000")

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1

int main() {
    int n,k;
    cin >> n >> k;
    int cnt = 0;
    while (n) {
        cnt++;
        n /= k;
    }
    cout<<cnt;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
using namespace std;

void solve(){
  int n, x; cin >> n >> x;
  vector<int> m(n);
  int sum = 0, minm = 1000;
  for(int i = 0; i < n; i++){
    cin >> m[i];
    sum += m[i];
    minm = min(m[i], minm);
  }
  int y = x - sum;
  cout << n + y / minm << endl;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

//typedef pair<int,int> P;



int main(){
	long long a,b;
	int k;
	scanf("%lld %lld %d", &a,&b,&k);

	if(2*k-1>=b-a){
		for(long long i=a;i<=b;i++){
			printf("%lld\n", i);
		}
	}else{
		for(long long i=a;i<a+k;i++){
			printf("%lld\n", i);
		}
		for(long long i=b-k+1;i<=b;i++){
			printf("%lld\n", i);
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;
typedef long long ll;

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

    bool rev = 0;
    int opt;
    int f;
    char c;

    vector<char> res;
    REP(i, s.length()) res.push_back(s.at(i));

    REP(i, q){
        cin >> opt;
        if (opt == 1){
            rev = !rev;
        }
        else{
            cin >> f >> c;
            if ((f == 1 && !rev) || (f == 2 && rev)){
                res.insert(res.begin(), c);
            }
            else{
                res.push_back(c);
            }
        }
    }
    if (rev){
        REPR(i, res.size()-1) cout << res[i];
    }
    else{
        REP(i, res.size()) cout << res[i];
    }
    cout << endl;
}

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

#define se second
#define fi first
#define mk(a,b) make_pair(a,b)

typedef long long ll;
typedef pair<int,ll> pil;
typedef pair<int,int> pii;
typedef pair<ll,pii> lii;

int N,M;
ll X;
ll mod = 1000000007;
vector<pil> G[1010],T[1010];
bool vis[1010];
int par[1010];
bool use[2010];
vector<lii> edge;
ll cost = 0;
int A,B,C;
ll F[3010] = {1};

void init()
{
    for(int i = 0; i < 1010; i++)par[i] = i;
    return;
}

int root(int x)
{
    if(par[x] == x)return x;
    return par[x] = root(par[x]);
}

void unite(int x,int y)
{
    x = root(x);
    y = root(y);
    if(x == y)return;
    par[x] = y;
    return;
}

bool same(int x,int y)
{
    return root(x) == root(y);
}

ll get_max(int v,int t,int p)
{
    for(int i = 0; i < T[v].size(); i++)
    {
        pil now = T[v][i];
        if(now.fi == p)continue;
        if(now.fi == t)return now.se;
        ll res = get_max(now.fi,t,v);
        if(res != -1)return max(res,now.se);
    }
    return -1;
}

int main()
{
    scanf("%d%d",&N,&M);
    scanf("%lld",&X);
    for(int i = 0; i < M; i++)
    {
        int a,b;
        ll c;
        scanf("%d%d%lld",&a,&b,&c);
        G[a].push_back(mk(b,c));
        G[b].push_back(mk(a,c));
        edge.push_back(mk(c,mk(a,b)));
    }

    for(int i = 1; i < 3000; i++)F[i] = F[i - 1] * 2LL % mod;

    sort(edge.begin(),edge.end());

    init();
    for(int i = 0; i < edge.size(); i++)
    {
        lii now = edge[i];
        if(!same(now.se.fi,now.se.se))
        {
            T[now.se.fi].push_back(mk(now.se.se,now.fi));
            T[now.se.se].push_back(mk(now.se.fi,now.fi));
            unite(now.se.fi,now.se.se);
            use[i] = true;
            cost += now.fi;
        }
    }

    for(int i = 0; i < edge.size(); i++)
    {
        if(!use[i])
        {
            lii now = edge[i];
            ll res = get_max(now.se.fi,now.se.se,0);
            if(res == now.fi)A++;
            else if(now.fi - res == X - cost)B++;
            else if(now.fi - res < X - cost)C++;
        }
    }

    ll ans = 1;
    if(X < cost)
    {
        printf("0\n");
        return 0;
    }
    if(cost == X)
    {
        printf("%lld\n",(F[N - 1 + A] - 2) * F[M - (N - 1 + A)] % mod);
        return 0;
    }
    if(cost < X)
    {
        printf("%lld\n",(2LL * F[B] - 2) * F[M - (N - 1) - B - A - C] % mod);
        return 0;
    }
}


Measured memory_bytes: 640
import math
N=int(input())
ans=(N*(N+1))/2
ans=ans-3*math.floor(N/3)*(math.floor(N/3)+1)/2
ans=ans-5*math.floor(N/5)*(math.floor(N/5)+1)/2
ans=ans+15*math.floor(N/15)*(math.floor(N/15)+1)/2
print(int(ans))

Measured memory_bytes: 9216