akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

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

typedef long long ll;

class Node {
 public:
  int id;
  int degree;
  int parent_id;
  int depth;
  vector<int> children;

  Node() {}
  Node(const int& i, const int& k)
      : id(i), degree(k), children(vector<int>(degree)), parent_id(-1) {}
};

void AddDepth(vector<Node>& nodes, int id, int depth) {
  nodes[id].depth = depth;
  depth++;
  FOR(i, 0, nodes[id].degree) { AddDepth(nodes, nodes[id].children[i], depth); }
}

int main() {
  int n;
  cin >> n;
  vector<Node> nodes(n);
  FOR(i, 0, n) {
    int id;
    int k_in;
    cin >> id >> k_in;
    Node node(id, k_in);
    FOR(j, 0, k_in) {
      int c;
      cin >> c;
      node.children[j] = c;
    }
    nodes[i] = node;
  }
  sort(nodes.begin(), nodes.end(),
       [](const Node& a, const Node& b) { return a.id < b.id; });
  // define parent
  FOR(i, 0, n) {
    FOR(j, 0, nodes[i].degree) {
      nodes[nodes[i].children[j]].parent_id = nodes[i].id;
    }
  }
  // define depth
  FOR(i, 0, n) {
    if (nodes[i].parent_id == -1) {
      AddDepth(nodes, i, 0);
    }
  }
  FOR(i, 0, n) {
    cout << "node " << nodes[i].id << ": parent = " << nodes[i].parent_id
         << ", depth = " << nodes[i].depth;
    if (nodes[i].parent_id == -1) {
      cout << ", root, [";
    } else if (nodes[i].degree > 0) {
      cout << ", internal node, [";
    } else {
      cout << ", leaf, [";
    }
    FOR(j, 0, nodes[i].degree) {
      if (j != 0) cout << ", ";
      cout << nodes[i].children[j];
    }
    cout << "]" << endl;
  }
  return 0;
}


Measured memory_bytes: 7540
# E - Colorful Blocks

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

modulus = 998244353

# nブロック m色で塗る → m ** n 通り
# 隣り合うブロックの組 n - 1組のうち 高々k組が同色

# n個ばらばら == m * (m-1) ** (n-1)
# k組同色 == n-k個ばらばら * k個をn-k組に分ける(choose(n-1, n-k-1))

def inv(x):
    return pow(x, modulus - 2, modulus)

choose = [1]  # choose(n-1, i)
for i in range(1, n):
    choose.append(choose[-1] * (n-1-i+1) * inv(i) % modulus)

def solve(n, k):
    x = m * pow(m-1, n-k-1, modulus)
    return x * choose[n-k-1] % modulus

print(sum(solve(n, i) for i in range(k+1)) % modulus)


Measured memory_bytes: 16924
//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error("\n");
  var start = Date.now();
  Main();
  var end = Date.now() - start;
  myerr("time : " + end + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function makeClone(obj){return JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  return {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw "ArrayIndexOutOfBoundsException ‚There is no more input";}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var K = nextInt();
  if(K % 2 == 0 || K % 5 == 0){
    myout(-1);
    return;
  }
  var N = 7;
  var output = 1;
  while(true){
    N %= K;
    if(N == 0){
      break;
    }
    N *= 10;
    N += 7;
    output++;
  }
  myout(output);
}


Measured memory_bytes: 32736
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();

        int answer = 753;

        for (int i = 0; i <= s.length() - 3; i++){
            int number = Integer.parseInt(s.substring(i, i + 3));

            int sabun = Math.abs(number - 753);

            if(sabun - answer < 0){
                answer = sabun;
            }
        }

        System.out.println(answer);


    }

}


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

using namespace std;

typedef long long ll;

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

	int a, b, c;
	cin >> a >> b >> c;

	vector<bool> rem(b, false);

	ll t = 0;
	while(true){
		t += a;
		t %= b;
		if(t == c){
			cout << "YES" << endl;
			return 0;
		}

		if(rem[t]){
			cout << "NO" << endl;
			return 0;
		}

		rem[t] = true;
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <string>


using namespace std;

int main(){
  string a, b, c;
  cin >> a >> b >> c;
  if((a[a.size()-1] == b[0]) && 
      b[b.size()-1] == c[0]) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}


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

typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;
typedef vector< vector< vector<ll> > > vvvint;
typedef vector<string> vstring;
typedef vector< vector<string> > vvstring;
typedef vector<char> vchar;
typedef vector< vector<char> > vvchar;
typedef vector<long double> vdouble;
typedef vector< vector<long double> > vvdouble;
typedef vector< vector< vector<long double> > > vvvdouble;
typedef pair<ll,ll> pint;
typedef vector<pint> vpint;
typedef vector<bool> vbool;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define ALL(obj) (obj).begin(), (obj).end()
// #define LLONG_MAX 9223372036854775806
#define vmax(vec) *max_element(vec.begin(), vec.end())
#define vmin(vec) *min_element(vec.begin(), vec.end())
#define vsort(vec) sort(vec.begin(), vec.end())
#define vsortgr(vec) sort(vec.begin(), vec.end(), greater<ll>())
#define MOD 1000000007
// #define MOD 998244353
// #define MOD LLONG_MAX
const double PI=3.14159265358979323846;
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 dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0,};

void printv(vint &v){
    for(auto e:v) cout<<e<<" ";
        cout<<endl;
    }

// 繰り返し二乗法
ll power(ll a, ll b){
    if(a==1)return a;
    // if(a==0)re
    ll res=1;
    while(b>0){
        if(b&1) res=res*a%MOD;
        a=a*a%MOD;
        b>>=1;
    }
    return res;
}

const int MAX=2100000;

ll fact[MAX], fact_inv[MAX];

