akhauriyash/Code-Regression huggingface dataset:
package main

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

var sc = bufio.NewScanner(os.Stdin)

func readNextInt() int{
  sc.Scan()
  n, _ := strconv.Atoi(sc.Text())
  return n
}

func isPrime(n int) bool {
  flag := true
  if n == 1 {
    flag = false
  }else if n==2 {
    flag = true
  }else{
    for i:=2; i*i <= n; i++{
      if n%i == 0{
        flag = false
      }
    }
  }
  return flag
}

func main() {
  //sc.Split(bufio.ScanWords)
  datanum := readNextInt()
  var inputs []int
  output := 0

  for i:=0; i<datanum; i++{
    inputs = append(inputs,readNextInt())
  }

  for i :=0; i<datanum; i++{
    if isPrime(inputs[i]) {
      output++
    }
  }

  fmt.Println(output)
}



Measured memory_bytes: 1556
#include<bits/stdc++.h>
using namespace std;
int main() {
    int n;
    int d;
    cin>>n>>d;
    int cnt=0;
    while (n--) {
        long long x, y;
        cin>>x>>y;
        double ans = (sqrt(x*x + y*y));
        if (ceil(ans)<=d) cnt++;
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 3656
#include<iostream>
#include<vector>
#include<utility>
#include<string>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

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

}

Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int cmp_s(const void * left, const void * right)
{
	char *left_char = (char *)left;
  char *right_char = (char *)right;
  return strcmp(left_char, right_char);
}
int cmp_s2(const void * left, const void * right)
{
	char *left_char = (char *)left;
  char *right_char = (char *)right;
  return -strcmp(left_char, right_char);
}

int main(void){

  char s[101], t[101];
  scanf("%s %s", s, t);
	int s_length = strlen(s);
	int t_length = strlen(t);
	qsort(s, s_length, sizeof(char), cmp_s);
	qsort(t, t_length, sizeof(char), cmp_s2);
	if (strcmp(s,t) < 0) {
		printf("Yes\n");
	} else {
		printf("No\n");
	}

  return 0;
}

Measured memory_bytes: 128
const main = (inputs) => {
  var W = inputs[0].split(" ")[0]-0;
  var H = inputs[0].split(" ")[1]-0;
  var x = inputs[0].split(" ")[2]-0;
  var y = inputs[0].split(" ")[3]-0;

  var ans = H*W/2;
  if(W/2==x && H/2==y) ans += " 1";
  else ans += " 0";
  console.log(ans);
}

main(require('fs').readFileSync('/dev/stdin', 'UTF-8').trim().split("\n"));


Measured memory_bytes: 7372
#pragma GCC optimize("O2")
/*
Arthor : Ender_zzm
E-mail zzm_ender_wiggin@outlook.com
Blog oi.ender-zzm.pro
*/
#include <bits/stdc++.h>
using namespace std;

inline int Isdigit(char c) {
	if (c < '0' || c > '9') return 0;
	return 1;
}
inline int readint(){
    register int x = 0, flag = 1;
    register char ch;
    while (!Isdigit(ch = getchar())) if (ch == '-') flag = -1;
    while (Isdigit(ch)) x = x * 10 + (ch & 15), ch = getchar();
	return x * flag;
}

inline long long readlong() {
	register long long x = 0, flag = 1;
	register char ch;
	while (!Isdigit(ch = getchar())) if (ch == '-') flag = -1;
    while (Isdigit(ch)) x = x * 10 + (ch & 15), ch = getchar();
	return x * flag;
}
template <class T>
inline void write(T x){
    if (x < 0)
        putchar('-'), x = -x;
    if(x >= 10) write(x / 10); 
    putchar(x % 10 + '0');
}

template<class T> inline bool Chkmax(T& x, const T& y) { return x < y ? x = y, true : false; }
template<class T> inline bool Chkmin(T& x, const T& y) { return x > y ? x = y, true : false; }

#define debug(x) cout << #x << " = " << x << endl;
#define For(i, x, y) for (int i = (x); i <= (y); i++) 
#define Rep(i, x, y) for (int i = (x); i >= (y); i--) 
#define ri readint
#define rl readlong

const int maxn = 2e5 + 30;
#define ls rt << 1
#define rs rt << 1 | 1
int n, cnt;
struct Point {
	int x, y, pp;
	bool operator < (const Point &a) const {
		return x < a.x;
	}
}a[maxn];
int cmpx(Point a, Point b) {
	return a.x < b.x;
}
int cmpy(Point a, Point b) {
	return a.y < b.y;
}
int main() {
	n = ri();
	for (int i = 1; i <= n; i++) {
		a[i].x = ri(), a[i].y = ri();
		int x = a[i].x, y = a[i].y;
		a[i].x = x + y;
		a[i].y = x - y;
	}
	sort(a + 1, a + 1 + n, cmpx);
	int ans = a[n].x - a[1].x;
	sort(a + 1, a + 1 + n, cmpy);
	ans = max(ans, a[n].y - a[1].y);
	printf("%d\n", ans);
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 1000000000

void solve_trust_b() {
	ll N;
	ll num = 0;
	string ans;

	cin >> N;

	num = N / 1.08;
	if ((ll)(num * 1.08) == N) {
		ans = to_string(num);
	}
	else if ((ll)((num+1) * 1.08) == N) {
		ans = to_string(num+1);
	}
	else {
		ans = ":(";
	}

	cout << ans << "\n";
}

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

	solve_trust_b();

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const double PI=3.14159265358979323846;

int main(){
    double a,b,x;
    cin >> a >> b >> x;
    double H = a*a*b / 2;
    if(a<b){
        if(H < x){
            cout << fixed << setprecision(12) << atan(2*(a*a*b-x)/a/a/a) *360 /2 / PI << endl;
        }else{
            cout << fixed << setprecision(12) << 90 - atan(2*x/a/b/b) * 360/2/PI << endl;
        }
    }else{
        if(H < x){
            cout << fixed << setprecision(12) << atan(2*(a*a*b-x)/a/a/a) *360 /2 / PI << endl;
        }else{
            cout << fixed << setprecision(12) << 90 - atan(2*x/a/b/b) * 360/2/PI << endl;
        }
    }

}

Measured memory_bytes: 384
#include <iostream>
#include<string>
#include<vector>
#define lli long long int
using namespace std;

int main() {
	// your code goes here
	lli x,k,n,c,las;
	c=0;
	cin>>n;
	vector<lli> v(n);
	for(lli i=0;i<n;i++)cin>>v[i];
	for(lli i=0;i<n-1;i++){
		
		for(lli j=i+1;j<n;j++){
			
			c+=v[i]*v[j];
			// cout<<v[i]<<" "<<v[j]<<" "<<c<<endl;
		}
	}
	cout<<c;
	
	// cout<<0;
	// x='Z';
	// las=int('Z');
	// if('Z'-(s[0]+k)>=0)cout<<(char)(s[0]+2);
	// cout<<'Z'<<" "<<(s[0]+k);
	// SUN, MON, TUE, WED, THU, FRI, or SAT, 
	return 0;
}

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

#define ll long long 
#define rep(i,n) for(int i=0;i<n;i++)
#define MX 100005
#define M 1000000007

using namespace std;

int main(){
    string  K;
    cin>>K;
    int D;
    ll d[101][2];
    memset(d,0,sizeof(d));
    cin>>D;
    rep(i,K[0]-'0')d[i%D][0]++;
    int m=K[0]-'0';
        m%=D;
    rep(i,K.size()){
        if(i==0)i++;
        rep(j,D){
            d[j][i%2]=0;
            rep(k,10)d[j][i%2]+=d[(j-k+D*10)%D][(i-1)%2];
            //cout<<d[j][i%2]<<" "<<i<<":"<<j<<"   ";
            d[j][i%2]%=M;
        }
        if(K[i]!='0')rep(k,K[i]-'0')d[(m+k)%D][i%2]++;
        m+=K[i]-'0';
        m%=D;
        //cout<<d[0][i%2]<<" "<<i<<":"<<0<<"   ";
    }
    ll ans=d[0][(K.size()-1)%2];
    ans--;
    if(m==0)ans++;
    ans%=M;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

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


Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int ar[26],i;
    string s;
    cin>>s;

    for(i=0;i<26;i++){
        ar[i]=0;  // a=0, b=1 ,z=26 ;
    }

    //counting sort

    for(i=0;i<s.size();i++){
        int p=s[i]-97;
        ar[p]++;
    }

   string ans = "Yes";
  for (int i = 0;i < 26;i++){
    if (ar[i]%2!=0){
      ans = "No";
      break;
  }


}
cout << ans <<endl;
}



Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define mp make_pair
typedef long long int ll;
const int N=1e5+5;
int n,vis[N];
pair< pair<int,int>, int >  p[N];
priority_queue < pair < int, pair<int,int> > > q;
ll ans;
int par(int x){
    return((vis[x]==-1||vis[x]==x)? x:par(vis[x]));
}
int main(){
    //cin.tie(NULL);
   // cout.tie(NULL);
    //ios_base::sync_with_stdio(false);
    memset(vis,-1,sizeof vis);
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>p[i].f.f>>p[i].f.s;
        p[i].s=i;
    }
    sort(p,p+n);
    for(int i=1;i<n;i++)
        q.push( mp( -(p[i].f.f-p[i-1].f.f),mp(p[i].s,p[i-1].s)));

    for(int i=0;i<n;i++)
        swap(p[i].f.f,p[i].f.s);
    sort(p,p+n);
    for(int i=1;i<n;i++)
        q.push( mp(-(p[i].f.f-p[i-1].f.f),mp(p[i].s,p[i-1].s)));
    while(q.size()){
        pair< int, pair<int,int> > x=q.top();
        q.pop();
        //cout<<x.s.f<<" "<<vis[x.s.f]<<" "<<x.s.s<<" "<<vis[x.s.s]<<" "<<x.f<<'\n';
        vis[x.s.f]=par(x.s.f);
        vis[x.s.s]=par(x.s.s);
        if(vis[x.s.f]==vis[x.s.s])
            continue;
        ans+=-x.f;
        vis[vis[x.s.f]]=vis[x.s.s];
    }
    cout<<ans<<'\n';
    return 0;
}


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

int compare_int(const void *a,const void *b){
  if(*(int*)a > *(int*)b) return 1;
  return -1;
}

int main(void){
  int n;
  scanf("%d", &n);
  int a[n];
  int allzerocount = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    if(a[i] == 0) allzerocount++;
  }
  if(allzerocount == n){
    printf("Yes\n");
    return 0;
  }

  qsort(a, n, sizeof(int), compare_int);

  if(allzerocount != 0 && allzerocount == n/3){
    int past = a[n/3];
    for (int i = n/3; i < n; i++) {
      if(a[i] != past){
        printf("No\n");
        return 0;
      }
    }
    printf("Yes\n");
    return 0;
  }

  int past = a[0];
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if(past == a[i]) cnt++;
    else if(cnt != n/3){
      printf("No\n");
      return 0;
    }else{
      cnt = 1;
      past = a[i];
    }
  }

  if(((a[0]^a[n/3])^a[n-1]) == 0) printf("Yes\n");
  else printf("No\n");

  return 0;
}

