akhauriyash/Code-Regression huggingface dataset:
from itertools import product, combinations
N,M,K=map(int, raw_input().split())


mod=10**9+7
fact, inv_fact = [1], [1]
fact_tmp = 1
for i in range(1, N*M+1):
    fact_tmp *= i
    fact_tmp %= mod
    fact.append(fact_tmp)
    inv_fact.append(pow(fact_tmp, mod-2, mod))
 
 
def ncr(n,r):
	if n < 0 or r < 0 or n < r:	return 0
	else:	return (fact[n] * inv_fact[r] * inv_fact[n-r]) %mod


torisuu=ncr(N*M-2,K-2)

ans=0
for i in range(N):
	for j in range(M):
		l_sum=(1+j)*j/2*N		#left
		r_sum=(1+(M-j-1))*(M-j-1)/2*N	#right	
		u_sum=(1+i)*i/2*M		#upper
		d_sum=(1+(N-i-1))*(N-i-1)/2*M	#down
		ans+=(l_sum+r_sum+u_sum+d_sum)*torisuu
		ans%=mod

print ( ans*pow(2,mod-2,mod) ) %mod

Measured memory_bytes: 60188
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;

struct Dsu
{
public:
    this(int n)
    {
        _n = n, parent_or_size = new int[](n);
        parent_or_size[] = -1;
    }

    int merge(int a, int b)
    {
        assert(0 <= a && a < _n);
        assert(0 <= b && b < _n);
        int x = leader(a), y = leader(b);
        if (x == y)
            return x;
        if (-parent_or_size[x] < -parent_or_size[y])
        {
            auto tmp = x;
            x = y;
            y = tmp;
        }
        parent_or_size[x] += parent_or_size[y];
        parent_or_size[y] = x;
        return x;
    }

    bool same(int a, int b)
    {
        assert(0 <= a && a < _n);
        assert(0 <= b && b < _n);
        return leader(a) == leader(b);
    }

    int leader(int a)
    {
        assert(0 <= a && a < _n);
        if (parent_or_size[a] < 0)
            return a;
        return parent_or_size[a] = leader(parent_or_size[a]);
    }

    int size(int a)
    {
        assert(0 <= a && a < _n);
        return -parent_or_size[leader(a)];
    }

    int[][] groups()
    {
        auto leader_buf = new int[](_n), group_size = new int[](_n);
        foreach (i; 0 .. _n)
        {
            leader_buf[i] = leader(i);
            group_size[leader_buf[i]]++;
        }
        auto result = new int[][](_n);
        foreach (i; 0 .. _n)
            result[i].reserve(group_size[i]);
        foreach (i; 0 .. _n)
            result[leader_buf[i]] ~= i;
        int[][] filtered;
        foreach (r; result)
            if (r.length != 0)
                filtered ~= r;
        return filtered;
    }

private:
    int _n;
    int[] parent_or_size;
}

void main()
{
    auto nq = readln.split.to!(int[]);
    auto N = nq[0];
    auto Q = nq[1];
    auto dsu = Dsu(N);
    while (Q--) {
        auto tuv = readln.split.to!(int[]);
        auto t = tuv[0];
        auto u = tuv[1];
        auto v = tuv[2];
        if (t == 0) {
            dsu.merge(u, v);
        } else {
            writeln(dsu.same(u, v) ? 1 : 0);
        }
    }
}

Measured memory_bytes: 4416
n = int(input())
count = 0

for i in range(n):
      DICE,dice = [int(x) for x in input().split()]
      if DICE == dice:
            count += 1
      else:
            count = 0
      
      if count >= 3:
            break

if count >= 3:
      print("Yes")
else:
      print("No")

Measured memory_bytes: 9180
#include<stdio.h>

int main(){
  int x,y,z;
  int *px = &x,*py = &y,*pz = &z;
  int temp;
  scanf("%d""%d""%d",&x,&y,&z);
  temp = *px;
  *px = *py;
  *py = temp;

  int temp2;
  temp2 = *px;
  *px = *pz;
  *pz = temp2;

  printf("%d"" ""%d"" ""%d\n",*px,*py,*pz);
  return 0;

}

Measured memory_bytes: 1732
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }

