akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <array>
#include <tuple>
#include <random>

using namespace std;
typedef long long int ll;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()

#define INF 10000000000

ll a, b, c, n, m, x, y, z, w, h, ans = 0, cnt = 0, mx = 0, mn = INF;
string s;

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

    cin >> n >> x;
    rep(i, n){
        cin >> m;
        mn = min(mn, m);
        x -= m;
    }
    cout << n + x / mn << endl;
}



Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int x = Integer.parseInt(sc.next());
        int y = Integer.parseInt(sc.next());
        sc.close();

        // 主処理
        long num = x * 2;
        long result = -1;
        if (x % y != 0) {
            while (num % y == 0) {
                num += x;
            }
            result = num;
        }

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 22868
def get_int(): return int(input())
def get_float(): return float(input())
def get_line(): return input().split()
def get_lines(v): return [get_line() for _ in range(v)]
def get_int_line(): return list(map(int, get_line()))
def get_int_lines(v): return [get_int_line() for _ in range(v)]
def get_float_line(): return list(map(float, get_line()))
def get_float_lines(v): return [get_float_line() for _ in range(v)]

N, M = get_int_line()
K = get_int_lines(N)

for i in range(N):
  K[i].remove(K[i][0])

ans = 0
for i in range(M):
  f = True
  for j in range(N):
    ff = len([v for v in K[j] if v == i + 1]) > 0
    if (not ff):
      f = False
  if (f): ans += 1

