akhauriyash/Code-Regression huggingface dataset:
import sys
def input():return sys.stdin.readline().strip()
from collections import defaultdict

def main():
    H, W, M = map(int,input().split())
    
    d_row = defaultdict(int)
    d_col = defaultdict(int)
    hw = []

    for _ in range(M):
        h, w = map(int, input().split())
        h -= 1
        w -= 1
        d_row[h] += 1
        d_col[w] += 1
        hw.append((h, w))


    max_row_val = max(d_row.values())
    max_col_val = max(d_col.values())

    max_rows = set(key for key, val in d_row.items() if val == max_row_val)
    max_cols = set(key for key, val in d_col.items() if val == max_col_val)
   
    if len(max_rows)*len(max_cols) == sum((h in max_rows and w in max_cols) for h, w in hw):
        ans = max_row_val + max_col_val - 1
    else:
        ans = max_row_val + max_col_val
    
    print(ans)
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 93396
#include <bits/stdc++.h>
using namespace std;
 
long long n, a, b, c, d;
string s;
 
bool solve();
 
int main() {
  cin >> n >> a >> b >> c >> d >> s;
  if(solve())
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}
 
bool solve() {
  --a, --b, --c, --d;
  bool ch = 0;
  for(int i = a + 1; i <= c; ++i)
    if(s[i] == s[i - 1] && s[i] == '#') return 0;
  for(int i = b + 1; i <= d; ++i)
    if(s[i] == s[i - 1] && s[i] == '#') return 0;
  if(c < d) return 1;
  for(int i = b; i <= d; ++i)
    if(i > 0 && i + 1 < n && s[i - 1] == s[i] &&
       s[i] == s[i + 1] && s[i] == '.')
      ch = 1;
  return ch;
}

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

int main(){
	int a,b;
	cin>>a>>b;
	int res=0;
	if(a>b){
		res+=a;
		a--;
	}else{
		res+=b;
		b--;
	}
	if(a>b){
			res+=a;
			a--;
		}else{
			res+=b;
			b--;
		}

	cout<<res<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl

using namespace std;

template<typename S,typename T>auto&operator<<(auto&o,pair<S,T>p){return o<<"{"<<p.fi<<","<<p.se<<"}";}
template<typename T>auto&operator<<(auto&o,set<T>s){for(auto&e:s)o<<e<<" ";return o;}
template<typename S,typename T,typename U>
auto&operator<<(auto&o,priority_queue<S,T,U>q){while(!q.empty())o<<q.top()<<" ",q.pop();return o;}
template<typename K,typename T>auto&operator<<(auto&o,map<K,T>&m){for(auto&e:m)o<<e<<" ";return o;}
template<typename T>auto&operator<<(auto&o,vector<T>v){for(auto&e:v)o<<e<<" ";return o;}
void ashow(){cout<<endl;}template<typename T,typename...A>void ashow(T t,A...a){cout<<t<<" ";ashow(a...);}
template<typename S,typename T,typename U>
struct TRI{S fi;T se;U th;TRI(){}TRI(S f,T s,U t):fi(f),se(s),th(t){}};
template<typename S,typename T,typename U>
auto& operator<<(auto& o,TRI<S,T,U>& t){return o<<"{"<<t.fi<<","<<t.se<<","<<t.th<<"}";}

typedef pair<int, int> P;
typedef pair<ll, ll> pll;
typedef TRI<int, int, int> tri;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<P> vp;
typedef vector<double> vd;
typedef vector<string> vs;

const int MAX_N = 100005;

int dp[MAX_N];
vector<int> G[MAX_N];

void dfs(int u, int p)
{
    int ch = 0, cri = 0;
    each(v, G[u]){
        if(v != p){
            ch++;
            dfs(v, u);
            if(dp[v]) dp[u] += dp[v], cri++;
        }
    }
    dp[u] += max(0, ch-1-cri);
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    rep(i,n-1){
        int a,b;
        cin >> a >> b;
        G[a].pb(b), G[b].pb(a);
    }
    rep(i,n){
        if(len(G[i]) > 2){
            dfs(i, -1);
            cout << dp[i] << "\n";
            return 0;
        }
    }
    cout << "1\n";
    return 0;
}


Measured memory_bytes: 10368
a, b = map(int, input().split())

if (a >= 1 and a <= 1000000000) and (b >= 1 and b <= 1000000000):
    d = int(a / b)
    r = int(a % b)
    f = float(a / b)

    print("{0:d} {1:d} {2:f}".format(d, r, f))
else:
    pass

Measured memory_bytes: 7684
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
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; }
#define fls(x) (64 - __builtin_clzll(x))
#define pcnt(x) __builtin_popcountll(x)
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    string s; cin >> s;
    int w = 0, ww = 0;
    rep (i, n) if (s[i] == 'W') w++;
    reprev (i, n - w, n) if (s[i] == 'W') ww++;
    cout << w - ww << "\n";
    return 0;
}

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

typedef long long ll;
#define MAX (1003)
#define MOD (1000000007LL)

int V;
vector<int> G[MAX];
vector<int> rG[MAX];
vector<int> nG[MAX];//?????£???????§£????????£???????????°????????°?????? 
vector<int> nrG[MAX];
vector<int> vs;
bool used[MAX];
int cmp[MAX]; //?±????????????£????????????????????????????????????
 
void add_edge(int from,int to){
  G[from].push_back(to);
  rG[to].push_back(from);
}
 
void dfs(int v){
  used[v] = true;
  for(int i = 0 ; i < G[v].size() ; i++){
    if(!used[G[v][i]]) dfs(G[v][i]);
  }
  vs.push_back(v);
}
 