ll ans = 0;
void calc(set<ll>& X, int now_num, int K, ll dig, int d) {
    if (X.size() > K) return;
    
    set<ll> new_X;
    ll t;
    REP(j, 0, 10) {
        for(auto &x : X){
            auto S = to_string(x);
            if (S.size() < d) {
                if (j <= 1) {
                    ans = ll(j) * (dig * 10) + x;
                    if (j != 0 && new_X.count(ans) == 0)
                        now_num++;
                    new_X.insert(ans);
                }
            }
            else if (
                j == (S[0] - 0x30) - 1 ||
                j == (S[0] - 0x30) ||
                j == (S[0] - 0x30) + 1)
            {
                ans = j * (dig * 10) + x;
                if (j != 0 && new_X.count(ans) == 0)
                    now_num++;
                new_X.insert(ans);
                
            }
            if (now_num >= K) break;
        }
        if (now_num >= K) break;
    }
    if (now_num >= K) return;
 
    calc(new_X, now_num, K, dig * 10, d + 1);
}

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

    set<ll> X;
    REP(i, 0, 10) {
        if (i == K) {
            cout << i << endl;
            return 0;
        }
        X.insert(i);
    }
    calc(X, 9, K, 1, 1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5376
n = int(input())
A = list(map(int,input().split()))
A_0 = A.sort(reverse=True)
swt = 0
Alice_point = 0
Bob_point = 0

for i in range(n):
    if swt == 0:
        Alice_point += A[i]
        swt = 1
    else:
        Bob_point += A[i]
        swt = 0
print(Alice_point - Bob_point)


Measured memory_bytes: 3060
n = gets.to_i
s = gets.chomp!
ans = 1
prime = 1000000007
array = []
("a".."z").each { |c|
  array.push([c,0])
}
s.chars { |c|
  array.each { |a|
    if a[0] == c
      a[1] += 1
    end
  }
}

# p array

array.each { |a|
  ans *= (a[1]+1)
  ans = ans % prime
}
puts ans-1


Measured memory_bytes: 1916
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

double distance(ddatas& x,ddatas& y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

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

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}
void judgement(int a){
  if(a){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  if(a){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}

int main(){
  ll i,j,N,K,H,a,b,ans=0,res,cnt=0;
  cin>>N;
  K=pow(2,N);
  vec v(N);
  pmat g(N);
  rep(i,N){
    cin>>H;
    g[i].resize(H);
    rep(j,H){
      cin>>a>>b;
      g[i][j]=datas(a-1,b);
    }
  }
  while(K--){
    res=1;
    cnt=0;
    rep(i,N){
      if(K&(1LL<<i)){
        cnt++;
        v[i]=1;
      }else{
        v[i]=0;
      }
    }
    if(cnt<=ans)continue;
    rep(i,N){
      if(v[i])for(auto j:g[i]){
        if(v[j.first]!=j.second)res=0;
      }
    }
    if(res){
      ans=cnt;
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 512
use std::io;
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

fn main() {
    let line: Vec<usize> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();
    
    let a = line[0];
    let b = line[1];
    let q = line[2];

    let mut s = Vec::with_capacity(a);
    for i in 0..a {
        let val: u64 = read_line().trim().parse().unwrap();
        s.push(val);
    }
    let mut t = Vec::with_capacity(b);
    for i in 0..b {
        let val: u64 = read_line().trim().parse().unwrap();
        t.push(val);
    }

    for i in 0..q {
        let query:u64 = read_line().trim().parse().unwrap();
        let mut low = 0;
        let mut high = a;
        while high - low > 1 {
            let mid = (high + low) / 2;
            if s[mid] <= query {
                low = mid;
            } else {
                high = mid;
            }
        }
        let si = low;
        let mut low = 0;
        let mut high = b;
        while high - low > 1 {
            let mid = (high + low) / 2;
            if t[mid] <= query {
                low = mid;
            } else {
                high = mid;
            }
        }
        let ti = low;
        let mut ans = query + s[si] + t[ti];
        if s[si] > query && t[ti] > query {
            ans = cmp::min(ans, cmp::max(s[si], t[ti]) - query);
        }
        if s[si] <= query && t[ti] <= query {
            ans = cmp::min(ans, query - cmp::min(s[si], t[ti]));
        }
        if si + 1 < a && t[ti] <=query {
            ans = cmp::min(ans, query - t[ti] + (s[si+1] - query) * 2);
            ans = cmp::min(ans, (query - t[ti])*2 + s[si+1] - query);
        }
        if si + 1 < a && t[ti] > query {
            ans = cmp::min(ans, cmp::max(s[si+1], t[ti]) - query);
        }
        if s[si] > query && t[ti] <= query {
            ans = cmp::min(ans, query - t[ti] + (s[si] - query) * 2);
            ans = cmp::min(ans, (query - t[ti])*2 + s[si] - query);
        }
        if ti + 1 < b && s[si] <= query {
            ans = cmp::min(ans, query - s[si] + (t[ti+1] - query) * 2);
            ans = cmp::min(ans, (query - s[si])*2 + t[ti+1] - query);
        }
        if ti + 1 < b && s[si] > query {
            ans = cmp::min(ans, cmp::max(s[si], t[ti+1]) - query);
        }
        if s[si] <= query && t[ti] > query {
            ans = cmp::min(ans, query - s[si] + (t[ti] - query) * 2);
            ans = cmp::min(ans, (query - s[si])*2 + t[ti] - query);
        }
        if si + 1 < a && ti + 1 < b {
            ans = cmp::min(ans, cmp::max(s[si+1], t[ti+1]) - query);
        }
        if si + 1 < a && ti + 2 < b {
            ans = cmp::min(ans, cmp::max(s[si+1], t[ti+2]) - query);
        }
        if si + 2 < a && ti + 1 < b {
            ans = cmp::min(ans, cmp::max(s[si+2], t[ti+1]) - query);
        }

        println!("{}", ans);
    }
}


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

using namespace std;

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

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

// 最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

// 素因数分解
map<ll, ll> prime_sum;

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

void solve_abc_e() {
	ll l_ans = 0;
	ll n;

	cin >> n;

	V a(n);
	rep(i, n) cin >> a[i];

	// 1
	bool is_pc = true;
	map<ll, ll> pf;
	rrep(i, n - 1, 1) {
		pf = prime_factor(a[i]);
		for (auto itr = pf.begin(); itr != pf.end(); itr++) {
			if (prime_sum.find(itr->first) != prime_sum.end()) {
				is_pc = false;
				break;
			}
			++prime_sum[itr->first];
		}
	}
	if (is_pc) {
		cout << "pairwise coprime" << "\n";
		return;
	}

	// 2
	ll all_gcd = a[0];
	rep(i, n) all_gcd = gcd(all_gcd, a[i]);

	if (all_gcd == 1) {
		cout << "setwise coprime" << "\n";
	}
	else {
		cout << "not coprime" << "\n";
	}

	return;
}

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

	solve_abc_e();

	return 0;
}

Measured memory_bytes: 15800
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        String t = sc.next();
        String ans = "";
        for(int i = 0;i<n;i++){
            ans += s.charAt(i);
            ans += t.charAt(i);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, nuint_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set; 
#define int long long
#define MOD 1000000007
#define what_is(x) cerr << #x << " is " << x << endl;
#define loop(i,a,n) for(int i=a;i<n;i++)
#define pb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, szof(x))
#define sortall(x) sort(aint(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626 
 
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef pair<int, int> pt;

signed main() {

	fastio();
	//#define LOCAL_DEFINE	
	#ifdef LOCAL_DEFINE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	//https://leetcode.com/problems/maximum-nesting-depth-of-two-valid-parentheses-strings/
	int n;
	cin>>n;
	vector<int> arr1(n,INT_MAX);
	vector<pair<int,int>> arr(n-1);
	for(int i=0;i<(n-1);i++)
	{
		int x;
		cin>>x;
		arr[i]={x,i};
	}
	sort(all(arr));
	for(int i=0;i<(n-1);i++)
	{
		int x=arr[i].ff;
		int y=arr[i].ss;
		arr1[y]=min(x,arr1[y]);
		arr1[y+1]=min(x,arr1[y+1]);
	}
	int ans=0;
	for(int i=0;i<n;i++)
	{
		//cout<<arr1[i]<<endl;
		ans+=arr1[i];
	}
	cout<<ans;
	return 0;
 
 }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  string S,T;
  cin>>S>>T;
  
  
  int ans=0;
  
  for(int i=0;i<S.size();i++){
    if(S[i]!=T[i]){
      ans++;
    }
  }
  
  cout<<ans<<endl;
}

Measured memory_bytes: 3860
#include <iostream>

using namespace std;

int main() 
{
    char a, b;
    cin >> a >> b;

    if (a == 'H') {
        cout << b << endl;
    }   
    else if (a == 'D' && b == 'H') {
        cout << 'D' << endl;
    }   
    else if (a == 'D' && b == 'D') {
        cout << 'H' << endl;
    }   
}


Measured memory_bytes: 256
#include <iterator>
#include <typeinfo>
#include <list>
#include <map>     
#include <numeric>
#include <utility>
#include <queue>
#include <set>
#include <sstream>
#include <iomanip>
#include <iostream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define rep(a,t) for(int a=0;a<t;++a) 
#define forever while(true)
#define Sort(a) sort(a.begin(),a.end())
#define Reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define int_maxvalue numeric_limits<int>::max()
ll mod = 1e9 + 7;
string Addition(string a,string b) {
	string ans = "";
	int bef = 0;
	int be1 = 0;
	for (int i = a.length() - 1; i >= 0; i--) {
		int added = stoi(a.substr(i, 1)) + stoi(b.substr(i, 1))+be1;

		if (added >= 10) {
			bef = 1;
			added -= 10;
		}
		else {
			bef = 0;
		}

		ans = to_string(added)+ans;
		/*/
		stringstream ss;
		ss << added;

		ans = ss.str() + ans;*/
		be1 = bef;
		if (i == 0)
		{
			break;
		}
	}
	if (be1 == 1) {
		ans = "1" + ans;
	}
	return ans;
}
int main() {
	int n;
	cin >> n;
	rep(o1, n) {
		string a, b;
		cin >> a >> b;
		if (a.length() < b.length()) {
			swap(a, b);
		}
		string b1 = b;
		for (int i = 0; i < a.length() - b1.length(); ++i) {
			b = '0' + b;
		}
		string ans = Addition(a, b);
		if (ans.length() > 80) { cout << "overflow" << endl; }
		else {
			cout << ans << endl;
		}
	}
	return 0;
}



Measured memory_bytes: 3272
#include <bits/stdc++.h>
#define int long long int
#define endl "\n"
#define mod 1000000007
#define ps(x,noOfDecimal) fixed<<setprecision(noOfDecimal)<<x
  
using namespace std;
signed main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(); cout.tie();
   int a ,b,c,d;
   cin>>a>>b>>c>>d;

   int val1 = a*c;
   int val2 = a*d;
   int val3 = b*c;
   int val4 = b*d;

   int ans = max(val1,max(val2,max(val3,val4)));
   cout<<ans;

  return 0;
}


Measured memory_bytes: 3596
s = input()
a,b = 0,0
for key,i in enumerate(s):
  if (key % 2):
    if i == "0":
      a += 1
    else:
      b += 1
  else:
    if i == "0":
      b += 1
    else:
      a += 1
print(min(a,b))
    

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

#define ran 202202

int n;
int a[ran], b[ran];

int main() {
	scanf("%d", &n);
	for(int i=0;i<n;i++) scanf("%d%d", &a[i], &b[i]);
	sort(a, a+n);
	sort(b, b+n);
	
	int lo = a[n/2], hi = b[n/2];
	if(n%2==0) {
		lo += a[n/2-1];
		hi += b[n/2-1];
	}
	printf("%d\n", hi-lo+1);
	
	return 0;
}


Measured memory_bytes: 5380
#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++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n == 0) return 1;

    ll res = modpow(x, n/2);
    if(n%2 == 0) return res*res%mod;
    else return res*res%mod*x%mod;
}

ll power(ll x, ll n){
    if(n == 0) return 1;

    ll res = power(x, n/2);
    if(n%2 == 0) return res*res;
    else return res*res*x;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

/* <--------------------------------------------> */

typedef tuple<ll, ll, ll> T;
// get<K>(tuple型の変数)



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

    int n; cin >> n;
    string s; cin >> s;
    s = '0'+s;
    vector<vector<int>> dp(n+5, vector<int>(n+5, 0));

    repr(i, 1, n+1){
        repr(j, i+1, n+1){
            if(s[i]==s[j]){
                dp[i][j] = min(j-i, dp[i-1][j-1]+1);
            }
        }
    }
    int ans=0;
    repr(i, 1, n+1) repr(j, i+1, n+1) chmax(ans, dp[i][j]);
    cout << ans << endl;

    return 0;
}



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

using namespace std;

int main(void)
{
    ios::sync_with_stdio(false);
    int n;
    while(cin >> n, n) {
        vector<int> v;
        for(int i = 512; i >= 1; i /= 2) {
            if(n < i) continue;
            n -= i;
            v.push_back(i);
            if(n <= 0) break;
        }
        for(int i=v.size()-1; i>=0; i--) {
            printf("%d%c", v[i], i ? ' ' : '\n');
        }

    }


    return 0;
}

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

const int INF = 1e9 + 5;

int main() {
  int h, w, k;
  cin >> h >> w >> k;
  vector<string> s(h);
  for (int i = 0; i < h; i++) {
    cin >> s[i];
  }
  int ans = INF;
  for (int div = 0; div < 1<<(h -1); div++) {
    int g = 0;
    vector<int> id(h);
    for (int i = 0; i < h; i++) {
      id[i] = g;
      if (div>>i&1) {
        g++;
      }
    }
    g++;

    vector<vector<int> > c(g, vector<int>(w, 0));
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        c[id[i]][j] += (s[i][j] - '0');
      }
    }

    int num = g - 1;
    vector<int> now(g);
    auto add = [&](int j) {
      for (int i = 0; i < g; i++) {
        now[i] += c[i][j];
      }
      for (int i = 0; i < g; i++) {
        if (now[i] > k) {
          return false;
        }
      }
      return true;
    };

    for (int j = 0; j < w; j++) {
      if (!add(j)) {
        num++;
        now = vector<int>(g);
        if (!add(j)) {
          num = INF;
          break;
        }
      }
    }
    ans = min(ans, num);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
from collections import deque

n, m = map(int, input().split())

graph = [[] for _ in range(n+1)]
for i in range(m):
    a,b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)

dist = [0] * (n + 1)

d=deque()
d.append(1)

while d:
    v = d.popleft()
    
    for i in graph[v]:
        if not dist[i]:
            dist[i] = v
            d.append(i)

ans = dist[2:]
print('Yes')
print(*ans,sep='\n')



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



int main(){
    int A[3][3],B[3][3];
    int i=0,j=0;
    rep(i,3){
        rep(j,3){
            cin >>A[i][j];
            B[i][j] = 0;
        }
    }
    int N;
    cin >>N;
    int b[N];
    for(int i=0;i<N;i++){
        cin >>b[i];
        for(int j=0;j<3;j++){
            for(int k=0;k<3;k++){
                if(A[j][k] == b[i]){
                    B[j][k] = 1;
                }
            }
        }
    }
    if((B[0][0]==1)&(B[1][1]==1)&(B[2][2] == 1)){
        cout <<"Yes"<<endl;
        return 0;
    }
    else if((B[2][0]==1)&(B[1][1]==1)&(B[0][2] == 1)){
        cout <<"Yes"<<endl;
        return 0;
    }
    for(int i=0;i<3;i++){
        if((B[i][0]==1)&(B[i][1]==1)&(B[i][2] == 1)){
            cout <<"Yes"<<endl;
            return 0;
        }
        else if((B[0][i]==1)&(B[1][i]==1)&(B[2][i] == 1)){
            cout << "Yes"<<endl;
            return 0;
        }
    }
    cout << "No" << endl;

}

Measured memory_bytes: 256
S = input()

a = S[0] == 'A'
b = S[2:-1].count('C') == 1
if a and b:
    S = list(S)
    S_1 = S[2:-1]
    S_1.remove('C')
#    print(S[0:2])
#    print(S_1)
#    print(S[-1:])
    S = S[0:2] + S_1 + S[-1:]
    del S[0]
#    print(S)
    c = str(S).islower()

if a and b and c:
    print('AC')
else:
    print('WA')


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            int P = in.nextInt();
            int Q = in.nextInt();
            int R = in.nextInt();
            int max = Math.max(P, Math.max(Q, R));
            System.out.println((P + Q + R) - max);
        }
    }
}


