akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func solve(sc *scanner, wr *bufio.Writer) {
	n, a, b := sc.getInt3()
	xs := sc.getInts(n)

	ans := 0
	for i := 0; i < n-1; i++ {
		walk := a * (xs[i+1] - xs[i])
		ans += min(walk, b)
	}
	fmt.Fprintln(wr, ans)
}

func main() {
	sc := newScanner()
	wr := bufio.NewWriter(os.Stdout)
	maxBufSize := int(1e8)
	sc.Buffer(make([]byte, 4096), maxBufSize)
	sc.Split(bufio.ScanWords)

	solve(sc, wr)
	wr.Flush()
}

// input ------------------------
type scanner struct {
	*bufio.Scanner
}

func newScanner() *scanner {
	sc := bufio.NewScanner(os.Stdin)
	return &scanner{sc}
}
func (sc *scanner) getInt() int {
	sc.Scan()
	ret, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return ret
}
func (sc *scanner) getInt2() (int, int) {
	return sc.getInt(), sc.getInt()
}
func (sc *scanner) getInt3() (int, int, int) {
	return sc.getInt(), sc.getInt(), sc.getInt()
}
func (sc *scanner) getInt4() (int, int, int, int) {
	return sc.getInt(), sc.getInt(), sc.getInt(), sc.getInt()
}
func (sc *scanner) getInts(n int) []int {
	ret := make([]int, n)
	for i := range ret {
		ret[i] = sc.getInt()
	}
	return ret
}
func (sc *scanner) getString() string {
	sc.Scan()
	return sc.Text()
}
func (sc *scanner) getRunes() []rune {
	return []rune(sc.getString())
}
func (sc *scanner) getFloat() float64 {
	sc.Scan()
	ret, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return ret
}
func (sc *scanner) getFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := range ret {
		ret[i] = sc.getFloat()
	}
	return ret
}

// math ----------------------------
func sum(ns ...int) int {
	var sum int
	for _, n := range ns {
		sum += n
	}
	return sum
}

func max(ns ...int) int {
	max := ns[0]
	for i := 1; i < len(ns); i++ {
		if max < ns[i] {
			max = ns[i]
		}
	}
	return max
}

func min(ns ...int) int {
	min := ns[0]
	for i := 1; i < len(ns); i++ {
		if min > ns[i] {
			min = ns[i]
		}
	}
	return min
}

func pow(a, b int) int {
	ret := 1
	for b > 0 {
		if b&1 > 0 {
			ret = ret * a
		}
		a = a * a
		b >>= 1
	}
	return ret
}


Measured memory_bytes: 4208
/*Made by Shivam Solanki*/
#include<bits/stdc++.h>
#pragma GCC optimize ("Ofast")
using namespace std;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define ll long long int
#define endl '\n'
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<pii> vp;
typedef vector<pll> vpll;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef set<int> sii;
typedef set<ll> sll;
typedef queue<int> qii;
typedef priority_queue<int> pq;
typedef unordered_map<int,int> umii;
typedef unordered_map<ll,ll> umll;
#define all(x) x.begin(),x.end()
#define rep(i,k,n) for (int i = k; i < n; ++i) 
#define repr(i,k,n) for (int i = n; i>=k; --i)
#define repll(i,k,n) for (ll i = k; i < n; ++i) 
#define pb push_back
#define mp make_pair
#define gcd __gcd
#define F first
#define S second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const int INF = 1e9+5;
const int MOD = 1e9+7;

void solve(){
    int n;
    cin>>n;
    cout<<(n%10==3?"bon":(n%10==2 or n%10==4 or n%10==5 or n%10==7 or n%10==9?"hon":"pon"));
}

int main(){ 
    // #ifndef ONLINE_JUDGE  
        // freopen("input.txt", "r", stdin); 
        // freopen("output.txt", "w", stdout); 
    // #endif 
    fastio;
    int t=1;
    // cin>>t;
    while(t--)
        solve();
    return 0;
}


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

using namespace std;

#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVS vector<vector<string>>
#define VVC vector<vector<char>>
#define fore(i,a) for(auto &i:a)
typedef long long ll;
typedef pair <int, int> P;
const int  INF = 2147483647;
const ll INFL = 9223372036854775807;
const ll mod = 1000000007;

using namespace std;


int main() {
	ll h, w, n;
	cin >> h >> w >> n;
	set<P> s;
	set<P> t;
	REP(i, n) {
		int a, b;
		cin >> a >> b;
		s.insert({ a,b });
		REP(j, 3)REP(k, 3)t.insert({ a - j,b - k });
	}

	VLL j(10, 0);
	for (P p : t) {
		int x = p.first;
		int y = p.second;
		if (0 < x&&x + 2 <= h && 0 < y&&y + 2 <= w) {
			int res = 0;
			REP(j, 3)REP(k, 3)res += s.count({ x + j,y + k });
			j[res]++;
		}
		

	}
	j[0] = (h - 2)*(w - 2) - j[1] - j[2] - j[3] - j[4] - j[5] - j[6] - j[7] - j[8] - j[9];
	REP(i, 10)cout << j[i] << endl;

	return 0;
}

