akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<vector>
#include<iomanip>
#include<map>
#include<set>
#include<utility>
#include<iterator>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
//#define t ll t;cin>>t;while(t--)
#define nn cout<<endl;
#define ff(a,n) for(ll i=a;i<n;i++)
#define cY cout<<"YES\n"
#define cN cout<<"NO\n"
#define cy cout<<"Yes\n"
#define cn cout<<"No\n"
#define sc second
#define fs first
#define c(a) cout<<a<<endl

void solve()
{
	ll n, k; cin>>n>>k; ll a[n];
	ff(0,n) cin>>a[i];
	sort(a, a+n);
	ll ans=0;
	ff(0,k)ans+=a[i];
	cout<<ans;
}

int main()
{
	solve();
}
/*
5 3
50 100 80 120 80



*/


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

string s;
int ok;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> s;
	for (int i=0;i<(int)s.size();i++){
		if (s[i]=='C'){
			for (int j=i+1;j<(int)s.size();j++){
				if (s[j]=='F') ok++;
			}
			break;
		}
	}
	cout << (ok?"Yes":"No") << "\n";
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <utility>
#include <map>

using namespace std;

template <class RandomIt, class T>
ptrdiff_t num_element(RandomIt first, RandomIt last, T value, T lb_, T ub_) {
    RandomIt ub=upper_bound(first, last, make_pair(value, ub_));
    RandomIt lb=lower_bound(first ,last, make_pair(value, lb_));
    return ub-lb;
}

bool testcase_ends() {
    size_t N;
    int M;
    if (scanf("%zu %d", &N, &M) == EOF)
        return 1;

    vector<pair<int, int>> X(N);
    map<int, int> maxrem;
    for (size_t i=0; i<N; ++i) {
        scanf("%d", &X[i].first);
        X[i].second = X[i].first/M;
        X[i].first %= M;
        maxrem[X[i].first] = max(maxrem[X[i].first], X[i].second);
    }

    sort(X.begin(), X.end());

    size_t res=0;
    for (int i=0; i<=M/2; ++i) {
        ptrdiff_t upper=num_element(X.begin(), X.end(), M-i, 0, 200000);
        ptrdiff_t lower=num_element(X.begin(), X.end(), i, 0, 200000);

        if (i == M-i || i == 0) {
            res += lower/2;
            continue;
        }

        ptrdiff_t pairs=min(upper, lower), remain=abs(upper-lower);

        if (remain < 2) {
            res += pairs;
            continue;
        }

        int k=(lower<upper? M-i:i);
        int ub=maxrem[k];
        ptrdiff_t cur=0;
        for (int j=0; j<=ub&&cur<=lower+upper; ++j)
            cur += num_element(X.begin(), X.end(), k, j, j)/2;

        res += min(cur+pairs, (upper+lower)/2);
    }

    printf("%zu\n", res);
    return 0;
}