Measured memory_bytes: 23764
#include <stdio.h>
#define LL long long
int main(void){
	LL N[100];
	N[0] = 2;
	N[1] = 1;
	for (int i = 2; i < 87; i++) {
		N[i] = N[i-1] + N[i-2];
	}
	int i;
	scanf("%d", &i);
	printf("%lld\n", N[i]);

}


Measured memory_bytes: 128
#include <bits/stdc++.h>
 
using namespace std;
 
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()
#define rep(i, st, n) for (int i = (st); i < (n); ++i)
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;
 
template <typename T1, typename T2> bool chkmin(T1 &x, T2 y) { return y < x ? (x = y, true) : false; }
template <typename T1, typename T2> bool chkmax(T1 &x, T2 y) { return y > x ? (x = y, true) : false; }

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
#ifdef DEBUG
    freopen("in", "r", stdin);
#endif
    
    string s;
    cin >> s;
    int n = s.size();
    bool ok = true;
    for (int i = 0; i < n; i += 2)
        ok &= s[i] != 'L';
    for (int i = 1; i < n; i += 2)
        ok &= s[i] != 'R';
    cout << (ok ? "Yes\n" : "No\n");

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include <cmath>
#include <iomanip>
#include <regex>
#include <bits/stdc++.h>
#include <string>
using namespace std;


