akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException{

         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
         int n = Integer.parseInt(br.readLine());

         String[] line = br.readLine().split(" ");

      	 int a[] = new int[line.length];

         for(int i=0;i<line.length;i++) {

       	  a[i] = Integer.parseInt(line[i]);

         }
         
         long min = a[0];
         long max = a[0];
         long sum = 0;
         
         for (int i = 0; i < n; i++) {
             min = Math.min(min, a[i]);
             max = Math.max(max, a[i]);
             sum += a[i];
         }

         System.out.println(min +" "+ max+" " + sum);

    }

}

Measured memory_bytes: 28704
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const ll INF = 1e12;
const int MOD = 1000000007;


int main() {
        int n;
        cin >> n;
        vector<ll> a(n);
        rep(i,n) cin >> a.at(i);
        ll ans = 0;
        int before = 0;
        rep(i,n){
                if( before == 1 && a[i] > 0) {ans ++; a[i] --;}
                ans += a[i]/2;
                before = a[i]%2;
        }
        cout << ans << endl;
        return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		char[] N = S.toCharArray();
		String P = "yes";
		for(int i = 0;i < N.length;i++) {
			for(int k = i+1;k < N.length;k++) {
				if(N[i] == N[k])P = "no";
			}
		}
		System.out.println(P);
	}

}

Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>


typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBAC
/*map<Keyの型, Valueの型> 変数名;
queue<型> 変数名;
priority_queue<型> 変数名;
priority_queue<型, vector<型>, greater<型>> 変数名;*/
//copy(v1.begin(), v1.end(), back_inserter(v2));
using namespace std;

int gcd(int a, int b) {
	int c;
	if (a < b) {
		c = a; a = b; b = c;
	}
	while (b != 0) {
		c = a % b; a = b; b = c;
	}
	return a;
}

int sort_greater(int m,int n) {
	vector<int> a(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(),greater<int>());
	for (int i = 0; i < n; i++) {
		cout << a[i];
	}
		return 0;
}

int bubblesort(int a[], int n) {
	int sw = 0;
	bool flag = 1;
	for (int i = 0; flag; i++) {
		flag = 0;
		for (int j = n - 1; j >= i + 1; j--) {
			if (a[j] < a[j - 1]) {
				swap(a[j], a[j - 1]);
				flag = 1;
				sw += 1;
			}
		}
	}
	return sw;
}

int a_z()
{
	for (int i = 0; i <= ('Z' - 'A'); i++) {
		cout << (char)('A' + i);
	}
	return 0;
}

int selecttionsort(int a[], int n) {
	int t,sw = 0, minj;
	for (int i = 0; i < n - 1; i++) {
		minj = i;
		for (int j = 0; j < n - 1; j++) {
			if (a[j] < a[minj]) {
				minj = j;
			}
		}
		t = a[i]; a[i] = a[minj]; a[minj] = t;
		if (i != minj) sw += 1;

	}
	return sw;
}

map<string, int> memo;


int main() {
	//sort(a.begin(),a.end());
	int n;
	cin >> n;
	vector<int> p(n);
	rep(i, n) cin >> p[i];
	int ans = 0,b=p[0];
	rep(i, n) {
		b = min(b, p[i]);
		if (b == p[i]) ans++;
	}
	cout << ans;
	return 0;
}









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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define foreach(e, v) for (auto &e : v)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
constexpr int MOD = 1e9 + 7;
constexpr int INF = __INT_MAX__;               // 2^31 - 1
constexpr long long INFLL = __LONG_LONG_MAX__; // 2^61 - 1
constexpr int MAX_N = 1e5 + 5;
constexpr double PI = acos(-1);

struct mint {
    // Preparation: MOD is already defined.
    ll value;

    mint(ll value = 0) : value((value % MOD + MOD) % MOD) {}

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    mint pow(mint m) const {
        return pow(m.value);
    }

    mint inv() const {
        ll a = value, b = MOD, u = 1, v = 0;
        while (b) {
            ll t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        u %= MOD;
        return u;
    }

    mint &operator+=(const mint a) {
        if ((value += a.value) >= MOD) value -= MOD;
        return *this;
    }
    mint &operator-=(const mint a) {
        if ((value += MOD - a.value) >= MOD) value -= MOD;
        return *this;
    }
    mint &operator*=(const mint a) {
        (value *= a.value) %= MOD;
        return *this;
    }
    mint &operator/=(const mint a) {
        return (*this) *= a.inv();
    }

    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

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

    bool ok = true;
    char last_ = words[0].back();
    rep(i, n - 1) {
        if (last_ != words[i + 1].front())
            ok = false;

        last_ = words[i + 1].back();
    }

    sort(all(words));
    rep(i, n - 1) {
        if (words[i] == words[i + 1])
            ok = false;
    }

    if (ok)
        CYES;
    else
        CNO;
}


Measured memory_bytes: 256
#include<iostream>

#include<cstdio>

#include<iostream>

#include<cstring>
using namespace std;
bool a[100005];
int b[100005];
int main()
{
    int n,m;
    while(cin>>n>>m)
    {
        int i;
        memset(a,0,sizeof(a));
        memset(b,0,sizeof(b));
        for(i=1;i<=n;i++)
            b[i]=1;
        a[1]=1;
        while(m--)
        {
            int x1,x2;
            cin>>x1>>x2;
            if(a[x1]==1&&b[x1]==1)
            {
                a[x1]=0;
                a[x2]=1;
            }
            else if(a[x1]==1)
                a[x2]=1;
            b[x1]--;
            b[x2]++;
        }
        int sum=0;
        for(i=1;i<=n;i++)
        {
            if(a[i]&&b[i]>0)
            {
                sum++;
            }
        }
        cout<<sum<<endl;
    }
}

Measured memory_bytes: 768
use std::io;

fn main() {
    let mut n = String::new();
    io::stdin().read_line(&mut n).ok();
    let n:u32 = n.trim().parse().unwrap();
    let a0 = n/100;
    let a1 = (n/10)%10;
    let a2 = n%10;
    if a0==a2 {
        println!("Yes");
    } else {
        println!("No");
    }
}

Measured memory_bytes: 4352
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    int N; cin >> N;
    string S; cin >> S;

