akhauriyash/Code-Regression huggingface dataset:
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

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

static const int INF=1000000000;

int n;
int d[100010],r[100010];
vector<vector<int>> vec(100010);

void bfs(int s){
  queue<int> q;
  q.push(s);
  rep(i,n+1) d[i]=INF;
  d[s]=0;
  int u;
  while(!q.empty()){
    u=q.front(); q.pop();
    rep(v,vec[u].size()){
      int x=vec[u][v];
      if(d[x]==INF){
        d[x]=u;
        q.push(x);
      }
    }
  }
}
      
  


int main(){
  int m,x,y;
  cin>>n>>m;
  
  rep(i,m){
    cin>>x>>y;
    vec[x].push_back(y);
    vec[y].push_back(x);
  }
  

  bfs(1);
  cout<<"Yes"<<endl;
  for(int i=2;i<=n;i++) cout<<d[i]<<endl;

  return 0;
}

Measured memory_bytes: 13360
input()
A = [int(v) for v in input().split(" ")]

def swap(A, i, j):
    t = A[i]
    A[i] = A[j]
    A[j] = t

swap_count = 0
for i in range(0, len(A) - 1):
    minJ = i
    for j in range(i, len(A)):
        if A[j] < A[minJ]:
            minJ = j

    if i != minJ:
        swap(A, i, minJ)
        swap_count += 1

print(" ".join([str(v) for v in A]))
print(swap_count)


Measured memory_bytes: 5604
#include<bits/stdc++.h>
using namespace std;
int main() {
  for (int i = 0; i < 3; i++) {
    string s;
    cin >> s;
    cout << string(1, (s[0] > 'Z' ? s[0] - ' ' : s[0]));
  }
  cout << endl;
}


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

const int mod = 998244353;
long long int mypow(long long int a, long long int b) {
    if (b == 0) return 1;
    if (b == 1) return a;
    long long int res = mypow(a, b / 2);
    res = res * res % mod;
    if (b % 2 == 1) res = res * a % mod;
    return res;
}

int main() {
    int n;
    cin >> n;
    vector<int> v;
    for (int i = 0; i < n; i++) {
        int t;
        cin >> t;
        v.push_back(t);
    }
    int s = accumulate(v.begin(), v.end(), 0);

    unordered_map<int, long long int> um1, um2, um3, um4;
    // [sum] = count
    um1[0] = 1;
    um3[0] = 1;
    for (int i = 0; i < n; i++) {
        um2 = um1;
        um4 = um3;
        for (auto it = um2.begin(); it != um2.end(); it++) {
            it->second *= 2;
            it->second %= mod;
        }
        for (auto it = um1.begin(); it != um1.end(); it++) {
            um2[it->first + v[i]] += it->second;
            um2[it->first + v[i]] %= mod;
            um4[it->first + v[i]] += um3[it->first];
            um4[it->first + v[i]] %= mod;
        }
        um1 = um2;
        um3 = um4;
    }

    long long int res = mypow(3, n);
    for (auto p : um1) {
        if (p.first * 2 >= s) {
            res -= p.second * 3 % mod;
            res %= mod;
        }
        if (p.first * 2 == s) {
            // res += p.second;
            res += um3[p.first] * 3;
            res %= mod;
        }
    }
    res += mod;
    res %= mod;
    cout << res << endl;
}


Measured memory_bytes: 14596
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

int n, a, b;