Measured memory_bytes: 47104
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
  int n;
  vector<double> v;
  cin >> n;
  for(int i=0; i<n; i++){
    double a;
    cin >> a;
    v.push_back(a);
  }
  sort(v.begin(), v.end());
  double ans=0;
  for(int i=0; i<n-1; i++){
    if(ans<((v[i]+v[i+1])/2.0)){
      ans=(v[i]+v[i+1])/2.0;
      v[i+1]=(v[i]+v[i+1])/2.0;
    }
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.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 (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int T, n, m;
vector<vi> g;

int dfs(int u){
	vi d;
	for(int v : g[u]) d.pb(dfs(v));
	sort(RALL(d));
	int res = 0;
	REP(i, d.size()) res = max(res, 1 + i + d[i]);
	return res;
}

int main(int argc, char *argv[]){
	ios::sync_with_stdio(false);
	cin >> n;
	g.resize(n);
	REPS(i, n-1){
		int p; cin >> p; p --;
		g[p].pb(i);
	}
	cout << dfs(0) << endl;
	return 0;
}


Measured memory_bytes: 15104
#include<bits/stdc++.h>
using namespace std;
#define For(i,m,n) for(int i=m;i<n;i++)
#define FOR(n) for(int i=0;i<n;i++)
#define ll long long
ll mob=1000000007;
using namespace std;
int main()
{ string h;
cin>>h;
int y=(int)h.length();
FOR(y)cout<<'x';
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 a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		if((a+b) % 2 == 0) System.out.println((a+b)/2);
		else System.out.println((a+b)/2 + 1);
	}
	
}

Measured memory_bytes: 23764
import sys
input = sys.stdin.buffer.readline

def main():
    A,B,C = map(int,input().split())
    if A%2 == 0 or B%2 == 0 or C%2 == 0:
        print(0)
    else:
        print(min(A*B,B*C,C*A))

if __name__ == "__main__":
    main()


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

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

//#define int long long
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int tbl[8];
int b[8 * 7 * 6 * 5 * 4 * 3 * 2 * 1];

int encode(int x[8]) {
	int p[8];
	int ret = 0;
	rep(i, 0,8) p[i] = i;
	rep(i, 0, 8) {
		int a = x[i];
		ret += p[a] * tbl[i];
		for (int i = a + 1; i < 8; i++) p[i]--;
	}
	return ret;
}

void decode(int x[8], int val) {
	int p[8];
	rep(i, 0, 8) p[i] = i;
	rep(i, 0, 7) {
		int a = val / tbl[i];
		val -= a * tbl[i];
		x[i] = p[a];
		for (int i = a; i < 7; i++) p[i] = p[i + 1];
	}
	x[7] = p[0];
}

void solve()
{
	static const int dz[] = { 4,1,-1,-4 };

	memset(b, -1, sizeof(b));
	tbl[6] = 1;
	for (int i = 5; i >= 0; i--) tbl[i] = tbl[i + 1] * (7 - i);

	queue<pii> q;
	q.push(pii(0, 0));
	b[0] = 0;

	while (!q.empty())
	{
		pii tp = q.front(); q.pop();
		int a[8];
		decode(a, tp.first);
		int pz = find(a, a + 8, 0) - a;
		rep(i, 0, 4)
		{
			int npz = pz + dz[i];
			if (0 <= npz&&npz < 8 && npz + pz != 7)
			{
				swap(a[pz], a[npz]);
				int en = encode(a);
				if (b[en] == -1)
				{
					b[en] = tp.second + 1;
					q.push(pii(en, tp.second + 1));
				}
				swap(a[pz], a[npz]);
			}
		}
	}
}

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

	solve();

	int A[8];
	while (true)
	{
		rep(i, 0, 8)
		{
			if (!(cin >> A[i]))
			{
				return 0;
			}
		}
		cout << b[encode(A)] << endl;
	}

	return 0;
}


Measured memory_bytes: 3284
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<(n);++i)
#define int long long
#define pb push_back
#define all(v) v.begin(),v.end()
#define yn(b) cout<<((b)?"Yes":"No")<<endl
#define YN(b) cout<<((b)?"YES":"NO")<<endl
#define call(a) for(auto t:a)cout<<t<<" ";cout<<endl
#define ENDL printf("\n");
#define debg(a) cout<<#a<<":"<<a<<endl;
#define SORT(a) sort(all(a));
#define out(i) cout<<i<<endl;
#define m_p make_pair
#define m_t make_tuple
#define Vec vector
typedef long long ll;
typedef string str;
typedef vector<int> V;
typedef vector<pair<int,int>> VP;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
int min(int a,int b){if(a>b)return b;return a;}
int max(int a,int b){if(a>b)return a;return b;}
int gcd(int a,int b){if(b==0)return a; return gcd(b,a%b);}
int lcm(int a,int b){return a/gcd(a,b)*b;}
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
const ll INF=1ll<<60;
const ll MOD=1e9+7;

int func(int a,int b){
  int res=0;
  while(a){
    res+=a%10;
    a/=10;
  }
  while(b){
    res+=b%10;
    b/=10;
  }
  return res;
}

signed main(){
  int n;
  cin>>n;
  int ans=INF;
  rep(i,n){
    if(i==0)continue;
    int a=i,b=n-i;
    ans=min(ans,func(a,b));
  }
  out(ans);
    
  return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
vector<pair<int,long long> >g[110000];
long long ijk[110000];
int v[110000];
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a-1;i++){
		int p,q;long long r;
		scanf("%d%d%lld",&p,&q,&r);
		p--;q--;
		g[p].push_back(make_pair(q,r));
		g[q].push_back(make_pair(p,r));
	}
	int b,c;scanf("%d%d",&b,&c);c--;
	priority_queue<pair<long long,int> > Q;
	for(int i=0;i<a;i++)ijk[i]=inf;
	ijk[c]=0;
	Q.push(make_pair(0LL,c));
	while(Q.size()){
		long long cost=-Q.top().first;
		int at=Q.top().second;
		Q.pop();
		if(v[at])continue;
		v[at]=1;
		for(int i=0;i<g[at].size();i++){
			int to=g[at][i].first;
			long long tc=cost+g[at][i].second;
			if(!v[to]&&ijk[to]>tc){
				ijk[to]=tc;Q.push(make_pair(-tc,to));
			}
		}
	}
	while(b--){
		int p,q;scanf("%d%d",&p,&q);p--;q--;
		printf("%lld\n",ijk[p]+ijk[q]);
	}
}

