akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstdint>
using namespace std;

#define REP(i,n) for (int i = 0; i < n; i++)
typedef long long ll;

int H,W;
int a[510][510];

int main () {

    cin >> H >> W;
    REP(i,H)REP(j,W) cin >> a[i][j];

    bool flag = false;
    vector < int > ans;
    for (int x = 0; x < H; x++) {
        if (x % 2 == 0) {   
            for (int y = 0; y < W; y++) {
                if (a[x][y] % 2 == 1) {
                    if (flag) {
                        flag = false;
                        ans.push_back(x);
                        ans.push_back(y);
                    } else {
                        flag = true;
                        ans.push_back(x);
                        ans.push_back(y);
                    }
                } else {
                    if (flag) {
                        ans.push_back(x);
                        ans.push_back(y);
                        ans.push_back(x);
                        ans.push_back(y);
                    }
                }
            }
        } else {
            for (int y = W - 1; y >= 0; y--) {
                if (a[x][y] % 2 == 1) {
                    if (flag) {
                        flag = false;
                        ans.push_back(x);
                        ans.push_back(y);
                    } else {
                        flag = true;
                        ans.push_back(x);
                        ans.push_back(y);
                    }
                } else {
                    if (flag) {
                        ans.push_back(x);
                        ans.push_back(y);
                        ans.push_back(x);
                        ans.push_back(y);
                    }
                }
            }
        }
    }

    cout << ans.size() / 4 << endl;
    REP(i,ans.size() / 4) {
        REP(j,4) {
            if (j == 3) cout << ans[i * 4 + j] + 1;
            else cout << ans[i * 4 + j] + 1 << " ";
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 5232
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define all(x) (x).begin (),(x).end()
#define pb push_back
#define mp make_pair
#define vi vector<ll>
#define pii pair<ll,ll>
#define vii vector<pii>
#define mi map<ll,ll>
#define endl "\n"
#define si set<ll>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define M 1000000007LL


void solve()
{
    float n,m;
    cin>>n>>m;

    float t = 4.0*m;
    float sum=0.0; vi a(n);
    rep(i,0,n)
    {
        cin>>a[i];
        sum+= a[i];
    }

    sum/=t;
    rep(i,0,n)
    {
        if(a[i]>=sum) m--;
    }
    if(m>0) cout<<"No";
    else cout<<"Yes";

}

int main()
{
    SPEED;
    ll t = 1;

   // cin>>t;

    while(t--) solve();

   return 0;
}


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

using namespace std;
typedef long long ll;

const int INF = 2e9;

struct Node {
    typedef Node* NP;
    NP l, r;
    int sz, mi;
    Node(int _sz) : l(NULL), r(NULL), sz(_sz) {
        mi = INF;
        if (sz == 1) return;
        l = new Node(sz/2);
        r = new Node(sz-sz/2);
    }
    void set(int k, int v) {
        if (sz == 1) {
            mi = min(mi, v);
            return;
        }
        if (k < sz/2) {
            l->set(k, v);
        } else {
            r->set(k-sz/2, v);
        }
        mi = min(l->mi, r->mi);
    }
    int get(int a, int b) {
        if (b <= 0 || sz <= a) return INF;
        if (a <= 0 && sz <= b) return mi;
        return min(l->get(a, b), r->get(a-sz/2, b-sz/2));
    }
};

const int MN = 233333;
int n, q;
int sum[MN], b[MN];
vector<int> v[MN];

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

    cin >> n;
    for (int i = 0; i < n; i++) cin >> b[i];
    for (int i = 0; i < n; i++) {
        sum[i+1] = sum[i] + 1 - b[i];
    }
    cin >> q;
    for (int i = 0; i < q; i++) {
        int l, r;
        cin >> l >> r; l--;
        v[l].push_back(r);
    }

    Node *t1 = new Node(n+1), *t2 = new Node(n+1);
    for (int i = 0; i <= n; i++) {
        if (i) {
            int c = t1->get(i-1, i) + b[i-1];
            t1->set(i, c);
            t2->set(i, c - sum[i]);
        } else {
            t1->set(0, 0);
            t2->set(0, 0);
        }
        for (int j = 0; j < int(v[i].size()); j++) {
            int r = v[i][j];
            int c = t2->get(i, r) + sum[r];
            t1->set(r, c);
            t2->set(r, c - sum[r]);
        }
    }
    cout << t1->get(n, n+1) << endl;
    return 0;
}

Measured memory_bytes: 36224
#include<bits/stdc++.h>
#define ll long long

using namespace std;
ll MOD = 1000000007;
//(power(a,b) % MOD) Complexity O(Log2(b))
ll bigmod(ll a, ll b) {
    if (b == 0) return 1;
    ll x = bigmod(a, b/2);
    x = (x*x)%MOD;
    if (b % 2 == 1) x *= a;
    return x%MOD;
}
ll n;
ll k;
ll pre[100005];
int main()
{
    ios::sync_with_stdio(0);
    cin >> n >> k;
    ll ans = 0;
    for (int i=k;i>=1;i--)
    {
        int muls = k / i;
        ll add = bigmod(muls , n);
        ll d = 0;
        for (int j=i + i;j<=k;j+=i)
        {
            d += pre[j];
            d %= MOD;
        }
        add -= d;
        add += MOD;
        add %= MOD;
        pre[i] = add;
    }
    for (int i=1;i<=k;i++)
    {
        ans += pre[i] * i;
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;
using ll = long long;
using PII = std::pair<int, int>;
using PLL = std::pair<ll, ll>;

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


const int mod = 1e9 + 7;

ll cal(ll r, ll c, char op)
{
    if (op == '*')
        return r * c;
    if (op == '+')
        return r + c;
    return 0;
}

int main()
{

#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif

    int n, r, i;
    cin >> n >> r;
    if (n >= 10)
        cout << r << endl;
    else
    {
        i = (10 - n) * 100;
        cout << r + i << endl;
    }
    

    return 0;
}


Measured memory_bytes: 256
/*input
2
1
1
2
3
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<atcoder/convolution>
using namespace std;
using namespace __gnu_pbds;
using namespace atcoder;
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
typedef long long int ll;
#define ld double
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
const int maxn=3e5+5;
const ll maxlg=__lg(maxn)+2;
const ll INF64=4e18;
const int INF=0x3f3f3f3f;
const ll MOD=998244353;
const ld PI=3.14159265358979323846;
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define MP make_pair
ll mult(ll a,ll b){
    return ((a%MOD)*(b%MOD))%MOD;
}
ll mypow(ll a,ll b){
    ll res=1LL;
    while(b){
        if(b&1) res=mult(res,a);
        a=mult(a,a);
        b>>=1;
    }
    return res;
}
ll inv(ll x){
    return mypow(x,MOD-2);
}

int arr[maxn];
ll fac[maxn];
ll get(int n){
    return mult(mult(fac[2*n],inv(fac[n])),inv(mypow(2,n)));
}
ll choose(int n,int r){
    return mult(fac[n],inv(mult(fac[n-r],fac[r])));
}
struct CustomCompare
{
    bool operator()(const vector<ll>& lhs, const vector<ll>& rhs)
    {
        return sz(lhs) > sz(rhs);
    }
};
int cnt[maxn];

int main(){
    ios::sync_with_stdio(false),cin.tie(0);
    int n;
    cin>>n;
    fac[0]=1;
    REP1(i,maxn-1){
        fac[i]=mult(i,fac[i-1]);
        //cout<<fac[i]<<'\n';
    }
    REP(i,2*n){
        int x;
        cin>>x;
        cnt[x]++;
    }
    ll ans=get(n);
    vector<ll> a;
    priority_queue<vector<ll>,vector<vector<ll>>,CustomCompare> v;
    a.pb(1);
  v.push(a);
    REP1(i,maxn-1){
        if(cnt[i]<2) continue;
        vector<ll> b;
        b.pb(1);
        REP1(j,cnt[i]/2){
            b.pb(mult(choose(cnt[i],j*2),get(j)));
        }
        v.push(b);
    }
  while(v.size()>1){
    auto x=v.top();
    v.pop();
    auto z=v.top();
    v.pop();
    v.push(convolution(x,z));
  }
   a=v.top();
    REP1(i,sz(a)-1){
        //cout<<a[i]<<'\n';
        if(i%2) ans-=mult(a[i],get(n-i));
        else ans+=mult(a[i],get(n-i));
        ans+=MOD;
        ans%=MOD;
    }   
    cout<<ans;
}


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

int main() {
    int a, b;
    cin >> a >> b;
    string s;
    cin >> s;
    bool h = s[a] == '-';
    s.erase(begin(s) + a);
    bool n = all_of(begin(s), end(s), ::isdigit);
    cout << (h && n ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define endl "\n"
const int MAX= 100005 ;
const long long mod = 1.0e9+7;
bool ispalin(string s,int l,int r)
{
    for(int i=l;i<=r;i++)
    {
        if(s[i]!=s[r-i])
            return false;
    }
    return true;
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int n,m,i,x,y,z;
    string s;
    cin>>s;
    n=s.length();
    bool ans=ispalin(s,0,n-1)&&ispalin(s,0,(n-1)/2-1)&&ispalin(s,(n+1)/2,n-1);
    if(ans)
        cout<<"Yes"<<endl;
    else
    {
        cout<<"No"<<endl;
    }
    
    return 0;
}

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

int main() {
    int a, b;
    cin >> a >> b;
    if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) cout << "Possible" << endl;
    else cout << "Impossible" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
int H,W,i,j;
while(1){
scanf("%d %d",&H,&W);
if(H==0&&W==0)
	break;
	for(i=0;i<H;i++){
		for(j=0;j<W;j++){
			printf("#");
		}
		printf("\n");
	}
	printf("\n");
}
return 0;
}

Measured memory_bytes: 1752
#include <bits/stdc++.h>
using namespace std;  
#define rep(i, a, b) for(ll i = a; i < b; i++)
#define Rep(i, a, b) for(ll i = a; i <= b; i++)
#define repr(i, a, b) for(ll i = b-1; i >= a; i--)
// #define _GLIBCXX_DEBUG
template <class T> using V = vector<T>;
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
const double pi = acos(-1.0);
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
#define pp pair<ll, pair<ll, ll>> 
// #define fi first
// #define se second
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};

/*--------------------------------------------------------------------------------

--------------------------------------------------------------------------------*/

int main(){
    ll n, x, m;
    cin >> n >> x >> m;
    // ループを見つける　鳩ノ巣原理
    V<ll> a;
    set<ll> st;
    a.push_back(x); 
    st.insert(x);
    ll bf_st;
    while(1){
        ll b = *a.rbegin();
        ll c = b*b%m;
        bf_st = sz(st);
        a.push_back(c);
        st.insert(c);
        if(sz(st) == bf_st){ // ループを見つけた
            break;
        }
    }
    //debug
    // rep(i, 0, sz(a)) cout << a[i] << " \n"[i==sz(a)-1];
    //
    ll T = 0; // 周期
    ll bf_roop = 0; // ループに入るまで
    rep(i, 0, sz(a)){
        if(a[i] == *a.rbegin()){
            bf_roop = i;
            T = sz(a)-1 - i;
            break;
        }
    }
    //debug
    // cout << bf_roop << " " << T << endl;
    //
    ll bf_sum = 0; // ループに入るまでの和
    ll roop_sum = 0; // ループの和
    rep(i, 0, bf_roop) bf_sum += a[i];
    rep(i, bf_roop, bf_roop+T) roop_sum += a[i];
    //debug
    // cout << bf_sum << " " << roop_sum << endl;
    //
    ll ans = 0;
    if(n <= bf_roop){
        rep(i, 0, n) ans += a[i];
    }else{
        n -= bf_roop;
        ans += bf_sum;
        ll ro_cnt = n/T, nokori = n%T;
        ans += ro_cnt * roop_sum;
        rep(i, bf_roop, bf_roop+nokori) ans += a[i];
    }
    cout << ans << endl;

    return 0;
}

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

#define int long long
#define rep(i, a, b) for (int i = a; i < b; i++)

signed main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, 0, N) {
        cin >> A[i];
    }

    vector<int> Index(N+1);
    rep(i, 0, N) {
        Index[A[i]] = i;
    }

    set<int> S;
    S.insert(-1); 
    S.insert(N);
    int ans = 0;

    rep(a, 1, N+1) {
        int i = Index[a];
        auto pos = S.lower_bound(i);
        int r = *pos;
        pos--;
        int l = *pos;
        int ci = (i - l) * (r - i);
        ans += ci * a;
        S.insert(i);
    }
    cout << ans << endl;
}

Measured memory_bytes: 12800
n, m = map(int, input().split())
T = [list(map(int, input().split())) for _ in range(n)]
ans = [0] * m

for i in range(n):
    for j in range(1, T[i][0] + 1):
        ans[T[i][j] - 1] = ans[T[i][j] - 1] + 1

print(ans.count(n))

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

int main(){
  char a; cin >> a;
  if(a == 'A') cout << 'T';
  else if(a == 'T') cout << 'A';
  else if(a == 'C') cout << 'G';
  else if(a == 'G') cout << 'C';
}

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


using namespace std;

int n;
int a[4005];
char col[4005];
int cw[2005][2005];
int cb[2005][2005];
int b[2005];
int w[2005];
int counts_b[2005];
int counts_w[2005];
int dp[2005][2005];

int main() {
  cin >> n;
  for (int i = 0; i < 2 * n; i++) {
    cin >> col[i] >> a[i];
    a[i]--;
    if (col[i] == 'W') w[a[i]] = i;
    else b[a[i]] = i;
  }

  for (int i = 0; i < n; i++) {
    int count_b = 0;
    int count_w = 0;
    for (int j = 0; j < i; j++) {
      if (b[i] < b[j]) count_b++;
      if (w[i] < w[j]) count_w++;
    }
    cb[i][0] = count_b;
    cw[i][0] = count_w;
  }

  cb[0][0] = 0;
  cw[0][0] = 0;
  for (int i = 0; i < n; i++) {
    //cb[i][0] = counts_b[i];
    //cw[i][0] = counts_w[i];
    int count_b = cb[i][0];
    int count_w = cw[i][0];
    for (int j = 0; j < n; j++) {
      if (b[i] < w[j]) count_b++;
      if (w[i] < b[j]) count_w++;
      cb[i][j + 1] = count_b;
      cw[i][j + 1] = count_w;
    }
  }

  dp[0][0] = 0;
  for (int i = 1; i <= n; i++) {
    dp[i][0] = dp[i - 1][0] + cb[i - 1][0];
    dp[0][i] = dp[0][i - 1] + cw[i - 1][0];
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      dp[i][j] = min(dp[i - 1][j] + cb[i - 1][j], dp[i][j - 1] + cw[j - 1][i]);
    }
  }
  cout << dp[n][n];
}


Measured memory_bytes: 47360
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int l = sc.nextInt();
		double a = sc.nextDouble();
		double b = sc.nextDouble();
		double c = sc.nextDouble();
		double d = sc.nextDouble();
		a = (int)(Math.ceil(a/c));
		b = (int)(Math.ceil(b/d));
		System.out.println(l - (int)Math.max(a, b));
		sc.close();
	}

}