int main() {

	cin >> n >> a >> b;
	cout << min(a * n , b) << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define repr(i,n) for(int i=(n-1);i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;

int main() {

    string s;

    cin >> s ;

    if(s == "Sunny" ){
        cout << "Cloudy" << endl;
    }else if(s == "Cloudy"){
        cout << "Rainy" << endl;
    }else if(s == "Rainy"){
        cout << "Sunny" << endl;
    }



}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define rep(i,n) for(int i = 0;  i < n ; ++i)
#define REP(i,a,b) for(int i = a ; i <= b ; ++i)
#define s(n) scanf("%d",&n)
#define rev(i,n) for(int i = n ; i >= 0 ; --i)
#define REV(i,a,b) for(int i = a ; i >= b ; --i)
#define miN(a,b) (((a)<(b))?(a):(b))
#define sc(n) scanf("%c",&n)
#define tr(c,i) for(typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define INF 1000000000
#define pii pair<long long int,long long int>
#define pb(a) push_back(a)
typedef long long ll;
using namespace std;
void pre(){}
void solve(){
    ll n,d;cin>>n;
    map<ll,ll>m;
    ll arr[n];
    for(int i=0;i<n;i++){
        cin>>d;
        m[d+i]++;
        arr[i]=i-d;
    }
    ll ans = 0;
    for(int i=0;i<n;i++){
        ans+=m[arr[i]];
    }
    cout<<ans<<"\n";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    pre();
    long long int num = 1;
    //cin>>num;
    for(long long int i=0;i<num;i++){
        //cout<<"Case #"<<i+1<<" :";
       	solve();
    }   
}




Measured memory_bytes: 27884
#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"a,b=map(int,input().split());print('NPeogsaittiivvee'[a>0 or(b-a)%2::2]*(a*b>0)or'Zero')\n"
"\"";
  system(s);
  return 0;
}            

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

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		HashSet<char> ng = new HashSet<char>();
		for(int i=0;i<D.Length;i++){
			ng.Add((char)('0' + D[i]));
		}
		for(int i = N;i<99999;i++){
			String s = i.ToString();
			bool chk = true;
			foreach(var c in s){
				if(ng.Contains(c)){
					chk = false;
					break;
				}
			}
			if(chk){
				Console.WriteLine(i);
				return;
			}
		}
		
		
		
		
		
	}
	int N,K;
	int[] D;
	public Sol(){
		var d = ria();
		N = d[0]; K = d[1];
		D = ria();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 5464
import sys
def input(): return sys.stdin.readline().rstrip()
from itertools import accumulate
def main():
    n, m, k = map(int,input().split())
    A = [0] + list(map(int,input().split()))
    B = [0] + list(map(int,input().split()))
    A = list(accumulate(A))
    B = list(accumulate(B))
    ans = 0
    j = m
    for i in range(n + 1):
        if A[i] > k:
            break
        while A[i] + B[j] > k:
            j -= 1
        ans = max(ans, i + j)
    print(ans)


if __name__=='__main__':
    main()

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

int main(){
    char a;
    cin>>a;
    if(a=='A'){
        cout<<'T';
    }
    else if(a=='C'){
        cout<<'G';
    }
    else if(a=='G'){
        cout<<'C';
    }
    else{
        cout<<'A';
    }

    return 0;
}

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

bool DEBUG = false;

int main(int argc, char** argv, char** envp) {
    if(argc == 2 && strcmp(argv[1], "--debug") == 0) {
        DEBUG = true;
    }
    int N;
    scanf("%d", &N);
    vector<int> L, R;
    L.resize(N);
    R.resize(N);
    for(int i = 0; i < N; i++) {
        scanf("%d %d", &L[i], &R[i]);
    }
    sort(L.begin(), L.end()); reverse(L.begin(), L.end());
    sort(R.begin(), R.end());
    long long has = 0, tmp;
    tmp = 0;
    for(int i = 0; i < N; i++) {
        tmp -= (long long)R[i]; has = max(has, tmp);
        tmp += (long long)L[i]; has = max(has, tmp);
    }
    tmp = 0;
    for(int i = 0; i < N; i++) {
        tmp += (long long)L[i]; has = max(has, tmp);
        tmp -= (long long)R[i]; has = max(has, tmp);
    }
    printf("%lld\n", has*2);
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
  public static void main(String[] args){
    Scanner r=new Scanner(System.in);
    int t = r.nextInt();
    for (int i = 1;i <= t ;i++ ) {
      int s = i;
      if (s%3==0||s%10==3||s/10==3) {
        System.out.print(" "+i);
      }else{
        while(s!=0){
          s/=10;
          if (s%10==3) {
            System.out.print(" "+i);
            break;
          }
        }
      }
    }
    System.out.println("");
  }
}

Measured memory_bytes: 28484
#include<iostream>
using namespace std;
int main(){
	int m,f,r;
	char s;
	while(1){
	cin>>m>>f>>r;
	if(m==-1&&f==-1&&r==-1)break;
	if(m==-1||f==-1)s='F';
	else if(m+f>=80)s='A';
	else if(m+f>=65)s='B';
	else if(m+f>=50||m+f>=30&&r>=50)s='C';
	else if(m+f>=30)s='D';
	else s='F';
	cout<<s<<endl;
	}
 return 0;
}



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


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

int chineseletter= n%10;


if( chineseletter == 2 || chineseletter == 4 || chineseletter == 5 || chineseletter == 7 || chineseletter ==9)
{
  cout << "hon";
}
else if (chineseletter == 0 || chineseletter == 1 || chineseletter == 6 || chineseletter == 8)
{
  cout << "pon";
}
else if(chineseletter == 3)
{
  cout << "bon";
}

return 0;






}


Measured memory_bytes: 3600
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

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

    for (int i = 3; i<=n; i++){
        if ((i % 3==0) or (i % 10==3))
        {
            cout << " "<<i;
            continue;
        }
        int x = i / 10;
        while(x){
            if (x % 10==3)
            {
                cout << " "<<i;
                break;
            }
            x /=10;
        }
    }
    cout << endl;

}


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

int main(){
  int N,M;
  cin>>N>>M;
  const int n=N;
  vector<int> v(n);
  for(int i=1;i<=N;i++){
    v.at(i-1)=i;
  }
  int d[9][9]={0};
  for(int i=0;i<M;i++){
    int a,b;
    cin>>a>>b;
    d[a][b]=1;
    d[b][a]=1;
  }
  int ans=0;
  do{
    bool check=true;
    for(int i=0;i<N-1;i++){
      if(d[v.at(i)][v.at(i+1)]==0) check=false;
    }
    if(check) ans++;
  }  while(next_permutation(v.begin(), v.end()) && v.at(0)==1);
  cout<<ans<<endl;
}

Measured memory_bytes: 3604
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();
		System.out.println(b + Math.min(a + b + 1, c));
	}
}

Measured memory_bytes: 22740
from collections import Counter
n = int(input())
V = [int(el) for el in input().split(' ')]
 
a = Counter(V[0::2]).most_common() + [(0,0)]
b = Counter(V[1::2]).most_common() + [(0,0)]

#print(a)
#print(b)
 
if a[0][0]!=b[0][0]:
    print(n-a[0][1]-b[0][1])
else:
    print(n-max(a[1][1]+b[0][1],a[0][1]+b[1][1]))

