akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author dyominov
 */
public class Main {
  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    InputReader in = new InputReader(inputStream);
    PrintWriter out = new PrintWriter(outputStream);
    BKEYENCEString solver = new BKEYENCEString();
    solver.solve(1, in, out);
    out.close();
  }

  static class BKEYENCEString {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
      String s = in.next();
      String key = "keyence";
      char[] arr = s.toCharArray();
      char[] arr2 = key.toCharArray();
      char[] res = new char[arr2.length];
      int index = arr.length - 1;
      int i = arr2.length - 1;
      while (i >= 0 && index >= 0 && arr[index] == arr2[i]) {
        res[i] = arr2[i];
        index--;
        i--;
      }
      i = 0;
      index = 0;
      while (i < arr2.length && index < arr.length && arr[index] == arr2[i]) {
        res[i] = arr2[i];
        index++;
        i++;
      }
      out.println(Arrays.equals(arr2, res) ? "YES" : "NO");

    }

  }

  static class InputReader implements AutoCloseable {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
      reader = new BufferedReader(new InputStreamReader(stream), 32768);
      tokenizer = null;
    }

    public String next() {
      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public void close() {
    }

  }
}



Measured memory_bytes: 23380
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int64_t h, m, l, k;
    cin >> h >> m >> l >> k;

    if (k % 2 == 1){
        if (abs(h - m) < pow(10, 18)){
            cout << m - h << endl;
        }    
        else{
            cout << "Unfair" << endl;
        }
    }
    else{
        if (abs(h - m) < pow(10, 18)){
            cout << h - m << endl;
        }    
        else{
            cout << "Unfair" << endl;
        }
    }
}

Measured memory_bytes: 256
/*Author
   SaJiB */

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


#define pb   push_back
#define fi   first
#define se   second
#define all(x)    x.begin(),x.end()

#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))

typedef long long int ll;
typedef unsigned long long int ull;
const double pi = 2.0*acos(0.0);

char small[26] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'} ;

ll big_mod(ll BASE, ll POWER, ll MOD){

    if(POWER == 0) return 1;
    else if(POWER %2 ==0){
        ll RESULT = big_mod(BASE,POWER/2,MOD);
        return ((RESULT % MOD)*(RESULT % MOD))% MOD;
    }
    else return ((BASE % MOD)*(big_mod(BASE,POWER-1,MOD)% MOD))% MOD;

}

int main(){

string a,b;
cin>>a>>b;
int check = 0;
for(int i = 0 ; i < a.size();i++){
    if(a[i] != b[i]) check++;
}

cout<<check<<endl;

}



Measured memory_bytes: 3896
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#include<map>
#include<iostream>
#include<cmath>
#include<functional>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main(){
   int a;
   cin >> a;
   cout << a + a * a + a * a * a << endl;
}

Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>
#include <climits>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>

#define barsik ios::sync_with_stdio(false)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)

typedef long long ll;
typedef std::vector<int> vi;
typedef std::pair <int, int> pii;
typedef std::unordered_set <int> u_si;

using namespace std;

int ar[500500], a[500500];

void solve(){
    int n;
    cin >> n;
    
    int cnt = 0;
    for(int i = 0; i < n; i++){
        char x;
        cin >> x;
        if(x == 'E'){
            cnt++;
            ar[i] = 1;
        }
        a[i] = cnt;
    }
    int ans = INT_MAX;
    for(int i = 0; i < n; i++){
        int tmp = i + 1 - a[i] + a[n - 1] - a[i];
        if(a[i] == 0) tmp -= 1;
        ans = min(ans, tmp);
    }
    cout << ans;
}

int main(){
    barsik;
    int q = 1;

    //cin >> q;

    for(int i = 1; i <= q; i++){
//        cout << "Case " << i << ": ";
        solve();
    }
}


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

int main()
{
   long long n ;
   cin>>n ;
   vector<vector<int>> vec(n,vector<int>(2,0)) ;
   long long x,y ;
   for(int i=0;i<n;i++)
   {
       cin>>vec[i][0]>>vec[i][1] ;
   }
   string ans="No" ;
   for(int i=0;i<n-2;i++)
   {
      if(vec[i][0]==vec[i][1] && vec[i+1][0]==vec[i+1][1] && vec[i+2][0]==vec[i+2][1])
      {
          ans="Yes" ;
          break ;
      }
   }
   cout<<ans<<endl ;
    return 0;
}


Measured memory_bytes: 3640
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
#define Max 1000005
bool vis[Max];
int prime[Max],cnt;
void print_prime()
{
    memset (vis,false,sizeof (vis));
    for (long long i=2;i<=sqrt(Max);i++)
        if (!vis[i])
        for (long long j=i*i;j<=Max;j+=i)
        vis[j]=true;
    for (long long i=2;i<=Max;i++)
        if (!vis[i])
        prime[cnt++]=i;
}
int main()
{
    print_prime();
    int n;
    while (scanf("%d",&n)!=EOF) {
        int i=0;
        while (prime[i]<=n) {
            i++;
        }
        printf("%d\n",i);
    }
    return 0;
}

Measured memory_bytes: 4400
package main

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

func stringsToInts(s, sep string) []int {
	ss := strings.Split(s, sep)
	ints := make([]int, 0)
	for _, c := range ss {
		i, err := strconv.Atoi(c)
		if err != nil {
			continue
		}
		ints = append(ints, i)
	}
	return ints
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	for scanner.Scan() {
		line := scanner.Text()
		ints := stringsToInts(line, " ")
		a, b := ints[0], ints[1]
		switch {
		case a < b:
			fmt.Println("a < b")
		case a > b:
			fmt.Println("a > b")
		case a == b:
			fmt.Println("a == b")
		default:
			continue
		}
	}

	if err := scanner.Err(); err != nil {
		// log.Println(err)
		return
	}
}