Measured memory_bytes: 18468
/*
 * short          2^15-1 ~ 3e4
 * int, long x86  2^31-1 ~ 2e9
 * long long      2^63-1 ~ 9e18
 */
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define fr(a, b) for (int a = 0; a < b; ++a)
using namespace std; typedef long long ll; const int inf = numeric_limits<int>::max(); void print() {cerr << endl;}
template<typename T, typename... Ts> void print(T&&a, Ts&&...etc) {cerr << a << ' '; print(etc...);}
template<typename T, typename U> ostream& operator<<(ostream& s, const pair<T,U>&p) {s << "<" << p.x << ", " << p.y << ">"; return s;} // ver. 2020-02-17
template<typename T> ostream& operator<<(ostream& s, const vector<T>&v) {s << "["; for (auto &x : v) s << x << ", "; if (!v.empty()) s << "\b\b"; s << "]"; return s;}
struct io{io(){ios_base::Init i; ios_base::sync_with_stdio(0); cin.tie(0);}}io;

int main() {
    string s;
    cin >> s;
    int a = 0, b = 0;
    fr(i,3) {
        if (s[i]=='A') ++a;
        else ++b;
    }
    cout << (a * b > 0 ? "Yes" : "No") << endl;
    return 0;
}


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

namespace AtCoder
{
    public class Code8
    {
        static void Main(string[] args)
        {
            string s1 = Console.ReadLine();

            Console.WriteLine(funcMain(s1));

            Console.ReadKey();
        }