Measured memory_bytes: 20572
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template<typename T> using rev_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<class S, class T> void map_init(map<S, T> &m, S k, T v){if(!m.count(k)) m[k] = v;}
void R_YESNO(bool p) { cout << (p ? "YES" : "NO") << endl; }
void R_YesNo(bool p) { cout << (p ? "Yes" : "No") << endl; }
using P = pair<int, int>;
int main() {
    int N;
    cin >> N;
    vector<i64> a(N);
    vector<P> ans;
    for(auto &x : a) cin >> x;
    int j = -1;
    bool neg = 0;
    for(int i = 0; i < N; i++) {
        if(j < 0 || abs(a[i]) > abs(a[j])) {
            j = i;
        }
    }
    neg = a[j] < 0;
    for(int i = 0; i < N; i++) {
        if(i != j) {
            ans.push_back({j, i});
            a[i] += j;
        }
    }
    if(neg) {
        for(int i = N - 1; i > 0; i--) {
            ans.push_back({i, i - 1});
        }
    } else {
        for(int i = 0; i < N - 1; i++) {
            ans.push_back({i, i + 1});
        }
    }
    cout << ans.size() << endl;
    for(auto x : ans) {
        cout << x.first + 1 << " " << x.second + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int N; cin>>N;
    int L[N]; for (int i=0; i<N; i++) cin>>L[i];
    sort(L, L+N);
    int ans=0;
	for (int i=0; i<N; i++)
        for(int j=i+1; j<N; j++)
            for(int k=j+1; k<N; k++)
                if(L[i]!=L[j]&&L[j]!=L[k]&&L[i]+L[j]>L[k]) ans++;
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3572
#include <iostream>
#include <algorithm>
#include <stdio.h>
using namespace std;

void selectionSort(int A[], unsigned short int N);//ソート関数
void trace(int A[], unsigned short int N);//配列の要素を順番に出力

int main()
{
	unsigned short int N;
	int A[100] = {};

	cin >> N;

	for (int i = 0;i<N;i++)
	{
		scanf("%d", &A[i]);
	}
	selectionSort(A, N);

	return 0;
}

void selectionSort(int A[], unsigned short int N)
{
	int minj, v;
	int c = 0;

	for (int i = 0;i < N;i++)
	{
		minj = i;

		for (int j = i; j<N ;j++)//未整列の領域（iからn-1）から最小値検索
		{
			if (A[j] < A[minj])
			{
				minj = j;
			}
		}
		v = A[i];
		A[i] = A[minj];
		A[minj] = v;
		if (i != minj)c = c + 1;
	}
	trace(A, N);
	cout << c << endl;
}

void trace(int A[], unsigned short int N)
{
	cout << A[0];
	for (int i = 1;i < N;i++)
	{
		cout << " " << A[i];
	}
	cout << endl;
}


Measured memory_bytes: 3144
S = input()

cnt =0
for i in range(len(S)):
    if i%2==0 and S[i] in ['R','U','D']:
        cnt+=1
    elif i%2!=0 and S[i] in ['L','U','D']:
        cnt+=1
if cnt==len(S):
    print('Yes')
else:
    print('No')
        

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define watch(x) cout<<(#x)<<" is "<<(x)<<endl;
#define mod 1000000007
#define pb push_back
#define endl '\n'
#define mp make_pair


#define all(x) x.begin(),x.end()

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


	string s,t;
	cin>>s>>t;

	string x = t.substr(0,t.size()-1);

	if(x==s) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 3640
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;

int main(){
  int h,w;
  while(true){
    cin >> h >> w;
    if(h == 0 && w == 0)
      break;
    for(int i=0; i<h; i++){
      for(int j=0; j<w; j++){
        if((i+j)%2 == 0)
          cout << "#";
        else
          cout << ".";
      }
      cout << endl;
    }
    cout << endl;
  }
  return 0;
}



Measured memory_bytes: 3120
#include<iostream>
#include<string>
#include<queue>
#include<vector>
using namespace std;
const int INF=1000000000;
int main(){
	int A,B,C,D,E,F,ansa=0,anse=0;
	cin>>A>>B>>C>>D>>E>>F;
	for(int i=0;i<=30;++i){
		for(int j=0;j<=30;++j){
			if((A*i+B*j)*100>F)break;
			int G=A*i+B*j;
			int Z=min(G*E,F-G*100);
			int h=0;
			int M=0;
			while(1){
				if(D*h>Z)break;
				int N=D*h;
				N=Z-(Z-N)%C;
				M=max(M,N);
				h++;
			}
			if(M*(ansa*100+anse)>=anse*(G*100+M)){
				ansa=G;
				anse=M;
			}

		}
	}
	cout<<ansa*100+anse<<" "<<anse<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h,w,k;
  cin >> h >> w >> k;
  vector<vector<char>> c(h,vector<char>(w));
  int blc=0;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin >> c.at(i).at(j);
    }
  }
  int ans=0;
  for(int i=0;i<(1<<h);i++){
    bitset<6> sh(i);
    for(int j=0;j<(1<<w);j++){
      bitset<6> sw(j);
      int blc=0;
      for(int i2=0;i2<h;i2++){
        for(int j2=0;j2<w;j2++){
          if(!sh.test(i2)){
            if(!sw.test(j2)){
              if(c.at(i2).at(j2)=='#') blc++;
            }
          }
        }
      }
      if(blc==k) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  int n;
  cin>>n;
  int c = 0;
  for (int i=1;i<=9;i++) {
    if (n % i == 0) {
      if (n / i <= 9) c++;
    }
  }
  cout<<(c==0 ? "No":"Yes")<<endl;
}

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

int main() {
  int n, m; cin >> n >> m;
  vector<int> card(2 * n + 1, 1); for (int i = 2; i <= 2 * n; i++) card[i] += card[i - 1];
  for (int i = 0; i < m; i++) {
    int k; cin >> k;
    vector<int> new_card(2 * n + 1);
    if (k == 0) {
      int j = 1;
      for (int i = 1; i <= 2 * n; i += 2) new_card[i] = card[j], j++;
      for (int i = 2; i <= 2 * n; i += 2) new_card[i] = card[j], j++;
    } else {
      vector<int> deck1(1), deck2(1);
      for (int i = 1; i <= 2 * n; i++)
        if (i <= k) deck1.push_back(card[i]); else deck2.push_back(card[i]);
      for (int i = 1; i <= 2 * n; i++)
        if (i <= 2 * n - k) new_card[i] = deck2[i]; else new_card[i] = deck1[i - (2 * n - k)];
    }
    card = new_card;
  }
  for (int i = 1; i <= 2 * n; i++) cout << card[i] << endl;
  return 0;
}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define sz(v) (int)(v).size()
using namespace std;
using P = pair<int, int>;
typedef long long ll;
int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	string s, t;
	cin >> s >> t;
	string ans = "Yes";
	rep(i, sz(s))
	{
		if (s[i] != t[i])	ans = "No";
	}
	if (sz(s) + 1 != sz(t))	ans = "No";
	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 3616
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

typedef long long LL;
ostream &debug = cout;

/* AOJ DPL_1_B */

const int N = 105;
const int M = 10005;

int n, m, wei[N], val[N], dp[M];

signed main(void) {
	/* input */
	{
		scanf("%d%d", &n, &m);
		for (int i = 1; i <= n; i++)
			scanf("%d%d", val + i, wei + i);
	}
	/* dynamic programming */
	{
		memset(dp, 0, sizeof(dp));
		for (int i = 1; i <= n; i++)
			for (int j = m; j >= wei[i]; j--)
				dp[j] = max(dp[j], dp[j - wei[i]] + val[i]);
	}
	/* output */
	{
		int ans = 0;
		for (int i = 0; i <= m; i++)
			ans = max(ans, dp[i]);
		printf("%d\n", ans);
	}
//	system("pause");
}

Measured memory_bytes: 1236
#include <iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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

//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

ll mod_pow(ll x, ll n, ll mod) {
	ll res = 1LL;
	while (n > 0) {
		if (n & 1) res = res * x % mod;
		x = x * x % mod;
		n >>= 1;
	}
	return res;
}

ll mod_inv(ll x, ll mod) {
	return mod_pow(x, mod - 2, mod);
}

void Dijkstra(Graph& G, ll s, Array& d) {//O(|E|log|V|)
	d.resize(G.size());
	REP(i, d.size())d[i] = INF;
	d[s] = 0;
	priority_queue<P, vector<P>, greater<P>> q;
	q.push(make_pair(0, s));
	while (!q.empty()) {
		P a = q.top();
		q.pop();
		if (d[a.second] < a.first)continue;
		REP(i, G[a.second].size()) {
			Edge e = G[a.second][i];
			if (d[e.to] > d[a.second] + e.cap) {
				d[e.to] = d[a.second] + e.cap;
				q.push(make_pair(d[e.to], e.to));
			}
		}
	}
}

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

	ll h, w;
	cin >> h >> w;
	vector<string> s(h);
	REP(i, h) cin >> s[i];

	Graph g(h * w);

	REP(i, h) {
		REP(j,w) {
			if (s[i][j] == '.') {
				if (i - 1 >= 0 && s[i-1][j] == '.') add_edge(g, i * w + j, (i - 1) * w + j, 1, false, 1);
				if (i + 1 < h && s[i+1][j] == '.') add_edge(g, i * w + j, (i + 1) * w + j, 1, false, 1);
				if (j - 1 >= 0 && s[i][j-1] == '.') add_edge(g, i * w + j, i * w + j - 1, 1, false, 1);
				if (j + 1 < w && s[i][j+1] == '.') add_edge(g, i * w + j, i * w + j + 1, 1, false, 1);
			}
		}
	}


	ll ans = 0;
	REP(i, h*w) {
		Array d;
		Dijkstra(g, i, d);
		REP(j, h*w) {
			if (i != j && d[j] != INF) chmax(ans, d[j]);
		}
	}

	cout << ans << endl;

	return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;

const int inf = 1e9;
const ll linf = 1e18;
const ll mod = 1e9 + 7;

const int MAXN = 2e+5;

int n, k, l;
int par[2][MAXN];

int find(int z, int x)
{
  if(x == par[z][x]) return x;
  return par[z][x] = find(z, par[z][x]);
}

void unite(int z, int x, int y)
{
  x = find(z, x);
  y = find(z, y);
  par[z][x] = y;
}

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

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

  rep(i, 2) rep(j, n) par[i][j] = j;

  rep(i, k){
    int p, q; 
    cin >> p >> q;
    p--; q--;
    unite(0, p, q);
  }
  rep(i, l){
    int r, s;
    cin >> r >> s;
    r--; s--;
    unite(1, r, s);
  }

  map<pii, int> cnt;
  rep(i, n) cnt[{find(0, i), find(1, i)}]++;
  rep(i, n) cout << cnt[{find(0, i), find(1, i)}] << " ";
  cout << endl;

  return 0;
}


Measured memory_bytes: 13568
#!/usr/bin/ruby
require 'mathn'
h={};2.step(36){|i|h[i]=i.prime_division}
while(l=gets)!="0 0"
	l=l.split
	n=l[0].to_i;m=l[1].to_i(n)
	if n==0 then break end
	p h[n].map{|a,b|
		z=m;r=0
		while z>0 do r+=(z=z.div a) end
		r.div b
	}.min
end

Measured memory_bytes: 3996
#!/usr/bin/env python3
import sys


def solve(A: int, B: int):
    count_plug = 0
    count_available = 1
    if B==1:
        print(0)
        return
    while True:
        count_available += A
        count_plug += 1
        count_available -= 1

        if count_available >= B:
            break
    print(count_plug)
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> anys;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
#ifdef DEBUG
#define debug(...) pr(anys{__VA_ARGS__})
#define debugv(x) pr((x))
#else
#define debug(...)
#define debugv(x)
#endif

int main(){
	int H, W;
	cin >> H >> W;
	vector<string> S(H);

	for(int i=0; i<H; i++) cin >> S[i];

	vector<vector<int>> dp(H, vector<int>(W, 1e9));

	for(int i=0; i<H; i++){
		for(int j=0; j<W; j++){
			if(i==0&&j==0){
				dp[i][j]=0;
				continue;
			}
			int dx[] = {0, 1};
			int dy[] = {1, 0};
			for(int k=0; k<2; k++){
				int px = i-dx[k];
				int py = j-dy[k];
				if(0<=px&&px<H&&0<=py&&py<W){
					dp[i][j] = min(dp[i][j], dp[px][py]+(S[i][j]==S[px][py]?0:1));
				}
			}
		}
	}

	if(S[0][0]=='.'&&S[H-1][W-1]=='.'){
		cout << dp[H-1][W-1]/2 << endl;
	} else if(S[0][0]=='#'&&S[H-1][W-1]=='#'){
		cout << dp[H-1][W-1]/2+1 << endl;
	} else {
		cout << (dp[H-1][W-1]+1)/2 << endl;
	}

	return 0;
}


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

int main() {
  string s,t;
  cin >> s >> t;
  string t_sub = t.substr(0, s.size());
  bool res = false;
  if (s == t_sub && t.size() == s.size()+1) res = true;
  if (res) {
      cout << "Yes" << endl;
  } else {
      cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3608
def cal(s):
    if s % 2 == 0:
        return int(s/2)
    else:
        return s * 3 + 1


s = int(input())
array = []
cnt = 1
array.append(s)
while True:
    s = cal(s)
    array.append(s)
    if array[cnt] in array[:cnt]:
        print(cnt +1)
        break
    cnt += 1


Measured memory_bytes: 3060
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug1: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug2: "<<x<<" "<<y<<endl;
#define bug3(x, y, z) cout<<"zdongdebug3: "<<x<<" "<<y<<" "<<z<<endl;
using namespace std;
typedef long long ll;
const int maxn = 200005;
const int mod = 998244353;

ll f[maxn];
ll p[maxn];

void gcd(ll a,ll b, ll& d,ll& x,ll& y){
  if(!b) {d=a;x=1;y=0;}
  else   {	gcd(b,a%b,d,y,x);	y-=a/b*x;}
}

ll inv(ll a,ll n)  {
  ll d,x,y;	gcd(a,n,d,x,y);
  return d==1?(x%n+n)%(n/d):-1;
}


int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  int n,m,K;
  cin>>n>>m>>K;
  f[1] = m;
  p[0] = 1;
  for(int i=1;i<=n;i++)p[i] = p[i-1] * i%mod;
  for(int i=2;i<=n;i++){
    f[i] = f[i-1]*(m-1)%mod;
  }
  ll ret = 0;
  for(int i=n-1-K;i<n;i++){
    ll tt = p[n-1]*inv(p[i]*p[n-1-i]%mod, mod)%mod;
    ret = (ret+tt*f[i+1]%mod)%mod;
  }
  cout<<ret<<endl;
  return 0;
}

Measured memory_bytes: 6708
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define dup(x,y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
inline int getInt() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MX = 200005;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
//---------------------------------------------------------------
#define fastio cin.tie(nullptr); std::ios::sync_with_stdio(false);
#define myio ifstream iofi; if(argc>1){iofi.open(argv[1]); std::cin.rdbuf(iofi.rdbuf());}
//--------------------------------------------------------------
void Main(){
  int n;
  cin>>n;
  vi h(n,0);
  cin>>h;
  int sum = accumulate(rng(h),0);
  int water=0;
  while(sum>0){
    int l=0;
    while(h[l]==0) l++;
    int r=l; int mini=h[l];
    while(h[r]>0 and r<n){
      mins(mini,h[r]);
      r++;
    }
    srep(i,l,r){
      h[i]-=mini;
    }
    sum -= (r-l)*mini;
    water+=mini;
  }
  cout<<water<<endl;
} int main(int argc,char** argv)
{fastio; myio; Main();}


Measured memory_bytes: 256
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}

console.log(main());
function main(){
  var n = o.a();
  var ans = 0;
  for(var i = 1; i <= n; i++){
    if(f(i))ans++;
  }
  return ans;
}

function f(n){
  if(n<10)return 1;
  if(n<100)return 0;
  if(n<1000)return 1;
  if(n<10000)return 0;
  if(n<100000)return 1;
  return 0;
}

Measured memory_bytes: 21192
#include <iostream>
#include <algorithm>
using namespace std;
bool rec(int xa, int ya, int xb, int yb) {
	bool ret = false;
	if (xa < 5 && xb < 5) ret = ret || !rec(min(xb + xa, 5), yb, xa, ya);
	if (xa < 5 && yb < 5) ret = ret || !rec(xb, min(yb + xa, 5), xa, ya);
	if (ya < 5 && xb < 5) ret = ret || !rec(min(xb + ya, 5), yb, xa, ya);
	if (ya < 5 && yb < 5) ret = ret || !rec(xb, min(yb + ya, 5), xa, ya);
	return ret;
}
int a, b, c, d;
int main() {
	cin >> a >> b >> c >> d;
	bool ret = rec(a, b, c, d);
	cout << (ret ? "ISONO" : "NAKAJIMA") << endl;
	return 0;
}

Measured memory_bytes: 3096
#include "bits/stdc++.h"
using namespace std;
typedef long long lint;
typedef vector<lint> LIV;
#define rep(i,n) for(int i=0;i<n;++i)
#define MAXN 100010
#define MAXM 1100000
#define all(v) v.begin(),v.end()
#define inf 2147483647
#define linf 1152921504606846976

int main(){
	lint n,ans=0;cin>>n;
	LIV a(n);rep(i,n)cin>>a[i];
	if(a[0]){cout<<"-1\n";return 0;}
	rep(i,n-1)if(a[i+1]){
		if(a[i+1]-a[i]>1){cout<<"-1\n";return 0;}
		if(a[i+1]-a[i]<1)ans+=a[i+1]-1;
		++ans;
	}cout<<ans<<endl;
}

Measured memory_bytes: 1792
// #Sazaの1日1AC
#include<bits/stdc++.h>
using namespace std;
const long long mod=1000000000+7;
const long long INF=9e15;
const double PI=3.14159265358979323846;

//マクロ
//型エイリアス
using ll = long long;
using P=pair<long long,long long>;
using vl=vector<long long>;
using vvl=vector<vector<long long>>;
using vP=vector<pair<long long, long long>>;
//ショートカット
#define rep(i,n) for(long long i = 0; i < n; i++)
#define rep2(i,k,n) for(long long i = k; i < n; i++) //半開区間
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define mkp make_pair
//入力
#define vin(v,N) for(long long id=0;id<N;id++) cin>>v.at(id)
#define lin(n) long long n;cin>>n
#define chin(x) char x;cin>>x;
#define sin(s) string s;cin>>s;
#define vlin(v,N) vector<long long>v(N);for(long long i=0;i<N;i++)cin>>v.at(i)

#define max(a,b) max((ll)a,(ll)b)
#define min(a,b) min((ll)a,(ll)b)

//関数
//最大公約数
long long gcd(long long m, long long n){
  long long a=max(m,n);
  long long b=min(m,n);
  long long r=a%b;
  while(r!=0){
    a=b; b=r; r=a%b;
  }
  return b;
}
// 最小公倍数
long long lcd(long long m, long long n){
  return m*n/gcd(m,n);
}
//xのn乗
long long power(long long x, long long N){
  long long ret=1;
  for(long long i=0;i<N;i++)   
    ret*=x;
  return ret;
}
//繰り返し二乗法
long long repeat_squaring(long long x, long long n){
  if(n==0) return 1;
  else if(n%2==0){
    long long t=repeat_squaring(x,n/2);
    return t*t%mod;
  }
  else
    return x*repeat_squaring(x,n-1);
}
//素因数分解(mapで返す)
map<long long,long long> factor(long long p){
  ll p1=p;
  map<long long,long long>ret;
  for(long long i=2;i*i<=p1;i++){
     while(p%i==0){
      ret[i]++;
      p/=i;
    }
  }
  if(p!=1)
  ret[p]++;
  return ret;
}
//素数判定
bool is_prime(long long N){
  for(long long i=2;i*i<=N;i++){
    if(N%i==0)
      return false;
  }
  return true;
}
//最大値更新
void chmax(long long &a,long long b){
  a=max(a,b);
}
//最小値更新
void chmin(long long &a,long long b){
  a=min(a,b);
}

//構造体

/////////////////⊂('ω'⊂ )))Σ≡GO!/////////////////


//メイン関数
int main(){
  //doubleの桁数
  cout<<fixed<<setprecision(10);
  
  lin(N);lin(K);
  vlin(G, N);
  rep(i, N) G[i]--;

  vector<bool> done(N, false);
  vl cnt(N);
  ll x = 1;
  ll m;
  ll u = 0;
  ll v;
  while(true){
    if(K == 0) break;
    if(done[u]){
      m = cnt[v] - cnt[u] + 1;
      break;
    }
    done[u] = true;
    cnt[u] = x;
    x++;
    v = u;
    u = G[u];
    K--;
  }

  if(K == 0) cout << u + 1 << endl;
  else{
    vl res(m);
    
    rep(i, m){
      res[i] = u;
      u = G[u];
    }
    
    cout << res[K % m] + 1 << endl;
  }
  

 //cout << m << endl;
}

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

using namespace std;
map<long long, long long> S;
void print(){
    map<long long, long long>::iterator it;
    long long ans=0;
    for(it=S.begin();it!=S.end();it++){
        pair<long long, long long> item=*it;
        ans += item.second*(item.second-1)/2;
    }
    cout << ans << endl;
}

int main(){
    long long N, sum=0;
    long long A[200000];

    S[0] = 1;
    cin >> N;
    for(int i=0;i<N;i++){
        cin >> A[i];
        sum += A[i];
        S[sum]++;
    }
    print();
    return 0;
}

Measured memory_bytes: 14336
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> card(N);
  for(int i = 0; i < N; i++){
    cin >> card[i];
  }
  sort(card.begin(), card.end());
  reverse(card.begin(), card.end());
  
  int alice = 0;
  int bob = 0;
  for (int i = 0; i < N; i++) {
    if(i % 2 == 0){
      alice += card[i];
    }else{
      bob += card[i];
    }
  }
  cout << alice - bob << endl;
  return 0;
}


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

int main(void){
  int n;cin >> n;
  vector<float> a(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  sort(a.begin(),a.end());
  for(int i=1;i<n;i++){
    a[i] = (a[i-1]+a[i])/2.0;
  }
  cout << a[n-1] << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>
#include<numeric>
using ll = long long;
using tp = std::tuple<int,int,int>;
class unionfind {
    std::vector<int> par, rank, size_;//速度ではなくメモリ効率を考えるならrankのかわりにsizeを使う
public:
    unionfind(int n) :par(n), rank(n), size_(n, 1) {
        std::iota(par.begin(),par.end(), 0);
    }
    int find(int x) {
        if (par[x] == x)return x;
        return par[x] = find(par[x]);
    }
    void unite(int x, int y) {
        x = find(x), y = find(y);
        if (x == y)return;
        if (rank[x] < rank[y])std::swap(x, y);
        par[y] = x;
        size_[x] += size_[y];
        if (rank[x] == rank[y])rank[x]++;
    }
    bool same(int x, int y) {
        return find(x) == find(y);
    }
    int size(int x) {
        return size_[find(x)];
    }
};

int main(){
    int N,M;
    std::cin >> N >> M;
    std::vector<tp>v;
    for(int i = 0; i < M; ++i){
        int x,y,z;
        std::cin >> x >> y >> z;
        v.emplace_back(x,y,z);
    }
    std::sort(v.begin(), v.end());
    std::vector<int>memo(N + 1, -1);
    int ans = 0;
    // -1 is undef, 0 is def, 1 is deciable
    auto uf = unionfind(N+1);
    for(auto tup : v){
        int x,y,z;
        std::tie(x,y,z) = tup;
        uf.unite(x,y);
    }
    for(int i = 1; i <= N; ++i){
        if(memo[uf.find(i)] == -1){
            ++ans;
            memo[uf.find(i)] = 1;
        }
    }
    std::cout << ans  << std::endl;
    
}


Measured memory_bytes: 2932
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    s = input()
    if s in ["hi","hihi","hihihi","hihihihi","hihihihihi"]:
        print("Yes")
    else:
        print("No")
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
#define _ ios::sync_with_stdio(false);cin.tie(0);
#define ll long long int
#define eb emplace_back
#define F first
#define S second

ll _max(ll a,ll b)
{
	if(a>b) return a;
	return b;
}

int main(){_
#define int long long int
	int n;
	while(cin>>n)
	{
		int a[n];
		int ans=0;
		for(int i=0;i<n;i++)
		{
			cin>>a[i];
			if(i!=0)
			{
				ans+=_max(0,a[i-1]-a[i]);
				a[i]=a[i]+_max(0,a[i-1]-a[i]);
			}
		}
		cout<<ans<<"\n";

	}

	return 0;
}

Measured memory_bytes: 5176
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

const int N = 100005;

int n, p[2 * N], vis[2 * N];
vector <int> a, b;

int find(int x){
    if(p[x] == x) return x;
    return p[x] = find(p[x]);
}
bool join(int x, int y){
    x = find(x);
    y = find(y);
    if(x == y) return 0;
    p[x] = y;
    return 1;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    for(int i = 0 ; i < 2 * N ; i++){
        p[i] = i;
    }
    cin >> n;
    a.resize(n);
    b.resize(n);
    for(auto &i : a) cin >> i;
    for(auto &i : b) cin >> i;
    int x = 0;
    for(auto &i : a) x ^= i;
    a.push_back(x);
    x = 0;
    for(auto &i : b) x ^= i;
    b.push_back(x);
    if(a == b) finish(0);
    multiset <int> g(a.begin(), a.end());
    multiset <int> h(b.begin(), b.end());
    if(g != h) finish(-1);
    map <int, int> mp;
    for(auto &i : a) mp[i];
    for(auto &i : b) mp[i];
    x = 0;
    for(auto &i : mp) i.second = x++;
    for(auto &i : a) i = mp[i];
    for(auto &i : b) i = mp[i];
    int ans = 0;
    for(int i = 0 ; i < n + 1 ; i++){
        if(i < n && a[i] == b[i]) continue;
        if(i < n) ans++;
        if(vis[a[i]] == 0) ans++;
        vis[a[i]] = 1;
        if(vis[b[i]] == 0) ans++;
        vis[b[i]] = 1;
        ans -= join(a[i], b[i]);
    }
    cout << ans - 1 << endl;
}


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


int main() {
	int N;
  cin >>N;
    if(0 < N && N <10) cout <<N <<endl;
  else if(9 < N &&N <100) cout <<9 <<endl;
  else if(99 < N &&N<1000) cout <<N - 90 <<endl;
  else if(999 < N &&N<10000) cout << 909 <<endl;
  else if(9999 < N&&N <100000) cout << N - 9090<<endl;
  else cout<<90909<<endl;
 }

Measured memory_bytes: 256
K = int(input())
import math
def gcd_three(a, b, c):
    r = math.gcd(a, b)
    if( r == 1 ):
        return 1
    else:
        return math.gcd(r, c)
sum = 0
if(K>2):
    for a in range(1, K-1):
        for b in range(a+1, K):
            for c in range(b+1, K+1):
                sum += gcd_three(a,b,c)*6
for a in range(1, K):
    for b in range(a+1, K+1):
        sum += math.gcd(a,b)*6
sum += K*(K+1)//2
print(sum)

Measured memory_bytes: 9216
from itertools import groupby
from numpy import cumsum


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

if len(set(S)) == 1:
    print(N)
    exit()

G = []
if S[0] == '0':
    G.append(0)
for k, v in groupby(S):
    G.append(len(list(v)))
G.append(0)

cum = [0]
cum.extend(list(cumsum(G)))
cum.append(0)

ans = 0
gc = len(G)
w = min(gc, 3+(K-1)*2)
for i in range(0, gc-w+2, 2):
    ans = max(ans, cum[i+w]-cum[i])
print(ans)


Measured memory_bytes: 20252
def main():
    x, n = map(int, input().split())
    P = list(map(int, input().split()))
    m = x
    M = x
    if len(P) == 0:
        print(x)
        exit()
    if not x in P:
        print(x)
        exit()

    while True:
        m -= 1
        M += 1
        if not m in P:
            print(m)
            exit()
        if not M in P:
            print(M)
            exit()



if __name__ == "__main__":
    main()


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

namespace AtCoder
{

    class Program
    {
        static void Main()
        {
            Solve();

            Console.ReadKey();
        }

        static void Solve()
        {
            var N = GetInt();
            var a = GetIntArray();
            var ans = a.Max() - a.Min();


            Console.Write(ans);
        }



        static public string GetStr() { return Console.ReadLine(); }
        static public int GetInt() { return int.Parse(Console.ReadLine()); }
        static public long GetLong() { return long.Parse(Console.ReadLine()); }
        static public string[] GetStrArray() { return Console.ReadLine().Split(' '); }
        static public int[] GetIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
        static public long[] GetLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
        static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); }
        static public void WriteObjects<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } }

        static bool eq<T, U>() => typeof(T).Equals(typeof(U));
        static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
        static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
                           : eq<T, long>() ? ct<T, long>(long.Parse(s))
                           : eq<T, double>() ? ct<T, double>(double.Parse(s))
                           : eq<T, char>() ? ct<T, char>(s[0])
                                             : ct<T, string>(s);
        static void Multi<T>(out T a) => a = cv<T>(GetStr());
        static void Multi<T, U>(out T a, out U b)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]);
        }
        static void Multi<T, U, V>(out T a, out U b, out V c)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]);
        }
    }
}

Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e9;
#define sz              300005
#define Fast            ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);


