akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,e) for(int i= 0; i< (int)(e); i++)
#define reps(i,s,e) for(int i = s; i < (int)(e); i++)
#define repr(i,s,e) for(int i = s; i > (int)(e); i--)
typedef long long ll;
long bigp = 1000000007;


int main(){
  int n,m;
  cin >> n >> m;
  vector<vector<int>> s(m);
  rep(i,m){
    int k;
    cin >> k;
    rep(j,k){
      int tmp;
      cin >> tmp;
      s[i].push_back(tmp-1);
    }
  }
  vector<int> p(m);
  rep(i,m){cin >> p[i];}
  int ans = 0;
  for (int bit = 0; bit < (1<<n); ++bit) {
    vector<int> S;
    for (int i = 0; i < n; ++i) {
      if (bit & (1<<i)) {
            S.push_back(i);
      }
    }
    string flag = "yes";
    rep(i,m){//each denkyu
      int k = s[i].size();
        int sum = 0;
      rep(j,k){//calc sum
        auto itr = find(S.begin(), S.end(), s[i][j]);
        if(itr != S.end()){
          sum += 1;
        }
      }
      if(sum%2!=p[i]){
        flag = "no";
        break;
      }
    }
    if(flag == "yes"){
      ans += 1;
    }
  }
  cout << ans;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
main()
{
	int n,l;
	while(cin>>n>>l,n)
	{
		vector<pair<int,int> >now(l,make_pair(-1,0));
		for(int i=0;i<n;i++)
		{
			char c;int m;cin>>c>>m;
			now[m].first=c=='L'?0:1;
			now[m].second=i+1;
		}
		bool flag=true;
		int cnt=1;
		while(flag)
		{
			cnt++;
			vector<pair<int,int> >nex(l,make_pair(-1,0));
			for(int i=1;i<l;i++)
			{
				if(now[i].second==0)continue;
				if(now[i].first!=1)
				{
					if(i==1)continue;
					else if(now[i-2].first<=0)
					{
						nex[i-1].first=0;
						nex[i-1].second=now[i].first==0?now[i].second:now[i].second%100;
					}
				}
				if(now[i].first!=0)
				{
					if(i==l-1)continue;
					else if(i>=l-2||now[i+2].first==1||now[i+2].first==-1)
					{
						nex[i+1].first=1;
						nex[i+1].second=now[i].first==1?now[i].second:now[i].second/100;
					}
					else
					{
						nex[i+1].first=2;
						nex[i+1].second=(now[i].first==1?now[i].second:now[i].second/100)
							+now[i+2].second%100*100;
					}
				}
			}
			now=nex;
			flag=false;
			for(int i=2;i<l-1;i++)flag|=now[i].second>0;
		}
		cout<<cnt<<" ";
		if(now[1].second>0)
		{
			cout<<now[1].second<<endl;
		}
		else
		{
			cout<<now[l-1].second<<endl;
		}
	}
}



Measured memory_bytes: 3032
fun main(args: Array<String>) {
    val (n, k) = readLine()?.split(" ")?.map(String::toInt) ?: return
    val h = readLine()?.split(" ")?.map(String::toInt) ?: return
    var count = 0L
    h.sortedDescending().drop(k).forEach {
        count += it
    }
    println(count)
}


Measured memory_bytes: 84816
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

const int N = 1000000;
int dp[N + 1], primes[N + 1];
int main(){
    fill(primes, primes + N + 1, 1);
    primes[0] = primes[1] = 0;
    for(int i = 2;i <= sqrt(N);i += 2){
        if(primes[i]){
            for(int j = i + i;j <= N;j += i){
                primes[j] = 0;
            }
        }
        if(i == 2) --i;
    }
    int n, x, a, ans;
    int ps[30];
    while(cin >> n >> x, n && x){
        fill(dp, dp + N + 1, 0);
        ans = 0;
        for(int i = 0;i < n;++i){
            cin >> a;
            ps[i] = a;
            dp[a] = 1;
        }
        for(int i = 0;i <= x;++i){
            if(dp[i]){
                for(int j = 0;j < n;++j){
                    if(i + ps[j] <= N && !dp[i + ps[j]]){
                        dp[i + ps[j]] = 1;
                    }
                }
            }
        }
        for(int i = x;i > 0;--i){
            if(dp[i] && primes[i]){
                ans = i;
                break;
            }
        }
        if(ans) cout << ans << endl;
        else cout << "NA" << endl;
    }
}

Measured memory_bytes: 8972
#include <bits/stdc++.h>
using namespace std;
using ll = long long ;
int main(){

    map<string,int> mp ;
    int n ;
    cin >> n ;
    int cont = 0 ;
    for(int i = 0; i < n; i++){
        string x ;
        cin >> x ;
        mp[x]++ ;
        cont = max(cont, mp[x]) ;
    }
    for(auto p : mp){
        if ( p.second == cont )
            cout << p.first << endl;
    }
 return 0  ;
}



Measured memory_bytes: 25216
//Date and time of submission: 
 
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll N=1e5+5;
ll a,b;
int main() {
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	cin>>a>>b;
	if(a+b>=10)
	cout<<"error";
	else
	cout<<a+b;
	return 0;
}


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

int main(){
    int n,m,r;
    cin >> n >> m >> r;
    vector<int> rs(r);
    for(int i=0; i<r; i++){
        cin >> rs[i];
    }
    vector<vector<int>> cost(n,vector<int>(n,INT_MAX));
    for(int i=0; i<m; i++){
        int a,b,c;
        cin >> a >> b >> c;
        cost[a-1][b-1] = c;
        cost[b-1][a-1] = c;
    }
    for(int i=0; i<n; i++){
        cost[i][i] = 0;
    }
    for(int k=0; k<n ;k++){
        for(int i=0; i<n; i++){
            for(int j=0; j<n; j++){
                if(cost[i][k] == INT_MAX || cost[k][j] == INT_MAX){
                    continue;
                }
                cost[i][j] = min(cost[i][j], cost[i][k]+cost[k][j]);
            }
        }
    }
    int _min = INT_MAX;
    sort(rs.begin(), rs.end());
    do{
        int sum = 0;
        for(int i=0; i<r-1; i++){
            sum += cost[rs[i]-1][rs[i+1]-1];
        }
        _min = min(_min,sum);
    }while(next_permutation(rs.begin(), rs.end()));
    cout << _min << endl;

}

Measured memory_bytes: 512
#include<cstdio>
#include<cstring>
const int N=1e5+50;
char s[N];
int len;
int main(){
    scanf("%s",s);
    len=strlen(s);
    if(s[0]!=s[len-1]){
        if(len&1)puts("First");
        else puts("Second");
    }else{
        if(len&1)puts("Second");
        else puts("First");
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;

string ans;
int n;

string changes(int n){
	stringstream ss;
	string res;
	ss << n;
	ss >> res;
	return res;
}

int main(){

	while (cin >> n&&n!=-1){
		if (n == 0){
			cout << 0 << endl;
			continue;
		}
		bool f = 0;
		if (n == -1)break;
		for (int i = 9; i >= 0; i--){
			int a = 0;
			if (n >= pow(4, i)){
				a = n / pow(4, i);
			}
			if (a != 0)f = 1;
			if (f){
				ans += changes(a);
				n -= a*pow(4, i);
			}
			//cout << n << " " << a << endl;
		}
		cout << ans << endl;
		ans.clear();
	}
}

Measured memory_bytes: 1264
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll dp[500][500];
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll N;
    cin>>N;
    ll i,a[N],b[N],j,k;
    for(i=0;i<N;i++) cin>>a[i];
    b[0]=a[0];
    for(i=1;i<N;i++) { b[i]=b[i-1]+a[i]; }
    for(i=0;i<N;i++) { for(j=0;j<N;j++) dp[i][j]=1e18+5; }
    for(j=0;j<N;j++)
    {
        for(i=0;i<N-j;i++)
        {
            if(j==0) dp[i][i+j]=0;
            else if(j==1) { if(i+j<N) dp[i][i+j]=a[i]+a[i+1]; }
            else
            {
                for(k=0;k<i+j;k++)
                {
                    if(i+k<i+j)
                    {
                        if(i>=1) dp[i][i+j]=min(dp[i][i+j],dp[i][i+k]+dp[i+k+1][i+j]+b[i+j]-b[i-1]);
                        else dp[i][i+j]=min(dp[i][i+j],dp[i][i+k]+dp[i+k+1][i+j]+b[i+j]);
                    }
                }
            }
        }
    }
    cout<<dp[0][N-1]<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
#define N 100

int main(){
  int i,j,n,tmp,count=0;
  int a[N];
  
  scanf("%d",&n);
  for( i=0 ; i<n ; i++ ){
    scanf("%d",&a[i]);
  }

  for( i=n-1 ; i>=1 ; i-- ){
    for( j=n-1 ; j>=1 ; j-- ){
      if(a[j] < a[j-1]){
	tmp = a[j];
	a[j] = a[j-1];
	a[j-1] = tmp;
	count++;
      }
    }
  }
  
  for( i=0 ; i<n ; i++ ){
    if( i == n-1 ){
      printf("%d\n",a[i]);
    }
    else{
      printf("%d ",a[i]);
    }
  }
  
  printf("%d\n",count);
  

return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <string>
#include <cmath>
#include <map>
#include <iomanip>
#include <tuple>
#define INF 1000000009
#define LINF 1000000000000000009
#define double long double
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
//ll mod = 1000000007;
//ll mod = 998244353;

int main() {
	ll n, a, b;
	cin >> n >> a >> b;
	n %= 12;
	for (int i = 0; i < n; i++) {
		if (i % 2 == 0) {
			a = a - b;
		}
		else {
			b = a + b;
		}
	}
	cout << a << ' ' << b << endl;
}


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

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int r, g, b, num;
  cin >> r >> g >> b;
  num = 100 * r + 10 * g + b;
  if (num % 4 == 0) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
  return 0;
}


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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define per(i, a, b) for(int i = (b)-1; i >= (a); --i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pii> vii;

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);

  int n, m;
  cin >> n >> m;

  vector<pair<pii, int>> ver, hor;
  vector<int> xs, ys;
  xs.pb(-1.1e9); xs.pb(0); xs.pb(1.1e9);
  ys.pb(-1.1e9); ys.pb(0); ys.pb(1.1e9);

  rep(i,0,n) {
    int a, b, c;
    cin >> a >> b >> c;
    ver.eb(mp(a,b), c);
    ys.pb(a);
    ys.pb(b);
    xs.pb(c);
  }

  rep(i,0,m) {
    int a, b, c;
    cin >> a >> b >> c;
    hor.eb(mp(b,c), a);
    xs.pb(b);
    xs.pb(c);
    ys.pb(a);
  }

  auto xpos = [&](int x) -> int {
    return lower_bound(all(xs), x) - xs.begin();
  };

  auto ypos = [&](int y) -> int {
    return lower_bound(all(ys), y) - ys.begin();
  };

  sort(all(xs));
  sort(all(ys));
  xs.resize(unique(all(xs))-xs.begin());
  ys.resize(unique(all(ys))-ys.begin());

  n = sz(ys);
  m = sz(xs);

  vvi mat(n, vi(m));

  int di[4] = {0, -1, 0, 1};
  int dj[4] = {1, 0, -1, 0};

  rep(i,0,sz(ver)) {
    auto [y1, y2] = ver[i].fst;
    int x = ver[i].snd;
    y1 = ypos(y1);
    y2 = ypos(y2);
    x = xpos(x);
    rep(i,y1,y2) {
      mat[i][x] |= 1<<2;
      mat[i][x-1] |= 1<<0;
    }
  }

  rep(i,0,sz(hor)) {
    auto [x1, x2] = hor[i].fst;
    int y = hor[i].snd;
    x1 = xpos(x1);
    x2 = xpos(x2);
    y = ypos(y);
    rep(i,x1,x2) {
      mat[y][i] |= 1<<1;
      mat[y-1][i] |= 1<<3;
    }
  }

#define in(i,j) ((i) >= 0 and (i) < n and (j) >= 0 and (j) < m)

  queue<pii> q;
  vector<bitset<4123>> vis(n);
  int x0 = xpos(0), y0 = ypos(0);
  q.emplace(y0, x0); q.emplace(y0-1, x0); q.emplace(y0, x0-1); q.emplace(y0-1, x0-1);
  vis[y0][x0] = 1; vis[y0-1][x0] = 1; vis[y0][x0-1] = 1; vis[y0-1][x0-1] = 1;

  while (not q.empty()) {
    auto [i, j] = q.front(); q.pop();
    rep(k,0,4) {
      if (mat[i][j]&(1<<k)) continue;
      int ni = i+di[k], nj = j+dj[k];
      if (not in(ni,nj)) continue;
      if (vis[ni][nj]) continue;
      vis[ni][nj] = 1;
      q.emplace(ni, nj);
    }
  }

  rep(i,0,n) {
    if (vis[i][0] or vis[i][m-1]) {
      cout << "INF\n";
      return 0;
    }
  }

  rep(i,0,m) {
    if (vis[0][i] or vis[n-1][i]) {
      cout << "INF\n";
      return 0;
    }
  }

  ll ans = 0;
  rep(i,0,n) rep(j,0,m) if (vis[i][j]) {
    ans += ll(xs[j+1] - xs[j]) * ll(ys[i+1] - ys[i]);
  }
  cout << ans << '\n';

}

Measured memory_bytes: 40148
#!/usr/bin/env python3
import math


def main():
    n, d = map(int, input().split())

    cnt: int = 0
    for _ in range(n):
        x, y = map(int, input().split())
        if math.sqrt(x ** 2 + y ** 2) <= d:
            cnt += 1

    print(cnt)

if __name__ == "__main__":
    main()


Measured memory_bytes: 9156
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll ;
#define rep(i, a, b) for (int i = a; i <= b; ++ i) 
const int N = 500005 ;
using namespace std ;

int n, m ;
ll A[N], a[N], B[N] ;

int main() {	
	scanf("%d%lld", &n, &A[0]) ;
	rep(i, 1, n) {
		scanf("%lld", &a[i]) ;
		A[i] = min(A[i - 1], max(a[i] - A[i - 1], A[i - 1] - a[i])) ;
	}
	B[n + 1] = 1 ;
	for (int i = n; i; -- i) {
		if (B[i + 1] <= a[i] / 2) B[i] = B[i + 1] ;
			else B[i] = B[i + 1] + a[i] ;
	}
	scanf("%d", &m) ; int x ;
	rep(i, 1, m) {
		scanf("%d", &x) ;
		if (B[x + 1] <= A[x - 1]) printf("YES\n") ; else printf("NO\n") ;
	}
	return 0 ; 
}

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

int main()
{
	int a,b,k,v,c=0;
	cin>>a>>b>>k;
	
	for(int i=a;i>0;i--){
		if(a%i==0&&b%i==0) c++;
		if(c==k){
			v=i;
			break;
		}
	}
	
	cout<<v<<endl;
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  long long mi=1000000000000000000;
  long long sum=0;
  for(int i=0;i<n;i++){
    cin >> a[i];
    sum+=a[i];
  }
  long long x=0;
  for(int i=0;i<n-1;i++){
    x+=a[i];
    sum-=a[i];
    long long sa=x-sum;
    if(sa<0)sa*=-1;
    mi=min(sa,mi);
  }
  cout << mi << endl;
  return 0;
    
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

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

	cout << min(a * n, b) << endl;
}


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

using namespace std;

#define debug(args...) fprintf(stderr,args)
#define pb push_back
#define mp make_pair

const int N = 5e6 + 5;
const int inf = 1791791791;
const int mod = 1e9+7;

typedef long long ll;

int main() {
	string s; cin >> s;
	int n = s.size();
	long long resp = 0;
	for (int i=0;i<n;i++) {
		for (int j=i;j<n;j++) {
			ll v = 0;
			for (int k=i;k<=j;k++) {
				v *= 10;
				v += (s[k] - '0');
			}
			int kl = max(0, i-1);
			int kr = max(0, n-j-2);
			debug("number = %lld, %d %d\n", v, kl, kr);
			resp += v * (1ll << kl) * (1ll << kr);
		}
	}
	printf("%lld\n", resp);
    return 0;
}


Measured memory_bytes: 256
def main():
    N, Q = map(int, input().split())
    S = input()
    S_sum = [0] * (N+1)
    for i in range(N):
        S_sum[i+1] = S_sum[i] + (1 if S[i:i+2] == 'AC' else 0)

    for _ in range(Q):
        l, r = map(int, input().split())
        print(S_sum[r-1]-S_sum[l-1])


main()

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

using namespace std;

int main() {
	string s,t;
	cin>>s>>t;
	for(int i=s.length()-t.length();i>=0;--i){
		string y=s.substr(i,t.length());
		bool flag=false;
		for(int j=0;j<t.length();++j){
			if(y[j]!=t[j] && y[j]!='?'){
				flag=true;
				break;
			}
		}
		if(flag)continue;
		if(1){
			string ans=s.substr(0,i)+t+s.substr(i+t.length());
			for(auto x:ans){
				if(x=='?')printf("%c",'a');
				else printf("%c",x);
			}
			printf("\n");
			return 0;
		}
	}
	cout<<"UNRESTORABLE"<<endl;
}

Measured memory_bytes: 256
//
//  main.cpp
//  vjudge
//
//  Created by Sudipto Mondal on 7/9/20.
//  Copyright © 2020 Sudipto Mondal. All rights reserved.
//

#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
    long long int a,b;
    cin>>a>>b;
    
    if(a==b){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}


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

int main( ){

    string s ;

    cin >> s ;

    int ans = 0 ;

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

        ans += s[i] - '0' ;

    }

    if( ans % 9 == 0 ){

        cout << "Yes" << endl ;

    }else{

        cout << "No" << endl ;

    }

}


Measured memory_bytes: 3688
import sys
input = sys.stdin.readline

H, W = map(int, input().split())
s = [input() for _ in range(H)]
dp = [[float('inf')] * W for _ in range(H)]
dp[0][0] = 1 if s[0][0] == '#' else 0
for i in range(H):
    for j in range(W):
        if i > 0:
            if s[i-1][j] == '.' and s[i][j] == '#':
                dp[i][j] = dp[i-1][j] + 1
            else:
                dp[i][j] = dp[i-1][j]
        if j > 0:
            if s[i][j-1] == '.' and s[i][j] == '#':
                dp[i][j] = min(dp[i][j], dp[i][j-1] + 1)
            else:
                dp[i][j] = min(dp[i][j], dp[i][j-1])
print(dp[-1][-1])

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

void dfs(int c, int h, int w, int k, const vector<vector<char>>& s, vector<int>& hs, vector<int>& ws, int& ans) {
  if (c == h + w) {
    int sum(0);
    for (int i = 0; i < h; ++i)
      for (int j = 0; j < w; ++j) {
        if (hs[i] || ws[j]) continue;
        sum += (s[i][j] == '#');
      }
    if (sum == k) ans++;
    return;
  }
  if (c < h) {
    //for (int i = c; i < h; ++i) {
    dfs(c + 1, h, w, k, s, hs, ws, ans);
    hs[c] = 1;
    dfs(c + 1, h, w, k, s, hs, ws, ans);
    hs[c] = 0;
    //}
  } else {
    dfs(c + 1, h, w, k, s, hs, ws, ans);
    ws[c - h] = 1;
    dfs(c + 1, h, w, k, s, hs, ws, ans);
    ws[c - h] = 0;
  }
}
int main() {
  int h, w, k, ans(0);
  cin >> h >> w >> k;
  //char s[h][w];
  vector<vector<char>> s(h, vector<char>(w));
  vector<int> hs(h), ws(w);
  for (int i = 0; i < h; ++i)
    for (int j = 0; j < w; ++j)
      cin >> s[i][j];
  dfs(0, h, w, k, s, hs, ws, ans);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N = n()
P = nl()

count = 0
for i in range(1, N-1):
    if P[i-1] <= P[i] and P[i] <= P[i+1]:
        count += 1
    elif P[i-1] >= P[i] and P[i] >= P[i+1]:
        count += 1

print(count)


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

using namespace std;

int main(){

    string s, t;

    cin >> s >> t;

    int len1 = s.size(), len2 = t.size(), i, j;

    int dp[len1 + 1][len2 + 1];

    for(i = 0; i <= len1; i++){

        for(j = 0; j <= len2; j++){

            if(i == 0 || j == 0){

                dp[i][j] = 0;
            }
            else if(s[i - 1] == t[j - 1]){

                dp[i][j] = dp[i - 1][j - 1] + 1;
            }
            else{

                dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]);
            }
        }
    }
    int len = dp[len1][len2];

    string lcs;

    i = len1, j = len2;

    int k = 0;

    while(i > 0 && j > 0){

        if(s[i - 1] == t[j - 1]){

            lcs.push_back(s[i - 1]);

            k++, i--, j--;
        }
        else if(dp[i - 1][j] > dp[i][j - 1]){

            i--;
        }
        else{

            j--;
        }
        if(k == len){

            break;
        }
    }
    for(i = len - 1; i >= 0; i--){

        cout << lcs[i];
    }

    return 0;
}