Measured memory_bytes: 11504
# -*- coding: utf-8 -*-
n, k = map(int, input().split())
p = list(map(int, input().split()))

sp = [0 for _ in range(n-k+1)]
sp[0] = sum(p[:k])
mv = sp[0]
mi = 0
for i in range(1, n-k+1):
    sp[i] = sp[i-1]
    sp[i] -= p[i-1]
    sp[i] += p[i+k-1]
    if mv < sp[i]:
        mv = sp[i]
        mi = i

exp = 0
for i in range(mi, mi+k):
    exp += (p[i] + 1) / 2.0

print(exp)


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

bool custom(pair<int, int> a, pair<int, int> b) {
  return (a.first < b.first);
}
int main() {
  int n;
  long long int k;
  cin >> n >> k;
  vector<pair<int, int>> ab(n);
  for(int i=0;i<n;i++) {
    cin >> ab[i].first >> ab[i].second;
  }

  sort(ab.begin(), ab.end(), custom);

  long long int total = 0;
  int ans = 0;

  for(int i=0;i<n;i++) {
    total += ab[i].second;
    if(total >= k) {
      ans = ab[i].first;
      break;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<algorithm>

using namespace std;

int main(){

  int n, t;
  int a[100000];
  int is_pushed[100000] = {};
  scanf("%d", &n);
  for(int i = 0; i < n; i++){
    scanf("%d", &t);
    a[i] = t - 1;
  }

  int button = 0, count = 0;
  while(button != 1){
    is_pushed[button] = 1;
    if(is_pushed[a[button]]){
      printf("-1\n");
      return 0;
    }
    button = a[button];
    count++;
  }

  printf("%d\n", count);

  return 0;
}


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

using namespace std;

int main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    for(int i=0; i<s.size(); i++)
    {
        char c=s[i];
        c+=(char)n;
        if(c>'Z')
        {
            int t=n-26;
            c=s[i]+char(t);
        }
        cout<<c;
    }
    return 0;
}


Measured memory_bytes: 256
N = int(input())
x = N % 10
#xはNを10で割ったあまり

if x == 2 or x == 4 or x == 5 or x == 7 or x == 9:
    k = 'hon'
elif x == 0 or x == 1 or x == 6 or x == 8:
    k = 'pon'
else:
    k = 'bon'

print(k)


Measured memory_bytes: 9004
#include <iostream>

int main() {
        // This seems trivial so I probably understood the problem statement wrong...
        int a, b, c, d, p;
        std::cin >> a >> b >> c >> d >> p;
        int px = a * p;
        int py = b;
        if (p > c) {
                py += (p - c) * d;
        }
        std::cout << std::min(px, py) << '\n';
}

Measured memory_bytes: 3100
a, b, c, d = map(int, input().split())
turn = 0

while a > 0 and c > 0:
    if turn == 0:
        c -= b
        turn = 1
    elif turn == 1:
        a -= d
        turn = 0
    else:
        raise RuntimeError('not supported turn')

print('Yes' if a > 0 else 'No')


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

#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define FAST_IO ios::sync_with_stdio(false)
#define CLR(arr,val) memset(arr,val,sizeof(arr))

typedef long long LL;

int main(){
    string a,b,c;
    cin>>a>>b;
    c=a+b;
    int len=c.size();
    int ans=0;
    for(int i=0;i<len;i++){
        ans=10*ans+(c[i]-'0');
    }
    int tmp=sqrt(1.0*ans);
    if(tmp*tmp==ans) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;
}


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

using namespace std;

#define REP(i,m) for(int i=0; i<m; i++)
#define FOR(i,n,m) for(int i=n; i<m; i++)
#define INF 1000000007
#define INFL (1LL << 60)
#define MOD 998244353
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define ll long long int

int main(){
	ll r, d, x;
	cin >> r >> d >> x;
	REP(i, 10){
		x = r*x-d;
		cout << x << endl;
	}
	return 0;
} 


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

typedef long long int ll;
typedef pair<ll,ll> P;

int a[112345];

int main(){
    int n;
    cin>>n;
    for(int i=0;i<=100000;i++){
        a[i]=0;
    }
    ll sum=0;
    for(int i=0;i<n;i++){
        int tt;
        cin>>tt;
        a[tt]++;
        sum+=tt;
    }
    int q;
    cin>>q;
    for(int i=0;i<q;i++){
        int b,c;
        cin>>b>>c;
        a[c]+=a[b];
        sum+=(c-b)*a[b];
        cout<<sum<<endl;
        a[b]=0;
    }
    return 0;
}


Measured memory_bytes: 4020
#include <iostream>
#include <string>
#include <stack>
#include <string.h>

using namespace std;

int main(){
  string x;
  cin >> x;
  // スタックを準備する
  stack<char> stack;
  for (int i = 0; i < x.length(); i++){
    if (x.c_str()[i] == 'T') {
      if(stack.size() != 0 && stack.top() == 'S'){
        stack.pop();
      } else {
        stack.push(x.c_str()[i]);
      }
    } else {
      stack.push(x.c_str()[i]);
    }
  }
  cout << stack.size() << endl;
}


Measured memory_bytes: 644
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

//#include <cv.h>
//#include <highgui.h>
#include <stdlib.h>
#include <time.h>

#include <string>

// 置換行列P,Qの積。ただし、p,qは対応する順列で、P[i][j] == 1 <==> p[i] = j となっている。
// N次元行列の表現に、先頭が0のN+1要素ベクトルを利用している。
std::vector<int> perm_product(std::vector<int> p, std::vector<int> q) {
    assert(p.size() == q.size());
    std::vector<int> r;
    r.resize(p.size());
    int N = p.size() - 1;
    for (int i = 1; i <= N; i++) {
        r[i] = q[p[i]];
    }
    return r;
}


const int MAX_N = 100050;
const int MAX_M = 100050;
int N, M;
long long K;
long long x[MAX_N];
int a[MAX_N];

long long ret[MAX_N];

int main(int argc, char **argv) {
    std::cin >> N;

    for (int i = 1; i <= N; i++) {
        std::cin >> x[i];
    }

    std::cin >> M >> K;

    for (int i = 1; i <= M; i++) {
        std::cin >> a[i];
    }

    std::vector<int> dist_idx, result;
    for (int i = 0; i < N; i++) {
        dist_idx.push_back(i);
        result.push_back(i);
    }

    /*
    std::cout << "check1:";
    for (int i = 1; i < N; i++) {
        std::cout << dist_idx[i] << " ";
    }
    std::cout << std::endl;
    */

    for (int i = 1; i <= M; i++) {
        std::swap(dist_idx[a[i]], dist_idx[a[i] - 1]);
    }

    /*
    std::cout << "check2:";
    for (int i = 1; i < N; i++) {
        std::cout << dist_idx[i] << " ";
    }
    std::cout << std::endl;
    */

    while (K > 0) {
        if (K & 1) {
            result = perm_product(result, dist_idx);
        }
        dist_idx = perm_product(dist_idx, dist_idx);
        K = (K >> 1);
    }

    ret[1] = x[1];
    for (int i = 2; i <= N; i++) {
        ret[i] = ret[i-1] + x[result[i-1] + 1] - x[result[i-1]];
    }


    for (int i = 1; i <= N; i++) {
        std::cout << ret[i] << std::endl;
    }
    
    return 0;
}


Measured memory_bytes: 5196
#include <stdio.h>


#define N 100000


int CC[N] = {0};

void init() {
  int i;
   for (i = 0; i < N; ++i) {
    CC[i] = i;
   }
}

int find(int a) {
   if (a == CC[a]) {
   return a;
  }

  return CC[a] = find(CC[a]);
}

int isSame(int a, int b) {

   if (find(a) == find(b)) {
    return 1;
   } else {
    return 0;
  }
}

void unite(int a, int b) {
  a = find(a);
  b = find(b);

  if (a == b) return;

  CC[b] = a;
}

int main() {
  int n, m, q, i, j, k;
  init();
  scanf("%d %d", &n, &m);

  for (i = 0; i < m; ++i) {
    scanf("%d %d", &j, &k);
    unite(j, k);
  }

  scanf("%d", &q);

  for (i = 0; i < q; i++) {
    scanf("%d %d", &j, &k);
     if (isSame(j, k)) {
      printf("yes\n");
     } else {
      printf("no\n");
     }

  }

  return 0;
}

Measured memory_bytes: 2108
#include <iostream>
#include <algorithm>
#include <array>
#include <limits>
#include <cmath>
#include <map>
#include <iomanip>
#include <queue>
#include <functional>

using namespace std;
using ll = long long;
using db = double;
using pll = pair<ll, ll>;
map<pll, ll> m;
array<ll, 10> arr;

int main() {
    ios::sync_with_stdio(false);
    ll h, w, n, a, b;
    arr.fill(0);
    cin >> h >> w >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a >> b;
        for (int x = 0; x < 3; ++x) {
            for (int y = 0; y < 3; ++y) {
                if (a - x >= 1 && b - y >= 1 && a - x + 2 <= h && b - y + 2 <= w)
                    ++m[make_pair(a - x, b - y)];
            }
        }
    }
    for (auto i:m) {
        ++arr[i.second];
    }
    arr[0] = static_cast<ll>((h - 2) * (w - 2) - m.size());
    for (auto i:arr) {
        cout << i << endl;
    }
}

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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<int,int>
#define V vector<int>
#define M map<int,int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int,V,greater<int>>

#define pb(a) push_back(a)
#define mp make_pair

#define dump(x)  cout << #x << " = " << (x) << "\n";
#define COUT(x) cout<<(x)<<"\n"

int main()
{
    int a = 0;
    cin >> a;
    COUT(180 * (a - 2));

    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (h, w, m) = readIntList()

    val hc = IntArray(h)
    val wc = IntArray(w)

    val tar = mutableSetOf<Pair<Int, Int>>()
    repeat(m) {
        val (hh, ww) = readIntList().map { it - 1 }
        tar.add(hh to ww)
        hc[hh]++
        wc[ww]++
    }

    val hMax = hc.max()!!
    val wMax = wc.max()!!

    val lsH = hc.withIndex().filter { it.value == hMax }.map { it.index }
    val lsW = wc.withIndex().filter { it.value == wMax }.map { it.index }

    val ans = hMax + wMax
    lsH.forEach { i ->
        lsW.forEach { j ->
            if (!tar.contains(i to j)) {
                println(ans)
                return
            }
        }
    }
    println(ans - 1)
}

// read
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

Measured memory_bytes: 112924
#include<bits/stdc++.h>
#include<string.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pl;
#define all(a) (a).begin(),(a).end()
#define overload4(_1, _2, _3, _4, name, ...) name
#define rep1(n) for(ll i = 0;i < (n);i++)
#define rep2(i,n) for(ll i = 0;i < (n);i++)
#define rep3(i,a,b) for(ll i = (a);i < (b);i++)
#define rep4(i,a,b,c) for(ll i = (a);i < (b);i += (c))
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep1(n) for(ll i = (n)-1;i >= 0;i--)
#define rrep2(i,n) for(ll i = (n)-1;i >= 0;i--)
#define rrep3(i,a,b) for(ll i = (a)-1;i >= (b);i--)
#define rrep4(i,a,b,c) for(ll i = (a)-1;i >= (b);i -= (c))
#define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define SHOW(x) cout << #x << ": " << x << endl;
template<class T> ll sumArr(const T& a){ return accumulate(all(a), 0LL);}
template<class T> auto minArr(const T& a){ return *min_element(all(a));}
template<class T> auto maxArr(const T& a){ return *max_element(all(a));}
template<class T> void DEBUG_PRINT(T tmp){cout<<tmp<<endl;}
template<class T1,class... T2> void DEBUG_PRINT(T1 tmp,T2... tmp2){cout<<tmp<<" ";DEBUG_PRINT(tmp2...);}
ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
const ll INF=1e18,MOD = 1e9+7;
const int iINF = 1e9;

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

    string s,t;
    cin>>s>>t;
    int ans = 0;
    rep(i,s.size()) if(s[i] != t[i])ans++;
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 3824
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (ll i = m; i < n; ++i)
#define FORR(i, m, n) for (ll i = m; i >= n; --i)
#define ALL(v) (v).begin(),(v).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; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,a,b,c,d,e;cin >> n >> a >> b >> c >> d >> e;
    ll m=min({a,b,c,d,e});
    cout << 4+(n+m-1)/m << endl;
}

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