int main(){
    Fast;
    int a,b,c, i,j, n,m,t, cs=1;

    cin>>n;
    n=n%10;
    if(n==2 || n==4|| n==5 || n==7 || n==9){
        cout<<"hon"<<endl;
    }
    else if(n==0 || n==1 || n==6 || n==8){
        cout<<"pon"<<endl;
    }
    else{
        cout<<"bon"<<endl;
    }






    return 0;
}



Measured memory_bytes: 3588
#include<stdio.h>
int main()
{
    int num;
    scanf("%d",&num);
    int l,r;
    l=num/100;
    r=num%100;

    if(1<=l&&l<=12){
        if(1<=r&&r<=12){
            printf("AMBIGUOUS\n");
        }
        else{
            printf("MMYY\n");
        }
    }
    else{
        if(1<=r&&r<=12){
            printf("YYMM\n");
        }
        else{
            printf("NA\n");
        }
    }
    return 0;
}

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

using namespace std;

int main() {
    long long n, k;
    cin >> n >> k;
    long long A[n+1], D[n+1];

    for(int i=1; i<n+1; i++) cin >> A[i];
    for(int i=1; i<n+1; i++) D[i] = -1;

    D[1] = 0;
    long long u = 1, d = 0;
    long long first = 0, second = 0;
    while(1) {
        u = A[u];
        d++;
        if(d == k) {
            cout << u << endl;
            return 0;
        }
        if(D[u] != -1) {
            first = D[u];
            second = d;
            break;
        }
        D[u] = d;
    }

    long long t = first + (k - first) % (second - first);
    for(int i=1; i<n+1; i++) {
        if(D[i] == t) cout << i << endl;
    }

    return 0;
}