Measured memory_bytes: 35456
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
using namespace std; 
#define pb push_back 
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define rep2(i,a,b) for(int i=a;i>=b;i--)
#define ll long long
#define sc(x) scanf("%lld",&x)
#define sd(x) scanf("%lf",&x)


ll sum[100005],a[100005];

int main(int argc, char** argv) {
	ll n;
	sc(n);
	rep(i,0,n)
	sc(a[i]);
	rep2(i,n,0)
	{
		sum[i]=sum[i+1]+a[i];
	}
	ll lst=1;
	if(n==0&&a[0]==1)
	{
		cout<<1;
		exit(0);
	}
	if(a[0]!=0)
	{
		puts("-1");
		exit(0);
	}
	ll ans=1;
	rep(i,1,n)
	{
		ll mx;
		if(lst*2<a[i])
		{
			puts("-1");
			return 0;
		}
		mx=lst*2-a[i];
		mx=min(mx,sum[i+1]);
		//cout<<mx<<endl;
		ans+=mx+a[i];
		lst=mx;
	}
	cout<<ans;
	return 0;
}



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

using namespace std;



int main()
{
	int len, q, num[100010], cnt = 0;
	cin >> len >> q;
	string ss;
	cin >> ss;
	memset(num, 0, sizeof(int)*len);
	for (int i = 1; i <= len; i++)
	{
		num[i] = cnt;
		if (ss[i - 1] == 'A' && ss[i] == 'C' && i < len)
			cnt++;
	}
	while (q--)
	{
		int a, b;
		cin >> a >> b;
		cout << num[b] - num[a] << endl;
	}
}