int main() {
    bool solved=false;
    while (!testcase_ends())
        solved |= 1;

    return !solved;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define per(i,a,n) for(int i=a;i<=n;i++)
using namespace std;
typedef long long ll;
typedef vector<ll>vec;
typedef vector<vector<ll>> mat;
set<int>s;
int a[5];
//vector<int>a[5];
int main()
{
  ll n,a,b;
  cin>>n>>a>>b;
  if(a==0) {cout<<0;return 0;}
  ll k=n%(a+b);
  ll kk=n/(a+b);
  ll ans=a*kk;
  if(k<=a) ans+=k;
  else ans+=a;
  cout<<ans;
  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
double pi=acos(-1);
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
// #define mp make_pair
#define pq priority_queue
const ll mod=1000000007;
#define f first
#define s second
#define pii pair< ll, ll >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace boost::multiprecision;
using namespace std;
void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}


const int N=1000005;
ll fact[N],invfact[N];
ll power(ll x,ll y){
  if(y<=0) return 1LL;
  ll z=power(x,y/2);
  if(y%2) return (((z*z)%mod)*x)%mod;
  return (z*z)%mod;
}

void pre(){
  fact[0]=invfact[0]=invfact[1]=fact[1]=1;
  rep(i,2,N) fact[i]=(i*fact[i-1])%mod;
  rep(i,2,N) invfact[i]=(invfact[i-1]*power(i,mod-2))%mod;
}
ll nCr(ll n,ll k){ return (((fact[n]*invfact[n-k])%mod)*invfact[k])%mod; }



const int N1=1e6+1;
vector<int> isprime(N1,1),prime;
void seive(){
  rep(i,2,sqrt(N1)+1){
      if(isprime[i]){
        for(int j=i*i;j<N1;j+=i) isprime[j]=0;
        prime.pb(i);
      }
  }
  rep(i,sqrt(N1)+1,N1) if(isprime[i]) prime.pb(i);
}



struct dsu {
    vector<int> par, rank;
    dsu(int n): par(n+1), rank(n+1) {
        for (int i = 0; i <= n; i++) {
            par[i] = i;
            rank[i]= 1;
        }
    }
    int root(int a) {
        if (a == par[a]) return a;
        return par[a] = root(par[a]);
    }
    void merge(int a, int b) {
        a = root(a);
        b = root(b);
        if (a == b) return;
        if (rank[a] > rank[b]) swap(a, b);
        par[b] = a;
    }
    set<int> parent(int n){
        set<int> s;
        for(int i=1;i<=n;i++){
            s.insert(root(i));
        }
        return s;
    }
};

void solve(){

  ull n,x,m;
  cin>>n>>x>>m;
  ull z=x,last=x;
  map<ull,ull> m1;
  vector<ull> v1;
  v1.push_back(last);
  m1[last]=0;
  int idx=-1,idx2=-1;
  rep(i,1,n){
    last=(last*last)%m;
    z=z+last;
    if(last==0) break;
    if( m1.find(last)!=m1.end()){
      idx=m1[last];
      idx2=i;
      break;
    }
    else{
      m1[last]=i;
      v1.push_back(last);
    }
  }
  if(idx2!=-1 ){
    ull cycle_sum=accumulate(v1.begin()+idx,v1.end(),0LL);
    ull ans=accumulate(v1.begin(),v1.end(),0LL);
    ull len=v1.size()-idx;
    ull l=n-idx2;
    ull num=l/len,num2=l%len;
    ans=ans+cycle_sum*num+accumulate(v1.begin()+idx,v1.begin()+idx+num2,0LL);
    cout<<ans<<endl;
  }
  else cout<<z<<endl;
}

int main(){
    optimizeIO();
    int r=1;
    // pre();
    {solve();}
}


Measured memory_bytes: 10532
#include<iostream>
#include<algorithm>
using namespace std;
int N;
long A[88];
main()
{
	cin>>N;
	for(int i=0;i<N;i++)cin>>A[i];
	long now=1000;
	for(int i=0;i<N-1;i++)
	{
		long X=now,Y=now%A[i]+now/A[i]*A[i+1];
		now=X<Y?Y:X;
	}
	cout<<now<<endl;
}


Measured memory_bytes: 3608
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <iterator>
#include <stack>
#include <string.h>
#include <cstdlib>
#include <queue>
#include <list>
#include <string>

using namespace std;

int main()
{
    int N;
    cin >> N;
    
    int p = 1000;
    
    while (p < N){
        p += 1000;
    }
    
    cout << p - N << endl;
}


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

#define LLINF (1LL<<60)
typedef long long ll;

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

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

template<typename T> inline T divrup(T a, T b) { if (a % b) return a/b+1; else return a/b;}

#define dbg_v1(i,V) do{cout<<"-v1----\n";rep(i,V.size())cout<<" "<<i<<"\t:"<<V[i]<<endl;cout<<endl;}while(0)
#define dbg_v2(i,k,V) do{cout<<"-v2----\n";rep(i,V.size()){rep(k,V[0].size())cout<<" "<<V[i][k];cout<<endl;}}while(0)

//C++14 (GCC 5.4.1)
int main() {
    int N;
    cin >>N;

    vector<int> V(N);
    rep(i,N) cin >> V[i];
    vector<int> CG(100001,0),CK(100001,0);
    
    //-----------------------------------
    bool is=false;
    int ans=0;
    rep(i,N/2){
        CG[V[i*2]]++;
        CK[V[i*2+1]]++;
    }
    int MaxKi=0,MaxGi=0;
    int MaxKSi=0,MaxGSi=0;
    repd(i,1,100001){
        if(CK[MaxKSi]<CK[i]){
            MaxKSi=i;
            if(CK[MaxKi]<CK[i]){
                MaxKSi=MaxKi;
                MaxKi=i;
            }
        }
        if(CG[MaxGSi]<CG[i]){
            MaxGSi=i;
            if(CG[MaxGi]<CG[i]){
                MaxGSi=MaxGi;
                MaxGi=i;
            }
        }
    }
    if(MaxGi==MaxKi){
        ans=N-CG[MaxGSi]-CK[MaxKi];
        chmin(ans,N-CG[MaxGi]-CK[MaxKSi]);
    }else{
        ans=N-CG[MaxGi]-CK[MaxKi];
    }
    cout << ans <<endl;
    return (0);
}


Measured memory_bytes: 1408
X,N = map(int,input().split())
if N==0:
  print(X)
else:
  p = list(map(int,input().split()))
  if X in p:
    p.remove(X)
    ans = 0
    for i in range(1,100):
      a = X+i
      b = X-i
      if b in p:
        p.remove(b)
      else:
        ans = b
        break

      if a in p:
        p.remove(a)
      else:
        ans = a
        break

    print(ans)
  else:
    print(X)

Measured memory_bytes: 61700
n = int(input())
a = list(map(int, input().split()))

dp = [[0] * (n+1) for _ in range(n+1)]

for l in range(1, n+1):
    for i in range(n - l + 1):
        j = i + l
        if (n - l) % 2 == 0:
            dp[i][j] = max(dp[i+1][j] + a[i], dp[i][j-1] + a[j-1])
        else:
            dp[i][j] = min(dp[i+1][j] - a[i], dp[i][j-1] - a[j-1])

print(dp[0][n])


Measured memory_bytes: 113244
_,a,b=gets.chomp.split(" ").map(&:to_i)
s=gets.chomp

is_passed=[]
passed=0
passed_b=0

s.chars.each do |c|
  if passed >= a+b or c == 'c'
    is_passed << false
    next
  end
  case c
  when 'a'
    is_passed << true
    passed += 1
  when 'b'
    if passed_b < b
      is_passed << true
      passed += 1
      passed_b += 1
    else
      is_passed << false
    end
  end
end

is_passed.each do |r|
  puts r ? "Yes" : "No"
end



Measured memory_bytes: 10748
A,B,C=map(int,input().split())
#t=100//A
#if 100%A==0:
#  t+=1
#d=[A*(i+1) for i in range(t)]
#M=sum(d)
j=0
while j<=10000000:
  if j%B==C:
    print("YES")
    break
  j+=A
else:
  print("NO")

Measured memory_bytes: 9052
#include<stdio.h>
int main(){
  int N;
  scanf("%d",&N);
  int a[N];
  for(int i = 0;i < N;i++){
    scanf("%d",&a[i]);
  }
  int max = -100,min = 100;
  for(int i = 0;i < N;i++){
    if(a[i] > max){
      max = a[i];
    }
    if(a[i] < min){
      min = a[i];
    }
  }
  int Min = 10000000;
  for(int i = min;i < max;i++){
    int sum = 0;
    for(int j = 0;j < N;j++){
      sum += (i - a[j]) * (i - a[j]);
    }
    if(Min > sum){
      Min = sum;
    }
  }
  if(max == min){
    printf("0");
  }else{
    printf("%d",Min);
  }
  return 0;
}

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

int top, S[1000];

void push(int x){
	S[++top] = x;
}

int pop(){
	top--;
	return S[top+1];
}

int main()
{
	int a, b;
	top = 0;
	char s[100];
	while(scanf("%s", s) != EOF){
		if( s[0] == '+'){
			a = pop();
			b = pop();
			push(a + b);
		} else if( s[0] == '-'){
			b = pop();
			a = pop();
			push(a - b);
		} else if( s[0] == '*'){
			a = pop();
			b = pop();
			push(a * b);
		} else{
			push(atoi(s));
		}
	}

	printf("%d\n", pop());

	return 0;
}


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

int main(){

  string s,t;
  cin >> s >> t;
  bool c  = true;

  for (int i = 0; i < t.size()-1; i++) {
    if (s[i] != t[i]) {
      c = false;
      break;
    }
  }

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




}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define PB push_back
#define MP make pair
#define FI first
#define SE second
using namespace std;
static const int INF = 1ll<<60;

int N,K;
int W,H,D;
int X1[55],Y1[55],Z1[55],X2[55],Y2[55],Z2[55];
int cx1[55],cy1[55],cz1[55],cx2[55],cy2[55],cz2[55];
vector<long long int> X,Y,Z;
char fld[51*6][51*6][51*6];

long long int ans;
vector<int> xs;

void compress(vector<long long int> &X,int* x1,int* x2,int* vx1,int* vx2,int w,int* P){
    xs.clear();
    for(int i=0;i<N;++i){
        x1[i]=vx1[i];
        x2[i]=vx2[i];
    }
    for(int i=0;i<N;++i){
        for(int d=-1;d<=1;++d){
            int tx1=x1[i]+d;
            int tx2=x2[i]+d;
            if(0<=tx1&&tx1<=w)xs.PB(tx1);
            if(0<=tx2&&tx2<=w)xs.PB(tx2);
        }
    }
    sort(xs.begin(),xs.end());
    xs.erase(unique(xs.begin(),xs.end()),xs.end());
    for(int i=0;i<N;++i){
        x1[i]=find(xs.begin(),xs.end(),x1[i])-xs.begin();
        x2[i]=find(xs.begin(),xs.end(),x2[i])-xs.begin();
    }
    //for(int i=0;i<xs.size();++i)cout<<xs[i]<<endl;
    for(int i=0;i<xs.size();++i){
        X.PB(xs[i+1]-xs[i]);
    }
    *P = xs.size();
}

int main(){
    cin>>N>>K;
    for(int i=0;i<N;++i)cin>>X1[i]>>Y1[i]>>Z1[i]>>X2[i]>>Y2[i]>>Z2[i];
    compress(X,cx1,cx2,X1,X2,1000000,&W);
    compress(Y,cy1,cy2,Y1,Y2,1000000,&H);
    compress(Z,cz1,cz2,Z1,Z2,1000000,&D);
    for(int i=0;i<N;++i){
        for(int z=cz1[i];z<cz2[i];++z){
            for(int y=cy1[i];y<cy2[i];++y){
                for(int x=cx1[i];x<cx2[i];++x){
                    fld[z][y][x]++;
                }
            }
        }
    }
    for(int z=0;z<=D;++z){
        for(int y=0;y<=H;++y){
            for(int x=0;x<=W;++x){
                if(fld[z][y][x]>=K)ans+=X[x]*Y[y]*Z[z];
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 27992
#include<iostream>
//#include<bits/stdc++.h>
#include<cstring>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<cmath>
#include<cstdio>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
using namespace std;
typedef long long ll;
//ll a,b,c,x,y;

ll ex_gcd(ll a,ll b,ll& x,ll& y)
{
    if(b==0)
    {
        x=1;
        y=0;
        return a;
    }
    ll ans = ex_gcd(b,a%b,x,y);
    ll tmp = x;
    x = y;
    y = tmp-a/b*y;
    return ans;
}
int n;
ll N[105];
int main()
{
    scanf("%d",&n);
    ll sum=0;
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&N[i]);
        sum+=N[i];
    }
    double x;
    x=(double)sum/(double)n;
    ll id=(ll)(x+0.5);
    sum=0;
    for(int i=1;i<=n;i++)
    {
        sum+=(N[i]-id)*(N[i]-id);
    }
    printf("%lld\n",sum);
    return 0;
}




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

int main()
{
    string s;
    cin >> s;
    int ans = -1;
    vector<int> a, z;

    for (int i = 0; i < s.length(); i++)
    {
        if (s[i] == 'A')
        {
            a.push_back(i);
        }
        if (s[i] == 'Z')
        {
            z.push_back(i);
        }
    }

    ans = z.back() - a.front() + 1;
    cout << ans << endl;
}

Measured memory_bytes: 1364
#include<bits/stdc++.h>
const int inf=0x3f3f3f3f;
using namespace std;
struct card{
    int a,b;
}pok[20];
struct card2{
    int x,pos;
    card2(int x,int pos):x(x),pos(pos){}
};
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;++i){
        cin>>pok[i].a;
    }
    for(int i=1;i<=n;++i){
        cin>>pok[i].b;
    }
    int ans=0;
    vector<int>v;
    vector<card2>c;
    bool flag;
    int mi=inf;
    for(int i=0;i<1<<n;++i){
        int ans=0;
        c.clear();
        v.clear();
        //cout<<i<<endl;
        for(int j=0;j<n;++j){
            if(i>>j&1){
                v.emplace_back(pok[j+1].b);
                c.emplace_back(card2(pok[j+1].b,1));
            }
            else{
                v.emplace_back(pok[j+1].a);
                c.emplace_back(card2(pok[j+1].a,0));
            }
        }
        sort(v.begin(),v.end());
        for(int j=0;j<n;++j){
            flag=true;
            //cout<<"v[j]=="<<v[j]<<endl;
            for(int k=j;k<n;++k){
                //cout<<"c[k].x=="<<c[k].x<<endl;
                if(c[k].x==v[j]&&((k-j)&1)==c[k].pos){
                    flag=false;
                    ans+=k-j;
                    for(int l=k-1;l>=j;--l){
                        c[l].pos^=1;
                        swap(c[l],c[l+1]);
                    }
                    break;
                }
            }
            if(flag)break;
        }
        if(flag)continue;
        else mi=min(ans,mi);
    }
    cout<<(mi==inf?(-1):mi)<<endl;
}



Measured memory_bytes: 256
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn calc_digit_sum(mut a: usize) -> usize {
    let mut ans = 0;
    while a > 0 {
        ans += a % 10;
        a /= 10;
    }
    ans
}

fn main() {
    let n: usize = read();
    let mut ans = (1..n)
        .map(|i| calc_digit_sum(i) + calc_digit_sum(n - i))
        .min()
        .unwrap();
    println!("{}", ans);
}


Measured memory_bytes: 4352
N = int(input())
A = list(map(int,input().split()))
Nc = 1
e = 0
B = [0]*N
for i in A:
    if (N-i-1) < 0:
        e = 1
        Nc = 0
        break
if e ==0:
    if A.count(0) >= 2:
        Nc *= 0
    else:
        if A.count(0) == 1:
            A.remove(0)
        for i in A:
            B[i] = B[i] + 1
        for i in B:
            if i == 2:
                Nc *= 2
            elif i == 0:
                Nc *= 1
            else:
                Nc *= 0
                break
print(Nc%1000000007)

Measured memory_bytes: 14136
#include <stdio.h>
int main(void){
    int n,i,a,p[100001]={0};
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a);
        p[a]=1;
    }
    a=0;
    for(i=0;i<100001;i++){
        a+=p[i];
    }
    if(a%2==0)a-=1;
    printf("%d\n",a);
    return 0;
}