print(ans)

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class Main {

    private static Scanner sc;

    public static void main(String[] args) {
        Main instance = new Main();
        sc = instance.new Scanner();
        instance.solve();
    }

    private void solve() {
        try {
            System.out.println();
            char[] input = sc.next().toCharArray();
            Arrays.sort(input);
            String sorted = new String(input);;
            if(sorted.equals("abc")) {
                System.out.println("Yes");
            } else {
                System.out.println("No");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private class Scanner {
        String[] s;
        int i;
        BufferedReader br;
        String regex = " ";

        public Scanner() {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        @Override
        protected void finalize() throws Throwable {
            try {
                super.finalize();
            } finally {
                destruction();
            }
        }

        private void destruction() throws IOException {
            if (br != null) br.close();
        }

        public String next() throws IOException {
            if (i < s.length) return s[i++];
            String st = br.readLine();
            while (st == "") st = br.readLine();
            s = st.split(regex, 0);
            i = 0;
            return s[i++];
        }

        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }

        public Long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }

        public Double nextDouble() throws NumberFormatException, IOException {
            return Double.parseDouble(next());
        }
    }
}


Measured memory_bytes: 21332
#include "bits/stdc++.h"
using namespace std;
#define pb          push_back
#define mp          make_pair
#define ll          long long
#define pii         pair<ll, ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<ll, ll>
#define mii         map<pii, ll>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rev(i,a,b)  for(int i=a;i>=b;i--)
#define lb          lower_bound
#define ub          upper_bound

#define bg(i)       i.begin()
#define fset(it,s)   for(auto it = s.begin(); it != s.end(); it++)
 
#define track(x)                 cerr<<#x<<": "<<x<<endl
#define track2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define track3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define track4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
 
#define ed(i)       i.end()
#define mem(a)	    memset(a, 0, sizeof(a))

#define MOD         1000000007
ll mult(ll a,ll b, ll p=MOD){return ((a%p)*(b%p))%p;}
ll add(ll a, ll b, ll p=MOD){return (a + b + p)%p;}
ll fpow(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1LL) {if (k & 1LL) r = mult(r,n,p); n = mult(n,n,p);} return r;}
ll inv(ll a, ll p = MOD) {return fpow(a, p - 2, p);}
void self_max(int &a, int b) {a = max(a, b); }
void self_min(int &a, int b) {a = min(a, b); }
void self_add(int &a, int b, int p = MOD) { a += b; if(a >= p) a -= p;}
void self_sub(int &a, int b, int p = MOD) { a -= b; if(a < 0) a += p;}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
const int INF = 1e9 + 5;
#define N	    	400001

void solve(){
    ll n, m;
    cin>>n>>m;
    vector<pair<ll, ll> > v;
    rep(i, 0, n) {
        int a, b;
        cin>>a>>b;
        v.pb(mp(a, b));
    }
    sort(all(v));
    ll amount = 0;
    rep(i, 0, n) {
        ll curr = min((ll)v[i].y, (ll)m);
        amount += v[i].x * curr;
        m = m - curr;
    }
    cout<<amount<<endl;
}
int main() {
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(20);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
//	cin>>t;
	while(t--){
		solve();
	}
}

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

int  main()
{
	string s1,s2,s3,v="";
	
	cin>>s1;
	cin>>s2;
	cin>>s3;
	
	v+=s1[0];
	v+=s2[1];
	v+=s3[2];
	
	cout<<v<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
 
int main(){
  int a,b,c,d;
  scanf("%d%d%d%d",&a,&b,&c,&d);
  while(a>0&&c>0){
    c=c-b;
    a=a-d;
  }
  if(c<=0) printf("Yes");
  else printf("No");
  return 0;
}

Measured memory_bytes: 1732
<?php
$buttonSize=trim(fgets(STDIN));
$buttonSize=explode(" ",$buttonSize);
$coin=0;
for($i=0;$i<2;$i++){
	if($buttonSize[0]>=$buttonSize[1]){
  		$coin+=$buttonSize[0];
		$buttonSize[0]-=1;
	}elseif($buttonSize[0]<$buttonSize[1]){
  		$coin+=$buttonSize[1];
		$buttonSize[1]-=1;
	}
}
echo $coin;

Measured memory_bytes: 3576
// Ryo Kamoi

#include<iostream>
#include<math.h>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>

using namespace std;

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

typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;

int INF = 1000000000;

int s;

bool yymm(int fst, int snd) {
  if (snd <= 0 || snd > 12) {
    return false;
  }
  return true;
}

bool mmyy(int fst, int snd) {
  if (fst == 0 || fst > 12) {
    return false;
  }
  return true;
}

int main(){
  cin >> s;
  int fst = s / 100;
  int snd = s % 100;

  bool ym = yymm(fst, snd);
  bool my = mmyy(fst, snd);

  if (ym && my) {
    cout << "AMBIGUOUS" << endl;
  } else if (ym) {
    cout << "YYMM" << endl;
  } else if (my) {
    cout << "MMYY" << endl;
  } else {
    cout << "NA" << endl;
  }
}


Measured memory_bytes: 256
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <iomanip>
#include <iostream>
#include <limits>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = int64_t;
using ull = uint64_t;

template<typename T>
vector<T> make_vec_nd(T init, size_t size) {
    return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, size_t size, Args... rest) {
    auto inner = make_vec_nd(init, rest...);
    return vector<decltype(inner)>(size, inner);
}

struct Node {
    ll parent;
    vector<ll> child;
};

vector<Node> tree;

ll dfs(ll cur) {
    vector<ll> depths;
    for (ll ch : tree[cur].child) {
        ll depth = dfs(ch);
        depths.push_back(depth);
    }
    sort(depths.rbegin(), depths.rend());
    ll mn = 0;
    for (ll i = 0; i < depths.size(); i++) {
        mn = max(mn, i + 1 + depths[i]);
    }
//    cout << "cur: " << cur << ", mn: " << mn << endl;
    return mn;
}

int main() {
    ll N;
    cin >> N;
    tree = vector<Node>(N);
    tree[0].parent = -1;
    for (ll i = 1; i < N; i++) {
        ll ai;
        cin >> ai;
        ai--;
        tree[i].parent = ai;
        tree[ai].child.push_back(i);
    }
    cout << dfs(0) << endl;
}



Measured memory_bytes: 17408
# coding: utf-8

N = int(input())
X = list(map(int, input().split()))

candidates = [sum(X) // N, sum(X) // N + 1]

ans = 0

a = 0
b = 0
for x in X:
    a += (x-candidates[0])**2
    b += (x-candidates[1])**2

if a < b:
    print(a)
else:
    print(b)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
 
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;

void fin(){
	freopen("test.txt", "r", stdin);
}

int check(int m, int M){
	if(M<m)M+=60;
	return M-m<=8;
}

int getper(vector<int> v){
	int cnt = 0;
	rep(i, v.size()){
		cnt += v[i];
	}
	return cnt*100/v.size();
}

int main(){
	int n;
	while(cin >> n, n){
		vector<int> guest[3];
		rep(i, n){
			int h, m, m2;
			char c;
			cin >> h >> c >> m >> m2;
			if(h >= 11 && h < 15)guest[0].push_back(check(m,m2));
			else if(h >= 18 && h < 21) guest[1].push_back(check(m,m2));
			else if(h < 2 || (h >= 21 && h <= 24))guest[2].push_back(check(m,m2));
		}
		int cnt = 0;
		string str[3] = {"lunch", "dinner", "midnight"};
		rep(i, 3){
			cout << str[i] << ' ';
			if(guest[i].size() == 0) cout << "no guest" << endl;
			else cout << getper(guest[i]) << endl;
		}
	}

	return 0;
}

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

int main(void) {
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    while (a >= b) {
        b *= 2;
        if (--k < 0) {
            cout << "No" << endl;
            return 0;
        }
    }
    while (b >= c) {
        c *= 2;
        if (--k < 0) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


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

using namespace std;

const int N = 51;
int a[N];
int cnt;

int main(){
    int n; cin>>n;
    for(int i = 1; i <= n; i++){
        cin>>a[i];
        if(a[i] != i) cnt++;
    } 
    
    if(cnt <= 2) cout<<"YES\n";
    else cout<<"NO\n";
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
    int main() {
        int x, y, z, swap;
        scanf("%d %d %d", &x, &y, &z);
        
        swap = x;
        x = y;
        y = swap;
        
        swap = x;
        x = z;
        z = swap;
        
        printf("%d %d %d\n", x, y, z);
        return 0;
    }

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

int main(){
  int N, n, f;
  f = 0;
  cin >> N;
  n = N;
  while (n > 0) {
    f += n%10;
    n /= 10;
  }
  if (N%f == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int P = sc.nextInt();
		V[] vs = new V[N];
		for (int i = 0; i < N; i++)
			vs[i] = new V(i);
		for (int i = 0; i < M; i++) {
			int a = sc.nextInt() - 1;
			int b = sc.nextInt() - 1;
			int c = P - sc.nextInt();
			vs[a].add(new int[] {b, c});
		}
		int[] reachable = new int[N];
		reachable[0] = 1;
		reachable[N-1] = 2;
		for (int i = 0; i < N; i++) {
			for (V v: vs) {
				for (int[] e: v) {
					if (reachable[v.id] % 2 == 1)
						reachable[e[0]] |= 1;
					if (reachable[e[0]] / 2 == 1)
						reachable[v.id] |= 2;
				}
			}
		}
		int[] d = new int[N];
		Arrays.fill(d, 1 << 25);
		d[0] = 0;
		for (int k = 0; k < N; k++) {
			for (V v: vs) {
				if (reachable[v.id] % 2 == 0) continue;
				for (int[] e: v) {
					if (reachable[e[0]] / 2 == 1 && d[e[0]] > d[v.id] + e[1]) {
						d[e[0]] = d[v.id] + e[1];
						if (k == N - 1) {
							System.out.println(-1);
							return;
						}
					}
				}
			}
		}
		System.out.println(d[N-1] == 1 << 25 ? -1 : Math.max(0, -d[N-1]));
	}
	static class V extends ArrayList<int[]> {
		int id;
		V(int _id) {id = _id;}
	}
}

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

int main() {
  int N;
  string S, n = "Three";
  cin >> N;
  for (int i = 0; i < N; i++){
    cin >> S;
    if (S == "Y"){
      n = "Four";
    }
  }
  cout << n <<endl;
}

Measured memory_bytes: 3636
import java.util.Scanner;

public class Main{
	public static int profit(int[] prices){
		int[] sell = new int[prices.length];
		int min = prices[0]; 
		sell[0] = 0 - prices[0];
		for(int i = 1; i < prices.length; i++)
		{
			if(sell[i-1] < prices[i]-min)
			{
				sell[i] = prices[i] - min;
			}else
			{
				sell[i] = sell[i-1];
			}
			if(min > prices[i])
			{
				min = prices[i];
			}
		}
		return sell[prices.length - 1];
	}
	
	public static void main(String[] args)
	{
		Scanner in = new Scanner(System.in);
		int length = in.nextInt();
		
		int[] prices = new int[length];
		for(int i = 0; i < length; i++)
		{
			//System.out.print(i);
			prices[i] = in.nextInt();
		}
		
		System.out.println(profit(prices));
	}
}



Measured memory_bytes: 101928
#include <stdio.h>
#define min(a, b) ((a)>(b) ? (b) : (a))

int n, m, s[6], c[6];
int ans = 10000;

void dfs(int array[]){
  if(array[0] == n){
    int num = 0;
    int flag = 1;
    for(int i=1; i<=n; i++){
      num = num * 10 + array[i];
      for(int j=0; j<m; j++)
	if(s[j] == i)
	  if(array[i] != c[j]){
	    flag = 0;
	    break;
	  }
    }
    if(flag)  ans = min(ans, num);
    return;
  }

  int start = (array[0]==0 ? n==1 ? 0 : 1 : 0);
  for(int i=start; i<=9; i++){
    array[++array[0]] = i;
    dfs(array);
    array[0]--;
  }
}

int main(){
  scanf("%d %d", &n, &m);
  for(int i=0; i<m; i++)  scanf("%d %d", &s[i], &c[i]);
  int array[5] = {0};
  dfs(array);
  ans = ans==10000 ? -1 : ans;
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 128
import sys
input = sys.stdin.readline
N = int(input())
W = [input().strip() for i in range(N)]
s = set(W)
flag = False
if len(list(s)) != N:
    print("No")
else:
    for i in range(N-1):
        if W[i][-1] != W[i+1][0]:
            flag = True
            break
    if flag:
        print("No")
    else:
        print("Yes")

Measured memory_bytes: 38256
def is_valid(ws):
    n = len(ws)
    for i in range(1, n):
        if ws[i-1][-1] != ws[i][0]:
            return False
    return len(set(ws)) == n

def solve(ws):
    return "Yes" if is_valid(ws) else "No"

assert solve(["hoge","english","hoge","enigma"]) == "No"
assert solve(["basic","c","cpp","php","python","nadesico","ocaml","lua","assembly"]) == "Yes"
n = input()
ws = [raw_input() for i in range(n)]
print solve(ws)

Measured memory_bytes: 2692
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int  N;
  cin >> N;
  vector<int> v(N);
  for (int i=0;i<N;i++){
    cin >> v.at(i);
  } 
  vector<int> v1(N);
  vector<int> v2(N);
  int a;
  for (int j=0;j<N;j++){
    a=0;
    for (int i=0;i<N;i++){
      if (v.at(i) > a)
        a=v.at(i);
    }
    for (int i=0;i<N;i++){
      if (v.at(i) == a){
        v.at(i)=0;
        break;
      }
    }
    if (j%2==0)
      v1.at(j)=a;
    else
      v2.at(j)=a;
  }
  int sum1=0,sum2=0;
  for (int i=0;i<N;i++){
    sum1 += v1.at(i);
  }
  for (int i=0;i<N;i++){
    sum2 += v2.at(i);
  }
  cout << sum1-sum2 << endl;
}

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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var l = Console.ReadLine().Split().Select(long.Parse).ToArray();
            long N = l[0], A = l[1], B = l[2];

            if (A > B)
                Console.WriteLine(0);
            else if (N == 1)
            {
                if (A == B)
                    Console.WriteLine(1);
                else
                    Console.WriteLine(0);
            }
            else
                Console.WriteLine((B - A) * (N - 2) + 1);
        }
    }
}


Measured memory_bytes: 13396
import java.util.*;
class  Main
{
    public static void main (String[] args) 
    {
       Scanner sc =new Scanner(System.in); 
       System.out.println();
       int r=sc.nextInt();
       double c=0.0d;
       c=2*3.14*r;
       System.out.println(c);
       
    }
}

Measured memory_bytes: 35948
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define ss second
#define ff first
#define INF 300000000000001
#define ll_max 9000000000000000001
#define mod 998244353
#define PI 3.14159265358979323846L
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define db(args...) {string _ss = #args; replace(_ss.begin(), _ss.end(), ',' , ' '); stringstream ___s(_ss) ; debug(___s, args);}
using namespace std;
typedef vector<pair<ll,ll> > vll;
typedef vector<pair<int,int> > vii ;
typedef pair<ll,ll> pll;
const ll N = 300001;
const ll M = 1;
struct point {
    ll x, y;
    ll i;
};

void debug(stringstream &s){}
template <typename T, typename... Args>
void debug(stringstream &s, T a, Args... args)
{
    string word;
    s >> word;
    cout << word << " = " << a << endl;
    debug(s, args...);
}

ll fast_exp(ll x, ll n)
{
    if(n == 0) return 1;
    else if(n & 1)
        return fast_exp(x, n - 1) * x % mod;
    else
    {
        ll tmp = fast_exp(x, n >> 1);
        return tmp * tmp % mod;
    }
}

int main()
{
    fast;
    int _ = 1;
    //cin >> _;
    int test = 0;
    while(_--)
    {
        ll n, m, x = 0, y = 0, ans = 0, k;
        cin >> n >> k;
        ll a[n + 1] = {};
        y = 0;
        while(k--)
        {
            y++;
                   cin >> x;
            for(int i = 0; i < x; i++)
            {
                cin >> m;
                a[m]++;
            }
        }
        for(int i = 1; i <= n; i++) ans += !a[i];
        cout << ans << "\n";
    }
    return 0;
}


Measured memory_bytes: 3640
n, m, c = map(int, input().split())

ans = int(0)

b = [int(i) for i in input().split()]

for k in range(n):
	aaa = 0
	a = [int(i) for i in input().split()]

	for j in range(m):
		aaa += a[j]*b[j]
	if aaa + c > 0:
		ans +=1
print(ans)

Measured memory_bytes: 3060
import math

S = int(input())

ans = 0

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

for i in range(S//3):
    ans += combinations_count(S-(3*(i+1)) + i, i)
    ans %= 1000000007

print(ans)

Measured memory_bytes: 9192
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


char S[11],T[12];

int main(){

	scanf("%s",S);
	scanf("%s",T);

	bool FLG = true;
	for(int i = 0; S[i] != '\0'; i++){
		if(S[i] != T[i]){
			FLG = false;
			break;
		}
	}

	if(FLG){

		printf("Yes\n");

	}else{

		printf("No\n");
	}

	return 0;
}


Measured memory_bytes: 3668
word=input().lower()
sent=[]
while True:
	tmp=input()
	
	if ("END_OF_TEXT" in tmp) ==True:
		break
	tmp=tmp.split(' ')
	sent.append(tmp)
	

sent=sum(sent,[])
sent= list(map(lambda x:x.lower(),sent))
# print(sent)
c=sent.count(word)

print(c)


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const int INF=1001001001;

int H,W;
char fld[111][111];

int S[111][111];

int ey,ex;

int dp[2][111][111][111];

inline int f(int y,int x,int yy,int xx){
    return S[yy][xx]-S[y][xx]-S[yy][x]+S[y][x];
}

signed main(){
    cin>>H>>W;
    rep(i,H)cin>>fld[i];

    rep(i,H)rep(j,W)S[i+1][j+1]=(fld[i][j]=='o')+S[i][j+1]+S[i+1][j]-S[i][j];

    rep(i,H)rep(j,W)if(fld[i][j]=='E'){
        ey=i;ex=j;
    }

    fill_n(***dp,2*111*111*111,-INF);
    dp[0][0][0][0]=0;


    int ans=0;

    for(int i=0;i<=ey;i++){
        for(int j=0;j<=ex;j++){
            for(int ii=0;ii<H-ey;ii++){
                for(int jj=0;jj<W-ex;jj++){
                    chmax(ans,dp[i&1][j][ii][jj]);
                   // cout<<i<<" "<<j<<" "<<ii<<" "<<jj<<" "<<dp[i&1][j][ii][jj]<<endl;
                    int l,u,tmp;
                    if(i+1<=ey){
                        tmp=0;
                        l=ex-j;
                        u=ex+jj+1;
                        chmax(l,jj);
                        chmin(u,W-j);
                        if(ey-i-1>=ii&&l<u)tmp=f(ey-i-1,l,ey-i,u);
                        chmax(dp[(i+1)&1][j][ii][jj],tmp+dp[i&1][j][ii][jj]);
                    }

                    if(j+1<=ex){
                        tmp=0;
                        l=ey-i;
                        u=ey+ii+1;
                        chmax(l,ii);
                        chmin(u,H-i);
                        if(ex-j-1>=jj&&l<u)tmp=f(l,ex-j-1,u,ex-j);
                        chmax(dp[i&1][j+1][ii][jj],tmp+dp[i&1][j][ii][jj]);
                    }
                    if(ii+1<H-ey){
                        tmp=0;
                        l=ex-j;
                        u=ex+jj+1;
                        chmax(l,jj);
                        chmin(u,W-j);
                        if(ey+ii+1<H-i&&l<u)tmp=f(ey+ii+1,l,ey+ii+2,u);
                        chmax(dp[i&1][j][ii+1][jj],tmp+dp[i&1][j][ii][jj]);
                    }
                    if(jj+1<W-ex){
                        tmp=0;
                        l=ey-i;
                        u=ey+ii+1;
                        chmax(l,ii);
                        chmin(u,H-i);
                        if(ex+jj+1<W-j&&l<u)tmp=f(l,ex+jj+1,u,ex+jj+2);
                        chmax(dp[i&1][j][ii][jj+1],tmp+dp[i&1][j][ii][jj]);
                    }
                    dp[i&1][j][ii][jj]=-INF;
                }
            }
        }
    }

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


Measured memory_bytes: 21760
import numpy as np
def main():
    n = int(input())
    p = list(map(int, input().split()))
    c = 0
    mi = 2*10**5+1
    for i in range(n):
        if mi > p[i]:
            c += 1
            mi = p[i]
    
    print(c)

if __name__ == "__main__":
    main()

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

int main(void){
    string s;
    cin>>s;
    int n=s.size();
    rep(i, (n+1)/2-1){
        if(s[i]!=s[n-1-i]){
            cout<<"No"<<endl;
            return 0;
        }
    }
    rep(i, (n+1)/4){
        if(s[i]!=s[(n-3)/2-i] || s[(n+3)/2-1+i]!=s[n-1-i]) {
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, char const *argv[]) {

  int H, N;
  int A[100000];
  int sum = 0;
  scanf("%d %d", &H, &N);

  for (int i = 0; i < N; i++) {
    scanf("%d", (A + i));
    sum += A[i];
    if (sum >= H) {
      printf("Yes\n");
      return 0;
    }
  }

  printf("No\n");

  return 0;
}


Measured memory_bytes: 512
$h, $w = gets.split.map(&:to_i)
$s = []
$h.times do
  $s.push gets.chomp.split('')
end

def is_in_boundary?(i, j)
  if i >= 0 && j >= 0 && i < $h && j < $w
    true
  else
    false
  end
end

def is_alone?(i, j)
  [[0, -1], [0, 1], [-1, 0], [1, 0]].each do |xy|
    x = xy.first
    y = xy.last
    if is_in_boundary?(i + x, j + y)
      return false if $s[i+x][j+y] == '#'
    end
  end
  true
end

0.upto($h-1) do |i|
  0.upto($w-1) do |j|
    if $s[i][j] == '#' && is_alone?(i, j)
      puts 'No'
      exit
    end
  end
end
puts 'Yes'


Measured memory_bytes: 2172
# coding: utf-8

n = int(raw_input())
cards = []
for i in range(1, 2*n+1):
	cards.append(i)

m = int(raw_input())
for ope in range(m):
	new_cards = []
	k = int(raw_input())
	if k == 0:
		for i in range(n):
			new_cards.append(cards[i])
			new_cards.append(cards[n+i])
	else:
		for i in range(k,2*n):
			new_cards.append(cards[i])
		for i in range(k):
			new_cards.append(cards[i])
	cards = new_cards

for card in cards:
	print(card)

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

int main() {
  int h, w;
  cin >> h >> w;
  
  //表の取得
  vector<vector<char>> v(h, vector<char>(w));
  for(int i=0; i<h; i++) {
    string s;
    cin >> s;
    for(int j=0; j<w; j++) v[i][j] = s[j];
  }
  
  //012
  //3.4 空マス周囲座標
  //567
  vector<int> dx = {-1, 0, 1, -1, 1, -1, 0, 1}; //横
  vector<int> dy = {-1, -1, -1, 0, 0, 1, 1, 1}; //縦

  for(int i=0; i<h; i++) {
    for(int j=0; j<w; j++) {
      if(v[i][j] == '#') continue; //爆弾
      
      //空白マスの周囲を検証
      int a, b;
      int count = 0;
      for(int k=0; k<8; k++) {
        a = j+dx[k];
        b = i+dy[k]; 
        if(a<0 || w<=a) continue; //枠外
        if(b<0 || h<=b) continue; //枠外
        if(v[b][a] == '#') count++; //爆弾をカウント
      }
      v[i][j] = char(count+'0');//空マス'.'を数字に置換
    }
  }
  
  //出力
  for(int i=0; i<h; i++) {
    for(int j=0; j<w; j++) {
      cout << v[i][j];
      if(j==w-1) cout << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3648
/*input

*/


// assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;

// order_of_key (k) : Number of items strictly smaller than k .
// find_by_order(k) : K-th element in a set (counting from zero).
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define ll          long long int
#define pb          push_back
#define pii         pair<ll ,ll >
#define vpii        vector< pii >
#define vi          vector<ll >
#define vs			vector< string >
#define vvi         vector< vector< ll > >
#define inf			(ll)1e18
#define all(it,a)   for(auto it=(a).begin();it!=(a).end();it++) 
#define F           first
#define S           second
#define sz(x)       (ll )x.size()
#define rep(i,a,b)	for(ll  i=a;i<b;i++)
#define repr(i,a,b) for(ll  i=a;i>b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define whatis(x)   cout << #x << " is " << x << "\n";
#define graph(n)    adj(n,vector< ll > () )
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define debug(x)     cout << #x << " " << x << endl;
#define debug_p(x)   cout << #x << " " << x.F << " " << x.S << endl;
#define debug_v(x)   {cout << #x << " "; for (auto ioi : x) cout << ioi << " "; cout << endl;}
#define debug_vp(x)  {cout << #x << " "; for (auto ioi : x) cout << '[' << ioi.F << " " << ioi.S << ']'; cout << endl;}
#define debug_v_v(x) {cout << #x << "/*\n"; for (auto ioi : x) { for (auto ioi2 : ioi) cout << ioi2 << " "; cout << '\n';} cout << "*/" << #x << endl;}

int solve()
{
	ll h1,m1,h2,m2,k;
	cin>>h1>>m1>>h2>>m2>>k;

	ll st = h1*60 + m1;
	ll ed = h2*60 + m2;

	ll ans = ed-k-st;
	cout<<ans<<"\n";

	return 0;
}

int main()
{
	auto start = chrono::high_resolution_clock::now();

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	ll test_cases=1;
	//cin>>test_cases;
	while(test_cases--)
		solve();

	auto stop = chrono::high_resolution_clock::now();
	auto duration = chrono::duration_cast<chrono::milliseconds>(stop-start);
	//cout<<"\nduration: "<<(double)duration.count()<<" milliseconds";
}

Measured memory_bytes: 3612
n=int(input())
a,b=map(int,input().split())
p=list(map(int,input().split()))
d=[0]*3
for i in p:
    if i<=a:
        d[0]+=1
    elif a+1<=i<=b:
        d[1]+=1
    elif b+1<=i:
        d[2]+=1
print(min(d))


Measured memory_bytes: 3060
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define int         long long   
#define double      long double
#define endl        "\n"
#define pb          push_back
#define PI          3.1415926535897932384626433832795l
#define F           first
#define S           second
#define mp          make_pair
#define f(i,n)      for(int i=0;i<n;i++)
#define fastio      ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v)      (v).begin(),(v).end()
#define sort(v)     sort((v).begin(),(v).end())
#define rall(v)     (v).rbegin(),(v).rend()
#define rsort(v)     sort((v).rbegin(),(v).rend())
#define gcd(a,b)    __gcd((a),(b))
#define minn(v)     *min_element(v.begin(), v.end());
#define maxx(v)     *max_element(v.begin(), v.end());
#define print(x)    cout<<(x)<<endl;
typedef pair<int,int> pii;  
typedef vector<int> vi;

signed main() 
{
    fastio;
    int n,k;
    cin>>n>>k;
    int dig = (int)(floor( log(n) /  log(k)) + 1);
    cout<<dig<<endl;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;

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

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

ll x, y;

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

	cin >> x >> y;
	ll ans = inf;
	if (x <= y)
		ans = min(ans, y - x);
	if (-x <= y)
		ans = min(ans, y + x + 1);
	if (x <= -y)
		ans = min(ans, -y - x + 1);
	if (-x <= -y)
		ans = min(ans, x - y + 2);
	cout << ans << endl;
}



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

int main(void){
  string s;
  cin >> s;
  
  sort(s.begin(), s.end());
  
  if (s.at(0) == s.at(1) && s.at(2) == s.at(3) && s.at(0) != s.at(2)) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl; 
  }
  
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <queue>
#define ll long long
#define space putchar(' ')
#define endl putchar('\n')
#define debug puts("------------------------")
#define F(i,x,n) for(int i=x;i<=n;++i)
#define F_(i,x,n) for(int i=x;i>=n;--i)
using namespace std;
inline void read(int &a) {a=0;int c=getchar(),b=1; while(c>'9'||c<'0') {if(c=='-')b=-1;c=getchar();} while(c>='0'&&c<='9') a=(a<<3)+(a<<1)+c-48,c=getchar();a*=b; }
inline int  Rem() {int a=0,c=getchar(),b=1; while(c>'9'||c<'0') {if(c=='-')b=-1;c=getchar();} while(c>='0'&&c<='9') a=(a<<3)+(a<<1)+c-48,c=getchar();return a*=b; }
inline void write(int x) {if(x>9)write(x/10);putchar('0'+x%10);}
inline void W(int x) {if(x<0){putchar('-'),x=-x;}write(x);}
/**/
int a,b;
/**/
int main()
{
    // freopen("test.in","r",stdin);
    // freopen("test.out","w",stdout);
    read(a);read(b);
    cout<<max(0,a-2*b);
    return 0;  
}

Measured memory_bytes: 256
a,b,c,d = input().split()

a = int(a)
b = int(b)
c = int(c)
d = int(d)

if abs(c-a) <= d:
    print("Yes")
elif abs(c-a) > d and abs(b-a) <= d and abs(c-b) <= d:
    print("Yes")
else:
    print("No")



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

using namespace std;
using ll = int64_t;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using mii = map<int, int>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using tpi = tuple<int, int, int>;

using vqi = vector<queue<int>>;
using vpi = vector<pii>;
using bs = bitset<60>;
using vbi = vector<bs>;

ll gcd(ll a, ll b) {
    if (a < b) {
        swap(a, b);
    }

    /* ユークリッドの互除法 */
    ll r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

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

constexpr int64_t __pow_mod(int64_t n, int64_t p, int64_t mod) noexcept {
    if (p == 0) {
        return 1;
    }
    if (p % 2 == 0) {
        int64_t t = __pow_mod(n, p / 2, mod);
        return (t * t) % mod;
    }
    return (n * (__pow_mod(n, p - 1, mod) % mod)) % mod;
}

constexpr int64_t pow_mod(int64_t n, int64_t p, int64_t mod) noexcept {
    int64_t res = __pow_mod(n, p, mod);
    if (res == 0) {
        res = mod;
    }
    return res;
}

constexpr int64_t nCr_mod(int64_t n, int64_t r, int64_t mod) noexcept {
    int64_t count = 1;
    auto a = r;
    for (auto i = n; i > n - r; i--) {
        count *= i;
        if (count % mod != 0) {
            count %= mod;
        }
        int64_t inv = pow_mod(a, mod - 2, mod);
        count *= inv;
        if (count % mod != 0) {
            count %= mod;
        }
        a--;
    }
    return count;
}

void dfs(int d, int count, int max, string prev) {
    if (d == max) {
        for (int i = 0; i <= count; i++) {
            string new_s = prev + static_cast<char>('a' + i);
            cout << new_s << endl;
        }
        return;
    } else {
        for (int i = 0; i < count; i++) {
            string new_s = prev + static_cast<char>('a' + i);
            dfs(d + 1, count, max, new_s);
        }
        string new_s = prev + static_cast<char>('a' + count);
        dfs(d + 1, count + 1, max, new_s);
    }
}

void solve(long long N) {
    if (N == 1) {
        cout << "a" << endl;
        return;
    }
    dfs(1, 1, N - 1, "a");
}

int main() {
    long long N;
    std::cin >> N;
    solve(N);
    return 0;
}


Measured memory_bytes: 1536
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;

#define ll long long

int main(void){

    int w,a,b;
    cin>>w>>a>>b;

    int ans = max(b-(a+w),a-(b+w));
    cout<<max(ans,0)<<endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    sc.close();
    long res = 0;
    long min = 0;
    long max = 0;
    for (int i = 0; i < k - 1; i++) {
      min += i;
      max += n - i;
    }
    for (int i = k; i <= n + 1; i++) {
      min += i - 1;
      max += n - (i - 1);
      res += max - min + 1;
    }
    res %= Math.pow(10, 9) + 7;
    System.out.println(res);
  }
}

Measured memory_bytes: 27260
N, M = map(int, input().split())
a = list(map(int, input().split()))
cost = [-1, 2, 5, 5, 4, 5, 6, 3, 7, 6]

cost = [cost[A] for A in a]

dp = [-float('inf')] * (N + 1)
dp[0] = 0
for i in range(1, N + 1):
    for j in range(len(cost)):
        if cost[j] <= i:
            dp[i] = max(dp[i], dp[i - cost[j]] * 10 + a[j])

print(dp[N])


Measured memory_bytes: 14516
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	deque<double> arr;
	for(int i=0;i<n;i++)
	{
		int a;
		cin>>a;
		arr.push_back(a);
	}
	sort(arr.begin(),arr.end());
	double sum = 0;
	while(arr.size()>=1)
	{
		if(arr.size()==1){
			sum=arr[0];
			break;
		}
		double x = arr[0];
		double y = arr[1];
		arr.pop_front();
		arr.pop_front();
		double mid = (x+y)/2;
		arr.push_back(mid);
		sort(arr.begin(),arr.end());
	}
	cout<<sum<<endl;
	return 0;
}

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

int main ()
{
    int r;
    int m;
    int a;
    cin >> r>>m>>a;
    if (a<m&&a>r){
        cout << "Yes";
    }
else if (a==r&&a==m){
    cout << "Yes";
}
else cout << "No";

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)

int main() {
    int n;
    string s,ans="Yes";
	cin>>n>>s;
	if(n%2)ans="No";
	else{
	    int m=n/2;
	    rep(j,m){
	        if(s[j]!=s[j+m]){
	            ans="No";
	            break;
	        }
	    }
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define Inf 0x3f3f3f3f
#define rg register
using namespace std;
const int Maxn = 1e5 + 5;
typedef long long ll;
typedef ll arr[Maxn];
ll min(ll x, ll y) { return x < y ? x : y; }
ll max(ll x, ll y) { return x > y ? x : y; }
inline ll read()
{
	rg ll res = 0, sign = 1;
	rg char ch = getchar();
	while (!isdigit(ch))
	{
		if (ch == '-')
			sign = -1;
		ch = getchar();
	}
	do
	{
		res = (res << 3) + (res << 1) + (ch ^ 48);
		ch = getchar();
	} while (isdigit(ch));
	return res * sign;
}
int n;
ll dist;
arr siz, fa, dis;
struct str
{
	ll d;
	int id;
	bool operator<(str A) const { return d < A.d; }
} p[Maxn];
vector<int>to[Maxn];
void DFS(int x)
{
    dist+=dis[x];
    for(rg int i=0,nx;i<to[x].size();i++)
    {
        nx=to[x][i];
        dis[nx]=dis[x]+1;
        DFS(nx);
    }
}
void Solve(int x)
{
    for(rg int i=0,nx;i<to[x].size();i++)
    {
        nx=to[x][i];
        dis[nx]=dis[x]+n-2*siz[nx];
        Solve(nx);
    }
}
int main()
{
    ll tmp;
	int now, s;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		p[i] = {read(), i};
		siz[i] = 1;
	}
	sort(p + 1, p + n + 1);
	for (int i = n; i > 1; i--)
	{
		now = p[i].id;
		tmp = p[i].d - n + 2 * siz[now];
		fa[now] = p[s = lower_bound(p + 1, p + n + 1, (str){tmp, 0}) - p].id;
        to[fa[now]].push_back(now);
		if (p[s].d != tmp || s >= i)
		{
			puts("-1");
			return 0;
		}
		siz[fa[now]] += siz[now];
	}
    DFS(p[1].id);
    dis[p[1].id]=dist;
    Solve(p[1].id);
    for(int i=1;i<=n;i++)
        if(dis[p[i].id]!=p[i].d)
        {
            puts("-1");
            return 0;
        }
	for (int i = 1; i <= n; i++)
		if (fa[i])
			printf("%d %d\n", fa[i], i);
	return 0;
}


Measured memory_bytes: 13056
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <unordered_map>
#include <cstdlib>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    ll N, K, A[100001], i, ans, count;

    cin >> N >> K;

    for(i=1; i<=N; i++){
        cin >> A[i];
    }

    if(N == K){
        cout << 1 << endl;
    }

    else{
        ans = 1;
        count = K;

        while(count < N){
            count += (K-1);
            ans++;
        }

        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
typedef long long LL;

int main() {
	char c;

	std::cin >> c;

	if (c == 'A') {
		std::cout << 'T' << std::endl;
	}
	else if (c == 'T') {
		std::cout << 'A' << std::endl;
	}
	else if (c == 'G') {
		std::cout << 'C' << std::endl;
	}
	else {
		std::cout << 'G' << std::endl;
	}
}

Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    #from math import gcd

    #inf = 10**17
    mod = 10**9 + 7

    n = int(input())
    c = list(map(int, input().split()))
    c.sort()
    res = 0
    b = pow(2, n, mod)
    for i in range(n):
        l = pow(2, i, mod)
        if n-i-2 >= 0:
            r = pow(2, n-i-1, mod) + (n-i-1)*pow(2, n-i-2, mod)
        else:
            r = pow(2, n-i-1, mod)
        res += b*c[i]*l*r % mod
        res %= mod
    print(res)

if __name__ == '__main__':
    main()


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

namespace WelcomeAtcordet
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int N = int.Parse(input[0]);
            int K = int.Parse(input[1]);

            long ans = K;

            for(int i = 2; i <= N; i++)
            {
                ans *= (K - 1);
            }

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 11092
# -*- coding: utf-8 -*-
import numpy as np

N, K = map(int, input().split())

d = []
A = []
for i in range(K):
  dd = int(input())
  aa = list(map(int, input().split()))
  d.append(dd)
  A.append(aa)

z = np.ones(N)
for i in range(K):
  for j in range(d[i]):
    z[A[i][j]-1] = 0

print(int(z.sum()))


Measured memory_bytes: 27308
#include<iostream>
#define M 1000000007
using namespace std;
typedef unsigned long long ullong;

ullong power(ullong m, ullong n){
  ullong res = 1;
  if ( n > 0){
    res = power(m * m % M , n / 2);
    if ( n % 2 == 1) res = res * m % M;
  }
  return res;
}

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

  cout << power(m, n) << endl;

  return 0;
}


Measured memory_bytes: 3112
#!/usr/bin/env python3
import sys
INF = float("inf")


def yes():
    print("Yes")  # type: str


def no():
    print("No")  # type: str


def solve(S: str):
    if "L" in S[0::2]:
        no()
        return
    elif "R" in S[1::2]:
        no()
        return
    yes()
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)


if __name__ == '__main__':
    main()


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

/**
 * author @sahil
 */
public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String s[]=br.readLine().split(" ");
        int c=0;
        int a[]=new int[n+1];
        for(int i=0;i<n;++i)a[i]=Integer.parseInt(s[i]);
        for(int i=1;i<=n;++i) {
            if(a[i-1]==i){
                ++c;
                if(i-1<n)
                a[i]=a[i-1];
            }
        }
            System.out.println(c);


    }
}


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

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
//const ll INF = LONG_LONG_MAX;
const ll MINF = LONG_LONG_MIN;
const int INF = INT_MAX;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)

bool contain(set<char> &s, int a) { return s.find(a) != s.end(); }


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

typedef priority_queue<ll, vector<ll>, greater<ll>> PQ_ASK;
const int mod = 1000000007;

int main() {

    string s;
    cin >> s;
    vector<bool> dp(s.size() + 1, false);
    vector<string> word = {"dream", "dreamer", "erase", "eraser",};
    dp[0] = true;

    for (int i = 0; i < s.size(); i++) {
        if (!dp[i]) continue;
        for (string w : word) {
            string sub_str = s.substr(i, w.size());
            if (sub_str == w) {
                dp[i + w.size()] = true;
            }
        }
    }

    cout << (dp.back() ? "YES" : "NO") << endl;

}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
//#include <stdio.h>
//#include <stack>
//#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
//#include <iomanip>
#include <stdlib.h>
#include <cctype>

using namespace std;

#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define ssort(z) sort(z.begin(),z.end())
#define rsort(z) sort(z.rbegin(),z.rend())
#define eerase(z) z.erase(unique(z.begin(),z.end()),z.end())
#define ccnt(z,w) count(z.begin(),z.end(),w)


void printVec(std::vector<int> & vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec2(std::vector<Int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

Int gcd(Int a, Int b) {
	return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b) {
	return a / gcd(a, b) *b;
	//a*bは64bit integer overflow
}

bool comp(const string a, const string b) {
	return a.length() < b.length();
}

bool integer(double num) {
	return floor(num) == num;
}

string gen(int num) {
	string str = "";
	for (int i = 0; i < num; i++) str += ".";
	return str;
}
Int fact(int num) {
	if (num == 0) return 1;
	else return num * fact(num - 1);
}


int main() {
	int a, b, c,d; cin >> a>>b>>c>>d ;
	//string s,t; cin >> s>>t;
	cout << max(a * b, c * d);


	cout << endl;
	return 0;
}


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

using namespace std;

int main(){
    int n,ans=0;
    cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }

    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            ans += a[i]*a[j];
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 764
#include <stdio.h>

int n, c = 0;

void dfs(int x, int f3, int f5, int f7, int l)
{
	if(x > n) return;
	if(f3 && f5 && f7) c++;
	if(l == 9) return;
	
	int t = 10 * x, tl = l + 1;
	dfs(t + 3, 1, f5, f7, tl);
	dfs(t + 5, f3, 1, f7, tl);
	dfs(t + 7, f3, f5, 1, tl);
}

int main() 
{
			
	scanf("%d", &n);	
	dfs(0, 0, 0, 0, 0);
	printf("%d\n", c);
			
	return 0;
}

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

int main(){
    long long a,b,k;
    cin >>a>>b>>k;
    //とりあえず引けたら全部引く
    if(k - a >= 0){
        k -= a;
        a = 0;
    }

    //余ってたら引く
    if(k - a < 0){
        a -= k;
        k = 0;
    }

    if(k - b >= 0){
        k -= b;
        b = 0;
    }

    if(k - b < 0){
        b -= k;
        k = 0;
    }


    while(k>0){
        if(a > 0){
            a--;
            k--;
        }else if(b > 0 ){
            b--;
            k--;
        }else{
            break;
        }
    }
    cout << a <<" "<< b << endl;
}



Measured memory_bytes: 256
n,k = map(int,input().split())
h = list(map(int,input().split()))
dp = [0]*n
for i in range(1,n):
    a = [0]*k
    for j in range(1,k+1):
        if i-j < 0:
            a[j-1] = 10**10
        else:
            a[j-1] = dp[i-j] + abs(h[i]-h[i-j])
    dp[i] = min(a)
print(dp[-1])

Measured memory_bytes: 52448