    for(auto c : S) {
        int ord = c - 'A';
        int nxt = (ord + N) % 26;
        cout << (char)('A' + nxt);
    }
    cout << endl;
    return 0;
}


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

int bind[200000];
int nind[200000];
void construct(int n){
	for( int i = 0; i < n; i++ ){
		bind[i] = (i + n - 1) % n;
		nind[i] = (i + 1) % n;
	}
}
int search(bool isRight, int baton, int a){
	int ind = baton;
	if( isRight ){
		for( int i = 0; i < a; i++ )
			ind = nind[ind];
	}
	else{
		for( int i = 0; i < a; i++ )
			ind = bind[ind];
	}
	return ind;
}
int erase(int ind){
	int u = bind[ind];
	int v = nind[ind];
	
	nind[u] = v;
	bind[v] = u;
	bind[ind] = -1;
	nind[ind] = -1;
	return v;
}
int query(int ind){
	return (bind[ind] >= 0);
}

int main(){
	int n, m, q;
	int a;
	int ind;
	
	cin >> n >> m >> q;
	construct(n);
	
	int baton = 0;
	for( int i = 0; i < m; i++ ){
		cin >> a;
		ind = search(a % 2 == 0, baton, a);
		baton = erase(ind);
	}
	
	for( int i = 0; i < q; i++ ){
		cin >> ind;
		cout << query(ind) << endl;
	}
	return 0;
}

Measured memory_bytes: 2724
n = int(input())
div_map = dict()
mod = 10 ** 9 + 7

for i in range(1, n + 1):
    is_prime_number = True
    for j in range(2, int(i ** (1 / 2)) + 1):
        if i % j == 0:
            is_prime_number = False
            break
    if is_prime_number:
        if i not in div_map:
            div_map[i] = 1
        else:
            div_map[i] += 1
    else:
        j = 2
        while i != 1:
            if i % j == 0:
                if j not in div_map:
                    div_map[j] = 1
                else:
                    div_map[j] += 1
                i //= j
            else:
                j += 1


res = 1
div_map[1] = 0
for key, value in div_map.items():
    res = res * (value + 1) % mod

print(res % mod)


Measured memory_bytes: 9268
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define deb(x) cout<< #x << " " << x << "\n";
#define MAX 9223372036854775807
#define MIN -9223372036854775807
#define PI 3.141592653589
#define setbits(n) __builtin_popcountll(n)
const ll mod=1e9+7;

const int N=2e5+1;
vector<ll> a(N),h(N);
ll n;
vector<ll> dp(N);

struct dat{
    ll minm = 2e18;
    ll maxm = -minm;
    dat(){}//default constructor
    dat(ll val){//declare constructor
        minm = maxm = val;
    }
};

struct SegmentTree{
    vector<ll> arr;
    ll n;
    dat combine (const dat & l, const dat & r){//combine Left and Right child
        dat ret;
        ret.minm = min(l.minm, r.minm);
        ret.maxm = max(l.maxm, r.maxm);
        return ret;
    }
    vector<dat> tree;
    SegmentTree(vector<ll> &a){
        arr = a;
        n = a.size();
        tree.resize(4*n);
        build(1, 0, n-1);
    }
    SegmentTree(ll cap){
        n = cap;
        arr.resize(n, 0);
        tree.resize(4*n);
    }
    void build(ll v, ll tl, ll tr) {
        if (tl == tr) {
            tree[v] = dat(arr[tl]);//see base conditions
        } else {
            int tm = (tl + tr) / 2;
            build(v*2, tl, tm);
            build(v*2+1, tm+1, tr);
            tree[v] = combine(tree[v*2] , tree[v*2+1]);
        }
    }
    void update(ll v, ll tl, ll tr, ll pos, ll new_val) {
        if (tl == tr) {
            arr[pos] = new_val;//See update operations
            tree[v] = dat(arr[pos]);
        } else {
            int tm = (tl + tr) / 2;
            if (pos <= tm)
                update(v*2, tl, tm, pos, new_val);
            else
                update(v*2+1, tm+1, tr, pos, new_val);
            tree[v] = combine(tree[v*2], tree[v*2+1]);
        }
    }
    dat query(ll v, ll tl, ll tr, ll l, ll r) {
        if (l > r) 
            return dat();//See what to return
        if (l == tl && r == tr) {
            return tree[v];
        }
        ll tm = (tl + tr) / 2;
        return combine(query(v*2, tl, tm, l, min(r, tm)) ,
            query(v*2+1, tm+1, tr, max(l, tm+1), r));
    }
    void update(ll pos, ll val){
        update(1, 0, n-1, pos, val);
    }
    dat query(ll l, ll r){
        return query(1, 0, n-1, l, r);
    }
};


int main() {
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll T=clock();

    cin>>n;
    for(ll i=0;i<n;i++)
        cin>>h[i];
    for(ll i=0;i<n;i++)
        cin>>a[i];
    SegmentTree st(dp);
    for(int i=0;i<n;i++){
        //for(int j=0;j<h[i];j++)
            //dp[h[i]]=max(dp[h[i]],a[i]+dp[j]);
        dat r=st.query(0,h[i]-1);
        st.update(h[i],a[i]+r.maxm);
    }
    cout<<st.query(0,n).maxm;


 
 
    cerr<<"\n\nTIME: "<<(double)(clock()-T)/CLOCKS_PER_SEC<<" sec\n";
    T = clock();
    return 0;
}