Measured memory_bytes: 1104
def abc042_c():
    price, len_hate_set = map(int, input().split())
    hate_set = set([int(i) for i in input().split()])

    while True:
        if all(map(lambda x: int(x) in set(range(0, 10)) - hate_set,
                   [int(str(price)[i]) for i in range(len(str(price)))])) and price >= price:
            return price

        price += 1


if __name__ == '__main__':
    print(abc042_c())


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int INF = 1000000007;
 
 
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
 
  int N;
  cin >> N;
  pair<double, double> P[N];
  for(int i=0;i<N;i++){
    cin >> P[i].first >> P[i].second;
  }
  double ans = 0.0;
  double count = 1;
  sort(P, P+N);
  do {
    for(int i=0;i<N-1;i++){
      double dx = P[i+1].first - P[i].first;
      double dy = P[i+1].second - P[i].second;
      ans += sqrt(dx*dx + dy*dy);
    }
  }while (next_permutation(P, P+N));

  for(int i=2;i<=N;i++){
    count *= i;
  }

  ans /= count;

  cout << fixed << setprecision(10);
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        try {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            String str = br.readLine();
            int alp[] = new int[26];
            for (int i = 0; i < str.length(); i++) {
                int index = (int)str.charAt(i) - 97;
                alp[index]++;
            }
            boolean flag = false;
            for (int i = 0; i < 26; i++) {
                if (alp[i] == 0) {
                    System.out.println((char)(i + 97));
                    flag = true;
                    break;
                }
            }
            if (!flag) {
                System.out.println("None");
            }
        } catch (IOException e) {
            e.printStackTrace();
           }
    }
}


Measured memory_bytes: 23124
def calc(a, b):
    if a <= 0 or b <= 0:
        return 0
    if a == b:
        return a
    a, b = min(a, b), max(a, b)
    x = max(1, b / (2 * a))
    return calc(b-x*a, a) + 2 * a * x

N, X = map(int, raw_input().split())
print calc(X, N-X) + N 


Measured memory_bytes: 2568
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
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; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;
const double PI = 3.1415926535897932;
const int MOD = 1e9 + 7;

//cin.tie(0);ios::sync_with_stdio(false);
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  int cnt = 0;
  rep (i, n) {
    cin >> a[i];
    if (a[i] < 0) cnt++;
  }

  ll sum = 0;
  rep (i, n) sum += abs(a[i]);

  ll min = INF;
  if (cnt % 2 != 0) {
    rep (i, n) {
      if (abs(a[i]) < min) min = abs(a[i]);
    }
    sum -= (min * 2);
  }

  cout << sum << endl;

  
  return 0;
}


Measured memory_bytes: 3716
<?php
    $num_a = intval(trim(fgets(STDIN)));
    $array_a = array_map('intval',explode(" ",trim(fgets(STDIN))));
    $num_b = intval(trim(fgets(STDIN)));
    $array_b = array_map('intval',explode(" ",trim(fgets(STDIN))));
    
    $Ss=array_fill(0,2000,0);
    $ans_array=array_fill(0,$num_b,0);
    // echo decbin(1<<2);
    //選ばれる側の数字の数の総和まで$bitを増やすことで全bitの組み合わせができる
    for($bit=0; $bit<(1<<$num_a);$bit++){
        
        $sum=0;
        for($i=0;$i<$num_a;$i++){
            if($bit & (1<<$i)){
                // echo $bit." ".$i." ".$array_a[$i]."  ";
                $sum+=$array_a[$i];
            }
        }

        for($i=0;$i<$num_b;$i++){
            if($array_b[$i]== $sum){
                $ans_array[$i]=1;
            }
        }
    }
    for($i=0;$i<$num_b;$i++){
        if($ans_array[$i]==1){
            echo "yes\n";
        }else{
            echo "no\n";
        }
    }
    
?>


Measured memory_bytes: 9380
n,d=map(int,input().split())
x=[[int(a) for a in input().split(" ")] for _ in range(n)]
cnt=0
for i in range(n-1):
  for j in range(i+1,n):
    dis=0
    for k in range(d):
      dis+=(x[i][k]-x[j][k])**2
    if (dis**0.5).is_integer():
        cnt+=1
print(cnt)

Measured memory_bytes: 3188
#include<iostream>
#include<string>
#include<stdio.h>
#include<cctype>
#include<algorithm>
#include<climits>
#include<cmath>
#include<map>
#include<vector>
#define INF INT_MAX
using namespace std;

int cnt;