Measured memory_bytes: 1408
#include <stdio.h>

int main() {
	int n, key, j;

	scanf("%d", &n);

	int arr[n];

	for (int i=0; i<n; i++) {
		scanf("%d", &arr[i]);
	}

	printf("%d", arr[0]);
	for (int x=1; x<n; x++) {
		printf(" %d", arr[x]);
	}
	printf("\n");

	for (int i=1; i<=n-1;i++) {
		key = arr[i];
		j = i - 1;
		while (j >= 0 && arr[j] > key) {
			arr[j+1] = arr[j];
			j--;
		}
		arr[j+1] = key;

		printf("%d", arr[0]);
		for (int x=1; x<n; x++) {
			printf(" %d", arr[x]);
		}
		printf("\n");
	}
}



Measured memory_bytes: 2712
#include <bits/stdc++.h>
//#include <atcoder/all>
#define ll long long int
#define MOD 1000000007
#define P pair<ll,ll>
#define INF 1000000000000000000

//using namespace atcoder;
using namespace std;

int main(void){
  ll x, y;
  cin >> x >> y;
  
  if (y % 2 == 1)
    cout << "No" << endl;
  else {
    if (y - 2*x >= 0 && 2*x - y/2 >= 0)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 3580
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;
    cin >> n >> m;
    if(n%2==0){
        n--;
    }
    ll sum = 1+((n+1)/4)*2;
    ll l = 1;
    ll cnt = 0;
    while(cnt<m&&l<sum-l){
        cout << l << " " << sum-l << endl;
        l++;
        cnt++;
    }
    if(cnt<m){
        m-=cnt;
        cnt=0;
        REP(i,m){
            cout << sum+i << " " << n-i << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 3656
#include <stdio.h>
#include <string.h>
#define NMAX 100000

int ufpar[NMAX], ufw[NMAX];

int UF_find(int);
int UF_weight(int);
int UF_union(int, int, int);
int UF_diff(int*, int, int);
int main(void)
{
  int i, n, q, com, x, y, z, ans;
  scanf("%d %d", &n, &q);
  memset(ufpar, -1, sizeof(ufpar));
  for (i = 0; i < q; i++) {
    scanf("%d", &com);
    if (com) {
      scanf("%d %d", &x, &y);
      z = UF_diff(&ans, x, y);
      if (z) printf("%d\n", ans);
      else printf("?\n");
    } else {
      scanf("%d %d %d", &x, &y, &z);
      UF_union(x, y, z);
    }
  }
}

int UF_find(int a)
{
  int p;
  if (ufpar[a] < 0) return a;
  p = UF_find(ufpar[a]);
  ufw[a] += ufw[ufpar[a]];
  return ufpar[a] = p;
}

int UF_weight(int a)
{
  UF_find(a);
  return ufw[a];
}

int UF_union(int x, int y, int w)
{
  w -= UF_weight(x);
  w += UF_weight(y);
  x = UF_find(x);
  y = UF_find(y);
  if (x == y) return 0;
  if (ufpar[x] > ufpar[y]) {
    ufpar[y] += ufpar[x];
    ufpar[x] = y;
    ufw[x] = w;
  } else {
    ufpar[x] += ufpar[y];
    ufpar[y] = x;
    ufw[y] = -w;
  }
  return 1;
}

int UF_diff(int *ans, int x, int y)
{
  if (UF_find(x) != UF_find(y)) return 0;
  else {
    *ans = ufw[x] - ufw[y];
    return 1;
  }
}


Measured memory_bytes: 2576
#include<stdio.h>
#include<string.h>
int main(void)
{
int i,sum=0;
char x[1002];
scanf("%s",x);
do{

for (i=0; i<1002;i++){
if(!x[i]){
printf("%d\n",sum);
break;
}else{
sum+=x[i]-0x30;
}
}
sum=0;
scanf("%s",x);
}while(x[0]-0x30);

return 0;
}

Measured memory_bytes: 536
from operator import itemgetter


class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0] * n
        self.size = [1] * n

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
    
    def same(self, x, y):
        if self.find(x) == self.find(y):
            return True
        else:
            return False


def kruskal(n, edges):
    uf = UnionFind(n)
    edges.sort()
    res = 0
    for d, s, t in edges:
        if not uf.same(s, t):
            uf.unite(s, t)
            res += d
    return res

n = int(input())

xy = [[i] + list(map(int, input().split())) for i in range(n)] 

edges = set()
for key in [itemgetter(1), itemgetter(2)]:
    xy.sort(key = key)
    for i in range(n-1):
        i1, x1, y1 = xy[i]
        i2, x2, y2 = xy[i+1]
        d = min(abs(x1 - x2), abs(y1 - y2))
        edges.add((d, i1, i2))

edges = list(edges)
print(kruskal(n, edges))


Measured memory_bytes: 55016
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
#define loop(i,N) for(ll (i)=0; (i)<(N);++(i))
struct _OMAZINAI_ { _OMAZINAI_() { std::ios::sync_with_stdio(false); std::cin.tie(0); } } __omazinai_instance__;
#define INF ((1LL<<61) + (1<<29))
#define YesNo(x) {std::cout << ((x)?"Yes":"No") << std::endl;}
#define YESNO(x) {std::cout << ((x)?"YES":"NO") << std::endl;}
#define OddEven(x) {std::cout << ((x)%2?"Odd":"Even") << std::endl;}
#define ODDEVEN(x) {std::cout << ((x)%2?"ODD":"EVEN") << std::endl;}
typedef long long int ll;
void _INPUT_IMPL_() {};
template <class T, class... Args> void _INPUT_IMPL_(T& dest, Args&... args) { cin >> dest; _INPUT_IMPL_(args...); }
void _OUTPUT_IMPL_() {};
template <class T, class... Args> void _OUTPUT_IMPL_(T dest, Args... args) { cout<< dest << (sizeof...(Args)?" ":""); _OUTPUT_IMPL_(args...); }
#define in(type, ...) type __VA_ARGS__; _INPUT_IMPL_(__VA_ARGS__)
#define in_v(type, name, cnt) vector<type> name(cnt); loop(i, cnt) cin >> name[i];
#define sort_v(v) std::sort(v.begin(), v.end())
#define out(...) (_OUTPUT_IMPL_(__VA_ARGS__), std::cout<<std::endl)
//小さい方に寄る
#define space_op(x, y, a, b, c) ([](auto x_, auto y_, auto a_, auto b_, auto c_){if(x_<y_)return a_;if(x_>y_)return c_;return b_;}(x,y,a,b,c))
#define space_out(x, y, a, b, c) out(space_op(x, y, a, b, c))

int main() {
	int cnt = 0, N, a, b = -1;
	cin >> N;
	loop(i, N){
		cin >> a;
		if(b>0&&a==b){
			a = -1;
			++cnt;
		}
		b = a;
	}
	out(cnt);
}


Measured memory_bytes: 384
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size,n=1,init=nil) #nに配列の次元数、sizeに配列の大きさ、initに初期値を投げることでその配列を返す
  if n==1
    return Array.new(size){init}
  else
    return Array.new(n).map{Array.new(size){init}}
  end
end

while true
  n,x=get_i
  break if n.zero? and x.zero?
  ans=0
  for i in 1..n
    (i+1).upto(n) do|j|
      next if i==j
      ans+=1 if x-(i+j)>j and x-(i+j)<=n
    end
  end
  puts ans
end


Measured memory_bytes: 6884
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int N, M, Q;
    cin >> N >> M >> Q;
    vector<int> L(M), R(M);
    rep(i, M) { cin >> L[i] >> R[i]; }

    vector<vector<int>> a(N, vector<int>(N));
    rep(i, M) { a[R[i] - 1][L[i] - 1]++; }

    vector<vector<int>> s(N + 1, vector<int>(N + 1));
    rep(i, N) rep(j, N) {
        s[i + 1][j + 1] = s[i][j + 1] + s[i + 1][j] - s[i][j] + a[i][j];
    }
    rep(i, Q) {
        int p, q;
        cin >> p >> q;
        cout << s[q][N] - s[q][p - 1] << '\n';
    }
    return 0;
}

Measured memory_bytes: 4480
#include <bits/stdc++.h>
using namespace std;
string a,b;
int ans;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>a>>b;
	for (int i=0;i<a.size();++i) if (a[i]==b[i]) ++ans;
	cout<<ans;
	return 0;
}

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