Measured memory_bytes: 512
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())


int n, a[300000];

long long mi[300000];
long long ma[300000];

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

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


	priority_queue<int, vector<int>, greater<int>> pq1;
	priority_queue<int> pq2;

	long long sum=0;
	for (int i=0;i<n;i++){
		sum += a[i];
		pq1.push(a[i]);
	}
	ma[n-1] = sum;
	for (int i=n;i<2*n;i++){
		if (pq1.top() < a[i]){
			sum += a[i] - pq1.top();
			pq1.pop();
			pq1.push(a[i]);
		}
		ma[i] = sum;
	}


	sum = 0;
	for (int i = 3*n-1; i>=2*n; i--){
		sum += a[i];
		pq2.push(a[i]);
	}
	mi[2*n] = sum;
	for (int i = 2*n-1; i>=n; i--){
		if (pq2.top() > a[i]){
			sum += a[i] - pq2.top();
			pq2.pop();
			pq2.push(a[i]);
		}
		mi[i] = sum;
	}
	long long ans = ma[n - 1] - mi[n];
	for (int i=n;i<=2*n;i++){
		ans = max(ans, ma[i-1] - mi[i]);
	}
	cout<<ans<<endl;


	return 0;
}

Measured memory_bytes: 5240
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix

N, M, L = [int(_) for _ in readline().split()]
ABCQST = np.array(read().split(), dtype=np.int64)
ABC = ABCQST[:3 * M]
ST = ABCQST[3 * M + 1:]
A, B, C = ABC[::3], ABC[1::3], ABC[2::3]
S, T = ST[::2], ST[1::2]
G = csr_matrix((C, (A, B)), shape=(N + 1, N + 1))
G2 = floyd_warshall(G, directed=0)
G3 = np.full((N + 1, N + 1), np.inf)
np.fill_diagonal(G3, 0)
G3[G2 <= L] = 1
G4 = floyd_warshall(G3, directed=0)
G4[G4 == np.inf] = 0
print(*(G4[S, T] - 1).astype(np.int64), sep='\n')