Measured memory_bytes: 892
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
AtoZ = [chr(i) for i in range(65,65+26)]
atoz = [chr(i) for i in range(97,97+26)]

def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

x,a,b = inpl()
if abs(x-a) > abs(x-b):
	print('B')
else:
	print('A')

Measured memory_bytes: 4204
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

int main(void)
{
	std::string s, s2;

	std::cin >> s;

	s2 = s;

	std::sort(s2.begin(), s2.end());
	s2.erase(std::unique(s2.begin(), s2.end()), s2.end());
	int count = 10000;
	for (char c : s2) {
		if (std::count(s.begin(), s.end(), c) == s.length()) {
			std::cout << 0 << std::endl;
			return 0;
		}
		std::string s3 = s;
		for (int i = 0; i < s.length(); i++) {
			for (int j = 0; j < s.length(); j++) {
				if (s3[j] == c || (j + 1 < s.length() && s3[j + 1] == c)) {
					s3[j] = c;
				}
			}
			//std::cout << s3 << " " << i << std::endl;
			if (std::count(s3.begin(), s3.end() - (i + 1), c) == s.length() - (i + 1)) {
				//std::cout << s3 << std::endl;
				count = std::min(count, i + 1);
				break;
			}
		}
	}

	std::cout << count << std::endl;

	return 0;
}

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