void rdfs(int v,int k){
  used[v] = true;
  cmp[v] = k;
  for(int i = 0 ; i < rG[v].size() ; i++){
    if(!used[rG[v][i]]) rdfs(rG[v][i],k);
  }
}
 
int scc(){ //?????£?????????????§£????????????
  memset(used, 0, sizeof(used));
  vs.clear();
  for(int v = 0 ; v < V ; v++){
    if(!used[v]) dfs(v);
  }   
  memset(used, 0, sizeof(used));
  int k = 1;
  for(int i = vs.size() - 1 ; i >= 0 ; i--){
    if(!used[vs[i]]) rdfs(vs[i],k++);
  }

  for(int i=0;i<V;i++){
    int v = cmp[i];
    for(int j=0;j<(int)G[i].size();j++){
      int to = cmp[G[i][j]];
      if( to != v ) {
	nG[v].push_back(to);
	nrG[to].push_back(v);
      }
    }
  }
  return k;
}

void dfs2(int id,bool *flag){
  if( flag[id] ) return;
  flag[id] = true;
  for(int i=0;i<(int)nrG[id].size();i++)
    dfs2(nrG[id][i],flag);
}
		 

int M;
ll dp[MAX];

bool ch[MAX];


void view(int id,vector<int> Gs[50]){
  cout << "vertex : " << id << endl;
  for(int j=0;j<(int)Gs[id].size();j++)
    cout << " -> " << Gs[id][j] << endl;;
}

int main(){

  cin >> V >> M;
  for(int i=0;i<M;i++){
    int s,d;
    cin >> s >> d;
    --s; --d;
    add_edge(s,d);
  }

  int K = scc();
  for(int i=1;i<K;i++){

    sort(nG[i].begin(),nG[i].end());
    nG[i].erase(unique(nG[i].begin(),nG[i].end()),nG[i].end());

    sort(nrG[i].begin(),nrG[i].end());
    nrG[i].erase(unique(nrG[i].begin(),nrG[i].end()),nrG[i].end());

    dp[i] = 1LL;
  }
  ll ret = 1;
  for(int i=1;i<K;i++){
    /*
    cout << "vertex : " << i << " dp = " << dp[i] << endl;
    for(int j=0;j<(int)nG[i].size();j++)
      cout << " -> " << nG[i][j] << endl;;
    */
    /*
    memset(used,0,sizeof(used));
    dfs2(i,used);
    for(int j=0;j<K;j++)
      if( used[j] ) 
	for(int k=0;k<(int)nG[j].size();k++)
	  if( !used[nG[j][k]] ) dp[nG[j][k]] = (dp[nG[j][k]] + dp[i])%MOD;
    */

    for(int j=0;j<(int)nG[i].size();j++){
      dp[nG[i][j]] = (dp[nG[i][j]] * (dp[i]+1LL))%MOD;
    }
    if( nG[i].empty() )
      ret  =  ( ret * (dp[i]+1LL) ) % MOD;
  }
  cout << ret << endl;
}

