akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
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
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int N = in.nextInt();
            String S = in.next();
            char[] cs = S.toCharArray();
            int z = 'Z' - 'A' + 1;
            for (int i = 0; i < cs.length; i++) {
                cs[i] += N;
                if ('Z' < cs[i]) {
                    cs[i] -= z;
                }
            }
            out.println(new String(cs));
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

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

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

    }
}



Measured memory_bytes: 22868
f = [[[0]*10 for _ in range (3)] for _ in range (4)]

n = int(input())
for _ in range(n):
    a,b,c,d = map(int,input().split())
    f[a-1][b-1][c-1] += d

for i in range(4):
    for j in range(3):
        for k in range(10):
            print(" %d"%(f[i][j][k]),end='')
        print()
    if i<3:print ('#'*20)




Measured memory_bytes: 5624
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>

#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

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

const ll MOD = 1000000007;
const long double EPS = 1e-10;
const int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    std::ios::sync_with_stdio(0); cin.tie(0);
    int a;
    set<int> st;
    for(int i=0;i<4;++i) {
        cin >> a;
        st.insert(a);
    }

    set<int> st2({1,7,9,4});

    cout << ((st == st2)?"YES":"NO") << endl;

}


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

using namespace std;

int main() {
  while(1){
    int n;
    cin>>n;
    if(!n)break;
    int m;cin>>m;
    string s;
    cin>>s;
    char old='*';
    int cnt=0;
    int len=0;
    for(char c:s){
      if(c=='I'){
        if(old=='O'){
          if(len>=n)cnt++;
        }else{
          len=0;
        }
      }else if(old=='I'){
        len++;
      }else{
        len=0;
      }
      old=c;
    }
    cout<<cnt<<endl;
  }
  return 0;
}

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

int gcd (int a, int b);

int main () {

    int N;
    scanf("%d", &N);

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

    int ans = A[0];

    for (int i = 1; i < N; i++) {
        ans = gcd(ans, A[i]);
    }
    cout << ans << endl;

    return 0;
}

