akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.StringTokenizer;

class Main {

    public static void main(String[] args) throws IOException {
        init(System.in);
        int n = nextInt(), k = nextInt();

        int steps = Integer.MAX_VALUE;
        for (int i = 2; i <= k; i++) {
            int st = (int) Math.ceil(((n - i)*1.0)/(k - 1)) + 1;
            steps = Math.min(st, steps);
        }
        System.out.println(steps);

    }

    //Input Reader
    private static BufferedReader reader;
    private static StringTokenizer tokenizer;

    private static void init(InputStream inputStream) {
        reader = new BufferedReader(new InputStreamReader(inputStream));
        tokenizer = new StringTokenizer("");
    }

    private static String next() throws IOException {
        String read;
        while (!tokenizer.hasMoreTokens()) {
            read = reader.readLine();
            if (read == null || read.equals(""))
                return "-1";
            tokenizer = new StringTokenizer(read);
        }

        return tokenizer.nextToken();
    }

    private static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

//    private static long nextLong() throws IOException {
//        return Long.parseLong(next());
//    }
//
//    //    Get a whole line.
//    private static String line() throws IOException {
//        return reader.readLine();
//    }
//
//    private static double nextDouble() throws IOException {
//        return Double.parseDouble(next());
//    }
}

Measured memory_bytes: 23364
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
#include <algorithm>
using namespace std;
int main()
{
	int N;
	cin >> N;
	vector<int> ifexist(100);
	for(int i=0; i<100; i++){
		ifexist.at(i)=0;
	}
	
	int tmp;
	for(int i=0; i<N; i++){
		cin >> tmp;
		ifexist.at(tmp-1) = 1;
	}
	
	int cnt=0;
	for(int i=0; i<100; i++){
		cnt += ifexist.at(i);
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <set>
#include <stdlib.h>
#include <cmath>
using namespace std;

int d, c[29], s[409][29], p[409], ap[409], cp[29], rs;
set<int> st[29];

int cc()
{
	for (int i = 0; i < 26; i++)
		cp[i] = 0;
	int ans = 0;
	for (int i = 1; i <= d; i++) {
		for (int j = 0; j < 26; j++) {
			if (p[i] == j) {
				cp[j] = i;
				ans += s[i][j];
			}
			else
				ans -= (i - cp[j]) * c[j];
		}
	}
	return ans;
}

void rm(int n, int k)
{
	auto pi = st[k].find(n);
	auto l = pi; l--;
	auto r = pi; r++;
	int pl = (n - (*l) - 1), pr = ((*r) - n - 1), plr = ((*r) - (*l) - 1);
	st[k].erase(n);
	rs -= s[n][k];
	rs += pl * (pl + 1) / 2 * c[k]; rs += pr * (pr + 1) / 2 * c[k];
	rs -= plr * (plr + 1) / 2 * c[k];
}

void ins(int n, int k)
{
	auto r = st[k].lower_bound(n);
	auto l = r; l--;
	int pl = (n - (*l) - 1), pr = ((*r) - n - 1), plr = ((*r) - (*l) - 1);
	st[k].insert(n);
	rs += s[n][k];
	rs -= pl * (pl + 1) / 2 * c[k]; rs -= pr * (pr + 1) / 2 * c[k];
	rs += plr * (plr + 1) / 2 * c[k];
}

void up(int n, int k)
{
	rm(n, p[n]);
	p[n] = k;
	ins(n, p[n]);
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> d;
	for (int i = 0; i < 26; i++) {
		cin >> c[i];
		st[i].insert(0); st[i].insert(d + 1);
	}
	for (int i = 1; i <= d; i++) {
		for (int j = 0; j < 26; j++)
			cin >> s[i][j];
		p[i] = rand() % 26;
		st[p[i]].insert(i);
	}
	rs = cc();
	double k = 300, sc = 350, kt = 0.99925, mx = rs;
	for (int i = 0; i < 3000000; i++) {
		double e1 = rs;
		int n = (rand() % d) + 1, kp = (rand() % 25) + 1;
		int hk = p[n], tk = (hk + kp) % 26;
		up(n, tk);
		int e2 = rs;
		double pb = exp((e2 - e1) / (k * sc));
		if (pb < rand() / (double)RAND_MAX)
			up(n, hk);
		k *= kt;
		if (mx < rs) {
			mx = rs;
			for (int j = 1; j <= d; j++)
				ap[j] = p[j];
		}
	}
	for (int i = 1; i <= d; i++)
		cout << ap[i] + 1 << '\n';
	return 0;
}

Measured memory_bytes: 4340
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
#define MAX_V 400010
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
template<typename A, size_t NNN, typename T>
void Fill(A (&array)[NNN], const T &val){
    fill( (T*)array, (T*)(array+NNN), val );
}
#define INF 1e9+7
#define LLINF 1e18+7
ll MOD=1e9+7;
#define N 610000
ll n,m,k;
ll dp[4000][4000];
ll a[N];
ll b[N];
int c[N];
vec G[N],GB[N];
int visited[N];
int dfs(int x){
    if(visited[x]!=-1){
        return visited[x];
    }
    int temp=0;
    rep(i,GB[x].size()){
        temp=max(temp,dfs(GB[x][i])+1);
    }
    return visited[x]=temp;
}
int main(){
    n=in();
    m=in();
    rep(i,m){
        int x=in(),y=in();
        GB[y].pb(x);
        c[x]++;
    }
    int ans=0;
        fill(visited,visited+(n+1),-1);
    rep2(i,1,n){
        if(c[i]==0){
            ans=max(ans,dfs(i));
        }
    }

    cout<<ans;
    return 0;
}

Measured memory_bytes: 39168
isPrime :: Int -> Bool
isPrime x
    | x < 2     = False
    | x == 2    = True
    | even x    = False
    | otherwise = all (\y -> x `mod` y /= 0) [3, 5 .. n]
        where n = floor $ sqrt $ fromIntegral x

solve :: [Int] -> String
solve xs = (show $ length $ filter isPrime xs) ++ "\n"

main :: IO ()
main = interact (solve . map read . lines)

Measured memory_bytes: 5424
import math

def A():
    temp = input().split()
    M = int(temp[0])
    D = int(temp[1])

    if D<22:
        print(0)
        return
    
    ans = 0

    for i in range(1, M+1):
        for j in range(22, D+1):
            if (j%10) >= 2 and (j%10)*int(j/10) == i:
                ans += 1
    
    print(ans)

def B():
    temp = input().split()
    N = int(temp[0])
    K = int(temp[1])
    A = [int(i) for i in input().split()]

    basic_inv = 0
    for i in range(0, len(A)):
        for j in range(i+1, len(A)):
            if A[i] > A[j]:
                basic_inv += 1
    
    if K == 1:
        print(basic_inv)
        return

    inv = 0
    for i in range(0, len(A)):
        for j in range(0, len(A)):
            if A[i] > A[j]:
                inv += 1

    
    s = (K*(K-1))//2
    num = s
    k_mod = K
    print(int(k_mod*basic_inv + num*inv)%(10**9+7))

    # #check
    # full = A*K
    # sum = 0
    # for i in range(0, len(full)):
    #     for j in range(i+1, len(full)):
    #         if full[i] > full[j]:
    #             sum += 1
    #             sum %= (10**9+7)
    
    # print("check:", sum)

B()



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

#define mp make_pair
#define pb push_back

#define int int64_t
#define ld long double

const int MOD = 1e9+7;
const int N = 1e6+5;

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

    int n;
    cin>>n;
    int arr[n+2];
    memset(arr,0,sizeof(arr));
    for(int i=0;i<n;i++) {
        cin>>arr[i];
    }   
    int dp[n+2];
    for(int i=0;i<n+2;i++) {
        dp[i]=1e15;
    }
    dp[0]=0;
    for(int i=0;i<n;i++) {
        // cout<<dp[i+1]<<" ";
        dp[i+1]=min(dp[i+1], dp[i]+abs(arr[i+1]-arr[i]));
        dp[i+2]=min(dp[i+2], dp[i]+abs(arr[i+2]-arr[i]));
    }

    cout<<dp[n-1];

    return 0;
}

Measured memory_bytes: 1792
#include<cstdio>
using ll = long long;
using ull = unsigned long long;

int main(){
	ll X;
	scanf("%lld", &X);
	for (ll i = -100; i < 200; ++i){
		ll high = 200;
		ll low = 0;
		while(high - low > 1){
			ll mid = (low + high)/2;
			if(mid*mid*mid*mid*mid - i*i*i*i*i <= X) low = mid;
			else high = mid;
		}
		if(low*low*low*low*low - i*i*i*i*i == X){
			printf("%lld %lld\n", low, i);
			return 0;
		}
	}
	return 0;
}

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

int main(){
    string S,T;
    cin >> S >> T;
    long count=0;
    for(long i=0; i<S.length(); i++){
        if(S[i]!=T[i]){
            count++;
        }
    }
    cout << count << endl;
}

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

mt19937 mt(time(nullptr));
// uniform_int_distribution< int > rand_int(0, 10) // rand[0, 10] inclusive

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  int n;
  cin >> n;
  vector< int > p(n);
  for (int i=0; i<n; ++i) cin >> p[i];
  int cnt = 0;
  for (int i=0; i<n; ++i) {
    if (p[i]!=i+1) cnt++;
  }
  cout << (cnt <= 2 ? "YES" : "NO") << endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

x1 = sum(A) - 2 * sum([A[i] for i in range(1,N,2)])
x = [x1]

for i in range(1,N):
    xi = 2 * A[i - 1] - x[i - 1]
    x.append(xi)

print(*x)

Measured memory_bytes: 14092
#include<stdio.h>
 
#define Max 101
int x;
int P[Max];
int M[Max][Max];
void Matrix_Chain_Order(){
  int n,i,j,l,k,q;
  n=x;
 
  for(i=1;i<=n;i++){
    M[i][i]=0;
  }
  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j=i+l-1;
      M[i][j]=100000;
      for(k=i;k<=j-1;k++){
    q=M[i][k]+M[k+1][j]+P[i]*P[k+1]*P[j+1];
    if(q<M[i][j]){
      M[i][j]=q;
    }
      }
    }
  }
  printf("%d\n", M[1][x]);
}
 