int main(){
    long N;
    cin>>N;
    long a[N];
    for(long i=0;i<N;i++){
        cin>>a[i];
    }
    long res=0;
    for(long i=0;i<N;i++){
        if(res+1==a[i])res++;
    }
    if(res == 0){
        cout<<-1<<endl;
        return 0;
    }

    cout<<N-res<<endl;
}

Measured memory_bytes: 1792
import java.io.PrintWriter;
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);

    PrintWriter out = new PrintWriter(System.out);

    int h = sc.nextInt();
    int w = sc.nextInt();
    char[][] arr = new char[h][w];
    int[][] dp = new int[h][w];

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

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

    void run() {
        for (int i=0; i<h; i++) {
            arr[i] = sc.next().toCharArray();
        }

        for (int i=0; i<h; i++) {
            for (int j=0; j<w; j++) {
                for (int k=0; k<2; k++) {
                    int ny = i + dy[k];
                    int nx = j + dx[k];
                    if (0<=ny && ny<h && 0<=nx && nx<w) {
                        if (arr[ny][nx]=='.') {
                            int up = Integer.MAX_VALUE;
                            int left = Integer.MAX_VALUE;
                            if (0<=ny-1) {
                                up = dp[ny-1][nx];
                            }
                            if (0<=nx-1) {
                                left = dp[ny][nx-1];
                            }
                            dp[ny][nx] = Math.min(up, left);
                        } else if (arr[ny][nx]=='#') {
                            int up = Integer.MAX_VALUE;
                            int left = Integer.MAX_VALUE;
                            if (0<=ny-1) {
                                up = dp[ny-1][nx];
                            }
                            if (0<=nx-1) {
                                left = dp[ny][nx-1];
                            }
                            if (0<=ny-1) {
                                if (arr[ny-1][nx]=='.') {
                                    up = dp[ny-1][nx]+1;
                                } else {
                                    up = dp[ny-1][nx];
                                }
                            }
                            if (0<=nx-1) {
                                if (arr[ny][nx-1]=='.') {
                                    left = dp[ny][nx-1]+1;
                                } else {
                                    left = dp[ny][nx-1];
                                }
                            }
                            dp[ny][nx] = Math.min(up, left);
                        }
                    }
                }
            }
        }
//        for (int i=0; i<h; i++) {
//            for (int j=0; j<w-1; j++) {
//                out.print(dp[i][j]);
//            }
//            out.println(dp[i][w-1]);
//        }
        if (arr[0][0]=='#') out.println(dp[h-1][w-1]+1);
        else out.println(dp[h-1][w-1]);
        out.flush();
    }
}