int main(){
	int L, R, d;
	cin >> L >> R >> d;
	for (int i = L; i <= R; i++){
		if (i%d == 0){
			cnt++;
		}
	}

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

Measured memory_bytes: 3596
#include<iostream>
#include<algorithm>
using namespace std;
int N;
long A[2<<17],B[2<<17];
main()
{
	cin>>N;
	for(int i=0;i<N;i++)cin>>A[i];
	for(int i=0;i<N;i++)cin>>B[i];
	long ans=0;
	for(int t=0;t<150;t++)
	{
		for(int i=t&1;i<N;i+=2)
		{
			long s=B[(i+N-1)%N]+B[(i+1)%N];
			long t=(B[i]-A[i])/s;
			ans+=t;
			B[i]-=t*s;
		}
	}
	for(int i=0;i<N;i++)
	{
		if(A[i]!=B[i])
		{
			cout<<-1<<endl;
			return 0;
		}
	}
	cout<<ans<<endl;
}

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

int main(){
    string data[] = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
    string s;cin >> s;
    for(int i=0;i<7;i++) if(data[i]==s) cout << 7-i << endl;
}

Measured memory_bytes: 3616
def digit_sum(n):
    res = 0
    while n > 0:
        res += n % 10
        n /= 10
    return res
k = int(raw_input())
snuke_num = 1
num_of_nums = 0
increment = 1
while num_of_nums < k:
    print snuke_num
    num_of_nums += 1
    candid = snuke_num + increment
    opponent = candid + increment
    if float(candid)/digit_sum(candid) > float(opponent) / digit_sum(opponent):
        increment *= 10
    snuke_num += increment

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

#define ll long long
#define pb push_back
#define vi vector<int>
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define sizeOf(A) (sizeof(A))/(sizeof(A[0]))
#define odd(x) ((x) % (2))
#define fastio ios_base::sync_with_stdio(false), cin.tie(0);

int main() {
    fastio;

    ll a, b;
    cin >> a >> b;
    cout << a*b <<"\n";
    return 0;
}


Measured memory_bytes: 3652
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();

		if (a > b) {
			for (int i = 0; i < a; i++) {
				System.out.print(b);
			}
		} else {
			for (int i = 0; i < b; i++) {
				System.out.print(a);
			}
		}

		sc.close();
	}
}

Measured memory_bytes: 35752
/*
मनस्वी म्रियते कामं कार्पण्यं न तु गच्छति ।
अपि निर्वाणमायाति नानलो याति शीतताम् ॥
*/

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long int
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define v2i vector<vector<int>>
#define v2l vector<vector<ll>>
#define ppi pair<int,int>
#define ppl pair<ll,ll>
#define vpi vector<ppi>
#define vpl vector<ppl>
#define all(x) x.begin(),x.end()
#define ii int,int 
#define ff first    
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define p2d(v) for(auto a:v){for(auto b:a)cout<<b<<" ";cout<<endl;}
#define p1d(v) for(auto a:v)cout<<a<<" ";cout<<endl;
#define ppd(v) for(auto a:v)cout<<a.ff<<" "<<a.ss<<endl;
#define imx INT_MAX
#define imn INT_MIN
#define inf 9000000000000000000
#define minf -inf
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse 
#define itr iterator 
#define pre cout<<fixed<<setprecision(10);
#define umap unordered_map
#define uset unordered_set
#define pi 3.141592653589793
#define MAXN 100005
#define test1(x) cout << #x " = " << x << endl;
#define test2(x,y) cout << #x " = " << x << " " << #y " = " << y << endl;
#define test3(x,y,z) cout << #x " = " << x << " " << #y " = " << y << " " << #z " = " << z << endl;
#define test4(w,x,y,z) cout << #w " = " << w << " " << #x " = " << x << " " << #y " = " << y << " " << #z " = " << z << endl;
const ll infinity = 9e18;

/*
#define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define MODM(a,b,md) ((a%md)*(b%md))%md
#define MODA(a,b,md) ((a%md)+(b%md))%md
#define ull unsigned long long int
*/

/*
bool compare(int a,int b) {return a > b;}
bool compare1(ppi a,ppi b) {return a.ff > b.ff;}
bool compare2(ppi a,ppi b) {return a.ss < b.ss;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;}
bool isprime(ll n){if(n < 2) return 0; ll i = 2; while(i*i <= n){if(n%i == 0) return 0; i++;} return 1;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/


int main()
{
    fast

/*
    #ifndef ONLINE_JUDGE
        freopen("input.txt",  "r",  stdin);
        freopen("output.txt", "w", stdout);
    #endif
//*/

        
    ll a,b;
    cin>>a>>b;

    ll ans = -1;

    for(ll i = 1; i <= 10000; i++)
    {
        ll x = ((8*i)/100);
        ll y = ((10*i)/100);

        if(x == a && y == b)
        {
            ans = i;
            break;
        }

    }

    cout<<ans;









    return 0;
}


Measured memory_bytes: 3660
#include<stdio.h>
int main(void){
	int i,n,price[10],max=0,sum=0;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d¥n",&price[i]);
		if(max<price[i]){
			max=price[i];
		}
	}
	for(i=0;i<n;i++){
		if(price[i]==max){
			price[i]=price[i]/2;
			max=100001;
		}
		sum+=price[i];
	}
	printf("%d",sum);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using vc = vector<char>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T>bool even(T n) { return ! (n & 1); }
template<class T>bool odd(T n) { return n & 1; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;} 
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        vllvll grid(3, vll(3));
        rep(i, 0, 3) rep(j, 0, 3) cin >> grid[i][j];
        vector<vector<bool>> is(3, vector<bool>(3, false));

        ll N;
        cin >> N;
        rep(i, 0, N) {
                ll b;
                cin >> b;
                rep(j, 0, 3) rep(k, 0, 3) {
                        if (grid[j][k] == b) is[j][k] = true;
                }
        }

        bool f1 = false;
        rep(i, 0, 3) if (is[i][0] and is[i][0] == is[i][1] and is[i][1] == is[i][2]) f1 = true;

        bool f2 = false;
        rep(i, 0, 3) if (is[0][i] and is[0][i] == is[1][i] and is[1][i] == is[2][i]) f2 = true;

        bool f3 = (is[0][0] and is[0][0] == is[1][1] and is[1][1] == is[2][2]) or (is[0][2] and is[0][2] == is[1][1] and is[1][1] == is[2][0]);

        if (f1 or f2 or f3) {
                cout << "Yes" << endl;
        } else {
                cout << "No" << endl;
        }
}