main(){
   
  int n,i,a,count;
  scanf("%d",&x);
   
  for(i=0;i<x;i++){
    scanf("%d %d",&P[i+1],&a);
     
  }
  P[i+1]=a;
   
  Matrix_Chain_Order();
   
  return 0;
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
#define  X first
#define  Y second

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;

const ll INF = 2e18;
const int inf = 1e9+10;
const int maxN = 1e5+10;
const int maxD = 15;
const int maxH = 100; 
const int MOD = 998244353;


int main()
{
	ll A,V;
	ll B,W;
	ll T;
	scanf("%lld%lld",&A,&V);
	scanf("%lld%lld",&B,&W);
	scanf("%lld",&T);
	if(A<B)
	{
		ll len1 = A + V*T;
		ll len2 = B + W*T;
		if(len1 >= len2)
		{
			puts("YES");
		}
		else
		{
			puts("NO");
		}
	}
	else
	{
		ll len1 = A - V*T;
		ll len2 = B - W*T;
		if(len2 >= len1)
		{
			puts("YES");
		}
		else
		{
			puts("NO");
		}
	}
	return 0;
}

Measured memory_bytes: 3760
#include <iostream>
#include<string.h>
#include<algorithm>
using namespace std;

int main() {
	int a,b;
	cin >> a>>b;
	if (a >= 13)cout << b << endl;
	else if (a <= 5)cout << "0" << endl;
	else cout << b / 2 << endl;
	return 0;
}

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

int main() {

long res;
long Q,H,S,D,N; cin >> Q >> H >> S >> D >> N; 
S=min(4*Q ,min(2*H ,S));
res = N/2*min(D,2*S)+(N%2)*S;
cout << res << endl ;

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_set>
#include <math.h>
using namespace std;

int main(){
  int N,K;
  cin >> N >> K;
  vector<int> h(N);
  for(int i = 0; i < N; i++){
    cin >> h[i];
  }
  int counter = 0;
  for(int i = 0; i < N; i++){
    if(h[i] >= K){
      counter++;
    }      
  }
  cout << counter << endl;
  return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;
import java.util.Arrays;

public class Main {

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

    void solve() {
        Scanner sc = new Scanner(System.in);
        String S=sc.next();
        char[] s=S.toCharArray();
        int ans=0;
        for(int i=0;i<4;i++){
            if(s[i]=='-'){
              ans--;  
            }else{
                ans++;
            }
        }
        System.out.println(ans);
    }

}

Measured memory_bytes: 21844
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		String S = sc.next();
		String ans = "No";
		if (S.substring(0, N/2).equals(S.substring(N/2, N))) { 
			ans = "Yes";
		}
		System.out.println(ans);
	}



	public static long gcd(long a, long b) {
		long remainder = a % b;
		if (remainder == 0) {
			return b;
		} else {
			return gcd(b, remainder);
		}
	}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 22996
#include<bits/stdc++.h>
using namespace std;
int a[201],n,ans;
bool iop()
{
	for(int i=1;i<=n;i++)
	    if(a[i]%2==1)return false;
	return true;
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	    cin>>a[i];
	while(iop())
	{
		ans++;
		for(int i=1;i<=n;i++)
		    a[i]/=2;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <cstdlib>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
#include <stack>
#include <functional>
#include <sstream>
#define rep(i,j,n) for(i=j;i<(n);i++)
#define rrep(i,j,n) for(i=j;i>(n);i--)
typedef long long int lli;
#define N 1000000007

using namespace std;

int main(){
    lli n,a,b,c,ans=0;
    string s;
    vector<lli> lucky;
    lli i,j;
    cin>>n>>s;
    rep(i,0,1000){
        c=i%10;
        b=(i%100-c)/10;
        a=i/100;
//        cout<<a<<b<<c<<"が可能か調べる"<<endl;
        if(s.find(to_string(a))!=string::npos){
            string t=s.substr(s.find(to_string(a))+1,s.size()-s.find(to_string(a))-1);
            if(t.find(to_string(b))!=string::npos){
                t=t.substr(t.find(to_string(b))+1,t.size()-t.find(to_string(b))-1);
                if(t.find(to_string(c))!=string::npos){
//                    cout<<"作成可能"<<endl;
                    ans++;
                }
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 384
#include<iostream>

using namespace std;

int main(){
  long long x[100009], mn=4e8;
  int zero, n, k;
  cin >> n >> k;
  for(int i=0;i<n;i++){
    cin >> x[i];
  }
  for(long long i=0;i+k-1<n;i++){
    long long tmp;
    if(x[i]<0 && x[i+k-1]>0){
      tmp = max(abs(x[i]), abs(x[i+k-1])) + 2*min(abs(x[i]), abs(x[i+k-1]));
    }
    else if(x[i+k-1]<=0){
      tmp = abs(x[i]);
    }
    else if(x[i]>=0){
      tmp = abs(x[i+k-1]);
    }
    mn = min(mn, tmp);
  }
  cout << mn << endl;
}


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

int main() {

  int x;
  cin >> x;

  if(x==2) {
      cout << 2 << endl;
      return 0;
  }

  for (int i = x; i < 1000000; i++) {
      for (int j = 2; j < i; j++) {
         if(i%j==0) break;
         else if(i%j!=0&&j==i-1) {
            cout << i << endl;
            return 0;
        }
      }
  }  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int           long long
#define pb            push_back
#define all(a)        (a).begin(),(a).end()
#define sz(x)         (int)x.size()
#define F             first
#define S             second
#define endl          "\n"
#define inf           (long long)1000000007
#define FOR(i, a, b)  for(int i=a; i<b; i++)
#define bigint        1e18
mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count()); 
#define SHUF(v) shuffle(aint(v), RNG);
// Use mt19937_64 for 64 bit random numbers. 

template <typename T>
T ceil(T a, T b){ return (a+b-1)/b; }


template<typename T>
T binpow(T a, T b, T m) {
    a %= m;
    T res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
  
void solve(){
    string s, t;
    cin>>s>>t;
    vector<char> a, b;
    FOR(i, 0, sz(s)){
        a.pb(s[i]);
    }
    FOR(i, 0, sz(t)){
        b.pb(t[i]);
    }
    int n = sz(a), m = sz(b);
    int res = inf;
    FOR(i, 0, n-m+1) {
        int temp=0;
        FOR(j, 0, m) {
            //cout<<i<<' '<<j<<' '<<a[i+j]<<" "<<b[j]<<endl;
            temp+=(a[i+j]!=b[j]);
        }
        res = min(res, temp);
    }
    cout<<res;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);     
    int t=1;
    //cin>>t;
    FOR(i, 1, t+1){ 
        //cout<<"Case #"<<i<<": ";
        solve();
    }
    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
 
}

Measured memory_bytes: 3652
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int sum= 0;
        //int len = 4000000;
        for(int i=0;i<n;i++) {
            a[i] = sc.nextInt();
            sum += a[i];
        }
        BitSet bs = new BitSet(sum+1);
        bs.set(sum);
        for(int i=0;i<n;i++){
            BitSet cur = bs.get(a[i],sum+1);
            bs.or(cur);
        }
        int ini = sum%2==0?sum/2:(sum+1)/2;
        for(int i=ini;i<=sum;i++){
            if(bs.get(i)){
                System.out.println(i);
                break;
            }
        }
    }
}


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

using ll = long long;
using P = pair<int, int>;

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  // 入力
  int a, b, c;
  cin >> a >> b >> c;
  ll k;
  cin >> k;

  // 解答
  cout << (k & 1 ? b - a : a - b) << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

#define sz(x) (int)(x.size())
#define rep(i,a,b) for(int i=a;i<b;++i)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
//////

int const N = 1e5 + 41;
int n, m;
ll k;
int x[N], a[N];
pii y[N];
int d[N];
ll ans[N];

vector<int> mul(vector<int> a, vector<int> b){
	vector<int> ret;
	ret.resize(sz(a));
	rep(i, 0, sz(a)) ret[i] = a[b[i]];
	return ret;
}

vector<int> bp(vector<int> x, ll d){
	if(!d){
		vector<int> ret;
		rep(i, 0, sz(x)) ret.pb(i);
		return ret;
	}
	if(d&1LL) return mul(x, bp(x,d-1));
	vector<int> r = bp(x, d/2);
	return mul(r, r);
}

void solve(){
	scanf("%d",&n);
	rep(i,0,n) scanf("%d",&x[i]);
	rep(i, 1, n){
		d[i-1] = x[i] - x[i-1];
	}

	scanf("%d %lld",&m,&k);
	rep(i, 0, m) scanf("%d",&a[i]), --a[i];
	vector<int> per;
	rep(i, 0, n-1) per.pb(i);
	vector<int> nper = per;
	rep(i, 0, m) swap(nper[a[i]], nper[a[i]-1]);
	vector<int> mn = nper;
	vector<int> res = bp(mn, k);
	res = mul(per, res); 

	ll cur = x[0];
	cout << cur << " ";
	rep(i, 0, n-1){
		cur += d[res[i]];
		cout << cur << " ";
	}
}

int main(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	solve();

	return 0;
}

Measured memory_bytes: 36856
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<unordered_map>
#include<unordered_set>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
#define PI acos(-1.0);

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

set<ll> divisor(ll n){
    set<ll> s;
    for(ll i = 1; i*i <= n; i++){
        if(n % i == 0){
            s.insert(i);
            s.insert(n/i);
        }
    }
    return s;
}

int main(){
	int N,K; cin >> N >> K;
	vector<int> A(N);
	rep(i,N) cin >> A[i];
	int sum = 0;
	rep(i,N) sum += A[i];
	set<ll> div = divisor(sum);
	int ans = 0;
	for(int u : div){
		vector<int> B = A;
		rep(i,N){
			B[i] %= u;
		}
		sort(B.begin(),B.end());
		vector<int> sum2(N+1),sum3(N+1);
		rep(i,N) sum2[i+1] = sum2[i]+B[i];
		rep(i,N) sum3[i+1] = sum3[i]+u-B[i];
		bool ok = false;
		rep(i,N+1){
			if(sum2[i] == sum3[N]-sum3[i] && sum2[i] <= K) ok = true;
		}
		if(ok) ans = max(ans,u);
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
import bisect
n = int(input())
A = sorted(list(map(int, input().split())))
B = list(map(int, input().split()))
C = sorted(list(map(int, input().split())))
cnt = 0
for i in range(n):
    a = bisect.bisect_left(A, B[i])
    c = bisect.bisect_right(C, B[i])
    cnt += a * (n-c)
print(cnt)


Measured memory_bytes: 23744
/// --- In the name of ALLAH --- ///


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


typedef long long              ll;
typedef vector<int>            vi;
typedef vector<ll>             vl;
typedef vector<vi>             vvi;
typedef vector<vl>             vvl;
typedef pair<int,int>          pii;
typedef pair<double, double>   pdd;
typedef pair<ll, ll>           pll;
typedef vector<pii>            vii;
typedef vector<pll>            vll;
typedef double                 dl;

#define endl                   '\n'
#define PB                     push_back
#define F                      first
#define S                      second
#define all(a)                 (a).begin(),(a).end()
#define rall(a)                (a).rbegin(),(a).rend()
#define sz(x)                  (ll)x.size()
#define wt                     ll t; cin>>t; while(t--)
#define input(a,n)             for(int i=0;i<n;i++) cin>>a[i];

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;


#define mem(a,b) memset(a, b, sizeof(a) )
#define sqr(a) ((a) * (a))
#define mod 10000007
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu () {            cerr << endl;}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest) {cerr << arg << ' ';faltu(rest...);}

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


const ll mx=1e9;




 main()
{
    optimize();

int a,b,k,m,i,j=0;
vi v;
cin>>a>>b>>k;
m=min(a,b);
for(i=1;i<=m;i++)
{
    if(a%i==0&&b%i==0)
        v.PB(i);
}
sort(rall(v));
for(auto u:v)
{
    j++;
    if(j==k)
    {
        cout<<u<<endl;
        break;
    }
}













    return 0;
}






























































































Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define rep0(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<string, int, int> TU;
typedef tuple<int, int, int> TI;

int main()
{
    int N;
    cin >> N;
    ll input[N];
    rep0(i,N){
        cin >> input[i];
    }
    sort(input,input+N);
    cout << input[N-1]-input[0] << endl;

}


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

map<int, int> mem;

int main()
{
  int Q, n;
  cin >> Q;
  for(int q = 0; q < Q; q++)
  {
    mem.clear();
    cin >> n;
    int m = 0;
    while(n >= 10)
    {
      m++;
      mem[n] = 1;
      int tmp = 0;
      for(int j = 10; ; j *= 10)
      {
        int a, b;
        a = n / j;
        b = n % j;
        if(!a)
          break;
        tmp = max(tmp, a * b);
      }
      n = tmp;
      if(mem.count(n))
      {
        cout << -1 << endl; 
        goto end;
      }
    }
    cout << m << endl;
end:;
  }
}

Measured memory_bytes: 1200
import java.util.Scanner;
class Main {
	int m, f, r, i, n;
	public void gr() {
		Scanner sc = new Scanner(System.in);
		m = sc.nextInt();
		f = sc.nextInt();
		r = sc.nextInt();
		while(m != -1 || f != -1 || r != -1) {
			if(m == -1 || f == -1) {
				System.out.println("F");
			} else if(m + f >= 80) {
				System.out.println("A");
			} else if(m + f >= 65) {
				System.out.println("B");
			} else if(m + f >= 50) {
				System.out.println("C");
			} else if(m + f >= 30) {
				if(r >= 50) {
					System.out.println("C");
				} else {
				System.out.println("D");
				}
			} else {
				System.out.println("F");
			}
			m = sc.nextInt();
			f = sc.nextInt();
			r = sc.nextInt();
		}
	}
	public static void main(String[] args) {
		new Main().gr();
	}
}

Measured memory_bytes: 19388
import java.io.*;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

        long X = scan.nextInt();

        long A = 0;
        long b;

        while (true) {
        	long Bfive = A*A*A*A*A - X;

        	if (Bfive < 0) {
        		b = -1;
        		while (b*b*b*b*b > Bfive) {
        			b--;
        		}
        		if (b*b*b*b*b == Bfive) {
        			break;
        		}

        	} else if (Bfive > 0) {
        		b = 1;
        		while (b*b*b*b*b < Bfive) {
        			b++;
        		}
        		if (b*b*b*b*b == Bfive) {
        			break;
        		}

        	} else if (Bfive == 0) {
        		b = 0;
        		break;
        	}

        	A++;
        }

		System.out.println(A+" "+b);

	}
}

Measured memory_bytes: 38852
#include <stdio.h>
#include <stdlib.h>

int main()
{
	int x, y;
	int t;

	for (;;) {
		scanf("%d%d", &x, &y);
		if (x == 0 && y == 0) break;
		if (x > y) t = x, x = y, y = t;
		printf("%d %d\n", x, y);
	}
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define REP(i,n) for(int i = 0; i < n; i++)
#define REPR(i,n) for(int i = n; i >= 0; i--)
#define FOR(i,m, n) for(int i = m-1; i < n; i++)
#define INF 2000000000
#define ALL(v) v.begin(), v.end()
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))
#define FILL2D(A,c) fill(A[0], A[0] +sizeof(A)/sizeof(**A),c)
#define FILL3D(A,c) fill(A[0][0], A[0][0] +sizeof(A)/sizeof(***A),c)
//vector<vector<要素の型>> 変数名(要素数1, vector<要素の型>(要素数2, 初期値))
//vector<intなど> 変数名(要素数,初期値)
using namespace std;
typedef long long ll;
//gcd,lcmセット
ll gcd(ll a, ll b){
   if (a%b == 0) return b;
   else return gcd(b, a%b);
}
ll lcm(ll a, ll b){	
   return a*b/gcd(a, b);
}
bool isPrime(ll x){
    int i;
    if(x < 2)return false;
    else if(x == 2) return true;
    if(x%2 == 0) return false;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return false;
    return true;
}
//dfsではvector<vector<int>> g(n);で◎
int main(){
    ll n,k;
    cin>>n>>k;
    int a=0;
    while(n>0){
        n/=k;
        a++;
    }
    cout<<a<<endl;
}

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

int main (void) {
  int c[3][3];
  int s = 0;
  REP(i, 3) REP(j, 3) {
    int in;
    cin >> in;
    s += in;
    c[i][j] = in;
  }
  // check sum mod
  if (s % 3 != 0)
    goto fail;

  FOR(i, 1, 3) {
    if (!(c[i][0] - c[i - 1][0] == c[i][1] - c[i - 1][1] && c[i][1] - c[i - 1][1] == c[i][2] - c[i - 1][2])) goto fail;
  }

  cout << "Yes" << endl;
  return 0;
fail:
  cout << "No" << endl;
  return 0;
}


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

UL CountBit(ULL B){
 B= (B&0x5555555555555555) + ((B>>1)&0x5555555555555555);
 B= (B&0x3333333333333333) + ((B>>2)&0x3333333333333333);
 B= (B&0x0f0f0f0f0f0f0f0f) + ((B>>4)&0x0f0f0f0f0f0f0f0f);
 B= (B&0x00ff00ff00ff00ff) + ((B>>8)&0x00ff00ff00ff00ff);
 B= (B&0x0000ffff0000ffff) + ((B>>16)&0x0000ffff0000ffff);
 B= (B&0x00000000ffffffff) + ((B>>32)&0x00000000ffffffff);
 return B;
}

int main() {
 UL N; scanf("%u",&N);
 ULL M[10]={};
 rep(i,N){
  UL K; scanf("%u",&K);
  rep(k,K){
   UL b; scanf("%u",&b);
   M[i] |= (1ull<<b);
  }
 }
 UL Q; scanf("%u",&Q);
 ULL B=0;
 rep(q,Q){
  UL c; scanf("%u",&c);
  if(c==0){
   UL i; scanf("%u",&i);
   printf((B&(1ull<<i))?"1\n":"0\n");
  }
  if(c==1){
   UL m; scanf("%u",&m);
   B |= M[m];
  }
  if(c==2){
   UL m; scanf("%u",&m);
   B &= ~M[m];
  }
  if(c==3){
   UL m; scanf("%u",&m);
   B ^= M[m];
  }
  if(c==4){
   UL m; scanf("%u",&m);
   printf(((B&M[m])==M[m])?"1\n":"0\n");
  }
  if(c==5){
   UL m; scanf("%u",&m);
   printf((B&M[m])?"1\n":"0\n");
  }
  if(c==6){
   UL m; scanf("%u",&m);
   printf(((B&M[m])==0)?"1\n":"0\n");
  }
  if(c==7){
   UL m; scanf("%u",&m);
   printf("%u\n",CountBit(B&M[m]));
  }
  if(c==8){
   UL m; scanf("%u",&m);
   printf("%llu\n",B&M[m]);
  }
 }
 return 0;
}



Measured memory_bytes: 3184
from collections import Counter

N = int(input())
S = input()
ans = 0

for j in range(1, N-1):
    cl, cr = Counter(S[:j]), Counter(S[j+1:])
    
    for i in set(cl.keys())-set(S[j]):
        ans += cl[i]*(N-1-j-cr[S[j]]-cr[i])
            
    for i in range(1, min(j, N-1-j)+1):
        if S[j] != S[j-i] and S[j] != S[j+i] and S[j-i]!=S[j+i]:
            ans -= 1
    
print(ans)
    

Measured memory_bytes: 9460
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 214748364700
#define LINF 9223372036854775807
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
//typedef long long int ll;
int a,b,q;
int s[111111],t[111111],x[111111];

int solve(int m){
    int ng=-1+1,ok=a+1;
	while(abs(ok-ng)>1){
        int mid=(ok+ng)/2;

        if(m<=s[mid])ok=mid;
        else ng=mid;
	}
	int ng2=-1+1,ok2=b+1;
	while(abs(ok2-ng2)>1){
        int mid=(ok2+ng2)/2;

        if(m<=t[mid])ok2=mid;
        else ng2=mid;
    }
    int ans;
    
    ans=min({
    	abs(m-s[ok])+abs(s[ok]-t[ok2]),
    	abs(m-s[ok])+abs(s[ok]-t[ng2]),
    	abs(m-s[ng])+abs(s[ng]-t[ok2]),
    	abs(m-s[ng])+abs(s[ng]-t[ng2]),
    	abs(m-t[ok2])+abs(s[ok]-t[ok2]),
    	abs(m-t[ok2])+abs(s[ng]-t[ok2]),
    	abs(m-t[ng2])+abs(s[ok]-t[ng2]),
    	abs(m-t[ng2])+abs(s[ng]-t[ng2]),
    	});
    	
    //ans=min(abs(s[ok]-t[ok2]),);
    //cout<<s[ok]<<" "<<s[ng]<<" "<<t[ok2]<<" "<<t[ng2]<<endl;
    
    return ans;
    
}

signed main(){
	
	cin>>a>>b>>q;
	for(int i=1;i<a+1;i++)cin>>s[i];
	s[0]=-INF,s[a+1]=INF;
	for(int i=1;i<b+1;i++)cin>>t[i];
	t[0]=-INF,t[b+1]=INF;
	rep(i,q)cin>>x[i];
	rep(i,q){
	    cout<<solve(x[i])<<endl;
	}
	/*int ng=-1,ok=a;
	while(abs(ok-ng)>1){
        int mid=(ok+ng)/2;

        if(900<=t[mid])ok=mid;
        else ng=mid;
	}
	cout<<t[ok]<<endl;*/
	
	

}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    int n,m;
    cin>>n>>m;
    int sum=0;
    vector<int> a(n);
    rep(i,n){
        cin>>a[i];
        sum+=a[i];
    }
    sort(all(a));
    reverse(all(a));
    bool ok=true;
    rep(i,m){
        if(a[i]*4*m<sum) ok=false;
    }
    if(ok) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
	public static void main(String[] args)
	{
		Scanner sc =new Scanner(System.in);
		int N=sc.nextInt();
		int D=sc.nextInt();
		int X=sc.nextInt();
		int ans=X;

		for(int i=0;i<N;i++){
			int A=sc.nextInt();
			ans+=((D-1)/A)+1;
		}

		//結果を出力
		System.out.println(ans);
	}
} 

Measured memory_bytes: 24016
class UnionFind():
    # 作りたい要素数nで初期化
    # 使用するインスタンス変数の初期化
    def __init__(self, n):
        self.n = n
        # root[x]<0ならそのノードが根かつその値が木の要素数
        # rootノードでその木の要素数を記録する
        self.root = [-1]*(n+1)
        # 木をくっつける時にアンバランスにならないように調整する
        self.rnk = [0]*(n+1)

    # ノードxのrootノードを見つける
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            # ここで代入しておくことで、後の繰り返しを避ける
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]
    # 木の併合、入力は併合したい各ノード
    def Unite(self, x, y):
        # 入力ノードのrootノードを見つける
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        # すでに同じ木に属していた場合
        if(x == y):
            return 
        # 違う木に属していた場合rnkを見てくっつける方を決める
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            # rnkが同じ（深さに差がない場合）は1増やす
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    # xとyが同じグループに属するか判断
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    # ノードxが属する木のサイズを返す
    def Count(self, x):
        return -self.root[self.Find_Root(x)]

n,m,k=map(int,input().split())
twi=UnionFind(n)
ans=[-1 for i in range(n+1)]
for i in range(m):
    a,b=map(int,input().split())
    twi.Unite(a,b)
    ans[a]-=1
    ans[b]-=1

for i in range(1,n+1):
    ans[i]+=twi.Count(i)

for i in range(k):
    c,d=map(int,input().split())
    if twi.isSameGroup(c,d):
        ans[c]-=1
        ans[d]-=1

for i in range(1,n):
    print(ans[i],end=" ")
print(ans[n])

Measured memory_bytes: 9424
n, m, c = [int(i) for i in input().split(" ")]
a_list = input().split(" ")
ia = 0

for i in range(n):
    b_list = input().split(" ")
    ans = c
    for j in range(m):
        ans += int(a_list[j]) * int(b_list[j])
    if ans > 0:
        ia += 1

print(ia)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long int
#define pll pair<ll, ll> 
#define pii pair<int, int> 
#define ff first
#define ss second
#define mp make_pair
#define pb push_back

using namespace std;

ll MOD = 1e9+7;

ll pwr(ll x, ll y) {
	ll res = 1;
	x = x%MOD;
	while (y > 0) {
		if (y&1) res = (res*x)%MOD;

		y = y>>1;
		x = (x*x)%MOD;
	}
	return res;
}

inline ll addmod(ll a, ll b){
	return ((a+b)%MOD);
}

inline ll mulmod(ll a, ll b){
	return ((a*b)%MOD);
}

class BIT {
	int *bit;
	int N;

public:
	void update(int x, int val) {
		int ind = x;
		while (ind <= N) {
			bit[ind] += val;
			ind += (ind & (-ind));
		}
	}

	BIT(int ar[], int n) {
		bit = new int[n+1];
		N = n+1;
		for (int i = 1; i < N; i++) bit[i] = 0;
		for (int i = 1; i < N; i++) update(i, ar[i-1]);
	}

	int getSum(int x) {
		if (x < 0) return 0;

		int ind = x+1;
		int sum = 0;
		while (ind > 0) {
			sum += bit[ind];
			ind = (ind & (ind-1));
		}
		return sum;
	}

	int getValue(int x) {
		return getSum(x) - getSum(x-1);
	}

	void changeElem(int x, int val) {
		update(x+1, val-getValue(x));
	}
};

int bsh(int val, int ar[], int n) {		// return ind such that val >= ar[ind] and val < ar[ind+1]
	int a = 0, b = n - 1, c = (a+b)/2;
	if (val < ar[0]) return -1;
	if (val >= ar[b]) return b;

	while (!(val >= ar[c] && val < ar[c+1])) {
		if (val < ar[c]) b = c;
		else {
			if (b-a == 1 && c == a) a = b;
			else a = c;
		}
		c = (a+b)/2;
	}
	return c;
}

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

	int h, w, k;
	cin >> h >> w >> k;
	int tot = 0;
	vector<int> bl[h];
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			char c; cin >> c;
			if (c == '#') {
				tot++;
				bl[i].pb(j);
			}
		}
	}
	int ans = 0;
	for (int i = 0; i < (1 << h); i++) {
		for (int j = 0; j < (1 << w); j++) {
			int black = 0;
			for (int ch = 0; ch < h; ch++) {
				if (!(i&(1<<ch))) continue;
				for (int l = 0; l < bl[ch].size(); l++) {
					if ((1<<bl[ch][l])&j) black++;
				}
			}
			if (black == k) ans++;
		}
	}
	cout << ans << endl;
}



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