Measured memory_bytes: 23572
S = list(input())

N = int(len(S))
num = 0

for i in range(int((N-1)/2)):
    if S[i] == S[int((N-1)/2-1-i)]:
        pass
    else:
        num += 1

for j in range(int((N-1)/2)):
    if S[int((N-1)/2+1+j)] == S[int(N-1-j)]:
        pass
    else:
        num += 1

for k in range(int(N)):
    if S[k] == S[N-k-1]:
        pass
    else:
        num += 1


if num == 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int n,ans;
int q[N],f[N];
int dp[N],a[N];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	memset(q,0x3f,sizeof(q));
	for(int i=1;i<=n;i++)
	{
		f[i]=upper_bound(q+1,q+n,-a[i])-q;
		q[f[i]]=-a[i];
		ans=max(ans,f[i]);
	}
	cout<<ans<<endl;
 } 

Measured memory_bytes: 4816
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

long long n, t;
vector<long long> tvec(200200, 0);

int main() {
    cin >> n >> t;
    long long sum = 0;
    for(int i = 0; i < n; ++i) cin >> tvec.at(i);
    long long next = 0;
    for(int i = 0; i < n; ++i) {
        if(next >= tvec.at(i)) {
            sum += tvec.at(i) - (next-t);
            next = tvec.at(i)+t;
        }else {
            sum += t;
            next = tvec.at(i)+t;
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 1792
s = input()
T = input()
n_s = len(s)
n_t = len(T)
S = ""
for i in range(n_s-n_t+1):
    s_i = s[i:n_t+i]
    flag = True
    for j in range(n_t):
        if s_i[j] != "?":
            if s_i[j] != T[j]:
                break
    else:
        S = s[:i] + T + s[n_t+i:]
#print(S)
if S == "":
    print("UNRESTORABLE")
    exit()
    
S = list(S)
for i in range(n_s):
    if S[i] == "?":
        S[i] = "a"
print("".join(S))


Measured memory_bytes: 61952
#include <bits/stdc++.h>
#include <cassert>
typedef long long int ll;
using namespace std;


int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N, A, B; cin >> N >> A >> B;
  ll diff = B - A;
  if (diff % 2 == 0) {
    cout << diff / 2 << endl;
    return 0;
  }
  ll prep = min(A - 1, N - B);
  cout << (prep + 1) + ((diff - 1) / 2) << endl;

  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <ctype.h>
#include <math.h>
#include <stack>
#include <string>
#include <string.h>
using namespace std;
double PI = 3.1415926535897932;
long mod = 1000000007;

const long INF = 1e9 + 1;

int main() {
  int a[3];
  cin >> a[0] >> a[1] >> a[2];
  sort(a,a+3);
  if(a[0] == a[1] & a[1] == a[2]) cout << "No" << endl;
  else if(a[0] != a[1] & a[1] != a[2]) cout << "No" << endl;
  else if(a[0] == a[1] & a[1] != a[2]) cout << "Yes" << endl;
  else if(a[0] != a[1] & a[1] == a[2]) cout << "Yes" << endl;
}


Measured memory_bytes: 3576
#include <iostream>
#include <vector>

using namespace std;

int main() {
	long long int n, x;
	cin >> n >> x;
	vector<long long int> a(n);
	vector<long long int> c(n);
	for (long long int i = 0; i < n; i++) {
		cin >> a[i];
		c[i] = a[i];
	}
	long long int d = 0;
	for (long long int i = 0; i < n-1; i++) {
		if (a[i]+a[i+1] > x) {
			int b = a[i]+a[i+1]-x;
			if (b > 0 && a[i+1] >= b) {
				a[i+1] -= b;
			} else {
				b -= a[i+1];
				a[i+1] = 0;
				a[i] -= b;
			}
		}
		d += c[i]-a[i];
		//cout << a[i] << ' ';
	}
	d += c[n-1]-a[n-1];
	cout << d << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <unordered_map>
#include <cmath>
#include <cstdlib>
#include <memory.h>
#include <ctime>
#include <bitset>

using namespace std;

#define ABS(a) ((a>0)?a:-(a))
#define MIN(a,b) ((a<b)?(a):(b))
#define MAX(a,b) ((a<b)?(b):(a))
#define FOR(i,a,n) for (int i=(a);i<(n);++i)
#define FI(i,n) for (int i=0; i<(n); ++i)
#define pnt pair <int, int>
#define mp make_pair
#define PI 3.1415926535897
#define MEMS(a,b) memset(a,b,sizeof(a))
#define LL long long
#define U unsigned

vector<vector<int>> g;
int a[100100];
bool ok;
LL dfs(int v, int par) {
	LL sum = 0;
	LL max1 = 0;
	bool wasChild = false;
	FOR(i,0,g[v].size()) {
		if (!ok) {
			return 0;
		}
		int to = g[v][i];
		if (to == par) {
			continue;
		}
		LL val = dfs(to, v);
		sum += val;
		max1 = max(max1, val);
		wasChild = true;
	}
	if (!ok) {
		return 0;
	}
	if (!wasChild) {
		return a[v];
	}
	LL maxC = 0;
	if (max1 + max1 <= sum) {
		maxC = sum / 2;
	} else {
		maxC = sum - max1;
	}
	LL c = sum - a[v];
	if ((c < 0) || (c > maxC)) {
		ok = false;
		return 0;
	}
	return sum - c - c;
}

int main()
{
#ifdef Fcdkbear
	freopen("in.txt", "r", stdin);
	double beg = clock();
	//freopen("out.txt", "w", stdout);
#endif

	int n;
	scanf("%d",&n);
	FOR(i,0,n) {
		scanf("%d",&a[i]);
	}
	g.resize(n);
	FOR(i,0,n-1) {
		int v1,v2;
		scanf("%d%d",&v1,&v2);
		v1--;
		v2--;
		g[v1].push_back(v2);
		g[v2].push_back(v1);
	}
	if (n == 2) {
		if (a[0] == a[1]) {
			printf("YES\n");
		} else {
			printf("NO\n");
		}
		return 0;
	}
	int root = 0;
	FOR(i,0,n) {
		if (g[i].size() > 1) {
			root = i;
		}
	}
	ok = true;
	LL val = dfs(root, -1);
	if ((ok) && (val == 0)) {
		printf("YES\n");
	} else {
		printf("NO\n");
	}

#ifdef Fcdkbear
	double end = clock();
	fprintf(stderr, "*** Total time = %.3lf ***\n", (end - beg) / CLOCKS_PER_SEC);
#endif
	return 0;
}


Measured memory_bytes: 13184
#include<bits/stdc++.h>
#define endl '\n'

using namespace std;

int vertices, aristas, a, b;
vector<int> grafo[100005];
int indegree[100005];
vector<int> orden_topologico;
int dp[100005];

bool dame_orden_topologico()
{
    queue<int> cola;
    for(int i = 1; i <= vertices; i++)
    {
        if(indegree[i] == 0)
            cola.push(i);
    }

    while(!cola.empty())
    {
        int elemento = cola.front();
        cola.pop();

        orden_topologico.push_back(elemento);

        for(int i = 0; i < grafo[elemento].size(); i++)
        {
            int temp = grafo[elemento][i];
            indegree[temp] -= 1;
            if(indegree[temp] == 0)
                cola.push(temp);
        }
    }

    // siempre es un DAG
    return true;
}

bool tiene_aristas(int v)
{
    return grafo[v].size() != 0;
}

void imprimir()
{
    cout << "orden topologico" << endl;
    for(int i = 0; i < orden_topologico.size(); i++)
    {
        cout << orden_topologico[i] << " ";
    }
    cout << endl;

    cout << "dp" << endl;
    for(int i = 1; i <= vertices; i++)
    {
        cout << dp[i] << " ";
    }
    cout << endl;
}

int metodo()
{
    for(int k = 0; k < orden_topologico.size(); k++)
    {
        int v = orden_topologico[k];
        for(int i = 0; i < grafo[v].size(); i++)
        {
            int temp = grafo[v][i];
            dp[temp] = max(dp[v] + 1, dp[temp]);
        }
    }
}

int get_max()
{
    int maximo = INT_MIN;
    for(int i = 0; i <= vertices; i++)
    {
        maximo = max(maximo, dp[i]);
    }
    return maximo;
}

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

    cin >> vertices >> aristas;

    for(int i = 0; i < aristas; i++)
    {
        cin >> a >> b;

        grafo[a].push_back(b);
        indegree[b] += 1;
    }

    dame_orden_topologico();
    metodo();
    //imprimir();

    int resp = get_max();

    cout << resp << endl;
}



Measured memory_bytes: 7032
#include<iostream>

using namespace std;

int main()
{
    int S;
    cin >> S;
    int h, m, s;
    h = S / 3600;
    m = (S % 3600) / 60;
    s = (S - (h * 3600) - (m * 60));
    cout << h <<':' << m << ':' << s << endl;
    return 0;
}

Measured memory_bytes: 3092
def main():
    X, Y = list(map(int, input().split(' ')))
    # a + b = X
    # 2a + 4b = Y
    if Y % 2 == 0 and 2*X <= Y <= 4*X:
        print('Yes')
    else:
        print('No')



if __name__ == '__main__':
    main()

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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
ll mod = 1000000007;

ll doubling(ll a, ll b) {
    // return a^b
    ll ans = 1;
    ll base = a;
    while (b != 0) {
        if (b & 1) {
            ans *= base;
            ans %= mod;
        }
        base *= base;
        base %= mod;
        b >>= 1;
    }
    return ans;
}

ll comb_single(ll a, ll b) {
    ll up = 1, down = 1;
    b = min(b, a - b);
    if (b < 0) {
        return 0;
    }
    rep(i, b) {
        up *= a - i;
        up %= mod;
        down *= b - i;
        down %= mod;
    }
    return (up * doubling(down, mod - 2)) % mod;
}

int main() {
source:
    ll n, a, b;
    cin >> n >> a >> b;
    ll all = doubling(2, n) - 1;
    ll ans = all + mod * 2 - comb_single(n, a) - comb_single(n, b);
    ans %= mod;
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
 
public class Main {
 
    void solve() throws IOException {
        Random rand = new Random();
        int d = ni();
        int[] c = new int[26];
        for (int i = 0; i < 26; i++) {
            c[i] = ni();
        }
        int[][] s = new int[d][26];
        for (int i = 0; i < d; i++) {
            for (int j = 0; j < 26; j++) {
                s[i][j] = ni();
            }
        }

        int count = 0;
        int maxscore = 0;
        int[] best = new int[d];
        while(count<100){
            int[] t = new int[d];
            for (int i = 0; i < t.length; i++) {
                t[i] = rand.nextInt(26);
            }
            int score = 0;
            int[] last = new int[26];
            for (int i = 1; i <= d; i++) {
                score += s[i-1][t[i-1]];
                last[t[i-1]] = i;
                for (int j = 0; j < 26; j++) {
                    score -= c[j]*(i-last[j]);
                }
            }
            if(maxscore < score){
                maxscore = score;
                best = t;
            }
            count++;
        }
        for (int i = 0; i < d; i++) {
            out.println(best[i]+1);
        }

    }

 
    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }
 
    int ni() throws IOException {
        return Integer.parseInt(ns());
    }
 
    long nl() throws IOException {
        return Long.parseLong(ns());
    }
 
    double nd() throws IOException {
        return Double.parseDouble(ns());
    }
 
    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }
 
    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }
 
    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }
 
    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;
 
    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

Measured memory_bytes: 36676
import std.algorithm;
import std.bigint;
import std.concurrency;
import std.container;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.meta;
import std.numeric;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.typecons;


auto solve(long N, long M, long[] X) {
    auto goals = X.sort();
    return goals.back - goals.front - iota(M - 1)
        .map!(i => goals[i + 1] - goals[i])
        .array
        .sort!"a > b"
        .take(N - 1)
        .sum;
}


void main() {
    auto input = stdin.byLine.map!split.joiner;

    long N;
    N = input.front.to!long;
    input.popFront;

    long M;
    M = input.front.to!long;
    input.popFront;

    long[] X = new long[](cast(size_t) (M));
    foreach (i; 0 .. cast(size_t) (M)) {
        X[i] = input.front.to!long;
        input.popFront;
    }

    static if (is(ReturnType!solve == void))
        solve(N, M, X);
    else
        solve(N, M, X).writeln;
}


Measured memory_bytes: 7404
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    static class CHonestOrUnkind2
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var list = new List<List<Tuple<int, int>>>();

            for (int i = 0; i < n; i++)
            {
                var a = int.Parse(Console.ReadLine());
                list.Add(new List<Tuple<int, int>>());
                for (int j = 0; j < a; j++)
                {
                    var xy = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();                    
                    list[i].Add(Tuple.Create(xy[0]- 1, xy[1]));
                }
            }

            int honestCount = 0;
            int maxHonestCount = 0;
            for (int bit = 0; bit < (1 << n); bit++)
            {
                honestCount = 0;

                if (!IsHonest(bit, list)) { continue; }

                for (int i = 0; i < n; i++)
                {
                    if ((bit & (1 << i)) > 0) { honestCount++; }
                }

                maxHonestCount = Math.Max(maxHonestCount, honestCount);
            }
            
            Console.WriteLine(maxHonestCount);
            Console.ReadLine();
        }

        static bool IsHonest(int bit, List<List<Tuple<int, int>>> list)
        {
            for (int i = 0; i < list.Count; i++)
            {
                // Number"i" is honest? Unkind is skip.
                if ((bit & (1 << i)) == 0) { continue; }

                foreach (var item in list[i])
                {
                    // Evidence is honest, but temp is unkind.
                    if (item.Item2 == 1 && (bit & (1 << item.Item1)) == 0)
                    {
                        // Exists unkind in bit.
                        return false;
                    }
                    // Evidence is unkind, but temp is honest.
                    if (item.Item2 == 0 && (bit & (1 << item.Item1)) > 0)
                    {
                        // Exists unkind in bit.
                        return false;
                    }
                }
            }

            // Not exists unkind in bit.
            return true;
        }
    }
}