Measured memory_bytes: 6764
/*
▄███████▀▀▀▀▀▀███████▄
░▐████▀▒ЗАПУСКАЕМ▒▀██████▄
░███▀▒▒▒▒▒ДЯДЮ▒▒▒▒▒▒▀█████
░▐██▒▒▒▒▒▒БОГДАНА▒▒▒▒▒████▌
░▐█▌▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒████▌
░░█▒▄▀▀▀▀▀▄▒▒▄▀▀▀▀▀▄▒▐███▌
░░░▐░░░▄▄░░▌▐░░░▄▄░░▌▐███▌
░▄▀▌░░░▀▀░░▌▐░░░▀▀░░▌▒▀▒█▌
░▌▒▀▄░░░░▄▀▒▒▀▄░░░▄▀▒▒▄▀▒▌
░▀▄▐▒▀▀▀▀▒▒▒▒▒▒▀▀▀▒▒▒▒▒▒█
░░░▀▌▒▄██▄▄▄▄████▄▒▒▒▒█▀
░░░░▄██████████████▒▒▐▌
░░░▀███▀▀████▀█████▀▒▌
░░░░░▌▒▒▒▄▒▒▒▄▒▒▒▒▒▒▐
░░░░░▌▒▒▒▒▀▀▀▒▒▒▒▒▒▒▐
 
*/
#pragma GCC optimize("Ofast")
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <cassert>
#include <iomanip>
#include <random>
 