const int MO=1e9+7;
const int M=1e5+5;

inline int add(int x,int y)
{
	x+=y;
	if(x>=MO) x-=MO;
	return x;
}
inline int sub(int x,int y)
{
	x-=y;
	if(x<0) x+=MO;
	return x;
}
inline int mul(int x,int y)
{
	return (1LL*x*y)%MO;
}

int n,k;
vector<int> g[M];

int fa[M],inv[M],ifa[M];

void init()
{
	fa[0]=ifa[0]=1;
	inv[1]=fa[1]=ifa[1]=1;
    for(int i=2;i<M;i++)
    {
    	fa[i]=mul(fa[i-1],i);
    	inv[i]=mul((MO-MO/i),inv[MO%i]);
    	ifa[i]=mul(inv[i],ifa[i-1]);
    }
}

inline int A(int n,int m)
{
	if(m>n) return 0;
	if(n<0||m<0) return 0;
	//cout<<"! "<<n<<" "<<m<<endl;
	return mul(fa[n],ifa[n-m]);
}

int dfs(int u,int fa)
{
	int cnt=g[u].size()-(fa?1:0);
	int ans=A(k-1-(fa?1:0),cnt);
	//cout<<u<<" "<<ans<<endl;
	for(int v:g[u])
	{
		if(v==fa) continue;
		ans=mul(ans,dfs(v,u));
	}
	//cout<<u<<" "<<ans<<endl;
	return ans;
}