        static public string funcMain(string arg1)
        {
            var N = int.Parse(arg1);
            var ret = new long[3];

            for (var i = 0; i <= N; i++)
            {
                if (i == 0)
                {
                    ret[1] = 2;
                    ret[2] = 2;
                }
                else if (i == 1)
                {
                    ret[0] = ret[1];
                    ret[1] = ret[2];
                    ret[2] = 1;
                }
                else {
                    ret[0] = ret[1];
                    ret[1] = ret[2];
                    ret[2] = ret[1] + ret[0];
                }
            }

            return ret[2].ToString();
        }

    }
}


Measured memory_bytes: 13140
N = int(input())
W = [input() for i in range(N)]
L = list()
ans = ''
for a in W:
  if W.count(a) >= 2:
    ans = 'No'
    break
  elif L == []:
    a = list(a)
    a.reverse()
    L.append(a[0])
  else:
    a = list(a)
    if a[0] == L[0]:
      a.reverse()
      L[0] = a[0]
      ans = 'Yes'
    else:
      ans = 'No'
      break
print(ans)

Measured memory_bytes: 3064
n = int(input())
h = list(map(int, input().split()))

cost = [0] * n
cost[1] = abs(h[1] - h[0])

for i in range(2, n):
  cost[i] = min(cost[i - 1] + abs(h[i] - h[i - 1]), cost[i - 2] + abs(h[i] - h[i - 2]))

