akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
vector<string> v;
int main(int argc, const char * argv[]) {
   
    string h;
    
    cin >> h;
    
    int k;
    
    scanf("%d",&k);
    
    for(int i=0;i<h.size();i++){
        string tmp = "";
        for(int j=0;j<k && i+j<h.size();j++){
            tmp+=h[i+j];
            v.push_back(tmp);
        }
    }
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());

    cout << v[k-1];
    return 0;
}


Measured memory_bytes: 1660
import java.util.*;
import static java.lang.System.*;

public class Main {
	public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
		int m = sc.nextInt();
		boolean[][] edges = new boolean[n][n];
		for (int i = 0; i < m; i++) {
			int a = sc.nextInt() - 1;
			int b = sc.nextInt() - 1;
			edges[a][b] = true;
			edges[b][a] = true;
		}

		// Generate all permutations by queue
		List<List<Integer>> permutations = new ArrayList<List<Integer>>();
		Queue<List<Integer>> queue = new LinkedList<List<Integer>>();
		queue.add(new ArrayList<Integer>());

		int[] nodes = new int[n];
		for (int i = 0; i < n; i++) {
			nodes[i] = i;
		}

		while (queue.size() > 0) {
			List<Integer> perm = queue.poll();
			for (int i = 0; i < nodes.length; i++) {
				if (!perm.contains(nodes[i])) {
					// Deep copy the perm
					List<Integer> nPerm = new ArrayList<Integer>();
					for (int j = 0; j < perm.size(); j++) {
						nPerm.add(perm.get(j));
					}

					nPerm.add(nodes[i]);
					if (nPerm.size() == nodes.length) {
						permutations.add(nPerm);
					} else {
						queue.add(nPerm);
					}
				}
			}
		}

		int cnt = 0;
		for (int i = 0; i < permutations.size(); i++) {
			List<Integer> perm = permutations.get(i);
			if (perm.get(0) != 0) {
				continue;
			}
			boolean oneStroke = true;
			for (int j = 0; j < perm.size() - 1; j++) {
				int nodeA = perm.get(j);
				int nodeB = perm.get(j + 1);
				if (!edges[nodeA][nodeB]) {
					oneStroke = false;
					break;
				}
			}
			if (oneStroke) {
				cnt++;
			}
		}

		out.println(cnt);
	}
}


Measured memory_bytes: 35020
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <array>
#include <cstdio>
#include <vector>

using namespace std;

int N;
int ans = -1000000000;

array<int, 10> F;
array<int, 11> P;

array<int, 10> joshino;

vector<array<int, 10>> vF;
vector<array<int, 11>> vP;

void func()
{
    int score = 0;
    int jcnt = 0;

    for (int i = 0; i < N; i++)
    {
        int cnt = 0;

        for (int j = 0; j < 10; j++)
        {
            if (joshino[j] == 1)
            {
                jcnt++;
                if (vF[i][j] == 1) cnt++;
            }
        }

        if (0 < jcnt) score += vP[i][cnt];
    }

    if (0 < jcnt) ans = max(ans, score);
}

void dfs(int i)
{
    if (i == 10)
    {
        func();
        return;
    }

    joshino[i] = 0;
    dfs(i + 1);

    joshino[i] = 1;
    dfs(i + 1);
}

int main()
{
    if (scanf("%d", &N) < 1) return 0;

    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < 10; j++) if (scanf("%d", &F[j]) < 1) return 0;
        vF.push_back(F);
    }

    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < 11; j++) if (scanf("%d", &P[j]) < 1) return 0;
        vP.push_back(P);
    }

    dfs(0);

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vector<vector<T>>;
using vl = vector<ll>;

const ll MOD = 1e9 + 7;
const ll INF = 1e14;
const long double EPS = 1e-11;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (int i = (l); i < (r); i++)
#define reper(i, l, r) for (int i = (r)-1; i >= (l); i--)

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

int main() {
    init();
    string s;
    cin >> s;
    cout << s.substr(0, 4) << " " << s.substr(4, 8) << endl;
    return 0;
}

Measured memory_bytes: 256
use proconio::input;
fn main() {
    input!{
        n: usize,
	m: usize,
	a: [usize; m],
    };
    let mut sum :usize = 0;
    for i in 0..m{
	sum += a[i];
    }
    if(n >= sum){
	println!("{}",n-sum);
    }else{
	println!("-1");
    }
}


Measured memory_bytes: 2236
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <numeric>
#include <limits>
#include <type_traits>


using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

typedef pair<long long int, long long int> pll;


const long long int mod = 1000000007;
const long long int INF = 1e18;
const long double PI=3.14159265358979323; 

long long int N,D,X,Y,x,y,nokori,tmp,res=0;
long long int hito[100]={1,2,3,4,5,6,7,8,9};

string str[1000];

int main()
{
    cout << fixed << setprecision(18);
    cin>>N;
    if(N%2==1){
        cout<<(N/2+1)/(long double)N<<endl;
    }else{
        cout<<0.5000000000000<<endl;
    }
}    