Measured memory_bytes: 11476
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <math.h>
#include <string>
#include <cstring>
#include <set>
#include <map>
#include <unordered_map>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<int,pair<int,int>> piii;
typedef vector<int> vi;
typedef vector<pii> vii;

#define ri(a) scanf("%d", &a)
#define rii(a,b) scanf("%d %d", &a, &b)
#define riii(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define rl(a) scanf("%lld", &a)
#define rll(a,b) scanf("%lld %lld", &a, &b)
#define FOR(i,n,m) for(int i=n; i<m; i++)
#define ROF(i,n,m) for(int i=n; i>m; i--)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define f first
#define s second

const int INF = 0x3f3f3f3f;
const ll LLINF = 1e18;
const int maxN = 100006; // CAMBIAR ESTE

// GJNM
int arr[maxN];

int main(){
	int n,k;
	rii(n,k);
	FOR(i,0,n)
		ri(arr[i]);
	if ( n <= k )
		printf("1\n");
	else{
		register int cnt = 1;
		n -= k;
		cnt += (n+k-2)/(k-1);
		printf("%d\n", cnt);
	}
	
	return 0;
}

Measured memory_bytes: 640
import collections
def solve(n, a_list):

    count = collections.Counter()
    for i in a_list:
        no = 8 if i // 400 >= 8 else i // 400
        count[no] += 1

    tmp = len([i for i in count.keys() if i != 8])
    max_value = tmp + count[8]
    min_value = 1 if tmp == 0 else tmp

    return "{0} {1}".format(min_value, max_value)