#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) begin(x), end(x)
#define uniq(x) (x).erase(unique(all(x)), end(x))
#define bit(n) (1LL << (n))
#define cdiv(a, b) (((a) - 1) / (b) + 1)
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr long double PI = 3.1415926535897932384626433832795028L;
constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int N;
int a[220000];
int u[220000], v[220000];
vint G[220000];
int dp[220000];
int ans[220000];
void dfs(int cur, int par) {
    int idx = lower_bound(dp, dp + N, a[cur]) - dp;
    int tmp = dp[idx];
    dp[idx] = a[cur];
    ans[cur] = lower_bound(dp, dp + N, LLONG_MAX) - dp;
    rep(i, G[cur].size()) {
        int nxt = G[cur][i];
        if (nxt == par) { continue; }
        dfs(nxt, cur);
    }
    dp[idx] = tmp;
}
signed main() {
    cin >> N;
    rep(i, N) { cin >> a[i]; }
    rep(i, N - 1) {
        cin >> u[i] >> v[i];
        u[i]--, v[i]--;
        G[u[i]].push_back(v[i]), G[v[i]].push_back(u[i]);
    }
    fill(dp, dp + N, LLONG_MAX);
    dfs(0, -1);
    rep(i, N) { cout << ans[i] << endl; }
    return 0;

}