int gcd (int a, int b) {

    if (a % b == 0) return b;
    else return gcd(b, a % b);
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
#define repi(i,a,b) for(int i=(a), i##_len=(b); i<i##_len; ++i)
#define rep(i,n) repi(i,0,n)
#define repi_(i,a,b) for(int i=(a), i##_len=(b); i<=i##_len; ++i)
#define rep_(i,n) repi_(i,0,n)
#define all(x) (x).begin(),(x).end()
#define vsort(v) sort((v).begin(), (v).end())
#define gsort(v) tsort(v); reverse((v).begin(), (v).end())
#define vrev(v) reverse((v).begin(), (v).end())
#define siz(v) ((int)(v).size())
#define ers(v, n) (v).erase((v).begin() + n)
#define cnt(v, n) count(all(v), n)
#define vmin(v) *min_element(v.begin(), v.end())
#define vmax(v) *max_element(v.begin(), v.end())
#define el "\n"
#define co(x) cout<<(x)<<el
#define coc(c, a, b) if(c)co((a));else co((b))
#define cosp(x) cout<<(x)<<' '
#define YES(c) coc(c,"YES", "NO")
#define Yes(c) coc(c,"Yes", "No")
#define yes(c) coc(c,"yes", "no")
#define POSSIBLE(c) coc(c, "POSSIBLE", "IMPOSSIBLE")
#define Possible(c) coc(c, "Possible", "Impossible")
#define possible(c) coc(c, "possible", "impossible")
#define inf INT_MAX
#ifdef tqktmp_2
#define gc() getchar(); getchar()
#else
#define gc() 1
#endif


typedef long long lint;
typedef vector<int> ivec; typedef vector<string> svec;

lint dx[8] = { 0,1,1,1,0,-1,-1,-1 },
dy[8] = { 1,1,0,-1,-1,-1,0,1 };

template<class T>inline bool maxi(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>inline bool mini(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }




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

	lint n, a, b, in;
	ivec x;
	lint ans = 0;
	cin >> n >> a >> b;
	rep(i, n) {
		cin >> in;
		x.push_back(in);
	}
	rep(i, n-1) {
		if (a*(x[i + 1] - x[i]) < b)ans += a * (x[i + 1] - x[i]);
		else ans += b;
	}
	co(ans);
	gc();
}

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

class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int a = saori.saori_hayami();
		int b = saori.saori_hayami();
		int x = saori.saori_hayami();
		if(a > x){
			System.out.println("NO");
		} else if(a+b >= x){
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
		
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 21076
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<ll, ll> pll;
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define pb push_back
const long double PI = acos(-1);
const long long INF = (1 << 30);
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 stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(const ll a, const ll b){return ((a)+(b)-1)/b;}


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

  ll n, k;
  cin >> n >> k;
  vector<ll> x(n);
  for(ll i = 0; i < n; i++) cin >> x[i];

  ll ans = 0;
  for(ll i = 0; i < n; i++){
    ans += min(abs(x[i]*2), abs(k-x[i])*2);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {

  int N;
  cin >> N;

  vector<int64_t> ans(N+1);
  
  for(int i=0; i<N+1; i++){
    if(i == 0){
      ans.at(i)=2;
    }
    
    if(i == 1){
      ans.at(i)=1;
    }
    
    if( i >= 2){
    ans.at(i)=ans.at(i-1) + ans.at(i-2);
    }
  
  }
  
  cout << ans.at(N) << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef long int li;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef pair<ll, ll>P;
#define PI 3.14159265358979
#define MOD 998244353
const int MAX = 510000;

ll N,M;
ll mark[100000];
ll visited[100000];
ll length[100000];//0からの距離
vector<vector<ll>>E(100000);
int flag=0;

void dfs(int k,int from){
  if(k==0&&from!=0){
    queue<P>qu;
    return;
  }
  else{
   for(auto t: E[k]){
    if(visited[t]!=-1){
    	if(::length[k]+1<::length[t]){
          ::length[t]=::length[k]+1;
          ::mark[t]=k;dfs(t,k);
        }
    }   
    else{  
  	::mark[t]=k;
    ::visited[t]=k;
    ::length[t]=length[k]+1;
    dfs(t,k);  
    }
   }  
  }  
}

int main() {
  cin>>N>>M;  
  rep(i,M){
  	ll a,b;cin>>a>>b;a--;b--;
    E[a].push_back(b);
    E[b].push_back(a);
  }
  
  rep(i,N){::mark[i]=-1;::visited[i]=-1;::length[i]=0;}
  ::mark[0]=0;
  ::visited[0]=-2;
  queue<P>qu;
  qu.push(P(0,0));
  while(!qu.empty()){
  auto x=qu.front();qu.pop();
  int k=x.first;  
  for(auto t: E[k]){
    if(visited[t]!=-1){
    	if(::length[k]+1<::length[t]){
          ::length[t]=::length[k]+1;
          ::mark[t]=k;
        }
    }   
    else{  
  	::mark[t]=k;
    ::visited[t]=k;
    ::length[t]=length[k]+1;
    qu.push(P(t,k));  
    }
   }  
  }
  cout<<"Yes"<<endl;
  for(int i=1;i<N;i++){
  cout<<mark[i]+1<<endl;
  }
}

Measured memory_bytes: 15080
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, BinaryHeap};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::io::stdin;

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
}

#[allow(unused_macros)]
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    get!($t)
                   ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    get!($($t),*)
                   ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn f(t: bool, op: i64, a: &[i64], memo: &mut HashMap<(bool, i64, usize), i64>) -> i64 {
    if let Some(res) = memo.get(&(t, op, a.len())).cloned() {
        return res;
    }


    let res = {
        let iter = (0..a.len()).map(|i| if i == a.len() - 1 {
            (op - a[i]).abs()
        } else {
            let h = a[i];
            f(!t, h, &a[i + 1..], memo)
        });

        if t {
            iter.max().unwrap()
        } else {
            iter.min().unwrap()
        }
    };

    memo.insert((t, op, a.len()), res);
    res
}

fn main() {
    let (n, z, w) = get!(i64, i64, i64);
    let a = util::gets::<i64>();

    println!("{}", f(true, w, &a, &mut HashMap::new()));
}


Measured memory_bytes: 5116
#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;
}

int main(){
  string s;
  cin >> s;
  int ans = 0;
  for(char c: s)if(c=='x')ans++;
  cout << ((ans<8)?"YES":"NO") << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>

struct Data
{
    int b, c;
    Data(int b = 0, int c = 0) : b(b), c(c) {}
};

int n, m;
long long a[100010];
Data d[100010];

int cmp(const Data& x, const Data& y)
{
    return x.c > y.c;
}

int cmp2(const int& x, const int& y)
{
    return x > y;
}

int main()
{
    std::ios::sync_with_stdio(0), std::cin.tie(0), std::cout.tie(0);
    std::cin >> n >> m;
    for (int i = 1; i <= n; ++i)
        std::cin >> a[i];
    for (int i = 1; i <= m; ++i)
    {
        int u = 0, v = 0;
        std::cin >> u >> v;
        d[i] = Data(u, v);
    }
    std::sort(d + 1, d + m + 1, cmp);
    std::sort(a + 1, a + n + 1, cmp2);
    long long ans = 0;
    for (int i = 0, j = 1, k = 1; i < n; )
    {
        while (i < n && a[j] >= d[k].c)
            ans += a[j], ++j, ++i;
        while (i < n && d[k].c >= a[j])
            if (i + d[k].b < n)
                ans += 1ll * d[k].b * d[k].c, i += d[k].b, ++k;
            else
            {
                ans += 1ll * d[k].c * (n - i);
                i = n;
            }
    }
    std::cout << ans << std::endl;
    
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int main(){
  string a,b;
  cin>>a>>b;
  int n=stoi(a+b);
  for(int i=0;i<400;i++){
    if(i*i==n){
      cout<<"Yes"<<endl;
      return 0;
      }
    }
  cout<<"No"<<endl;
  return 0;
  }

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
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;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int w, h;
vector<vector<int>> c;
int ans;

int dx[8] = {1, 1, 1, 0, -1, -1, -1, 0};
int dy[8] = {1, 0, -1, -1, -1, 0, 1, 1};

void dfs(int _x, int _y) {
  // 訪問したマスは0に変えて
  c[_x][_y] = 0;
  // 次行くマスを決めて
  for(int i = 0; i < 8; ++i) {
    if(_x + dx[i] < 0 || _x + dx[i] >= h || _y + dy[i] < 0 || _y + dy[i] >= w) continue;
    if(c[_x + dx[i]][_y + dy[i]] == 1) dfs(_x + dx[i], _y + dy[i]);
  }
}

int main() {
  while(true) {
    cin >> w >> h;
    c.resize(h);
    if(w == 0 && h == 0) break;
    REP(k, h) {
      REP(m, w) {
        int C; cin >> C;
        c[k].push_back(C);
      }
    }
    ans = 0;
    REP(i, h) {
      REP(k, w) {
        if(c[i][k] == 1) {
          dfs(i, k);
          ans++;
        }
      }
    }
    cout << ans << endl;
    c.clear();
  }
}



Measured memory_bytes: 3148
import java.lang.String;
import java.lang.System;
import java.util.*;
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner cin = new Scanner(System.in);
        String text = cin.next();
        String sub = text.substring(0, 4);
        String remainder = text.substring(4);
        System.out.println(sub+" "+remainder);
    }
}

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

int main()
{
    int t=1;
    //cin>>t;
    
    while(t--)
    {
        long long int n;
        cin>>n;
        
        unordered_map<int, int> mp;
        
        long long int a[n], cnt=0;
        for(long long int i=0;i<n;i++)
        {
            cin>>a[i];
            mp[a[i]]++;
            cnt+=a[i];
        }
        
        long long int q;
        cin>>q;
        
        for(long long int i=0;i<q;i++)
        {
            long long int b, c;
            cin>>b>>c;
            
            cnt -= mp[b] * b;
            cnt += mp[b] * c;
            
            mp[c] += mp[b];
            mp[b] = 0;
            
            cout<<cnt<<endl;
        }
    }    
    return 0;
}

Measured memory_bytes: 7804
N=int(input())
count=[0]*(10**4+1)
for x in range(1,10**2):
    for y in range(1,10**2):
        for z in range(1,10**2):
            n=x**2+y**2+z**2+x*y+y*z+z*x
            if n<=10**4:
                count[n]+=1
for i in range(1,N+1):
    print(count[i])

Measured memory_bytes: 9316
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
   string s,ans;
   ans="AC";
   cin>>s;
   int i;
   int co=0;
   int co2=0;
   int n=s.size();
   if(s[0]!='A'){
     ans="WA";
   }
   for(i=2;i<n-1;i++){
     if(s[i]=='C'){
       co++;
     }
   }
   rep(i,n){
     if(s[i]>='a'&&s[i]<='z'){
       co2++;
     }
   }
   if(co!=1||co2!=n-2){
     ans="WA";
   }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
/*
int dx[]={-1,1,0,0};
int dy[]={0,0,-1,1};
vector<long long int> adj[200001];
bool vis[200001];
*/
#define ull unsigned long long int
#define ll long long int
#define MAX 1000000007
//1e9+7

#define pll pair<ll,ll>
#define pii pair<int,int>
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FO ifstream fin("a.in");ofstream fout("a.out");
#define TEST ll t;cin>>t;while(t--)
#define all(x) (x).begin(),(x).end()
#define mset0(x) memset((x), 0, sizeof((x)));
#define mset1(x) memset((x), -1, sizeof((x)));

string cmp(string a,string b){
    int n=a.size(),m=b.size();
    if(n>m) return(a);
    if(m>n) return(b);
    for(int i=0;i<n;i++){
        if(a[i]==b[i]) continue;
        if((a[i]-'0')>(b[i]-'0')) return(a);
        else return(b);
    }
    return(a);
}
string ss="0123456789";
int main(){
    IO
    int n,m;
    cin>>n>>m;
    int mat[]={0,2,5,5,4,5,6,3,7,6};
    int arr[m];
    for(int i=0;i<m;i++) cin>>arr[i];
    sort(arr,arr+m);
    map<int,string> mp;
    //for(int i=0;i<=n;i++) mp[i]="";
    /*
    for(int i=0;i<m;i++){
        string s=mp[mat[arr[i]]];
        string p="";
        p+=ss[arr[i]];
        //cout<<s<<" "<<p<<endl;
        mp[mat[arr[i]]]=cmp(p,s);
    }
    */

    for(int i=0;i<=n;i++){
        for(int j=0;j<m;j++){
            if(i-mat[arr[j]]<0) continue;
            string s=mp[i-mat[arr[j]]];
            string p=mp[i];
            if(s=="" && i!=mat[arr[j]]) continue;
            s+=ss[arr[j]];
            sort(s.rbegin(),s.rend());
            mp[i]=cmp(s,p);
            /*
            cout<<"i is "<< i<<" ";
            cout<<"j is "<<j<<" ";
            cout<<" mat[arr["<<j<<"]] is "<<mat[arr[j]]<<" ";
            cout<<"mp["<<i<<"] is "<<mp[i]<<"\n";
            */
        }

    }
    /*
    for(int i=1;i<=n;i++){
        cout<<i<<" "<<mp[i]<<"\n";
    }
    */
    cout<<mp[n];
    return(0);
}


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

struct Point{
    double x;
    double y;
    Point(double x, double y) : x(x), y(y){}
    Point operator+(Point p){
        return Point(x + p.x, y + p.y);
    }
    Point operator*(double d){
        return Point(x * d, y * d);
    }
};
typedef Point Vector;
double dot(Vector v1, Vector v2){
    return v1.x * v2.x + v1.y * v2.y;
}

int main(){
    int x_p1, y_p1, x_p2, y_p2;
    cin >> x_p1 >> y_p1 >> x_p2 >> y_p2;
    Point p1(x_p1, y_p1);
    Point p2(x_p2, y_p2);
    Vector base(x_p2 - x_p1, y_p2 - y_p1);
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int x_p, y_p;
        cin >> x_p >> y_p;
        Point p(x_p, y_p);
        Vector hypo(x_p - x_p1, y_p - y_p1);
        Point cross_p = p1 +
                        base * (dot(hypo, base) / dot(base, base));
        Point ans = p + Vector(cross_p.x - p.x, cross_p.y - p.y) * 2.0;
        cout << fixed << setprecision(10);
        cout << ans.x << " " << ans.y << endl;
    }
    return 0;
}