print(cost[-1])

Measured memory_bytes: 13928
import java.util.*;

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

    }
}

Measured memory_bytes: 23636
import sys
from collections import defaultdict
N = int(input())
if N <= 3:
    print(0)
    sys.exit()
s = input()
ls = [defaultdict(int) for i in range(N)]
a = ['R', 'G', 'B']
for i, x in enumerate(s):
    for y in a:
        if x == y:
            ls[i][y] = ls[max(0, i-1)][y] + 1
        else:
            ls[i][y] = ls[max(0, i-1)][y]
ans = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        if s[i] != s[j]:
            for k in a:
                if k != s[i] and k != s[j]:
                    ans += ls[-1][k] - ls[j][k]
            if 2*j-i <N and s[i] != s[2*j-i] and s[j] != s[2*j-i]:
                ans -= 1
print(ans)


Measured memory_bytes: 76692
#!/bin/sh
# 1 2 7 5 = 1 - 2 (2= 5-1-2)
# 0 1 6 1 = 0
# 0 0 6 1 = -1

read a b c k

plusline=$(( $a + $b))

if [ $k -le $a ]; then
        echo $k
        exit
fi

if [ $k -le $plusline ]; then
        echo $a
else        
        minus=$(($k - $a - $b))
        echo $(($a - $minus))
fi

Measured memory_bytes: 3792
import sys
from itertools import groupby

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    S = readline().strip()
    N = len(S)

    s = 0
    ans = [0] * N
    for k, g in groupby(S):
        n = len(list(g))
        if k == 'R':
            ans[s + n - 1] += n - n // 2
            ans[s + n] += n // 2
        else:
            ans[s] += n - n // 2
            ans[s - 1] += n // 2
        s += n

    print(*ans)
    return


if __name__ == '__main__':
    main()


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