Measured memory_bytes: 1424
#include<bits/stdc++.h>
using namespace std;
map<pair<int,int>,int>cnt;
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		double x;
		scanf("%lf",&x);
		long long ret=(llround(x*1e9));
		int two=0,five=0;
		while(ret%2==0){
			ret/=2;
			two++;
		}
		while(ret%5==0){
			ret/=5;
			five++;
		}
		++cnt[{two,five}];
	}
	long long ans=0;
	for(auto p1:cnt){
		for(auto p2:cnt){
			if(p1.first.first+p2.first.first>=18&&p1.first.second+p2.first.second>=18){
				if(p1<p2) ans+=1ll*p1.second*p2.second;
				else if(p1==p2) ans+=1ll*p1.second*(p1.second-1)/2;
			}
		}
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 3860
// ABC142 F

#include <iostream>
#include <vector>
#include <queue>

using namespace std;

const int MAX_N = 1000;
int N;
int M;

const int INF = 1 << 30;

vector<int> table[MAX_N];

vector<int> bfs(int start) {
    vector<int> dis(N, INF);
    dis[start] = 0;
    vector<int> prev(N, -1);

    queue<int> que;
    que.push(start);
    while (!que.empty()) {
        int v = que.front(); que.pop();
        for (int next : table[v]) {
            if (dis[next] != INF) continue;
            dis[next] = dis[v] + 1;
            prev[next] = v;
            que.push(next);
        }
    }

    int mn = N + 1;

    for (int v = 0; v < N; ++v) {
        for (int next : table[v]) {
            if (next != start) continue;
            mn = min(mn, dis[v] + 1);
        }
    }

    for (int v = 0; v < N; ++v) {
        if (dis[v] + 1 != mn) continue;

        for (int next : table[v]) {
            if (next != start) continue;

            vector<int> nodes({v});
            int node = v;
            while (node != start) {
                node = prev[node];
                nodes.push_back(node);
            }

            return nodes;
        }
    }

    return vector<int>();
}

signed main() {
    cin >> N >> M;
    for (int j = 0; j < M; ++j) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        table[a].push_back(b);
    }

    int mn = N + 1;
    vector<int> ans;
    for (int start = 0; start < N; start++) {
        vector<int> res = bfs(start);
        int sz = res.size();
        if (sz == 0 || sz >= mn) continue;
        mn = sz;
        ans = res;
    }

    if (mn == N + 1) {
        cout << -1 << endl;
    } else {
        cout << mn << endl;
        for (int v : ans) cout << v + 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 384
import numpy as np
import sys
input = sys.stdin.buffer.readline

N, M, K = map(int, input().split())
cumA = np.zeros(N+1, dtype=np.int64)
cumA[1:] = np.array(input().split(), dtype=np.int64).cumsum()
cumB = np.zeros(M+1, dtype=np.int64)
cumB[1:] = np.array(input().split(), dtype=np.int64).cumsum()
# print(cumA)
# print(cumB)

ans = 0
for i in range(N, -1, -1):
    if cumA[i] > K: continue
    j = np.searchsorted(cumB, K-cumA[i], side='right')
    ans = max(ans, i+j-1)
print(ans)

Measured memory_bytes: 44616
#include <cstdio>
#include <cstring>
#define LL long long

LL D,p10[100];

LL dfs(int l,LL d,int flag){
	if(l<=1){
		if(d!=0) return 0;
		if(!l) return 1;
		return flag?10:9;
	}
	if(d%10!=0 && l>=17) return 0;
	LL temp=(d%10+10)%10;
	LL ans=0;
	if(temp<=9)
		ans+=(9-temp+flag)*dfs(l-2,(d-temp*(1-p10[l-1]))/10,1);
	if(temp-10>=-9)
		ans+=(temp-1+flag)*dfs(l-2,(d-(temp-10)*(1-p10[l-1]))/10,1);
	return ans;
}

int main(){
#ifdef DEBUG
	freopen("F.in","r",stdin);
#endif
	p10[0]=1;
	for(int i=1;i<100;i++) p10[i]=p10[i-1]*10;
	scanf("%lld",&D);
	LL ans=0;
	for(int i=1;i<=30;i++)
		ans+=dfs(i,D,0);
	printf("%lld\n",ans);
}


Measured memory_bytes: 128
from heapq import heapify, heappop
N = int(input())
AB = [tuple(map(int, input().split())) for _ in range(N - 1)]
C = list(map(int, input().split()))

M = sum(C) - max(C)

nl = [list() for i in range(N)]
for a, b in AB:
    nl[a - 1].append(b - 1)
    nl[b - 1].append(a - 1)

v0 = -1
mlen = 0
for i, n in enumerate(nl):
    if len(n) > mlen:
        mlen = len(n)
        v0 = i

q = [-c for c in C]
heapify(q)
ans = [0] * N
stack = [(v0, -1)]
while len(stack) > 0:
    v, p = stack.pop()
    c = heappop(q)
    ans[v] = -c
    for next_v in nl[v]:
        if next_v != p:
            stack.append((next_v, v))
print(M)
print(*ans)

Measured memory_bytes: 60376
// Problem : B - Distance 
// Contest : AtCoder - AtCoder Beginner Contest 174
// URL : https://atcoder.jp/contests/abc174/tasks/abc174_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/*
	“Whether you think you can, or you think you can’t – you’re right” - Henry Ford 
*/

#pragma GCC optimize("Ofast")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) x.begin(), x.end()
#define F first
#define S second
#define pb push_back
#define pl pair<ll, ll>
#define vl vector<ll>
#define vi vector<int>
#define endl '\n'

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#ifdef LOCAL
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

template <typename T, typename TT>
ostream &operator<<(ostream &os, const pair<T, TT> &t) {
    return os << t.first << " " << t.second;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &t) {
    for (auto &i : t) os << i << " ";
    return os;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (T &t : v) is >> t;
    return is;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, vector<pair<T1, T2>> &v) {
    for (pair<T1, T2> &t : v) is >> t.first >> t.second;
    return is;
}

const ll mod = 1e9 + 7;

void solve() {
	long double n, d, c= 0;
	cin >> n >> d;
	while(n--) {
		ll a, b; cin >> a >> b;
		long double dis = sqrt(a*a + b*b);
		if(dis <= d) c++;
	}
	cout << c << endl;
}

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


Measured memory_bytes: 3864
import java.util.*;

public class Main {
    public void main(Scanner sc) {
        long x = sc.nextLong();
        long y = sc.nextLong();

        System.out.println(Math.abs(x - y) <= 1 ? "Brown" : "Alice");
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        new Main().main(sc);
        sc.close();
    }
}


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

struct Card{
	char number;
	char mark;
	int id;
};

void printResult(bool isStable){
	if(isStable)cout << "Stable" << endl;
	else cout << "Not stable" << endl;
	return;
}

int main(){

	Card bubbleCard[36];
	Card selectionCard[36];
	char dubbleList[36];

	int numOfCard;

	cin >> numOfCard;

	for(int i = 0; i < numOfCard; i++){
		char bufm; 
		char bufn;
		
		cin >> bufm;
		cin >> bufn;

		bubbleCard[i].number = selectionCard[i].number = bufn;
		bubbleCard[i].mark = selectionCard[i].mark = bufm;
		bubbleCard[i].id = selectionCard[i].id = i;
	}

			

	//bubbleSort
	for(int i = 0; i < numOfCard; i ++){
		for(int j = numOfCard - 1; j >= i + 1; j--){
			if(bubbleCard[j].number < bubbleCard[j -1].number){
				Card buf = bubbleCard[j];
				bubbleCard[j] = bubbleCard[j-1];
				bubbleCard[j-1] = buf;
			}
		}
	}
	
	//selectionCard
	for(int i = 0; i < numOfCard; i++){
		int index = i;
		for(int j = i; j < numOfCard; j++){
			if(selectionCard[j].number < selectionCard[index].number){
				index = j;
			}
		}
		if(index != i){
			Card buf = selectionCard[i];
			selectionCard[i] = selectionCard[index];
			selectionCard[index] = buf;
		}
	}

	

	//cout bubble
	
	bool isStable = true;

	for(int i = 0; i < numOfCard; i ++){

		cout << bubbleCard[i].mark;
		cout << bubbleCard[i].number;
		
		if(i + 1 == numOfCard)cout << endl;
		else {
			if(bubbleCard[i].number == bubbleCard[i+1].number && bubbleCard[i].id > bubbleCard[i + 1].id && isStable){
				isStable = false;
			}
			cout << " ";
		}
			
	}
	printResult(isStable);


	//cout selection 

	isStable = true;
	for(int i = 0; i < numOfCard; i ++){

		cout << selectionCard[i].mark;
		cout << selectionCard[i].number;
		
		if(i + 1 == numOfCard)cout << endl;
		else{
			if(selectionCard[i].number == selectionCard[i+1].number && selectionCard[i].id > selectionCard[i + 1].id && isStable){
				isStable = false;	
			}
			cout << " ";
		}
	}
	printResult(isStable);

	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
int main()
{
    vector<int> cnt(100010, 0);
    int N;
    cin >> N;

    rep(i, N) {
        int a;
        cin >> a;
        a++;
        cnt[a]++;
        cnt[a - 1]++;
        cnt[a + 1]++;
    }

    sort(all(cnt));
    reverse(all(cnt));

    cout << cnt[0] << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pint pair<int, int>
#define pll pair<ll, ll>
#define vint vector<int >
#define vll vector<ll >
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i,n) for (int i = 0; i < (n); ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    string s;
    cin >> s;
    if(s[0] <= 0x5a){
        cout << "A\n";
    }else{
        cout << "a\n";
    }

    return 0;
}

Measured memory_bytes: 3676
#include<stdio.h>
#include<limits.h>//调用INT_MAX与INT_MIN的
#include<algorithm>
using namespace std;
int main()
{
    int n,tmp,minv=INT_MAX,maxv=INT_MIN;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&tmp);
        maxv=max(maxv,tmp-minv);
        minv=min(minv,tmp);
    }
    printf("%d\n",maxv);
}



Measured memory_bytes: 2764
#include <algorithm>
#include <cmath>
#include <ctype.h>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define ENDL '\n'
#define FOR(i, n) for (int i = 0; i < n; i++)
#define FOR_EACH(i, v) for (auto&& i : v);

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

	int N;
	int K;
	cin >> N >> K;

	cout << K * (int)pow(K - 1, N - 1) << ENDL;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N];
        int[] b = new int[N];
        for(int i=0;i<N;i++){
            int tmp = sc.nextInt();
            a[i] = tmp;
            b[i] = tmp;
        }
        Arrays.sort(a);
        int max1 = a[N-1];
        int max2 = a[N-2];
        for(int i=0;i<N;i++){
            if(b[i] == max1){
                System.out.println(max2);
            }
            else{
                System.out.println(max1);
            }
        }
    }
}