Measured memory_bytes: 32564
N, M = input().split()
A = input().split()

N = int(N)
M = int(M)

a_s = sorted(A, reverse=True)
a_i = [int(x) for x in a_s ]
total = sum(a_i)
m_4 = total / (4 * M)

count = 0
for i in a_i:
  if i >= m_4:
    count += 1
  
if M <= count:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define forn(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define ford(i, a, n) for (int i = (int)(n) - 1; i >= (int)(a); --i)
#define fore(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define fs first
#define sn second
#define trace(a)\
    for (auto i : a) cerr << i << ' ';\
    cerr << '\n'
#define eb emplace_back

#ifndef M_PI
const ld M_PI = acos(-1.0);
#endif

template<typename T>
inline void setmax(T& a, T b) {
    if (a < b) a = b;
}

template<typename T>
inline void setmin(T& a, T b) {
    if (a > b) a = b;
}

template<typename T, typename S>
istream& operator>> (istream& in, pair<S, T>& p) {
    in >> p.fs >> p.sn;
    return in;
}
template<typename T, typename S>
ostream& operator<< (ostream& out, pair<S, T>& p) {
    out << p.fs << ' ' << p.sn << ' ';
    return out;
}

template<typename T>
istream& operator>> (istream& in, vector<T>& v) {
    for (T& x : v) in >> x;
    return in;
}
template<typename T>
ostream& operator<< (ostream& out, vector<T>& v) {
    for (T& x : v) out << x << ' ';
    return out;
}

const ld eps = 1e-9;
const int INF = 2000000000;
const ll LINF = 1ll * INF * INF;
const ll MOD = 1000000007;

const int N = 2018;
int w[N][2 * N], b[N][2 * N];
int posw[N], posb[N];
int dp[N][N];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); 
    srand((unsigned)chrono::high_resolution_clock::now().time_since_epoch().count());
    int n;
    cin >> n;
    forn(i, 0, 2 * n) {
        char c;
        int val;
        cin >> c >> val;
        (c == 'B' ? posb : posw)[--val] = i;
    }
    forn(i, 0, n) {
        if (i) {
            forn(j, 0, 2 * n) w[i][j] = w[i - 1][j];
            forn(j, 0, 2 * n) b[i][j] = b[i - 1][j];
        }
        forn(j, posw[i], 2 * n) ++w[i][j];
        forn(j, posb[i], 2 * n) ++b[i][j];
    }
    fore(i, 0, n)
        fore(j, 0, n) {
            if (i == 0 && j == 0) continue;
            dp[i][j] = INF;
            if (i) {
                --i, --j;
                int lftI = posw[i] - (i ? w[i - 1][posw[i]] : 0) - (j == -1 ? 0 : b[j][posw[i]]);
                ++i, ++j;
                setmin(dp[i][j], dp[i - 1][j] + lftI);
            }
            if (j) {
                --i, --j;
                int lftJ = posb[j] - (j ? b[j - 1][posb[j]] : 0) - (i == -1 ? 0 : w[i][posb[j]]);
                ++i, ++j;
                setmin(dp[i][j], dp[i][j - 1] + lftJ);
            }
        }
    //fore(i, 0, n) {
    //    fore(j, 0, n) cerr << dp[i][j] << ' ';
    //    cerr << '\n';
    //}
    cout << dp[n][n] << '\n';
}