int main()
{
	init();
	scanf("%d%d",&n,&k);
	int u,v;
	for(int i=1;i<n;i++)
	{
		scanf("%d%d",&u,&v);
		g[u].push_back(v);
		g[v].push_back(u);
	}
	printf("%d\n",mul(k,dfs(1,0)));
	return 0;
}

Measured memory_bytes: 11520
#include<iostream>

using namespace std;

bool dice4(int* d,int* e){ 

        int tmp;
        for ( int i = 0; i < 4; i++){
                tmp = d[0]; d[0] = d[1]; d[1] = d[5]; d[5] = d[4]; d[4] = tmp;  //N 

                for ( int i = 0; i< 4; i++){
                        if(d[0] == e[0] and d[1] == e[1] and d[2] == e[2] and d[3] == e[3] and d[4] == e[4] and d[5] == e[5]){
                                return true;
                        }   
                        tmp = d[1]; d[1] = d[2]; d[2] = d[4]; d[4] = d[3]; d[3] = tmp; //spin
                }   
        }    
        tmp = d[0]; d[0] = d[3]; d[3] = d[5]; d[5] = d[2]; d[2] = tmp; //E 
        for ( int i = 0; i< 4; i++){
                if(d[0] == e[0] and d[1] == e[1] and d[2] == e[2] and d[3] == e[3] and d[4] == e[4] and d[5] == e[5]){
                                return true;
                }   
                tmp = d[1]; d[1] = d[2]; d[2] = d[4]; d[4] = d[3]; d[3] = tmp; //spin
        }   
        tmp = d[0]; d[0] = d[3]; d[3] = d[5]; d[5] = d[2]; d[2] = tmp; //E 
        tmp = d[0]; d[0] = d[3]; d[3] = d[5]; d[5] = d[2]; d[2] = tmp; //E 
        for ( int i = 0; i< 4; i++){
                if(d[0] == e[0] and d[1] == e[1] and d[2] == e[2] and d[3] == e[3] and d[4] == e[4] and d[5] == e[5]){
                                return true;
                }   
                tmp = d[1]; d[1] = d[2]; d[2] = d[4]; d[4] = d[3]; d[3] = tmp; //spin
        }   
        return false;
}