Measured memory_bytes: 101768
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
#include<set>
 
using namespace std;
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define P(p) cout<<(p)<<endl;
#define PP(p) cout<<(p)<<" ";
#define INF 1e18
#include<iomanip>
typedef long long ll;
#define PI 3.141592653589793
#define int ll
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pi;
//int dy[8]={1,1,1,0,-1,-1,-1,0};
//int dx[8]={-1,0,1,1,1,0,-1,-1};
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int a,b,h,m;
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>a>>b>>h>>m;
    double r1,r2;
    double totalM = 60*h+m;
    r1 = fmod(totalM*(360.0/720.0),360); //短
    r2 = fmod(totalM*(360.0/60.0),360); //長
    double rad = abs(r1-r2)*PI/180.0;
    double l = sqrt((double)(a*a + b*b )-(double)(2*a*b)*cos(rad));
    cout<<fixed<<setprecision(15)<<l<<endl;
    return 0;
}


Measured memory_bytes: 4240
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


class Program
{


    static void Main(string[] args)
    {
        Solve();
    }

    static void Solve()
    {
        Scan sc = new Scan();
        write wr = new write();

        var ああ = sc.intarr;
        int a = ああ[0];
        int b = ああ[1];

        int min = b - a;
        wr.wri(wa(min)-b);

    }

    static int wa(int n)
    {
        return n * (n + 1) / 2;
    }


}
    class Scan
    {
        public string str => Console.ReadLine();

        public string[] strarr => str.Split(' ');

        public long[] longarr => strarr.Select(long.Parse).ToArray();
        public int[] intarr => strarr.Select(int.Parse).ToArray();
        public char[] chararr => str.ToArray();


}



class write
{
    public void wri<Type>(Type x)
    {
        Console.WriteLine(x);
    }
}


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

#define INF (int)1e9+7
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define N 100005
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795

ll no_of_div(ll a)
{
  ll cnt=0,i;
  if (a==2)return 1;
  for(i=2;i*i<a;i++)
  {
if(a%i==0)cnt+=2;
  }
  if(i*i==a)cnt++;
  return cnt;
}

//vl a(1001);

ll powM(ll a,ll b)
{ 
  ll ans=1;
  while(b>0)
  {
    if(b&1)ans=ans*a;
    a=a*a;
    b>>=1;
  }

return ans;
}







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


string s;cin>>s;
vector<string>store;