Measured memory_bytes: 79488
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int X; cin >> X;
  if(X >= 400 && X <= 599){
    cout << 8 << endl;
  }else if(X >= 600 && X <= 799){
    cout << 7 << endl;
  }else if(X >= 800 && X <= 999){
    cout << 6 << endl;
  }else if(X >= 1000 && X <= 1199){
    cout << 5 << endl;
  }else if(X >= 1200 && X <= 1399){
    cout << 4 << endl;
  }else if(X >= 1400 && X <= 1599){
    cout << 3 << endl;
  }else if(X >= 1600 && X <= 1799){
    cout << 2 << endl;
  }else if(X >= 1800 && X <= 1999){
    cout << 1 << endl;
  }
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef pair<ll,P>  PP;
typedef vector<ll> Vector;
typedef vector<Vector> DVector;
typedef priority_queue<PP, vector<PP>, greater<PP>> PPQueue;

#define fi          first
#define se          second
#define sfi         se.fi
#define sse         se.se
#define pb          push_back
#define INF         INT_MAX
#define MOD         1000000007
#define bcnt        __builtin_popcount
#define all(x)      (x).begin(),(x).end()
#define uni(x)      x.erase(unique(all(x)),x.end())
#define ub(x,y)     (upper_bound(all(x),y)-x.begin())
#define lb(x,y)     (lower_bound(all(x),y)-x.begin())
#define rep(i,n)    repl(i,0,n-1)
#define usort(x)    sort(all(x))
#define dsort(x)    sort(all(x),greater<ll>())
#define mkp(x,y)    make_pair(x,y)
#define mmax(x,y)   (x>y?x:y)
#define mmin(x,y)   (x<y?x:y)
#define maxch(x,y)  x=mmax(x,y)
#define minch(x,y)  x=mmin(x,y)
#define exist(x,y)  (find(all(x),y)!=x.end())
#define each(itr,v) for(auto itr:v)
#define repl(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);i++)

int main(void){
  cin.sync_with_stdio(false);
  ll H, W, N;
  cin >> H >> W >> N;
  Vector a(N), b(N);
  rep(i,N) cin >> a[i] >> b[i];
  Vector ans(10);
  map<P,ll> ma;
  rep(i,N){
    ll x;
    ll y;
    rep(k,9) {
      x = a[i] + k % 3 - 1;
      y = b[i] + k / 3 - 1;
      if(x < 2 || x > H - 1 || y < 2 || y > W - 1)continue;
      else ma[mkp(x,y)]++;
    }

  }
  ans[0] = (H-2) * (W-2);
  rep(i,N){
    ll x;
    ll y;
    rep(k,9){
      x = a[i] + k % 3 - 1;
      y = b[i] + k / 3 - 1;
      if(x < 2 || x > H - 1 || y < 2 || y > W - 1)continue;
      else if(ma[mkp(x,y)] != 0)ans[ma[mkp(x, y)]]++;
    }
  }
  rep(i,9)ans[0] -= ans[i+1]/(i+1);
  rep(i,10) cout << ans[i]/(mmax(1,i)) << endl;
}


Measured memory_bytes: 58112
function Koch(n,p1x,p1y,p2x,p2y){
    if(n <= 0)
        return ;

    var sx = (p1x * 2 + p2x) / 3,sy = (p1y * 2 + p2y) / 3;
    Koch(n - 1,p1x,p1y,sx,sy);
    console.log(sx + " " + sy);
    var tx = (p1x + p2x * 2) / 3,ty = (p1y + p2y * 2) / 3;
    var ux = 0.5 * (tx + sx) - Math.sqrt(3) * 0.5 * (ty - sy),uy = Math.sqrt(3) * 0.5 * (tx - sx) + 0.5 * (ty + sy);
    Koch(n - 1,sx,sy,ux,uy);
    console.log(ux + " " + uy);
    Koch(n - 1,ux,uy,tx,ty);
    console.log(tx + " " + ty);
    Koch(n - 1,tx,ty,p2x,p2y);

}

function Main(input){
    var n = parseInt(input,10);

    console.log("0.00000000 0.00000000\n");
    Koch(n,0.0,0.0,100.0,0.0);
    console.log("100.00000000 0.00000000");
    return 0;
}

Main(require("fs").readFileSync("/dev/stdin","utf8"));

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

using namespace std;

int main()
{
    int i, j;
    int n, r;
    int ans;

    cin >> n >> r;
    if (n < 10) {
        ans = r + (100 * (10 - n));
    } else {
        ans = r;
    }

    cout << ans << endl;

    return 0;
}


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

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

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

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		while (scan.hasNext()) {
			int n = Integer.parseInt(scan.nextLine());
			int[] arr = new int[n];
			for (int i = 0; i < n; i++) {
				arr[i] = scan.nextInt();
			}
			int[] arr2 = new int[n];
			for (int i = 0; i < n; i++) {
				arr2[arr[i] - 1] = i + 1;
			}
			for (int i = 0; i < n; i++)
				System.out.print(arr2[i] + " ");
		}
	}
}


Measured memory_bytes: 61436
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define EPS      (double)1e-9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cerr<<' ';cerr<<elem;}cerr<<endl;}