Measured memory_bytes: 21900
#include<iostream>
using namespace std;
int main(){
    int a;
    int b;
    int c;
    cin>>a >>b >>c;
    if (a<=b && b<=c){
        cout<<a<<" "<<b<<" "<<c<<endl;
    }else if (a<=c && c<=b){
        cout<<a<<" "<<c<<" "<<b<<endl;
    }else if (b<=a && a<=c) {
        cout<<b<<" "<<a<<" "<<c<<endl;
    }else if (b<=c && c<=a){
        cout<<b<<" "<<c<<" "<<a<<endl;
    }else if (c<=a && a<=b){
        cout<<c<<" "<<c<<" "<<b<<endl;
    }else if (c<=b && b<=a){
        cout<<c<<" "<<b<<" "<<a<<endl;
    }
    return 0;
}


Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
  

int main(){
  int N;
  cin >> N;
  vector<ll> vec(N);
  int ans=0;
  for(int i=0;i<N;i++){
    cin >> vec[i];
    while(vec[i]%2==0){
      vec[i]/=2;
      ans++;
    }
  }
  cout << ans <<endl;
}

  
  

Measured memory_bytes: 3684
#include <cstdio>
#include <algorithm>

using namespace std;

int main(){
	int n;
	scanf("%d",&n);
	int ecnt = 0, ocnt = 0;
	for (int i = 0; i <n; i++) {
		int d;
		scanf("%d",&d);
		if (d % 2) {
			ocnt++;
		} else {
			ecnt++;
		}
	}
	if (ocnt%2 && n > 1) {
		printf("NO\n");
	} else {
		printf("YES\n");
	}
	return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <algorithm>

using namespace std;

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

    int b = 0;
    int c;
    int q_min = 10;
    for(int i = 0; i < 5; i++){
        c = (a[i] / 10) * 10;
        if(a[i] % 10 == 0){
            b += c;
        }else{
            b += c + 10;
            q_min = min(q_min, a[i] % 10);
        }
    }

    printf("%d\n", b - (10 - q_min));

    return 0;
}

Measured memory_bytes: 128
#include <iostream>

int main()
{
	int a, b, c, count = 0, tmp;
	int s1, s2, s3;
	std::cin >> a >> b >> c;
	if(a < b)
	{
		tmp = b;
		b = a;
		a = tmp;
	}
	if(a < c)
	{
		tmp = c;
		c = a;
		a =tmp;

	}
	//std::cout << max << std::endl;

	while(1)
	{
		if(a == b &&  a == c)
		{
			break;
		
		}else{
			s1 = a - b;
			s2 = a - c;
			
			if(s1 == s2)
			{
				b = b + 1;
				c = c + 1;
				count++;
					//std::cout << count << std::endl;
					//std::cout << a << " " << b << " " << c << std::endl;
				/*if(b == a && c == a)
				{
					break;
				}*/
			}else if(b < a && c < a){
				b = b + 1;
				c = c + 1;
				count++;
					//std::cout << a << " " << b << " " << c << std::endl;
			}else if (a == b){
				s3 = a - c;
				if(s3 % 2  == 0)
				{
					c = c + 2;
					count++;
						//std::cout << a << " " << b << " " << c << std::endl;
				}else{
					b++;
					a++;
					count++;
						//std::cout << a << " " << b << " " << c << std::endl;
				}
			}else if(a == c){
				s3 = a - b;
					//std::cout << s3 << std::endl;
				if(s3 % 2  == 0)
				{
					b = b + 2;
					count++;
						//std::cout << a << " " << b << " " << c << std::endl;
				}else{
					a++;
					c++;
					count++;
						//std::cout << a << " " << b << " " << c << std::endl;
					
				}
			}
		}
	}
	std::cout << count << std::endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 	int n;cin>>n;
  	vector<int> c(n);
  	vector<int> s(n);
  	vector<int> f(n);
  
  	for(int i=0;i<n;i++){
    	cin>>c[i]>>s[i]>>f[i];
    }
  	long long int temp=0;
  	for(int i=0;i<n-1;i++){
      	int temp=s[i]+c[i];
  		for(int j=i+1;j<n-1;j++){
        	if(temp<=s[j]){
            	temp=s[j]+c[j];
            }else if(temp%f[j]==0){
              	temp+=c[j];
            }else{
            	temp+=f[j]-temp%f[j]+c[j];
            }
        }
      cout<<temp<<endl;
  	}  
  cout<<0<<endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		String s = sc.nextLine();
		String[] strs = s.split(" ");
		Map<String,Integer> map = new HashMap<>();
		int length_max = Integer.MIN_VALUE;
		int length_max_i = 0;
		int count_max = Integer.MIN_VALUE;
		for (int i=0; i<strs.length; i++) {
			map.put(strs[i],map.getOrDefault(strs[i],0));
			map.put(strs[i],map.get(strs[i])+1);
			if (length_max < strs[i].length()) {length_max_i = i;}
			length_max = Math.max(length_max,strs[i].length());
			count_max = Math.max(count_max,map.get(strs[i]));
		}
		
		for (Map.Entry<String,Integer> entry : map.entrySet()) {
			int a = entry.getValue();
			if (a==count_max) {System.out.print(entry.getKey());}
		}
		System.out.println(" "+strs[length_max_i]);
	}
}


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