Measured memory_bytes: 36992
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;
ll MOD=1000000007;

int main() {
  ll n,k;
  cin>>n>>k;
  ll sum=0;
for(ll i=k;i<n+2;i++) sum+=((2*n-i+1)*i/2-(i-1)*i/2+1)%MOD;
  cout<<sum%MOD<<endl;
return 0;
}


Measured memory_bytes: 3620
#include <iostream>
using namespace std;
int C[10001]={0};
int n=0, a;
int main() 
{
	cin>>n;
	for(int i=0;i<n;i++) {
		cin>>a; C[a]++;
	}
	bool first = true;
	for(int i=0;i<10001;i++){
		for(int j=0;j<C[i];j++){
			if (first) { first=false;} else {cout<<' ';}
			cout<<i;
		}
	}
cout<<endl;
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REP(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define rep1(i,x,n) for(int (i)=(x);(i)<(int)(n);(i)++)
#define REP1(i,x,n) for(int (i)=(x);(i)<=(int)(n);(i)++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using Int = long long;
 
//INT_MAX = 2147483647;
//LLONG_MAX = 9223372036854775807;
//ULLONG_MAX = 18446744073709551615;
const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;
typedef pair<int,int> P;
typedef std::priority_queue<int> IntPrioQueue;
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue;
 
//少数点表示
//cout << std::fixed << std::setprecision(14) << 値
 
int main(){
    cin.tie( 0 ); ios::sync_with_stdio( false );
 
    string ans="";
 
    ll n,m;
    cin >> n;
    m = n;
 
    while(m>0){
        m--;
        char s = 'a'+ m%26;
        ans.push_back(s);
        m /= 26;
    }
    reverse(ans.begin(),ans.end());
    cout << ans << endl;
 
    return 0;
}

Measured memory_bytes: 3604
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = Integer.parseInt(sc.next());
		int B = Integer.parseInt(sc.next());
		sc.close();
		int cnt = 0;
		int sum = 0;
		if(B == 1) {
			System.out.println(0);
			return;
		}else {
			sum += A;
			cnt++;
			if(sum >= B) {
				System.out.println(1);
				return;
			}
			while(sum < B) {
				sum  = (sum - 1) + A;
				cnt++;
			}
			System.out.println(cnt);
		}
	}
}