Measured memory_bytes: 3604
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
#include<tuple>
#include<stdio.h>
#include<set>

using namespace std;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)

#define shosu setprecision(10)
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Q;
typedef pair<Q,ll> R;
ll longinf=1ll<<60;
int inf=1<<29;
//mleしなければぜんぶllでかく。
//↑はあんまり気にしなくていい。
const ll MOD = 1e9+7;
const int index = 2*1e5+1;

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

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

ll power(ll a,ll b){
      if(b==0) return 1;
      else if(b%2==0){
            ll ret=power(a,b/2);
            return ((ret%MOD)*(ret%MOD))%MOD;
      }
      else return ((power(a,b-1)%MOD)*(a%MOD))%MOD;
}
ll dive(ll a,ll b){
      return ((a%MOD)*(power(b,MOD-2)%MOD))%MOD;
}

ll frac[index+1];
void calc(){ //main関数内にcalc();を入れること
      frac[0]=1;
      rep0(i,index){
            frac[i+1]=mul(frac[i],i+1);
      }
}

int main(){
      int n,m,k;
      cin>>n>>m>>k;
      ll ans=0;
      calc();
      rep0(i,n){
            ans+=mul( mul(mul(m,m),mul(i,n-i)) , dive( frac[m*n-2] , mul(frac[m*n-k],frac[k-2]) ) );
            ans%=MOD;
      }
      swap(n,m);
      rep0(i,n){
            ans+=mul( mul(mul(m,m),mul(i,n-i)) , dive( frac[m*n-2] , mul(frac[m*n-k],frac[k-2]) ) );
            ans%=MOD;
      }
      cout<<ans<<endl;
return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;

int main(){
    string s;
    cin >> s;
    int ans = 0;
    for(int i = 0; i < s.size(); i++){
        if(s.at(i) == '+'){
            ans++;
        } else {
            ans--;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
n,a,b,c,d = [int(x) for x in input().split()]
s = input()

if s[a-1:c].count("##") > 0 or s[a-1:d].count("##") > 0:
    print("No")
elif d < c:
    if s[b-2:d+1].count("..."):
        print("Yes")
    else:
        print("No")
else:
    print("Yes")

Measured memory_bytes: 3572
function Main(input) {
  //入力から変数を全て定義
  lines = input.split("\n");
  firstLine = lines[0].split(" ");
  N = +firstLine[0];
  X = +firstLine[1];
  secondLine = lines[1].split(" ");
  
  //跳ねた距離がX以下かどうか判定するための変数
  distanceTravelled = 0;
  //跳ねた回数を記録するための変数（初期値が１なのは、最初に０地点でバウンスするのを先に含めているから）
  numBounces= 1;
  
  //distanceTravelledに毎回バウンスする距離を足していき、
  //もし跳ねた先がまだX以下の距離ならカウントを足す。これをN回やる。
  for(i=0;i<N; i++){
    distanceTravelled += +secondLine[i];
    
    if(distanceTravelled <= X){
      numBounces += 1;
    }
  }
  
  console.log(numBounces);
  
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));



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

map<ll, ll> prime_factor(ll n)
{
  map<ll, ll> res;
  for (ll i=2; i*i<=n; i++) {
    while (n%i == 0) {
      ++res[i];
      n /= i;
    }
  }
  if (n != 1) res[n] = 1;
  return res;
}

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

ll modinv(ll a)
{
  ll b=mod, x=1, y=0;
  while (b) {
    ll t = a/b;
    a -= t*b; swap(a, b);
    x -= t*y; swap(x, y);
  }
  x %= mod;
  if (x<0) x += mod;
  return x;
}

int main()
{
  ll n; cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  map<ll, ll> mp;
  rep(i, n) {
    map<ll, ll> tmp = prime_factor(a[i]);
    for (auto v:tmp) {
      if (mp[v.first] < v.second) mp[v.first] = v.second;
    }
  }
  ll lcm = 1;
  for (auto v:mp) lcm = (lcm * modpow(v.first, v.second)) % mod;
  ll ans = 0;
  rep(i, n) ans = (ans + (lcm * modinv(a[i])) % mod) % mod;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 896
#include<stdio.h>

int main(){
    int n, i, j, prime[200000], count;
    long long int sum;

    prime[0] = prime[1] = 1;
    for(i = 2; i < 200000; i++){
        if(prime[i] != 1){
            for(j = 2 * i; j < 200000; j += i) prime[j] = 1;
        }
    }

    while(scanf("%d", &n) != EOF){
        if(n == 0) break;
        count = sum = 0;

        for(i = 0; i < 200000; i++){
            if(prime[i] != 1){
                count++;
                sum += i;
                if(count == n) break;
            }
        }

        printf("%lld\n", sum);
    }
    return 0;
};

Measured memory_bytes: 1380
n = int(input())

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

lst = factorization(n)
res = 0
for elem1, elem2 in lst:
    cnt = 1
    if elem1 == 1:
        continue
    while elem2 >= cnt:
        elem2 -= cnt
        cnt += 1
        res += 1
print(res)

Measured memory_bytes: 9512
#include <stdio.h>

int main(){
    
    
    int n, i, flag, t, c;
    int a[100];
    scanf("%d", &n);
    
    flag = 1;
    c = 0;
    
    
    for (i = 0; i < n; ++i){
        scanf("%d", &a[i]);
    }
    
    while(flag) {
        flag = 0;
        
        for (i = n-1; i > 0; --i){
            if (a[i] < a[i-1]){
                t = a[i];
                a[i] = a[i-1];
                a[i-1] = t;
                flag = 1;
                c = c + 1;
            }
        }
    }
    
    for (i = 0; i < n; ++i){
        printf("%d",a[i]);
        if (i != n-1) {
            putchar(' ');
        }
        else{
            putchar('\n');
        }
    }
    
    printf("%d\n",c);
    
    return 0;
}

Measured memory_bytes: 1852
# coding: utf-8

N, M = (int(x) for x in input().split())

adj_list = [[] for i in range(N)]
for i in range(M):
	x, y, z = (int(x) for x in input().split())
	adj_list[x - 1].append(y - 1)
	adj_list[y - 1].append(x - 1)

searched = [False] * N
count = 0
for i in range(N):
	if searched[i] == True:
		continue

	count += 1
	stack = [i]
	searched[i] = True
	while len(stack) > 0:
		node = stack.pop()	
		for n in adj_list[node]:
			if searched[n] == False:
				stack.append(n)
				searched[n] = True

print(count)

Measured memory_bytes: 23624
#include <bits/stdc++.h>
using namespace std;
int main(void){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(15);
    int mod = 1000000007;

    int n;
    cin>>n;
    vector<int> a(n);

    long long sum=0;
    for(int i=0; i<n; i++){
        cin>>a[i];
        sum+=a[i];
        sum%=mod;
    }
    
    long long ans=0;
    for(int i=0; i<n; i++){
        sum-=a[i];
        if(sum<0)   sum+=mod;
        ans+=a[i]*sum;
        ans%=mod;
    }
    
    cout<<ans<<endl;
    return 0;
}

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

int main() {
	string str;
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == '0') {
			str.push_back('0');
		}
		if (s[i] == '1') {
			str.push_back('1');
		}
		if (s[i] == 'B'&&str.size()!=0) {
			str.pop_back();
		}
	}
	cout << str;
	return 0;
}

Measured memory_bytes: 256
/*  TAHMID RAHMAN
    DAMIAN FOREVER
     MATH LOVER
    NEVER GIVE UP
*/
#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define pb push_back
#define fi first
#define se second
#define in insert
#define mp make_pair
#define GCD(a,b) __gcd(a,b);
#define endl "\n"
#define FRU freopen("out.txt","w",stdout)
#define FRO freopen("in.txt","r",stdin)
#define INFLL 9223372036854775807
#define debug 0
#define MAXN   100001
//Don't hesitate to ask me if you don't understand my code.......Happy coding,Tahmid...;
ll a[MAXN]={0};
int main()
{
    fastio;
    ll n,i,t,sum=0,k,co,f;
    cin>>n;
    vector<ll>v(n);
    for(i=0;i<n;i++)
    {
        cin>>v[i];
        sum+=v[i];
        a[v[i]]++;
    }
    cin>>t;
    vector<pair<ll,ll>>p(t);
    for(i=0;i<t;i++)
    {
        ll x,y;
        cin>>x>>y;
        p[i]=mp(x,y);
    }
  //  cout<<sum<<endl;
  sort(v.begin(),v.end());
    for(i=0;i<t;i++)
    {
        co=a[p[i].fi];
       // ll z,c;
        //z=lower_bound(v.begin(),v.end(),p[i].fi)-v.begin();
        //c=upper_bound(v.begin(),v.end(),p[i].fi)-v.begin();
        //cout<<c-z<<endl;
        a[p[i].se]+=co;
        a[p[i].fi]=0;
        sum-=co*p[i].fi;
        sum+=co*p[i].se;
        cout<<sum<<endl;
        //cout<<a[2];

    }

    if(debug)
    {
        for(auto z:p)
        {
            cout<<z.fi<<" "<<z.se<<endl;
        }
    }
}


Measured memory_bytes: 6408
from fractions import gcd
a,b,c,d=map(int,input().split())

ans=0
gc=int(c*d/gcd(c,d))

if a%c==0:
    ans-=1
if a%d==0:
    ans-=1
if a%gc==0:
    ans+=1

ans+=(b-a+1)-(b//c+b//d-a//c-a//d-b//gc+a//gc)

print(ans)

Measured memory_bytes: 63980
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<climits>
#include<set>
#include<utility>
using namespace std;
typedef long long int ll;
const ll MOD=1e9+7;

int main(){

  int n;
  cin >> n;
  if(n%10==9){
    cout << "Yes" << endl;
  } else {
    n/=10;
    if(n==9){
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }

	return 0;
}


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

#define N 2000000

int A[N];
int H;

void maxHeapify(int);
void build();
void swap(int *, int *);

int main(){
  char com[10];
  int num;
  int end=0;
  int i;

  while(1){
    scanf("%s",com);

    switch(com[0]){
    case 'i':
      scanf("%d",&num);
      H++;
      A[H] = num;

      i=H;
      while(i > 1 && A[i/2] < A[i]){
	swap(&A[i/2], &A[i]);
	i = i/2;
      }
      
      break;

    case 'e':
      if(com[1] == 'x'){
	printf("%d\n",A[1]);

	A[1] = A[H];
	H--;

	maxHeapify(1);
      }

      if(com[1] == 'n')
	end++;
      
	break;
    }
    
    if(end>0)
      break;
  }
}

void maxHeapify(int i){
  int l = 2*i;
  int r = 2*i + 1;
  int largest;

  if(l <= H && A[l] > A[i])
    largest = l;

  else
    largest = i;

  if(r <= H && A[r] > A[largest])
    largest = r;

  if(largest != i){
    swap(&A[i], &A[largest]);
    maxHeapify(largest);
  }
}

void build(){
  int i;

  for(i=H/2; i>0; i--)
    maxHeapify(i);
}

void swap(int *a, int *b){
  int tmp;

  tmp = *a;
  *a = *b;
  *b = tmp;
}



Measured memory_bytes: 5684
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc=new Scanner(System.in);
        int s=sc.nextInt();
        if(s/100<=12 && s%100<=12 && s/100>0 && s%100>0)
            System.out.println("AMBIGUOUS");
        else if(s/100<=12 && s/100>0)
            System.out.println("MMYY");
        else if(s%100<=12 && s%100>0)
            System.out.println("YYMM");
        else
            System.out.println("NA");
    }
}


Measured memory_bytes: 21844
import numpy as np
n=int(input())
A=list(map(int,input().split()))
C=A
A=np.array(A)
length=len(format(max(A),"b"))

B=""
for i in range(length):
    cnt=np.count_nonzero(A&1)
    if cnt%2==0:B +="0"
    else:B +="1"
    A >>=1

B=int(B[::-1],2)
D=[]
for i in C:
    D.append(B^i)
print(*D)

Measured memory_bytes: 50068
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c,k;
  cin>>a>>b>>c>>k;
  if(a>=k){
    cout<<k;
  }else if(a+b>=k){
    cout<<a;
  }else{
    cout<<a-k+a+b;
  }
}


Measured memory_bytes: 3632
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <deque>
#include <stack>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define DEBUG(x) cout << (#x) << ": " << (x) << endl
#define DEBUG_VEC(v)            \
    cerr << #v << ": ";         \
    REP(__i, (v).size())        \
    cerr << ((v)[__i]) << ", "; \
    cerr << endl

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

int main()
{
    ios::sync_with_stdio(false);
    int N, M, C;
    cin >> N >> M >> C;
    vi B(M); REP(i, M) cin >> B[i];
    int ans = 0;

    REP(i, N) {
        vi A(M); REP(i, M) cin >> A[i];
        int tmp = C;
        REP(i, M) {
            tmp += A[i] * B[i];
        }
        if (tmp > 0) ans++;
    }

    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // long long64_t, long long*_t
#include <cstdio> // prlong longf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip> //setprecision
#include <limits>
using namespace std;
int main(){
    int s,w;
    cin >> s >> w;
    if(w>=s) cout << "unsafe" << endl;
    else cout << "safe" << endl;
}


Measured memory_bytes: 3636
N, M, X = map(int, input().split())
U = [list(input().split()) for i in range(N)]

search = []
costs = []

for i in range(2 ** N):
    B = []
    for j in range(N):
        if ((i >> j) & 1):
            B.append(j)
    search.append(B)

for i in search:
    sum = [0 for t in range(M)]
    for k in range(M):
        for j in i:
            sum[k] += int(U[j][k + 1])

    if min(sum) >= X:
        cost = 0
        for l in i:
            cost += int(U[l][0])
        costs.append(cost)

if len(costs) == 0:
    print(-1)
else:
    print(min(costs))


Measured memory_bytes: 9640
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
bool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } }
bool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } }

long mod = 10^^9 + 7;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{	
	auto N = RD;
	auto K = RD;
	auto S = RD!string;

	long[] cnts;
	long cnt;
	char last = S[0];
	foreach (c; S)
	{
		if (c != last)
		{
			cnts ~= cnt;
			cnt = 1;
			last = c;
		}
		else
		{
			++cnt;
		}
	}
	cnts ~= cnt;

	long eo = S[0] == '0' ? 0 : 1;
	long len = cnts.length / 2;
	len += eo == 0 ? cnts.length % 2 : 0;

	auto dp = new long[](max(1, len-K+1));
	dp[0] = eo == 1 ? cnts[0] : 0;
	foreach (i; 0..K)
	{
		auto j = i * 2 + eo;
		if (j < cnts.length)
			dp[0] += cnts[j];
		if (j+1 < cnts.length)
			dp[0] += cnts[j+1];
	}

	long ans = dp[0];
	foreach (i; 1..dp.length)
	{
		dp[i] = dp[i-1];
		
		auto j = (i-1) * 2 + eo;
		dp[i] -= cnts[j];
		if (j >= 1)
			dp[i] -= cnts[j-1];

		auto k = (i+K-1) * 2 + eo;
		if (k < cnts.length)
			dp[i] += cnts[k];
		if (k+1 < cnts.length)
			dp[i] += cnts[k+1];

		ans = max(ans, dp[i]);
	}

	debug writeln(cnts);
	debug writeln(dp);
	
	writeln(ans);
	stdout.flush();
	debug readln();
}