Measured memory_bytes: 3288
import collections

N = int(input())
X = list(map(int,input().split()))

x = collections.Counter(X)

N = len(x)
s = min(list(x.keys()))
e = max(list(x.keys()))

xl = list(x)

m = [0]*(e+1-s)

for i in range(s, e+1):
    p = 0
    for j in range(N):
        p += pow(xl[j]-i,2) * x[xl[j]]
    m[i-s] = p

print(min(m))

Measured memory_bytes: 3444
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
long N,X,D,ans;
long L[2<<17],R[2<<17];
long gcd(long a,long b){return b?gcd(b,a%b):a;}
vector<pair<long,int> >A[2<<17];
main()
{
	cin>>N>>X>>D;
	if(D==0)
	{
		cout<<(X==0?1:N+1)<<endl;
		return 0;
	}
	long g=gcd(X>0?X:-X,D>0?D:-D);
	X/=g;
	D/=g;
	long diff=D>0?D:-D;
	for(long i=0;i<=N;i++)
	{
		L[i]=i*(i-1)/2;
		R[i]=L[i]+(N-i)*i;
		L[i]+=X*i/D;
		R[i]+=X*i/D;
		int j=i%diff;
		A[j].push_back(make_pair(L[i],1));
		A[j].push_back(make_pair(R[i]+1,-1));
	}
	for(int i=0;i<=N&&i<diff;i++)
	{
		if(A[i].empty())continue;
		sort(A[i].begin(),A[i].end());
		int cnt=A[i][0].second;
		long pre=A[i][0].first;
		for(int j=1;j<A[i].size();j++)
		{
			if(cnt>0)
			{
				ans+=A[i][j].first-pre;
			}
			cnt+=A[i][j].second;
			pre=A[i][j].first;
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 20992
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rrep(i, n) for (int i = (n)-1; i >= 0; --i)
#define rrep2(i, a, b) for (int i = (a)-1; i >= b; --i)
#define range(i, a, b, c) for (int i = a;             \
                               c > 0 ? i < b : i > b; \
                               i += c)
#define chmax(a, b) (a = (a) < (b) ? (b) : (a))
#define chmin(a, b) (a = (a) > (b) ? (b) : (a))
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(a) begin(a), end(a)
#define ifnot(a) if (not(a))
#define dump(x) cerr << #x << " = " << (x) << endl
#define int long long
#ifdef _MSC_VER
const bool test = true;
#else
const bool test = false;
#endif

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
const int INF = (int)1 << 60;
const ll INFL = (ll)1 << 60;
ll mod_n = (int)1e9 + 7;
const double eps = 1e-10;
typedef long double Real;
// return -1, 0, 1
int sgn(const Real &r) { return (r > eps) - (r < -eps); }
int sgn(const Real &a, const Real &b) { return sgn(a - b); }

//.....................
const int MAX = (int)2e5 + 5;

vector<string> split(const string &str, char sep)
{
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while (getline(ss, buffer, sep))
    {
        v.push_back(buffer);
    }
    return v;
}

template <class InputIterator>
int sum(InputIterator begin, InputIterator end)
{
    return accumulate(begin, end, 0ll);
}

void solve();

signed main()
{
    cout << fixed << setprecision(20);
    solve();
    while (true)
    {
        char s[MAX];
        if (scanf("%s", s) == EOF)
            break;
        int n = strlen(s);
        for (int i = n - 1; i > -1; i--)
        {
            ungetc(s[i], stdin);
        }
        solve();
    }
    return 0;
}

int sx, sy, tx, ty;

void solve()
{
    cin >> sx >> sy >> tx >> ty;
    string res;
    int y_diff = ty - sy;
    int x_diff = tx - sx;
    rep(i, y_diff) res += 'U';
    rep(i, x_diff) res += 'R';
    rep(i, y_diff) res += 'D';
    rep(i, x_diff) res += 'L';

    res += 'L';
    rep(i, y_diff + 1) res += 'U';
    rep(i, x_diff + 1) res += 'R';
    res += 'D';
    res += 'R';
    rep(i, y_diff + 1) res += 'D';
    rep(i, x_diff + 1) res += 'L';
    res += 'U';

    cout << res << endl;
}


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

int main()
{
    int s, hh, mm, ss;
    cin >> s;

    hh = s / 3600;
    mm = (s % 3600) / 60;
    ss = s % 60;

    printf("%d:%d:%d\n", hh, mm, ss);
}

Measured memory_bytes: 3184
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <deque>
#include <stack>

using namespace std;

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

	int a, b, k;
	cin >> a >> b >> k;

	if (k >= (b - a) / 2 + 1) {
		for (int i = a; i <= b; i++)  cout << i << endl;
	} else {
		for (int i = a; i <= a + (k - 1); i++) cout << i << endl;
		for (int i = b - (k - 1); i <= b; i++) cout << i << endl;
	}
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long


    /// 16 30


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

        int h,w,n,sr,sc;
        string s,t;
//        int r[2],l[2],u[2],d[2];

        cin>>h>>w>>n;
        cin>>sr>>sc;
        sr--;
        sc--;
        cin>>s;
        cin>>t;
        int l=0,r=0,u=0,d=0;
        for( int i=n-1;i>=0;i-- ){
                if(l<0)l=0;
                if(r<0)r=0;
                if(u<0)u=0;
                if(d<0)d=0;

            if( s[i] == 'L'&& t[i]=='U' ) l++,d--;
            if( s[i] == 'L' && t[i] =='D' )l++,u--;
            if( s[i] == 'R' && t[i] =='U' )r++,d--;
            if( s[i] == 'R' && t[i] =='D' )r++,u--;

            if( s[i] == 'U'&& t[i]=='R' ) u++,l--;
            if( s[i] == 'U' && t[i] =='L' )u++,r--;
            if( s[i] == 'D' && t[i] =='R' )d++,l--;
            if( s[i] == 'D' && t[i] =='L' )d++,r--;

            if( s[i] == 'R' && t[i] =='R' )r++,l--; /// prvo bilo samo r++
            if( s[i] == 'L' && t[i] =='L' )l++,r--;
            if( s[i] == 'U' && t[i] =='U' )u++,d--;
            if( s[i] == 'D' && t[i] =='D' )d++,u--;

            /// ovo tek na kraju dodajem, jer sam skonto da ipak mora
            if( s[i] == 'R' && r==0 )r++;
            if( s[i]=='L' && l==0 ) l++;
            if( s[i] =='U'&&u==0 ) u++;
            if( s[i]=='D'&&d==0 )d++;

            if( r == w || l == w || d==h || u==h ){
                    cout<<"NO"<<endl;
                    return 0;
                }
        }

        int levo = sc+1, desno=w-sc, gore=sr+1,dole=h-sr;
        if( levo > l && desno > r && gore > u && dole > d ){
            cout <<"YES"<<endl;
        }
        else cout<<"NO"<<endl;

    return 0;
    }





















Measured memory_bytes: 920
#include <iostream>
#include <set>
using namespace std;
string s;
int main()
{
	string s;
	cin>>s;
	int N=s.length();
	if(N<26){
        for(char i='a';i<='z';i++){
            if(s.find(i)==-1){
                cout<<s<<i;
                return 0;
            }
        }
	}
	else{
        set<char>x;
        while(!s.empty()){
            char p=s.back();
            s.pop_back();
            x.insert(p);
            if(*x.rbegin()!=p){
                cout<<s<<*x.upper_bound(p);
                return 0;
            }
        }
	}
	cout<<-1;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")   //Comment optimisations for interactive problems (use endl)
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>

using namespace std;

#define  fastio         ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
#define  randomINIT     mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define  all(x)         (x).begin(),(x).end()
#define  mset(x,val)    memset(x,val,sizeof(x))
#define  endl           "\n"
#define  pb             push_back
#define  sym(s)         s="#"+s+"#";
#define  mp             make_pair
#define  s              second
#define  f              first
#define  dline          cerr<<"///REACHED///\n";
#define  debv(a)        for(auto it: a)cout<<it<<" ";cout<<endl;
#define  deb1(a)        cout<<a<<endl;
#define  deb2(a,b)      cout<<a<<" "<<b<<endl;
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c<<endl;
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
#define  uniq(a)        a.resize(unique(a.begin(), a.end()) - a.begin());

typedef  long long             ll;
typedef  unsigned long long    ull;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  vector<pll>           vpll;

const ll   MOD   =  1e+9+7;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;
const ll   N  =  3e+5+7;

vll adj[N];ll vis[N]={};
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1};
int dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};