int main()
{
  string S;

  cin >> S;

  bool flag = true;

  for (int i = 0; i < S.length(); i++)
  {
    if (i % 2 == 0)
    {
      if (S.at(i) != 'h')
      {
        flag = false;
        break;
      }
    }
    if (i % 2 == 1)
    {
      if (S.at(i) != 'i')
      {
        flag = false;
        break;
      }
    }
  }

  if (S.length() % 2 != 0)
  {
    flag = false;
  }

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


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


int main()
{
	int n; cin >> n;
	int A[101], x = 1e9, y = 0;
	for (int i = 0; i < n; ++i)
	{
		cin >> A[i];
		x = min(x, A[i]);
		y = max(y, A[i]);
	}
	cout << y-x << endl;
}




Measured memory_bytes: 3600
digit_number, requirements_count = gets.chomp.split(' ').map(&:to_i)

requirements = []
requirements_count.times do
  requirements << gets.chomp.split(' ').map(&:to_i)
end

result = Array.new(digit_number, 0)

f_flag = false


requirements.each do |req|
  target_index = req[0] - 1
  
  if (digit_number >= 2) && (target_index == 0) && req[1] == 0 
    f_flag = true
    break
  elsif  result[target_index] != 0  && result[target_index] != req[1] 
    f_flag = true
    break
  else
    result[target_index] = req[1]
  end
end

result[0] = 1 if digit_number >= 2 && result[0] == 0

if f_flag
  puts -1
else
  puts "#{result[0]}#{result[1]}#{result[2]}".to_i
end


Measured memory_bytes: 1788
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<queue>
#include<stack>
#include<list>
#include<unordered_map>
#include<unordered_set>
#include<cctype>
#include<iomanip>
#include<limits>
#include<bitset>

using namespace std;
typedef long long int ll; typedef pair<int, int> P; typedef unsigned long long int ull;
const ll mod = 1000000007;
const int inf = 1e9 + 7;
const ll linf = 1LL << 60;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define REP(i,m,n) for(int i=(m);i<(int)n;i++)
#define all(a) (a).begin(),(a).end()
#define allg(a) (a).begin(),(a).end(),greater<>()
#define SUM(a) accumulate((a).begin(),(a).end(),0)
#define d10 std::setprecision(10)
#define d20 std::setprecision(20)
#define vec vector<int>
#define vecb vector<bool>
#define vecd vector<double>
using str = string;
const double PI = 3.14159265359;
ll gcd(ll a, ll b) { ll t; while (b != 0) { t = a % b; a = b; b = t; }return a; }
int gcd(int a, int b) { int t; while (b != 0) { t = a % b; a = b; b = t; }return a; }
ll recfact(ll start, ll n) {
	ll i;
	if (n <= 16) {
		ll r = start;
		for (i = start + 1; i < start + n; i++) r = r * i % mod;
		return r % mod;
	}
	i = n / 2;
	return recfact(start, i) % mod * recfact(start + i, n - i) % mod;
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}
ll fct(ll n) { return recfact(1, n); }
ll ncm(ll n, ll m) {
	if (n < m)return 0;
	ll x = (fct(n) % mod / (fct(m) * fct(n - m)) % mod) % mod;
	return x;
}
std::string sreverse(string str, int firstItr, int secondItr) {
	if (firstItr < 0 || secondItr>int(str.size() - 1))return str;
	while (firstItr < secondItr) {
		swap(str[firstItr], str[secondItr]);
		firstItr++; secondItr--;
	}
	return str;
}
std::string RunLengthEncoding(std::string str) {
	int itr = 0; std::string res;
	while (itr < int(str.size())) {
		char tmp = str[itr++];
		int length = 1;
		while (itr <int(str.size()) && str[itr] == tmp) { ++itr; ++length; }
		res.push_back(tmp);
		res += to_string(length);
	}
	return res;
}
std::string split(std::string str, size_t first_itr, size_t second_itr) {
	std::string tmp;
	for (size_t i = first_itr; i < second_itr + 1; i++) {
		tmp.push_back(str.at(i));
	}
	return tmp;
}
ll max(ll a, ll b) {
	return a > b ? a : b;
}
ll min(ll a, ll b) {
	return a < b ? a : b;
}


int main() {
	int n; cin >> n;
	vector<ll> v(n), tmp(n);
	rep(i, n)
	{
		cin >> v[i];
		tmp[i] = v[i];
	}
	sort(allg(v));
	rep(i, n) {
		if (v[0] == tmp[i]) {
			cout << v[1] << endl;
		}
		else {
			cout << v[0] << endl;
		}
	}



	return 0;
}

Measured memory_bytes: 4736
N, K = map(int,input().split())
p = tuple(map(int,input().split()))
MaxSum = sum(p[:K])
tmp_SumSlice = MaxSum
for i in range(K, N):
    tmp_SumSlice = tmp_SumSlice + p[i] - p[i - K]
    if MaxSum < tmp_SumSlice:
        MaxSum = tmp_SumSlice
print((MaxSum+K)/2)

Measured memory_bytes: 25316
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check

const ll INF = 1LL << 60;
const string YES = "Yes";
const string NO = "No";

void solve(long long N){
    if(N == 1){
        cout<<YES<<endl;
        cout<<2<<endl;
        cout<< "1 1"<<endl;
        cout<< "1 1"<<endl;
        return;
    }
    ll k=1;
    bool isGood=false;
    for(;k <=N; k++){
        if(k*(k-1)/2 == N){
            isGood = true;
            break;
        }
            
    }
    if(!isGood){
        cout<<NO<<endl; return;
    }

    vector<vll> G(k);
    map<pll, ll> r;
    ll cnt=0;
    REP(i, k){
        for(ll j =i+1; j < k; j++){
            cnt++;
            G[j].push_back(i);
            G[i].push_back(j);
            r[pll(i, j)] = cnt;
            r[pll(j, i)] = cnt;
        }
    }
    cout<<YES<<endl;
    cout<<k<<endl;
    REP(i, k){
        cout<<G[i].size();
        for(auto j: G[i])
            cout<<" "<<r[pll(i, j)];
        cout<<endl;
    }
    return;
}

int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


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

int main() {
   int A,B,H,M;
   cin >> A >> B >> H >> M;
   double a,b;
   a=2*3.14159265358979*(H*60+M)/720;
   b=2*3.14159265358979*M/60;
   double n;
   n=A*A+B*B-2*A*B*cos(abs(a-b));
   n=sqrt(n);
   cout << fixed << setprecision(10);
   cout << n << endl;
}

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

int main(){
  int H1,M1,H2,M2,K;
  cin >> H1 >> M1 >> H2 >> M2 >> K;
  
  int S,F;
  S = H1*60 + M1;
  F = H2*60 + M2;
  
  int last;
  last = F - K;
  
  int ans = last - S;
  
  cout << ans << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define mp make_pair
#define ft first
#define sd second
#define snd sd.ft
#define td sd.sd
#define debug(x) cout<<"### x is: "<<x<<"###"<<endl
#define all(a) a.begin(),a.end()
 
#define ninf -1000000000
#define pinf 1000000000
 
typedef long long int ll; 
const ll MOD= 1e9+7;
typedef vector<pair<ll,ll> > vecpair;
typedef vector<pair<ll, pair<ll,ll> > > vecpair3;
typedef pair<ll, ll> pi; 
 
//double mei ye line cout << fixed << setprecision(10); kam mei le 
 
ll power(ll a, ll b) {ll ret=1;while(b) {if(b&1) ret*=a;a*=a;if(ret>=MOD) ret%=MOD;if(a>=MOD) a%=MOD;b>>=1;}return ret;}
 
struct subset // disjoint set use subsets.claer and subsets.resize............
{
	int parent,sz;
};
vector< subset> subsets;
int find( int i)
{
    if (subsets[i].parent != i)
        subsets[i].parent = find(subsets[i].parent);
 
    return subsets[i].parent;
}
void uniona(int x, int y){
	if( x == y)
	return ;
    int xroot = find( x);
    int yroot = find( y);
    if (subsets[xroot].sz < subsets[yroot].sz){
        subsets[xroot].parent = yroot;
        subsets[yroot].sz += subsets[xroot].sz;
    }
    else{
        subsets[yroot].parent = xroot;
        subsets[xroot].sz += subsets[yroot].sz;
    }
}
//..............................
 
int n;
int h[100005],dp[100005];

ll solve(ll i)
{
	if(i>n)
      return pinf;
  else if(i==n)
    	return 0;
  else if(dp[i]!=-1)
    return dp[i];
  dp[i]=min(abs(h[i]-h[i+1])+solve(i+1),abs(h[i]-h[i+2])+solve(i+2));
    return dp[i];
}
int main()
{
	std:ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	cin >> n;
	for(int i=0;i<100005;i++)
    dp[i]=-1;
  	for(int i=1;i<=n;i++)
    {
    	cin >> h[i];
    }	
  	int ans=solve(1);
  	//for(int i=1;i<=n;i++)
  	//	 debug(dp[i]);
	cout << dp[1];
	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<map>
#include<math.h>
#include<queue>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int MOD = 1000000007;
const int mod = 1000000007;
const int INF = 1000000000;
const long long LINF = 1e18;
const int MAX = 510000;
int main() {
	int cng = 0;
	int ans = 0;
	int ansr = 0, ansl = 0;
	int l = 0, r = 0;
	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;
	for (int i = 0; i < s.size() - 1; i++) {
		if (s[i] != s[i + 1])cng++;
		else if (s[i] == s[i + 1] )ans++;
		//else if (s[i] == s[i + 1] && s[i] == 'L')ansl++;
		
	}
	if (s[0] == s[n - 1]) {
		if (cng/2 <= k) {
			ans = n - 1;

		}
		else {
			ans += 2 * k;
		}
	}
	else {
		if ((cng - 1) / 2 >= k) {
			ans += 2 * k;
		}
		else {
			ans = n - 1;
		}
	}
	cout << ans<<endl;
	return 0;
}

Measured memory_bytes: 3696
fun main(args: Array<String>) {
    abc072c()
}

fun abc072c() {
    val n = readLine()!!.toInt()
    val aList = readLine()!!.split(" ").map { it.toInt() }
        .sorted()

    val grouped = aList.groupBy { it }

    val answer = aList.map { (grouped[it - 1]?.size ?: 0) + (grouped[it]?.size ?: 0) + (grouped[it + 1]?.size ?: 0) }
        .max()

    println(answer)
}


Measured memory_bytes: 58196
import java.util.*;
import java.util.stream.Collectors;

class City implements Comparable<City>{
	final int num;
	final int prefecture;
	private final int year;

	City(int num, int prefecture, int year){
		this.num = num;
		this.prefecture = prefecture;
		this.year = year;
	}

	String toString(int number){
		return String.format("%06d%06d", prefecture, number);
	}

	@Override
	public int compareTo(City o) {
		return Comparator.<City>comparingInt(t -> t.year).compare(this, o);
	}
}

class Solver {
	static final Solver INSTANCE = new Solver();

	void solve(Scanner sc) {
		int N = sc.nextInt();
		int M = sc.nextInt();
		PriorityQueue<City> cities = new PriorityQueue<>(N);
		for (int i = 0; i < M; i++) {
			int P = sc.nextInt();
			int Y = sc.nextInt();
			cities.add(new City(i, P, Y));
		}

		int[] prefecturesCounter = new int[N];
		String[] output = new String[M];
		while (!cities.isEmpty()){
			City city = cities.remove();
			output[city.num] = (city.toString(prefecturesCounter[city.prefecture - 1]++ + 1));
		}
		System.out.println(String.join("\n", output));
	}
}

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

		Solver.INSTANCE.solve(in);

		in.close();
	}
}

Measured memory_bytes: 157872
# include<bits/stdc++.h>
using namespace std;
int main (){
int n;
cin>>n;
if (((n%10000)/1000)==((n%1000)/100) and ((n%1000)/100)==((n%100)/10)){
    cout<<"Yes";
}
else if(((n%1000)/100)==((n%100)/10) and ((n%100)/10)==(n%10))
    cout<<"Yes";

else
    cout<<"No";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,ans=0;
	cin >> n;
	int a[n];
	for(int i=0;i<n;i++){
		cin >> a[i];
		if(a[i]%2!=0){
			ans++;
		}
	}
	if(ans%2==0){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 640
def solve(N, Y):
    for x in range(N + 1):
        for y in range(N - x + 1):
            z = N - x - y
            if 10000 * x + 5000 * y + 1000 * z == Y:
                return x, y, z
    return -1, -1, -1


N, Y = list(map(int, input().split()))
x, y, z = solve(N, Y)
print('{} {} {}'.format(x, y, z))

Measured memory_bytes: 3064
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		if((b-2*a)%2==0&&4*a-b>=0&&b>=2*a) {
			System.out.println("Yes"); 
		}else {
			System.out.println("No");
		}
		

	}

}


Measured memory_bytes: 35804
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> l(N);
    for(int i = 0; i < N; i++)
        cin >> l[i];
    sort(l.begin(), l.end(), greater<int>());
    int length = 0;
    for(int i = 0; i < K; i++)
        length += l.at(i);
    cout << length << endl;
    return 0;
}

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