Measured memory_bytes: 256
function Main(input) {
    // console.log(input);
    
    const N = parseInt(input[0].split(" ")[0]);
    const Q = parseInt(input[0].split(" ")[1]);
    const S = input[1];
    
    var ctArr = new Array(N);
    ctArr[0] = 0;
    for(var i = 1; i < N+1; i++) {
        ctArr[i] = ctArr[i-1] + ((S[i-1] == 'A' && S[i] == 'C') ? 1 : 0);
    }

    for(var i = 2; i < input.length; i++) {
        var l = input[i].split(" ")[0];
        var r = input[i].split(" ")[1];
        console.log(ctArr[r-1] - ctArr[l-1]);
    }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n"));


Measured memory_bytes: 34440
#pragma GCC optimize(3)
#include<cstdio>
#include<cstring>
using namespace std;
const int maxn=200010,maxm=400010;
int n,m,cnt,head[maxn];
struct edge{
    int to,next;
}edges[maxm];
bool c[maxn],sz[maxn];
char cc;
inline bool check(int p){
    bool hd;
    if(head[p]<0) return false;
    register int j;
    for(j=head[p];sz[edges[j].to];j=edges[j].next);
    if(j>=0) hd=c[edges[j].to];
    for(;j>=0;j=edges[j].next) if(!sz[edges[j].to]){
        if(c[edges[j].to]^hd) return true;
    }
    return false;
}
inline void dfs(int p){
    sz[p]=true;
    for(register int j=head[p];j>=0;j=edges[j].next) if((!sz[edges[j].to])&&(!check(edges[j].to))) dfs(edges[j].to);
}
inline void gi(int &x){
    for(cc=getchar();cc<48||cc>57;cc=getchar());
    for(x=0;cc<='9'&&cc>='0';cc=getchar()) x=x*10+(cc&15);
}
int main(){
    scanf("%d%d",&n,&m);getchar();
    for(register int i=1;i<=n;i++) c[i]=(getchar()==65);
    int xx,yy;memset(head,-1,sizeof(head));
    for(register int i=1;i<=m;i++){
        gi(xx);gi(yy);
        edges[cnt]=(edge){yy,head[xx]};
        head[xx]=cnt++;
        edges[cnt]=(edge){xx,head[yy]};
        head[yy]=cnt++;
    }
    bool flag;//memset(sz,1,sizeof(sz));
    while(true){
        flag=true;
        for(register int i=1;i<=n;i++) if((!sz[i])&&(!check(i))){
            flag=false;dfs(i);
        }
        if(flag) break;
    }
    for(register int i=1;i<=n;i++) if(!sz[i]){
        printf("Yes\n");return 0;
    }
    printf("No\n");
    return 0;
}

Measured memory_bytes: 5888
#pragma GCC optimize("Ofast")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define gcd(a,b) __gcd(a,b)
#define pb push_back
#define DRACO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long int
#define GO ll t; cin>>t; while(t--)
#define mod  1000000007
#define vect vector<long long int>
#define fore(p) for(auto& x:p)
#define bins binary_search
#define vecti vector<int>::iterator
#define bitout __builtin_popcount
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(), x.rend()
#define PY 3.141592653589793238
#define F first
#define S second
int main() 
{   DRACO
    ll i,j,k,l,n,m;
    cout.precision(10);
    //GO
    {   
        ll d, t ,s;
        cin >> d >> t >> s;

        if( s* t >= d)
        	cout<<"Yes\n";
        else
        	cout<<"No\n";
        
    }
return 0;
}
//check the corner cases(n==1)
//try checking in reverse order
//check your logic again

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

struct Node {
	Node() {
		parent = -1;
		depth = 0;
		children_num = 0;
	}
	int parent;
	int children_num;
	vector<int> children;
	int depth;
};

void calc_depth(Node nodes[], int root) {
	for(int i = 0; i < nodes[root].children_num; i++) {
		nodes[nodes[root].children[i]].depth = nodes[root].depth+1;
		calc_depth(nodes, nodes[root].children[i]);
	}
}


int main() {
	int n;
	cin >> n;
	Node nodes[n];

	for(int i = 0; i < n; i++) {
		int id, k;
		cin >> id >> k;
		nodes[id].children_num = k;
		for(int j = 0; j < k; j++) {
			int child_id;
			cin >> child_id;
			nodes[id].children.push_back(child_id);
			nodes[child_id].parent = id;
		}
	}
	
	int find_par;
	for(find_par = 0; find_par < n; find_par++) {
		if(nodes[find_par].parent == -1) {
			break;
		}
	}

	calc_depth(nodes, find_par);


	for(int i = 0; i < n; i++) {
		if(nodes[i].parent == -1) {
			cout << "node " << i << ": parent = -1, depth = 0, root, ";
		}
		else if(nodes[i].children_num == 0) {
			cout << "node " << i << ": parent = " << nodes[i].parent << ", depth = " << nodes[i].depth << ", leaf, ";
		}
		else {
			cout << "node " << i << ": parent = " << nodes[i].parent << ", depth = " << nodes[i].depth << ", internal node, ";
		}
		cout << "[";
		for(int j = 0; j < nodes[i].children_num-1; j++) {
			cout << nodes[i].children[j] << ", ";
		}
		if(nodes[i].children_num > 0) {
			cout << nodes[i].children[nodes[i].children_num-1];
		}
		cout << "]";
		cout << endl;
	}
}



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

#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(a) a.begin(), a.end()
#define ll long long
#define mod 1e9+7

using namespace std;

int main()
{
  string s, _;
  cin >> _ >> s >> _;
  cout << 'A' << s[0] << 'C' << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<queue>
#include<map>
#include<vector>
#include <cstdlib>
#include<algorithm>
#include <cstdio>
#include <cctype>
using namespace std;
const long long INF=10000000000000LL;
typedef long long ll;
typedef pair<ll,ll> P;
ll N,M,K=0;
ll T,a[15]={},b=0;
ll A,B,C;
ll D[1005];
string str;
map<string,int> m;

int main(){
	cin>>A>>B>>str;
	for(int i=0;i<str.size();++i){
		if(str[i]=='-'){
			++b;
		}else{
			a[b]++;
		}
	}
	if(a[0]==A&&a[1]==B&&b==1){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long l,r;
    cin>>l>>r;
    r=min(r,l+2019);
    int ans=2018;
    for(long long i=l;i<=r;i++){
        for(long long j=i+1;j<=r;j++){
            int x = i*j%2019;
            ans=min(x,ans);
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

int main() {
    int a;
    cin >>a;
    string s;
    cin>>s;
    if(a>=3200){
        cout<<s<<endl;
    }
    else
    {
        cout<<"red"<<endl;
    }
    
}



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

#define Rep(i,n) for(int i=0;i<n;i++)
#define For(i,n1,n2) for(int i=n1;i<n2;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define RREP(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()

typedef long long ll;
typedef pair<int, int> P;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){if(a>b){a=b;return 1;}return 0;}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){if(a<b){a=b;return 1;}return 0;}


int gcd(int u, int v) {
    int r;
    while (v) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}
int gcd(vector<int> a){
    int l = a.size();
    int res = gcd(a[0],a[1]);
    FOR(i,2,l){
        res = gcd(res,a[2]);
    }
    return res;
}
int n,k;

int main(){
    cin >> n >> k;
    vector<int> a(n);
    
    REP(i,n){
        cin >> a[i];
    }
    int r = gcd(a);
    int m = *max_element(all(a));
    if(k%r==0&&k<=m){
        put("POSSIBLE");
    }else{
        put("IMPOSSIBLE");
    }
    return 0;
}


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

int n;
vector<vector<int>> adj;
vector<long long> DP;
const long long inf = (long long)1e9 + 7;

int popcount(uint32_t a)
{
	int counter = 0;
	while (a != 0)
	{
		if (a & 1)
			counter++;
		a= a >> 1;
	}
	return counter;
}

int main()
{
	cin >> n;
	adj.resize(n + 1);
	for (int i = 1; i < n + 1; i++)
	{
		adj[i].resize(n + 1);
		for (int j = 1; j < n + 1; j++)
			cin >> adj[i][j];
	}
	// bit mask DP, iterate through the men one by one (for matching) and use a mask to record which women are available
	// current state, remaining women are recorded in the mask
	// DP[mask], mask 0 ... 2^(n)-1 aruond 4mil
	DP.resize(1 << (n));
	DP[0] = 1; // no women are available, all men are matched

	for (int mask = 1; mask < (1 << n); mask++)
	{
		int a = n+1-popcount(mask);  // number of women remaining, should be matching number of men remaining, also remember we are doing men sequentially
		for (int b = 1; b < n + 1; b++) // scan through women to match with a
		{
			if (adj[a][b] == 1 && mask >> (b - 1) & 1) // a is connected to b; b is available
			{
				//cout << "matching " << a << " to " << b << endl;
				//cout << " mask " << mask << endl;
				//cout << " DP[mask] " << DP[mask] << endl;
				//cout << " mask & (!(1 << (b - 1))) " << (mask & (~(1 << (b - 1)))) << endl;
				DP[mask] = (DP[mask]+DP[mask & (~(1 << (b - 1)))])%inf;
				//cout << DP[mask] << endl;
			}
		}
	}
	cout << DP[(1 << n) - 1] << endl;
}


Measured memory_bytes: 19608
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

ll dp[55][55][2505];
int n,a;
int x[55];

int main(){
  cin >> n >> a;
  rep(i,n) cin >> x[i];
  
  dp[0][0][0] = 1;
  rep(i,n){
    for(int j = 0; j <= i; j++){
      rep(k,2505){
        if(k+x[i] < 2505){
          //i枚目を選んだ場合
          dp[i+1][j+1][k+x[i]] += dp[i][j][k];
          //i枚目を選ばない場合
          dp[i+1][j][k] += dp[i][j][k];
        }
      }
    }
  }
  
  ll ans = 0;
  
  for(int j = 1; j <= n; j++){
    ans += dp[n][j][a*j];
  }
  
  cout << ans << endl;
  
  return 0;
}

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

int main() {
  string S;
  int hugs = 0;
  int l = 0;
  
  
  cin >> S;
  int e = S.size() - 1;
  
  while (e > l) {
    if (S[l++] != S[e--]) {
      hugs++;
    }
  }

  cout << hugs;

  return 0;
}

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

int main(){
    string s;
    cin >> s;
    int ans=0;
    for(int i=0;i<s.size();i++){
        ans+=s.at(i)-'0';
    }
    if(ans%9==0)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3752
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
int a[n],b[n],c[n];
for(int i=0;i<n;i++)
cin>>a[i]>>b[i]>>c[i];
int dp[n][3];
memset(dp,0,sizeof(dp));
dp[0][0]=a[0];
dp[0][1]=b[0];
dp[0][2]=c[0];
for(int i=1;i<n;i++)
{
  dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i];
  dp[i][1]=max(dp[i-1][2],dp[i-1][0])+b[i];
  dp[i][2]=max(dp[i-1][1],dp[i-1][0])+c[i];
}
cout<<max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2]);
}



Measured memory_bytes: 5952
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
  cin>>N;
  vector<int64_t>A(N);
  for(int i=0;i<N;i++)
    cin>>A.at(i);
  map<int64_t,int64_t>M;
  for(int i=0;i<N;i++){
  if(M.count(A.at(i)))
    M.at(A.at(i))++;
    else
      M[A.at(i)]=1;
  }int64_t ans=0;
  for(auto p:M){
  auto k=p.first;
    auto v=p.second;
  ans+=(v*(v-1))/2;
  }for(int i=0;i<N;i++){
  int64_t a=M.at(A.at(i));
    a--;
    cout<<ans-a<<endl;
  
  }
    return 0;
}