int n=s.size();
string ss="";
for(int i=0;i<n-1;i++)
{
if(s[i]=='L'&&s[i+1]=='R')
{
  ss+=s[i];
  store.pb(ss);
  ss="";
}
else ss+=s[i];

}
ss+='L';
store.pb(ss);
/*
for(int i=0;i<store.size();i++)
{

cout<<store[i]<<"\n";
}
*/
for(int i=0;i<store.size();i++)
{
  ll l=0,r=0,pos_r,pos_l;
  for(int j=0;j<store[i].size();j++)
  {
    if(store[i][j]=='R')r++;
    else 
    {
      pos_r=j-1;
      pos_l=j;
      l=store[i].size()-j;
      break;
    }
  }
  //cout<<pos_r<<" "<<pos_l<<"\n";
ll xl,xr;
  if(store[i].size()&1)
  {
    ll x=max(l,r)-1;
    if(r>l)
    {
      if(x&1)
      {
        xl=1;
        xr=-1;
      }
      else 
      {
        xl=-1;
        xr=1;
      }
    }
      else 
      {
          if(x&1)
          {
            xl=-1;
            xr=1;
          }
          else
            {
              xl=1;
              xr=-1;
            }
      }
    }
    ll count_r=(store[i].size()+xr)/2;
   // if(r>l)count_r--;
    ll count_l=store[i].size()-count_r;
if(store[i].size()&1){
         for(int k=0;k<store[i].size();k++)
         {
          if(k==pos_r)cout<<count_r<<" ";
          else if(k==pos_l)cout<<count_l<<" ";
          else cout<<0<<" ";
        
         }
  }
  else 
  {
     for(int k=0;k<store[i].size();k++)
     {
      if(k==pos_r)cout<<store[i].size()/2<<" ";
      else if(k==pos_l)cout<<store[i].size()/2<<" ";
      else cout<<0<<" ";
     }
  }
}



  return 0;


}

Measured memory_bytes: 3272
#include<stdio.h>
#include<math.h>
int main(){
      int n,a[100005],i=0,j=0,flag=1,t=0;
      scanf("%d",&n);
      for(i=0;i<n;i++)
        scanf("%d",&a[i]);
        while(flag){
      for(j=0;j<n;j++){
        if(a[j]%2!=0){
            flag=0;
            break;
        }
        else if(a[j]%2==0)
            a[j]/=2;
        if(j==n-1)
            t++;
      }

      }
      printf("%d",t);
      return 0;
}


Measured memory_bytes: 128
//This Code was made by Chinese_zjc_.
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<bitset>
#include<cmath>
#include<queue>
#include<stack>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<map>
#include<set>
#include<time.h>
// #include<windows.h>
#define int long long
#define PI 3.14159265358979323
#define INF 0x3fffffffffffffff
using namespace std;
int d,s,t;
signed main()
{
    ios::sync_with_stdio(false);
    cin>>d>>t>>s;
    cout<<(s*t>=d?"Yes":"No")<<endl;
    return 0;
}

Measured memory_bytes: 3644
route_list = []
for i in range(3):
    route_list.append(list(map(int, input().strip().split())))

city_routes = [0, 0, 0, 0]
for route in route_list:
    city_routes[route[0] - 1] += 1
    city_routes[route[1] - 1] += 1

ans = "YES"
if(max(city_routes) > 2):
    ans = "NO"
if(min(city_routes) < 1):
    ans = "NO"
print(ans)

Measured memory_bytes: 3064
// -----------------------------------------------
// Framework <https://github.com/vain0x/procon>
//
// See the bottom of file for solution.
// -----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let S = rl();

    let T = "keyence";
    let mut ok = false;
    for i in 0..T.len() + 1 {
        ok = ok || S.starts_with(&T[..i]) && S.ends_with(&T[i..]);
    }

    println!("{}", if ok { "YES" } else { "NO" })
}


Measured memory_bytes: 4352
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
import Data.List
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import Control.Monad
import Data.Bits
-- import Control.Monad.ST
-- import Debug.Trace

solve :: Int -> Int -> [Int] -> Int
solve n k as = value 0 seq
  where

    size = n * (n+1) `div` 2
    acc = VU.fromList $ scanl' (+) 0 as
    subsum = [(acc VU.! i) - (acc VU.! j) | j <- [0..n], i <- [j+1..n]]

    seq = unfoldr f (subsum, 47)
      where
        f (_, -1) = Nothing
        f (lst, p) | length ok >= k = Just (1, (ok, p-1))
                   | otherwise      = Just (0, (lst, p-1))
          where
            ok = filter (\x -> testBit x p) lst

    value acc [] = acc
    value acc (b:bs) = value (2*acc + b) bs

int2bits :: Int -> [Int]
int2bits x = take 48 $ unfoldr f x
  where
    f y = Just (q, p)
      where (p,q) = divMod y 2


readBInt :: B.ByteString -> Int
readBInt = fst . fromJust . B.readInt

tmain :: B.ByteString -> Int
tmain cont =
  let remLines0 = map B.words (B.lines cont)
      [bs_n,bs_k]:remLines1 = remLines0
      n = readBInt bs_n
      k = readBInt bs_k
      line2:remLines2 = remLines1
      as = map readBInt line2
  in solve n k as

outAnswer :: Int -> IO ()
outAnswer = putStrLn . show

main :: IO ()
main = outAnswer . tmain =<< B.getContents


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