Measured memory_bytes: 21844
N = int(input())

def abc114_c(s):
  if(int(s) > N):
    return 0
  if(all(s.count(c) > 0 for c in "753")):
    ans = 1
  else:
    ans = 0
  for c in "753":
    ans += abc114_c(s+c)
  return ans
print(abc114_c("0"))

Measured memory_bytes: 3064
//Nihal Mittal - nihal_47
//Strike First , Strike Hard , No Mercy !!
 
/**⠀⠀⠀⠀⠀⠀⣀⣤⣤⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣰⣿⣿⣿⣿⠿⠿⣿⣿⣿⣿⣿⣿⣿⣧⢀⠀⠀⠀⠀
⠀⠀⠀⣿⣿⣿⠋⠀⠀⠀⠀⠀⠙⠀⠙⣿⣿⣿⣷⢳⢀⠀⠀⠀
⠀⠀⣠⣿⣿⣿⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⢀
⠀⠀⣸⣿⣿⣿⠸⠀⠀⠀⠒⠒⠒⠐⠀⠀⢿⣿⣿⣿⣿⣿⠀⠀
⠀⣴⣿⣿⣿⡿⠀⠒⣋⣙⡒⢰⠀⠤⣖⠒⢾⣿⣿⣿⣿⣧⠀⠀
⢺⣿⣿⣿⣿⢀⠀⠀⠉⠉⠉⠸⠀⡇⠉⠉⠀⢿⣿⣿⣿⣄⠀⠀
⠀⠙⣿⣿⣧⢻⠀⠀⠀⠀⠀⠠⠀⠰⠀⠀⠀⣸⠸⣿⣿⠿⠰⠀
⠀⠀⠀⠹⣿⣿⣿⣷⠀⡠⠙⣲⣔⣅⢡⣰⣷⣿⣿⣿⣧⠀⠀⠀
⠀⠀⠀⣼⣿⣿⣿⣿⠀⡿⠭⠭⠭⠭⢿⠀⣿⢻⣿⣿⠃⠀⠀⠀
⠀⠀⠀⠙⠛⣿⢻⠹⣿⠐⠙⠛⠟⠉⢀⣴⡟⢿⣿⡏⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⡟⠀⠀⠻⣦⣤⣶⠾⠋⠀⠀⠁⡦⢄⢀⠀⠀⠀
⠀⠀⠀⠀⡠⠁⡇⠑⢄⠀⠀⠀⠀⠀⠀⠔⠀⠀⠁⠀⠀⠀⠉⠁
⠀⠔⠊⠁⠀⠀⣇⠀⠀⠀⠑⡤⠤⢎⠁⠀⠀⡘⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⢢⠠⠀⡠⢆⠀⠀⡠⠙⢄⠀⡸⠀
**/
#include<bits/stdc++.h>
#define ll long long
#define l long
#define mk make_pair
#define pb push_back
#define in insert
#define se second
#define fi first
#define mod 1000000007
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define all(v) (v).begin(),(v).end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define pii pair<int,int>
#define maxn 100005
using namespace std;
ll x[100][100] , y[100][100] , a[100];
signed main()
{
    fast;
    ll n,i,j,ans=0,k;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>a[i];
        for(j=1;j<=a[i];j++)
        {
            ll tx,ty;
            cin>>tx>>ty;
            x[i][j] = tx;
            y[i][j] = ty;
        }
    }
    for(i=0;i < (1<<n);i++)
    {
        bool ok = true;
        for(j=1;j<=n;j++)
        {
            if(!((i >> (j-1)) & 1)) continue;
            for(k=1;k<=a[j];k++)
            {
                if(((i >> (x[j][k]-1)) & 1)!=y[j][k]) ok = false;
            }
        }
        ll aa = __builtin_popcount(i);
        if(ok) ans = max(ans, aa);
    }
    cout<<ans;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define BUGAVOID(x) x