using namespace std;
 
 
 
#define ll long long
#define ld double
#define null NULL
#define prev prev228
#define index index228
#define left left228
#define right right228
#define hash hash228
#define y1 y1228
#define firn(i, n) for (int i = 0; i < (int)n; ++i)
#define forn(i, n) for (int i = 1; i <= (int)n; ++i)
#define int long long


template<typename T> inline void uin(T &a, T b) {
	if (b < a) a = b;
}

template<typename T> inline void uax(T &a, T b) {
	if (b > a) a = b;
}

const int maxn = 100 * 1000 + 228;

int a[maxn];



signed main() {
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	int sum = 0;
	forn(i, n) {
		cin >> a[i];
	}
	forn(i, n - 1) {
		sum += abs(a[i + 1] - a[i]);
	}
	sum += abs(a[n]);
	sum += abs(a[1]);
	forn(i, n) {
		int res = sum;
		if (1 < i) {
			res -= abs(a[i] - a[i - 1]);
		}
		if (i < n) {
			res -= abs(a[i + 1] - a[i]);
		}
		if (i == 1) {
			res -= abs(a[i]);
		}
		if (i == n) {
			res -= abs(a[n]);
		}
		if (i > 1 && i < n) {
			res += abs(a[i + 1] - a[i - 1]);
		} else {
			if (i == 1) {
				res += abs(a[2]);
			} else {
				if (i == n) {
					res += abs(a[n - 1]);
				}
			}
		}
		cout << res << "\n";
	}
	return 0;
}














Measured memory_bytes: 2048
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N, K, X, Y;
  cin>>N>>K>>X>>Y;
  if(N>=K) cout<<X*K+Y*(N-K)<<endl;
  else cout<<X*N<<endl;
}



Measured memory_bytes: 3564