akhauriyash/Code-Regression huggingface dataset:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

a, p = MAP()

print((a*3+p)//2)

Measured memory_bytes: 5268
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++) 
#define ALL(n) begin(n),end(n)
int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    cout << (  b - a == c - b ? "YES" : "NO" ) << endl;
    return 0;
}

Measured memory_bytes: 256
fn input_one<T: std::str::FromStr> () -> Result<T, T::Err> {
    let mut n = String::new();
    std::io::stdin().read_line(&mut n).unwrap();
    n.trim().parse()
}

fn input_pair<T: std::str::FromStr + Copy> () -> (T, T) {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let arr: Vec<_> = s.trim().split_whitespace().flat_map(str::parse).collect();
    (arr[0], arr[1])
}

pub struct Permutations<'a, T: 'a> {
    items: &'a [T],
    indices: Option<Vec<usize>>,
    is_first: bool,
}

impl<'a, T: 'a> Iterator for Permutations<'a, T> {
    type Item = Vec<&'a T>;

    fn next(&mut self) -> Option<Vec<&'a T>> {
        if !self.is_first {
            let indices_opt = self.indices.take();
            if let Some(indices) = indices_opt {
                self.indices = next_permutation(indices);
            }
        } else {
            self.is_first = false;
        }

        self.indices.as_ref().map(|indices| {
            indices.into_iter().map(|&i| &self.items[i]).collect()
        })
    }
}

fn next_permutation(mut indices: Vec<usize>) -> Option<Vec<usize>> {
    (0 .. indices.len().saturating_sub(1)).rev()
        .find(|&left| indices[left] < indices[left+1])
        .map(|left| {
            let right = (0..indices.len()).rev()
                .find(|&right| indices[left] < indices[right])
                .unwrap();
            indices.swap(left, right);
            indices[left+1..].reverse();
            indices
        })
}

pub trait SliceExt<T> {
    fn permutations(&self) -> Permutations<T>;
}

impl<T> SliceExt<T> for [T] {
    fn permutations(&self) -> Permutations<T> {
        let indices = if self.is_empty() {
            None
        } else {
            Some((0..self.len()).collect())
        };

        Permutations {
            items: self,
            indices: indices,
            is_first: true,
        }
    }
}

fn main() {
    let n: usize = input_one().unwrap();
    let cities: Vec<_> = (0..n).map(|_| input_pair::<isize>()).collect();
    let mut c = 0;
    println!("{}", cities.permutations().map(|route| {
        let (mut px, mut py) = route[0].clone();
        let mut v = 0f64;
        for &(x, y) in route.into_iter().skip(1) {
            v += (((x - px) * (x - px) + (y - py) * (y - py)) as f64).sqrt();
            px = x;
            py = y;
        }
        c += 1;
        v
    }).fold(0f64, |a, c| a + c) / c as f64);
}


Measured memory_bytes: 2208
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	int flag = 0, n, k;
	scanf("%d", &n);
	while(n--) {
		scanf("%d", &k);
		if((k & 1) == 0) {
			if(k % 3 && k % 5) flag = 1;
		}
	}
	if(!flag) printf("APPROVED\n");
	else printf("DENIED\n");
	return 0;
}

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


def solve(S: str):

    dest_list = [-1] * len(S)
    dest = -1
    clear_dest = False
    for i in range(len(S)-1):
        if clear_dest:
            dest = -1
            clear_dest = False

        if S[i] == "R" and S[i+1] == "L":
            dest = i
        elif S[i] == "L" and S[i+1] == "R":
            clear_dest = True
        dest_list[i] = dest
    dest_list[len(S)-1] = dest

    for i in range(len(S)-1,0,-1):
        if dest_list[i] != -1 and dest_list[i-1] == -1:
            dest_list[i-1] = dest_list[i]


    res = [0] * len(S)
    for i,d in enumerate(dest_list):
        diff = abs(i - d)
        if diff % 2 == 0:
            res[d] += 1
        else:
            res[d+1] += 1

    print(" ".join([str(i) for i in res]))

    return


# Generated by 1.1.4 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()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 13008
#include <bits/stdc++.h>
#define ll long long
#define Arman_Sykot ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
 
using namespace std;

int main()
{
/*********************/
// Author:
        Arman_Sykot;
/*********************/
    
	int count = 0, max = 0;
    string s;
    cin >> s;
 
    for (int i = 0; i < 3; i++) {
        if (s[i] == 'R') {
            while (s[i] == 'R') {
                count++;
                i++;
            }
        }
 
        if (count > max) {
            max = count;
            count = 0;
        }
    }
 
    cout << max << endl;
 
	
	return 0;
} 



Measured memory_bytes: 3584
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int dx[4] = {-1,0,1,0};
  int dy[4] = {0,-1,0,1};
  while(true){
    int n;
    cin >> n;
    if(0 == n)return 0;
    vector<int> x(n);
    vector<int> y(n);
    x[0] = 0;
    y[0] = 0;
    for(int i = 1;i < n;i++){
      int ni,di;
      cin >> ni;
      cin >> di;//0左 1下 2右 3上
      x[i] = x[ni] + dx[di];
      y[i] = y[ni] + dy[di];
    }
    int minX = 0;int maxX = 0;
    int minY = 0;int maxY = 0;
    
    for(int i = 1;i < n;i++){
      if(maxX < x[i]){
	maxX = x[i];
      }else if( minX > x[i]){
	minX = x[i];
      }
      if(maxY < y[i]){
	maxY = y[i];
      }else if(minY > y[i]){
	minY = y[i];
      }
    }
    cout << maxX - minX+1 << " " << maxY - minY+1 << endl;
    
  }
  return 0;
}