int main(){
        int n; cin >> n;
        int D[100][6];
        for ( int i = 0; i < n; i++){
                for ( int j = 0; j < 6; j++){
                        cin >> D[i][j];
                }   
        }   
        for ( int k = 0; k < n; k++){
                for ( int l = k + 1; l < n; l++){ 
                        if (dice4(D[k],D[l])){
                                cout << "No" << endl;
                                return 0;
                        }   
                }   
        }   
        cout << "Yes" << endl;
        return 0;
}

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

int main() {
    int x, y, z;
    int k, s;
    int sum = 0;
    int count = 0;
    cin >> k >> s;
    
// s = x+y+z;
    for(x=0;x<=s;x++){
        if(x>k){
            continue;
        }
        for(y=0;y<=s;y++){
            if(y>k){
                break;
            }
            z = s-x-y;
            if((z>=0) && (z<=k)){
                count++;
            }
        }
    }

    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdint>
#include<map>
#include<vector>

int const MAXN = 2e5;
int64_t N, X, D;
typedef std::vector<std::pair<int64_t, int64_t>> IA;

int64_t calc() {
  int64_t res;
  if(D == 0) {
    if(X == 0) return 1;
    return N+1;
  }
  if(D < 0) { D = -D; X = -X; }
  std::map<int64_t, IA> m;
  for(int64_t k = 0; k <= N; ++k) {
    // S = kX + jD where j in [k(k-1)/2, k(2N-1-k)/2]
    int64_t rem = (k*X%D+D)%D;
    int64_t l = k*X/D + k*(k-1)/2;
    int64_t r = k*X/D + k*(N+N-k-1)/2;
    m[rem].emplace_back(l, r);
  }
  int64_t ans = 0;
  for(auto ia: m) {
    IA& v = ia.second;
    std::sort(v.begin(), v.end());
    int64_t last = -1e18;
    for(auto iv: v) {
      ans += std::max(iv.second - std::max(iv.first, last) + 1, (int64_t)0);
      last = std::max(last, iv.second+1);
    }
  }
  return ans;
}

int main() {
  std::cin >> N >> X >> D;
  std::cout << calc() << std::endl;
  return 0;
}



Measured memory_bytes: 22144
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 17;
int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<n;i++)
#define Se second
#define Fi first