MOD = 2019  # type: int

def solve(L: int, R: int):
    if R-L >= 2018:
        print(0)
        return 
    
    lr_all = list(range(L,R+1))
    answer = 2019
    for i in range(R-L+1):
        for j in range(i+1,R-L+1):
            answer = min(lr_all[i]*lr_all[j]%MOD,answer)
    
    print(answer)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    L = int(next(tokens))  # type: int
    R = int(next(tokens))  # type: int
    solve(L, R)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N, M;
    cin >> N;
    vector<int> T(N);
    for(int i = 0; i < N;i++){
        cin >> T.at(i);
    }
    cin >> M;
    vector<int> P(M);
    vector<int> X(M);
    for(int i = 0; i < M; i++){
        cin >> P.at(i) >> X.at(i);
    }
    long long int ans;
    long long int sum = accumulate(T.begin(), T.end(), 0);
    for(int i = 0; i < M; i++){
        ans = sum - T[P[i]-1] + X[i];
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
S=input()
T=input()
A=S+T
if T[:-1]!= S:
  print("No")
elif len(T)-len(S)!=1:
  print("No")
elif len(S)<= 0 or len(S)>= 11:
  print("No")
elif  A.isalpha() and A.islower():
  print("Yes")
else:
  print("No")

Measured memory_bytes: 8956
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
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; }
typedef long long ll;
typedef pair<int,int> P;

vector<int> to[55];
vector<bool> visited(55,0);

void dfs(int a,int b,int v){
    visited[v]=1;
    for(int u:to[v]){
        if(visited[u])continue;
        if(u==a&&v==b)continue;
        if(v==a&&u==b)continue;
        dfs(a,b,u);
    }
}

int main(){
    int n,m;
    cin >> n >> m;
    int a[m],b[m];
    rep(i,m){
        int at,bt;
        cin >> at >> bt;
        at--,bt--;
        a[i]=at;
        b[i]=bt;
        to[at].push_back(bt);
        to[bt].push_back(at);
    }
    int ans = 0;
    rep(i,m){
        rep(j,n)visited[j]=0;
        dfs(a[i],b[i],0);
        int c = 0;
        rep(j,n)c+=visited[j];
        if(c!=n)ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

/**
 * Created by zzt on 17-1-17.
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int L = scanner.nextInt();
        String[] strings = new String[N];
        for (int i = 0; i < N; i++) {
            strings[i] = scanner.next();
        }
        Arrays.sort(strings, (o1, o2) -> {
            int min = Math.min(o1.length(), o2.length());
            char[] c1 = o1.toCharArray();
            char[] c2 = o2.toCharArray();
            for (int i = 0; i < min; i++) {
                if (c1[i]!=c2[i])
                    return c1[i] - c2[i];
            }
            return o1.length() - o2.length();
        });
        for (int i = 0; i < N; i++) {
            System.out.print(strings[i]);
        }
        System.out.println();
    }
}

Measured memory_bytes: 16752
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const string EMP = " ";
const ll INF = 1LL<<60;
const ll MOD = 1000000007;
const double PI = acos(-1);

int main(){
  int a,b,h,m; cin >> a >> b >> h >> m;
  double hh = double(60*h+m) / 720 * 2*PI;
  double mm = double(m) / 60 * 2*PI;
  double dd = abs(hh-mm);
  double ans = double(a*a + b*b) - 2*a*b*cos(dd);
  ans = sqrt(ans);
  printf("%.15f\n", ans);
  return 0;
}


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

typedef long long ll;
typedef vector<long long> vll;
typedef vector<int> vi;
typedef pair<int, int> pi;

#define pb push_back

#define rep(i, l, n) for (int i = (l); i < n; i++)
#define rep_d(j, n) for (int j = n; j >= 0; j--)
#define rep_d_op(j, n, a) for (int j = n; j >= a; j--)

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

const int MOD = 1000000007;

const vector<int> dx = {1, 0};
const vector<int> dy = {0, 1};
const ll INF = 1LL << 60;

// int max = *std::max_element(vec.begin(), vec.end());
// int sum = accumulate(list, list + size, 0);

int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }

using Graph = vector<vector<int>>;

Graph G;

vector<bool> seen;
void dfs(const Graph &G, int v)
{
    seen[v] = true;

    for (auto next_v : G[v])
    {
        if (seen[next_v])
            continue;
        dfs(G, next_v);
    }
}

int main()
{
    int n;
    cin >> n;
    vll h(n);
    rep(i, 0, n)
    {
        cin >> h[i];
    }

    ll dp[100010];
    rep(i, 0, 100010)
    {
        dp[i] = INF;
    }
    dp[0] = 0;

    rep(i, 1, n)
    {
        chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
        if (i >= 2)
        {
            chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
        }
    }
    cout << dp[n - 1] << endl;
}

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

using namespace std;

struct I{I(){ios::sync_with_stdio(false);cin.tie(0);}}cww;

#define rep(i,s,t) for(auto i=s;i<t;i++)

typedef long long LL;
const LL MOD=1e9+7;

template<typename T>
string debug(vector<T> v,string c){
    string res;
    for(int i=0,sz=v,size();i<sz;i++){
        if(i)res+=c;
        res+=v[i];
    }
    return res;
}
string P="Positive";
string N="Negative";
string Z="Zero";

int main(){
    int a,b;cin>>a>>b;
    if(a<=0&&0<=b)cout<<Z<<endl;
    else if(a>0)cout<<P<<endl;
    else if((b-a+1)%2)cout<<N<<endl;
    else cout<<P<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
using namespace std;
vector<string> name; //空港の名前

bool isvowel(char c) {
  return (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o');
}

string getCode(string s, int k) {
  string ans;
  ans = s[0];
  int len = s.size() - 1;
  for(int i = 0; i < len; i++) {
    if(isvowel(s[i])) {
      ans += s[i+1];
    }
  }
  if((int)ans.size() < k)
    return ans;
  return ans.substr(0, k);
}

int code_length(int n) {
  bool flag;

  for(int k = 1; k < 51; k++) {
    flag = true;
    map<string, bool> mp;
    for(int i = 0; i < n; i++) {
      string s = getCode(name[i], k);
      if(mp.count(s) == 0) {
        mp[s] = true;
      }
      else {
        flag = false;
        break;
      }
    }
    if(flag)
      return k;
  }
  return -1;
}

int main() {
  int n; //空港の数

  while(1) {
    cin >> n;
    if(n == 0)
      break;

    for(int i = 0; i < n; i++) {
      string str;
      cin >> str;
      name.push_back(str);
    }

    cout << code_length(n) << endl;
    name.clear();
  }
}



Measured memory_bytes: 3160
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @author Pavel Mavrin
 */
public class Main {

    private void solve() throws IOException {
        int n = nextInt();
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextInt();
        }
        Arrays.sort(a);
        long s = 0;
        int j = 0;
        for (int i = 0; i < n - 1; i++) {
            s += a[i];
            if (a[i + 1] > s * 2) {
                j = i + 1;
            }
        }
        out.println(n - j);
    }

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

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st;
    PrintWriter out = new PrintWriter(System.out);

    String next() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }

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

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

    private void run() throws IOException {
        solve();
        out.close();
    }

}


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