Measured memory_bytes: 11904
#include <bits/stdc++.h>
using namespace std;
int n,a[210],s=0;
int main()
{
	cin>>n;
	for (int i=1;i<=2*n;i++)
	  cin>>a[i];
	sort(a+1,a+2*n+1);
	for (int i=1;i<=2*n;i+=2)
	  s+=a[i];
	cout<<s;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int tsum[1000060];
int toddsum[1000060];

int main()
{
  int n;
  cin >> n;
  int last = 1;
  tsum[1] = 1;
  toddsum[1] = 1;

  while (n > 0)
    {
      for (;last < n+1; last++)
	{
	  for (int i = 1; i*(i+1)*(i+2)/6 < last+1; i++)
	    {
	      int tet = i*(i+1)*(i+2)/6;
	      if (last - tet >= 0 && 
		  (tsum[last] == 0 || tsum[last-tet] + 1 < tsum[last]))
		tsum[last] = tsum[last-tet]+1;
	      if ((tet % 2 == 1) &&
		  last - tet >= 0 &&
		  (toddsum[last] == 0 || 
		  toddsum[last-tet] + 1 < toddsum[last]))
		toddsum[last] = toddsum[last-tet]+1;
	    }
	}
      cout << tsum[n] << " " << toddsum[n] << "\n";
      cin >> n;
    }

  
}

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

int main() {
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  for (int i = 0; i < k; ++i) {
    if (a >= b) {
      b *= 2;
    } else if (b >= c) {
      c *= 2;
    }
  }
  if (a < b && b < c) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


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

int main(){

    int a,b;
    cin >> a >> b;
	if(a>b){
	   cout << "a > b" << endl;
	}else if(a<b){
	   cout << "a < b" << endl;
	}else{
	   cout << "a == b" << endl;
	}
    

    return 0;
}

Measured memory_bytes: 1156
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		// for (; solver.hasNext();) {
		// solver.readBody(in.readLine());
		// }
		// solver.solve();
	}
}