//<<-----Declare Variable Here------->>//
int t=1;
ll h,w,m;
ll h1[N],w1[N];
vll v[N];
map<ll,ll>map1,map2;
set<ll>set2;
//<<-----Implement Functions Here---->>//


//<<-----Start of Main--------------->>//
void MAIN(){
		cin>>h>>w>>m;ll max1 = 0,max2 = 0;
		for(ll i=1;i<=m;i++)
		{
			cin>>h1[i]>>w1[i];
			v[h1[i]].pb(w1[i]);
			map1[h1[i]]++;map2[w1[i]]++;
		}
		for(auto it:map1)max1 = max(max1,it.s);
		for(auto it:map2)max2 = max(max2,it.s);
		ll ans = max1+max2-1;
		for(auto it:map2){if(it.s==max2)set2.insert(it.f);}
		
		for(auto it:map1)
		{
			if(it.s==max1)
			{
				set<ll>set1 = set2;
				for(auto it1:v[it.f]){set1.erase(it1);}
				if(set1.size()!=0){cout<<ans+1;return;}
			}
		}
		cout<<ans;

}

int main(){
    fastio;randomINIT;

    //cin>>t;
    while(t--){
        MAIN();
    }

    #ifndef ONLINE_JUDGE
    cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    #endif
}