const int MX = 300005;
const int MM = 1000000007;

int X[MX], T[MX];
pii D[MX];

int main()
{
	int N, L;
	scanf("%d%d", &N, &L);
	for(int i = 1; i <= N; i++) scanf("%d", X+i);
	for(int i = 1; i <= N; i++) scanf("%d", T+i);

	ll ans = 0;
	for(int i = 1; i <= N; i++){
		ans += T[i] / (2*L);
		T[i] %= (2*L);
	}

	for(int i = 1; i <= N; i++){
		pii c = pii(0, 0);
		if(T[i] <= (L-X[i])*2) c.first = 1;
		if(T[i] <= X[i]*2) c.second = 1;
		if(T[i] == 0) c = pii(0, 0);
		if(c == pii(0, 0) && T[i]) ans++;
		D[i] = c;
	}
	
	int mn = 1e9;
	int s = 0, e = N, m1, m2;
	while(s <= e){
		auto f = [&](int v){
			int cur = 0, ans = 0, rm = v;
			for(int j = 1; j <= N; j++){
				int f, s;
				tie(f, s) = D[j];
				if(cur == 0) cur++, ans++;
				if(f && s){
					if(rm) --rm, cur++, ans++;
					else cur--;
				}
				else if(f) cur--;
				else if(s) cur++, ans++;
			}
			return ans;
		};
		m1 = (s*2+e)/3;
		m2 = (s+e*2+1)/3;
		int v1 = f(m1), v2 = f(m2);
		mn = min({mn, v1, v2});
		if(v1 <= v2) e = m2-1;
		else s = m1+1;
	}
	printf("%lld\n", (ans+mn) * (2*L));
}