class Solver {
	int N;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		// String[] strArr = str.split("\\s+");
		// N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
		if (str.charAt(2) == str.charAt(3) && str.charAt(4) == str.charAt(5))
			System.out.println("Yes");
		else
			System.out.println("No");
	}

	public boolean hasNext() {
		return cnt < N;
	}

	public void readBody(String str) {
		// System.out.println(str);
		cnt++;
	}

	public void solve() {

	}
}


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

	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		
		int e[] = new int[4];
		
		int sameLength = 0;
		
		for(int i = 0 ; i < 4 ; i++) {
			e[i] = scan.nextInt();
			for(int j = 0 ; j < i ; j++) {
				if(e[i] == e[j]) {
					++sameLength;
					e[i] = -1;
					e[j] = -1;
					break;
				}
			}
		}
		if(sameLength == 2) {
			System.out.println("yes");
		}else {
			System.out.println("no");
		}
	}
}



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

using namespace std;
typedef long long int ll;

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

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

  int total = 0;
  for (int i = 1; i <= N; i+=2) {
    int count = 0;
    for (int j = 1; j <= i; j++) {
      if (i % j == 0) {
        count++;
      }
    }

    if (count == 8) {
      total++;
    }
  }

  printf("%d\n", total);
}


Measured memory_bytes: 128
s = input()
t = input()

for i in range(len(s) - len(t) + 1)[::-1]:
    cnt = 0
    q = 0
    for j in range(len(t))[::-1]:
        if s[i + j] == '?':
            q += 1
        elif s[i + j] == t[j]:
            cnt += 1
    
    if cnt == len(t) - q:
        idx = i
        s = s[:idx] + t + s[idx + len(t):]
        for k in range(len(s)):
            if s[k] == '?':
                s = s[:k] + 'a' + s[k + 1:]
        print(s)
        break
else:
    print('UNRESTORABLE')

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

#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
const int N = 100;
const int MX = 1e9;

int n, m;
vector<pair<int, int>> conn[N];
map<pair<int, int>, bool> used;

void dijkstra(int v) {
	vector<int> dist(n, MX), parent(n, -1);
	vector<bool> vis(n, false);
	dist[v] = 0;
	
	for (int i = 0; i < n; ++i) {
		int c = -1;
		for (int j = 0; j < n; ++j) {
			if (!vis[j] && (c == -1 || dist[j] < dist[c])) c = j;
		}
		
		vis[c] = true;
		// Parent part
		if (parent[c] != -1) {
			int a = c, b = parent[c];
			if (a > b) swap(a, b);
			used[{a, b}] = true;
		}
		for (auto edge : conn[c]) {
			int to = edge.first, len = edge.second;
			if (dist[c] + len < dist[to]) {
				dist[to] = dist[c] + len;
				parent[to] = c;
			}
		}
	}
}


int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin >> n >> m;
	for (int i = 0; i < m; ++i) {
		int a, b, c;
		cin >> a >> b >> c;
		--a, --b;
		conn[a].push_back({b, c});
		conn[b].push_back({a, c});
		if (a > b) swap(a, b);
		used[{a, b}] = false;
	}
	
	for (int i = 0; i < n; ++i) {
		dijkstra(i);
	}
	
	int cnt = 0;
	for (auto i : used) {
		cnt += !i.second;
	}
	cout << cnt;
}


Measured memory_bytes: 3712
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

using namespace std;

inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}

typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EACH(t,i,c) for(t::iretator i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

const double EPS = 1e-10;

int seamap[52][52];
int num = 0;

void dfs(int x, int y) {
	if(seamap[x][y]) {
		seamap[x][y] = 0;

		if(seamap[x-1][y-1]) {
			dfs(x-1, y-1);
		}
		if(seamap[x][y-1]) {
			dfs(x, y-1);
		}
		if(seamap[x+1][y-1]) {
			dfs(x+1, y-1);
		}
		if(seamap[x-1][y]) {
			dfs(x-1, y);
		}
		if(seamap[x+1][y]) {
			dfs(x+1, y);
		}
		if(seamap[x-1][y+1]) {
			dfs(x-1, y+1);
		}
		if(seamap[x][y+1]) {
			dfs(x, y+1);
		}
		if(seamap[x+1][y+1]) {
			dfs(x+1, y+1);
		}
	}
}


int main() {
	int w, h;

	REP(i, 52) {
		REP(j, 52) {
			seamap[i][j] = 0;
		}
	}

	while(cin >> w >> h, w) {
		FOR(i, 0, 52) {
			FOR(j, 0, 52) {
				seamap[i][j] = 0;
			}
		}

		FOR(i, 1, h+1) {
			FOR(j, 1, w+1) {
				cin >> seamap[i][j];
			}
		}

		num = 0;

		FOR(i, 1, 51) {
			FOR(j, 1, 51) {
				if(seamap[i][j]) {
					num++;
					dfs(i, j);
				}
			}
		}

		cout << num << endl;
	}

	return 0;
}

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

int main () {
  int N;
  string S;
  cin >> N >> S;
  vector<int> e(N+1), w(N+1);
  w.at(0) = 0;
  if (S.at(0) == 'W') w.at(1) = 1;
  else w.at(1) = 0;
  for (int i = 2; i < N+1; i++) {
    if(S.at(i-1) == 'W') w.at(i) = w.at(i-1)+1;
    else w.at(i) = w.at(i-1);
  }
  
  e.at(0) = 0;
  if (S.at(N-1) == 'E') e.at(1) = 1;
  else e.at(1) = 0;
  for (int i = 2; i < N+1; i++) {
    if (S.at(N-i) == 'E') e.at(i) = e.at(i-1)+1;
    else e.at(i) = e.at(i-1);
  }
  
  int ans = N;
  for(int i = 0; i < N+1; i++) {
    int count = w.at(i) + e.at(N-i);
    ans = min(ans, count);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3076
//----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#include<stdlib.h>
#include<stdio.h>
#define test ll t; cin>>t; while(t--)
#define FOR(p,n) for(ll i=p;i<(ll)n;i++)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define MAX 1000005
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
#define vs vector<string>
#define mii map<int,int>
#define msi map<string,int>
#define vpii vector< pair<int, int > >
#define vpsi vector< pair< string ,int > >
#define forci(p,q) for(int i=p;i<q;i++)
ll gcd(ll a,ll b){ if(b==0) return a;    return gcd(b,a%b);}
ll lcm(ll a,ll b) { return (a/gcd(a,b)*b);}
ull power(ull a, ull b) {a %= mod;  ull res = 1;  while (b > 0) { if (b & 1) res = res * a % mod;  a = a * a % mod;  b >>= 1; }  return res%mod; }
ll modmul(ll x, ll y){return (x*y)%mod;}
ll modadd(ll x, ll y){return (x+y)%mod;}
ll modsub(ll x, ll y){return (x-y+mod)%mod;}
ll fact[1000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<100007;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[r],mod-2)))%mod; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
inline long long toint(const std::string &s) {std::stringstream ss; ss << s; long long x; ss >> x; return x;}
inline std::string tostring(long long number) {std::stringstream ss; ss << number; return ss.str();}
inline std::string tobin(long long x) {return std::bitset<63>(x).to_string();}
bool prime[MAX];
ull sieve(){memset(prime,true,sizeof(prime));for(ull p=2;p*p<MAX;p++){if(prime[p]==true){for(ull i=2*p;i<MAX;i+=p){prime[i]=false;}}}prime[0]=0;prime[1]=0;
}
/*int inv[1000001]={0};
void findinverse(){inv[1] = 1;for(int i = 2; i <=1e6 ; ++i)	inv[i] = (mod - (mod/i) * inv[mod%i] % mod) % mod;}
*/
using namespace std;
set<int > g;
void primeFactors(int n)  
{  
    while (n % 2 == 0)  
    {  
        g.insert(2); 
        n = n/2;  
    }  
 	 for (int i = 3; i <= sqrt(n); i = i + 2)  
    { 
        while (n % i == 0)  
        {  
            g.insert(i);
            n = n/i;  
        }  
    }   
    if (n > 2)  
        g.insert(n); 
}  
int solve()
{
	
	int a,b;
	cin>>a>>b;
	int x=gcd(a,b);
	primeFactors(x);
	cout<<g.size()+1<<endl;
	return  0;
}
signed main()
{
	fastio;
//	test
		solve();
}

Measured memory_bytes: 3692
//#include<bits/stdc++.h>
#include<cstdio>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 19;
char cn[cm], * ci = cn;
inline int getint() {
	char C = *ci++;
	int A = C - '0';
	while ((C = *ci++) >= '0') A = A * 10 + C - '0';
	return A;
}

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

	fread(cn, 1, cm, stdin);

	int N = getint(), K = getint();
	int kotae = 0;
	rep(i, N) if (getint() >= K) kotae++;
	printf("%d", kotae);

	Would you please return 0;
}

Measured memory_bytes: 512
#include<cstdio>
#include<algorithm>
#include<cstring>

using namespace std;

int n,l;

int main(){
  scanf("%d %d", &n, &l);
  char str[n][l + 1];
  
  for(int i = 0; i < n; i++){
    scanf("%s\n", str[i]);
  }

  for(int i = 0; i < n; i++){
    for(int j = i + 1; j < n; j++){
      if(strcmp(str[i], str[j]) > 0){
        char tmp[l];
        strncpy(tmp, str[i],l);
        strncpy(str[i], str[j], l);
        strncpy(str[j], tmp, l);
      }
    }
  }

  for(int i = 0; i < n; i++)
    printf("%s", str[i]);

  printf("\n");
  
  return 0;
}


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

n,m = inpl()
res = [False] * n
res[0] = True
cnt = [1] * n
for i in range(m):
    a,b = inpl()
    a,b = a-1,b-1
    cnt[a] -= 1; cnt[b] += 1
    if res[a]:
        res[b] = True
    if cnt[a] == 0:
        res[a] = False
print(sum(res))

Measured memory_bytes: 96020
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    k=II()
    s=SI()
    if len(s)<=k:print(s)
    else:print(s[:k]+"...")

main()

Measured memory_bytes: 9200
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    int n = Integer.parseInt(sc.next());
    int ans = IntStream.range(0, n).map(i -> countB(i + 1, n)).sum();
    pw.println(ans);
  }

  static int countB(int a, int n) {
    String aString = String.valueOf(a);
    int aHead = Integer.parseInt(String.valueOf(aString.charAt(0)));
    int aTail = Integer.parseInt(String.valueOf(aString.charAt(aString.length() - 1)));
    if (aTail == 0) {
      return 0;
    }
    int bCount = 0;
    if (aHead == aTail && aHead <= n) {
      bCount++;
    }
    for (int i = 10; ; i = i * 10) {
      int bBase = aTail * i + aHead;
      if (bBase > n) {
        break;
      }
      int bMax = bBase + i - 10;
      if (bMax <= n) {
        bCount += i / 10;
      } else {
        for (int j = 0; ; j += 10) {
          int bCandidate = bBase + j;
          if (bCandidate <= n) {
            bCount++;
          } else {
            break;
          }
        }
      }
    }
    return bCount;
  }
}