int main(){
	int n;
	llong d;
	cin>>n>>d;
	d=d*d;
	
	int ans=0;
	REP(i,n){
		llong x,y;
		cin>>x>>y;
		
		if(x*x+y*y<=d) ans++;
	}
	
	cout<<ans<<endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define gpf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
typedef long long ll;

int n, d1, x;

long double calc(int len, long double a1, long double d){
	if (len == 0) return 0;
	long double res = (a1 + d * len - d * 0.5);
	long double ta1, td;
	ta1 = (a1 * (2 * len + 2) - d * len * 2 + d + (2 * len + 4) * d) / ((long double)len * 2);
	td = d * (len * 2 + 4) / ((long double)len * 2);
	res = res + calc(len - 1, ta1, td);
	return res;
}

int main(){
	scanf("%d%d%d", &n, &d1, &x);
	printf("%.10LF\n", calc(n, (long double)d1, (long double)x));
	return 0;
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
typedef vector<int>   vi;
typedef vector<long long> vll;
typedef vector<pair<int,int> > vii;
#define ll long long
#define pb push_back
#define mp  make_pair
#define ff first
#define ss second
#define pq priority_queue
#define sf(x) scanf("%d",&x)
int inf = (1e9) + 7;



int n,m;
vi graph[200005];
int visited[200005];
void dfs(int start, int rem)
{
	if(start == n-1){
		printf("POSSIBLE\n");
		exit(0);
	}
	if(rem == 0)
		return;
	for(auto u: graph[start])
	{
		if(!visited[u])
			dfs(u,rem-1);
	}
	visited[start] = 1;
}


int main(){
	cin >> n >> m;

	int a,b;
	for (int i = 0; i < m; ++i)
	{
		sf(a);
		sf(b);
		a--;
		b--;
		graph[a].pb(b);
		graph[b].pb(a);
	}

	memset(visited,0,sizeof(visited));
	dfs(0,2);
	printf("IMPOSSIBLE\n");
}


Measured memory_bytes: 12784
#include <iostream>
#include <vector>
using namespace std;
typedef vector<int> vi;
const int size=4000;
vi graph[size];
int lineDistances[size][size];
bool visited[size][size];
vi vertexA, vertexB;
int number, diameter;
void dfs(int root, int start, int distanceInLines)
{
	//commandsBeforeVisitRecursion.
	visited[root][start]=true;
	lineDistances[root][start]=distanceInLines;
	for(int next : graph[start])
	{
		if(!visited[root][next])
		{
			dfs(root, next, distanceInLines+1);
		}
	}
	//commandsAfterVisitRecursion.
}
void usingDFS()
{
	cin>>number>>diameter;
	int vertex0, vertex1;
	for(int i=1; i<number; ++i)
	{
		cin>>vertex0>>vertex1;
		graph[vertex0].push_back(vertex1);
		graph[vertex1].push_back(vertex0);
		vertexA.push_back(vertex0);
		vertexB.push_back(vertex1);
	}
	for(int vertex=1; vertex<=number; ++vertex)
	{
		dfs(vertex, vertex, 0);
	}
	if(diameter%2==0)
	{
		int minimum=4000;
		for(int i=1; i<=number; ++i)
		{
			int counter=0;
			for(int j=1; j<=number; ++j)
			{
				if(lineDistances[i][j]>diameter/2)
				{
					++counter;
				}
			}
			minimum=min(minimum, counter);
		}
		cout<<minimum<<endl;
	}
	else
	{
		int dotA, dotB, tempMaxDist, minimum=4000;
		for(int i=0; i<vertexA.size(); ++i)
		{
			int counter=0;
			dotA=vertexA[i];
			dotB=vertexB[i];
			for(int j=1; j<=number; ++j)
			{
				tempMaxDist=min(lineDistances[j][dotA], lineDistances[j][dotB]);
				if(tempMaxDist>diameter/2)
				{
					++counter;
				}
			}
			minimum=min(minimum, counter);
		}
		cout<<minimum<<endl;
	}
}
int main()
{
    usingDFS();
	return 0;
}

Measured memory_bytes: 42880
import kotlin.*


fun main(args: Array<String>) {
    Program().solve()
}

class Program {
    fun solve() {
        val sc = MyScanner()
        val n = sc.nextInt()
        val k = sc.nextInt()
        val p = sc.intList().sorted()
        var sum = 0
        for(i in 0 until k) sum += p[i]
        
        print(sum)
    }
}

class MyScanner {
    private var ptr = 0
    private var l = listOf<String>()

    fun next(): String {
        while (l.size <= ptr) {
            l = readLine()!!.split(' ')
            ptr = 0
        }
        return l[ptr++]
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextDouble() = next().toDouble()
    fun nextCharArray() = next().toCharArray()
    fun nextChar() = next()[0]

    fun list(): List<String> {
        ptr = l.size
        return readLine()!!.split(' ')
    }

    fun intList() = list().map { s -> s.toInt() }
    fun longList() = list().map { s -> s.toLong() }
    fun doubleList() = list().map { s -> s.toDouble() }

    fun array() = list().toTypedArray()
    fun intArray() = intList().toIntArray()
    fun longArray() = longList().toLongArray()
    fun doubleArray() = doubleList().toDoubleArray()
}


Measured memory_bytes: 40516
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, ans;
  cin >> N;
  bool result = false;
  
  for (int i = 0; i < N; i++){
    char C;
    cin >> C;
    if (C =='Y') result = true;
  }
  
  if (result) cout << "Four" << endl;
  else cout << "Three" << endl;
}


Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math;

void main()
{
    auto N = readln.chomp.to!int;
    auto as = readln.split.to!(int[]);

    size_t max_p, min_p;
    int max_a = int.min, min_a = int.max;
    foreach (i, a; as) {
        if (a > max_a) {
            max_a = a;
            max_p = i;
        }
        if (a < min_a) {
            min_a = a;
            min_p = i;
        }
    }

    writeln(N * 2 - 1);

    if (abs(max_a) > abs(min_a)) {
        foreach (i; 0..N) writefln("%s %s", max_p+1, i+1);
        foreach (i; 0..N-1) writefln("%s %s", i+1, i+2);
    } else {
        foreach (i; 0..N) writefln("%s %s", min_p+1, i+1);
        foreach_reverse (i; 1..N) writefln("%s %s", i+1, i);
    }
}

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

using namespace std;

typedef long long ll;

int n;
const int N = 1e5 + 10;
int inf = 1e9;
int c[N];
int dp[N];

int solve(int idx)
{
	if(idx == n - 1)
		return 0;
	int &ans = dp[idx];
	if(ans != -1)
		return ans;
	int c1 = inf, c2 = inf;
	if(idx + 1 < n)
		c1 = solve(idx + 1) + abs(c[idx + 1] - c[idx]);
	if(idx + 2 < n)
		c2 = solve(idx + 2) + abs(c[idx + 2] - c[idx]);
	return ans = min(c1, c2);
}
int main()
{
	cin >> n;
	for(int i = 0; i< n; i++)
		cin >> c[i];
	memset(dp, -1, sizeof(dp));
	cout << solve(0);
	return 0;
}

Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
const double pi = acos(-1);
const double eps = 1e-10;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
double a[MAXN];
int main() {
	int n, l; read(n), read(l);
	for (int i = 1; i <= n; i++)
		read(a[i]);
	double ansx = 0, ansy = 0;
	for (int i = 1; i <= n; i++)
	for (int j = i + 1; j <= n; j++) {
		ansx += cos(pi * (a[i] + a[j]) / l) * (n - (j - i + 1));
		ansy += sin(pi * (a[i] + a[j]) / l) * (n - (j - i + 1));
		ansx += cos(pi * (a[i] + a[j] + l) / l) * (j - i - 1);
		ansy += sin(pi * (a[i] + a[j] + l) / l) * (j - i - 1);
	}
	double cnt = 1.0 * n * (n - 1) * (n - 2) / 6;
	printf("%.10lf %.10lf\n", ansx / cnt, ansy / cnt);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define fort(i,n) for (int i = 1; i <= n; ++i)
#define pi pair<int,int>
#define vi vector<int>
#define pb push_back
#define sz size()
#define er erase
#define fr first
#define sc second
#define rc(x) return cout << x, 0
using namespace std;

int n;
string s;

int32_t main()
{
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin >> s;
    fort (i,4)
        if (s[i-1]=='2') ++n;
    cout << n;
}

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

using namespace std;

typedef long long ll;

int main(){
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    cout << x2 + y1 - y2 << " " << y2 + x2 - x1 << " " << x1 + y1 - y2 << " " <<y1 + x2 -x1 << endl; 
    return 0;
}

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

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

  ll N; cin >> N;
  ll W; cin >> W;
  vector<ll> w(N), v(N);
  for (ll i = 0; i < N; i++) {
    cin >> w[i] >> v[i];
  }
  ll MAX = 100005, INF = 1e15;
  vector<ll> dp(MAX, INF), dp2(MAX, INF);
  dp2[0] = 0;
  for (ll i = 0; i < N; i++) {
    for (ll j = 0; j <= MAX; j++) {
      dp[j] = min(dp2[j], w[i]);
      if (j >= v[i]) {
        dp[j] = min(dp2[j], dp2[j - v[i]] + w[i]);
      }
    }
    dp2 = dp;
  }
  for (ll i = MAX - 1; i >= 0; i--) {
    if (dp[i] <= W) {
      cout << i << '\n';
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=2e5+5,MOD=998244353;
int n,ans;
int f[N];
bool vis[N];
int cnt,head[N];
struct edge{int next,to;}e[N<<1];
struct number{int x,d;}num[N];
struct node
{
	int x,id;
	inline bool operator < (const node &now) const
	{
		return now.x<x;
	}
};

inline bool cmp(number a,number b){return a.x<b.x;}

inline void add(int u,int v)
{
	cnt++;
	e[cnt].next=head[u];
	e[cnt].to=v;
	head[u]=cnt;
}

void dfs(int u)
{
	vis[u]=true;
	f[u]=1;
	for (register int i=head[u]; i; i=e[i].next)
	if (!vis[e[i].to])
	{
		dfs(e[i].to);
		f[u]=f[u]*f[e[i].to]%MOD;	
	}
	f[u]=(f[u]+1)%MOD;
}

signed main(){
	scanf("%lld",&n);
	for (register int i=1; i<=n; ++i) scanf("%lld%lld",&num[i].x,&num[i].d);

	sort(num+1,num+n+1,cmp);	
	priority_queue<node>q;
	for (register int i=n; i>=1; --i)
	{
		while (q.size() && num[i].x+num[i].d>q.top().x) 
		{
			add(i,q.top().id),q.pop();
		}
		q.push((node){num[i].x,i});
	}
	ans=1;
	for (register int i=1; i<=n; ++i) 
	if (!vis[i]) 
	{
		dfs(i); 
		ans=ans*f[i]%MOD;	
	}
	printf("%lld\n",ans);
return 0;	
}

Measured memory_bytes: 22272
#include <iostream>
#include <string.h>

using namespace std;

int main(){
	int n;
	cin >> n;
	char* s = (char*)calloc(n+1, sizeof(char));
	cin >> s;
	
	if(n % 2 != 0) {cout << "No" << endl; return 0;}
	
	char* t = (char*)calloc((n/2)+1, sizeof(char));
	for(int i = 0; i < (n/2); i++){
		t[i] = s[i];
	}
	for(int i = (n/2); i < n; i++){
		if(s[i] != t[i-(n/2)]){
			cout << "No" << endl;
			return 0;
		}
	}
	
	cout << "Yes" << endl;
	return 0;
	
}

Measured memory_bytes: 3648
import sys
from collections import deque
s=sys.stdin.readlines()
n,q=map(int,s[0].split())
d=deque(e.split()for e in s[1:])
t=0
while d:
 k,v=d.popleft()
 v=int(v)
 if v>q:
  v-=q
  t+=q
  d.append([k,v])
 else:
  t+=v
  print(k,t)


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

int main() {

    int a, b, c, i;

    cin >> a >> b >> c;

    for(i = 0; i < c; i++) {
        if(b < a * (i + 1)) {
            break;
        }
    }

    cout << i << endl;

    return 0;
}

Measured memory_bytes: 256
k, n = gets.chomp.split(" ").map(&:to_i)
a = gets.chomp.split(" ").map(&:to_i)
b = n.times.map do |i|
  i == 0 ? a[i] + k - a[i - 1] : a[i] - a[i - 1]
end
puts k - b.max

Measured memory_bytes: 18436
#include <stdio.h>
int main(void) {
  int a,b,t;
scanf("%d%d",&a,&b);
if(a<b){
    t=a;
    a=b;
    b=t;
}
for(;;){
if(b==0)break;  
t=a%b;
a=b;
b=t;
}
printf("%d\n",a);
  return 0;
}


Measured memory_bytes: 2100
from  math import gcd
dic = {}
K = int(input())
sum_=0
for a in range(1,K+1):
    for b in range(a,K+1):
        for c in range(b,K+1):
            if a == b and b == c:
                sum_ += gcd(gcd(a, b),c)
            elif a == b or b == c or c == a:
                sum_ += gcd(gcd(a, b),c)*3
            else:
                sum_ += gcd(gcd(a, b),c)*6
print(sum_)

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

string a, b, c;
int n;
int main() {
  cin >> n >> a >> b >> c;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] != b[i] && a[i] != c[i] && b[i] != c[i]) ans += 2;
    else if (a[i] == b[i] && a[i] == c[i] && b[i] == c[i]) ans += 0;
    else ans += 1;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstdint>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <utility>
#include <limits>
#include <list>
#include <type_traits>

/* template start */
 
#define rep(i, a, b) for (long long i = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()

#ifdef LOCAL
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  if(sizeof...(t)>0)std::cout<<" :";
  debug_out(t...);
}
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}

template<typename Num>
constexpr Num mypow(Num a, long long b) {
  if(b==0)return 1;
  if (a==0)return 0;
  Num x = 1;
  while (b > 0) {
    if(b & 1)x*=a;
    a*=a;
    b >>= 1;
  }
  return x;
}

/* template end */

using ll = long long;

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

  ll h,w,k;
  std::cin>>h>>w>>k;

  std::vector<std::string> grid(h);
  for(auto&& e:grid)std::cin>>e;

  ll ans=0;

  rep(hbit,0,1ll<<h){
    rep(wbit,0,1ll<<w){
      ll cnt=0;
      rep(i,0,h){
        rep(j,0,w){
          if((hbit&(1ll<<i))&&(wbit&(1ll<<j))&&grid[i][j]=='#')cnt++;
        }
      }
      if(cnt==k)ans++;
    }
  }

  std::cout<<ans<<"\n";

  return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<double> x(n);
    vector<string> u(n);
    for(int i=0;i<n;i++){
        cin>>x[i]>>u[i];
    }
    double sum=0;
    for(int i=0;i<n;i++){
        if("JPY"==u[i]){
            sum+=x[i];
        }else{
            sum+=380000*x[i];
        }
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <cstring>

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair < int, int >
#define pll pair < long long, long long>
#define ull unsigned long long
#define vi vector < int >
#define vll vector < long long >
#define sz(a) (int)a.size()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++)
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x))
#define fname "searching"

const int inf = (int)1e9;
const ll INF = (ll)1e18;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int mod = (int)1e9 + 7;

int solve(){
    int n;
    cin >> n;
    multiset<int> s;
    for(int i = 0, x; i < n; ++i){
        cin >> x;
        if(s.find(x) == s.end())
            s.insert(x);
        else
            s.erase(x);
    }
    return sz(s);
}

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

    cout << solve() << "\n";
    
    return 0;
}


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