int main() {
  string s;
  cin >> s;
  for (int i = 0; i <= s.size(); i++) {
    if (s[i] == 'A' && s[i + 1] == 'C') {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;

/*

*/

int main(void){
	ll n,k,l,t1[200010]={},t2[200010]={};
	vector<ll> v1[200010],v2[200010];
	map<mp,ll> M;
	cin>>n>>k>>l;
	rep(i,k){
		ll p,q;
		cin>>p>>q;
		v1[p].push_back(q);
		v1[q].push_back(p);
	}
	rep(i,l){
		ll p,q;
		cin>>p>>q;
		v2[p].push_back(q);
		v2[q].push_back(p);
	}
	reg(i,1,n){
		if(t1[i]==0){
			t1[i]=i;
			queue<ll> Q;
			Q.push(i);
			while(!Q.empty()){
				ll p=Q.front();Q.pop();
				rep(j,v1[p].size()){
					ll q=v1[p][j];
					if(t1[q]==0){
						t1[q]=i;
						Q.push(q);
					}
				}
			}
		}
	}
	reg(i,1,n){
		if(t2[i]==0){
			t2[i]=i;
			queue<ll> Q;
			Q.push(i);
			while(!Q.empty()){
				ll p=Q.front();Q.pop();
				rep(j,v2[p].size()){
					ll q=v2[p][j];
					if(t2[q]==0){
						t2[q]=i;
						Q.push(q);
					}
				}
			}
		}
	}
	reg(i,1,n){
		M[make_pair(t1[i],t2[i])]++;
	}
	reg(i,1,n){
		printf("%lld ",M[make_pair(t1[i],t2[i])]);
	}
	return 0;
}

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

using namespace std;

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

  long N,M; cin>>N>>M;
  vector<int> A(N);
  for (auto& a : A) cin>>a;
  sort(A.begin(), A.end(), [](auto l, auto r) {return l > r;});

  vector<int> cnt(2e5+1, 0);
  for (auto a : A) cnt[a]++;
  for (int i = cnt.size()-2; i >= 0; i--) {
    cnt[i] += cnt[i+1];
  }
  auto count_pairs = [&](int hold) {
    long res = 0;
    for (int i = 0; i < N; i++) {
      if (hold - A[i] < 0)
        res += N;
      else
        res += cnt[hold - A[i]];
    }
    return res;
  };

  int l = 0, r = A[0]*2;
  int x = l;
  while (l <= r) {
    auto c = (l+r)/2;
    if (count_pairs(c) >= M) {
      x = c;
      l = c+1;
    } else {
      r = c-1;
    }
  }

  vector<long> CA(N+1);
  for (int i = 1; i <= N; i++) {
    CA[i] = CA[i-1]+A[i-1];
  }

  long ans = 0;
  for (int i = 0; i < N; i++) {
    auto num = x-A[i] >= 0 ? cnt[x-A[i]] : N;
    ans += long(A[i])*num + CA[num];
  }

  auto members = count_pairs(x);
  if (members > M)
    ans -= (long)x*(members-M);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a[10],k,flg=0;
  cin>>a[0]>>a[1]>>a[2]>>a[3]>>a[4]>>k;
  for(int i=0; i<4; i++){
    for(int j=i+1; j<5; j++){
      if(abs(a[i]-a[j])>k){
	flg=1;
      }
    }
  }
  if(flg==0){
    cout<<"Yay!"<<'\n';
  }else{
    cout<<":("<<'\n';
  }
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
class ProgramD
    {
        static void Main(string[] args)
        {
            
            //入力
            string input = Console.ReadLine();
            long h = long.Parse(input);
            int count = 0;
            long sum = 1;
            
            while(h != 1)
            {
                h /= 2;
                count++;
            }

            for(int i = 0;i < count;i++)
                sum = sum * 2 + 1;

            Console.WriteLine(sum);
        } 
    }  

Measured memory_bytes: 11092
#include<cstdio>
#include<cstring>
#include<queue>
#include<cmath>
using namespace std;
char s[100001];
int main()
{
    scanf("%s",s);
    int len=strlen(s);
    if(s[0]==s[len-1])
    {
        if(len%2==1)
    printf("Second");
        else
    printf("First");
    }
    else
    {
        if(len%2==1)
    printf("First");
        else
    printf("Second");
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<set>
#include<bitset>
#include<iomanip>
#define BUG puts("no bug")
#define sci(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define ll long long
#define ull unsigned long long
#define REP(a,b,c) for(ll a=b;a<=c;a++)
#define PER(a,b,c) for(ll a=b;a>=c;a--)
#define lb(a) (a&(-a))
#define pp (p<<1)
#define ppp (p<<1|1)
#define pi pair<ll,ll>
#define pii pair<pair<ll,ll>,ll>
using namespace std;
const ll MAXN=1e6+5;
ll n,m,t;
ll mod=1e9+7;
ll qk(ll x,ll n){
    ll ans=1;
    while(n){
        if(n&1)ans=ans*x%mod;
        x=x*x%mod;
        n>>=1;
    }
    return ans;
}
ll sum[MAXN];
int main(){
    cin>>n>>m;
    ll ans=0;
    REP(i,1,m){
        sum[i]=qk(m/i,n)%mod;
    }
    PER(i,m,1){
        for(ll j=i*2;j<=m;j+=i){
            sum[i]=(sum[i]-sum[j]+mod)%mod;
        }
    }
    REP(i,1,m)ans=(ans+i*sum[i]%mod)%mod;
    cout<<ans;
}

Measured memory_bytes: 3940
//2020.1.26
//s1270188 xxxmk2
//alds1_11d

#include<stdio.h>
#include<stdlib.h>
#define N 100001

//struct
struct node{
  int id;
  struct node* next;
};

//global
struct node data[N];
int num, color[N];

//prototype
void insert(int,int);
void dfs(int,int);

int main(){
  int i, j, a, b;
  //input
  scanf("%d",&num);
  for(i=0;i<num;i++)  data[i].next=NULL;

  scanf("%d",&j);
  for(i=0;i<j;i++) {
    scanf("%d %d",&a,&b);
    insert(a,b);
    insert(b,a);
  }

  /*
  struct node *n;
  for(i=0;i<=num;i++){
    printf("%2d:",i);
    for(n=data[i].next;n!=NULL;n=n->next) printf(" %d",n->id);
    printf("\n");
  }
  */

  //dfs
  for(i=0;i<num;i++) color[i]=-1;
  j=1;
  for(i=0;i<num;i++)
    if(color[i]==-1) dfs(i,j++);
  
  //question
  scanf("%d",&j);
  for(i=0;i<j;i++){
    scanf("%d %d",&a,&b);
    if(color[a]==color[b]) printf("yes\n");
    else printf("no\n");
  }
  
  return 0;
}


void insert(int a, int b){
  struct node *n, *tmp;

  n=malloc(sizeof(struct node));
  n->id=b;
  n->next=NULL;

  for(tmp=&data[a];tmp->next!=NULL;tmp=tmp->next);
  tmp->next=n;
}


void dfs(int u, int c){
  struct node *n;
  
  color[u]=c;
  for(n=data[u].next;n!=NULL;n=n->next){
    if(color[n->id]==-1) dfs(n->id,c);
  }
}



Measured memory_bytes: 13056
#include<cstdio>
#include<algorithm>
#include<functional>
using namespace std;
int flg[1000000];
int main(void)
{
	int n,i,cnt1,cnt2,a;
	char s[200001];
	scanf("%d",&n);
	scanf("%s",s);
	cnt1=0;
	for(i=0;i<n;i++)	{
		if(s[i]=='R')	cnt1++;
	}
	cnt2=0;
	for(i=0;i<cnt1;i++)	{
		if(s[i]=='R')	cnt2++;
	}
	a=cnt1-cnt2;
	printf("%d\n",a);
	return 0;
}

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

int main(void){
  int a,b;
  cin >> a >> b;
  if(a == 1) a =14;
  if(b == 1) b =14;
  if(a>b){
    cout << "Alice" << endl;
  }else if(a<b){
    cout << "Bob" << endl;
  }else{
    cout << "Draw" << endl;
  }return 0;
}



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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

const int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
const int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
struct UnionFind {
	vector<int> par;
	vector<int> sizes;

	UnionFind(int n) {
		par.resize(n);
		sizes.resize(n);
		REP(i, n) {
			par[i] = i;
			sizes[i] = 1;
		}
	}

	int root(int a) {
		return par[a] == a ? a : par[a] = root(par[a]);
	}

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

	void unite(int x, int y) {
		x = root(x);
		y = root(y);
		if (x == y)return;
		if (sizes[x] < sizes[y]) swap(x, y);

		par[y] = x;
		sizes[x] += sizes[y];
	}
	int size(int x) {
		return sizes[root(x)];
	}
};

using pq = priority_queue < ll, vl, less<ll>>;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vl a(n);
	REP(i, n)cin >> a[i];
	map<int, vl> mp;
	UnionFind uf(n);
	REP(i, m) {
		int x, y;
		cin >> x >> y;
		
		uf.unite(x, y);
	}
	REP(i, n) {
		mp[uf.root(i)].push_back(a[i]);
	}
	ll ans = 0;
	vl tmp;
	for (auto b : mp) {
		sort(ALL(b.second), greater<int>());
		ans += b.second.back();
		b.second.pop_back();
		REP(i, b.second.size()) {
			tmp.push_back(b.second[i]);
		}
	}
	if (2 * (mp.size() - 1) > n) {
		cout << "Impossible" << endl;
		return 0;
	}
	sort(ALL(tmp));
	if (m == n - 1)cout << 0 << endl;
	else {
		REP(i, mp.size() - 2) {
			ans += tmp[i];
		}
		cout << ans << endl;
	}

	
	
	

}


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

int main(void){
    int n, k;
    cin >> n >> k;

    ll h[n];
    rep(i, n){
        cin >> h[i];
    }

    sort(h, h + n);

    ll diff = 10000000000;
    rep(i, n){
        if(i + k - 1 == n)
            break;
        diff = min(h[i + k - 1] - h[i], diff);
    }

    cout << diff << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
int main(){
    int n;
    scanf("%d",&n);
    double ans=0;
    for(int i=0;i<n;i++){
        double x;
        char u[4];
        scanf("%lf%s",&x,u);
        if(u[0]=='J')ans+=x;
        else ans+=380000*x;
    }
    printf("%lf\n",ans);
    return 0;
}

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

public class Hello
{
    private const int MOD_N = 1000000000 + 7;

    public static void Main()
    {
        var list1 = Console.ReadLine().Split(' ');
        var n = int.Parse(list1[0]);
        var x = int.Parse(list1[1]);

        var list2 = Console.ReadLine().Split(' ');
        var ls = new int[n];
        for (int i = 0; i < ls.Length; ++i)
        {
            ls[i] = int.Parse(list2[i]);
        }

        int ans = 1;
        int d = 0;

        for (int i = 0; i < ls.Length; ++i)
        {
            d += ls[i];
            if (d > x)
                break;
            ++ans;
        }

        Console.WriteLine(ans);
    }

    private static int Comb(int m, int n)
    {
        var t = m - n;
        if (n > t)
            n = t;

        long numerator = 1;
        for (int i = 0; i < n; ++i)
        {
            numerator *= m - i;
            numerator %= MOD_N;
        }
        long denominator = 1;
        for (; n != 0; --n)
        {
            denominator *= n;
            denominator %= MOD_N;
        }

        var inv_denominator = ModInv((int)denominator, MOD_N);
        var ret = (int)(numerator * inv_denominator % MOD_N);

        return ret >= 0 ? ret : ret + MOD_N;
    }

    private static int ModInv(int a, int m)
    {
        int b = m, x = 1, y = 0;
        while (b != 0)
        {
            var t = a / b;
            a -= t * b;
            Swap(ref a, ref b);
            x -= t * y;
            Swap(ref x, ref y);
        }
        x %= m;
        return x >= 0 ? x : x + m;
    }

    private static void Swap<T>(ref T a, ref T b)
    {
        var t = a;
        a = b;
        b = t;
    }
}


Measured memory_bytes: 11092
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		int dx[]={1,0,-1,0};
		int dy[]={0,1,0,-1};
		for(;;)
		{
			int W=in.nextInt();
			int H=in.nextInt();
			if((H|W)==0)
				return;
			int sh=0,sw=0;
			int cost[][]=new int[H][W];
			char map[][]=new char[H][W];
			LinkedList<String>que=new LinkedList<String>();
			for(int i=0;i<H;i++)
				Arrays.fill(cost[i], 100);
			for(int i=0;i<H;i++)
			{
				String st=in.next();
				for(int j=0;j<W;j++)
				{
					map[i][j]=st.charAt(j);
					if(map[i][j]=='&')
					{
						sh=i;
						sw=j;
					}
				}
			}
			cost[sh][sw]=0;
			que.add(sh+" "+sw);
			while(!que.isEmpty())
			{
				int size=que.size();
				for(int i=0;i<size;i++)
				{
					String now[]=que.poll().split(" ");
					int nh=Integer.valueOf(now[0]);
					int nw=Integer.valueOf(now[1]);
					for(int j=0;j<4;j++)
					{
						int h=dy[j]+nh;
						int w=dx[j]+nw;
						if(h>=0&&h<H&&w>=0&&w<W)
						{
							if((map[nh][nw]=='#'||map[h][w]=='.')&&cost[nh][nw]<cost[h][w])
							{
								cost[h][w]=cost[nh][nw];
										que.add(h+" "+w);
							}
							else if(map[nh][nw]!='#'&&map[h][w]=='#'&&cost[nh][nw]+1<cost[h][w])
							{
								cost[h][w]=cost[nh][nw]+1;
								que.add(h+" "+w);
							}
						}
					}
				}
			}
			int ans=100;
			for(int i=0;i<H;i++)
			{
				for(int j=0;j<W;j++)
				{
					if(i<1||i>H-2||j<1||j>W-2)
						ans=Math.min(ans, cost[i][j]);
				}
			}
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 13000
use std::io::stdin;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().ok().unwrap()
}

fn read_2taple<T: FromStr>() -> (T, T) {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let mut iter = buf
        .trim()
        .split_whitespace()
        .map(|x| x.parse().ok().unwrap());
    (iter.next().unwrap(), iter.next().unwrap())
}

fn main() {
    let (n, _l) = read_2taple::<usize>();
    let mut s: Vec<String> = (0..n).map(|_| read::<String>()).collect();
    s.sort();
    let ans = s.iter().fold(String::from(""), |ans, s| ans + s);
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = s.size();
    string ans = "";
    for(int i = 0; i < n; i++) {
        ans += "x";
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
 
int main() {
  int n, k;
  string s, targ;
  cin >> n;
  cin >> s;
  cin >> k;
  targ = s[k - 1];
  for (int i = 0; i < n; i++){
    if (s[i] != targ[0]) s[i] = '*';
  }
  cout << s << endl;
}

Measured memory_bytes: 256
n = int(input())
s = {}

for i in range(n):
  tmp = ''.join(sorted(input()))
  if tmp in s:
    s[tmp] += 1
  else:
    s[tmp] = 1

ans = 0
for i in s.values():
  if i >= 2:
    ans += i*(i-1)/2
print(int(ans))

Measured memory_bytes: 22216
#include <iostream>
typedef long long ll; 

using namespace std; 

int main() {
	int i;
	int set[5];
	for(i = 0; i < 5; i++) {
		cin >> set[i];
		if(set[i] == 0) {
			cout << i + 1 << endl;
		}
	}
	
	return 0;
}


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define hash dhsjakhd
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef long double ld;

ll n,m,T,k,d;
const ll big = 1000000007;

vi A;
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("autput.txt","w",stdout);
    int a,b,c,e;
    cin >> n;
    ll sum = 0;
    for(int c1 = 0; c1 < n; c1++){
        cin >> a;
        sum += a;
        A.push_back(a);
    }
    int mi = big;
    int ans = 0;
    for(int c1 = 0;c1 < n; c1++){
        a = abs(n*A[c1]-sum);
        if(a < mi){
            mi = a;
            ans = c1;
        }
    }
    cout << ans << "\n";
    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll n;
  cin>>n;
  vll a(n);
  REP(i,n)cin>>a[i];

  vll rem(n+1);
  REP(i,n)rem[i+1]=rem[i]+a[i];

  ll ans=0;
  REP(i,n){
    ll l=a[i];
    ll r=(rem[n]-rem[i+1])%MOD;
    ans=(ans+l*r%MOD)%MOD;
  }

  cout<<ans<<endl;


}



Measured memory_bytes: 6364
import java.util.Scanner;

class Main{
	public static void main(String args[]){
	Scanner scan = new Scanner(System.in);
	int i,div = 0;
	int a = scan.nextInt();
	int b = scan.nextInt();
	int c = scan.nextInt();
	for(i = a;i <= b;i++){
		if(c % i == 0){
			div++;
		}
	}
	System.out.println(div);
	}
	
}

Measured memory_bytes: 26176
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <cassert>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int cnt[100005],n,m;
set<int>S;
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) cnt[i] = 1;
	S.insert(1);
	for(int i=0;i<m;i++){
		int a,b; scanf("%d%d",&a,&b);
		if(S.find(a) == S.end()){
			cnt[a]--; cnt[b]++; continue;
		}
		else{
			if(cnt[a] == 1) S.erase(S.find(a));
			S.insert(b);
			cnt[a]--; cnt[b]++;
		}
	}
	cout << S.size() << endl;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
#define gcd(m,n) __gcd(m,n)
#define lcm(m,n) m*(n/gcd(m,n))
#define fast std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pi acos(-1.0)
#define endl '\n'
#define MOD 1000000007
#define ull unsigned long long
#define ll long long
#define ld long double
#define pb push_back
#define dbg(x) cout << #x << "  " << x << endl;
 
ll power(ll base, ll exp) 
{ll res=1;while(exp>0) {if(exp%2==1) res=(res*base);base=(base*base);exp/=2;}return res;}
ll mod(ll a, ll b) {return (a % b + b) % b;}
using namespace std;
 

int main() 
{
	fast;
	ull K;  cin>>K;
	queue<ull>q; 
	ull temp = K-1;
	for(ull i = 1; i <= 9; i++) q.push(i);
	while(temp--)
	{
		ull t = q.front(); q.pop();
		ull tt = t % 10;
		if(tt != 0) q.push(10*t + (tt) - 1);
		q.push( 10*t + (tt) );
		if(tt != 9 ) q.push(10*t + (tt) + 1);
	}
	cout << q.front() << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <math.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define PI acos(-1)
typedef long long int ll;
typedef long double ld;

int main(void) {
  int   scan;

  ll    answer;
  ll    d;
  ll    t; 
  ll    s; 
  answer = 0;
  scan = scanf("%lld", &d);
  scan = scanf("%lld", &t);
  scan = scanf("%lld", &s);

  if (d > t * s) {
    printf("No");
    return (0);
  } else {
    printf("Yes");
    return (0);
  }

  return (0);
}



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

int main(){
  int x,y;
  cin>>x>>y;
  
  set<int> A={1,3,5,7,8,10,12},B={3,6,9,11},C={2};
  
  if((A.count(x)&&A.count(y))||(B.count(x)&&B.count(y))||(C.count(x)&&C.count(y))){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256