akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long INF = 100000000000;
typedef pair<int,int> P;
typedef long long ll;


/*
*/

int main() {
  int N,W;
  cin >> N >> W;
  vector<ll> w(N);
  vector<ll> v(N);
  rep(i,N){
    cin >> w[i];
    cin >> v[i];
  }

  vector<vector<ll>> dp(N+3, vector<ll>(W+10));
  for(int i = 0;i<N;i++){
   for(int j = 0;j<=W;j++){
     dp[i+1][j] = dp[i][j];
     if(j>=w[i]) dp[i+1][j] = max(dp[i+1][j],dp[i][j-w[i]] + v[i]);
   }
  }
  cout << dp[N][W] << endl;
}

Measured memory_bytes: 81792
x1,y1,x2,y2 = list(map(int,input().split()))

x4=x1-(y2-y1)
y4=y1+(x2-x1)
x3=x2+x4-x1
y3=y2+y4-y1

print("{} {} {} {}".format(x3,y3,x4,y4))

Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <limits.h>
#include <float.h>
#include <numeric>
#include <queue>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

#define fs first
#define sc second

map<char, char> m1;
map<char, char> m2;

int main(){
    string s1, s2;
    cin >> s1;
    cin >> s2;

    int len = s1.length();

    for(int i = 0; i < len; i++){
        if(m1.find(s1[i]) == m1.end() && m2.find(s2[i]) == m2.end()){
            m1[s1[i]] = s2[i];
            m2[s2[i]] = s1[i];
        }
        else if(m1.find(s1[i]) == m1.end() && m2.find(s2[i]) != m2.end()){
            cout << "No" << endl;
            return 0;
        }
        else if(m1.find(s1[i]) != m1.end() && m2.find(s2[i]) == m2.end()){
            cout << "No" << endl;
            return 0;
        }
        else if(m1[s1[i]] == s2[i] && m2[s2[i]] == s1[i]){
            continue;
        }
        else {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 776
Ns,Ms,=input().split()
N=int(Ns)
K=int(Ms)
A=[]
B=[]
for i in range(K):
    d=input().split()
    A.append(list(map(int,input().split())))

for i in A:
    for j in i:
        B.append(j)
print(N-len(set(B)))

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

#define reps(i, n, m) for (int i = (int) (n); i < (int) (m); i++)
#define rep(i, n) reps(i, 0, (n))
#define all(v) (v).begin(), (v).end()

int main() {
    int n; cin >> n;
    int a = 0;
    {
        int k; cin >> k;
        rep(i, k) {
            int x; cin >> x;
            a |= 1 << x;
        }
    }
    reps(b, a, 1 << n) {
        if ((a & b) == a) {
            cout << b << ":";
            rep(i, n) {
                if ((b >> i) & 1) cout << " " << i;
            }
            cout << endl;
        } 
    }
}


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

int a, b;
int main () {
	cin >> a >> b;
	if (a == b){
		cout << "Draw" << endl;
	}
	else if (a == 1){
		cout << "Alice" << endl;
	}
	else if (b == 1){
		cout << "Bob" << endl;
	}
	else if (a < b){
		cout << "Bob" << endl;
	}
	else if (a > b){
		cout << "Alice" << endl;
	}
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ri register
#define int long long
#define E (n+1)
using namespace std; const int N=200010;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
int n,H,book[N];
struct Node
{
    int a,b,id;
}q[N];
inline bool cp(Node x,Node y) { return x.a==y.a?x.b<y.b:x.a>y.a; }
inline bool cp1(Node x,Node y) { return x.b>y.b; }
signed main()
{
    int res=0;
    n=read(), H=read();
    for(ri int i=1;i<=n;i++) q[i].a=read(), q[i].b=read(), q[i].id=i;
    sort(q+1,q+1+n,cp);
    book[q[1].id]=1;
    int qwq=q[1].a;
    int tt=q[1].b;
    sort(q+1,q+1+n,cp1);
    for(ri int i=1;i<=n;i++)
    {
        if(book[q[i].id]) continue;
        if(q[i].b<qwq) break;
        H-=q[i].b; res++;
        if(H<=0) { printf("%lld\n",res); return 0; }
    }
    if(qwq>=tt)
    {
        printf("%lld\n",res+(H-1)/qwq+1);
        return 0;
    }
    else
    {
        H-=tt; res++;
        if(H<=0) { printf("%lld\n",res); return 0; }
        printf("%lld\n",res+(H-1)/qwq+1);
    }
    return 0;
}

Measured memory_bytes: 6108
import java.util.Scanner;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int total = 0;
		for (int i = 0 ; i < n ; i++){
			total += i + 1;
		}
		System.out.println(total);
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <vector>


using namespace std;

int main(){
    
    int A, B;
    
    cin >> A >> B;
    
    
    if (A+B >= A-B && A+B >= A*B) {
        cout << A+B << endl;
    }else if (A-B >= A+B && A-B >= A*B) {
        cout << A-B << endl;
    }else if (A*B >= A+B && A*B >= A-B) {
        cout << A*B << endl;
    }
    
    
    
    
    return 0;
    
}


Measured memory_bytes: 256
package main

import "fmt"

func stringToRunes(s string) (runes []rune) {
	runes = make([]rune, len(s))
	for i, r := range s {
		runes[i] = r
	}
	return
}

func main() {
	var s string
	fmt.Scan(&s)
	runes := stringToRunes(s)
	cnt := 0
	for i := 0; i < len(runes); i++ {
		if runes[i] == '1' {
			cnt++
		}
	}
	fmt.Println(cnt)
}


Measured memory_bytes: 512
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;

template <class T>
using vec = vector<T>;
template <class T>
using vec2 = vector<vec<T>>;
template <class T>
using vec3 = vector<vec2<T>>;

constexpr int INF = numeric_limits<int>::max();
constexpr ll INFL = numeric_limits<ll>::max();
constexpr ll MOD = 1000000007; // 10^9+7

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

ll N;
string C;

ll solve()
{
    int l = 0;
    int r = N - 1;
    ll ret = 0;
    while (r > l)
    {
        if (C[l] == 'R')
        {
            ++l;
        }
        else if (C[r] == 'W')
        {
            --r;
        }
        else
        {
            --r;
            ++l;
            ++ret;
        }
    }

    return ret;
}

int main()
{
    cin >> N >> C;
    cout << solve() << endl;
    return 0;
}


Measured memory_bytes: 3716
class UnionFind: # simple
    def __init__(self, n):
        self.prsz = [-1] * n # parent ' size
    def find(self, v): # root
        if self.prsz[v] < 0: return v
        self.prsz[v] = self.find(self.prsz[v])
        return self.prsz[v]
    def union(self, v, u): # unite
        v = self.find(v); u = self.find(u)
        if v == u: return False
        if self.prsz[v] > self.prsz[u]: v, u = u, v # size(v) < size(u)
        self.prsz[v] += self.prsz[u]
        self.prsz[u] = v
        return True
    def size(self, v): return -self.prsz[self.find(v)]

n, m = map(int, input().split())
uf = UnionFind(n)
for _ in range(m): uf.union(*map(lambda x: int(x)-1, input().split())) # unite
ans = 0
for i in range(n): ans = max(ans, uf.size(i))
print(ans)


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

using namespace std;
map<int, int> mymap;

int arr[200000];
long long int dp[101][100001];

vector<pair<int, int>> objects;

int main(){

    int N, W, w, v;
    int V = 100000;
    objects.push_back({0, 0});
    cin >> N >> W;
    for(int i = 0; i < N; i++){

        cin >> w >> v;
        objects.push_back({w, v});

    }

    for(int i = 1; i <= V; i++)
        dp[1][i] = i == objects[1].second ? objects[1].first : 1e15;

    for(int i = 2; i <= N; i++){
        for(int j = 1; j <= V; j++){
            dp[i][j] = dp[i-1][j];
            if(j - objects[i].second >= 0)
                dp[i][j] = min(dp[i][j], dp[i-1][j-objects[i].second] + objects[i].first);
        }
    }
    int res = 0;
    for(int i = 0; i <= V; i++)  if(dp[N][i] <= W) res = max(res, i);
    cout << res << endl;
}


Measured memory_bytes: 78336
def main():
    dist = []
    import numpy as np
    from collections import deque
    n, x, y = map(int,input().split())
    g = [[] for _ in range(n)] 
    for i in range(n-1):

        g[i] += i+1,
        g[i+1] += i,
    g[x-1] += y-1,
    g[y-1] += x-1,
    a = [0]*n
    for start in range(n):
        d = [-1] * n
        d[start] = 0
        q = deque([start])
        while q:
            v = q.popleft()
            for nv in g[v]:
                if d[nv] < 0:
                    d[nv] = d[v]+1
                    q.append(nv)
        for i in d:
            a[i] += 1
    #     dist.append(d)
    # dist = np.array(dist).flatten()
    # for i in range(1,n):
    #     print(int(np.count_nonzero(dist==i)/2))
    # for i in range(1,n):
    #     print(int(a[i]/2))
    print(' '.join(str(i//2) for i in a[1:]))
main()

Measured memory_bytes: 14592
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define eps 0.000001
#define ll long long
#define INF 1e18
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define uint unsigned int

const int mod = 1000000000+7;
const int N = 10000+5;
string s;

ll dp[2][100][N];
ll pw[N];

main()
{ 
	SPEED;
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int d;
	cin >> s;
	cin >> d;
	dp[0][0][0] = 1;
	dp[1][0][0] = 1;
	for(int i = 1 ; i <=s.size(); i++)
	{
		for(int j = 0; j<d; j++)
		{
			int num = s[s.size()-i]-'0';
			for(int k = 0; k<num; k++)
			{
				dp[0][j][i] += dp[1][(j+k)%d][i-1];
			}
			dp[0][j][i] += dp[0][(j+num)%d][i-1];
			for(int k = 0; k<10; k++){
				dp[1][j][i] += dp[1][(j+k)%d][i-1];
			}
			dp[0][j][i] %= mod;
			dp[1][j][i] %= mod;
		}
	}
	cout <<(dp[0][0][s.size()]+mod-1)%mod << endl;
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

int main() {
    int N;
    cin >> N;
    vector<vector<int>> xy(N, vector<int>(2));
    rep(i,0,N) {
        cin >> xy[i][0] >> xy[i][1];
    }

    vector<int> town(N);
    rep(i,0,N) town[i] = i;
    double sum_dist = 0;
    do {
        rep(i,0,N-1) {
            double dist = sqrt(pow((double)xy[town[i]][0]-xy[town[i+1]][0],2)+pow((double)xy[town[i]][1]-xy[town[i+1]][1],2));
            sum_dist += dist;
        }
    } while (next_permutation(all(town)));

    int N_fact = 1;
    rep(i,1,N+1) N_fact *= i;

    cout << fixed << setprecision(20);
    cout << sum_dist / N_fact << endl;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <algorithm>
#define INF (1LL << 60)
using namespace std;
int n, u[3], mode, tar; long long d, x[30], y[30], ret, seg[33554432], val[14348907]; pair<long long, long long> t[2][14348907];
inline void rec(int pos, long long a, long long b) {
	if (pos == tar) {
		if (b <= 0) t[mode][u[mode]++] = make_pair(a, b);
		return;
	}
	rec(pos + 1, a + x[pos], b + y[pos]);
	rec(pos + 1, a - x[pos], b - y[pos]);
	rec(pos + 1, a, b);
}
inline long long query(int a, int b, int k, int l, int r) {
	if (r <= a || b <= l) return INF;
	if (a <= l && r <= b) return seg[k];
	long long lch = query(a, b, k << 1, l, (l + r) >> 1);
	long long rch = query(a, b, (k << 1) + 1, (l + r) >> 1, r);
	return min(lch, rch);
}
int main() {
	scanf("%d%lld", &n, &d);
	for (int i = 0; i < n; i++) scanf("%lld%lld", &x[i], &y[i]);
	mode = 0; tar = n / 2; rec(0, 0, 0);
	mode = 1; tar = n; rec(n / 2, 0, 0);
	sort(t[1], t[1] + u[1]);
	for (u[2] = 1; u[2] <= u[1]; u[2] <<= 1);
	for (int i = 0; i < u[1]; i++) val[i] = t[1][i].first;
	for (int i = 0; i < u[1]; i++) seg[i + u[2]] = t[1][i].second;
	for (int i = u[2]; i >= 1; i--) seg[i] = min(seg[2 * i], seg[2 * i + 1]);
	for (int i = 0; i < u[0]; i++) {
		int pl = lower_bound(val, val + u[1], -t[0][i].first - d) - val;
		int pr = upper_bound(val, val + u[1], -t[0][i].first + d) - val;
		long long res = query(pl, pr, 1, 0, u[2]);
		ret = max(ret, -t[0][i].second - res);
	}
	printf("%lld\n", ret);
	return 0;
}

Measured memory_bytes: 405020
n=int(input())
a=list(map(int,input().split()))
ans=1
now=a[0]
start=1

if n==1:
    print(1)
    exit()

while now==a[start]:
    start+=1
if a[0]<a[start]:#増加
    jugh=1
else:#現象
    jugh=2
#print(start,jugh)
i=start
while i<n:
    if jugh==0:
        while now==a[start]:
            start+=1
        if now<a[start]:#増加
            jugh=1
        else:#現象
            jugh=2
    if jugh==1:
        if a[i-1]>a[i]:
            jugh=0
            ans+=1
            now=a[i]
            start=i+1
            #print(a[i-1],a[i])
                
    else:
        if a[i-1]<a[i]:
            jugh=0
            ans+=1
            now=a[i]
            start=i+1
            #print(a[i-1],a[i])
            
    i+=1   

print(ans)

Measured memory_bytes: 14480
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#include<iomanip>
#include<map>
#include<queue>
#define int long long
using namespace std;

const int INF = 1e10;
const int ZERO = 0;
int N;
int answer;
int dfs(int cnt,int a,int b,int c) {
	if(cnt > N) {
		return false;
	}
	else {
		if(cnt != 0 && a != 0 && b != 0 && c != 0) {
			answer++;
		}
		dfs(cnt * 10 + 3,a + 1,b,c);
		dfs(cnt * 10 + 5,a,b + 1,c);
		dfs(cnt * 10 + 7,a,b,c + 1);
	}
}
signed main() {
	cin >> N;
	dfs(0,0,0,0);
	cout << answer << endl;
}


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

int main(){
  int n5 = 0 , n7 = 0 , tmp;
  for (int i=0;i<3;i++) {
    cin >> tmp;
    switch (tmp) {
      case 5:
        n5++;
        break;
      case 7:
        n7++;
        break;
    }
  }
  if (n5==2&&n7==1) cout << "YES";
  else cout << "NO";
  return 0;
}
    

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

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

	vector <long long> x(10000010);
	long long num = n;

	for (long long i = 2; i*i <= n; i++) {
		while (num%i == 0) {
		x.at(i)++;
		num /= i;
		}
	}
	long long d=0; bool rr=false;
	if (num!=1){ rr=true;}
	long long A[55]={};
	A[0]=0;
	A[1]=1;
	for(long long i=1; i<50; i++){
	    
	    A[i+1]=A[i]+i+1;
	}
	long long sum=0;
	for(long long i=2; i*i<=n; i++){
	    for(long long j=0; j<50; j++){
	   if(x[i]>=A[j] && x[i]<A[j+1]) sum+=j;
	}
	}
	if(rr==true){sum+=1;}
	cout<<sum<<endl;
}

Measured memory_bytes: 81404
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <bitset>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <functional>
#include <numeric>

using namespace std;

template<typename T> ostream& operator<<(ostream& os, const vector<T>& v){
    os << "{ ";
    for (auto it = v.begin(); it != v.end(); ++it)
        os << *it << (it + 1 == v.end() ? "" : ", ");
    os << " }";
    return os;
}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
#define vv(type,w,h,init) vector<vector<type>>(h,vector<type>(w,init))
typedef vector<string> vs;
typedef long long ll;
typedef unsigned uint;
typedef unsigned long ul;
typedef unsigned long long ull;

#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)
#define pb push_back
#define mp make_pair

bool check(int n, string s){
    rep(i, s.size()){
        if (s[i] == 'X') s[i] = n + '0';
    }
    auto iplus = s.find('+');
    auto ieq = s.find('=');
    vs ss(3);
    ss[0] = s.substr(0, iplus);
    ss[1] = s.substr(iplus + 1, ieq - iplus - 1);
    ss[2] = s.substr(ieq + 1);
    rep(i, 3){
        if (ss[i].size() != 1 && ss[i][0] == '0') return false;
    }

    rep(i, 3){
        reverse(all(ss[i]));
        ss[i].resize(ss[2].size(),'0');
    }
    int carry = 0;
    rep(i, ss[2].size()){
        if ((ss[0][i] + ss[1][i] - 2 * '0' + carry)%10 == ss[2][i] - '0'){
            carry = ss[0][i] + ss[1][i] - 2 * '0' + carry >= 10;
        }
        else {
            return false;
        }
    }
    return true;
}

int main(){
    string s;
    while (cin >> s){
        int ans = -1;
        rep(i, 10){
            if (check(i, s)){
                ans = i;
                break;
            }
        }
        if (ans == -1) cout << "NA";
        else cout << ans;
        cout << endl;
    }
}

Measured memory_bytes: 1200
import java.util.*;

public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    int K = sc.nextInt();
    
      if(K<=A){
    System.out.println(K);
      }else if(K<=A+B){
	System.out.println(A);
      }else if(K<A+B+C){
    System.out.println(A-(K-A-B));
      }else{
	System.out.println(A-C);	
      }
      }
}

Measured memory_bytes: 35524
#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define MOD 1000000007
#define pb push_back
#define cy cout<<"Yes\n"
#define cn cout<<"No\n"
typedef unsigned long long int ll;
int main()
{
   int n;
   cin>>n;
   int a[n];
   for(int i=0;i<n;i++)
    cin>>a[i];
   int tot=0;
   for(int i=0;i<n;i++)
    tot=a[i]^tot;
   for(int i=0;i<n;i++)
    a[i]=a[i]^tot;
   for(auto i:a)
    cout<<i<<" ";
   cout<<endl;
}


Measured memory_bytes: 4352
import sys

x = [0 for i in range(26)]
c0 = 97
for line in sys.stdin:
    for c in line.strip('\n').lower():
        if 'a' <= c and c <= 'z':
            x[ord(c)-c0] += 1

for i in range(26):
    print '%s : %d' %(chr(i + c0), x[i])

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

Measured memory_bytes: 572
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int r;
    cin >> r;
    cout << r * r << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<utility>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<math.h>
#include <map>
using namespace std;
typedef long long int ll;
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define all(u) u.begin(),u.end()
#define pl pair<ll,ll>
#define fi first
#define se second
#define inf 1000000007

ll N,X;
vector<ll> x;
vector<ll> ds;

ll gcd(ll a, ll b){
    if (a % b == 0) return b;
    else{
        ll r = a % b;
        return gcd(b,r);
    }
}

int main() {
    scanf("%lld%lld",&N,&X);
    x.push_back(X);
    rep(i,N){
        ll temp; scanf("%lld",&temp);
        x.push_back(temp);
    }
    sort(x.begin(),x.end());
    repi(i,1,x.size()){
        ds.push_back(x[i]-x[0]);
    }
    ll ans = ds[0];
    repi(i,1,ds.size()) ans = gcd(ans,ds[i]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2548
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
#define INF 1001001001
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define repX(i, n ,x) for (int i = x; i < (int)(n); ++i)
#define repBack(i, n) for (int i = n; i >= 0; --i)
#define dup(x,y) (((x)+(y)-1)/(y))

int main() {
    int N;
    string S;
    cin >> N >> S;
    vector<vector<int>> dp(N+5,vector<int>(N+5,0));
    repBack(i,N-1)repBack(j,N-1)if(S[i]==S[j])dp[i][j] = dp[i+1][j+1]+1;
    int ans = 0;
    rep(i,N){
        rep(j,N){
            if(i >= j)continue;
            ans = max(min(dp[i][j],j-i),ans);
        }
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 98304
#include <iostream>
#include <vector>
#include <string>

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

using namespace std;

typedef long long int lli;

int main () {
    int N, M, T;
    cin >> N >> M >> T;
    vector<int> v(N);
    REP (i, 0, N) cin >> v[i];
    lli sum = v[0] - M;
    REP (i, 0, N - 1) {
        if (2 * M <= v[i + 1] - v[i]) {
            sum += (v[i + 1] - v[i] - 2 * M);
        }
    }
    if (v[N - 1] + M <= T) {
        sum += (T - M - v[N - 1]);
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3092
n=gets.to_i
arr=Array.new(n){Array.new}
n.times{|i| arr[i]=gets.split.map(&:to_i)}
t=0
x=0
y=0
check=""
n.times do |i|
  move=(arr[i][1]-x).abs+(arr[i][2]-y).abs
  if move>(arr[i][0]-t).abs
    check="No"
    break
  end
  if move%2==(arr[i][0]-t)%2
    check="Yes"
    t=arr[i][0]
    x=arr[i][1]
    y=arr[i][2]
  else
    check="No"
  end
  break if check=="No"
end
puts check


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

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;

int h,w;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> h >> w;
    F0R(i,h) F0R(j,w) {
        string ss; cin >> ss;
        if (ss == "snuke") {
            cout << char('A'+j) << i+1;
            exit(0);
        }
    }
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
   string s1,s2;
   cin>>s1>>s2;
   if(s1[0]=='H'&&s2[0]=='H')
    cout<<'H'<<endl;
   else if(s1[0]=='D'&&s2[0]=='D')
    cout<<'H'<<endl;
    else
        cout<<'D'<<endl;
} 


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

def ReverseDigits(n):
    d = str()
    for i in range(5):
        d += str(n % 10)
        n = n // 10
    return(d)

ans = 0

for i in range(A, B+1):
    if str(i) == ReverseDigits(i):
        ans += 1
    else:
        pass

print(ans)

Measured memory_bytes: 3060
import os, sys, re, math

def dorow(N):
    cnt = 0
    for i in range(1, N+1):
        if N % i == 0:
            cnt += 1
    return cnt

H,W = map(int,input().split(' '))
table = []
for h in range(H):
    tmp = input()
    if tmp != '.' * W:
        table.append(tmp)

ret = ['' for _ in range(len(table))]

for i in range(W):
    flg = False
    for j in range(len(table)):
        if table[j][i] == '#':
            flg = True
            break

    if flg:
        for j in range(len(table)):
            ret[j] += table[j][i]

for r in ret:
    print(r)


Measured memory_bytes: 38768
#include<stdio.h>

int main()
{
    int n,m,d=0;
    scanf("%d %d",&n,&m);
    for(int i=0;i<m;i++){
        int x;
        scanf("%d",&x);
        d += x;
    }
    if(n>=d)
        printf("%d\n",n-d);
    else
        printf("-1\n");
    return 0;
}



Measured memory_bytes: 1712
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);
constexpr ll INF = 1LL << 60;

int main(void) {
	int n, m;
	cin >> n >> m;
	
	vector< vector<int> > G(n);
	vector<int> d(n, 0);
	for(int i = 0; i < m; ++i) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		G[x].push_back(y);
		d[y]++;
	}
	
	queue<int> q;
	for(int i = 0; i < n; ++i) {
		if( d[i] == 0 ) q.push(i);
	}
	
	vector<int> end;
	vector<int> dp(n + 1, 0);
	
	while( !q.empty() ) {
		int now = q.front();
		q.pop();
		end.push_back(now);
		
		for(auto& v : G[now]) {	
			d[v]--;
			
			if( d[v] == 0 ) {
				q.push(v);
				dp[v] = max(dp[v], dp[now] + 1);
			}
		}
	}
	
	int ans = 0;
	for(int i = 0; i < n; ++i) {
		ans = max(ans, dp[i]);
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 10120
// 2020-07-14 20:48:26
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vp = vector<P>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

ll f(vp& cs) {
  int sz = cs.size();
  vector<vector<int> > vec(sz+1);
  for(auto& c : cs) {
    vec[min(sz, c.first)].emplace_back(c.second);
  }
  priority_queue<int> que;
  ll res = 0;
  REPCM(i, sz, 1) {
    for(auto k : vec[i]) que.emplace(k);
    if(!que.empty()) {
      res += que.top(); que.pop();
    }
  }
  return res;
}
void answer() {
  int n;
  cin >> n;
  ll ans = 0;
  vp ls, rs;
  rep(i, n) {
    int k, l, r;
    cin >> k >> l >> r;
    int base = min(l, r);
    ans += base;
    l -= base;
    r -= base;
    if(l > 0) ls.emplace_back(k, l);
    else if(r > 0) rs.emplace_back(n-k, r);
  }
  ans += f(ls);
  ans += f(rs);
  cout << ans << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  int t;
  cin >> t;
  rep(_, t) answer();
  return 0;
}

Measured memory_bytes: 9460
//#pragma GCC optimize "trapv"
#include<bits/stdc++.h>
#define  all(v)            v.begin(), v.end()
#define  sz(x)             (long long)x.size()
#define  debug(x)          cout << #x << ':' << x << endl;
#define  rep(i,n)          for(int i = 0; i <  n ; i++)
#define  reps(i,n)         for(int i = 1; i <= n ; i++)
#define  make_unique(v)    sort(all(v));v.erase(unique(all(v)), v.end());
#define  REMOVE(v,a)       v.erase(remove(v.begin(),v.end(), a), v.end());
#define  pb                push_back
#define  mp                make_pair
#define  endl              '\n'
#define  fi                first
#define  se                second
#define  ajs(a)            (a<0)?(-1*a):a

using namespace std;
typedef long long          ll;
typedef vector<long long>  vll;
typedef pair<ll,ll>        pll;
typedef vector<int>        vi;
const ll MOD = 1e9+7;
const int dx4[4] = {0, 1, 0, -1};
const int dy4[4] = {-1, 0, 1, 0};
const int dx8[8] = { -1, -1, -1, 0, 1, 1, 1, 0};
const int dy8[8] = { -1, 0, 1, 1, 1, 0, -1, -1};
bool cmp(int X, int Y) {return X > Y;}


ll gcd(ll a, ll b) {return !b ? a : gcd(b, a % b);}
ll lcm(ll a, ll b) {return (a / gcd(a, b)) * b;}
ll modpow(ll a, ll b, ll m=MOD){a %= m; ll res = 1; while (b) {if (b & 1)res = (res * a) % m; a = (a * a) % m; b >>= 1;} return res;}
ll bpow(ll a, ll b){if(b<0){return 0;}ll res = 1; while (b) {if (b & 1)res = res * a; a = a * a; b >>= 1;} return res;}
ll modinv(ll a, ll m = MOD) {return modpow(a, m - 2, m);}


const int N = 1e6 + 5;
vi adj[N];
ll vis[102][102];



int main(){ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
string s;cin>>s;
ll sum = 0;
ll n= s.length();
rep(i,n){
	ll c = s[i] - '0';
	sum+=c;
	}
if(sum%9==0){
	cout<<"Yes";
	
	}else{
		cout<<"No";
		}
	
}





	
	




		



Measured memory_bytes: 27136
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <limits>
#include <sstream>
#include <fstream>
#include <climits>
#include <map>
#include <numeric>
#include <functional>
#include <utility>

using namespace std;

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

struct Info {
  int a;
  int b;
  int c;
  int d;
};

void dfs(const vector<Info>& info, vector<int> A, int n, int m, int* pAns) {
  if (A.size() == n + 1) {
    // calc score
    int tot = 0;
    rep(i, info.size()) {
      if (A[info[i].b] - A[info[i].a] == info[i].c) {
        tot += info[i].d;
      }
    }
    *pAns = max(*pAns, tot);
    return;
  }

  A.push_back(A.back());

  while (true) {
    dfs(info, A, n, m, pAns);
    int val = A.back() + 1;
    A.pop_back();
    if (val > m) {
      break;
    }
    A.push_back(val);
  }

  return;
}

int main(void) {
  int n, m, q;
  cin >> n >> m >> q;
  vector<Info> info(q);
  rep(i, q) cin >> info[i].a >> info[i].b >> info[i].c >> info[i].d;
  vector<int> A(1, 1);
  int ans = 0;
  dfs(info, A, n, m, &ans);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3624
#include "bits/stdc++.h"
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
using ll = long long int;

const int mod = 1e9+7;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

	int n; cin >> n;
	map<int, int> m;
	vector<int> a(n), b(n);
	for (auto &i : a) {
		cin >> i;
		++m[i];
	}
	for (auto &i : b) {
		cin >> i;
		++m[i];
	}
	reverse(begin(b), end(b));
	set<int> bad;
	int intersect = -1;
	for (int i = 0; i < n; ++i) {
		if (a[i] != b[i]) continue;
		bad.insert(i);
		intersect = a[i];
	}
	set<int> active;
	for (int i = 0; i < n; ++i) {
		if (a[i] == intersect || b[i] == intersect) continue;
		active.insert(i);
	}
	for (auto i : bad) {
		if (active.empty()) return cout << "No\n", 0;
		auto u = *active.begin();
		swap(b[i], b[u]);
		active.erase(u);
	}
	cout << "Yes\n";
	for (auto x : b)
		cout << x << ' ';
	cout << '\n';
}

// Suppose a[i] = b[i] and a[j] = b[j], i < j
// i < j -> a[i] <= a[j], b[i] >= b[j]
// a[i] + x = b[i] - y for some x, y >= 0
// x + y = 0
// x = y = 0

// Suppose intersection is with x
// c1x in a, c2x in b, c3x common
// c1x + c2x <= n
// n - c1x - c2x + c3x free spots
// Claim: c3x <= n - c1x - c2x + c3x
// 0 <= n-c1x-c2x
// True
// Why WA?????

Measured memory_bytes: 23504
def main():
    n = int(input())
    pedras = input()

    r = 0
    for p in pedras:
        if p == 'R':
            r += 1

    st2 = 'R'*r + 'W'*(n - r)

    resp = 0

    for i in range(n):
        if pedras[i] == 'R' and st2[i] == 'W':
            resp += 1

    print(resp)
main()
        
         

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

int main()
{
	int x,y,z,a;
	cin>>x>>y>>z;
	a=x;
	x=y;
	y=a;
	a=x;
	x=z;
	z=a;
	cout<<x<<" "<<y<<" "<<z;
	return 0;
} 

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(){
	int n;
	scanf("%d",&n);
	if(n%2==0){
		printf("%d\n",n/2);
	}
	else{
		printf("%d\n",n/2+1);
	}
	return 0;
}

Measured memory_bytes: 888
#include<iostream>
using namespace std;
#define N 100
int main()
{
	int n;
	int i;
	int j;
	int swap;
	int a=0;
	int num[N];
	cin >> n;
	for (i = 0;i < n;i++)
	{
		cin >> num[i];
	}
	for (i = 0;i<n;i++)
	{
		for (j = n - 1;j > i ;j--)
		{
			if (num[j] < num[j - 1])
			{
				swap = num[j];
				num[j] = num[j - 1];
				num[j - 1] = swap;
				a++;
			}
		}
	}
	for (i = 0;i < n;i++)
	{
		if (i > 0)
		{
			cout << " ";
		}
		cout << num[i];
	}
	cout << endl;
	cout << a<<endl;

    return 0;
}


Measured memory_bytes: 3048
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <vector>
typedef long long ll;
typedef unsigned long long ull;
typedef long double LD;
using namespace std;
const int INF = 2147483647;
const int INF2 = 0x3f3f3f3f;
const ll INF64 = 1e18;
const double INFD = 1e30;
const double EPS = 1e-6;
const double PI = 3.14159265;
const ll MOD = 1e9 + 7;
template <typename T>
inline T read() {
    T X = 0, w = 0;
    char ch = 0;
    while (!isdigit(ch)) {
        w |= ch == '-';
        ch = getchar();
    }
    while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
    return w ? -X : X;
}
const int MAXN = 200005;
int n, m, k;
int dr[4] = {1, 0, -1, 0};
int dc[4] = {0, 1, 0, -1};
int dr2[8] = {1, 1, 1, -1, -1, -1, 0, 0};
int dc2[8] = {1, 0, -1, 1, 0, -1, 1, -1};
int CASE = 1;
int arr[MAXN];
int main() {
#ifdef LOCALLL
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; i++) {
        scanf("%d", &arr[i]);
    }
    sort(arr, arr + n);
    reverse(arr, arr + n);
    ll ans = 0;
    for (int i = m; i < n; i++) {
        ans += arr[i];
    }
    printf("%lld", ans);
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

static const int MAX = 1e+5;
enum {W, S};
enum {x, o};
int n;
bool anim[MAX], same[MAX];

bool check(bool a1, bool a2){
    anim[0] = a1, anim[1] = a2;
    for(int i = 1; i < n - 1; i++){
        if(same[i]){
            if(anim[i] == S) anim[i + 1] = anim[i - 1];
            else anim[i + 1] = !anim[i - 1];
        } else {
            if(anim[i] == S) anim[i + 1] = !anim[i - 1];
            else anim[i + 1] = anim[i - 1];
        }
    }
    bool res;
    res = (same[n - 1] == anim[n - 1]) == (anim[n - 2] == anim[0]);
    res = res && (same[0] == anim[0]) == (anim[n - 1] == anim[1]);
    return res;
}

int main(){
    cin >> n;
    char ch;
    rep(i, n){
        cin >> ch;
        same[i] = (ch == 'o' ? o : x);
    }

    if(check(S, S)){
        rep(i, n) cout << (anim[i] == S ? 'S' : 'W');
        cout << endl;
    } else if(check(S, W)){
        rep(i, n) cout << (anim[i] == S ? 'S' : 'W');
        cout << endl;
    } else if(check(W, S)){
        rep(i, n) cout << (anim[i] == S ? 'S' : 'W');
        cout << endl;
    } else if(check(W, W)){
        rep(i, n) cout << (anim[i] == S ? 'S' : 'W');
        cout << endl;
    } else cout << -1 << endl;

    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const ll INFLL = 1001001001001001001;  // > 10^18
const int MOD = (int)1e9 + 7;
const ll MODLL = (ll)1e9 + 7;
const double EPS = 1e-9;

int main () {

    string dream = "maerd";
    string dreamer = "remaerd";
    string erase = "esare";
    string eraser = "resare";

    string s; cin >>s;
    reverse(s.begin(), s.end());

    for (int i = 0; i < s.length();) {
        if (s[i] == 'm') {
            for (int j = 0; j < dream.length(); j++) {
                if (i + j >= s.length() || s[i+j] != dream[j]) {
                    cout << "NO" << endl; 
                    return 0;
                } 
            }
            i += dream.length();
        } else if (s[i] == 'e') {
            for (int j = 0; j < erase.length(); j++) {
                if (i + j >= s.length() || s[i+j] != erase[j]) {
                    cout << "NO" << endl; 
                    return 0;
                } 
            }
            i += erase.length();
        } else if (s[i] == 'r') {
            if (i + 2 >= s.length() || s[i+2] == 'm') {
                for (int j = 0; j < dreamer.length(); j++) {
                    if (i + j >= s.length() || s[i+j] != dreamer[j]) {
                        cout << "NO" << endl; 
                        return 0;
                    } 
                }
                i += dreamer.length();
            } else if (i + 2 >= s.length() || s[i+2] == 's') {
                for (int j = 0; j < eraser.length(); j++) {
                    if (i + j >= s.length() || s[i+j] != eraser[j]) {
                        cout << "NO" << endl; 
                        return 0;
                    } 
                }
                i += eraser.length();
            } else {
                cout << "NO" << endl;
                return 0;
            } 
        } else {
            cout << "NO" << endl;
            return 0;
        } 
    }

    cout << "YES" << endl;
    return 0;
}




Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
signed main(){
  int a,b; cin>>a>>b;
  string A,B;
  rep(i,0,a) B+='0'+b;
  rep(i,0,b) A+='0'+a;
  cout<<min(A,B)<<endl;
  }


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

#define int long long
#define ll long long
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define rf(i,n,a) for(int i=n ; i>=a ; i--)
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;

const int inf = 1e9;
const int inf64 = 1e18;
const int MOD = inf + 7;

int32_t main(){
   fast;
   int h,w,m;
   cin >> h >> w >> m;

   map<int,int> row, col;
   map<pii,int> cell;

   f(i,0,m){
      int x,y;
      cin >> x >> y;
      cell[{x,y}]++;
      row[x]++;
      col[y]++;
   }

   set<pii> kol, raw;
   for(auto it : col) kol.insert({it.S, it.F});
   for(auto it : row) raw.insert({it.S, it.F});

   int ans = 0;
   
   f(i,1,3e5+1){
      int cm = (*kol.rbegin()).S;
      ans = max(ans, row[i] + col[cm] - cell[{i,cm}]);

      if(sz(kol) > 1){
         int cm = (*(++kol.rbegin())).S;
         ans = max(ans, row[i] + col[cm] - cell[{i,cm}]);
      }
   }

   f(i,1,3e5+1){
      int rm = (*raw.rbegin()).S;
      ans = max(ans, row[rm] + col[i] - cell[{rm,i}]);

      if(sz(raw) > 1){
         int rm = (*(++raw.rbegin())).S;
         ans = max(ans, row[rm] + col[i] - cell[{rm,i}]);
      }
   }


   cout << ans << "\n";
}

Measured memory_bytes: 172340
#pragma region Macros
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())
#define IN(x, a, b) x >= a and x < b

using namespace std;
using ll = long long;

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> constexpr T INF = numeric_limits<T>::max() / 2;
#pragma endregion

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

  string a, b;
  cin >> a >> b;
  vector<vector<int>> dp(a.size() + 1, vector<int>(b.size() + 1, 0));
  REP(i, a.size()) {
    REP(j, b.size()) {
      if (a[i] == b[j]) {
        dp[i + 1][j + 1] = dp[i][j] + 1;
      }
      chmax(dp[i + 1][j + 1], dp[i][j + 1]);
      chmax(dp[i + 1][j + 1], dp[i + 1][j]);
    }
  }

  int i = a.size();
  int j = b.size();
  string ans;
  while (i > 0 and j > 0) {
    if (dp[i][j] == dp[i - 1][j]) {
      i--;
    } else if (dp[i][j] == dp[i][j - 1]) {
      j--;
    } else {
      i--;
      j--;
      ans += a[i];
    }
  }
  reverse(ALL(ans));
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 35584
#include<cstdio>
#include<algorithm>
using namespace std;

int lim, n;

int main() {
	scanf("%d%d", &lim, &n);
	int l = 1, r = lim;
	for(int i=0;i<n;i++) {
		int x, y; scanf("%d%d", &x, &y);
		l = max(l, x);
		r = min(r, y);
	}
	printf("%d\n", max(0, r-l+1));
	
	return 0;
}

Measured memory_bytes: 128
import sys

def f(s):
    return s

N=int(input())
a=[list(map(f,input().split()))+[i] for i in range(N)]
for i in range(N):
    a[i][1]=100-int(a[i][1])
a.sort()

for i in range(N):
    print(a[i][2]+1)

Measured memory_bytes: 3064
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n,m = readInts()
G = [[] for _ in range(n)]
for i in range(m):
    a,b = map(lambda x:int(x)-1, input().split())
    G[a].append(b)
    G[b].append(a)
q = deque([0])
def pa():
    while q:
        v = q.popleft()
        for nv in G[v]:
            if arrived[nv] < 0:
                arrived[nv] = v + 1
                q.append(nv)
arrived = [-1] * n
pa()
if -1 in arrived[1:]:
    print('No')
else:
    print('Yes')
    print(*arrived[1:],sep='\n')


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

int main()
{
    long long n;
    std::cin>>n;
    std::unordered_map<char,long long> um;
    for(long long i=0;i<n;i++){
        std::string t;
        std::cin>>t;
        if(t[0] == 'M' || t[0] == 'A' || t[0] == 'R' || t[0] == 'C' || t[0] == 'H'){
            um[t[0]]++;
        }
    }
    long long ans = 0;
    ans += um['M'] * um['A'] * um['R'];
    ans += um['M'] * um['A'] * um['C'];
    ans += um['M'] * um['A'] * um['H'];
    ans += um['M'] * um['R'] * um['C'];
    ans += um['M'] * um['R'] * um['H'];
    ans += um['M'] * um['C'] * um['H'];
    ans += um['A'] * um['R'] * um['C'];
    ans += um['A'] * um['R'] * um['H'];
    ans += um['A'] * um['C'] * um['H'];
    ans += um['R'] * um['C'] * um['H'];
    std::cout<<ans<<std::endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define reps(x,c) for(auto x:c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a) 
#define mp(a,b) make_pair((a),(b))
#define pl pair<ll,ll>
#define INF 2147483600
#define MOD 1000000007
#define fi first
#define se second
#define dbg(x) cout << #x"="<< (x) << endl
#define dbgv(x) cout<<#x<<endl;reps(y,x){cout<<y<<" ";}cout<<endl

ll D[1010][1010],C[510][510];

int main(){
  ll n,c;cin>>n>>c;
  rep(i,c){
    rep(j,c){
      cin>>D[i][j];
    }
  }
  rep(i,n){
    rep(j,n){
      cin>>C[i][j];
    }
  }

  vector<pl> v0(c);
  vector<pl> v1(c);
  vector<pl> v2(c);
    
  rep(i,c){
  	v0[i].se=i;
  	v1[i].se=i;
  	v2[i].se=i;
  	rep(j,n){
  	  rep(k,n){
  	    if((j+k+2)%3==0){
  	      v0[i].fi+=D[C[j][k]-1][i];
  	    }else if((j+k+2)%3==1){
  	    	v1[i].fi+=D[C[j][k]-1][i];
  	    }else{
  	    	v2[i].fi+=D[C[j][k]-1][i];
  	    }
  	  }
  	}
  }

  sort(all(v0));
  sort(all(v1));
  sort(all(v2));

  ll ans=INF;

  rep(i,3){
  	rep(j,3){
  	  rep(k,3){
  	    if(v0[i].se!=v1[j].se&&v0[i].se!=v2[k].se&&v1[j].se!=v2[k].se){
  	    	ans=min(ans,v0[i].fi+v1[j].fi+v2[k].fi);
  	    }
  	  }
  	}
  }

  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

const int DAT_SIZE=1<<22;
const int MAX_N=500050;
int N;

vll dat1(DAT_SIZE),dat2(DAT_SIZE);
vll v(MAX_N);

//[a,b)にxを加算
//0-indexであることに注意
void add(int a,int b,ll x,int k=0,int l=0,int r=N){
    if(a<=l&&r<=b)dat1[k]+=x;
    else if(l<b&&a<r){
        dat2[k]+=(ll)(min(b,r)-max(a,l))*x;
        add(a,b,x,2*k+1,l,(l+r)/2);
        add(a,b,x,2*k+2,(l+r)/2,r);
    }
}

//初期化
void init(int n){
    N=1;
    while(N<n)N*=2;
    //rep(i,n)add(i,i+1,v[i],0,0,n);
}

//[a,b)の和
//0-indexであることに注意
ll getsum(int a,int b,int k=0,int l=0,int r=N){
    if(b<=l||r<=a)return 0;
    else if(a<=l&&r<=b)return dat1[k]*(ll)(r-l)+dat2[k];
    else{
        ll res=(ll)(min(b,r)-max(a,l))*dat1[k];
        res+=getsum(a,b,2*k+1,l,(l+r)/2);
        res+=getsum(a,b,2*k+2,(l+r)/2,r);
        return res;
    }
}

int main(){
    int n,q;cin>>n>>q;
    vin c(n);rep(i,n)cin>>c[i];
    vector<tuple<int,int,int>> query(q);
    int l,r;
    rep(i,q){
        cin>>l>>r;
        l--;r--;
        query[i]=make_tuple(r,l,i);
    }
    sort(all(query));
    init(n);
    int x,y,z;int tmp=0;
    vin prev(n+1,-1);
    vin ans(q);
    rep(i,q){
        y=get<0>(query[i]);
        x=get<1>(query[i]);
        z=get<2>(query[i]);
        rep2(j,tmp,y+1){
            add(prev[c[j]]+1,j+1,1);
            prev[c[j]]=j;
        }
        tmp=y;
        ans[z]=getsum(x,x+1);
    }
    rep(i,q)cout<<ans[i]<<endl;
}

Measured memory_bytes: 85080
def main():
    n = int(input())
    if 1<=n<=9:
        print(n)
    elif 10<=n<=99:
        print(9)
    elif 100<=n<=999:
        print(9+n-99)
    elif 1000<=n<=9999:
        print(9+900)
    elif 10000<=n<=99999:
        print(9+900+n-9999)
    else:
        print(90909)
    
if __name__ == '__main__':
    main()

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int H,W;
int P[101010];
int Q[101010];
vector<pair<int,int>> V;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>H>>W;
	FOR(i,H) {
		cin>>P[i];
		V.push_back({P[i],i});
	}
	FOR(i,W) {
		cin>>Q[i];
		V.push_back({Q[i],i+1000000});
	}
	
	ll HH=H+1,WW=W+1;
	sort(ALL(V));
	ll ret=0;
	FORR(r,V) {
		if(r.second<1000000) {
			ret += WW*r.first;
			HH--;
		}
		else {
			ret += HH*r.first;
			WW--;
		}
		
	}
	cout<<ret<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 2932
#include<iostream>

using namespace std ;

int main()
{
	int a ,b ,c ;
	cin >> a >> b >> c ;
	int ans = 0 ;
	for( ; a <= b ; a++ )
	{
		if( ! ( c % a ) )
			ans++ ;
	}
	cout << ans << endl ;
	return 0 ;
}

Measured memory_bytes: 3096