Measured memory_bytes: 97348
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <array>
#include <algorithm>
#include <set>
#include <iomanip>
#include <cstdio>
#include <queue>

using namespace std;

#define int long long

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

    int in;
    int ans = 0;

    string s;

    cin >> s;

    s[3] = '8';

    cout << s << endl;

}

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

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using mii = map<int, int>;
using msi = map<string, int>;
using pii = pair<int, int>;

struct Edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    Edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<Edge>>;

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

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

int main() {
	int n,k;
	cin>>n>>k;
	
	int t;
	
	bool mod=0;
	if(k%2==0) {
		t=k/2;
		mod=1;
	}
	int tmp=n;
	
	long long numbera=0;//half
	long long numberb=0;//all
	
	if(mod) {
		if(n>=t) {
			tmp-=t;
			numbera++;
		}
		while(tmp>=k) {
			tmp-=k;
			numbera++;
		}
	}
	
	tmp=n;
	while(tmp>=k) {
		tmp-=k;
		numberb++;
	}
	
	long long ans=0;
	
	ans+=(numbera*numbera*numbera);
	ans+=(numberb*numberb*numberb);
		
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define mp make_pair
#define ll long long
#define pb push_back

void solve()
{

  int n;
  cin>>n;

  vector<int>v(n);

  int i,j;
  int maxi = INT_MIN;

  
  
  for(i=0;i<n;i++)
  {
      cin>>v[i];
      maxi = max(maxi, v[i]);
      
      
  }
  int gcd  = v[0];
  
  vector<int>sieve(maxi+1,-1);
  
  sieve[1] = 1;

  for(i=2;i<=maxi;i++)
  {
      if(sieve[i]!=-1)continue;

      for(j=i;j<=maxi;j=j+i)
      {
          if(sieve[j]==-1)
            sieve[j] = i;
      }
  }



  bool f = 1;

  map<int,int>m;

  for(auto it=v.begin();it!=v.end();it++)
  {
      int val = *it;
      gcd = __gcd(gcd, val);

      while(val>1)
      {
          int x = sieve[val];

          if(x==-1)
            break;
           m[x]++;

          while(val%x==0)
            val = val/x;
      }
  }
  
  for(auto it=m.begin();it!=m.end();it++)
  {
      if(it->second > 1)f=0;
  }

  if(f==1)
  {
      cout<<"pairwise coprime"<<endl;
      return;
  }
  if(gcd==1)
  {
      cout<<"setwise coprime"<<endl;
      return;
  }

  cout<<"not coprime"<<endl;
}

int main()
{

  int t = 1;
  //cin>>t;

  while(t--)
    solve();

  return 0;
}


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

#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;

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

int main() {
  int w, h, x, y;
  cin >> w >> h >> x >> y;

  double res1 = (double) w * h / 2;
  int res2 = (x + x == w) && (y + y == h);

  cout << fixed << setprecision(10) << res1;
  cout << " " << res2 << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int n,m,l,r,max,min;
    scanf("%d %d",&n,&m);
    max=n;
    min=0;
    for(int i=0;i<m;i++){
        scanf("%d %d",&l,&r);
        if(min<l){
            min=l;
        }
        if(max>r){
            max=r;
        }
    }
    if(max>=min)printf("%d",max-min+1);
    else printf("0");
    return 0;
}

Measured memory_bytes: 128
import bisect
n=int(input())
A=[]
for i in range(n):
  A.append(int(input()))
Ans=[A[-1]]
for i in reversed(range(n-1)):
  a=A[i]
  if a>=Ans[-1]:
    Ans.append(a)
  else:

    Ans[bisect.bisect_right(Ans,a)]=a

print(len(Ans))


Measured memory_bytes: 7844
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int l,r;
	l=r=-1;
	for(int i=0;i<=s.size();i++)
		if(s[i]=='C' && l==-1) l=i;
		else if(s[i]=='F') r=i;
	if(l==-1 || r==-1 || l>r) cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>

int main(){
  char str1[1001];
  
  scanf("%s", str1);
  
  while(strcmp(str1, "0") != 0){
    int sum = 0;
    for(int i = 0; i < (int)strlen(str1); ++i){
      int a = str1[i] - '0';
      sum += a;
    }
    printf("%d\n", sum);
    scanf("%s", str1);
  }
  
  return 0;
}

Measured memory_bytes: 2720
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define tcase int _; cin >> _; while(_--)
const int MAX = 1e6;

ll n, k;

// 5 3
// 2 3
// 1 3
//
// 10 3
// 7 3
// 4 3
// 1 3

void solve() {
	cin >> n >> k;
	cout << min(n%k, k-n%k) << "\n";
}

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

 	solve();

  	return 0;
}