Measured memory_bytes: 3324
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def main():
    N, X, *xn = map(int, open(0).read().split())
    ans = None
    for x in xn:
        if ans is not None:
            if abs(X - x) % ans:
                ans = gcd(ans, abs(X - x))
        else:
            ans = abs(X - xn[0])
    print(ans)
    return


main()


Measured memory_bytes: 14052
n = int(input())
L = [int(_) for _ in input().split()]
L.sort()
total = 100000000000000000
num = 0
if L[0] == L[-1]:
    print(0)
else:
    for l in range(L[0], L[-1]):
        tot = 0
        for j in range(n):
            tot += abs(L[j] - l)**2
        if tot < total:
            num = l
            total = tot
            
    print(total)

Measured memory_bytes: 3064
from typing import List


class DSU:
    def __init__(self, n: int) -> None:
        self._n = n
        self.parent_or_size = [-1] * n

    def merge(self, a: int, b: int) -> int:
        assert 0 <= a <= self._n
        assert 0 <= b <= self._n
        x, y = self.leader(a), self.leader(b)
        if x == y:
            return x
        if -self.parent_or_size[x] < -self.parent_or_size[y]:
            x, y = y, x
        self.parent_or_size[x] += self.parent_or_size[y]
        self.parent_or_size[y] = x
        return x

    def same(self, a: int, b: int) -> bool:
        assert 0 <= a <= self._n
        assert 0 <= b <= self._n
        return self.leader(a) == self.leader(b)

    def leader(self, a: int) -> int:
        assert 0 <= a < self._n
        if self.parent_or_size[a] < 0:
            return a
        result = self.leader(self.parent_or_size[a])
        self.parent_or_size[a] = result
        return result

    def size(self, a: int) -> int:
        assert 0 <= a <= self._n
        return -self.parent_or_size[self.leader(a)]

    def groups(self) -> List[List[int]]:
        leader_buf = [self.leader(i) for i in range(self._n)]
        group_size = [0] * self._n
        for i in leader_buf:
            group_size[i] += 1
        result = [[] for _ in range(self._n)]
        for i in range(self._n):
            result[leader_buf[i]].append(i)
        result = [i for i in result if i]
        return result