#define ll long long

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    priority_queue<ll> pq;
    for (int i = 0; i < n; i++) {
        ll x;
        cin >> x;
        pq.push(x);
    }
    while (m--) {
        ll c = pq.top();
        pq.pop();
        c /= 2;
        pq.push(c);
    }
    ll ans = 0;
    while (!pq.empty()) {
        ans += pq.top();
        pq.pop();
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 1400
#include <algorithm>
#include <queue>
#include <cctype>
#include <cstdio>
#include <vector>

using namespace std;
#define reps(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reps(i,0,n)

typedef vector<int> vi;
typedef vector<vi> vvi;

const int INF = 1001001001;

int dev[32][32][33][33];
int sup[32][32][33][33];

int main()
{
	int h, w, s;
	while(scanf("%d%d%d", &h, &w, &s), h){
		int d[32][32];
		rep(i, h) rep(j, w)
			scanf("%d", &d[i][j]);

		int sum[33][33] = {{0}};
		rep(i, h) rep(j, w)
			sum[i+1][j+1] = sum[i+1][j] + sum[i][j+1] - sum[i][j] + d[i][j];

		s = sum[h][w] - s;
		reps(i, 1, h+1) reps(j, 1, w+1) rep(y, h-i+1) rep(x, w-j+1){
			dev[y][x][i][j] = 1;
			sup[y][x][i][j] = sum[y+i][x+j] - sum[y+i][x] - sum[y][x+j] + sum[y][x];
			reps(k, 1, i){
				int supsa = min(sup[y][x][k][j], sup[y+k][x][i-k][j]);
				if(supsa >= s){
					int devsa = dev[y][x][k][j] + dev[y+k][x][i-k][j] - dev[y][x][i][j];
					if(devsa>0 || (devsa==0 && supsa > sup[y][x][i][j])){
						dev[y][x][i][j] += devsa;
						sup[y][x][i][j] = supsa;
					}
				}
			}
			reps(k, 1, j){
				int supsa = min(sup[y][x][i][k], sup[y][x+k][i][j-k]);
				if(supsa >= s){
					int devsa = dev[y][x][i][k] + dev[y][x+k][i][j-k] - dev[y][x][i][j];
					if(devsa>0 || (devsa==0 && supsa > sup[y][x][i][j])){
						dev[y][x][i][j] += devsa;
						sup[y][x][i][j] = supsa;
					}
				}
			}
		}
		printf("%d %d\n", dev[0][0][h][w], sup[0][0][h][w]-s);
	}
	return 0;
}

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

using namespace std;
typedef long long ll;
#define _IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll N=3e5+5,mod=1e9+7,inf=1e18;
struct node{

    ll l,r;
    ll val;
}tr[N*4];
ll n,k;


void pushup(ll u){

    tr[u].val = max(tr[u*2].val , tr[u*2+1].val);
    
}

void build(ll u , ll l ,ll r){

    if(l==r){
        tr[u] = {l,r,0};
    }
    else{

        tr[u] = {l,r};
        ll mid = (l+r)/2;
        build(u*2 ,l ,mid);
        build(u*2+1, mid+1 ,r);
        pushup(u);
    }
}

void modify(ll u ,ll x, ll v){

    if(tr[u].l>x || tr[u].r<x ) return;
    if(tr[u].l == tr[u].r){
        tr[u].val = max(tr[u].val , v);
        return;
    }
    else{
        
        //ll mid = tr[u].l+tr[u].r>>1;
        ll mid = (tr[u].l+tr[u].r)/2;
        modify(u*2 , x , v);
        modify(u*2+1 , x , v);
        pushup(u);
    }

}


ll query(ll u , ll l , ll r){


    if(tr[u].l>r || tr[u].r<l) return -inf;
    if(tr[u].l>=l && tr[u].r <=r) return tr[u].val;
    else{
        ll mid = (tr[u].l+tr[u].r)/2;
        return max(query(u*2,l,r),query(u*2+1,l,r));
    }

}




int main()
{
    _IO;
    ll n,k;
    cin >> n >> k;
    build(1, 0, N);

    ll mx = 0;
    while(n--){
        ll x;
        cin >> x;
        ll p = query(1 , max(0LL , x-k) , min(N , x+k));
        modify(1 , x, p+1);
        mx = max(mx, p+1);
    }
    cout << mx;

    return 0;
}



Measured memory_bytes: 28228
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define mem(x,y)		(x*)malloc(sizeof(x)*(y));

int find(int a,int b,int** list,int n)
{
	int* cost = mem(int,n);
	int* flg = mem(int,n);
	int i,j,k;
	for(i = 0;i < n;i++)
	{
		cost[i] = 100000000;
		flg[i] = 1;
	}
	cost[a-1] = 0;
	for(i = 1;i < n;i++)
	{
		for(j = 0;j < n;j++)
		{
			if(flg[j])
			{
				flg[j] = 0;
				for(k = 0;k < n;k++)
				{
					if(list[j][k] < 1000000 && cost[k] > cost[j]+list[j][k])
					{
						cost[k] = cost[j]+list[j][k];
						flg[k] = 1;
					}
				}
			}
		}
	}
	return cost[b-1];
}

int main()
{
	int n,k,i,j;
	int** list;
	while(scanf("%d %d",&n,&k),n)
	{
		list = mem(int*,n);
		for(i = 0;i < n;i++)
		{
			list[i] = mem(int,n);
			for(j = 0;j < n;j++)
			{
				list[i][j] = 1000001;
			}
		}
		for(i = 0;i < k;i++)
		{
			int cmd;
			scanf("%d",&cmd);
			if(cmd == 1)
			{
				int a,b,e;
				scanf("%d %d %d",&a,&b,&e);
				if(list[a-1][b-1] > e)
				{
					list[a-1][b-1] = list[b-1][a-1] = e;
				}
			}
			else
			{
				int a,b;
				scanf("%d %d",&a,&b);
				int cost = find(a,b,list,n);
				if(cost < n*1000000)
					printf("%d\n",cost);
				else
					printf("-1\n");
			}
		}
	}
	return 0;
}

Measured memory_bytes: 5768
#include <iostream>
#include <map>

using namespace std;

long long maxx(long long a,long long b)
{
    return a>b ? a: b;
}
int main()
{
    map<int ,int> m;
    int n;
    cin>>n;
    for(int i=1,x;i<=n;++i)
        cin>>x,m[x]++;
    map<int,int>::reverse_iterator it;
    it=m.rbegin();
    int a=0,b=0,c=0,flag=0;
    while(flag!=2 && it != m.rend())
    {
        if((*it).second>=4)
            if(c==0)    c=(*it).first;
        if((*it).second>=2)
            b=a,a=(*it).first,flag++;
        ++it;
    }
    if(flag!=2&&c==0)
        cout<<"0"<<endl;
    else
    {
        cout<< maxx((long long)a*b,(long long )c*c)<<endl;
    }
    return 0;
}


Measured memory_bytes: 4992
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;

int main() {
    cin.tie(0);
    cin.sync_with_stdio(0);
    
    int n;
    cin >> n;

    vector<ll> a(n), b(n), diff(n);
    ll sum_a = 0, sum_b = 0, need = 0;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
        sum_a += a[i];
    }
    for (int i = 0; i < n; i++) {
        scanf("%d", &b[i]);
        sum_b += b[i];
        diff[i] = a[i] - b[i];
        if (diff[i] < 0) {
            need -= diff[i];
            ans++;
        }
    }

    if (sum_a < sum_b) {
        cout << -1 << endl;
        return 0;
    }

    sort(diff.begin(), diff.end(), greater<ll>());
    int idx = 0;
    while(need > 0) {
        need -= diff[idx];
        ans++;
        idx++;
    }

    cout << ans << endl;
}

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