Measured memory_bytes: 3592
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <utility>

#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; i++)
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 (a > b) {a = b; return 1;} return 0; }

typedef long long ll;
using namespace std;
const ll p = 1000000007;

int main() {

    int h, w;
    cin >> h >> w;
    vector<string> a(h, "");
    REP(i, h) cin >> a[i];
    
    vector<vector<ll>> dp(h, vector<ll>(w, 0)); // SSSS.Grid 1 Man
    dp[0][0] = 1ll;
    REP(d, w + h) {
        for (int i = d, j = 0; i >= 0; i--, j++) {
            if (i+1 < h && j   < w && a[i+1][j] == '.') {
                dp[i+1][j] += dp[i][j];
                dp[i+1][j] %= p;
            }
            if (i   < h && j+1 < w && a[i][j+1] == '.') {
                dp[i][j+1] += dp[i][j];
                dp[i][j+1] %= p;
            }
        }
    }

    cout << dp[h-1][w-1] << endl;
    
}

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

#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)

using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;

constexpr int MOD = 1000000007;

struct Point {
    double x, y;
    Point(double x = 0, double y = 0) : x(x), y(y) {}
    Point(const Point& p) : x(p.x), y(p.y) {}

    Point operator+(const Point& p) const { return Point(x + p.x, y + p.y); }
    Point operator-(const Point& p) const { return Point(x - p.x, y - p.y); }
    Point operator*(double k) const { return Point(k * x, k * y); }
    Point operator/(double k) const { return Point(x / k, y / k); }