#define rep(...) BUGAVOID(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll;
typedef vector<int> vi; typedef vector<ll> vll; template<class T, class U>using vp = vector<pair<T, U>>;
template<class T>using vv = vector<vector<T>>; template<class T, class U>using vvp = vv<pair<T, U>>;
template<class T>vv<T> vvec(size_t n, size_t m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T>bool chmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<class T>bool chmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 28, MOD = 1e9 + 7; constexpr ll LINF = 1ll << 60; constexpr double EPS = 1e-6;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;
constexpr int dy[4] = { 0,1,0,-1 }; constexpr int dx[4] = { 1,0,-1,0 };

int H, W, N, sy, sx;
string S, T;
bool ans = true;

int main() {
    cin >> H >> W >> N >> sy >> sx >> S >> T;

    vv<int> lmt = vvec(N + 1, 4, 0);
    lmt[N][0] = W;
    lmt[N][1] = H;
    lmt[N][2] = 1;
    lmt[N][3] = 1;

    for (int i = N - 1; i >= 0; --i) {
        rep(d, 4) lmt[i] = lmt[i + 1];

        if (T[i] == 'L') lmt[i][0] = min(W, lmt[i + 1][0] + 1);
        else if (T[i] == 'R') lmt[i][2] = max(1, lmt[i + 1][2] - 1);
        else if (T[i] == 'D') lmt[i][3] = max(1, lmt[i + 1][3] - 1);
        else lmt[i][1] = min(H, lmt[i + 1][1] + 1);

        if (S[i] == 'R') lmt[i][0]--;
        else if (S[i] == 'L') lmt[i][2]++;
        else if (S[i] == 'U') lmt[i][3]++;
        else lmt[i][1]--;

        if (lmt[i][0] < lmt[i][2] || lmt[i][1] < lmt[i][3]) ans = false;
    }

    if (ans) {
        ans = !(sy < lmt[0][3] || lmt[0][1] < sy || sx < lmt[0][2] || lmt[0][0] < sx);
    }

    write(ans ? "YES" : "NO");
}

Measured memory_bytes: 11544
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
using namespace std;

char s[100001];
char ans[100001];

const char circle = 'o';
const char ex = 'x';

const char S = 'S';
const char W = 'W';

const char *NONE = "-1";
const char yz = '\0';

int N;

void set()
{
    for (int i = 1; i < N - 1; i++)
    {
        if (ans[i] == S && s[i] == circle)
        {
            ans[i + 1] = ans[i - 1];
        }
        else if (ans[i] == S && s[i] == ex)
        {
            ans[i + 1] = ans[i - 1] == S ? W : S;
        }
        else if (ans[i] == W && s[i] == circle)
        {
            ans[i + 1] = ans[i - 1] == S ? W : S;
        }
        else
        {
            ans[i + 1] = ans[i - 1];
        }
    }
}

bool out()
{
    bool flg = false;
    if (s[N - 1] == circle
        && ans[N - 1] == S
        && ans[N - 2] == ans[0])
    {
        flg = !flg;
    }
    else if (s[N - 1] == circle
        && ans[N - 1] == W
        && ans[N - 2] != ans[0])
    {
        flg = !flg;
    }
    else if (s[N - 1] == ex
        && ans[N - 1] == S
        && ans[N - 2] != ans[0])
    {
        flg = !flg;
    }
    else if (s[N - 1] == ex
        && ans[N - 1] == W
        && ans[N - 2] == ans[0])
    {
        flg = !flg;
    }

    // 偽
    if (!flg) return flg;

    ans[N] = yz;
    if (s[0] == circle
        && ans[0] == S
        && ans[N - 1] == ans[1])
    {
        printf("%s\n", ans);
    }
    else if (s[0] == circle
        && ans[0] == W
        && ans[N - 1] != ans[1])
    {
        printf("%s\n", ans);
    }
    else if (s[0] == ex
        && ans[0] == S
        && ans[N - 1] != ans[1])
    {
        printf("%s\n", ans);
    }
    else if (s[0] == ex
        && ans[0] == W
        && ans[N - 1] == ans[1])
    {
        printf("%s\n", ans);
    }
    else
    {
        // 偽
        flg = !flg;
    }

    return flg;
}

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

    if (scanf("%s", s) < 1) return 0;

    ans[0] = S;
    ans[1] = S;

    set();
    if (out()) return 0;

    ans[0] = S;
    ans[1] = W;

    set();
    if (out()) return 0;

    ans[0] = W;
    ans[1] = S;

    set();
    if (out()) return 0;

    ans[0] = W;
    ans[1] = W;

    set();
    if (out()) return 0;

    printf("%s\n", NONE);
    return 0;
}