using namespace std;
 
#define ll int
typedef unsigned long long ull;
typedef long double ld;

#define pii         pair<ll ,ll >
#define vi          vector<ll >
#define vii         vector<pii>
#define mi          map<ll ,ll >
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define pb          push_back
#define hell        1000000007 
#define rep(i,a,b)  for(ll int i=a;i<b;i++)
#define take        rep(i,0,n) cin>>v[i];
#define MAXN        200005


#define allr(c) (c).rbegin(),(c).rend()
int mod = 998244353;
const int inf = 1034567891;
const long long LL_INF = 1234567890123456789ll;
#define PI 3.14159265
#define endl '\n'
#define F first
#define S second
#define debug(x) cout << #x << " = " << x << endl;
#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define out(container) for (auto it : container) cout << it << " "; cout << endl;
 
 
template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > string toString(T a)       { return to_string(a); }
template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}
inline int add(long long x, long long y){ x += y; if(x >= mod) x -= mod; return x;}
inline int sub(ll x, ll y){ x -= y; if(x < 0) x += mod; return x;}
inline int mul(ll x, ll y){ return (x * 1ll * y) % mod;}
inline ll powr(ll a, ll b){
  int x = 1 % mod;
  while(b){
    if(b & 1) x = mul(x, a);
    a = mul(a, a);
    b >>= 1;
  }
  return x;
}
inline long long inv(long long a){ return powr(a, mod - 2);}
ll Powb(ll b,ll n,ll m)
{
    if(n==0) return 1LL;
    if(n==1) return b;
    ll temp = Powb(b,n/2,m);
    if(n%2==0){return (temp*temp)%m;}
    else{return (b*((temp*temp)%m))%m;}
}