Measured memory_bytes: 47692
#!/usr/bin/env python3
from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall, dijkstra
# G = csgraph_from_dense(edge, null_value=10**9)
# f = floyd_warshall(G)
# d = dijkstra(G, indices=1)
import sys
input = lambda: sys.stdin.readline()[:-1]
sys.setrecursionlimit(10**8)

xs,ys,xt,yt=map(int,input().split())
n=int(input())
xyr=[(xs,ys,0),(xt,yt,0)]
data=[[-1]*(n+2) for i in range(n+2)]
for i in range(n):
    xyr.append(tuple(map(int,input().split())))
# print(xyr)

for i in range(n+1):
    for j in range(i+1,n+2):
        x0 = xyr[i][0]
        y0 = xyr[i][1]
        r0 = xyr[i][2]
        x1 = xyr[j][0]
        y1 = xyr[j][1]
        r1 = xyr[j][2]
        data[i][j]=max(((x0-x1)**2+(y0-y1)**2)**.5-r0-r1,0)

G = csgraph_from_dense(data, null_value=-1)
# for i in G:
#     print(i)
d = dijkstra(G, indices=0, directed=False)
print(d[1])



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

#define int long long
#define endl "\n"
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);


main(){
	FIO
	int n,q;
	cin>>n;
	int arr[n],i,j,k=0;
	map<int,int>mp;
	for(i=0;i<n;i++){
		cin>>arr[i];
		mp[arr[i]]++;
		k+=arr[i];
	}
	cin>>q;
	while(q--){
		int a,b;
		cin>>a>>b;
		int x = mp[a];
		mp[a] = 0;
		mp[b] += x;
		k = k - (x*a) + (x*b);
		cout<<k<<endl;
	}
}

Measured memory_bytes: 10176
#include <iostream>
#include <list>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <cmath>
#include <algorithm>

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define MOD 1000000007

#define MAXNUM 2000

typedef long long ll;

const ll INF = 1LL << 50;

using namespace std;

int main(){
    // スコアの正負を逆にしてスコアの最小化を考える
    // そうした場合はスコアを距離とみなした最短経路を求める問題に帰着できる
    int N, M;
    cin >> N >> M;
    int a[MAXNUM], b[MAXNUM];
    ll c[MAXNUM];
    REP(i, M)
    {
    	cin >> a[i] >> b[i] >> c[i];
    	// 0-index に直す
    	a[i] = a[i] - 1;
    	b[i] = b[i] - 1;
    	c[i] = -c[i];
     }

    // ベルマンフォード法を用いて最短経路を求める
    // とりあえずは負閉路を考えない
    // 1. 始点からの最短距離配列dist の初期化
    // 2. 辺の数だけ最短距離を更新
    // 3. 2 を頂点の数 - 1だけ繰り返す(始点は最短距離が0)
    ll dist[N];
    REP(i, N)
    {
    	dist[i] = INF;
    }

    dist[0] = 0;
    REP(n, N - 1)
    {
    	// 全ての辺について最短距離を更新
    	REP(i, M)
    	{
    		int source = a[i];
    		int destination = b[i];
    		ll cost = c[i];
    		// 辺の始点の最短距離が定義されていなければとばす
    		if (dist[source] == INF) continue;
    		if (dist[destination] > dist[source] + cost) dist[destination] = dist[source] + cost;
    	}
    }

    // 最短距離となる経路に負閉路があるか調べる
    // negative[i] : 頂点i までの最短経路に負の閉路があるかどうか
    bool negative[N];
    REP(i, N)
    {
    	negative[i] = false;
    }
    // 頂点N までの最短経路で負閉路がある場合は、その負閉路の長さは最大でN である
    REP(i, N)
    {
    	REP(i, M)
    	{
    		int source = a[i];
    		int destination = b[i];
    		ll cost = c[i];
    		// 辺の始点の最短距離が定義されていなければとばす
    		if (dist[source] == INF) continue;

    		if (dist[destination] > dist[source] + cost)
    		{
    			dist[destination] = dist[source] + cost;
    			negative[destination] = true;
    		}
    		if (negative[source])
    		{
    			negative[destination] = true;
    		}
    	}
    }

    if (negative[N - 1])
    {
    	cout << "inf" << endl;
    }
    else
    {
    	// 最短距離を最大スコアに直す
    	cout << -dist[N - 1] << endl;
    }

}


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

int main()
{
    int N;
    cin >> N;
    vector<int> v(N);
    for (int i = 0; i < N; i++)
    {
        cin >> v.at(i);
    }

    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());

    int a = 0, b = 0;
    for (int i = 0; i < N; i++)
    {
        if (i % 2 == 0)
        {
            a += v.at(i);
        }
        else
        {
            b += v.at(i);
        }
    }
    cout << a - b;
}


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

struct coo
{
    int x;
    int y;
    int h;
} sto[110];

int main()
{
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> sto[i].x >> sto[i].y >> sto[i].h;
    int flag = 0;
    while (sto[flag].h == 0)
        flag++;
    for (int i = 0; i <= 100; i++)
    {
        for (int j = 0; j <= 100; j++)
        {
            int ans = sto[flag].h + abs(i - sto[flag].x) + abs(j - sto[flag].y);
            bool swi = 0;
            for (int k = 0; k < n; k++)
            {
                int tmp = ans - abs(i - sto[k].x) - abs(j - sto[k].y);
                if (tmp < 0)
                    tmp = 0;
                if (tmp != sto[k].h)
                {
                    swi = 1;
                    break;
                }
            }
            if (!swi)
            {
                cout << i << ' ' << j << ' ' << ans << endl;
                return 0;
            }
        }
    }
}

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