n, q = map(int, input().split())
uf = DSU(n)
for i in range(q):
    t, u, v = map(int, input().split())
    if t:
        print(int(uf.same(u, v)))
    else:
        uf.merge(u, v)


Measured memory_bytes: 88472
#include <bits/stdc++.h>
#define int long long
#pragma GCC optimize("O3,Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("avx,avx2,sse")
using namespace std;

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

    int n, k;
    cin >> n >> k;
    vector<int> arr(n);
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
    }
    sort(arr.begin(), arr.end());
    int tot = 0;
    for (int i = 0; i < k; i++) {
        tot += arr[i];
    }
    cout << tot << '\n';

    fflush(stdout);
    return 0;
}


Measured memory_bytes: 3664
N = int(input())
a = list(int(i) for i in input().split())
a.sort(reverse = True)
A, B = 0, 0

for i in range(N):
    if (i+1) % 2 == 1:
        A += a[i]
    else:
        B += a[i]
        
print(A-B)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
#include <set>
#define rep(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 long double ld;
typedef pair<int,int> P;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
//struct area

//function area

//main area
int main(){
    string s, t;
    cin >> s >> t;
    int ans = 10000000;
    rep(i, s.size()-t.size()+1){
        int count = 0;
        rep(j, t.size()){
            if(s[i+j]!=t[j]){
                count++;
            }
        }
        ans = min(ans, count);
    }
    cout << ans << endl;
}
/*



*/

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
long long n,k;
vector<int> a(200005);
int main()
{
	cin>>n>>k;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	vector<int> s;
	vector<int> ord(n+1,-1);
	int v=1;
	int c,l;
	while(ord[v]==-1)
	{
		ord[v]=s.size();
		s.push_back(v);
		v=a[v-1];
	}
	c=s.size()-ord[v];
	l=ord[v];
	if(k<l)
	{
		cout<<s[k];
	}
	else
	{
		k-=l;
		k%=c;
		cout<<s[k+l];
	}
	cout<<endl;
	return 0;
}


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

#define rep(i, n) REP(i, 0, n)
#define REP(i, x, n) for (int i = x; i < n; i++)
#define REP2(i, x, n) for (int i = x; i <= n; i++)
#define OP(x) cout << x << endl;
template<typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
typedef long long ll;
typedef long long int lli;

int main() {
    ll k, n; cin >> k >> n;
    vector<ll> a(n); rep(i, n) cin >> a[i];

    lli ans = k;
    rep(i, n){
        lli tmp = 0;
        if(i == 0){
           tmp = abs(a[n - 1] - a[i]);
        }else{
           tmp = abs((a[i - 1] + k) - a[i]);
        }
        ans = min(ans, tmp);
    }
    OP(ans);
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,v) for (int i = 0; i < v.size(); i++)
#define RREPALL(i,v) for (int i = v.size()-1; i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(v.begin(), v.end())
#define MIN_ELEMENT(v) min_element(v.begin(), v.end())
#define MAX_ELEMENT(v) max_element(v.begin(), v.end())
#define COUNT(v,n) count(v.begin(), v.end(), n)
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

int main()
{
    int n;
    ll ans = 0ll;
    cin>>n;
    vector<ll> a(n+1), b(n);
    REP(i,n+1) cin>>a[i];
    REP(i,n) cin>>b[i];
    REP(i,n) {
        if (a[i] > b[i]) {
            ans += b[i];
        } else {
            ans += a[i];
            int d = min(a[i+1], b[i] - a[i]);
            ans += d;
            a[i+1] -= d;
        }
    }
    cout<<ans<<endl;

    return 0;
}


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

int main()
{
int roop=1;
while (roop<=3){
	int h_in,m_in,s_in,h_out,m_out,s_out;
	cin >>h_in>>m_in>>s_in>>h_out>>m_out>>s_out;
	int sec;
	sec = s_out + m_out*60 + h_out*3600 - (s_in +m_in*60 + h_in*3600);

	cout << sec/3600	<<" ";
	cout << (sec%3600)/60	<<" ";
	cout << (sec%3600)%60	<<endl;
	roop=roop+1;
}
	return 0;
}
                                           

Measured memory_bytes: 1160
function Main(input){
    input=input.split("\n");  //ここまで必須
    var kosu=parseInt(input[0].length)-1;
    var kai=input[0].slice(kosu,kosu+1);

    if(input[0].slice(kosu,kosu+1)==3){console.log("bon")}
    else if(kai==0){console.log("pon")}
    else if(kai==1){console.log("pon")}
    else if(kai==6){console.log("pon")}
    else if(kai==8){console.log("pon")}
    else {console.log("hon")}
}
Main(require("fs").readFileSync("/dev/stdin","utf8"));