if __name__ == "__main__":
    n = int(input())
    a_list = [int(i) for i in input().split()]
    print(solve(n, a_list))

Measured memory_bytes: 3316
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
const int mod=998244353;
inline void add(int &x,int y){(x+=y)>=mod?x-=mod:0;}
vector<int>d[101];
map<long long,int>dp[101][101][2];
int n;
long long w[101][101][101],t[101];
char s[101];
int solve(int l,int r,bool b,long long p)
{
	if(l==r)return p==-1?s[l]-'0'+1:p+1;
	if(dp[l][r][b].count(p))return dp[l][r][b][p];
	int sum=0;
	if(p==-1)
	{
		if(!b)for(int k=l;k<r;++k)sum=(sum+1ll*solve(l,k,1,-1)*solve(k+1,r,0,-1))%mod;
		for(int i:d[r-l+1])add(sum,solve(l,l+i-1,0,w[l][l+i-1][(r-l+1)/i]));
	}
	else
	{
		if(!b)for(int k=l;k<r;++k)sum=(sum+1ll*solve(l,k,1,p&t[k-l+1])*solve(k+1,r,0,p>>k-l+1))%mod;
		for(int i:d[r-l+1])
		{
			long long np=p&t[i];
			for(int j=1;j<(r-l+1)/i;++j)np&=p>>i*j;
			add(sum,solve(l,l+i-1,0,np));
		}
	}
//	printf("%d %d %lld %d\n",l,r,p,sum);
	dp[l][r][b][p]=sum;
	return sum;
}
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	for(int i=1;i<=n/2;++i)t[i]=(1ll<<i)-1;
	for(int len=1;len<=n/2;++len)
		for(int i=n-len+1,j=n;i;--i,--j)
		{
			for(int k=0;k<len;++k)if(s[i+k]=='1')w[i][j][1]|=1ll<<k;
			for(int k=2;i+k*len-1<=n;++k)w[i][j][k]=w[i][j][1]&w[i+len][j+len][k-1];
		}
	for(int i=1;i<=n;++i)
		for(int j=2*i;j<=n;j+=i)d[j].push_back(i);
	printf("%d",solve(1,n,0,-1));
	return 0;
}

Measured memory_bytes: 19456
#include <bits/stdc++.h>
using namespace std;
const char duom[] ="i.txt";

int weight[100005];
long long value [100005];
long long dp[100005];
long long ans;
int main()
{
  // ifstream cin (duom);
   int n,w;
   cin >>n>>w;
   for(int i=1;i<=n;i++)
   {
       cin >> weight[i]>>value[i];
   }
   for(int i=1;i<=w;i++)dp[i]=-1;
   dp[0]=0;
   for(int i=1;i<=n;i++)
   {
       for(int j=w;j>=0;j--)
       {
           if(dp[j]!=-1&&j+weight[i]<=w)
           {
               dp[j+weight[i]]=max(dp[j+weight[i]],dp[j]+value[i]);
               ans=max(dp[j+weight[i]],ans);
           }
       }
   }
cout << ans;
    return 0;
}



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

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for(auto &i : A) cin >> i;
    
    for(auto e = A.begin() + 1; e != A.end()+1; e++){
        sort(A.begin(), e);
        for(int i = 0; i < N-1; i++){
            cout << A[i] << " ";
        }
        cout << A[N-1] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1212