void solve()
{
	string s;
	cin>>s;
	ll m=0;
	for(auto x:s)
	{
		m=m+(ll)(x-'0');
		m=m%9;
	}
	if(m>0)
	{
		cout<<"No"<<endl;
		
	}
	else
	{
		cout<<"Yes"<<endl;
	}
	
}
int main()
{
	ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);                                                        
      
    ll t;
        
    t=1;
   
    
  // cin>>t;
    while(t--)
    solve();
}

Measured memory_bytes: 3788
h, w, n  = map(int, input().split())
sr, sc = map(int, input().split())
S = list(str(input()))
T = list(str(input()))

y = sr
for s,t in zip(S, T):
    if s == 'U':
        y -= 1
        if y < 1:
            print('NO')
            exit()
    if t == 'D':
        if y < h:
            y += 1

y = sr
for s, t in zip(S, T):
    if s == 'D':
        y += 1
        if y > h:
            print('NO')
            exit()
    if t == 'U':
        if y > 1:
            y -= 1

x = sc
for s, t in zip(S, T):
    if s == 'R':
        x += 1
        if x > w:
            print('NO')
            exit()
    if t == 'L':
        if x > 1:
            x -= 1

x = sc
for s, t in zip(S, T):
    if s == 'L':
        x -= 1
        if x < 1:
            print('NO')
            exit()
    if t == 'R':
        if x < w:
            x += 1

print('YES')

Measured memory_bytes: 71752