    bool operator<(const Point& p) const { return x != p.x ? x < p.x : y < p.y; }
    bool operator==(const Point& p) const { return fabs(x - p.x) < 1e-10 && fabs(y - p.y) < 1e-10; }

    static double norm(const Point& p) { return sqrt(p.x * p.x + p.y * p.y); }
    static double dot(const Point& p1, const Point& p2) { return p1.x * p2.x + p1.y * p2.y; }
    static double cross(const Point& p1, const Point& p2) { return p1.x * p2.y - p1.y * p2.x; }
};
typedef Point Vector;

Point projection(const Point& p1, const Point& p2, const Point& p) {
    double dot = Vector::dot(p2 - p1, p - p1);
    double norm = Vector::norm(p2 - p1);
    return Point(p2 - p1) * dot / (norm * norm) + p1;
}

Point reflection(const Point& p1, const Point& p2, const Point& p) {
    Vector pcross = (projection(p1, p2, p) - p) * 2;
    return p + pcross;
}

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

    Point p1, p2;
    cin >> p1.x >> p1.y >> p2.x >> p2.y;

    int q;
    cin >> q;

    rep(i, 0, q) {
        Point p;
        cin >> p.x >> p.y;
        Point ans = reflection(p1, p2, p);
        printf("%.10f %.10f\n", ans.x, ans.y);
    }

    return 0;
}


Measured memory_bytes: 3240
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };



signed main() {
	int i, j;
	int n, k;
	vector<int>list;

	cin >> n >> k;

	for (i = 0; i < n; i++) {
		int num;
		cin >> num;
		list.push_back(num);
	}

	sort(list.begin(), list.end(), greater<int>());

	int minn = 999999999;

	for (i = 0; i < n - (k-1); i++) {
		minn = min(minn, list[i] - list[i + (k - 1)]);
	}
	cout << minn << endl;


	









	getchar();
	getchar();
	return 0;
}

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