int f[10][10];
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int foo = i;
    int fi;
    int la = foo % 10;
    while (foo > 0) {
      if (foo < 10) fi = foo;
      foo /= 10;
    }
    f[fi][la]++;
  }
  long long ans = 0;
  for (int i = 0; i <= 9; i++) {
    for (int j = 0; j <= 9; j++) {
      ans += f[i][j] * f[j][i];
    }
  }
  cout << ans << '\n';
  return 0;
}

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

using namespace std;

const int N = 234567;

int n, maxd[N], smaxd[N], sum[N];
long long answer;
vector<int> adj[N];
string s;

void dfs(int x, int f) {
  sum[x] = s[x - 1] == '1';
  for (auto y : adj[x]) {
    if (y != f) {
      dfs(y, x);
      sum[x] += sum[y];
      int d = maxd[y] + 1;
      if (d > maxd[x]) {
        smaxd[x] = maxd[x];
        maxd[x] = d;
      } else {
        smaxd[x] = max(smaxd[x], d);
      }
    }
  }
}

void dfs(int x, int f, int fa_d) {
  int first = maxd[x], second = smaxd[x];
  if (fa_d > first) {
    second = first;
    first = fa_d;
  } else {
    second = max(second, fa_d);
  }
  int mind = n + 1;
  if (sum[1] - sum[x] > 0) {
    mind = min(mind, fa_d);
  }
  for (auto y : adj[x]) {
    if (y != f) {
      int new_d = max(fa_d, maxd[y] + 1 == maxd[x] ? smaxd[x] : maxd[x]);
      dfs(y, x, new_d + 1);
      if (new_d <= maxd[y] && sum[1] - sum[y] > 0) {
        ++answer;
      } else if (new_d >= maxd[y] && sum[y] > 0) {
        ++answer;
      }
      if (sum[y]) {
        mind = min(mind, maxd[y] + 1);
      }
    }
  }
  int up = second, down = s[x - 1] == '1' ? 0 : mind;
  answer += max(0, up - down + 1);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1, x, y; i < n; ++i) {
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  cin >> s;
  dfs(1, 0);
  dfs(1, 0, 0);
  cout << answer << '\n';
  return 0;
}