Measured memory_bytes: 29600
import math,fractions,sys
from collections import Counter
n = int(input())
x = [0] * n
y = [0] * n
h = [0] * n
tmp = 0
if n == 1:
    print(x[0],y[0],h[0])
    sys.exit()
def cal(i,j):
    for _ in range(n):
        if h[_] != 0:
            H = abs(i-x[_]) + abs(j-y[_]) + h[_]
            break
    for _ in range(n):
        h_tmp = max(H - abs(i-x[_]) - abs(j-y[_]),0)
        if h[_] != h_tmp:
            return -1
    return H                      
for i in range(n):
    x[i],y[i],h[i] = map(int,input().split())

for i in range(101):   #x
    for j in range(101):   #y
        if cal(i,j) != -1:
            print(i,j,cal(i,j))

Measured memory_bytes: 5048
package main

import(
    "fmt"
    "sort"
    "strings"
)



func main() {
    var n,k int
    fmt.Scan(&n,&k)
    ans := k
    for i:=1;i<n;i++{
        ans *= k-1
    }
    fmt.Println(ans)
}





// Pairsort
type Pair struct {
    first,second int64
}

type By func(p1, p2 *Pair) bool

func (by By) Sort(pairs []Pair) {
    ps := &pairSorter{
            pairs : pairs,
            by: by,
    }
    sort.Sort(ps)
}

type pairSorter struct {
    pairs []Pair
    by func(p1, p2 *Pair) bool
}

func (s *pairSorter) Len() int {
    return len(s.pairs)
}

func (s *pairSorter) Swap(i, j int) {
    s.pairs[i], s.pairs[j] = s.pairs[j], s.pairs[i]
}

func (s *pairSorter) Less(i, j int) bool {
    return s.by(&s.pairs[i], &s.pairs[j])
}

func first (p1, p2 *Pair) bool {
        return p1.first < p2.first
}

func second (p1, p2 *Pair) bool {
        return p1.second < p2.second
}
// end



func abs32(a int) int {
    if a<0{
        return -a
    }
    return a
}

func abs64(a int64) int64 {
    if a<0{
        return -a
    }
    return a
}

func min32(a, b int) int {
    if a >= b {
        return b
    }
    return a
}

func max32(a, b int) int {
    if a >= b {
        return a
    }
    return b
}

func min64(a, b int64) int64 {
    if a >= b {
        return b
    }
    return a
}

func max64(a, b int64) int64 {
    if a >= b {
        return a
    }
    return b
}

func gcd(a, b int64) int64 {
    if a % b == 0 {
        return b
    } else {
        return gcd(b, a%b)
    }
}

func lcm(a, b int64) int64 {
    return a / gcd(a, b) * b
}

func scanNums(len int) (nums []int){
    var num int
    for i:=0; i<len; i++{
        fmt.Scan(&num)
        nums = append(nums,num)
    }
    return
}

func scanNums64(len int) (nums []int64){
    var num int64
    for i:=0; i<len; i++{
        fmt.Scan(&num)
        nums = append(nums,num)
    }
    return
}

func scanString(len int) (str []string){
    var s string
    for i:=0; i<len; i++{
        fmt.Scan(&s)
        str = append(str,s)
    }
    return
}

func makeTwoNums(n,m int) ([][]int){
    Nums := make([][]int, n)
    for i:=0; i<n; i++{
        Nums[i] = make([]int, m)
    }
    return Nums
}

func sortString(s string) string{
    t := strings.Split(s, "")
    sort.Strings(t)
    return strings.Join(t, "")
}

func reverseString(s string) string{
    t := []rune(s)
    for i,j := 0, len(s)-1 ; i < j ; i, j = i+1, j-1 {
        t[i], t[j] = t[j], t[i]
    }
    return string(t)
}

func inside(h,w,H,W int) bool{
    if h>=0 && h<H && w>=0 && w<W{
        return true
    }
    return false
}


Measured memory_bytes: 640
a = input()
b = int(a)
sum = 0

for i in range(1, b+1):
    if i % 15 == 0:
        #print("Fizz Buzz!")
        sum += 0
    elif i % 3 == 0:
        #print("Fizz!")
        sum += 0
    elif i % 5 == 0:
        #print("Buzz!")
        sum += 0
    else:
        sum += i

print(sum)

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

int  main()
{
	string s; cin >> s;
	rep(i, 3)
	{
		if (s[i] == '1')
			s[i] += 8;
		else if (s[i] == '9')
			s[i] -= 8;
	}
	cout << s << endl;
	return (0);
}


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

    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine().ToCharArray();
            var T = Console.ReadLine();

            var answer = new List<string>();
            for(int i=0;i<=S.Length- T.Length; i++)
            {
                var tmpS = S.ToList().ToArray();
                for(int k =0;k<T.Length;k++)
                {
                    if (tmpS[i + k] == '?') tmpS[i + k] = T[k];
                    if (tmpS[i + k] != T[k]) break;
                }
                if(string.Concat(tmpS).Contains(T))
                {
                    answer.Add(string.Concat(tmpS).Replace('?', 'a'));
                }
            }

            if(!answer.Any())
            {
                Console.WriteLine("UNRESTORABLE");
                return;
            }
            answer.Sort();
            Console.WriteLine(answer.First());
        }
    }

Measured memory_bytes: 13268