const int MAXN = 2e5 + 5;

int N, K;
int perm[MAXN];
int mini[MAXN], maks[MAXN];
int dad[MAXN], rnk[MAXN];
int bad[MAXN];

void load() {
	scanf("%d%d", &N, &K);
	for (int i = 0; i < N; i++)
		scanf("%d", perm + i);
}

int find(int x) {
	return dad[x] == x ? x : dad[x] = find(dad[x]);
}

void join(int x, int y) {
	x = find(x);
	y = find(y);
	if (x == y)
		return;
	if (rnk[x] > rnk[y])
		swap(x, y);
	dad[x] = y;
	rnk[y] += rnk[x] == rnk[y];
}

int solve() {
	for (int i = 0; i < N; i++)
		dad[i] = i;
	
	for (int i = 1; i < N; i++)
		bad[i] = bad[i - 1] + (perm[i - 1] > perm[i]);
	
	set <int> curr;
	for (int i = 0; i < N; i++) {
		curr.insert(perm[i]);
		if (i >= K)
			curr.erase(perm[i - K]);
		if (i >= K - 1) {
			mini[i - K + 1] = *curr.begin();
			maks[i - K + 1] = *curr.rbegin();
		}
	}
	
	int last = -1;
	for (int i = 0; i + K - 1 < N; i++) {
		if (bad[i + K - 1] == bad[i]) {
			if (last != -1)
				join(last, i);
			last = i;
		}
		if (i + K - 1 < N - 1 && perm[i] == mini[i] && perm[i + K] == maks[i + 1])
			join(i, i + 1);
	}
	
	int sol = 0;
	for (int i = 0; i + K - 1 < N; i++)
		sol += find(i) == i;
	
	return sol;
}