void init_fact(ll n){
    fact[0]=1;
    // 階乗の計算
    for(ll i=0; i<n; i++) fact[i+1]=fact[i]*(i+1)%MOD;
    fact_inv[n]=power(fact[n], MOD-2);
    // 逆元の計算
    for(ll i=n-1;i>=0;i--) fact_inv[i]=fact_inv[i+1]*(i+1)%MOD;
}

ll comb(ll n, ll r){
    return (fact[n]*fact_inv[r])%MOD*fact_inv[n-r]%MOD;
}

ll perm(ll n, ll r){
    return (fact[n]*fact_inv[n-r])%MOD;
}

vector< int64_t > divisor(int64_t n) {
  vector< int64_t > ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int main() {
    cout<<fixed<<setprecision(10);

    ll n; cin>>n;

    auto m1 = divisor(n);
    auto m2 = divisor(n-1);
    ll ans = m2.size()-1;
    for(auto e:m1){
        if(e==1) continue;
        ll x = n;
        while(x >= e && x%e == 0) x /= e;
        if(x%e == 1) ans++;
    }
    cout<<ans<<endl;


    return 0;

}

Measured memory_bytes: 384
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <numeric>
using namespace std;
 
#define LOCAL  1
#define UPLOAD 2
 
#define ll long long
const long long INF = 1LL << 60;
 
template <class T = long long> T input(){T x;cin >> x;return x;}
template <class T> void output(T x){cout << x << endl;}
#define debug(x) cerr << #x<< ": " << x<< '\n';
#define debugBit(x,n) cerr << #x<< ": " << std::bitset<n>(x) << '\n';
#define REP(i,M) for(int i=0;i<M;i++)
 
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
 
int main()
{
#if ENVIRONMENT == LOCAL
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
 
  ll N = input();
  ll M = input();
  output(N*(N-1)/2 + M*(M-1)/2);

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(long long i=0; i<(int)n; i++)
#define rep2(i,a,n) for(long long i=(a); i<(int)(n); i++)
#define all(vec) vec.begin(),vec.end()
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using psi = pair<string, int>;
const int dx[4] = {1, 0,-1, 0};
const int dy[4] = {0, 1, 0,-1};
const int mod = 1e9+7;
int gcd(int a, int b){if(a%b == 0){return(b);}else{return(gcd(b, a%b));}}
int lcm(int a, int b){return a * b / gcd(a, b);}

int N, M, K, H, W, L, R, X;
//string S, T;
map<int,int> mp;
void bunkai(int a){
  int i = 2;
  while(a>1){
    while(a%i == 0){
    mp[i]++;
    a /= i;
    }
    i++;
  }
  return;
}


signed main(){
  cin >> N; 
  vi m;
  rep2(i,1,N+1) bunkai(i);
  int ans = 1;
  for(auto itr : mp){
    ans *= (itr.second+1);
    ans %= mod;
  }
  cout << ans << endl;
  return 0;
}

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

typedef long long ll;

int main(){
  string S, T;
  cin >> S >> T;
  vector<int> start(26, -1);
  vector<int> goal(26, -1);

  for (int i = 0; i < S.size(); i++) {

    int a = S.at(i) - 'a';
    int b = T.at(i) - 'a';

    if (start.at(a)!=-1 || goal.at(b)!=-1){
      if (start.at(a)!=b || goal.at(b)!=a){
        cout << "No" << endl;
        return 0;
      }
    }
    start.at(a) = b;
    goal.at(b) = a;
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 776
#include <bits/stdc++.h>
 
#define ALL(l)  (l).begin(),(l).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
//const ll mod =  1000000007;
//const ll maxn = 1000000000;

//---------------------------------------------------------------------------------------------------
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vll = vector<ll>; // intの1次元の型に vi という別名をつける
using vvll = vector<vll>; // intの2次元の型に vvi という別名をつける
using vs = vector<string>; // stringの1次元の型に vs という別名をつける
using pll = pair<ll, ll>; // これ以降 pii という型名はpair<ll, ll> と同じ意味で使える
//---------------------------------------------------------------------------------------------------

int main(){
    bool ans=true;
    string s;
    cin>>s;
    rep(i,s.size()){
        if(s.at(i)=='7')ans=false;
    }
    if(ans)cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
}
   



Measured memory_bytes: 3596
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
template<class Read>void in(Read &x){
    x=0;
    int f=0;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        f|=(ch=='-');
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    x=f?-x:x;
    return;
}
char s[200005];
int suma[200005],sumb[200005],sum[200005];
int main(){
    scanf("%s",s+1);
    int n=strlen(s+1);
    suma[1]=1;sumb[n]=n;
    for(int i=2;i<=n;i++){
        if(s[i]=='R')suma[i]=i;
        else suma[i]=suma[i-1];
    }
    for(int i=n-1;i>=1;i--){
        if(s[i]=='L')sumb[i]=i;
        else sumb[i]=sumb[i+1];
    }
    for(int i=1;i<=n;i++){
        if(s[i]=='R'){
            if((sumb[i]-i)&1)sum[sumb[i]-1]++;
            else sum[sumb[i]]++;
        }
        if(s[i]=='L'){
            if((i-suma[i])&1)sum[suma[i]+1]++;
            else sum[suma[i]]++;
        }
    }
    for(int i=1;i<=n;i++)printf("%d ",sum[i]);
    puts("");
    return 0;
}


Measured memory_bytes: 1664
N, M = map(int, input().split())
X = sorted(list(map(int, input().split())))

if N >= M:
    print(0)
else:
    dif = [abs(X[i] - X[i+1]) for i in range(M-1)]
    dif = sorted(dif)
    print(sum(dif[:M-N]))

Measured memory_bytes: 13968
#include<stdio.h>
int main(){
  int a,b,c,d,e,f,g,h,suma,sumb;

  scanf("%d %d %d %d\n %d %d %d %d",&a,&b,&c,&d,&e,&f,&g,&h);
  
  suma=a+b+c+d;
  sumb=e+f+g+h;
  
  if(suma >= sumb){
    printf("%d\n",suma);
  }
  else{
    printf("%d\n",sumb);
      }
  
  return 0;
  
}

Measured memory_bytes: 592
#include "bits/stdc++.h"

using namespace std;
typedef long long int ll;
typedef pair<double, double > pi; 
typedef pair<pair<ll ,ll >,ll > pii; 

int main(){
    
    ll N, T ,A;
    cin >> N >> T >> A;

    priority_queue<pi, vector<pi>, greater<pi > > ans;
    
    for(ll i = 0; i < N; i++){
        double H; cin >> H;
        ans.push(make_pair(abs((double)A - (T - H * 0.006)), i + 1));
    }

    cout << ans.top().second << endl;


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define inf 2e9
using namespace std;
int main(){
    int n,ans,cnt,e[300001];
    string s;
    cin>>n;
    getline(cin>>ws,s);
    s[0]=='E' ? e[0]=1 : e[0]=0;
    for (int i=1;i<n;i++)
        e[i]=e[i-1]+(s[i]=='E');
    ans=inf;
    for (int i=0;i<n;i++){
        cnt=0;
        if (i-1>=0)
            cnt+=i-e[i-1];
        //cout<<cnt<<" ";
        if (i+1<n)
            cnt+=e[n-1]-e[i];
        //cout<<cnt<<"\n";
        ans=min(ans,cnt);
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 1796
//#define LOCAL

#include <fstream>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <cstring>
#include <climits>

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

#define MOD 1000000007

using namespace std;



signed main()
{
#ifdef LOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif

    int A, B;
    
    cin >> A >> B;
    if (A + B >= 10) {
        cout << "error" << endl;
    } else {
        cout << A + B << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
main(){
long long int n;
cin>>n;
long long int a[n],b[n],c[n];

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


for(int i=1;i<n;i++)
{
a[i]+=max(b[i-1],c[i-1]);
b[i]+=max(a[i-1],c[i-1]);
c[i]+=max(a[i-1],b[i-1]);
}
cout<<max(a[n-1],max(b[n-1],c[n-1]));

}


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

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

    vector<int64_t> A(N);
    vector<int64_t> B(N);
    vector<int64_t> C(N);

    for(int i = 0; i < N; ++i) cin >> A[i];
    sort(A.begin(), A.end());

    for(int i = 0; i < N; ++i) cin >> B[i];
    sort(B.begin(), B.end());

    for(int i = 0; i < N; ++i) cin >> C[i];
    sort(C.begin(), C.end());

    vector<int64_t> Bsize(N, 0);
    int bnum = 0;
    int cnum = 0;
    while(bnum < N && cnum < N){
        if(B[bnum] < C[cnum]){
            Bsize[bnum] = N - cnum;
            bnum++;
        }
        else {
            cnum++;
        }
    }
    
    for(int i = N - 1; i > 0; --i){
        Bsize[i - 1] += Bsize[i];
    }

    int anum = 0;
    bnum = 0;
    int64_t ans = 0;
    while(anum < N && bnum < N){
        if(A[anum] < B[bnum]){
            ans += Bsize[bnum];
            anum++;
        }
        else {
            bnum++;
        }
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    int a, b, c;
    cin >> a >> b >> c;
    int d, e, f;
    cin >> d >> e >> f;
    set<int> waters;
    for(auto i = 0;i*a*100 <= f; i++) {
        for(auto j = 0; (i*a+j*b)*100 <=f; j++) waters.insert((i*a+j*b) * 100);
    }
    waters.erase(0);
    vector<int> waterv(waters.begin(),waters.end());
    
    vector<int> sugar;
    for(auto w:waterv) sugar.push_back(w/100*e);
    //REP(i,sugar.size()) cerr << sugar[i] << endl;
    int maxc = 0;
    int ans = 100 * a;
    int anss = 0;
    REP(i,waterv.size()) {
        for(auto j = 0;j*c <= sugar[i];j++) {
            for (auto k = 0; j*c+ k*d <=sugar[i]; k++) {
                int ms = 0;
                if (waterv[i] + j*c+ k*d <= f) ms = j*c+ k*d;
                int cons = ms * 10000 / (waterv[i] + ms);
                if (maxc < cons) {
                    maxc = cons;
                    ans = waterv[i] + ms;
                    anss = ms;
                }
            }
        }
        //cerr << ans << " " << anss << endl;
    }

    cout << ans << " " << anss << endl;

    return 0;
}

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

using namespace std;

//FILE *fi=freopen("1.txt","r",stdin);

int n,m,k,lim=1,a[301][301];
char c[301][301];

void nhap()
{
    scanf("%d %d %d",&n,&m,&k);
    for (int i=1;i<=n;++i)
    {
        string s;
        cin>>s;
        for (int j=1;j<=m;++j)
            c[i][j]=s[j-1];
    }
}

bool check(int i)
{
    for (int j=1;j<=m;++j)
        if (c[i][j]=='#')
            return true;
    return false;
}

void process()
{
    for (int i=1;i<=n;++i)
    {
        if (check(i))
        {
            bool f=0;
            for (int j=1;j<=m;++j)
            {
                if (c[i][j]=='#')
                {
                    if (!f)
                    {
                        f=1;
                    }
                    else lim++;
                }
                a[i][j]=lim;
            }
            if (f) lim++;
        }
        else
        {
            for (int j=1;j<=m;++j)
                a[i][j]=a[i-1][j];
        }
    }
    for (int i=n;i>0;--i)
    {
        for (int j=1;j<=m;++j)
        {
            if (!a[i][j])
                a[i][j]=a[i+1][j];
        }
    }
    for (int i=1;i<=n;++i)
    {
        for (int j=1;j<=m;++j)
            cout<<a[i][j]<<" ";
        cout<<"\n";
    }
}

int main()
{
    nhap();
    process();
    return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define ull unsigned long long int
#define forn(i,n)for(ll i=0;i<(n);i++)
#define forn_rev(i,n)for(ll i=(n)-1;i>=0;i--)
#define for1n(i,n) for(ll i=1;i<=(n);i++)
#define ARRAY_SIZE(a) sizeof(a)/sizeof(*a)
#define MOD 1000000007
#define MAXN 1000005

using namespace std;

vector<ll> adj[MAXN],d(MAXN,0),parent(MAXN,-1);
bool visited[MAXN];

void bfs(){
    visited[0]=1;
    queue<ll> q;
    q.push(0);
    d[0]=0;
    while(!q.empty()){
        ll u=q.front();
        q.pop();
        forn(v,adj[u].size()){
            if(!visited[adj[u][v]]){
                visited[adj[u][v]]=1;
                q.push(adj[u][v]);
                d[adj[u][v]]=d[u]+1;
                parent[adj[u][v]]=u;
            }
        }
        //cout<<q.size()<<endl;

    }


}


int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL); cout.tie(NULL);
    memset(visited,0,sizeof visited);
    ll T=1;
    //cin>>T;
    while(T--)
    {
        ll N,M;
        cin>>N>>M;
        forn(i,M){
            ll u,v;
            cin>>u>>v;
            adj[u-1].push_back(v-1);
            adj[v-1].push_back(u-1);
        }
        bfs();

        forn(i,N){
            if(!visited[i]){
                cout<<"No";
                return 0;
            }
        }
        cout<<"Yes"<<endl;
        forn(i,N-1){
            cout<<parent[i+1]+1<<endl;
        }







    }



    return 0;
}

Measured memory_bytes: 49868
#include<stdio.h>
int main()
{
    int a,b,i;
    scanf("%d %d",&a,&b);
    for(i=a-1;i>=1;i--)
        printf("%d ",b-i);
    printf("%d ",b);
    for(i=1;i<a;i++)
        printf("%d ",b+i);
}


Measured memory_bytes: 128
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <tuple>
#include <algorithm>
#include <map>
#include <cmath>
#include <tuple>
using namespace std;
long long int MOD = 1000000000 + 7;
using ll = long long;
ll LARGE = 1000000;


int main() {
	ll n;
	cin >> n;
	for (ll i = 0; i < n; ++i) {
		ll x;
		cin >> x;
		if (x % 2 == 0) {
			if (x % 3 == 0) {
				continue;
			}
			if (x % 5 == 0) {
				continue;
			}
			cout << "DENIED" << endl;
			return 0;
		}
	}
	cout << "APPROVED" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;

void Main() {
  ll n,m;
  cin >> n >> m;
  PP p[n];
  rep(i,n) cin >> p[i].S.F >> p[i].S.S >> p[i].F;
  sort(p,p+n);
  set<P> s;
  rep(i,m) {
    ll x;
    R x;
    s.in(P(x,i));
  }
  ll d[m];
  memset(d,-1,sizeof(d));
  rep(i,n) {
    ll x=p[i].S.F-p[i].F,y=p[i].S.S-p[i].F;
    iter(s) it=s.lower_bound(P(x,-1));
    vector<P> v;
    while(it!=s.end()){
      P p=*it;
      if(p.F<y) {
        v.pb(p);
        it++;
      } else break;
    }
    rep(k,v.size()) {
      d[v[k].S]=p[i].F;
      s.erase(v[k]);
    }
  }
  rep(i,m) pr(d[i]);
}

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


Measured memory_bytes: 25116
#include<cstdio>
#include<algorithm>
using namespace std;
int n,h,ans;
struct Stu{
	long long a,b; 
}k[1000100];
int cmp(Stu x,Stu y)
{
	return x.a<y.a;
}
int main()
{
	scanf("%d%d",&n,&h);
	int oo=1;
	for(int i=1;i<=n;++i)
	{
		scanf("%d",&k[oo++].a);
		k[oo-1].b=1;
		scanf("%d",&k[oo++].a);
	}
	sort(k+1,k+2*n+1,cmp);
	int o=2*n;
	while(h>0)
	{
		if(k[o].b==0)
		{
			h-=k[o].a;
			ans++;
		}
		else break;
		o--;
	}
	if(h<0) h=0;
	if(h%k[o].a==0) printf("%d\n",ans+h/k[o].a);
	else printf("%d\n",ans+h/k[o].a+1);
	return 0;
}

Measured memory_bytes: 4224
#include <cstdio>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

int main()
{
  int n,m;
  scanf("%d%d",&n,&m);
  static int A[200000],B[200000],C[200000];
  static pair<int,int> P[1000000];
  for(int i=0;i<m;i++){
    int p,q,c;
    scanf("%d%d%d",A+i,B+i,C+i);
    A[i]--;
    B[i]--;
    P[i]=make_pair(A[i],C[i]);
    P[i+m]=make_pair(B[i],C[i]);
  }
  for(int i=0;i<n;i++){
    P[2*m+i]=make_pair(i,0);
  }
  int N=2*m+n;
  sort(P,P+N);
  vector<vector<int> > e(N);
  for(int i=0;i<N;i++){
    if(P[i].second==0){
      continue;
    }
    int a=P[i].first;
    int k=lower_bound(P,P+N,make_pair(a,0))-P;
    e[k].push_back(i);
    e[i].push_back(k);
  }
  for(int i=0;i<m;i++){
    int a=lower_bound(P,P+N,make_pair(A[i],C[i]))-P;
    int b=lower_bound(P,P+N,make_pair(B[i],C[i]))-P;
    e[a].push_back(b);
    e[b].push_back(a);
  }
  queue<int> Q[2];
  bool b=0;
  static int v[1000000]={0};
  int s=lower_bound(P,P+N,make_pair(0,0))-P;
  Q[b].push(s);
  v[s]=1;
  int t=1;
  int ans=-1;
  while(1){
    if(Q[b].empty()){
      if(Q[!b].empty()){
	break;
      }
      b=!b;
      t++;
    }
    int i=Q[b].front();
    Q[b].pop();
    if(v[i]<t){
      continue;
    }
    if(P[i].first==n-1){
      ans=t-1;
      break;
    }
    for(int x=0;x<e[i].size();x++){
      int j=e[i][x];
      if(P[i].second==0){
	if(!v[j]){
	  v[j]=t+1;
	  Q[!b].push(j);
	}
      }
      else{
	if(!v[j]||v[j]>t){
	  v[j]=t;
	  Q[b].push(j);
	}
      }
    }
  }
  printf("%d\n",ans);
  return 0;
}



Measured memory_bytes: 39296
//:Ditttoo
#include<bits/stdc++.h>
#define int long long int 
using namespace std;
int32_t main()
{
	int n,c;
	cin>>n>>c;

	int v[n+1], w[n+1];

	int dp[n+1][c+1];

	for(int i=1;i<=n;i++){
		cin>>w[i]>>v[i];
	}

	for(int i=0;i<=n;i++){
		for(int j=0;j<=c;j++)
			dp[i][j] = 0;
	}

	

	for(int i=1;i<=n;i++){
		for(int j=1;j<=c;j++){
			if(j - w[i] >= 0){
				dp[i][j] = max(dp[i-1][j] , dp[i-1][j-w[i]] + v[i]);
			}
			else dp[i][j] = dp[i-1][j];
		}
	}

	// for(int i=0;i<=n;i++){
	// 	for(int j=0;j<=c;j++){
	// 		cout<<dp[i][j]<<" ";
	// 	}
	// 	cout<<"\n";
	// }

	cout<<dp[n][c];
	return 0;
}        

Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;
// const ll MOD=998244353;

const int MAX_N=2020;
ll inv[MAX_N+1], fact[MAX_N+1], ifact[MAX_N+1];

ll comb(int n, int k){
  if(n<k) return 0;
  return fact[n]*ifact[k]%MOD*ifact[n-k]%MOD;
}

void prepare(){
  inv[1]=fact[0]=fact[1]=ifact[0]=ifact[1]=1LL;
  for(int i=2;i<=MAX_N;i++){
    inv[i]=inv[MOD%i]*(MOD-MOD/i)%MOD;
    fact[i]=fact[i-1]*i%MOD;
    ifact[i]=ifact[i-1]*inv[i]%MOD;
  }
}


int main(){
  prepare();
  int N,K; cin>>N>>K;
  for(int i=1;i<=K;i++){
    cout<<comb(N-K+1,i)*comb(K-1,i-1)%MOD<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <vector>
#include <cmath>
using namespace std;
int mp[555][555];
struct node
{
    int x1,y1,x2,y2;
    node(int x,int y,int xx,int yy):
        x1(x),y1(y),x2(xx),y2(yy){}
};
 
int main()
{
    vector<node> ans;
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            scanf("%d",&mp[i][j]);
    for(int i=1;i<=n;i++){
        for(int j=1;j<m;j++){
            if(mp[i][j]&1){
                ans.push_back(node(i,j,i,j+1));
                mp[i][j+1]++;
            }
        }
    }
    for(int i=1;i<n;i++){
        if(mp[i][m]&1)
            ans.push_back(node(i,m,i+1,m)),mp[i+1][m]++;
    }
    printf("%d\n",ans.size());
    for(int i=0;i<ans.size();i++){
        printf("%d %d %d %d\n",ans[i].x1,ans[i].y1,ans[i].x2,ans[i].y2);
    }
}


Measured memory_bytes: 5232
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

int main(){
    int n;
    int ans = 0;
    cin >> n;
    vector<int> d(n);
    for (int i = 0; i < n; i++) {
        cin >> d.at(i);
    }
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            ans += d.at(i) * d.at(j);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner

object Main {
  def solve(sc: => Scanner): Unit = {
    val A, B, C, D = sc.nextInt
    println(Math.max(0, (Math.min(B, D) - Math.max(A, C))))
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    solve(sc)
  }
}

Measured memory_bytes: 25556
#include<iostream>
using namespace std;
int main()
{
  int k,a,b;
  cin>>k>>a>>b;
  int min;
  min=a/k;
  min++;
  if(a%k==0 || b%k==0 || min*k<=b)
  {
        cout<<"OK\n";
  }
  else
  {
    cout<<"NG\n";
  }
  return 0;
  
  
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
       string s;
       int c=0,c1=0,c2=0,c3=0;
    while(n--){
        cin>>s;
        if(s=="AC") c++;
        else if(s=="WA") c1++;
        else if(s=="TLE") c2++;
        else c3++;

    }
    cout<<"AC x "<<c<<endl;
    cout<<"WA x "<<c1<<endl;
    cout<<"TLE x "<<c2<<endl;
    cout<<"RE x "<<c3<<endl;

    return 0;
}


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

const int MAXN = 1e5+10;
int pt[3][MAXN];
int v[3][MAXN];

int main(){
	int n, a, b, c;
	scanf("%d", &n);
	for (int i = 0; i < n; i++){
		scanf("%d %d %d", &a, &b, &c);
		pt[0][i] = a;
		pt[1][i] = b;
		pt[2][i] = c;
	}
	v[0][0] = pt[0][0];
	v[1][0] = pt[1][0];
	v[2][0] = pt[2][0];
	for (int i = 1; i < n; i++){
		v[0][i] = max(v[1][i-1], v[2][i-1]) + pt[0][i];
		v[1][i] = max(v[0][i-1], v[2][i-1]) + pt[1][i];
		v[2][i] = max(v[1][i-1], v[0][i-1]) + pt[2][i];
	}
	printf("%d\n", (int) max(v[0][n-1], max(v[1][n-1], v[2][n-1])));
	return 0;
}

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

int main() {
  int n,y,t;
  cin>>n>>y;
  t=y/1000;
  rep(now_ft,20001){
    rep(now_tt,2001){
      int now_t=t;
      now_t=now_t-5*now_ft-10*now_tt;
      if(now_t>=0){
        if(y==now_t*1000+now_ft*5000+now_tt*10000){
          if(n==now_t+now_ft+now_tt){
            cout<<now_tt<<" "<<now_ft<<" "<<now_t<<endl;
            return 0;
          }
        }
      }
    }
  }
  cout<<-1<<" "<<-1<<" "<<-1<<endl;
}


Measured memory_bytes: 256
def lcs(x, y):
    m, n = len(x), len(y)
    dp = [[-1] * (n+1) for _ in range(m+1)]

    for i in range(m+1):
        for j in range(n+1):
            if i == 0 or j == 0:
                dp[i][j] = 0
            elif x[i-1] == y[j-1]:
                dp[i][j] = 1 + dp[i-1][j-1]
            else:
                dp[i][j] = max(dp[i-1][j], dp[i][j-1])

    i, j = m, n
    idx = dp[m][n]
    seq = [''] * (idx + 1)

    while i > 0 and j > 0:
        if x[i-1] == y[j-1]:
            seq[idx-1] = x[i-1]
            i -= 1
            j -= 1
            idx -= 1
        elif dp[i-1][j] > dp[i][j-1]:
            i -= 1
        else:
            j -= 1

    return ''.join(seq)


def main():
    str1 = input()
    str2 = input()
    ans = lcs(str1, str2)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 111580
// Problem : A - Serval vs Monster
// Contest : AtCoder - AtCoder Beginner Contest 153
// URL : https://atcoder.jp/contests/abc153/tasks/abc153_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

//Macros

#define ll long long
#define db long double
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int,int>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define inf 1e10
#define PI acos(-1.0)
#define int long long
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define N 100005

//Solution

void solve(){
    int a,b;
    cin>>a>>b;
    cout<<(a+b-1)/b<<endl;
}

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    int tests;
    //cin>>tests;
    tests = 1;
    while(tests--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3620
#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;

int main()
{
    int N;
    cin >> N;
    int fizz;
    int buzz;
    int fizzbuzz;
    long sum = 0;
    for(int i=1 ; i<=N; i++){
        if(i%3 != 0 && i%5 != 0){
            sum += i;        
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    string a, b, c;
    cin >> a >> b >> c;
    if(a[(int)a.size()-1]==b[0] && b[(int)b.size()-1]==c[0]){
        cout << "YES" << endl;
    }else cout << "NO" << endl;
    
}

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


int main(){
    int N, A[200000];
    scanf("%d", &N);
    for(int i=0;i<N;i++) scanf("%d", &A[i]);
    // end input

    int s = 0;
    for(int i=0;i<N;i++){
        s ^= A[i];
    }

    for(int i=0;i<N;i++){
        int ans = s^A[i];
        printf("%d ", ans);
    }
    printf("\n");

    return 0;
}



Measured memory_bytes: 3288
//Compete against Yourself.
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n, a[N], k;

void yes(){
   cout<<"YES"<<endl;
   //exit (0);
}
void no(){
   cout<<"NO"<<endl;
   //exit (0);   
}

int32_t main(){_
   
   cin>>n>>k;

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

   sort(a.rbegin(), a.rend());

   int ans = 0;
   for (int i = k; i < n; ++i)
   {
      ans += a[i];
   }

   cout<<ans;


   return 0;
}

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

int main(){
  int A,B,C;
  bool a=false;
  cin>>A>>B>>C;
  for(int i=1;i<B+1;i++){
    if(A*i%B==C){
      a=true;
      break;
    }
  }
  if(a){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
  
  
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <map>
#define ull unsigned long long
#define ll long long
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,a,ans=0,cmp1;
    cin >> n;
    vector<int> a_1,cmp;
    for(int i=0;i<n;i++){
        cin >> a;
        a_1.push_back(a);
        if(i>0){
            ans+=abs(a_1[i-1]-a_1[i]);
        }
    }
    ans+=abs(a_1[0])+abs(a_1[n-1]);
    cmp1=ans;
    for(int i=0;i<n;i++){
        if(i==0){
            ans=ans-(abs(a_1[i])+abs(a_1[i]-a_1[i+1]))+abs(a_1[i+1]);
        }
        else if(i==n-1){
            ans=ans-(abs(a_1[i])+abs(a_1[i]-a_1[i-1]))+abs(a_1[i-1]);
        }
        else {
            ans=ans-(abs(a_1[i]-a_1[i-1])+abs(a_1[i]-a_1[i+1]))+abs(a_1[i-1]-a_1[i+1]);
        }

        cout << ans << endl;
        ans=cmp1;
    }

    return 0;
}

Measured memory_bytes: 1784
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int maxN = sc.nextInt();
		int maxM = sc.nextInt();
		int want = sc.nextInt();
		Set<Integer> set = new HashSet<Integer>();
		for(int n = 0; n <= maxM; n++) {
			for(int m = 0; m <= maxN; m++) {
				set.add(maxN * n + maxM * m - 2 * n * m);
			}
		}
		System.out.println(set.contains(want) ? "Yes" : "No");
	}
}

Measured memory_bytes: 56916
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,m;cin>>n>>m;
    int wr = 0; int rig = 0;
    map<int,pair<int,bool>> arr;
    for(int i = 0; i<m; i++){
        int a; string s;cin>>a>>s;
        if(s=="AC"){
            if (arr[a].second!=1){
                arr[a].second =1;
            }
        }else if(s == "WA"){
            if(arr[a].second!=1){
                arr[a].first+=1;
            }
        }
    }
    for(auto a: arr){
        if(a.second.second==1){
            wr+=a.second.first;
        rig+=a.second.second;    
        }
        
    }
    cout<<rig<<" "<<wr<<endl;
    return 0;
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll MOD = 1000000007;
const double PI = 3.141592653589793238463;
const ll N=2e5+9;
ll fastpow(ll base, ll exp)
{
    if (exp == 0)
        return 1;
    if (exp == 1)
        return base % MOD;
    ll t = fastpow(base, exp / 2);
    t = (t * t) % MOD;
    if (exp % 2 == 0)
        return t;
    else
        return ((base % MOD) * t) % MOD;
}
int main()
{
    FASTINOUT;
    ll x,y,z;
    cin>>x>>y>>z;
    ll sum=fastpow(2,x)-1;
    ll res=1;
    ll kl=1;
    for (ll i=1; i<=y; ++i)
    {
        res *= (x+1-i);
        res %= MOD;
        res*= fastpow(i,MOD-2);
        res%= MOD;
    }
    for (ll i=1; i<=z; ++i)
    {
        kl *= (x+1-i);
        kl %= MOD;
        kl *= fastpow(i,MOD-2);
        kl %= MOD;
    }
    sum=(sum-res+MOD)%MOD;
    sum=(sum-kl+MOD)%MOD;
    cout<<sum<<endl;
    return 0;
}


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

int main() {
    int n;
    ll max_w;

    cin >> n >> max_w;

    vector<int> w(n);
    vector<int> v(n);

    for ( int i = 0; i < n; i++ ) {
        cin >> w[i] >> v[i];
    }

    vector<ll> dp(100000+1);

    for ( int i = 0; i <= 100000; i++ ) {
        dp[i] = 1e13;
    }

    dp[0] = 0;
    for ( int i = 1; i <= n; i++ ) {
        for ( ll j = 100000; j >= 0; j-- ) {
            if ( j >= v[i-1] ) {
                dp[j] = min(dp[j], dp[j - v[i-1]] + w[i-1]);
            }
        }
    }

    ll ans = 0;
    for ( ll i = 0; i <= 100000; i++ ) {
        if ( dp[i] <= max_w ) {
            ans = max(ans, (ll)i);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
import sys
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

def main():
	S = input().rstrip()
	S = [s for s in S]

	# print(S)
	scnt = 0
	remove = 0
	for s in S:
		if s == 'S':
			scnt += 1
		else:
			if scnt:
				scnt -= 1
				remove += 2
	
	# print(remove)
	print(len(S)-remove)

if __name__ == '__main__':
	main()

Measured memory_bytes: 5096
H, W = map(int, input().split())
c = [list(map(int, input().split())) for i in range(10)]
A = [list(map(int, input().split())) for i in range(H)]
 
path = [[0]*10 for i in range(10)]
for i in range(10):
    for j in range(10):
        path[i][j] = c[i][j]
 
for k in range(10):
    for i in range(10):
        for j in range(10):
            path[i][j] = min(path[i][j], path[i][k]+path[k][j])
 
min_route = []
for i in range(10):
    min_route.append(path[i][1])
 
wall_num = [0]*10
for a in A:
    for i in range(10):
        wall_num[i] += a.count(i)
 
ans = 0
for i in range(10):
    ans += wall_num[i] * min_route[i]
 
print(ans)

Measured memory_bytes: 3444
/*#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")*/
//#pragma GCC optimize("fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
//#pragma GCC optimize("unroll-loops")
//#define _CRT_SECURE_NO_WARNINGS
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
//#pragma GCC optimize("Ofast")
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <bitset>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <math.h>
#include <random>
using namespace std;
typedef long long  ll;
typedef pair<ll, ll> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
#define all(a) a.begin(), a.end()
#define lb(a, x) lower_bound(a.begin(), a.end(), x)
#define pb(x) push_back(x)
#define fr(i, n) for(int i = 0; i < n; ++i)
//typedef cc_hash_table<int, int, hash<int>> hst2;
//typedef cc_hash_table<int, hst2, hash<int>> hst;
typedef pii ord_set_t;
#ifdef ABCD
typedef map<ord_set_t, vi> ordered_set;
int __builtin_popcount(int x)
{
	int cnt = 0;
	for (; x > 0; x >>= 1) cnt += x & 1;
	return cnt;
}
#else
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
mt19937 rnd(239);
using namespace __gnu_pbds;
typedef tree<
	ord_set_t,
	vi,
	less_equal<ord_set_t>,
	rb_tree_tag,
	tree_order_statistics_node_update>
	ordered_set;
#endif
const int N = 300001;
ll mod = 1000 * 1000 * 1000 + 7;
ll dp[N][14];
int main()
{

	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef ABCD
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else

#endif
	string str; cin >> str;
	fr(i, 10) dp[0][i] = (str[0] == '?' || str[0] - '0' == i);
	int n = str.size();
	for (int i = 1; i < n; ++i)
	{
		if (str[i] == '?')
		{
			fr(j, 13)
			{
				fr(k, 10)
				{
					dp[i][(10*j + k) % 13] += dp[i - 1][j];
					dp[i][(10*j + k) % 13] %= mod;
				}
			}
		}
		else
		{
			fr(j, 13)
			{
				dp[i][(10*j + str[i] - '0') % 13] += dp[i - 1][j];
				dp[i][(10*j + str[i] - '0') % 13] %= mod;
			}
		}
	}
	cout << dp[n - 1][5];
}


Measured memory_bytes: 12752
A, B, K = map(int, input().split())

def get(num):
    yakusuu_array = []
    for i in range(1,num + 1):
        if num % i == 0:
            yakusuu_array.append(i)
    return yakusuu_array

a = list(set(get(A)) & set(get(B)))
a.sort(reverse=True)


print(a[(K-1)])



Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
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);
}
/*-------------------------------------------*/

class UnionFind {
    vector<int> par;
    int c;

  public:
    UnionFind(int n) : par(n, -1), c(n) {}
    int find(int x) { return par[x] < 0 ? x : par[x] = find(par[x]); }
    int size(int x) { return -par[find(x)]; }
    int count() const { return c; }
    bool same(int x, int y) { return find(x) == find(y); }
    bool unite(int x, int y) {
        if((x = find(x)) == (y = find(y))) return false;
        if(par[x] < par[y]) swap(x, y);
        par[y] += par[x];
        par[x] = y;
        return c--;
    }
};

int n, m;

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

    cin >> n >> m;
    UnionFind uf(n);

    rep(i, m) {
        int a, b;
        cin >> a >> b;
        uf.unite(a - 1, b - 1);
    }

    int ans = 0;
    rep(i, n) chmax(ans, uf.size(i));

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3984
#include <bits/stdc++.h>
bool a[300001];
using namespace std;
int main(){
  int z,a,m,b,c,i;
  while(cin>>z,z){
    a=z*z*z;
    for(m=0,i=1;i*i*i<a;i++){
      b=pow((double)(a-i*i*i),1.0/3.0);
      c=i*i*i+b*b*b;
      m=max(c,m);
    }
    cout<<a-m<<endl;
  }
}

Measured memory_bytes: 3164
// clang-format off
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
// clang-format on

int main() {
    int n, x, y;
    cin >> n >> x >> y;
    --x;
    --y;

    vector<int> a(n + 1);
    int c = y - x + 1;

    auto ADD_C = [&](int d) {
        ++a[d];
        --a[d + 1];
        a[d + 1] += 2;
        a[d + (c + 1) / 2] -= 2;
        if (c % 2 == 0) {
            ++a[d + c / 2];
            --a[d + c / 2 + 1];
        }
    };

    rep(i, x) {
        // cycle
        ADD_C(x - i);

        // i->0
        ++a[1];
        --a[i + 1];

        // i->x-1
        ++a[1];
        --a[x - 1 - i + 1];

        // y+1->n-1
        if (y < n - 1) {
            int w = n - 1 - y;
            int s = x - i + 2;
            ++a[s];
            --a[s + w];
        }
    }

    for (int i = x; i <= y; ++i) {
        // cycle
        ADD_C(0);

        // x-1->0
        if (x > 0) {
            int w = x;
            int s = min(i - x, y - i + 1) + 1;
            ++a[s];
            --a[s + w];
        }
        // y+1->n-1
        if (y < n - 1) {
            int w = n - 1 - y;
            int s = min(i - x + 1, y - i) + 1;
            ++a[s];
            --a[s + w];
        }
    }

    for (int i = y + 1; i < n; ++i) {
        // cycle
        ADD_C(i - y);

        // i->n-1
        ++a[1];
        --a[n - 1 - i + 1];

        // i->y+1
        ++a[1];
        --a[i - (y + 1) + 1];

        // x-1->0
        if (x > 0) {
            int w = x;
            int s = i - y + 2;
            ++a[s];
            --a[s + w];
        }
    }

    rep(i, n) a[i + 1] += a[i];
    for (int i = 1; i < n; ++i) cout << a[i] / 2 << "\n";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,k;
	cin>>n;
	vector< pair<int,int> >a(n);
	for(int i=0;i<n;i++){
		cin>>k;
		a[i]=make_pair(k,i);
	}
	sort(a.begin(),a.end());
	for(int i=0;i<n;i++){
		cout<<a[i].second+1<<" ";
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
int a[100+5]={0};
int main(){
	int n,sum = 0;
	cin >> n;
	for(int i=1;i<n;i++)
		cin >> a[i];
	sum = a[1];
	for(int i =1;i<n-1;i++){
		sum += min(a[i],a[i+1]);
	}
	sum += a[n-1];
	cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n,m;
    cin>>n>>m;
    vector<ll> x;
    vector<ll> y;
    x.pb(0);
    y.pb(0);
    for(int i=0;i<n;i++){
        ll a;
        cin>>a;
        x.pb(a);
    }
    for(int i=0;i<m;i++){
        ll a;
        cin>>a;
        y.pb(a);
    }
    ll countx=0;
    for(int i=1;i<=n-1;i++){
        countx+=(x[i+1]-x[i])*i*(n-i);
        countx=countx%1000000007;
    }
    ll county=0;
    for(int j=1;j<=m-1;j++){
        county+=(y[j+1]-y[j])*j*(m-j);
        county=county%1000000007;
    }
    ll ans=countx*county;
    ans=ans%1000000007;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 2548
#include <bits/stdc++.h>
using namespace std;
const int maxn=1<<18+5;
typedef long long ll;
const int inf=1e9;
int a,b,c; 
int main(){
	cin>>a>>b>>c;
	if(a+b+c>=22)cout<<"bust"<<endl;
	else cout<<"win"<<endl;
    return 0;
}


Measured memory_bytes: 256