int main()
{

	long long N, A, B;

	cin >> N >> A >> B;

	long long repeat = 0;
	long long countA = 0;

	repeat = N / (A + B);

	long long rem = N%(A+B);
	countA = repeat * A + ((rem < A)? rem : A);

	cout << countA << endl;
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n),b(n),c(n-1);
    rep(i,n){ cin >> a[i]; a[i]--;}
    rep(i,n) cin >> b[i];
    rep(i,n-1) cin >> c[i];
    int add = a[0];
    int sum = b[a[0]];
    for(int i=1;i<n;i++){
        sum+=b[a[i]];
        if(add+1 == a[i]) sum+=c[add];
        add = a[i];

    }    
    cout << sum << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;

const int V = 100010;

int main()
{
	int n, weight;
	cin >> n >> weight;

	vector<ll> w(n), v(n);

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

	vector<vector<ll>> dp(n + 1, vector<ll>(V));
	for (int i = 0; i <= n; i++)
	{
		for (int j = 0; j < V; j++)
		{
			dp[i][j] = inf;
		}
	}

	dp[0][0] = 0;

	for (int i = 0; i < n; i++)
	{
		for (int sv = 0; sv < V; sv++)
		{
			if (sv - v[i] >= 0)
			{
				dp[i + 1][sv] = min(dp[i + 1][sv], dp[i][sv - v[i]] + w[i]);
			}

			dp[i + 1][sv] = min(dp[i + 1][sv], dp[i][sv]);
		}

	}

	ll res = 0;
	for (int sv = 0; sv < V; sv++)
	{
		if (dp[n][sv] <= weight)
		{
			res = sv;
		}
	}

	println(res);
}

Measured memory_bytes: 80256
#include <iostream>
#include <vector>
#include <string>
#include <math.h>

using namespace std;

int main() {
  int n, c;
  cin >> n >> c;
  vector<vector<int>> d(c, vector<int>(c, 0));
  for(int i = 0; i < c; i++)
  {
    for(int j = 0; j < c; j++)
    {
      cin >> d[i][j];
    }
  }
  vector<vector<int>> grid(n, vector<int>(n, 0));
  for(int i = 0; i < n; i++)
  {
    for(int j = 0; j < n; j++)
    {
      cin >> grid[i][j];
    }
  }
  vector<vector<int>> color(3, vector<int>(c, 0));
  for(int i = 0; i < n; i++)
  {
    for(int j = 0; j < n; j++)
    {
      int temp = i + 1 + j + 1;
      temp = temp % 3;
      color[temp][grid[i][j] - 1]++;
    }
  }
  long long int mind = 1000 * n * n;
  auto check = [&](int c0, int c1, int c2)
  {
    long long int diff = 0;
    for(int i = 0; i < 3; i++)
    {
      for(int j = 0; j < c; j++)
      {
        if(i == 0)
        {
          diff += color[i][j] * d[j][c0 - 1];
        }else if(i == 1)
        {
          diff += color[i][j] * d[j][c1 - 1];
        }else{
          diff += color[i][j] * d[j][c2 - 1];
        }
      }
    }
    return diff;
  };
  for(int i = 1; i <= c; i++)
  {
    for(int j = 1; j <= c; j++)
    {
      for(int k = 1; k <=c; k++)
      {
        if(i == j || j == k || i == k) continue;
        long long int temp = check(i, j, k);
        mind = min(mind, temp);
      }
    }
  }
  cout << mind << endl;
  return 0;
}


Measured memory_bytes: 1280
#include <iostream>

using namespace std;

int main() {
    int W, H, x, y;
    cin >> W >> H >> x >> y;
    double w = W;
    double h = H;
    double area = w * h / 2;
    int ans1 = 0;
    if(x * 2 == W && y * 2 == H) {
        ans1 = 1;
    }

    cout << area << " " << ans1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;

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

    vector<int> stair(N+1, 1);
    for (int i = 0; i < M; i++)
    {
        int pos;
        cin >> pos;
        stair[pos] = 0;
    }

    vector<ll> dp(N+1, 0);
    dp[0] = 1;
    for (int now = 0; now < N; now++)
    {
        for (int next = now+1; next <= min(N, now+2); next++)
        {
            if(stair[next] > 0){
                dp[next] += dp[now];
                dp[next] %= mod;
            }
        }
        
    }

    cout << dp[N] << endl;
    
    return 0;
}


Measured memory_bytes: 4560
//This code was made by Chinese_zjc_.
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#define int long long
#define INF 0x3fffffffffffffff
using namespace std;
int x;
int _5(int now)
{
	return now*now*now*now*now;
}
signed main()
{
	std::ios::sync_with_stdio(false);
	cin>>x;
	for(int i=-200;i<=200;++i)
	{
		for(int j=-200;j<=200;++j)
		{
			if(_5(i)-_5(j)==x)
			{
				cout<<i<<' '<<j<<endl;
				return 0;
			}
		}
	}
	return 0;
}


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