Measured memory_bytes: 1196
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.awt.geom.Point2D.Double;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.TreeSet;
import java.lang.Object;
 
public class Main {
    Scanner sc = new Scanner(System.in);
   
    public static void main(String[] args) {
        new Main(); 
    }
   
    public Main() {
        new B().doIt();
    }
    class B{
    	void doIt(){
    		int n = sc.nextInt();
    		long a[] = new long[n+1];
    		long sum = 0;
    		long cnt = 0;
    		for(int i = 1;i < n+1;i++){
    			a[i] = sc.nextLong();
    			sum = sum + ((a[i] + cnt) / 2);
    			if(a[i] > 0)cnt = (a[i] + cnt) % 2;
    			else cnt = 0;
//    			System.out.println(i+" "+cnt+" "+sum);
    		}
    		System.out.println(sum);
    	}
    }
}

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

//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//template <typename T> using orderMSet =
//tree <T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef unsigned long long llu;
#define filein freopen("input.txt", "r", stdin)
#define fileout freopen("output.txt", "w", stdout)
#define inf 1000000000000000018
#define mod 1000000007
#define ff first
#define ss second
#define pb push_back
#define mk make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>

#define MX 200005
ll arr[MX], cnt[MX];

int main()
{
	ll n;
	scanf("%lld", &n);

	for(ll i = 0; i < n; i++) {
        scanf("%lld", &arr[i]);
        cnt[arr[i]]++;
	}

	ll sm = 0, ans;
    for(ll i = 1; i <= n; i++) {
		sm += (cnt[i]*(cnt[i]-1))/2;
    }

    for(ll i = 0; i < n; i++) {
        ans = sm-cnt[arr[i]]+1;
        printf("%lld\n", ans);
    }
}


Measured memory_bytes: 4736
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
////////////////////////////////////////

int main() {
	int N, K; cin >> N >> K;
	int x[100100], y[100100], c[100100];
	for (int i = 0; i < N; ++i) {
		char sc;
		cin >> x[i] >> y[i] >> sc;
		x[i] %= K * 2;
		y[i] %= K * 2;
		c[i] = (sc == 'W');
	}
	int white[1010][1010];
	memset(white, 0, sizeof(white));
	//white[x][y]=マス(x,y)を右上とした長方形に含まれている白マスー黒マスの総数
	int bnum = 0;
	//含まれている黒マスの数
	//k*kの範囲に絞る
	//座標をkで割った値の偶奇で色が変わる
	for (int i = 0; i < N; ++i) {
		c[i] += x[i] / K + y[i] / K;
		c[i] %= 2;
		x[i] %= K;
		y[i] %= K;
		white[x[i]][y[i]] += (c[i] ? 1 : -1);
		if (c[i] == 0)++bnum;
	}
	//二次元いもすの要領で展開
	for (int x = 0; x < K; ++x) {
		for (int y = 1; y < K; ++y) {
			white[x][y] += white[x][y - 1];
		}
	}
	for (int x = 1; x < K; ++x) {
		for (int y = 0; y < K; ++y) {
			white[x][y] += white[x - 1][y];
		}
	}
	int ans = 0;
	for (int x = 0; x < K; ++x) {
		for (int y = 0; y < K; ++y) {
			int w = white[K - 1][K - 1] - white[x][K - 1] - white[K - 1][y] + white[x][y] * 2 + bnum;
			ans = max(ans, max(w, N - w));
		}
	}
	cout << ans << endl;
	return 0;
}


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