Measured memory_bytes: 4992
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace kyoupuro {

    class MainClass {

        public static void Main() {
            var a = Input.NextInt();
            var b = Input.NextInt();
            var c = Input.NextInt();
            var d = Input.NextInt();

            Console.WriteLine(Math.Max(0, Math.Min(b, d) - Math.Max(a, c)));
        }
    }

    class Input {
        static IEnumerator<string> enumerator = new string[] { }.AsEnumerable().GetEnumerator();

        public static string Line() {
            return Console.ReadLine();
        }

        public static int NextInt() {
            while (!enumerator.MoveNext()) {
                enumerator = StrArr().AsEnumerable().GetEnumerator();
            }
            return int.Parse(enumerator.Current);
        }

        public static long NextLong() {
            while (!enumerator.MoveNext()) {
                enumerator = StrArr().AsEnumerable().GetEnumerator();
            }
            return long.Parse(enumerator.Current);
        }

        public static string[] StrArr() {
            return Line().Split(' ');
        }

        public static List<int> IntList() {
            return StrArr().Select(int.Parse).ToList();
        }

        public static List<long> LongList() {
            return StrArr().Select(long.Parse).ToList();
        }

        public static void Skip(int line = 1) {
            enumerator.Reset();
            for (int i = 0; i < line; i++) Console.ReadLine();
        }

        public static void Reset() {
            enumerator.Reset();
        }
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

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

using namespace std;
int dx[4]={0,0,-1,1},dy[4]={-1,1,0,0};
int solve(vector<vector<int> > field,int h,int w,int y,int x,int steps){
  if(steps>=10) return 100;
  int answer=100;
  REP(i,4){
    if(y+dy[i]<0||h<=y+dy[i]||x+dx[i]<0||w<=x+dx[i]||field[y+dy[i]][x+dx[i]]==1) continue;
    else{
      int tmpx=x,tmpy=y;
      while(0<=tmpy&&tmpy<h&&0<=tmpx&&tmpx<w&&field[tmpy][tmpx]==0){
	tmpy+=dy[i];
	tmpx+=dx[i];
      }
      if(tmpy<0||h<=tmpy||tmpx<0||w<=tmpx) continue;
      if(field[tmpy][tmpx]==3) return 1;
      if(field[tmpy][tmpx]==1){
	vector<vector<int> > newfield;
	newfield.resize(h);
	REP(j,h){
	  newfield[j].resize(w);
	  REP(k,w)
	    newfield[j][k]=field[j][k];
	}
	newfield[tmpy][tmpx]=0;
	answer=min(answer,solve(newfield,h,w,tmpy-dy[i],tmpx-dx[i],steps+1)+1);
      }
    }
  }
  return answer;
}
int main(void)
{
  for(;;){
    int w,h;
    cin >> w >> h;
    if(!w&&!h) return 0;
    vector<vector<int> > field;
    field.resize(h);
    REP(i,h){
      field[i].resize(w);
      REP(j,w){
	cin >> field[i][j];
      }
    }
    int x,y;
    REP(i,h){
      REP(j,w){
	if(field[i][j]==2){
	  y=i;
	  x=j;
	  field[i][j]=0;
	}	  
      }
    }
    int answer=solve(field,h,w,y,x,0);
    if(answer>10) answer=-1;
    cout << answer << endl;
  }
}

Measured memory_bytes: 1348