signed main() {
	int n;
	cin >> n;
	vector<int> p(n);
	for (int i = 0; i < n; ++i)cin >> p[i];
	int ans = 0;
	for (int i = 1; i < n-1; ++i) {
		if (p[i - 1] < p[i] && p[i] < p[i + 1])ans++;
		else if (p[i - 1] > p[i] && p[i] > p[i + 1])ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
int n,max=0,i,x=0;
char s[1001];
scanf("%d", &n);
scanf("%s", s);
for(i=0; i<n; i++){
if(s[i]=='I') x++;
else x--;
if(x > max) max=x;
}
printf("%d\n", max);
return 0;
}

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

using namespace std;
using int64 = long long;
//const int mod = 1e9 + 7;
const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

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

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

int main() {
  int N, K;
  cin >> N >> K;
  vector< int > L(N);
  cin >> L;
  int ok = inf, ng = 0;
  auto check = [&](int t) {
    int add = 0;
    for(auto &c : L) {
      add += (c + t - 1) / t;
    }
    return add <= K + N;
  };
  while(ok - ng > 1) {
    int mid = (ok + ng) / 2;
    if(check(mid)) ok = mid;
    else ng = mid;
  }
  cout << ok << "\n";
}




Measured memory_bytes: 3948
#include <iostream>
using namespace std;
int main()
{
    char c[2][4];
    scanf("%s%s", c[0], c[1]);
    if(c[0][0] == c[1][2] && c[0][1] == c[1][1] && c[0][2] == c[1][0])
        cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<cstring>

using namespace std;
int len,ans = 0 ,res=0;
char d[3]={'3','5','7'},x[11];
    int  num;
bool isValid(char a[])
{
    int cnt[11]={0};
    for(int i=0;i<strlen(a);i++)
    {
        cnt[a[i]-'0']++;
    }

    if(cnt[3] >= 1 && cnt[5] >= 1 && cnt[7] >= 1 &&  cnt[3] + cnt[5] + cnt[7] == strlen(a))
    {
        if(atoi(a) <= num)
        return true;
    }
    return false;
}

void dfs(int pos ,int len ,char  a[] )
{
    if(pos == len )
    {
        a[len]='\0';
        if(isValid(a))
        {
            res++;
        }
        return ;
    }
        a[pos] = '3';
        dfs(pos+1,len,a);

        a[pos] = '5';
        dfs(pos+1,len,a);

        a[pos] = '7';
        dfs(pos+1,len,a);
}
int main()
{

    int i,j,k;
    char str[11];
     scanf("%s",&str);
    num = atoi(str);
    len = strlen(str);

    for(i = 3;i<=len;i++)
        dfs(0,i,x);
    cout<<res;

    return 0;
}


Measured memory_bytes: 256
import collections
n = int(raw_input())
cca = collections.Counter([raw_input() for _ in range(n)])
m = int(raw_input())
ccb = collections.Counter([raw_input() for _ in range(m)])

r = 0
for w in cca.keys() + ccb.keys():
	r = max(r,cca[w] - ccb[w])
print r

Measured memory_bytes: 86724
package main

import (
	"fmt"
)

func main() {
	var westTowerHeight, eastTowerHeight int
	fmt.Scan(&westTowerHeight, &eastTowerHeight)

	diffHeight := eastTowerHeight - westTowerHeight
	realHeight := 0
	for i := 1; i < diffHeight; i++ {
		realHeight += i
	}

	fmt.Println(realHeight - westTowerHeight)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define why(n,x) int n;while(cin >>n,n!=x)
#define iFOR(i,x,n)for(int i=x;i<n;i++)
#define unless(flg) if ( !(flg) )
#define read cin<<
#define echo cout<<
#define fin <<'\n'
#define __ <<" "<<
#define bash push_back
#define alles(x) x.begin(),x.end()
int dx[]={1,0,-1,0,1,1,-1,-1};
int dy[]={0,-1,0,1,-1,1,-1,1};
const int INF=1 << 30;
bool inside(int x,int y,int w,int h){
return (x>=0 && y>=0 && x<w && y<h);}
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vit;
typedef map<string,int> mstit;
typedef priority_queue<int> pqit;
 
ll n,a[1000005];
int main(){
cin.tie(0), ios::sync_with_stdio(false);
cin >>n;
FOR(i,n*3){
cin >>a[i];
}
sort(a,a+n*3,greater<int>());
ll ans=0;
for(int i=1;i<=n*2;i+=2){
ans+=a[i];
}
cout <<ans fin;
return 0;
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
#define INF (1e9)

int main() {
  int T;
  cin >> T;
  while (T--) {
    int N, ans = 0;
    cin >> N;
    vi A(N), B(1, 0);
    for (int i = 0; i < N; i++) cin >> A[i];
    string S;
    cin >> S;
    for (int i = N - 1; i >= 0; i--) {
      for (ll b : B) A[i] = min(A[i], A[i] ^ b);
      if (A[i] == 0) continue;
      if (S[i] == '0') B.push_back(A[i]);
      else ans = 1;
    }
    cout << ans << endl;
  }
}


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> B(N);
  vector<int> C(N-1);
  for(int i = 0; i < N; i++){
    cin >> A.at(i);
  }
  for(int i = 0; i < N; i++){
    cin >> B.at(i);
  }
  for(int i = 0; i < N-1; i++){
    cin >> C.at(i);
  }
  int out = 0;
  int pre = -1;
  for(int i = 0; i < N; i++){
    int ind = A.at(i);
    if(ind == pre + 1){
      out += C.at(pre - 1);
    }
    out += B.at(ind - 1);
    pre = ind;
  }
    
  cout << out;
}


Measured memory_bytes: 256