int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
vector<char> alp{'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'};
    for(int i = 0; i < S.size(); i++){
    	for(int j = 0; j < 26; j++){
        	if(S[i]== alp[j]){
            	cout << alp[(j+N)%26];
            }
        }
    }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int len; cin >> len;
	string s; cin >> s;
	int ans = 0;
	for(int i = 0; i < 10; i++){
		for(int j = 0; j < 10; j++){
			int l = 0, r = len - 1;
			while(l < len && s[l] != i + '0') l++;
			while(r > -1 && s[r] != j + '0') r--;
			int msk = 0;
			for(int k = l + 1; k < r; k++){
				msk |= 1<<(s[k] - '0');
			}
			ans += __builtin_popcount(msk);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
# B
N, K = map(int, input().split())
a_list = list(map(int, input().split()))
NN = N*(N+1) // 2

arr = [0] * NN
res = 0

# bruce
ind = 0
for i in range(N):
    r = 0
    for j in range(i, N):
        r += a_list[j]
        arr[ind] = r
        ind += 1
        
# get Greedy
for m in range(40, -1, -1):
    cnt = 0
    for i in range(NN):
        if (arr[i] // (2**m)) % 2 == 1:
            cnt += 1
    if cnt >= K:
        res += 2**m
        for i in range(NN):
            if (arr[i] // (2**m)) % 2 == 0:
                arr[i] = 0

print(res)

Measured memory_bytes: 47868
using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;

class Program
{
    static void Main(string[] args)
    {
        var sc = new Scanner();

        int n = sc.nextInt();
        if (n % 2 == 1) Console.WriteLine((double)(n / 2 + 1) / n);
        else Console.WriteLine((double)(n / 2) / n);
    }
}

// chokudai's Scanner
class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <sstream>
#include <string>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <limits>
#include <unordered_map>
#include <unordered_set>
#include <math.h>
#include <fstream>
#include <iterator>
#include <random>
#include <chrono>
 
 
#define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i)
#define set_map_includes(set, elt) (set.find((elt)) != set.end())
#define readint(i) int i; cin >> i
#define readll(i) ll i; cin >> i
#define readdouble(i) double i; cin >> i
#define readstring(s) string s; cin >> s
 
typedef long long ll;
 
using namespace std;

ll modd = 1000*1000*1000+7;

ll binary_search(function<bool(ll)> func, ll start, ll end) {
    /*      func:int ->bool
            returns smallest int x where func(x) evaluates to true, searches in [start,end), it is assumed the values are false, .. , false, true ...
             */
    if (end <= start) {   return end;  }   // has to be here, otherwise func(end-1) in next line could be a problem
    if (!func(end-1)) {  return end;  }
    while (end-start>1) {
        ll mid = (start+end)/2;
        if (func(mid)) {  end = mid;  } else { start = mid;   }
    }
    if (func(start)) {  return start;  } else {  return end;   }
};


template<class T>
T fastpower(T a, long long n) {  // n must be >= 1
  if (n==0) {return 1;}
  if (n % 2 == 0) {  
      T halfpower = fastpower<T>(a, n/2);
      return (halfpower*halfpower) % modd;
  } else {
      if (n == 1) {  return a; } else {  
          T halfpower = fastpower<T>(a, n/2);
          return (((halfpower*halfpower)%modd)*a)%modd;
      }
  }
};


int main()   {

    ios_base::sync_with_stdio(false);

    cout.precision(17);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    uniform_int_distribution<int> rand_gen(0, modd);   // rand_gen(rng) gets the rand no
 
//    auto start = chrono::steady_clock::now();
  
//    readint(test_cases);
    int test_cases = 1;
    forr(t, 1, test_cases) {
        readll(n);
        vector<ll> a;
        forr(i,0,n) {
            readll(kk); a.push_back(kk);
        }
        sort(a.begin(), a.end());

        ll ret = 0;
        multiset<ll> ints;
        ints.insert(a.back());
        for(int i = a.size()-2; i >= 0; --i) {
            ll largest = *prev(ints.end());
            ret += largest;
            ints.erase(prev(ints.end()));
            ints.insert(a[i]);
            ints.insert(a[i]);
        }

        cout << ret << endl;

    }
 
//    auto end = chrono::steady_clock::now();
//    cout << chrono::duration_cast<chrono::milliseconds>(end - start).count() << endl;
 
    return 0;
}

Measured memory_bytes: 14288
#include <bits/stdc++.h>
using namespace std;
#define repr(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;

int main(){
    string s;
    cin >> s;
    int x;
    int a[26]={0};
    x=s.length();
    for(int i=0;i<x;i++){
        a[s[i]-'a']++;
    }
    
    for(int i=0;i<26;i++){
        if(a[i]==0){
            char y=i+'a';
            cout << y << endl;
            return 0;
        }
    }
    
    cout << "None" << endl;
    
    
    return 0;
}








Measured memory_bytes: 512