Measured memory_bytes: 29328
#include<bits/stdc++.h>
using ll = long long;
using namespace std;
signed main() {
	ll n;
	cin >> n; vector<ll> aa(n), bb(n);
	for (int h = 0; h < n; h++) {
		cin >> aa[h] >> bb[h];
	}
	sort(aa.begin(), aa.end()); sort(bb.begin(), bb.end());
	if (n % 2 == 1) { cout << max((ll)0, bb[n / 2] - aa[n / 2] + 1) << endl; }
	else {
		cout << (bb[n / 2] + bb[n / 2 - 1]) - (aa[n / 2] + aa[n / 2 - 1]) + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 6372
/* ファイル名：ITP1_1_D	*/
/* 内容：秒単位の時間 S が与えられるので、h:m:s の形式へ変換して出力	*/

/* include	*/
#include <stdio.h>

/* 外部変数宣言	*/

/* プロトタイプ宣言	*/

/* 関数名:main	*/
/* 処理内容:秒単位の時間 S が与えられるので、h:m:s の形式へ変換して出力	*/
int main( void )
{
	/* 内部変数定義	*/
	int S;	/* 入力される秒単位の時間	*/
	
	int h;	/* 時間						*/
	int m;	/* 分						*/
	int s;	/* 秒						*/
	
	scanf("%d",&S);	/* 秒単位の時間を取得	*/
	
	/* 演算	*/
	h = S / 3600;			/* 時間を算出	*/
	m = ( S % 3600 ) / 60;	/* 分を算出		*/
	s = ( S % 3600 ) % 60;	/* 秒を算出		*/
	
	printf("%d:%d:%d\n",h,m,s);/* 出力		*/
	
	return 0;
}



Measured memory_bytes: 2100
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_set>
using namespace std;
typedef long long ll;

int main(){
  int A,B;
  string S,T,U;
  cin >> S >> T;
  cin >> A >> B;
  cin >> U;

  if(U == S){
    A--;
  }else if(U == T){
    B--;
  }
  cout << A << "\t" << B << endl;
  return 0;
}


Measured memory_bytes: 256
import Control.Monad
import Control.Monad.ST
import qualified Data.ByteString.Char8 as C
import Data.Vector.Unboxed ((!), drop, modify, unsafeFreeze, unsafeThaw)
import qualified Data.Vector.Unboxed as U
import Data.Vector.Unboxed.Mutable (unsafeRead, unsafeWrite)

main = C.interact $ put . sol . get

get = U.unfoldr (C.readInt . C.dropWhile (<'0'))

put = C.pack . show

sol v = case n of
  1 -> 0
  2 -> a!1
  _ -> if a==b then U.sum (U.filter (< inf) c) `div` 2 else -1
  where
  n = v!0
  a = U.drop 1 v
  b = modify (f n) a
  c = modify (g n) a

f n v = do
  let
    putw i j = unsafeWrite v (i*n+j)
    getw i j = unsafeRead v (i*n+j)
  forM_ [0..n-1] $ \k ->
    forM_ [0..n-1] $ \i ->
      forM_ [0..n-1] $ \j -> do
        a <- getw i k
        b <- getw k j
        p <- getw i j
        putw i j (min p (a+b))

g n v = do
  let
    putw i j = unsafeWrite v (i*n+j)
    getw i j = unsafeRead v (i*n+j)
  forM_ [0..n-1] $ \k ->
    forM_ [0..n-1] $ \i ->
      forM_ [0..n-1] $ \j -> when (k/=i && k/=j && i/=j) $ do
        a <- getw i k
        b <- getw k j
        p <- getw i j
        when (a+b<=p) $ putw i j inf

inf = maxBound `div` 4 :: Int

Measured memory_bytes: 9548
#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;
using   ll=long long;
using   ld=long double;

#define fast        	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ordered_set 	tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>

#define endl        	"\n"
#define pb          	push_back
#define mp          	make_pair
#define F           	first
#define S           	second
#define int             long long int
#define pll				pair<int , int>

#define ALL(v)      	v.begin(),v.end()
#define ALLR(v)     	v.rbegin(),v.rend()
#define pii         	3.14159265358979323
#define inf     		LLONG_MAX
#define ones(x)     	__builtin_popcount(x)
#define fill(a,b)   	memset(a,b,sizeof(a))
#define mod 			1000000007
#define hell            998244353 

ll mod_pow(ll a,ll b,ll m) 
{
    ll res = 1;
    while(b)	
    {
        if(b&1) 	
        {
        	res=(res*a) % m;
        }
        a=(a*a) % m;
        b>>=1;
    }
    return res;
}

ll mod_inverse(ll a) 
{
	return mod_pow(a , mod-2 , mod);
}

void solve()
{
	int n;
	
	cin >> n;
	
	int a[n];
	
	for(int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	
	sort(a , a+n);
	
	int f1 = -1;
	int f2 = -1;
	
	for(int i = n-1; i > 0; i--) {
		if(a[i] == a[i-1]) {
			if(f1 == -1) {
				f1 = a[i];
			}
			else if(f2 == -1) {
				f2 = a[i];
			}
			else {
				break;
			}
			
			i--;
		}
	}
	
	if(f1 == -1 or f2 == -1) {
		f1 = 0;
	}
	
	cout << max(0LL , f1*f2);
}

signed main() {
    fast;
    
    int t = 1;
    
	//cin >> t;
    
    while(t--) {
        solve();
    }
 
    return 0;
}


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

using namespace std;

#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<int, pii> para;
const int inf = 1e9 + 7;
const int maxN = 1e6 + 5;

int n, arr[maxN], diff, used[maxN];
ll fact[maxN];


ll power(ll a, ll b) {
	if (b == 0) return 1;
	if (b == 1) return a;
	if (b % 2 == 0)
		return power((a * a) % inf, b / 2) % inf;
	return ((power((a * a) % inf, b / 2) % inf) * a) % inf;
}

ll choose(ll x, ll y) {
	if (y > x) return 0;
	ll inv = power((fact[y] * fact[x - y]) % inf, inf - 2);
	//cout<<fact[x]<<" "<<inv<<"HSDGAVJDS"<<endl;
	return (fact[x] * inv) % inf;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin>>n;
	RI(i, n + 1) {
		cin>>arr[i];
		//cout<<arr[i]<<endl;
		if (used[arr[i]] != 0) {
			diff = i - used[arr[i]];
			//cout<<arr[i]<<" "<<diff<<endl;
		} else {
			used[arr[i]] = i;
		}
	}
	fact[0] = 1;
	RI(i, n + 1) {
		fact[i] = (fact[i - 1] * i) % inf;
	}

	RI(i, n + 1) {
		ll ans = choose(n + 1, i);
		ll tmp = choose(n - diff, i - 1);
		//cout<<"pascal : "<<" "<<n - diff<<" "<<tmp<<endl;
		cout<<(ans - tmp + inf) % inf<<endl;
	}
	// (n + 1) choose i and (n - diff) choose i
	return 0;
}


Measured memory_bytes: 8192
#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 int long long int
#define mod 1000000007
#define string_mod 2549536629329_base_255
#define pb push_back
#define F first
#define S second
#define ff first
#define endl "\n"
#define ss second
#define all(v) v.begin(), v.end()
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int power(int x, unsigned int y, int p)
{
  int res = 1;
  x = x % p;
  while (y > 0)
  {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
int32_t main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int tc;
  tc = 1;
  //cin>>tc;
  while (tc--)
  {
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 1; i <= n;i++){
      for (int j = 1; j <= n;j++){
        int g = __gcd(i, j);
        for (int k = 1; k <= n;k++){
          ans += __gcd(g, k);
        }
      }
    }
      cout << ans;
  }

  return 0;
}

Measured memory_bytes: 3648
import fractions
from functools import reduce

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

N, X = map(int, input().split())
x = [int(i) for i in input().split()]

x.append(X)
x.sort()

dist = []
for i in range(N):
    dist.append(x[i+1]-x[i])

print(gcd(*dist))


Measured memory_bytes: 16304
from collections import defaultdict

N, T = map(int, input().split())
*a, = map(int, input().split())
t = defaultdict(int)
m = a[0]
p = 0
for i in range(1, N):
    c = a[i] - m
    if t[m] < c:
        t[m] = c
    if a[i] < m:
        m = a[i]
    if c > p:
        p = c

ans = 0
for k, v in t.items():
    if v == p:
        ans += 1

print(ans)


Measured memory_bytes: 65388
#include <iostream>

using namespace std; 
typedef long long int ll;

int main(void){
  ll A;
  double B;
  int x,y,z;
  
  cin >> A >> B;
  B = B+0.001;
  x = (int)B;
  y = ((int)(10.0*B))%10;
  z = ((int)(100.0*B))%10;
  double rem1 = ((A*y)%10)/10.0;
  double rem2 = ((A*z)%100)/100.0;
  int fixed = (int)(rem1+rem2);
  //cout << A*x << " " << A*y << " " << A*z << endl;
  ll ans = A*x + (A*y)/10 + (A*z)/100 + fixed;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3724
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vvl = vector<vl>;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    int N, K;
    cin >> N >> K;
    ll ans = K;
    REP(i, N - 1) { ans *= K - 1; }
    cout << ans << endl;
    return 0;
}

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

typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;

#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define ARR(array) for(int i=0;i<array.size();i++)
#define all(in) in.begin(),in.end()
#define ALL(in,K) (in),(in)+(K)

#define INF 1e18
#define MOD 1000000007
#define SIZE 10005
#define PI 	3.14159265358979323846

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a, b)*b; } //最小公倍数

ll input(){
ll a;
  cin >> a;
  return a;
}

vi sub(vector<bool> fin,ll n) {
  vi ret;
  REP(i,n) {
    if(fin.at(i))continue;
    vector<bool> cp = fin;
    cp.at(i) = true;
    vi result = sub(cp,n);
    ret.insert(ret.end(),result.begin(),result.end());
  }
  return ret;
}

int main() {
  if(input()==1)cout << "Hello World" << endl;
  else cout << input()+input() << endl;
}


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

int main() {
  string s;
  cin >> s;
  int n = s.size();
  vector<int>k(n,0);
  
  for (int i = 0; i < n; i++) {
    if (s.at(i) == 'C' || s.at(i) == 'G' || s.at(i) == 'T' || s.at(i) == 'A') {
      k.at(i) = 1;
    }
  }
  int ans=0,cnt = 0;
  for (int i = 0; i < n; i++) {
    cnt = (cnt + k.at(i)) * k.at(i);
    ans = max(ans,cnt);
  }
  cout << ans;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define pb push_back

// #define int long long

int main(){
    string s;
    bool flag=false;
    bool ans=false;
    cin>>s;

    for(int i=0;i<s.size();i++){
        if(s[i]=='C')flag=true;
        if(flag&&s[i]=='F')ans=true;
    }

    if(ans){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long int
#define ld long double
#define getFaster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define rev(i,n,init) for(int i=n;i>=init;i--)
#define MAXN 200005
#define MOD2 998244353
#define MOD1 1e9+7
#define f first
#define s second
#define endl '\n'
#define pii pair<int,int>
#define piii pair<pii,int>
#define precise(i) cout<<fixed<<setprecision(i)
#define codejam cout<<"Case #"<<ii+1<<": ";
#define impossible cout<<"IMPOSSIBLE"<<endl;
#define error(s) throw runtime_error(s)
using namespace std;
const long double PI = atan(1.0)*4;
const int64_t INF=8e18;
const int32_t LOG=21;
const int MOD=MOD1;

int32_t main()
{ 
      getFaster;
      int tests=1;
      //cin>>tests;
      rep(ii,0,tests)
      {
         int h1,s1,h2,s2;
         cin>>h1>>s1>>h2>>s2;

         int ind=0;
         
         while(1)
         {
             if(ind==0 && h1<=0)break;
             if(ind==1 && h2<=0)break;
             if(ind==0)
             {
                h2-=s1;
             }
             else
             {
                 h1-=s2;
             }
             ind++;
             ind%=2;
         }

         if(ind)cout<<"Yes"<<endl;
         else cout<<"No"<<endl;

      }     
      return 0;                         
}

/*
 TIPS:
 1.) Check for corner cases (like 0 is exception case)
 2.) Check for global memory sizes,memory refreshments and its complexity 
 3.) Check for sorting criteria (if used 1-based indexing)
 4.) Check for numbers overflow (while multiplying and doing MOD)
 5.) Check for typecasting issues like int to float( while dividing numbers)
*/

Measured memory_bytes: 3656
#![allow(unused_imports)]
#![allow(unused_macros)]
use itertools::Itertools;
use std::cmp::{max, min};
use std::collections::*;
use std::i64;
use std::io::{stdin, Read};
use std::usize;

trait ChMinMax {
    fn chmin(&mut self, other: Self);
    fn chmax(&mut self, other: Self);
}
impl<T> ChMinMax for T
where
    T: PartialOrd,
{
    fn chmin(&mut self, other: Self) {
        if *self > other {
            *self = other
        }
    }
    fn chmax(&mut self, other: Self) {
        if *self < other {
            *self = other
        }
    }
}

#[allow(unused_macros)]
macro_rules! parse {
    ($it: ident ) => {};
    ($it: ident, ) => {};
    ($it: ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, $var:ident $($r:tt)*) => {
        let $var = parse_val!($it, usize);
        parse!($it $($r)*);
    };
}

#[allow(unused_macros)]
macro_rules! parse_val {
    ($it: ident, [$t:tt; $len:expr]) => {
        (0..$len).map(|_| parse_val!($it, $t)).collect::<Vec<_>>();
    };
    ($it: ident, ($($t: tt),*)) => {
        ($(parse_val!($it, $t)),*)
    };
    ($it: ident, u1) => {
        $it.next().unwrap().parse::<usize>().unwrap() -1
    };
    ($it: ident, $t: ty) => {
        $it.next().unwrap().parse::<$t>().unwrap()
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    let m = 998244353;
    parse!(it, n: usize, k: usize);
    let mut lr: Vec<(usize, usize)> = vec![];
    for _ in 0..k {
        parse!(it, l: usize, r: usize);
        lr.push((l, r + 1));
    }
    let mut dp = vec![0i64; n];
    dp[0] = 1;
    dp[1] = -1;
    let mut cur = 0;
    for i in 0..n {
        cur += dp[i];
        cur %= m;
        for &(l, r) in &lr {
            if l + i < n {
                dp[l + i] += cur;
                dp[l + i] %= m;
            }
            if r + i < n {
                dp[r + i] -= cur;
                dp[r + i] %= m;
            }
        }
    }
    println!("{}", (cur + m) % m);
}

pub fn num_divs(facts: &HashMap<usize, usize>) -> usize {
    facts.iter().map(|(_, v)| v + 1).product()
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


Measured memory_bytes: 3640
import heapq

n = int(input())
Edge = [[] for _ in range(n+1)]
for _ in range(n-1):
    a, b, c = map(int, input().split())
    # (コスト, 行き先)として追加する
    Edge[a].append([c,b])
    Edge[b].append([c,a])

q, k = map(int, input().split())
XY = []
for _ in range(q):
    x, y = map(int, input().split())
    XY.append([x,y])

# 関数への入力はs(start)とEdgeリスト
def dijkstra_heap(s, Edge):
    Dist = [10**10 for _ in range(n+1)]
    Dist[s] = 0
    Used = [False for _ in range(n+1)]
    Used[s] = True

    Edgelist = []

    for edge in Edge[s]:
        heapq.heappush(Edgelist, edge)

    while len(Edgelist) >= 1:
        minedge = heapq.heappop(Edgelist)
        cost, v = minedge[0], minedge[1]
        if Used[v] == True:
            continue
        Used[v] = True
        Dist[v] = cost

        for next_edge in Edge[v]:
            next_cost = next_edge[0]
            next_v = next_edge[1]
            heapq.heappush(Edgelist, [next_cost + Dist[v], next_v])
    return Dist

# print(Edge)
Dist_k = dijkstra_heap(k, Edge)

for xy in XY:
    x = xy[0]
    y = xy[1]
    ans = Dist_k[x] + Dist_k[y]
    print(ans)

# print(Dist_k)




Measured memory_bytes: 74456
#include <cstdio>
int st[4005]; 
char str[15], ans[4005]; 
inline bool query(int x, int y)
{
	printf("? %d %d\n", x, y);
	fflush(stdout);
	scanf("%s", str); 
	return str[0] == 'Y'; 
}
int main()
{
	int a, b; 
	scanf("%d%d", &a, &b);
	if (a <= b)
	{
		puts("Impossible"); 
		return 0; 
	}
	int n = a + b, tp = 0; 
	for (int i = 0; i < n; i++)
	{
		if (tp && !query(st[tp - 1], i))
			tp--;
		else
			st[tp++] = i; 
	}
	for (int i = 0; i < n; i++)
		ans[i] = query(st[tp - 1], i) + '0'; 
	printf("! %s\n", ans);
	return 0; 
}


Measured memory_bytes: 688
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <bitset>
using namespace std;
#define LL long long
#define pb push_back
#define mk make_pair
#define pill pair<int, int>
#define mst(a, b)    memset(a, b, sizeof a)
#define REP(i, x, n)    for(int i = x; i <= n; ++i)
#define INF 0x3f3f3f3f
#define ll long long
#define pi acos(-1.0)
int main(){
	int n,k;
	int Min = INF;
	int a[100010];
	scanf("%d %d",&n,&k);
	for(int i = 1 ; i <= n ; i++){
		scanf("%d",&a[i]);
	}
	sort(a+1,a+n+1);
	for(int i = k ; i <= n ; i++){
		Min = min(Min,min(abs(a[i]),abs(a[i-k+1]))+a[i]-a[i-k+1]);
	}
	printf("%d\n",Min);
}
/*
10
5 9 5 9 8 9 3 5 4 3
*/

Measured memory_bytes: 640
#include <iostream>

using namespace std;

void solve()
{
	int data[1112];
	for(int i = 0; i < 1112; ++i)
	{
		data[i] = i * i * i;
	}
	int n;
	while(cin >> n, n)
	{
		int min = 2000000000;
		for(int i = n - 1; i >= 1; --i)
		{
			for(int j = i; j >= 1; --j)
			{
				int sum = data[i] + data[j];
				int answer = data[n] - sum;
				if(answer >= 0 && answer < min)
				{
					min = answer;
					break;
				}
				if(answer > min)
				{
					break;
				}
			}
		}
		cout << min << endl;
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define TEST int t;cin>>t;for(int T=1;T<=t;T++)
#define F first
#define S second
int main()
{
    //TEST
    {
        int n;
        cin>>n;
        map<string,ll>mp;
        map<string,ll>:: iterator it;
        for(int i=1; i<=n; i++)
        {
            string s;
            int a;
            cin>>s;
            mp[s]++;
        }
        cout<<"AC x "<<mp["AC"]<<endl;
        cout<<"WA x "<<mp["WA"]<<endl;
        cout<<"TLE x "<<mp["TLE"]<<endl;
        cout<<"RE x "<<mp["RE"]<<endl;
    }
}



Measured memory_bytes: 3644
#include <iostream>
#include <cstdio>
#include <queue>
using namespace std;

const int N = 1505, INF = 1E9 + 7;

struct SEdge
{
    int v, t;
};
struct SNode
{
    int u, v;
};
struct SLine
{
    int x, y;
};
vector<SEdge> adj[N];
vector<SLine> cur;
vector<int> ans;
int n, m, u, v, t, dist[N][N];

inline bool operator<(const SNode &a, const SNode &b)
{
    return a.v > b.v;
}
priority_queue<SNode, vector<SNode>, less<SNode>> pq;

void Dijkstra(int st)
{
    fill(dist[st], dist[st] + N, INF);
    pq.push((SNode){st, dist[st][st] = 0});
    while (!pq.empty())
    {
        SNode cur = pq.top();
        pq.pop();
        for (SEdge v : adj[cur.u])
            if (dist[st][v.v] > dist[st][cur.u] + v.t)
                pq.push((SNode){v.v, dist[st][v.v] = dist[st][cur.u] + v.t});
        while (!pq.empty() && pq.top().v > dist[st][pq.top().u])
            pq.pop();
    }
}

int main()
{
    scanf("%d%d", &n, &m);
    while (m--)
    {
        scanf("%d%d%d", &u, &v, &t);
        adj[u].push_back((SEdge){v, t});
        adj[v].push_back((SEdge){u, t});
    }
    for (int i = 1; i <= n; i++)
        Dijkstra(i);
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
            if (cur.empty() || dist[i][j] == dist[cur.back().x][cur.back().y])
                cur.push_back((SLine){i, j});
            else if (dist[i][j] > dist[cur.back().x][cur.back().y])
            {
                cur.clear();
                cur.push_back((SLine){i, j});
            }
    for (int i = 1; i <= n; i++)
    {
        for (SLine v : cur)
            if (dist[v.x][i] + dist[i][v.y] == dist[v.x][v.y])
                goto br;
        ans.push_back(i);
    br:
        continue;
    }
    printf("%d\n", ans.size());
    for (int v : ans)
        printf("%d\n", v);
}



Measured memory_bytes: 44856
H, W = map(int,input().split())
Root = [[0 for i in range(W)] for j in range(H)]
for i in range(H):
    String = input()
    for j in range(W):
        Root[i][j] = String[j]
if Root[0][0] == '.':
    Grid = [[0 for i in range(W+1)] for j in range(H+1)]
for i in range(H):
    for j in range(W):
        if Root[i][j] == '.':
            if i == 0 and j == 0:
                Grid[1][1] = 1
            else:
                Grid[i+1][j+1] = Grid[i+1][j] + Grid[i][j+1]
        else:
            Grid[i+1][j+1] = 0
print(Grid[H][W] % 1000000007)


Measured memory_bytes: 166140
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

void isIdentical(vi a, vi b){
	sort(all(a)); sort(all(b));
	if(a != b){
		cout << -1 << endl;
		exit(0);
	}
}
int shrink(vi &a, vi &b){
	int n = a.size() - 1;
	vi c, d;
	
	rep(i, n) if(a[i] != b[i]){
		c.pb(a[i]);
		d.pb(b[i]);
	}
	c.pb(a[n]); d.pb(b[n]);
	
	map<int, int> id;
	int k = 0;
	
	rep(i, c.size()) if(!id.count(c[i])) id[c[i]] = k++;
	rep(i, c.size()){
		c[i] = id[c[i]];
		d[i] = id[d[i]];
	}
	a = c; b = d;
	return k;
}

bool done[100010];
int p[100010];
int root(int x){
	if(p[x] < 0) return x;
	return p[x] = root(p[x]);
}
void merge(int a, int b){
	a = root(a); b = root(b);
	if(a != b){
		p[a] += p[b];
		p[b] = a;
	}
}

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	int n; cin >> n;
	vi a(n + 1), b(n + 1);
	rep(i, n){
		cin >> a[i];
		a[n] ^= a[i];
	}
	rep(i, n){
		cin >> b[i];
		b[n] ^= b[i];
	}
	
	isIdentical(a, b);
	int N = shrink(a, b);
	
	rep(i, N) p[i] = -1;
	rep(i, a.size()) merge(a[i], b[i]);
	
	int ans = (int)a.size() - N - 2;
	rep(i, a.size()){
		int r = root(a[i]);
		if(done[r]) continue;
		done[r] = 1;
		ans -= p[r] - 1;
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 6640
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
#include <cmath>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#define rep(i,n) for (int i = 0; i < (n); ++i)

using namespace std;
const int MOD = 1000000007;


typedef long long int ll; 
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;

void floatOutPutSetup(){
    cout << fixed;
    cout << setprecision(10);
}

int main(){
    int k,n;
    cin>>k>>n;
    vector<int> a(n);
    vector<int> su(n+1);
    cin>>a[0];
    su[0]=a[0];
    rep(i,n-1){
        cin>>a[i+1];
        su[i+1]=a[i+1]-a[i];
    }
    su[0]+=k-a[n-1];

    // rep(i,n){
    //     cout<<su[i]<<endl;
    // }
    sort(su.begin(),su.end());
    cout<<k - *max_element(su.begin(),su.end());

    return 0;
}

Measured memory_bytes: 1792
# coding: utf-8
# Your code here!

s = input()

a = dict()

for i in s:
    if i not in a:
        a[i] = 1
    else:
        a[i] += 1

for i,v in a.items():
    if v != 2:
        print("No")
        exit()
else:
    print("Yes")
    











Measured memory_bytes: 2940