int main()
{
    int ans = 0;
    string a, b;
    cin >> a;
    cin >> b;

    for (int i = 0; i < 3; i++)
    {
        if (a[i] == b[i])
        {
            ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
import sys

#+++++
		
def main():
	n = int(input())
	bl = list(map(int, input().split()))
	bl=[bl[0]] + bl + [bl[-1]]
	rr = [min(i,j) for i,j in zip(bl,bl[1:])]
	ret=sum(rr)
	print(ret)
	
	
#+++++


if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(x) x.begin(),x.end()
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

ll n,q;
vector<ll>a,b,c;
map<ll,ll>mp;

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

    cin>>n;
    a.resize(n);
    ll sum=0;
    rep(i,n){
        cin>>a[i];
        mp[a[i]]++;
        sum+=a[i];
        }
    cin>>q;
    b.resize(q);
    c.resize(q);
    rep(i,q){
        cin>>b[i]>>c[i];
        ll cur=mp[b[i]];
        mp[b[i]]=0;
        mp[c[i]]+=cur;
        sum-=b[i]*cur;
        sum+=c[i]*cur;
        cout<<sum<<endl;
    }

    return 0;
}

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

vector<int> tonari[200005];

int main(){
    int N,Q;
    cin>>N>>Q;
    int a,b;
    for (int i = 0; i < N-1; ++i) {
        cin>>a>>b; a--; b--;
        tonari[a].push_back(b);
        tonari[b].push_back(a);
    }

    vector<ll> pushed(N,0ll);
    int p,x;
    for (int i = 0; i < Q; ++i) {
        cin>>p>>x; p--;
        pushed[p]+=x;
    }
    vector<ll> score(N,-1ll);
    queue<int> q;
    score[0]=pushed[0];
    q.push(0);
    while(!q.empty()){
        int node=q.front();
        q.pop();
        for(auto tsugi:tonari[node]){
            if(score[tsugi]>=0) continue;
            score[tsugi]=score[node]+pushed[tsugi];
            q.push(tsugi);
        }
    }

    for (int i = 0; i < N; ++i) {
        cout<<score[i];
        if(i<N-1) cout<<" ";
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 17908
# input
X, Y, A, B, C = map(int, input().split())
P = [int(x) for x in input().split()]
Q = [int(x) for x in input().split()]
R = [int(x) for x in input().split()]

# process
P.sort(reverse=True)
Q.sort(reverse=True)
R.sort(reverse=True)

def eat(idx):
    p = -1 if idx[0] == X else P[idx[0]]
    q = -1 if idx[1] == Y else Q[idx[1]]
    r = -1 if idx[2] == C else R[idx[2]]

    if p > q:
        if p > r:
            idx[0] += 1
            return p 
        else:
            idx[2] += 1
            return r
    else:
        if q > r:
            idx[1] += 1
            return q
        else:
            idx[2] += 1
            return r

ans = 0
idx = [0, 0, 0]
while True:
    ans += eat(idx)
    if sum(idx) == X+Y:
        break

# output
print(ans)


Measured memory_bytes: 23340
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String first = sc.nextLine();
        String[] f = first.split(" ");
        int H = Integer.valueOf(f[0]);
        int W = Integer.valueOf(f[1]);
        String[] input = new String[H];
        for(int i=0; i<H; i++) {
            input[i] = sc.nextLine();
        }
        int[][] distance = new int[H][W];
        Deque<Point> deque = new LinkedList<>();
        for(int i = 0; i < H ; i++) {
            // String line = sc.nextLine();
            String line = input[i];
            for (int j = 0; j < W; j++) {
                if(line.charAt(j) == '#') {
                    distance[i][j] = 0;
                    deque.addLast(new Point(i,j));
                } else {
                    distance[i][j] = -1;
                }
            }
        }
        int maxDistance = 0; 
        while(deque.size() > 0) {
            Point s = deque.pollFirst();
            int sx = s.x;
            int sy = s.y;
            int ds = distance[sx][sy];
            List<Point> neighbors = s.getNeighbors(H, W);
            for(Point t : neighbors) {
                if(distance[t.x][t.y] != -1) continue;
                distance[t.x][t.y] = ds + 1;
                maxDistance = Math.max(maxDistance, ds + 1);
                deque.addLast(t);
            }
        }
        System.out.println(maxDistance);
    }

    public static class Point {
        public int x;
        public int y;
        public Point(int x, int y) {
            this.x = x;
            this.y = y;
        }

        public List<Point> getNeighbors(int height, int width) {
            List<Point> ans = new ArrayList<>();
            if(y!=0) {
                ans.add(new Point(x,y-1));
            } 
            if (y != width - 1) {
                ans.add(new Point(x,y+1));
            } 
            if (x != 0) {
                ans.add(new Point(x-1, y));
            }
            if (x != height -1) {
                ans.add(new Point(x+1, y));
            }

            return ans;
        }
    }
}


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

int main(){
  int n,b,f,r,v;
  int room[4][3][10]={0};

  cin >> n;

  for(int i=0;i<n;i++){
    cin >> b >> f >> r >> v;
    room[b-1][f-1][r-1]+=v;
  }

  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      for(int k=0;k<10;k++){
        cout << " " << room[i][j][k];
      }
      cout << endl;
    }
    cout << "####################" << endl;
  }

  for(int j=0;j<3;j++){
    for(int k=0;k<10;k++){
      cout << " " << room[3][j][k];
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>

using namespace std;

int main() {
  int N, a, count = 0;
  cin >> N;
  for (int i = 1; i <= N; i++){
    cin >> a;
    if (a%2 == 1 && i%2 == 1) count++;
  }
  
  cout << count << endl;
  return 0;
}

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

int main(){
    int N, M;
    int Ltmp, Rtmp;
    int L = 0;
    int R = 1e5+1;
    cin >> N >> M;
    for(int m=0;m<M;m++){
        cin >> Ltmp >> Rtmp;
        L = max(L, Ltmp);
        R = min(R, Rtmp);
    }

    cout << max(R - L + 1, 0) << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
hon = [2, 4, 5, 7, 9]
pon = [0, 1, 6, 8]
bon = [3]

if n / 100 >= 1:
  if (n % 100) % 10 in hon:
    print("hon")
  elif (n % 100) % 10 in pon:
    print("pon")
  else:
    print("bon")

elif n /10 >= 1:
  if n % 10 in hon:
    print("hon")
  elif n % 10 in pon:
    print("pon")
  else:
    print("bon")
else:
  if n in hon:
    print("hon")
  elif n in pon:
    print("pon")
  else:
    print("bon")
    
  
  

Measured memory_bytes: 8976
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;

#define LL long long

const int MAXN = 200000 + 5;


int main()
{
    int X;
    cin >> X;
    if (X >= 30){
        cout << "Yes";
    }
    else{
        cout << "No";
    }
    system("pause");
    return 0;
}

Measured memory_bytes: 3692
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }

using T = tuple<int, int, int, char>;
int main() {
    init();

    int n;
    while (1) {
        cin >> n;
        if (n == 0)break;
        vector<T> team(n);
        FOR(i, 0, n) {
            char t; int w = 0, l = 0, r;
            cin >> t;
            FOR(j, 0, n - 1) {
                cin >> r;
                if (r == 0)w--;
                else if (r == 1)l++;
            }
            team[i] = make_tuple(w, l, i, t);
        }
        SORT(team);
        FOR(i, 0, n)cout << get<3>(team[i]) << "\n";
    }
}



Measured memory_bytes: 3068
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>
  
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);

int main(void){
	string a, a1, a2;
	cin >> a;
  a1 = a.substr(0,4);
  a2 = a.substr(4,8);
	cout << a1 << " " << a2 << endl;
}

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

int main(){
  vector<int>a(3);
  for(int i=0;i<3;i++)cin>>a[i];
  sort(a.begin(),a.end());
  if(a[0]+a[1]==a[2])cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  
  return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;

int main() {
	ll n, a, b;
	cin >> n;
	vector<vector<ll> > v(n+1);
	for(int i=1;i<n;i++){
		cin >> a >> b;
		v[a].pb(b);
		v[b].pb(a);
	}
	ll ans = 0, now = 0;
	for(int i=1;i<=n;i++){
		now += i;
		for(auto& to: v[i]) if(to < i) now -= to;
		ans += now;
	}
	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 15856
/* -------------------------------- Template -------------------------------- */

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = std::min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = std::max(a, b); }

// template<typename T> constexpr T inf = [](){ assert(false); };
// template<> constexpr int inf<int> = 1e9;
// template<> constexpr ll inf<ll> = 1e18;
// template<> constexpr ld inf<ld> = 1e30;

struct yes_no : std::numpunct<char> {
  string_type do_truename()  const { return "Yes"; }
  string_type do_falsename() const { return "No"; }
};

void solve();

int main() {
  std::locale loc(std::locale(), new yes_no);
  std::cout << std::boolalpha << std::setprecision(12) << std::fixed;
  std::cout.imbue(loc);
  solve();
  return 0;
}

using namespace std;

/* -------------------------------- Library -------------------------------- */

/* ---------------------------------- Main ---------------------------------- */

void solve() {
  int N, K;
  cin >> N >> K;
  int res = K;
  REP(i,N-1) res *= K - 1;
  cout << res << endl;
  return;
}


Measured memory_bytes: 256
class Dice:
    def __init__(self,t,f,r,l,ba,bo):
        self.t = t
        self.f = f
        self.r = r
        self.l = l
        self.ba = ba
        self.bo = bo
    
    def E(self):
        a = self.t
        b = self.r
        c = self.bo
        d = self.l
        self.r = a
        self.bo = b
        self.l = c
        self.t = d
    
    def N(self):
        a = self.t
        b = self.ba
        c = self.bo
        d = self.f
        self.ba = a
        self.bo = b
        self.f = c
        self.t = d
    
    def S(self):
        a = self.t
        b = self.ba
        c = self.bo
        d = self.f
        self.f = a
        self.t = b
        self.ba = c
        self.bo = d
    
    def W(self):
        a = self.t
        b = self.r
        c = self.bo
        d = self.l
        self.l = a
        self.t = b
        self.r = c
        self.bo = d

s = input().split(" ")
dice1 = Dice(s[0],s[1],s[2],s[3],s[4],s[5])
s = input().split(" ")
dice2 = Dice(s[0],s[1],s[2],s[3],s[4],s[5])

if dice1.t == dice2.f:
    dice2.N()
elif dice1.t == dice2.r:
    dice2.W()
elif dice1.t == dice2.l:
    dice2.E()
elif dice1.t == dice2.ba:
    dice2.S()
elif dice1.t == dice2.bo:
    dice2.E()
    dice2.E()
if dice1.bo != dice2.bo:
    dice2.N()
    for i in range(4):
        if dice1.t == dice2.t and dice1.bo == dice2.bo:
            break
        dice2.E()
for i in range(4):
    if dice1.t == dice2.t and dice1.f == dice2.f and dice1.r == dice2.r and dice1.l == dice2.l and dice1.ba == dice2.ba and dice1.bo == dice2.bo:
        print("Yes")
        break
    dice2.N()
    dice2.E()
    dice2.S()
    if i == 3:
        print("No")

Measured memory_bytes: 7648
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(0)
#define loop(i, a, b) for(lli i=a; i<b; i++)
#define loopb(i, a, b) for(lli i=a; i>=b; i--)
#define pb push_back
#define umap unordered_map
typedef long long int lli;
typedef pair<lli, lli> pii;
typedef vector<lli> vll;
// use to avoid collision
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
 
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
// for pair in unordered_map
struct hash_pair {
    static uint64_t splitmix64(uint64_t x) {
    // http://xorshift.di.unimi.it/splitmix64.c
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
	}
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const{
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        uint64_t x = hash1 ^ hash2;
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
lli M = 1e9 + 7;
lli power(lli x, lli y){
    lli res = 1;
    x = x ;
    while (y > 0) {
        if (y & 1)
            res = (res*x)%M;
        y = y>>1;
        x = (x*x)%M;
    }
    return res%M;
}
lli calc_lcm(vll& A){
	lli n = A.size();
	const lli N = 1e6 + 5;
	vector<lli> lp(N, 0);
	vll pr;
	lp[1] = 1;
	loop(i, 2, N){
		if(lp[i] == 0){
			pr.pb(i);
			lp[i] = i;
		}
		for(lli j = 0; j < pr.size() && lp[i] >= pr[j] && i*pr[j] < N; j++){
			lp[i*pr[j]] = pr[j];
		}
	}
	lli lcm = 1;
	umap<lli, lli> max_pow;
	loop(i, 0, n){
		umap<lli, lli> mp;
		lli temp = A[i];
		while(temp > 1){
			mp[lp[temp]]++;
			temp = temp / lp[temp];
		}
		if(mp.size() != 0)
			for(auto i : mp){
				if(max_pow.find(i.fi) == max_pow.end())
					max_pow[i.fi] = 0;
				max_pow[i.fi] = max(max_pow[i.fi], i.se);
			}
	}
	// loop(i, 0, 100)
	// 	cout<<pr[i] <<" "<<cnt[i]<<"\n";
	// cout<<"\n";
	for(auto i : max_pow)
		lcm = (power(i.fi, i.se) * lcm) % M;
	return lcm;
}
lli solve(){
	lli n;
	cin>>n;
	vll A(n);
	loop(i, 0, n)
		cin>>A[i];
	if(n == 1){
		cout<<1<<"\n";
		return 0;
	}
	lli lcm = calc_lcm(A);
	// cout<<lcm<<"\n";
	lli ans = 0;
	loop(i, 0, n){
		ans = ((ans + (power(A[i], M-2) * lcm) % M) + M)%M;
	}
	cout<<ans<<"\n";
	return 0;
}
int main(){
	// fastio;
	lli t;
	// cin>>t;
	t = 1;
	while(t>0){
		t--;
		solve();
	}
}

Measured memory_bytes: 9336
#include <bits/stdc++.h>
#define ll long long
#define maxn 1000111


using namespace std;
ll n;
ll a[maxn];
ll f[maxn];

 main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    f[1]=0;
    f[2]=abs(a[2]-a[1]);
    for(int i=3;i<=n;i++)
    {
        f[i]=min(f[i-1]+abs(a[i]-a[i-1]),f[i-2]+abs(a[i]-a[i-2]));
    }
     cout<<f[n];
}


Measured memory_bytes: 5120
# -*- coding: utf-8 -*-

line = list(input())
a = int(line[0])
b = int(line[1])
c = int(line[2])
d = int(line[3])

op = ["+", "-"]

for op1 in op:
    for op2 in op:
        for op3 in op:
            ret = a
            if op1=="+":
                ret += b
            else:
                ret -= b
            if op2=="+":
                ret += c
            else:
                ret -= c
            if op3=="+":
                ret += d
            else:
                ret -= d
            if ret==7:
                print(a,op1,b,op2,c,op3,d,"=7",sep="")
                exit()


Measured memory_bytes: 3064
from collections import deque
H, W = map(int,input().split())
A = [list(input()) for _ in range(H)]

task = deque([])
visited = [[0 for _ in range(W)] for _ in range(H)]
cost = [[0 for _ in range(W)] for _ in range(H)]

for i in range(H):
  for j in range(W):
    if A[i][j] == "#":
      task.append(((i,j),0))
      visited[i][j] = 1
      
black = 0#黒点個数
ans = 0
while task:
  p, c = task.popleft()
  cost[p[0]][p[1]] = c
  ans = max(ans,c)
  i = p[0]
  j = p[1]
  black += 1
  if i > 0 and visited[i-1][j] == 0 and A[i-1][j] == ".":
    task.append(((i-1,j),c+1))
    visited[i-1][j] = 1
  if j > 0 and visited[i][j-1] == 0 and A[i][j-1] == ".":
    task.append(((i,j-1),c+1))
    visited[i][j-1] = 1
  if i < H-1 and visited[i+1][j] == 0 and A[i+1][j] == ".":
    task.append(((i+1,j),c+1))
    visited[i+1][j] = 1
  if j < W-1 and visited[i][j+1] == 0 and A[i][j+1] == ".":
    task.append(((i,j+1),c+1))
    visited[i][j+1] = 1
#print(cost)    
print(ans if black == H*W else -1)
  
      
      

Measured memory_bytes: 190180
import java.util.*;
import java.io.*;
import java.math.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        long h = sc.nextLong();
        long ans = 0;
        long cnt = 1;
        while(h >= 1){
            ans += cnt;
            h /= 2;
            cnt *= 2;
        }
        System.out.println(ans);
    }
}
 

Measured memory_bytes: 21844
import java.util.*;
import java.lang.*;
  
public class Main{
  public static void main(String[] args){
    Scanner stdIn=new Scanner(System.in);
    int a=stdIn.nextInt(), b=stdIn.nextInt(), c=stdIn.nextInt();
    if (a<b && b<c){
      System.out.println("Yes");
    }else{
	System.out.println("No");
    }
    
  }
}



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


class Program
{
    static void Main(string[] args)
    {
        // 入力
        //var s = Console.ReadLine();
        //var n = int.Parse(Console.ReadLine());
        int[] np = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var n = np[0];
        var p = np[1];

        var e = new List<int>();
        var o = new List<int>();
        for (int i = 0; i < a.Length; i++)
        {
            if (a[i] % 2 == 0) e.Add(a[i]);
            else o.Add(a[i]);
        }

        decimal ans = 0;
        if (p == 0)
        {
            ans = (decimal)Math.Pow(2, e.Count());

            decimal tmp = 0;
            for (int i = 0; i <= o.Count; i += 2)
            {
                tmp += nCr(o.Count, i);
            }

            ans *= tmp;
        }
        else
        {
            ans = (decimal)Math.Pow(2, e.Count());

            decimal tmp = 0;
            for (int i = 1; i <= o.Count; i += 2)
            {
                tmp += nCr(o.Count, i);
            }

            ans *= tmp;
        }

        // 出力
        Console.WriteLine(ans);
    }

    public static decimal nCr(decimal n, decimal r)
    {
        // naive: return Factorial(n) / (Factorial(r) * Factorial(n - r));
        return nPr(n, r) / Factorial(r);
    }

    public static decimal nPr(decimal n, decimal r)
    {
        // naive: return Factorial(n) / Factorial(n - r);
        return FactorialDivision(n, n - r);
    }

    private static decimal FactorialDivision(decimal topFactorial, decimal divisorFactorial)
    {
        decimal result = 1;
        for (decimal i = topFactorial; i > divisorFactorial; i--)
            result *= i;
        return result;
    }

    private static decimal Factorial(decimal i)
    {
        if (i <= 1)
            return 1;
        return i * Factorial(i - 1);
    }
}

Measured memory_bytes: 28672
if isfile("mystdin.txt");mystdin=open("mystdin.txt","r");redirect_stdin(mystdin);end
function f(x::Int,y::Int,z::Int)
  return x^2+y^2+z^2+x*y+y*z+z*x
end
function main()
  n=parse(Int,readline())
  for i=1:n
    count=0
    qi=Int(isqrt(i))
    for x=1:qi
      for y=1:qi
        nn=i-x^2-y^2-x*y
        if nn>=1
          nz=Int(isqrt(nn))
          for z=1:nz
            count+=z*(z+x+y)==nn
          end
        end
      end      
    end
    println(count)
  end
end
main()
if isdefined(Base, :mystdin);close(mystdin);end

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

using namespace std;

#define COUNTOF(array) (sizeof(array) / sizeof(array[0]))
#define OUT(P) cout << (P) << endl
#define OUT2(P1, P2) cout << (P1) << " " << (P2) << endl
#define PRINT_ARRAY(P) for(int i=0; i<P.size(); i++) cout << P[i] << endl;
#define PRINT_ARRAY_INLINE(P) do { for(int i=0; i<P.size(); i++) cout << P[i] << " "; cout << endl; } while(0)
#define PRINT_ARRAY_WITH_LABEL(L, P) do { cout << L << ": "; PRINT_ARRAY_INLINE(P); cout << endl; } while(0)
typedef long long ll;

int sum_digits(int num);
template <class T>
vector<T> copy_vector(vector<T> vec);
int gcd(int a, int b);

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if((a < c && b > c) || (a > c && b < c)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

/******************************/
/***** DECRARED FUNCTIONS *****/
/******************************/

int sum_digits(int num) {
    int rtn = 0;
    while(num != 0) {
        int tmp = num % 10; 
        rtn += tmp;
        num /= 10; 
    }   
    return rtn;
}
//int sum_digits(int num) {
//    int rtn = 0;
//    string num_str = to_string(num);
//    for(int i=0; i<num_str.size(); i++) {
//        rtn += num_str[i] - '0';
//    }   
//    return rtn;
//}

// vectorのコピー
template <class T>
vector<T> copy_vector(vector<T> vec) {
    vector<T> rtn;
    rtn.reserve(vec.size());
    copy(vec.begin(), vec.end(), back_inserter(rtn));
    return rtn;
}

// ユークリウッドの互除法
int gcd(int a, int b) {
    if(b==0) return a;
    else return gcd(b, a % b);
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <math.h>
#include <cstring>
#include <algorithm>

using namespace std;

int main()
{
    int i,a,b,c;
    cin>>a>>b>>c;
    if(a>c || b<c)
        cout<<"No"<<endl;
    else
        cout<<"Yes"<<endl;
    return 0;
}



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

struct City {
    int prefecture;
    int year;
    int x;
};

int main() {
    int N, M;
    cin >> N >> M;
    vector<City> city(M + 1);
    map<int, map<int, int>> years;
    for (int i = 1; i <= M; i++) {
        int Pi, Yi;
        cin >> Pi >> Yi;
        city[i].prefecture = Pi, city[i].year = Yi;
        years[Pi][Yi] = i;
    }

    for (int Pi = 1; Pi <= N; Pi++) {
        int x = 1;
        for (auto year_i : years[Pi]) city[year_i.second].x = x++;
    }

    for (int i = 1; i <= M; i++) {
        cout << setfill('0');
        cout << setw(6) << city[i].prefecture;
        cout << setw(6) << city[i].x << endl;
    }
}

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

typedef long long ll;
constexpr ll mod = 1e9+7;
void solve();
ll mpow(ll x, ll n){ //x^n(mod) ←普通にpow(x,n)では溢れてしまうため，随時mod計算 2分累乗法だから早い
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % mod;
        x = x*x % mod;
        n = n >> 1;
    }
    return ans;
}
class mint {
 private:
  ll _num,_mod;
  mint set(ll num){ 
      _num = num ;
      if(_num>=0) _num%=_mod;
      else _num+=(1-(_num+1)/_mod)*_mod; 
      return *this;
  }
  ll imod(ll n){return mpow(n , _mod-2);}
 public:
  mint(){ _num = 0;_mod=mod; }
  mint(ll num){ _mod = mod; _num = (num+(1LL<<25)*mod) % mod; }
  mint(ll num,ll M){ _mod=M;_num=(num+(1LL<<25)*mod)%_mod; }
  mint(const mint &cp){_num=cp._num;_mod=cp._mod;}
  mint operator= (const ll x){ return set(x); }
  mint operator+ (const ll x){ return mint(_num + (x % _mod) , _mod); }
  mint operator- (const ll x){ return mint(_num - (x % _mod), _mod); }
  mint operator* (const ll x){ return mint(_num * (x % _mod) , _mod); }
  mint operator/ (ll x){ return mint(_num * imod(x) , _mod);}
  mint operator+=(const ll x){ return set(_num + (x % _mod)); }
  mint operator-=(const ll x){ return set(_num - (x % _mod)); }
  mint operator*=(const ll x){ return set(_num * (x % _mod)); }
  mint operator/=(ll x){ return set(_num * imod(x));}
  mint operator+ (const mint &x){ return mint(_num + x._num , _mod); }
  mint operator- (const mint &x){ return mint(_num - x._num , _mod);}
  mint operator* (const mint &x){ return mint(_num * x._num , _mod); }
  mint operator/ (mint x){ return mint(_num * imod(x._num) , _mod);}
  mint operator+=(const mint &x){ return set(_num + x._num); }
  mint operator-=(const mint &x){ return set(_num - x._num); }
  mint operator*=(const mint &x){ return set(_num * x._num); }
  mint operator/=(mint x){ return set(_num * imod(x._num));}

  bool operator<(const mint &x){return _num<x._num;}

  friend mint operator+(ll x,const mint &m){return mint(m._num + (x % m._mod) , m._mod);}
  friend mint operator-(ll x,const mint &m){return mint( (x % m._mod) - m._num , m._mod);}
  friend mint operator*(ll x,const mint &m){return mint(m._num * (x % m._mod) , m._mod);}
  friend mint operator/(ll x,mint m){return mint(m.imod(m._num) * x , m._mod);}

  explicit operator ll() { return _num; }
  explicit operator int() { return (int)_num; }

  friend ostream& operator<<(ostream &os, const mint &x){ os << x._num; return os; }
  friend istream& operator>>(istream &is, mint &x){ll val; is>>val; x.set(val); return is;}
};
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

void solve(){
    ll N;
    mint K;
    cin>>N>>K;
    vector<int> A(N);
    REP(i, N) cin >> A[i];
    mint ans=0;
    vector<ll> left(N,0),right(N,0);
    REP(i,N) REP(j,N){
        if(A[i]>A[j]){
            if(i<j) right[i]++;
            else left[i]++;
        }
    }
    REP(i,N){
        ans+=(right[i]+left[i])*K*(K+1)/2-left[i]*K;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD (1000000007)
//#define MOD (998244353)
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
//ifstream cinn("input.txt");ofstream coutt("output.txt");

int h,w,k;
int v[11][1001];


int f(int mask){
    int sz=__builtin_popcount(mask)+1;
    vi vv[sz];
    for(int i=0;i<sz;i++)vv[i]=vi(w,0);
    for(int i=0;i<w;i++)vv[0][i]=v[0][i];
    
    int kk=0;
    for(int i=0;i<(h-1);i++){
        if((mask&(1LL<<i))==0){
            for(int ii=0;ii<w;ii++)vv[kk][ii]+=v[i+1][ii];
        }else{
            kk++;
            for(int ii=0;ii<w;ii++)vv[kk][ii]+=v[i+1][ii];
        }
    }

    int cuts=sz-1;
    int sum[sz]={0};
    for(int i=0;i<w;i++){
        int flg=0;
        for(int j=0;j<sz;j++){
            //sum[j]=(j?sum[j-1]:0)+vv[j][i];
            //cout<<j<<" "<<i<<" "<<sum[j]<<" "<<vv[j][i]<<"\n";
            sum[j]+=vv[j][i];
            if(sum[j]>k){
                flg=1;
            }
        }
        for(int j=0;j<sz && flg;j++){
            sum[j]=vv[j][i];
            if(sum[j]>k)return INF;
            
        }
        cuts+=flg;
    }
    
//    for(int i=0;i<sz;i++){
//        for(int j=0;j<w;j++){
//            cout<<vv[i][j]<<" ";
//        }
//        cout<<"\n";
//    }
//    cout<<cuts<<"\n\n\n";
    
    return cuts;
}

signed main(){
    FASTER;
    cin>>h>>w>>k;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            char c;cin>>c;
            v[i][j]=(c=='1');
        }
    }
    int ans=INF;
    for(int i=0;i<(1LL<<(h-1));i++){//
        ans=min(ans,f(i));
    }
    cout<<ans;
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, H, W;
    cin >> N >> H >> W;
    int cnt = 0;
    rep(i, N) {
        int A, B;
        cin >> A >> B;
        if (A >= H && B >= W) {
            cnt++;
        }
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include<vector>
#include <algorithm>
#include <utility>
#include<stack>
#include<queue>
#include<map>
#include <fstream>

using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
        long long res=1;
        long long n,k;
        long long mod=1000000007;
        vector<vector<int>> adjl;
        bool visited[100010];

        void dfs( int x, int par, int parpar, int numc )
        {
            visited[x]=true;
            long long fact = k;
            if( par!= -1 ) fact--;
            if( parpar!=-1 ) fact--;
            fact-=numc;
        /*    if( par!=-1 ){
                for( int i=0;i<adjl[par].size();i++  ){
              //      cout <<i << " " << par << " " << adjl[par][i] <<endl;
                    if( adjl[par][i] == x || adjl[par][i] == parpar ) continue;
                if( visited[ adjl[par][i] ] ) fact--;
            }
            }*/
     //         cout <<x << " " <<par << " " << parpar << " " << fact <<endl;
            res*=fact%mod;
            res%=mod;
            //cout <<  " klkaa  "<<endl;
            bool is=false;
            for( int i=0;i<adjl[x].size();i++ ){
                    if( adjl[x][i] == par  ){
                        is=true;
                        continue;
                    }
                   if( !visited[ adjl[x][i] ] )
                   dfs( adjl[x][i], x, par,i - is );
            }
        }

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

        cin>>n>>k;
        adjl.resize(n);
        for( int i=0;i<n;i++ ) visited[i]=false;
        int u,v;
        for( int i=0;i<n-1;i++ ){
            cin>>u>>v;
            u--;
            v--;
            adjl[u].pb( v );
            adjl[v].pb(u);
        }
        dfs( 0,-1,-1,0 );
        cout<<res%mod<<endl;

      return 0;
    }



























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


int main() {
ll H,ans = 0;
cin >> H;

for (int i = 0;i < INF;i++) {
    if (H == 1) {
        ans += pow(2,i);
        cout << ans << endl;
        return 0;
    }
    H /= 2;
    ans += pow(2,i);
}

return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<queue>
#include<bitset>
#include<map>
using namespace std;
template<typename __T>
inline void read(__T &x)
{
    x=0;
    int f=1;char c=getchar();
    while(!isdigit(c)){if(c=='-')	f=-1;c=getchar();}
    while(isdigit(c))	{x=x*10+c-'0';c=getchar();}
    x*=f;
}
int A,B;
int dis[15][15];
int ed[105][105];
int main()
{
	read(A);
	read(B);
	memset(ed,0,sizeof(ed));
	for(int i=1;i<=A;i++)
		for(int j=1;j<=B;j++)
		{
			read(dis[i][j]);
			for(int a=0;a<=100;a++)
				for(int b=0;b<=100;b++)
					ed[a][b]=max(ed[a][b],dis[i][j]-a*i-b*j);
		}
	for(int i=1;i<=A;i++)
		for(int j=1;j<=B;j++)
		{
			long long ans=12345678987654321ll;
			for(int a=0;a<=100;a++)
				for(int b=0;b<=100;b++)
					ans=min(ans,1ll*a*i+b*j+ed[a][b]);
			if(ans!=dis[i][j])
			{
				printf("Impossible\n");
				return 0;
			}
		}
	printf("Possible\n");
	cout<<202<<' '<<101*101+200<<endl;
	for(int i=1;i<=100;i++)
		cout<<i<<' '<<i+1<<" X"<<endl;
	for(int i=1;i<=100;i++)
		cout<<i+101+1<<' '<<i+101<<" Y"<<endl;
	for(int i=0;i<=100;i++)
		for(int j=0;j<=100;j++)
			cout<<i+1<<' '<<j+101+1<<' '<<ed[i][j]<<endl;
	cout<<1<<' '<<102<<endl;
	return 0;
}

Measured memory_bytes: 384
A=[input() for i in range(2)]
S=A[0]
T=A[1]
s=[]
t=[]
for c in S:
    s.append(c)
for c in T:
    t.append(c)

v=1
for i in range(len(s)):
    if not s[i]==t[i]:
        v=0
if v==1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9108
#include <bits/stdc++.h>
using namespace std;
map<string,int>mp;
const int maxn=2e5+10;
string ans[maxn];
int let=0,rigt=0;
int main(){
	int n,m=0;
	cin>>n;
	string s;
	for(int i=0;i<n;i++){
		cin>>s;
		if(!mp[s]) mp[s]=1;
		else mp[s]++;
		if(mp[s]>m){
			m=mp[s];
			ans[rigt]=s;
			let=rigt;
			rigt++;
		}
		else if(mp[s]==m){
			ans[rigt]=s;
			rigt++;
		}
//		cout<<s<<" "<<mp[s]<<endl;
	}
	sort(ans+let,ans+rigt);
	for(int i=let;i<rigt;i++) cout<<ans[i]<<endl;
}

Measured memory_bytes: 27648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef std::pair<int,int> pair2;
typedef std::pair<int,pair2> pair3;
const ll INF = 1LL<<60;

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

ll ans=0;
  
  for(ll i=0;i<N.size();i++){
  ans=ans+N[i]-'0';
  }

 // cout<<ans<<endl;
  if(ans%9==0){
  cout<<"Yes"<<endl;}
  else {
  cout<<"No"<<endl;}
  
}


Measured memory_bytes: 3764
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <map>
#include <sstream>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <functional>
#include <utility>
#include <stdio.h>
#define ll long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define F first
#define S second
#define SHN 1e9
#define lSHN 1e18
using namespace std;
int n,m;
ll d[100010];
bool b[100010];
ll md=1e9+7;
int main()
{
	cin >>n>>m;
	for (int i=0;i<m;i++)
	{
		int x;
		cin >>x;
		b[x]=1;
	}
	d[0]=1;
	for (int i=1;i<=n;i++)
	{
		d[i]=0;
		if (!b[i-1]) d[i]=d[i-1];
		if (i>1 && !b[i-2]) d[i]=(d[i]+d[i-2])%md;
	}
	cout <<d[n];
	return 0;
}

Measured memory_bytes: 1152
import bisect,sys
import math
from collections import deque

def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))

INF = 1 << 29

DIV = (10**9) + 7

def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def CONV_TBL(max, mod=DIV):
    fac, finv, inv = [0]*max, [0]*max, [0]*max
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod - inv[mod % i] * (mod//i) % mod
        finv[i] = finv[i-1]*inv[i] % mod

    class CONV:
        def __init__(self):
            self.fac =fac
            self.finv = finv
            pass

        def ncr(self, n, k):
            if(n < k):
                return 0
            if(n < 0 or k < 0):
                return 0
            return fac[n]*(finv[k]*finv[n-k] % mod) % mod
        
    return CONV()



sys.setrecursionlimit(200005)

def main():
    N,M = isRaw()
    As = isRaw()
    As.sort(reverse=True)
    sumA = sum(As)
    ans = "Yes" if As[M-1] >= sumA/(4*M) else "No"
    return ans

if __name__ == "__main__":
    print(main())


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

using namespace std;

#define st first
#define nd second
#define ALL(x) (x).begin(), (x).end()

template <class T>
void mini(T& l, T r) {
  l = min(l, r);
}
template <class T>
void maxi(T& l, T r) {
  l = max(l, r);
}

using LL = long long;
using LD = long double;
using ULL = unsigned long long;
const int dx[] = {0, 1, 0, -1, -1, -1, 1, 1},
          dy[] = {1, 0, -1, 0, -1, 1, -1, 1};
const int INF = 1e9;
const LL MOD = 1e9 + 7;

void Solve() {
  string s;
  cin >> s;
  int l = s.size();
  int res = 0;
  for (int i = 0; i < (l / 2); i++) {
    if (s[i] != s[l - 1 - i]) res++;
  }
  cout << res << '\n';
}

void Prepare() {
  // TODO
  return;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  Prepare();
  // int t, T;
  // cin >> T;
  // for (t = 1; t <= T; t++) {
  Solve();
  // }
  return 0;
}

Measured memory_bytes: 256