int main() {
	load();
	printf("%d\n", solve());
	return 0;
}

Measured memory_bytes: 13568
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<queue>
#include<stack>
#include<list>
#include<set>
#include<cstring>
#include<string>
using namespace std;
int main(){
	char n;
	int a,b;
    scanf("%d %d",&a,&b);
    for(int s=0;s<a;s++){
        cin>>n;
        if(n<'0'||n>'9'){
            printf("No\n");
            return 0;
        }
    }
    cin>>n;
    if(n!='-'){
        printf("No\n");
        return 0;
    }
    for(int s=0;s<b;s++){
        cin>>n;
        if(n<'0'||n>'9'){
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
    return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> V(30),C(30);
  for(int i=0;i<N;i++)cin >> V[i];
  for(int i=0;i<N;i++)cin >> C[i];
  int ans=0;
  for(int i=0;i<N;i++){ans+=max(0,V[i]-C[i]);}
  cout << ans << endl;
}

Measured memory_bytes: 256
import sys
input=sys.stdin.readline #文字列入力はするな！！
sys.setrecursionlimit(10**9) #再帰の上限をあげる
n=int(input())
a=list(map(int,input().split()))
z=[0]*(10**6+1)
ans=0
for i in a:
    z[i]+=1

x=[-1]*(10**6+1) #2以上の自然数に対して最小の素因数を表す
x[0]=0
x[1]=1
i=2
prime=[]
while i<=10**6:
    if x[i]==-1:
        x[i]=i
        prime.append(i)
    for j in prime:
        if i*j>10**6 or j>x[i]:break
        x[j*i]=j
    i+=1

for i in a:
    f=0
    u=i
    if z[u]>=2:
        f=1
    w=[[1,1]]
    p=x[u]
    cnt=1
    while u>1:
        if p==x[u//p]:
            cnt+=1
            u=u//p
        else:
            w.append([p,cnt])
            cnt=1
            u=u//p
            p=x[u]

    m=len(w)

    def s(d,h,y):
        global m
        global i
        global f
        if d==m-1:
            p=y*(w[d][0]**h)
            if p!=i and z[p]>=1:
                f=1
        else:
            y*=w[d][0]**h
            for j in range(w[d+1][1]+1):
                s(d+1,j,y)

    s(0,1,1)
    if f==0:
        ans+=1
print(ans)


Measured memory_bytes: 122452
from collections import defaultdict

s = input()
n = len(s)
mod = 2019
DP = [0 for i in range(n+2)]
DP[n+1] = 0

num = 1
for i in reversed(range(n)):
    DP[i] = (DP[i+1] + int(s[i])*(num))%mod
    num = num*10%mod
DP.pop(-1)

arr = defaultdict(int)
for dp in DP:
    arr[dp]+=1

ans = 0
for i in arr.values():
    ans += i*(i-1)//2
print(ans)


Measured memory_bytes: 17032
from collections import Counter
n=int(input())
x=list(map(int,input().split()))
a=[]
b=[]
for i in range(n):
    a.append(x[i]+i+1)
    b.append((i+1)-x[i])
a,b=Counter(a),Counter(b)
ans=0
for i in range(n):
    ans+=a[i]*b[i]
print(ans)

Measured memory_bytes: 63376
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) ((y)<0||(x)<0||(y)>=(h)||(x)>=(w))
#define dump(...)
const signed INF_=1001001001; const ll INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":"\n");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
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;}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct{template<class T> operator T(){T x;cin>>x;return x;}} IN;
struct before_main_function {
    before_main_function() {
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int N,M;
    cin>>N>>M;
    if(N==1 && M==1) {
        cout<<1<<endl;
    } else if(N==1) {
        cout<<max(0LL,M-2)<<endl;
    } else if(M==1) {
        cout<<max(0LL,N-2)<<endl;
    } else {
        cout<<max(0LL,N-2)*max(0LL,M-2)<<endl;
    }
    return 0;
}



Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

s = input()
t = ['SAT','FRI','THU','WED','TUE','MON','SUN']
for i in range(7):
    if s == t[i]:
        print(i+1)

Measured memory_bytes: 64620
#include<iostream>
using namespace std;
static const int MAX = 1000;

void trace(int a[], int n){
  for(int i=0; i<n; i++ ){
    if(i>0)cout<<' ';
    cout<<a[i];
  }
  cout<<endl;   
}

void insertionSort(int a[], int n){
  for( int i=1; i <=n-1; i++ ){
    int v=a[i];
    int j=i-1;
    while( j>= 0 && a[j] > v ){
      a[j+1] = a[j];
      j--;
    }
    a[j+1] = v;
    trace(a,n);
  }
}

int main(){
  int n, a[MAX], v, j;

  cin >> n;

  for( int i=0; i<n; i++ ) cin >> a[i];

  trace(a,n);
  insertionSort(a,n);
  
  return 0;

}


Measured memory_bytes: 3088
N,Q = map(int,input().split())
tree = [[] for i in range(N+1)]
for i in range(N-1):
    a,b = map(int,input().split())
    tree[a].append(b)
    tree[b].append(a)

value = [0]*(N+1)
for i in range(1,Q+1):
    p,x = map(int,input().split())
    value[p] += x

from collections import deque
todo = deque([(1,0)])

while len(todo) > 0:
    child,parent = todo.pop()
    value[child] += value[parent]
    for next in tree[child]:
        if next == parent:
            continue
        else:
            todo.append((next,child))

print(' '.join(map(str,value[1:])))

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

int main() {
  char c;
  cin >> c;
  if ((c == 'a') || (c == 'e') || (c == 'i') || (c == 'o') || (c == 'u')) {
    cout << "vowel" << endl;
  } else {
    cout << "consonant" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int H, W;
	cin >> H >> W;
	int dp[1010][1010] = { 0 };
	vector<string> S;
	REP(i, H) {
		string s;
		cin >> s;
		S.push_back(s);
	}
	dp[0][0] = 1;
	REP(i, H) {
		REP(j, W) {
			if (S[i][j] == '#')continue;
			if (i == 0) {
				if (j == 0)continue;
				else {
					if(S[i][j]=='.')dp[i][j] = dp[i][j - 1];
				}
			}
			else {
				if (j == 0)dp[i][j] = dp[i - 1][j];
				else {
					dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
				}
			}
			dp[i][j] %= mod;
		}
	}
	cout << dp[H - 1][W - 1] << endl;

	return 0;
}



Measured memory_bytes: 9344
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,F,A;
  cin >> N >> F >> A;
  vector<int> M (F,0);
  for (int i = 0; i<F ; i++ ) {
    cin >> M[i];
  }
  int ans = 0;
  for (int i = 0; i<N ; i++ ) {
    int D = 0;
    for ( int j = 0 ; j<F ; j++ ) {
      int E;
      cin >> E;
      D += E * M[j];
    }
    D+=A;
    if ( D > 0 ) {
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
N = 8
M = 1 << N

POPCOUNT = M.times.map do |i|
  N.times.select { |j| i >> j & 1 == 1 }.size
end

CANDIDATE = M.times.map do |i|
  N.times.select { |j| i >> j & 1 == 0 }
end

class Queen
  attr_accessor :ans, :seen

  def initialize(ans = nil, seen = nil)
    @ans = ans || [0] * N
    @seen = seen || [0] * N
  end

  def dup
    Queen.new(@ans.dup, @seen.dup)
  end

  def candidate
    seen.each_with_index do |row, y|
      CANDIDATE[row].each do |x|
        yield dup.set(y, x)
      end
    end
  end

  def goal?
    ans.map { |v| POPCOUNT[v] }.inject(:+) == N
  end

  def set(y, x)
    set_queen(y, x)
    set_column(x)
    set_row(y)
    set_diag(y, x, 1, 1)
    set_diag(y, x, 1, -1)
    set_diag(y, x, -1, 1)
    set_diag(y, x, -1, -1)
    self
  end

  def set_queen(y, x)
    ans[y] |= 1 << x
  end

  def set_column(x)
    mask = 1 << x
    seen.map! { |v| v | mask }
  end

  def set_row(y)
    seen[y] = M - 1
  end

  def set_diag(y, x, dx, dy)
    inside = ->y, x, h, w { 0 <= y && y < h && 0 <= x && x < w }
    while inside[y, x, N, N]
      seen[y] |= 1 << x
      x += dx
      y += dy
    end
  end

  def to_s
    ans.map do |v|
      sprintf("%0*b", N, v).gsub(/0/, ".").gsub(/1/, "Q").reverse
    end.join("\n")
  end

  def inspect
    seen.map do |v|
      sprintf("%0*b", N, v).gsub(/0/, ".").gsub(/1/, "x").reverse
    end.join("\n") + ("-" * N) + to_s
  end
end

v = Queen.new
n = gets.to_i
n.times do
  y, x = gets.split.map &:to_i
  v.set(y, x)
end

que = [v]
while !que.empty?
  now = que.shift
  if now.goal?
    puts now
    exit
  else
    now.candidate do |nq|
      que << nq
    end
  end
end



Measured memory_bytes: 11652
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int,int> pii;
typedef pair <db,db> pdd;
typedef vector<int> vi;
//typedef vector<vector<int> > matrix;
 
#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))
 
#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
 
inline int gcd(int a,int b){if(a==0) return b;return gcd(b%a,a);}
inline int power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}
const double EPS = 1e-9;
const ll MOD=998244353;
const ll hell=1000000007;
const int INF = 1e16;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937 rng(seed);
 
double startTime;
double getCurrentTime() {
    return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}
const int dx[] = { -1, 0, 1, 0 };
const int dy[] = { 0, 1, 0, -1 };
 
const int N=200005;

int dp[N+1];vi adj[N+1];
int ans[N+1];

int m;

void dfs(int u,int p)
{
dp[u]=1%m;
for(int v:adj[u])
{
    if(v!=p)
    {
        dfs(v,u);
        dp[u]=(dp[u]*(1+dp[v]))%m;
    }
}
}
void dfs(int u,int p,int z)
{

ans[u]=(dp[u]*(1+z))%m;
z++;
vi ve;
int n1=0;
for(int v:adj[u])
{
    if(v!=p)
    {
        ve.pb(v);
        n1++;
    }
}
if(ve.empty())
return;
int pr[n1+1];
pr[0]=1%m;
int suff[n1+2];
for(int i=1;i<=n1;i++)
pr[i]=(pr[i-1]*(1+dp[ve[i-1]]))%m;
suff[n1+1]=1%m;
for(int i=n1;i>=1;i--)
suff[i]=(suff[i+1]*(1+dp[ve[i-1]]))%m;

for(int i=0;i<ve.size();i++)
{
    int x=(pr[i]*suff[i+2])%m;
    dfs(ve[i],u,(z*x)%m);
}


}


void solve()
{
int n;
cin>>n>>m;
int u,v;
for(int i=0;i<n-1;i++)
{
    cin>>u>>v;
    adj[u].pb(v);
    adj[v].pb(u);
}
dfs(1,0);
dfs(1,0,0);
for(int i=0;i<n;i++)
cout<<ans[i+1]<<endl;




}

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


Measured memory_bytes: 29060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

int main(int argc, char *argv[]) { ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
  int n,k;cin>>n>>k;
  vector<int> v(n);
  for(int i=0;i<n;i++)cin>>v[i];

  ll ans=pow(10,10);
  for(int i=0;i<n;i++){
    int nx = i+k-1;
    if(nx>=n)break;
    ll t1 = abs(v[i]) + abs(v[i]-v[nx]);
    ll t2 = abs(v[nx]) + abs(v[nx]-v[i]);
    ans = min(ans, min(t1, t2));
  }
  cout<<ans<<endl;

  
  return 0;
}


Measured memory_bytes: 3704
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <complex>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << (x) << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 2010

char s[SIZE][SIZE];
int memo[SIZE][SIZE] = {};

int main(){
  int h,w;
  scanf("%d%d",&h,&w);

  for(int i=0;i<h;i++){
    scanf("%s",s[i]);
  }

  vector<pair<pair<int,int>,int> > ans;
  
  int max_ans = w;
  
  for(int i=1;i<h;i++){

    vector<pair<pair<int,int>,int> > ans2;

    memset(memo, -1, sizeof(memo));
    
    ans.push_back({{0,w-1},i-1});
    
    for(int j=0;j<ans.size();j++){
      int l = ans[j].first.first;
      int r = ans[j].first.second;

      int t = (s[i-1][l] == '#') ^ (s[i][l] == '#');

      for(int k=l;k<=r;k++){
        if( ((s[i-1][k] == '#') ^ (s[i][k] == '#')) != t){

          if(memo[l][k-1] == -1 && (h - ans[j].second)*(k-l) > max_ans){
            memo[l][k-1] = ans[j].second;
            max_ans = max(max_ans,(i - ans[j].second + 1) * (k - l));
            ans2.push_back({{l,k-1},ans[j].second});
          }
          t = (s[i-1][k] == '#') ^ (s[i][k] == '#');
          l = k;
        }
      }

      if(memo[l][r] == -1 && (h - ans[j].second)*(r - l + 1) > max_ans){
        memo[l][r] = ans[j].second;
        max_ans = max(max_ans,(i - ans[j].second + 1) * (r - l + 1));
        ans2.push_back({{l,r},ans[j].second});
      }
      
    }

    ans = ans2;
  }
  
  printf("%d\n",max_ans);
  
  return 0;
}


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

int solve(const int& num) {
  int tmp = num;
  int digit_sums = 0;
  while (tmp > 0) {
    digit_sums += tmp % 10;
    tmp /= 10;
  }
  return digit_sums;
}

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

  if (N % solve(N) == 0) {
    printf("Yes");
  } else {
    printf("No");
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MAIN 200010
using namespace std;
map <int,int> mp;
struct node
{
    int a,b;
    bool operator < (const node &xx) const
    {
        return b<xx.b;
    }
} data[MAIN];
int main()
{
    mp.clear();
    int n,k,a[MAIN];
    cin>>n>>k;
    for(int i=1; i<=n; i++)
    {
        cin>>a[i];
        mp[a[i]]++;
    }
    if(mp.size()<=k)
    {
        cout<<"0"<<endl;
        return 0;
    }
    int tot=0;
    for(auto it: mp)
    {
        data[++tot].a=it.first;
        data[tot].b=it.second;
    }
    sort(data+1,data+1+tot);
    int ans=0;
    for(int i=1; i<=(mp.size()-k); i++)
        ans+=data[i].b;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 11904
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;

int main() {
	long long N; cin >> N;
	if (N < 65 || N > 122 || (N > 90 && N < 97)) cout << 0 << endl;
	else if (N >= 65 && N <= 90) cout << 1 << endl;
	else cout << 2 << endl;
	return 0;
}


Measured memory_bytes: 3104