int main() {
  string S;
  string ans = "No";
  int c=0;

  string fh="",fb="";
  string qhh="",qhb="",qbh="",qbb="";

  cin >> S;

  int n=S.length();

  //  cout << n << endl;

  for(int i=0;i<n;i++) {
    if(i<(n-1)/2) {fh+=S[i];}
    else if(i>=(n+3)/2-1) {fb+=S[i];}
  }

  reverse(fb.begin(),fb.end());

  if(fh==fb) {
    for(int i=0;i<fh.length();i++) {
      if(fh.length()%2==0) {
        if(i<fh.length()/2) {qhh+=fh[i];}
        else if(i>=fh.length()/2) {qhb+=fh[i];}
      }
      else {
        if(i<(fh.length()-1)/2) {qhh+=fh[i];}
        else if(i>=(fh.length()+3)/2-1) {qhb+=fh[i];}
      }
    }
    for(int i=0;i<fb.length();i++) {
      if(fb.length()%2==0) {
        if(i<fb.length()/2) {qbh+=fb[i];}
        else if(i>=fb.length()/2) {qbb+=fb[i];}
      }
      else {
        if(i<(fb.length()-1)/2) {qbh+=fb[i];}
        else if(i>=(fb.length()+3)/2-1) {qbb+=fb[i];}
      }
    }
    reverse(qhb.begin(),qhb.end());
    reverse(qbb.begin(),qbb.end());
    if(qhh == qhb && qbh == qbb) ans = "Yes";

  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define pd(a,n) for(int i=0;i<n;i++)cout<<a[i]<<((i==n-1)?"\n":" ");cout<<endl;
#define pdd(a,n,m)for(int i=0;i<n;i++){for(int j=0;j<m;j++)cout<<a[i][j]<<" ";cout<<endl;}
#define mp make_pair
#define pb push_back
#define ll long long
//#define __int64 lng long
#define P pair<int,int>
#define PP pair<P,int>
ll n,k;

int main(){
  cin>>n>>k;
  cout<<min(n%k,abs(n%k-k))<<endl;
  return 0;
}

Measured memory_bytes: 256
def is_kaibun(s):
  s_len = len(s)
  is_kaibun = True
  for i in range(s_len//2):
    is_kaibun *= (s[i] == s[-(i+1)])
  return is_kaibun

s = input()
N = len(s)
s1 = s[:(N+1)//2-1]
s2 = s[(N+3)//2-1:]
if is_kaibun(s) and is_kaibun(s1) and is_kaibun(s2):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define RFOR(i,a,b) for(int i=(b-1); i>=(a); i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back
using ll = long long;
using D = double;
using LD = long double;
using P = pair<int, int>;
const int mod = 1e9+7;
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; }

int main(){
    int n,q; string s;
    cin >> n;
    cin >> s;
    cin >> q;

    set<int> se[26];
    rep(i,26){
        se[i].clear();
        se[i].insert(n);
    }

    rep(i,n) se[s[i] - 'a'].insert(i);

    auto change = [&](int i, char c){
        se[s[i] - 'a'].erase(i);
        s[i] = c;
        se[s[i] - 'a'].insert(i);
    };

    auto count = [&](int l, int r){
        int res = 0;
        rep(i,26){
            auto itr = se[i].lower_bound(l);
            if(*itr <= r) res++;
        }
        return res;
    };

    rep(_,q){
        int type; cin >> type;

        if(type == 1){
            int i; char c; cin >> i >> c; i--;
            change(i,c);
        }

        else{
            int l,r; cin >> l >> r; l--; r--;
            cout << count(l,r) << endl;
        }
    }
}


Measured memory_bytes: 24196
#include<bits/stdc++.h>
  using namespace std;
    #define ll long long
    #define ull unsigned long long
    #define fr(i,a,b) for(int i =a ; i < b; i++)
    #define FR(i,a,b) for(int i =a ; i > b; i--) 
    #define frj(j,a,b) for(int j =a ; j < b; j++)
    #define FRE(i,a,b) for(int i =a ; i >= b; i--) 
    #define fre(i,a,b) for(int i =a ; i <= b; i++)
    #define fra(s) for(auto it = s.begin(); it != s.end() ; ++it)

    #define mkp make_pair 
    #define pb push_back
    #define pii pair<int,int>
    #define speed   ios::sync_with_stdio(false), cin.tie(0) , cout.tie(0)
    //#define c(a,b) cout<<a<<"--"<<b<<endl;
    #define frv(i,a,v) for(int i =  a ; i < v.size() ; ++i)
    #define cp(a,i)  cout<<a[i].first<<" "<<a[i].second<<endl;
    #define pp(a) cout<<a.first<<" "<<a.second<<endl;
    //sum array
    #define sa(n) int a[n]; int s[n];cin>>a[0];s[0]=a[0];fr(i,1,n) {cin>>a[i];s[i]=s[i-1]+a[i];}
    #define sa1(n) int a[n+1]; long long s[n+1]; a[0]=0; s[0]=0;cin>>a[1];s[1]=a[1];fr(i,2,n+1) {cin>>a[i];\
    s[i]=s[i-1]+a[i];}

    #define pr(a,n) fr(i,0,n){cout<<a[i]<<" ";}cout<<endl;
    #define prv(v)   for(auto it = v.begin() ; it!= v.end() ;++it){cout<<*it<<" ";}cout<<endl;
    #define prs(s)   for(auto x : s){cout<<x<<" ";}cout<<endl;
    
    #define all(x)           x.begin(), x.end()
    #define prm(m,r,c) fr(i,0,r){frj(j,0,c){cout<<m[i][j]<<" "; }cout<<endl;}
    #define fillm(m,r,c,k) fr(i,0,r)frj(j,0,c)m[i][j]=k;
    constexpr auto PI  = 3.14159265358979323846L;
    constexpr auto eps = 1e-6;
    constexpr auto mod = 1000000007;
    #define MOD 1000000007
    #define maxv 100005
    #define MAXN 100001

  template<class T> ostream& operator<<(ostream& out, vector<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
  template<class T> ostream& operator<<(ostream& out, set<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }

      ll dp[101][maxv];

    const long long  INF = 1e15 +5;

int main(){
      
      speed;
      int n;
      cin>>n;
      
      int w;
      cin>>w;

      //input is as w , v
      vector<pair<int,int> > h;
      
      int x,y;
      fr(i,0,n)
      { cin>>x>>y;
        h.pb(mkp(x,y));
      }
        

      //dp[i][j]
      //minimum wight to get j value with  elements till i  knapsack 
     //  maxv at end of n items
      fillm(dp,n,maxv,INF);

      fr(i,0,maxv)
      {
        if(i<=h[0].second)
          dp[0][i]=h[0].first;
      }
      fr(i,0,n)
      {
        dp[i][0]=0;
      }

      fr(i,1,n)
      {
      //prm(dp,n,w+1);

          fr(j,1,maxv)
          { 

            if((j-h[i].second)>=0)
            dp[i][j] = dp[i-1][j-h[i].second]+h[i].first;
            else
            dp[i][j]=h[i].first;
        //    cout<<dp[i][j]<<" "<<i-1<<j-h[i].first<<dp[i-1][j-h[i].first]<<endl;
            dp[i][j]=min(dp[i-1][j],dp[i][j]);
          }
      }
      //prm(dp,n,141);
      ll ans =0;
      fr(i,0,maxv)
      if(dp[n-1][i]>0 && dp[n-1][i] <= w)
        ans = i;
      
      cout<<ans<<endl;

      return 0;

  }



Measured memory_bytes: 78336
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MODADD(ADD_X,ADD_Y)  (ADD_X+ADD_Y)%MOD;
#define MODSUB(SUB_X,SUB_Y)  (SUB_X-SUB_Y)+MOD)%MOD;
#define MODMUL(MUL_X,MUL_Y)  (MUL_X*MUL_Y)%MOD;
#define LCM(LCM_X,LCM_Y) (LCM_X*LCM_Y)/__gcd(LCM_X,LCM_Y);
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
int dx[]= {1,0,-1,0,1,-1,1,-1};
int dy[]= {0,1,0,-1,1,-1,-1,1};

int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int a,b,c;
    cin>>a>>b>>c;
    int sum=a+b+c;
    if(sum>=22)
        cout<<"bust"<<endl;
    else
        cout<<"win"<<endl;

    return 0;
}


Measured memory_bytes: 3648
process.stdin.resume();
process.stdin.setEncoding('utf8');

function kaibun(s){
    l = s.length;
    var flag = true;
    for (var i=0; i<(l-l%2)/2; i++){
        if (s[i] != s[l-1-i]){
            flag = false;
        }
    }

    return flag;
}

function Main(input){
    var s = input.trim();
    var mae = s.substr(0, (s.length-1)/2);
    var ato = s.substr(((s.length+3)/2)-1, (s.length-1)/2);
    var ans = kaibun(s) && kaibun(mae) && kaibun(ato);
    if (ans){
        console.log("Yes");
    } else{
        console.log("No");
    }
}

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

Measured memory_bytes: 21192
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int main() {
  int n;
  cin >>n ;
  int ans=0 ;
  vector<int> P(n);
  rep(i,n){
    cin>>P[i] ;
  }
  int mi=1e9 ;
  rep(i,n){
    mi= min( mi,P[i]) ;
    if(mi==P[i])
    ans++ ;
  }

  
  cout << ans <<endl ;
  
  return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<cmath>
#include<cstring>
#include<set>
#include<climits>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define all(a) a.begin(),a.end()
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
llfor;
/*pi*/double pi=acos(-1);
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll ans=1;rep(i,0,n){ans*=x;}return ans;}
/*階乗*/ll fact(ll x){ll ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){ll ans=1;rrp(i,n-r+1,n+1){ans*=i;}return ans/=fact(r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
/*Fibonacci数列*/ll fib(ll x){ll fibo[x+10];fibo[0]=1;fibo[1]=1;fibo[2]=1;rep(i,3,x+1)fibo[i]=fibo[i-1]+fibo[i-2];return fibo[x];}
/*桁数*/ll dig(ll n){ll d=0;i=0;while(n/10>0){i++;d++;}return d;}
ll ans=0;ll mod=llpow(10,9)+7;
////////////////////////////////////////////////////////////
ll n,m;
bool a[200000];
int main(){
 cin>>n>>m;
 ll b;
 rep(i,0,n)a[i]=false;
 rep(j,1,m+1){
  sc(b);
  a[b]=true;
 }
 
 ll step[n+10]={0};
 step[0]=1;
 if(!a[1])step[1]=1;
 rep(i,2,n+1){
  step[i]=step[i-2]+step[i-1];
  step[i]%=mod;
  if(a[i])step[i]=0;
 // cout<<i<<" "<<a[i]<<" "<<step[i]<<endl;
 }
 pr(step[n]);
return 0;}

Measured memory_bytes: 4488
#include <bits/stdc++.h>
#include <algorithm> //next_permutation

using namespace std;
typedef long long ll;
//typedef pair<int, int> P;
bool prime (int x){
  if (x<=1) return false;
  for (int i=2; i*i<x; i++){
    if (x%i==0) return false;
  }
  return true;
}
int main(){
  int n;
  cin>>n;
  int p=n;
  while (!prime(p)) p++;
  cout<<p;

  }


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <random>
#include <chrono>
#include <tuple>

using namespace std;

typedef long long ll;
typedef long double ld;
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

const ll SIZE = 1e5 * 2 + 10, INF = 1e9 + 10, MOD = 1e9 + 7;

const ll SQR = 10000;

ll dp[303][303][303];
bool used[303][303];
string s;
ll k, ans = 0;

void lcs(ll l, ll r) {
    if (used[l][r]) return;
    used[l][r] = 1;
    if (l == r) {
        for (int t = 0; t <= k; t++) {
            dp[l][r][t] = 1;
            ans = max(ans, dp[l][r][t]);
        }
        return;
    } else if (l == r - 1) {
        lcs(l + 1, r);
        lcs(l, r - 1);
        for (int t = 0; t <= k; t++) {
            dp[l][r][t] = 1;
            dp[l][r][t] = max(ll((s[l] == s[r]) * 2), dp[l][r][t]);
            if (t > 0) {
                dp[l][r][t] = max(dp[l][r][t], 2ll);
            }
            ans = max(ans, dp[l][r][t]);
        }
        return;
    } else {
        lcs(l + 1, r);
        lcs(l, r - 1);
        for (int t = 0; t <= k; t++) {
            dp[l][r][t] = max(dp[l + 1][r][t], dp[l][r - 1][t]);
            if (s[l] == s[r]) dp[l][r][t] = max(dp[l + 1][r - 1][t] + 2, dp[l][r][t]);
            if (t > 0) {
                dp[l][r][t] = max(dp[l][r][t], dp[l][r][t - 1]);
                dp[l][r][t] = max(dp[l + 1][r - 1][t - 1] + 2, dp[l][r][t]);
            }
            ans = max(ans, dp[l][r][t]);
        }
    }
}

int main()
{
    fastInp;

    cin >> s;
    cin >> k;

    lcs(0, s.size() - 1);
    cout << ans << "\n";
    return 0;
}

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

int main()
{
    ll n,i,j,k;
    cin>>n;
    ll ar[n];
    for(i=0;i<n;i++)
        cin>>ar[i];
    ll ans=0;
    for(i=0;i<n-1;i++){
        if(ar[i]<=ar[i+1])
            ;
        else{
            ans+=(ar[i]-ar[i+1]);
            ar[i+1]=ar[i];
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 5168
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	int a = 0;
	while (1)
	{
		int e = 1000000;
		cin >> a;
		if (a == 0)
		{
			break;
		}
		int d[1000];
		for (int i = 0; i < a; i++)
		{
			cin >> d[i];
		}
		sort(d, d + a);
		for (int i = 0; i < (a - 1); i++)
		{
			if (e > d[i + 1] - d[i])
			{
				e = d[i + 1] - d[i];
			}
		}
		cout << e << endl;
	}
return 0;
}

Measured memory_bytes: 3072
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

vector<vector<int>> level;

void dfs(int offset, int n, int L)
{
    if (n == 1) {
        return;
    }

    int m = n / 2;
    for (int i = offset; i < offset + m; i++) {
        for (int j = offset + m; j < offset + n; j++) {
            level[i][j] = level[j][i] = L;
        }
    }

    dfs(offset, m, L + 1);
    dfs(offset + m, n - m, L + 1);
}

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

    level.resize(n, vector<int>(n));
    dfs(0, n, 1);
    rep(i, n - 1)
    {
        for (int j = i + 1; j < n; j++) {
            cout << level[i][j] << " ";
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 1536
//#include "SaveFuncs.cpp"

#include <iostream>
#include <array>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <iomanip>	//cout << fixed << setprecision(桁数);
#include <stdexcept>

using namespace std;
using ll = long long;

#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; i++)
#define rep1(i, n) for(int i=1, i##_len=(n); i<i##_len; i++)
#define rrep(i, n) for(int i=(n)-1; i >= 0; i--)
#define rrep1(i, n) for(int i=(n); i > 0; i--)
#define all(x) (x).begin(), (x).end()
#define pair(a, b) make_pair(a, b);
//#define int long long
constexpr int INF = 2000000100;
constexpr int DIV = 1000000007;	// 10e9+7
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> T divUp(T a, T b) { if (a % b == 0) { return a / b; } return a / b + 1; }
string strMulti(string t, int n) { string out = ""; for (int i = 0; i < n; i++) { out += t; } return out; }

/*****/

int Main()
{
	string S;
	cin >> S;

	int N = S.length();

	vector<bool> SLoop(N);
	for (int i = 0; i < N - 1; i++)
	{
		if (S.at(i) == 'R' &&
			S.at(i + 1) == 'L')
		{
			SLoop.at(i) = true;
			SLoop.at(i + 1) = true;
		}
	}

	vector<int> C(N), M(N, -1);

	for (int i = 0; i < N; i++)
	{
		int now = i, time = 0;

		if (!SLoop.at(i))
		{
			if (i > 1 && !SLoop.at(i - 2))
			{
				if (S.at(i) == S.at(i - 2))
				{
					now = M.at(i - 2);
					//cout << i << "←" << i - 2 << endl;
				}
			}
		}

		while (true)
		{
			if (SLoop.at(now) && time % 2 == 0)
			{
				break;
			}

			if (S.at(now) == 'R')
			{
				now++;
			}
			else
			{
				now--;
			}

			time++;
		}

		M.at(i) = now;
	}

	rep(i, N)
	{
		C.at(M.at(i))++;
	}

	rep(i, N - 1)
	{
		if (C.at(i) == 0)
			cout << "0 ";
		else
			cout << C.at(i) << " ";
	}
	cout << C.at(N - 1) << endl;

	return 0;
}

/*****/

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

	Main();

	return 0;
}


Measured memory_bytes: 1488
#include <iostream>
#include <math.h>
#include <string>
#include <string.h> 
#include <cstdio>
using namespace std;
#define MAX 200000
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define IN(n) scanf("%d",&n,);
#define OUT(n) printf("%d",n);
#define IN2(n,k) scanf("%d%d",&n,&k);
#define OUT2(n,k) printf("%d%d",n,k);
#define IN3(n,k,s) scanf("%d%d%d",&n,&k,&s);
#define OUT3(n,k,s) printf("%d%d%d",n,k,s);


int main(){
    char s[200];
    int n;
    scanf("%s",s);
    n=strlen(s);
    n%2==1 ? n--: n-=2;
    while(n>1){
        bool flag=1;
        for(int i=0;i<(n/2);i++){
            if(s[i]!=s[i+(n/2)]){
                flag=0;                
            }
        }
        if(flag==1){
            OUT(n);
            return 0;
        }
        n-=2;
    }
    return 0;
}

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

#define x first
#define y second

const int maxn = 100005;

int n;
long long ans;
vector < pair < int, int > > xy, yx;
map < pair < int, int >, pair < int, int > > root;
vector < pair < int, pair < pair < int, int >, pair < int, int > > > > edges;

pair < int, int > dsu_find (pair < int, int > a) {
    if (root[a] == a)
        return a;
    return root[a] = dsu_find(root[a]);
}

void dsu_unite (pair < int, int > a, pair < int, int > b) {
    a = dsu_find(a), b = dsu_find(b);
    if (a != b) {
        if (rand() & 1)
            swap(a, b);
        root[a] = b;
    }
}

signed main () { 
    scanf("%d", &n);
    xy.resize(n);
    yx.resize(n);
    for (int i = 0; i < n; ++i) {
        scanf("%d %d", &xy[i].x, &xy[i].y);
        yx[i].x = xy[i].y, yx[i].y = xy[i].x;
        root[make_pair(xy[i].x, xy[i].y)] = make_pair(xy[i].x, xy[i].y);
    }
    sort(xy.begin(), xy.end());
    sort(yx.begin(), yx.end());
    for (int i = 0; i < n; ++i) {
        for (int j = max(i - 2, 0); j < min(i + 3, n); ++j) {
            edges.push_back(make_pair(min(abs(xy[i].x - xy[j].x), abs(xy[i].y - xy[j].y)), make_pair(xy[i], xy[j])));
            edges.push_back(make_pair(min(abs(yx[i].x - yx[j].x), abs(yx[i].y - yx[j].y)), make_pair(make_pair(yx[i].y, yx[i].x), make_pair(yx[j].y, yx[j].x))));
        }
    }
    sort(edges.begin(), edges.end());
    for (auto e: edges) {
        int w = e.x;
        pair < int, int > u = e.y.x, v = e.y.y;
        if (dsu_find(u) != dsu_find(v)) {
            dsu_unite(u, v);
            ans += w;
        }
    }
    printf("%lld\n", ans);
}


Measured memory_bytes: 31716
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{

    static void Main(string[] args)
    {
        var N = long.Parse(Console.ReadLine());
        var ans = dfs("0", N);
        Console.WriteLine(ans);
    }

    static long dfs(string current, long N)
    {
        var value = long.Parse(current);
        if (value > N)
        {
            return 0;
        }

        if (value == 0)
        {
            current = "";
        }

        var targets = new string[] { "3", "5", "7" };

        long count = 1;
        foreach (var c in targets)
        {
            if (!current.Contains(c))
            {
                count = 0;
                break;
            }
        }
        foreach (var c in targets)
        {
            long result = dfs(current + c, N);
            count += result;
        }

        return count;
    }
}



Measured memory_bytes: 15312
def main():
  from collections import deque
  s=input()
  q=int(input())
  turn = 2
  d=deque(s)

  for _ in [0]*q:
      query = input()
      if query[0] == "1":
          t = int(query)
          turn = 3 - turn
      else:
          t,f,c = map(str,query.split())
          if (int(f) + turn)% 2  == 0:
              d.append(c)
          else:
              d.appendleft(c)
  if turn == 2:
      print("".join(d))
  else:
      print("".join(list(d)[::-1]))
main()


Measured memory_bytes: 10072
# include <bits/stdc++.h>
using namespace std;
long long n,a[1000005],w,a1[1000005],usj,k,ans,b,t,v2[1000005],ans1[1000005],m;
vector <long long > v1;
long long mod=1000000007;
map <long long , long long > mp;
long long f_p(long long base, long long power) 
{
    long long result=1;
    while(power>0) 
    {
        if(power%2==1) 
        {
            result=(result*base)%mod;
        }
        base=(base*base)%mod;
        power=power/2;
    }
    return result;
}
int main()
{
	cin>>n;
	for (long long i=1; i<=n; i++)
	cin>>a[i];
	for (long long i=1; i<=n; i++)
	{
	    a1[i]=a[i];
		for(long long j=2; j*j<=a1[i]; j++) 
		{
			v2[j]=0;
			while(a1[i]%j==0) 
			{
				v2[j]++;
				ans1[j]=max(ans1[j],v2[j]);
				m=max(m,j);
				a1[i]/=j;
			}
		}
		long long bw=1;
		if (a1[i]!=1) 
		{
		ans1[a1[i]]=max(ans1[a1[i]],bw);
		m=max(a1[i],m);
		}
	}
	usj=1;
	for (long long  i=2; i<=m; i++)
	{
		for (long long  j=1; j<=ans1[i]; j++)
		{
			usj*=i;
			usj%=mod;
		}
	}
		//cout<<usj<<endl;
	for (long long i=1; i<=n; i++)
	{
		    b=mod-2;
		    w=a[i];
		    t=f_p(w,b);
		    ans+=t;
		    ans%=mod;
	}
	cout<<(usj*ans)%mod<<endl;
	
}

Measured memory_bytes: 12288
#include <algorithm>
#include <cstdlib>
#include <iostream>
using namespace std;

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

	string s;
	cin >> s;

	if(s.size() >= 6
	   && any_of(s.begin(), s.end(), [](char c) { return islower(c);})
	   && any_of(s.begin(), s.end(), [](char c) { return isupper(c);})
	   && any_of(s.begin(), s.end(), [](char c) { return isdigit(c);})) {
		cout << "VALID" << endl;
	}
	else {
		cout << "INVALID" << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);

int main(){
    fastIO;
    string a, b;
    cin >> a >> b;
    a = a+b;
    auto num = std::atoi(a.c_str());
    float sq = sqrt(num);
    float integral_part = 0;
    float f = modf(sq, &integral_part);
    if (f==0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
string s[4];

int main(){
	int n;
//	while(cin>>n){
	cin>>n;
		s[0] = "YYMM";
		s[1]="MMYY";
		s[2]="AMBIGUOUS";
		s[3]="NA";
		int x = n/100;
		int y = n%100;
	if(x==0&&y<=12&&y>0){
		cout<<s[0]<<endl;
	}
	else if(y==0&&x<=12&&x>0){
		cout<<s[1]<<endl;
	}
	else if(y==0||x==0){
		cout<<s[3]<<endl; 
	}
	else if(x<=12&&y<=12){
		cout<<s[2]<<endl;
	}
	else if(x>12&&y<=12){
		cout<<s[0]<<endl;
	}
	else if(y>12&&x<=12){
		cout<<s[1]<<endl;
	}
	else {
		cout<<s[3]<<endl;
	}
	
//	}
	
} 

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define Abs(x)((x) < 0 ? (x) * -1 : (x))
#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y) - 1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define All(x) (x).begin(),(x).end()
#define Mem0(x) memset(x, 0, sizeof(x))
#define Mem1(x) memset(x, -1, sizeof(x))
#define End '\n'
#define Out(x) cout<<(x)<<End
template<typename T> inline bool Max(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool Min(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T> >;

#define pb push_back
#define mp make_pair

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

#define LOCAL 0

int main()
{
#if LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif

    cin.tie(0);
    ios::sync_with_stdio(false);

    long n;

    cin >> n;

    ll a[n];
    ll m, half;
    ll diff = LLONG_MAX;
    long index;

    long i;

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

    sort(a, a + n);

    m = a[n - 1];
    half = m / 2;

    rep(i, n) {
        if (Abs(half - a[i]) <= diff) {
            diff = Abs(half - a[i]);
            index = i;
        }
    }

    if (index == n - 1) index = n - 2;

    cout << m << " " << a[index] << End;

    return 0;
}


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

using namespace std;

const int nmax = 8;
vector<vector<bool>> graph(nmax, vector<bool>(nmax, false));

//nは超点数 vは現在の頂点番号
int dfs(int n, int v, vector<bool> & visited){
    bool all_visited = true;
    
    //すべての頂点を訪問しているかどうか調べる
    for (int i = 0; i < n; i++){
        if (!visited[i]) all_visited = false;
    }
    
    if (all_visited) return 1; //条件を満たすパスを一つ発見した
    
    int ret = 0;
    
    for (int i = 0; i < n; i++){
        
        //隣接していない場合はだめ
        //１度以上訪問している場合もダメ
        if (!graph[v][i]) continue;
        if (visited[i]) continue;
        
        visited[i] = true; //頂点vに隣接した頂点iを訪問する
        
        ret += dfs(n, i, visited);
        
        visited[i] = false; //iを未訪問に戻す
    }
    
    return ret;
    
}

int main(){
    int n, m;
    cin >> n >> m;
    
    
    for (int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        a--, b--;
        
        //隣接リストを作る
        graph[a][b] = true;
        graph[b][a] = true;
    }
    
    //訪問済みの頂点と未訪問の頂点を管理する
    vector<bool> visited(nmax, false);
    
    // 頂点０を始点とする
    visited[0] = true;
    
    //dfs -> 頂点０から出発して, n個の頂点すべてを一筆書きで訪問するパスの総数
    cout << dfs(n, 0, visited) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
    int s=0, st=0;
    string a;
    cin >> a;
    for(int i=0; i<a.size(); i++){
        if(a[i]=='S'){
            s++;
        }
        else{
            if(s>0){
                st++;
                s--;
            }
        }
    }
    st*=2;
    cout << a.size()-st << endl;
    return 0;
}

Measured memory_bytes: 640