int main() {
  long long n; cin>>n;
  vector<int> v;
  int tmp = 0;
  while (true) {
    tmp = n % 26;
    if (tmp == 0) tmp += 26;
    v.push_back(tmp);
    n -= tmp;
    n = n / 26;
    if (n == 0) break;
  }

  for (int i= v.size()-1; i >= 0; --i) {
    cout << (char)(v.at(i)+96);
  }

  cout << endl;

  return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define ll unsigned long long int
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	ll n,t;cin>>n>>t;
	ll sum=0;
	ll temp;cin>>temp;
	sum+=t;
	//<<sum<<endl;
	ll pre=(temp+t);
	for(int i=1;i<n;i++){
		ll x;cin>>x;
		if(x>pre){
			sum+=((t));
			pre=x+t;
		}
		else{
			if(x+t>pre){
				sum+=((x+t)-pre);
				pre=x+t;
			}
		}
	}
	cout<<sum<<endl;
	return 0;
}

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

#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define DEBUG if(0)
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l,T r)
{bool a=l>r;if(a)l=r;return a;}
template <typename T>inline bool chmax(T &l,T r)
{bool a=l<r;if(a)l=r;return a;}
template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}
typedef pair<LL,LL> P;
typedef vector<LL> V;
int R,C,N;
int calc(int r,int c){
    if(r==0&&c==0)return 0;
    if(c==0)return r;
    if(r==R)return R+c;
    if(c==C)return(R+C+R-r);
    if(r==0)return R+R+C+C-c;
    return -1;
}

int main(){

    cin>>R>>C>>N;
    vector<P> e;
    V f;
    map<LL,int> z;
    REP(i,N){
        int a,b,c,d;
        cin>>a>>b>>c>>d;
        int x=calc(a,b);
        int y=calc(c,d);
        if(x==-1||y==-1)continue;
        //cout<<x<<" "<<y<<endl;
        e.pb({x,y});
        z[x]=0;
        z[y]=0;
    }
    int cnt=0;
    for(auto &it:z)it.se=cnt++;
    vector<int> val(cnt*2);
    int M=e.size();
    REP(i,M){
        int bg=z[e[i].fi];
        int ed=z[e[i].se];
        val[bg]=i+1;
        val[ed]=-i-1;
    }
    stack<int> st;
    V exist(M+1,0);
    REP(i,cnt){
        if(exist[abs(val[i])]){
            if(st.empty())continue;
            if(-st.top()==val[i]){
                //cout<<val[i]<<endl;
                st.pop();
                exist[abs(val[i])]=0;
            }
            else {
                cout<<"NO"<<endl;return 0;
            }
        }
        else {
            //cout<<val[i]<<endl;
            exist[abs(val[i])]=1;
            st.push(val[i]);
        }
    }
    REP(i,cnt){
        if(exist[abs(val[i])]){
            if(st.empty())continue;
            if(-st.top()==val[i]){
                //cout<<val[i]<<endl;
                st.pop();
                exist[abs(val[i])]=0;
            }
            else {
                cout<<"NO"<<endl;return 0;
            }
        }
        else {
            //cout<<val[i]<<endl;
            exist[abs(val[i])]=1;
            st.push(val[i]);
        }
    }
    cout<<"YES"<<endl;
    
    return 0;
}


Measured memory_bytes: 16880
// Problem : D - Anything Goes to Zero
// Contest : AtCoder - AIsing Programming Contest 2020
// URL : https://atcoder.jp/contests/aising2020/tasks/aising2020_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) begin(x),end(x)
#define setbits(x)  __builtin_popcount(x)
int mod = 1e9+7;
//int inf = 4e18;
const int N = 5e5+5;
int pwrTwo[N];
int getMod(string str, int n, int k) 
{ 

	// pwrTwo[i] will store ((2^i) % k) 
	int pwrTwo[n]; 
	pwrTwo[0] = 1 % k; 
	for (int i = 1; i < n; i++) 
	{ 
		pwrTwo[i] = pwrTwo[i - 1] * (2 % k); 
		pwrTwo[i] %= k; 
	} 

	// To store the result 
	int res = 0; 
	int i = 0, j = n - 1; 
	while (i < n) 
	{ 

		// If current bit is 1 
		if (str[j] == '1') 
		{ 

			// Add the current power of 2 
			res += (pwrTwo[i]); 
			res %= k; 
		} 
		i++; 
		j--; 
	} 
	return res; 
}
int help(int n)
{
	int ct = 0;
	while(n!=0)
	{
		int xxx = setbits(n);
		n = n%xxx;
		++ct;
	}
	return ct;
}		
signed main()
{
    io
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {
		int n;
		cin>>n;
		string s;
		cin>>s;
		int ct  = 0;
		for(int i=0;i<n;++i)
		{
			if(s[i]=='1')
			++ct;
		}
		int pwrmore[n],pwrless[n];
		pwrmore[0] = 1%(ct+1);
		if(ct!=1)
		pwrless[0] = 1%(ct-1);
		for(int i=1;i<n;++i)
		{
			pwrmore[i] = pwrmore[i-1]*(2%(ct+1));
			pwrmore[i]%=(ct+1);
		}
		if(ct!=1)
		for(int i=1;i<n;++i)
		{
			pwrless[i] = pwrless[i-1]*(2%(ct-1));
			pwrless[i]%=(ct-1);
		}
		int more = getMod(s,n,ct+1);
		int less = 0;
		if(ct!=1)
		 less = getMod(s,n,ct-1);
		//cout<<more<<" "<<less<<"\n";
		for(int i=0;i<n;++i)
		{
			if(s[i]=='1')
			{
				if(ct==1)
				{
					cout<<0<<"\n";
					continue;
				}
				else
				{
					int xxx = (less+ct-1-pwrless[n-1-i])%(ct-1);
					cout<<help(xxx)+1<<"\n";
				}	
			}
			else // '0'
			{
				int xxx = (more+pwrmore[n-1-i])%(ct+1);
				cout<<help(xxx)+1<<"\n";
			}
		}
    }
    return 0;
}