Measured memory_bytes: 512
n,m=map(int, input().split())
a=set(int(input())  for i in  range(m))
x=(10**9)+7

dp=[0]*(n+1)
dp[0]=1
if 1 not in a:
  dp[1]=1

for i in range(2,n+1):
  if i in a:
    continue
  dp[i]+=dp[i-1]+dp[i-2]
  #print(dp)
  
print(dp[-1]%x)

Measured memory_bytes: 468196
A,B,M = map(int, input().split())
a = list(map(int ,input().split()))
b = list(map(int, input().split()))
ticket = [list(map(int, input().split())) for _ in range(M)]
ans = min(a) + min(b)
for i in ticket:
  ans = min(ans, a[i[0]-1] + b[i[1]-1] - i[2])
#print(ans)
print(ans)

Measured memory_bytes: 38560
n = int(input())
ans = 0
used_s = {}
for _ in range(n):
    s = "".join(sorted(input()))
    if not s in used_s.keys():
        used_s[s] = 0
    else:
        used_s[s] += 1
        ans += 1 * used_s[s]

print(ans)

Measured memory_bytes: 17848
#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <string.h>
#include <stack>
#include <algorithm>
#include <stdio.h>
using namespace std;

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

	if (a < b && b < c)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    while (n-- > 0) {
        vector<int> cards[2];
        for (int i = 0; i < 18; i++) {
            int temp;
            cin >> temp;
            if (i < 9) {
                cards[0].push_back(temp);
            } else {
                cards[1].push_back(temp);
            }
        }
        sort(cards[0].begin(), cards[0].end());
        sort(cards[1].begin(), cards[1].end());

        int win = 0, trial = 0;
        do {
            int scores[2] = {};
            for (int i = 0; i < 9; i++) {
                if (cards[0][i] > cards[1][i]) {
                    scores[0] += cards[0][i] + cards[1][i];
                } else {
                    scores[1] += cards[0][i] + cards[1][i];
                }
                if (scores[0] > 85) {
                    win++;
                    break;
                } else if (scores[1] > 85) {
                    break;
                }
            }
            trial++;
        } while (next_permutation(cards[1].begin(), cards[1].end()));
        printf("%.5f %.5f\n", (double) win / trial, (double) (trial - win) / trial);
    }
}

Measured memory_bytes: 952
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <utility>
#include <cmath>
#include <iomanip>
#include <queue>

using namespace std;

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

int main()
{
	int n[7],a[7];
	bool flag = true;

	REP(i,7)a[i]=0;
	REP(i,6){
		cin >> n[i];
		a[n[i]]++; 
	}

	REP(i,6)if(a[i]>=3)flag = false;

	if(flag)cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
 
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input! {
        n: usize,
        p: [usize; n],
    }

    let mut count = 0;
    for i in 1..n+1 {
        if i != p[i-1] {
            count = count + 1;
        }
    }

    if count < 3 {
        println!("YES");
    } else {
        println!("NO");
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
	int n;
	int t,tmp,ans,stop,start;
	cin >> n >> t;
	vector<int> v;
	for(int i=0;i<n;i++){
		cin >> tmp;
		v.push_back(tmp);
	}
	ans=0;
	start=0;
	stop=t;
	for(int i=0;i<n;i++){
		if(stop >= v[i]){
			if(i==(n-1)){
				stop = v[i]+t;
				ans += stop-start;
			}else{
				stop = v[i]+t;
			}
		}else{
			ans += stop-start;
			start = v[i];
			stop = v[i]+t;
			if(i==(n-1)){
				ans +=t;
			}
		}
	}
	cout << ans <<endl;
	return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int,int>;
using Graph = vector<vector<int>>;
#define rep(i,n) for(ll i = 0; i < (ll)(n); ++i)
 
constexpr double PI = acos(-1);
int alre[1000000];
int main() {
    ll n,k;
    cin >> n >> k;
    vector<int> g(n+1,0);
    int a;
    rep(i,n) {
        cin >> a;
        g.at(i+1) = a;
    }
    vector<int> log;
    int nowPos;
    nowPos = 1;
    log.emplace_back(1);
    ll s,e,flag,loop;
    s = e = flag = loop = 0;
    rep(i,k+1) {
        int ii = i + 1;
        nowPos = g.at(nowPos);
        log.emplace_back(nowPos);
        if(flag == 0 && alre[nowPos]) {
            s = ii;
            flag++;
        } else if(flag == 1 && log.at(ii)==log.at(s)) {
            flag++;
            e = ii;
            loop = (k-s)%(e-s);
            break;
        }
        alre[nowPos]=1;
    }
    if(loop==0 && flag<2) {
        cout << log.at(k) << "\n";
        return 0;
    }
    nowPos = log.at(s+loop);
    cout << nowPos << "\n";
    return 0;
}

Measured memory_bytes: 6680
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const int INF = 0x3f3f3f3f;
const int maxn = 2e5 + 9;
inline int read()
{
    int data = 0, f = 1;
    char ch = getchar();
    while (!isdigit(ch))
    {
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while (isdigit(ch))
    {
        data = (data << 3) + (data << 1) + ch - '0';
        ch = getchar();
    }
    return f * data;
}
int h[maxn], ans[maxn];
int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("data.txt","w",stdout);
    //std::ios::sync_with_stdio(false);
    //std::cin.tie(0);
    int n = read();
    for (int i = 1; i <= n; ++i)
        h[i] = read();
    ans[2] = abs(h[2] - h[1]);
    for (int i = 3; i <= n; ++i)
        ans[i] = min(ans[i - 1] + abs(h[i] - h[i - 1]), ans[i - 2] + abs(h[i] - h[i - 2]));
    printf("%d\n", ans[n]);
    //fclose(stdin);
    //fclose(stdout);
    return 0;
}

Measured memory_bytes: 4536