Measured memory_bytes: 6104
import java.util.*;

public class Main {
    Scanner sc = new Scanner(System.in);
    int N = 0;
    int [] a;
    int [] mask;
    long [][] dp;
    final long INF = 1L << 50;
    void doIt() {
	N = sc.nextInt();
	int M = sc.nextInt();
	a = new int[M];
	mask = new int[M];
	for(int i = 0; i < M; i++) {
	    a[i] = sc.nextInt();
	    int b = sc.nextInt();
	    int v = 0;
	    for(int j = 0; j < b; j++) {
		int c = sc.nextInt() - 1;
		v |= (1<<c);
	    }
	    mask[i] = v;
	}
	dp = new long[M+1][1<<N];
	for(int i = 0; i < dp.length; i++) {
	    for(int j = 0; j < dp[0].length; j++) {
		dp[i][j] = INF;
	    }
	}
	dp[0][0] = 0;
	for(int i = 0; i < M; i++) {
	    for(int j = 0; j < dp[0].length; j++) {
		long cv = dp[i][j];
		long nv = cv + a[i];
		int nj = j | mask[i];
		//System.out.println(i+1 + " " + j + " " + nj);
		dp[i+1][j] = Math.min(dp[i+1][j], cv);
		dp[i+1][nj] = Math.min(dp[i+1][nj], nv);
	    }
	}
	//System.out.println("Answer=");
	long ans = dp[M][(1<<N)-1];
	if(ans >= INF) ans = -1;
	System.out.println(ans);
    }
    
    public static void main(String args[]) {
	new Main().doIt();
    }
}

Measured memory_bytes: 66164
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define rep(i,a,b) for(int (i) = (a); (i) <= (b); i++)
#define repd(i,a,b) for(int (i) = (a); (i) >= (b); i--)
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); it++)
#define mp make_pair
#define pb push_back
#define countbits __builtin_popcount
using namespace std;
#define is_digit(c) ((c) >= '0' && (c) <= '9')
#define is_upper(c) ((c) >= 'A' && (c) <= 'Z')
#define is_lower(c) ((c) >= 'a' && (c) <= 'z')
#define readchar() ((char)fgetc(stdin))
#define printchar(c) fputc((c), stdout)
void readline(char *s) {int len=0;char c;for(c=readchar(); c!='\n'; s[len++]=c, c=readchar());s[len]=0;}
void readstr(char *s) {int len=0;char c;for(c=readchar(); c!=' '&&c!='\n'; s[len++]=c, c=readchar());s[len]=0;}
void printstr(const char *s) {int len=strlen(s);rep(i,0,len-1) printchar(s[i]);}
void to_lower(char *s, int L, int R) {rep(i,L,R) if (is_upper(s[i])) s[i]=s[i]-'A'+'a';}
void to_upper(char *s, int L, int R) {rep(i,L,R) if (is_lower(s[i])) s[i]=s[i]-'a'+'A';}
ll readll() {
	char c;ll ans=0, x=1;for (c=readchar(); !is_digit(c)&&c!='-'; c=readchar());
	if (c=='-') x=-1, c=readchar();for (; is_digit(c); ans=ans*10+c-'0', c=readchar());return ans*x;
}
void printll(ll x) {
	int a[25], cnt=0;if (x==0) { printchar('0'); return; }if (x<0) printchar('-'), x=-x;
	for (; x; a[cnt++]=x-x/10*10, x/=10);repd(i,cnt-1,0) printchar(a[i]+'0');
}
#define readint() ((int)readll())
#define printint(x) printll((ll)(x))
ll k,a[51];
int n;
int main() {
	k=readll();
	if (!k) {
		n=2;a[1]=a[2]=1;
	} else if (k==1) {
		n=2;a[1]=0;a[2]=2;
	} else {
		n=2;
		while (k/n>10000000000001000ll||k/n-k%n<0) n++;
		int x=k%n;
		rep(i,1,n) {
			a[i]=k/n+n-1-x;
			if (x>n-i) {
				a[i]+=n+1;
			}
		}
	}
	printint(n);printchar('\n');
	rep(i,1,n) {
		printll(a[i]);printchar(i==n?'\n':' ');
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <new>

using namespace std;

typedef long long ll;

#define rep(i, N) for (ll i = 0; i < (ll)(N); ++i)

int main(){
    ll A,B;
    string S,T,U;
    cin >> S >> T;
    cin >> A >> B;
    cin >> U;

    if(S == U){
        A--;
    }else if(T == U){
        B--;
    }

    cout << A << " " << B << endl;
    return 0;
}

Measured memory_bytes: 256
#1行目
hoge = gets.chomp.to_i - 1

#2行目読み込み
x = gets.chomp.split(" ").map!{|i | i.to_i} 
unchi = 0

for i in 0..(hoge-1) do
  sa = x[hoge - i] - x[hoge - i - 1]
   if sa < -1
    unchi = 1
    break
  elsif
    sa == -1
    x[hoge - i - 1] = x[hoge - i - 1] - 1
  end
end

if unchi > 0
  print "No"
else print "Yes"
end


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

/*  using namespace  */
using namespace std;

/*  local var  */
string s;

/*  define  */
#define loop(i,j) for(int i = 0; i < j; i++)
#define scan1(d) scanf("%lld",&d);
#define scan2(a,b) scanf("%lld %lld",&a,&b);

/*  typedef  */
//None

/*  main program  */
int main()
{
	long long ans=0;
	long long N,T;
	scan2(N,T);
	int A[200005];
	loop(i,N) cin>>A[i];
	loop(i,N-1){	
		if(A[i+1]-A[i]<T) ans+=T-abs(A[i+1]-A[i]);
	}
	cout<<N*T-ans<<endl;
}
	

Measured memory_bytes: 1024