akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
int bittree[250005]={},n,arr[505],ans[250005],reversebittree[250005]={};
bool possible=true;
vector <pair<int,int> > daftar;
int lsone(int angka)
{
	return (angka&-angka);
}
int ubah(int indeks)
{
	return (n*n-indeks+1);
}
void tambah(int indeks,int tambah)
{
	while(indeks<=n*n)
	{
		bittree[indeks]+=tambah;
		indeks+=lsone(indeks);
	}
}
int nilai(int indeks)
{
	int ret=0;
	while(indeks>0)
	{
		ret+=bittree[indeks];
		indeks-=lsone(indeks);
	}
	return ret;
}
void buatBIT()
{
	for(int i=1;i<=n*n;i++)		//ceritanya semua dalam keadaan on
		bittree[i]=lsone(i);
}
int lower()	//cari bilangan pertama yang masih kosong
{
	int bawah=1,atas=n*n,mid;
	while(bawah<=atas)
	{
		mid=(bawah+atas)>>1;
		if(nilai(mid)>=1)
			atas=mid-1;
		else
			bawah=mid+1;
	}
	return bawah;
}
int biggestlower()	//cari bilangan terbesar yang masih kosong
{
	int target=nilai(n*n);
	int bawah=1,atas=n*n,mid;
	while(bawah<=atas)
	{
		mid=(bawah+atas)>>1;
		if(nilai(mid)>=target)
			atas=mid-1;
		else
			bawah=mid+1;
	}
	return bawah;
}
bool checkans()
{
	int occ[n+5]={},last=1;
	for(int i=0;i<daftar.size();i++)
	{
		//cout<<"tai"<<endl;
		for(last;last<=daftar[i].first;last++)
			occ[ans[last]]++;
		if(!((ans[last-1]==daftar[i].second)&&(occ[daftar[i].second]==daftar[i].second)))
		{
			//cout<<daftar[i].second<<" "<<occ[daftar[i].second]<<endl;
			return false;
		}
	}
	return true;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&arr[i]);
	}
	buatBIT();
	//cout<<"satu"<<endl;
	for(int i=1;i<=n;i++)		//prioritaskan yang di tunjuk;
	{
		daftar.push_back(make_pair(arr[i],i));
		ans[arr[i]]=i;
		tambah(arr[i],-1);
	}
	sort(daftar.begin(),daftar.end());
	//cout<<"endl"<<endl;
	for(int i=0;i<daftar.size();i++)
	{
		pair<int,int> temp=daftar[i];
		for(int j=1;j<=temp.second-1;j++)
		{
			int indeks=lower();
			ans[indeks]=temp.second;
			tambah(indeks,-1);
		}
	}
	//cout<<"tiga"<<endl;
	for(int i=daftar.size()-1;i>=0;i--)
	{
		pair<int,int> temp=daftar[i];
		for(int j=temp.second+1;j<=n;j++)
		{
			int indeks=biggestlower();
			ans[indeks]=temp.second;
			tambah(indeks,-1);
		}
	}
	//cout<<"emapt"<<endl;
	if(!checkans())
	{
		printf("No\n");
		return 0;
	}
	printf("Yes\n");
	printf("%d",ans[1]);
	for(int i=2;i<=n*n;i++)
		printf(" %d",ans[i]);
	printf("\n");
}

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

const int mod=1e9+7;
const int inv2=500000004
;
signed main(){
    int n, ans=0, sum=0, a;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a;
        sum=(sum+a*a%mod)%mod;
        ans=(ans+a)%mod;
    }
    ans=ans*ans%mod;
    ans-=sum;
    ans=(ans%mod+mod)%mod;
    cout<<(ans*inv2%mod)<<endl;
}

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

#define F first
#define S second
#define pb push_back
#define endl '\n'

using namespace std;
using ll = long long;

const int MOD = 1e9 + 7;
const int N = 1e3 + 10;

ll n, p = 1;
int main() {
   	ios_base::sync_with_stdio(false);
   	cin.tie(0); cout.tie(0);

	cin >> n;
	int l = 0;
	n--;
	for (l = 1; ; ++l) {
		p *= 26;
		if(n >= p) {
			 n -= p;
		} else {
			break;
		}
	}
	string res(l, 'z');
	for (int i = 0; i < l; ++i) {
		res[l - 1 - i] = n%26 + 'a';
		n /= 26;
	}
	cout << res << endl;
}
//jjddja

Measured memory_bytes: 3636
function Main(input){
  input = input.split(' ');
  var a = input[0];
  var b = input[1];
  var c = input[2];

  var result = [];

  function upper(x) {
      var upper_x = x.toUpperCase();
      upper_x = upper_x.split('');
      return upper_x;
  }

  result.push(upper(a).shift());
  result.push(upper(b).shift());
  result.push(upper(c).shift());
  console.log(result.join(''));

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

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

int main()
{
	int n;cin>>n;bool ok=false;
	int d1[n],d2[n];
	for(int i=0;i<n;i++)
	{
		cin>>d1[i]>>d2[i];
	}
	for(int i=0;i<=n-3;i++)
	{
		if(d1[i]==d2[i]&&d1[i+1]==d2[i+1]&&d1[i+2]==d2[i+2])
		{
			ok=true;
			break;
		}
	}
	if(ok) cout<<"Yes"<<"\n";
	else cout<<"No"<<"\n";
}


Measured memory_bytes: 3584
N = gets.to_i
As = gets.split.map(&:to_i)
Ass = As.map.with_index{|x,index| x - (index+1)}
mid = Ass.sort[N/2]

tmp = Ass.map{|x| (x-mid).abs}
tmp_sum = tmp.inject{|sum,x| sum + x}

puts tmp_sum

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

int graph[40][40];
int ans[40];

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

  for(int i = 1; i <= n; i++)
  {
    int a, b;
    scanf("%d,%d", &a, &b);
    graph[a][i] = b;
    graph[b][i] = a;
  }

  for(int i = 1; i <= w; i++)
  {
    int x = i;
    for(int y = 1; y <= n; y++)
    {
      if(graph[x][y])
	x = graph[x][y];
    }
    ans[x] = i;
  }

  for(int i = 1; i <= w; i++)
    cout << ans[i] << endl;
  return 0;
}

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

using namespace std;
int c[3][3];
int a[3];
int b[3];

int main()
{
  for(int i = 0; i < 3; i++)
    for(int j = 0; j < 3; j++)
      cin >> c[i][j];

  // Propose a[0] = 0 and calculate b values
  for(int i = 0; i < 3; i++) {
    b[i] = c[0][i];
  }
  // Calculate a values
  for(int i = 0; i < 3; i++)
    a[i] = c[i][0] - b[0];

  for(int i = 0; i < 3; i++) {
    for(int j = 0; j < 3; j++) {
      if(c[i][j] != a[i] + b[j]) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
from itertools import product

n, k = map(int, input().split())
a = list(map(int, input().split()))

ans = 10 ** 20
for bit in product([0, 1], repeat=n):
    if sum(bit) != k or bit[0] == 0:
        continue
    cnt = 0
    tmp = a[0]
    for i, v in enumerate(bit):
        if v == 1:
            if i != 0:
                cnt += max(tmp + 1 - a[i], 0)
                tmp = max(tmp + 1, a[i])
        else:
            tmp = max(tmp, a[i])
    ans = min(ans, cnt)
print(ans)


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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

int main() {
    string s;
    cin >> s;
    li n = sz(s);
    li res = 0;
    rep(i, n - 1) {
        if (s[i] != s[i + 1]) {
            ++res;
        }
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
using namespace std;
const int mod = 1000000007;
#define ll long long

vector<ll> R;
int main()
{
	ll N; cin >> N;
	bool r = false;
	for (ll i = 1; i * i <= N; i++) {
		if (N % i == 0) {
			if (N == i * i) {
				R.push_back(i);
				r = true;
			}
			else {
				R.push_back(i);
				R.push_back(N / i);
			}
		}
	}
	sort(R.begin(), R.end());
	if (r) {
		cout << (R[R.size() / 2] - 1) * 2 << endl;
	}
	else {
		cout << R[R.size() / 2] - 1 + R[R.size() / 2 - 1] - 1 << endl;
	}
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define int long long int
signed main()
{
	// int t;
	// cin>>t;
	// while(t--)
	// {
		int n;
		cin>>n;

		int sum=0;

		for(int i=1;i<=n;i++)
		{
			if(i%3!=0 and i%5!=0)
			{
				sum+=i;
			}
		}
		cout<<sum<<endl;
	
}

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

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

    int l, r;
    int maxl = 0, minr = n;

    for (int i = 0; i < m; i++) {
        cin >> l >> r;

        maxl = max(maxl, l);
        minr = min(minr, r);
    }

    cout << max(0, minr - maxl + 1) << endl;

    return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var N int
	fmt.Scan(&N)
	A := make([]int, N)
	var a, sum, min, max, k int
	min = 999999999999
	for i := 0; i < N; i++ {
		fmt.Scan(&a)
		A[i] = a
		if min > a {
			min = a
		}
		if max < a {
			max = a
		}
		sum += a
	}
	k = N * (N + 1) / 2
	if sum%k != 0 {
		fmt.Println("NO")
		return
	}
	t := sum / k
	v := true
	for i := 0; i < N-1; i++ {
		d := A[i+1] - A[i]
		w := t - d
		if w < 0 || w%N != 0 {
			v = false
		}
	}
	if v {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Measured memory_bytes: 5504
#include<stdio.h>

#define MAX 100
#define INFTY 2000000
#define White 0
#define Gray 1
#define Black 2


int G[MAX][MAX],n;

int prim(){

  int color[MAX],d[MAX],p[MAX];
  int min,u,v,sum=0;
  int i;
 
  for(i = 0; i < n; i++){
    color[i] = White;
    d[i] = INFTY;
    p[i] = -1;
  }
 
  d[0] = 0;
  p[0] = -1;
   
  while(1){
    min = INFTY;
    for(i = 0; i < n; i++){
      if(color[i] != Black && d[i] < min){
    min = d[i];
    u = i;
      }
    }
    if(min == INFTY) break;
      color[u] = Black;
       
      for(v = 0; v < n; v++){
    if(color[v] != Black && G[u][v] != INFTY){
      if(G[u][v] < d[v]){
        d[v] = G[u][v];
        p[v] = u;
        color[v] = Gray;
      }
    }
      }
  }
  for(i = 0; i < n; i++){
    if(p[i] != -1) sum += G[i][p[i]];
  }
  return sum;

}
int main(){
  
  int i,j;
  
  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      
      scanf("%d",&G[i][j]);
      if(G[i][j] == -1) G[i][j] = INFTY;
    }
  }
  
  printf("%d\n",prim());
  
  return 0;
}

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

//#define int long long
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define rep11(i, n) for (int i = 1; i < (int)(n); ++i)
#define repo(i, o, n) for (int i = o; i < (int)(n); ++i)
#define repm(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1002000007
#define INF LONG_LONG_MAX

int main()
{
    string S;
    cin >> S;
    int co = 0;
    for (int i = 0; i < S.length(); i++){
        if (S[i] != S[S.length()-1-i]){
            S[S.length()-1-i]=S[i];
            co++;
        }
    }
    cout << co <<endl;
}

Measured memory_bytes: 764
H,W = map(int,input().split())
A = [input() for i in range(H)]
from collections import Counter
ctr = Counter()
for row in A:
    ctr.update(row)

if H%2==0 and W%2==0:
    print('Yes' if all(v%4==0 for v in ctr.values()) else 'No')
    exit()

if H%2==0 or W%2==0:
    if H%2: H,W = W,H
    if any(v%2 for v in ctr.values()):
        print('No')
        exit()
    pair = 0
    for v in ctr.values():
        if v%4==2:
            pair += 1
    print('Yes' if pair*2 <= H else 'No')

else:
    odd = 0
    for k in ctr.keys():
        if ctr[k]%2:
            odd += 1
            ctr[k] -= 1
    if odd != 1:
        print('No')
        exit()
    pair = 0
    for v in ctr.values():
        if v%4==2:
            pair += 1
    print('Yes' if pair*2 <= H+W-2 else 'No')

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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#ifdef LOCAL
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define dump(x)
#define debug(x)
#define dassert(...)
#endif
//#define int long long

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

void solve(long long X){
    cout << (X / 500 * 1000 + (X % 500) / 5 * 5) << endl;
}

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    long long X;
    scanf("%lld",&X);
    solve(X);
    return 0;
}


Measured memory_bytes: 256
def f(i):
    global ans
    if i == n - 1:
        if G[0][s[0]] == 0:
            return
        t = sorted(s)
        for j in range(n - 2):
            if t[j] == t[j + 1]:
                return
        for j in range(n - 2):
            if G[s[j]][s[j + 1]] == 0:
                return
        ans += 1
        return
    for j in range(n - 1, 0, -1):
        f(i + 1)
        s[i] = j

n, m = map(int, input().split())
G = [[0 for _ in range(n)] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    G[a - 1][b - 1] = 1
    G[b - 1][a - 1] = 1
s = [1] * (n - 1)
ans = 0
f(0)
print(ans)

Measured memory_bytes: 3064
#include<iostream>

using namespace std;

int main() {
  	int A,B,C,D;
  	cin >> A >> B >> C >> D;

	int n = C % B > 0 ? C / B : C / B - 1;
	if (A - D * n <= 0) {
		cout << "No" << endl;
	} else {
		cout << "Yes" << endl;
	}
	return 0; 
}

Measured memory_bytes: 3572
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#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

int main(){
  ll n;cin>>n;
  string temp;
  map<string,ll> s;
  rep(i,n){
    cin>>temp;
    s[temp]++;
  }
  ll m;cin>>m;
  map<string,ll> t;
  rep(i,m){
    cin>>temp;
    t[temp]++;
  }
  ll ans=0;
  reps(x,s){
  	ans=max(ans,x.se-t[x.fi]);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <stack>
#include <algorithm>
using namespace std;
int dp[6][6];
int H = 5, W = 5;
int buffer[6][6], T[6][6];

struct Rectangle {int height, pos; };

int getLargestRectangle(int row) {
    stack<Rectangle> S;
    int maxv = 0;
    T[row][W] = 0;

    Rectangle rect, pre;
    int target, area;
    for (int i = 0; i <= W; i++) {
        rect.height = T[row][i];
        rect.pos = i;
        if (S.empty()) S.push(rect);
        else {
            if (S.top().height < rect.height) S.push(rect);
            else {
                target = i;
                while (!S.empty() && S.top().height >= rect.height) {
                    pre = S.top(); S.pop();
                    area = pre.height * (i - pre.pos);
                    maxv = max(maxv, area);
                    target = pre.pos;
                }
                rect.pos = target;
                S.push(rect);
            }
        }
    }
    return maxv;
}

void solve() {
    for (int j = 0; j < W; j++) {
        for (int i = 0; i < H; i++) {
            if (buffer[i][j]) T[i][j] = 0;
            else T[i][j] = (i > 0) ? T[i-1][j]+1 : 1;
        }
    }
    int maxv = 0;
    for (int i = 0; i < H; i++) maxv = max(maxv, getLargestRectangle(i));
    printf("%d\n", maxv);
}



int main()
{

    int n, t;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                scanf("%d", &t);
                buffer[i][j] = (t+1) %2;
            }
        }
        solve();
    }

    return 0;
}



Measured memory_bytes: 2724
import sys
input = sys.stdin.readline
from collections import deque
n, m = map(int, input().split())
G = [[] for _ in range(n+1)]
for _ in range(m):
    u, v = map(int, input().split())
    G[u].append(v)
    G[v].append(u)
q = deque([1])
p = [0]*(n+1)
while q:
    v = q.popleft()
    for u in G[v]:
        if p[u] == 0:
            p[u] = v
            q.append(u)
print("Yes\n"+"\n".join(map(str, p[2:])))

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

using namespace std;

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

using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vs = vector<string>;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

const int dx[] = { -1, 0, 1, 0 };
const int dy[] = { 0, 1, 0, -1 };

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

int func(int n, int v, int w) {
	if (n == 1) {
		return min(v + 1, w + 1);
	} else if (v == w) {
		return v + 1;
	}

	return v < w ? func(n, v, (w - 1) / n) : func(n, (v - 1) / n, w);
}

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

	int n, q;
	cin >> n >> q;
	
	for (int i = 0; i < q; i++) {
		int v, w;

		cin >> v >> w;
		cout << func(n, v - 1, w - 1) << endl;
	}
	return 0;
}

Measured memory_bytes: 1280
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
#define rint register int
#define rep(i,l,r) for(rint i=l;i<=r;i++)
#define per(i,l,r) for(rint i=l;i>=r;i--)
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define fir first
#define sec second
#define mset(s,t) memset(s,t,sizeof(s))
template<typename T1,typename T2>void ckmin(T1 &a,T2 b){if(a>b)a=b;}
template<typename T1,typename T2>void ckmax(T1 &a,T2 b){if(a<b)a=b;}
template<typename T>T gcd(T a,T b){return b?gcd(b,a%b):a;}
int read(){
  int x=0,f=0;
  char ch=getchar();
  while(!isdigit(ch))f|=ch=='-',ch=getchar();
  while(isdigit(ch))x=10*x+ch-'0',ch=getchar();
  return f?-x:x;
}
#define int long long
const int N=3000005;
int n,q;
struct Seg{
  #define ls (u<<1)
  #define rs (u<<1|1)
  int minn[N],tag[N];
  void pushup(int u){
    minn[u]=min(minn[ls],minn[rs]);
  } 
  void pushdown(int u){
    if(tag[u]!=1e9){
      tag[ls]=min(tag[ls],tag[u]);
      tag[rs]=min(tag[rs],tag[u]);
      minn[ls]=min(minn[ls],tag[u]);
      minn[rs]=min(minn[rs],tag[u]);
      tag[u]=1e9;
    }
  }
  void build(int u,int l,int r){
    tag[u]=1e9,minn[u]=n;
    if(l==r)return;
    int mid=l+r>>1;
    build(ls,l,mid),build(rs,mid+1,r);
  }
  void update(int u,int l,int r,int ql,int qr,int dlt){
    pushdown(u);
    if(ql<=l&&r<=qr){
      minn[u]=min(minn[u],dlt);
      tag[u]=min(tag[u],dlt);
      return;
    }
    pushdown(u);
    int mid=l+r>>1;
    if(ql<=mid)update(ls,l,mid,ql,qr,dlt);
    if(qr>mid)update(rs,mid+1,r,ql,qr,dlt);
    pushup(u);
  }
  int query(int u,int l,int r,int pos){
    pushdown(u);
    if(l==r)return minn[u];
    int mid=l+r>>1;
    if(pos<=mid)return query(ls,l,mid,pos);
    else return query(rs,mid+1,r,pos);
  }
}row,col;
// row:行，col:列 
signed main(){
  n=read(),q=read();
  ll ans=1ll*(n-2)*(n-2);
  row.build(1,1,n);
  col.build(1,1,n);
  while(q--){
    int opt=read(),x=read();
    if(opt==1){
      int t=col.query(1,1,n,x);
      //printf("opt = 1, t=%d\n",t);
      ans-=max(0ll,t-2);
      if(t-1>=2)row.update(1,1,n,2,t-1,x);
    }else{
      int t=row.query(1,1,n,x);
      ans-=max(0ll,t-2);
      if(t-1>=2)col.update(1,1,n,2,t-1,x);
    }
    //printf("%lld\n",ans);
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 34660
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <stack>
#define ll long long
using namespace std;
int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	ll N, T, Q; cin >> N >> T >> Q;
	vector <pair<ll, ll>> A(N + 1);
	for (int i = 1; i <= N; i++) {
		cin >> A[i].first >> A[i].second;
		if (A[i].second == 2) A[i].second = -1;
	}
	vector<ll> q(Q);
	for (int i = 0; i < Q;i++) cin >> q[i];


	vector<ll> ans(N + 1);
	int f = 0;
	ll l;
	ll mid;
	for (int i = 1; i <= N;i++) {
		if (f == 0 && A[i].second == -1) {
			ans[i] = A[i].first + A[i].second*T;
			continue;
		}
		if (f == 0 && A[i].second == 1) {
			f = 1; l = i;
			continue;
		}
		if (f == 1 && A[i].second == 1) continue;
		if (f == 1 && A[i].second == -1) {
			mid = (A[i].first + A[i - 1].first) / 2;
			ans[i] = max(mid, A[i].first + A[i].second * T);

			for (int at = l; at < i; at++) {
				ans[at] = min(mid, A[at].first + A[at].second*T);
			}
			f = 2;
			continue;
		}
		if (f == 2 && A[i].second == -1) {
			ans[i] = max(mid, A[i].first + A[i].second*T);
			continue;
		}
		if (f == 2 && A[i].second == 1) {
			f = 1; l = i;
			continue;
		}
	}
	if (f == 1) {
		//ans[N] = A[N].first + A[N].second*T;
		for (int at = l; at <= N; at++) {
			ans[at] = A[at].first + A[at].second*T;
		}
	}

	for (int i = 0; i < Q;i++) {
		cout << ans[q[i]] << endl;
	}
}

Measured memory_bytes: 5208
#include<iostream>
using namespace std;
int main(){
    int A[5][4][11], n;
    for(int i = 1; i <= 4; i++){
        for(int j = 1; j <= 3; j++){
            for(int k = 1; k <= 10; k++){
                A[i][j][k] = 0;
            }
        }
    }
    
    cin >> n;
    for(int i = 0; i < n; i++){
        int b, f, r, v;
        cin >> b >> f >> r >> v;
        A[b][f][r] += v;
    }
    
    for(int f = 1; f <= 4; f++){
        if(f > 1) cout << "####################\n";
        for(int b = 1; b <= 3; b++){
            for(int r = 1; r <= 10; r++){
                cout << " " << A[f][b][r];
            }
            cout << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3116
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <vector>
#include <map>
using namespace std;

int gcd(int a, int b)
{
    if (b == 0)
        return a;
    a %= b;
    return gcd(b, a);
}

int main()
{
    long long n, m;
    cin >> n >> m;
    string s, t;
    cin >> s >> t;
    int g = gcd(n, m);
    long long z = n * m / g;

    map<long long, char> mic;
    for (int i = 0; i < n; ++i)
    {
        long long idx = i * (z / n) + 1;
        mic[idx] = s[i];
    }

    bool success = true;
    for (int j = 0; j < m; ++j)
    {
        long long idx = j * (z / m) + 1;
        if (mic.count(idx))
        {
            if (mic[idx] != t[j])
                success = false;
        }
    }

    cout << (success ? z : -1) << endl;
}


Measured memory_bytes: 6144
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;

int main() {
    vector<int> cards(3);

    for (int i = 0; i < 3; ++i) {
        cin >> cards[i];
    }

    sort(cards.begin(), cards.end());

    const int ans = cards[2]*10+cards[1]+cards[0];
    cout << ans << endl;

    return 0;
}


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

char mp[105][105];

int main() {
  int w, h, n; cin >> w >> h >> n;
  
  for (int i = 0; i < n; i++) {
   	int x, y, a; cin >> x >> y >> a;
    x--; y--;
    switch (a) {
      case 1:
        for (int i = 0; i <= x; i++)
          for (int j = 0; j < h; j++)
            mp[i][j] = 1;
        break;
      case 2:
        for (int i = x + 1; i < w; i++)
          for (int j = 0; j < h; j++)
            mp[i][j] = 1;
        break;
      case 3:
        for (int i = 0; i < w; i++)
          for (int j = 0; j <= y; j++)
            mp[i][j] = 1;
        break;
      case 4:
        for (int i = 0; i < w; i++)
          for (int j = y + 1; j < h; j++)
            mp[i][j] = 1;
        break;
    }
  }
  
  int ans = 0; 
  for (int i = 0; i < w; i++) for (int j = 0; j < h; j++) if (!mp[i][j]) ans++;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long n;
long long a[11000000],s[11000000],b[11000000];
int main()
{
	cin>>n;
	n=(long long)pow(2,n);
	for(int i=0;i<n;i++)scanf("%lld",&a[i]);
	for(int i=0;i<n;i++)
	  for(int j=i;j<=n;j=(j+1)|i)
	  {
	  	s[j]=max(s[j],a[i]+b[j]);
	  	b[j]=max(b[j],a[i]);
	  }
	for(int i=1;i<n;i++)s[i]=max(s[i],s[i-1]);
	for(int i=1;i<n;i++)printf("%lld\n",s[i]);
	return 0;
} 

Measured memory_bytes: 10352
import java.util.*;	
public class Main {
public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		double[] A  = new double[N];
		double[] B  = new double[N];
		double[] C  = new double[N];
		long count = 0;
		
	    for(int i=0; i<N; i++) {
			A[i]=sc.nextInt();			
	    }
	    for(int i=0; i<N; i++) {
			B[i]=sc.nextInt();			
	    }
	    for(int i=0; i<N; i++) {
			C[i]=sc.nextInt();			
	    }
	    Arrays.sort(A);
	    Arrays.sort(B);
	    Arrays.sort(C);
	    for(int i = 0; i<N; i++) {
	    	long foundA=0,foundC=0;
	    	foundA=-1-Arrays.binarySearch(A,B[i]-0.1);
	    	foundC=N+1+Arrays.binarySearch(C,B[i]+0.1);
	    	count+=foundA*foundC;
	     }
	    System.out.println(count);
	  }	          	
}

Measured memory_bytes: 99468
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <utility>
#include <algorithm>
#include <map>
#include <cassert>
using namespace std;
#define REPP(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,a) for(int i = 0; i < (a); ++i)
#define PER(i,a) for(int i = (a) - 1; i >= 0; --i)
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define MP make_pair

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

const int mod = 1e9 + 7;
const int maxn = 3005;
int dp[maxn][maxn], sum[maxn];

void add(int& a, int b) {
    a += b;
    if (a >= mod) a -= mod;
}

int main() {
    int n;
    string s;
    cin >> n >> s;
    dp[1][1] = 1;
    REPP(len, 2, n + 1) {
        memset(sum, 0, sizeof(sum));
        REPP(i, 1, len) sum[i] = (sum[i - 1] + dp[len - 1][i]) % mod;
        REPP(i, 1, len + 1) {
            int l, r;
            if (s[len - 2] == '<') l = 1, r = i - 1;
            else l = i, r = len - 1;
            add(dp[len][i], (sum[r] - sum[l - 1] + mod) % mod);
        }
    }
    int ans = 0;
    REPP(i, 1, n + 1) add(ans, dp[n][i]);
    cout << ans << endl;
    return 0;
}


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

#include <math.h>
#include <stdlib.h>


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

template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true; } return false; }
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true; } return false; }

// const int INF = 1001001001;
// long long max => LLONG_MAX

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int x, t; cin >> x >> t;
    cout << max(x-t, 0) << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long x = sc.nextLong();
		long[] a = new long[N];
		for (int i = 0; i < N; i++) {
			a[i] = sc.nextLong();
		}
		long[][] mtx = new long[N][N];
		long[] wk = new long[N];

		wk[0] = 0;
		for (int i = 0; i < N; i++) {
			mtx[i][0] = a[i];
			wk[0] += mtx[i][0];
		}
		for (int j = 1; j < N; j++) {
			wk[j] = 0;
			for (int i = 0; i < N; i++) {
				mtx[i][j] = Math.min(mtx[i][j - 1], a[(i + j) % N]);
				wk[j] += mtx[i][j];
			}
		}

		long ans = Long.MAX_VALUE;
		for (int j = 0; j < N; j++) {
			ans = Math.min(ans, wk[j] + x * j);
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 43408
s = input()

if s == 'RRR':
    print(3)
if s == 'RSS':
    print(1)
if s == 'SRS':
    print(1)
if s == 'SSR':
    print(1)
if s =='SSS':
    print(0)
if s == 'RSR':
    print(1)
if s == 'RRS':
    print(2)
if s == 'SRR':
    print(2)

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

class C {
    static void Main(string[] args) {
        var st = Console.ReadLine().Split().Select(long.Parse).ToArray();

        long N = st[0];
        long K = st[1];

        var H = Console.ReadLine().Split().Select(long.Parse).ToArray();

        Array.Sort(H);
        var h = H.Reverse();

        if (K >= N) {
            Console.WriteLine(0);
            return;
        }

        var skipList = h.ToList().Skip((int)K);

        //Console.WriteLine(string.Join(" ", skipList));

        Console.WriteLine(skipList.Sum());


    }
}

Measured memory_bytes: 38272
import sys

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

def main():
    ap=set()
    s=input()
    for c in s:
        if c in ap:
            print("no")
            exit()
        ap.add(c)
    print("yes")
main()

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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;}

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};

// Problem Specific Parameter:

int main() {
  int n; cin >> n;
  int a[100];
  for(int i = 0; i < n; i++) cin >> a[i];
  int ret = 0;
  for(int i = 1; i < n; i++) {
    if(a[i-1] == a[i]) {
      a[i] = 1000 + i;
      ++ret;
    }
  }
  cout << ret << endl;

  return 0;
}


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

using namespace std;

// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

/*
 * Given a set of intervals (some of them overlap), find minimum number
 * of vertical lines need to cross all of them.
 */
/* greedy */

struct Point { int i,x,t; };

bool cmp(const Point& a, const Point& b)
{
    if (a.x == b.x)
        return a.t > b.t;
    return a.x < b.x;
}

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    ios::sync_with_stdio(false);
    int n,m;
    while (cin >> n >> m) {
        vector<Point> A;
        FOR(i,0,m) {
            Point a,b; cin >> a.x >> b.x;
            a.i = i; a.t = 0;
            b.i = i; b.t = 1;
            A.push_back(a);
            A.push_back(b);
        }
        sort(ALL(A),cmp);
        vector<int> colr(m); int ans = 0;
        FOR_ALL(a,A) {
            const int i = a->i;
            const int x = a->x;
            const int t = a->t;
            if (!t)
                colr[i] = ans;
            if (t && colr[i] == ans)
                ans++;
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 4980
#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>
#include <queue>
using namespace std;
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define print(x) cout<<(x)<<'\n'
#define print_vec(v) rep(i,v.size()){if(i!=0)cout<<" ";cout<<v[i];}cout<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<'\n'
#define pb push_back
#define mp make_pair
#define MOD 1000000007 //10^9+7
#define fi first
#define sc second
using ll=long long;
using pll=pair<ll,ll>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vstr=vector<string>;

void solve() {
    // ll N;
    string N;
    cin >> N;
    ll ans = 0;
    for(char i:N){
        ans += i - '0';
    }
    // for(int i=0;i<100;i++){
    //     while(N>0){
    //         ans += N%10;
    //         N /= 10;
    //     }
    //     N = ans;
    //     ans = 0;
    // }
    if(ans%9==0){
    // if(N%9==0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }


}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(20);
    //int q; cin >> q;
	//while (q--)
		solve();
    return 0;
}


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

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<ll, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
//const ll INF = LONG_LONG_MAX / 100;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)

bool contain(set<char> &s, int a) { return s.find(a) != s.end(); }


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

typedef priority_queue<ll, vector<ll>, greater<ll>> PQ_ASK;
const int mod = 1000000007;


int main() {

    int n;
    int k;
    cin >> n >> k;

    k = min(n, k);
    vector<ll> monsters(n);
    rep(i, n) cin >> monsters[i];
    sort(monsters.rbegin(), monsters.rend());
    rep(i, k) monsters[i] = 0;

    ll all = accumulate(monsters.begin(), monsters.end(), 0ll);

    cout << all << endl;

}


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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y=x;
    if(z->key < x->key)
      x=x->left;
    else
      x=x->right;
  }

  z->parent=y;

  if(y==NIL)
    root=z;
  else if(z->key < y->key)
    y->left=z;
  else
    y->right=z;


}

void inorder(Node x){
  if(x!=NIL){
    inorder(x->left);
    printf(" %d",x->key);
    inorder(x->right);
  }
}

void preorder(Node x){
  if(x!=NIL){
    printf(" %d",x->key);
    preorder(x->left);
    preorder(x->right);
  }
  
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
     
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      
    }
  }

  return 0;
}

Measured memory_bytes: 24036
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define vl          vector<ll>
#define vi          vector<int>
#define pi          pair<int,int>
#define pl          pair<ll,ll>
#define all(a)      a.begin(),a.end()
#define mem(a,x)    memset(a,x,sizeof(a))
#define pb          push_back
#define mp          make_pair
#define F           first
#define S           second
#define trace(x)     cerr<<#x<<":"<<x<<endl;
#define trace2(x,y) cerr<<#x<<":"<<x<<"|"<<#y<<":"<<y<<endl;
#define trace3(x,y,z) cerr<<#x<<":"<<x<<"|"<<#y<<":"<<y<<"|"<<#z<<":"<<z<<endl;
#define fast_io     std::ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

int main(){
	fast_io;
	string s,t;
	cin>>s>>t;
	vector<vi > dp(3001, vi (3001, 0));
	for(int i=1;i<=s.size();i++){
		for(int j=1;j<=t.size();j++){
			if(s[i-1] == t[j-1]){
				dp[i][j] = 1 + dp[i-1][j-1];
			}
			else{
				dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
			}
		}
	}
	int i = s.size(), j = t.size();
	string ans;
	while(i && j){
		if(s[i-1] == t[j-1]){
			ans = s[i-1] + ans;
			i--;
			j--;
		}
		else{
			if(dp[i-1][j]>dp[i][j-1])
				i--;
			else j--;
		}
	}
	cout<<ans;
	cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

Measured memory_bytes: 35584
#include <memory.h>

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

#define mod 1000000007

int main() {
	int n, a, b;
	cin >> n >> a >> b;
	map<long long int, int> cnt;
	for (int i = 0; i < n; i++) {
		long long int v;
		cin >> v;
		if (cnt.find(v) == cnt.end())
			cnt[v] = 1;
		else
			cnt[v]++;
	}
	long long int comb[51][51] = {};
	for (int i = 0; i <= n; i++) {
		comb[i][0] = comb[i][i] = 1;
		for (int j = 1; j <= i - 1; j++) {
			comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j];
		}
	}
	auto itr = cnt.end();
	itr--;
	double ans_av;
	long long int ans_comb = 0;
	if ((*itr).second < a) {
		double sum = (*itr).first * (*itr).second;
		int cnt = (*itr).second;
		ans_comb = 1;
		itr--;
		while (cnt < a) {
			if ((*itr).second + cnt < a) {
				sum += (*itr).first * (*itr).second;
				cnt += (*itr).second;
			} else {
				sum += (*itr).first * (a - cnt);
				ans_comb = comb[(*itr).second][a - cnt];
				break;
			}
			itr--;
		}
		ans_av = (double)sum / (a + 0.0);
	} else {
		ans_av = (*itr).first;
		for (int i = a; i <= min(b, (*itr).second); i++) {
			ans_comb += comb[(*itr).second][i];
		}
	}
	printf("%.10f\n", ans_av);
	cout << ans_comb << endl;
}

Measured memory_bytes: 256
#[derive(Debug)]
struct Task {
    a: usize,
    b: usize,
}

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();

    let mut task_s = Vec::with_capacity(n);
    for _ in 0..n {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        let mut iter = buf.split_whitespace();
        let a: usize = iter.next().unwrap().parse().unwrap();
        let b: usize = iter.next().unwrap().parse().unwrap();
        task_s.push(Task{a:a, b:b});
    }
    task_s.sort_by(|x, y| x.b.cmp(&y.b));

    let mut ans = "Yes".to_owned();
    let mut now_t = 0;
    for task in task_s {
        now_t += task.a;
        if now_t > task.b {
            ans = "No".to_owned();
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 10492
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 1; i < (int)(n + 1); i++)
// vector<vector<int>> A(3, vector<int>(4));
int main() {
    int A,B,C;
    cin>>A>>B>>C;
    bool ans=false;
    rrep(i,B){
        if((A*i)%B==C){
            ans=true;
            break;
        }
    }
    if(ans==true){
        cout<<"YES"<<endl;
    }
    else{
        cout<<"NO"<<endl;
    }
}


Measured memory_bytes: 3600
#include<iostream>
#include<cstdlib>
#include<stack>
#include<string>
using namespace std;
int main() {
	string s;
	int a, b;
	stack<int> st;
	while (cin >> s) {
		if (s[0] == '+') {
			a = st.top();
			st.pop();
			b = st.top();
			st.pop();
			st.push(a + b);
		}
		else if (s[0] == '-') {
			a = st.top();
			st.pop();
			b = st.top();
			st.pop();
			st.push(b - a);
		}
		else if (s[0] == '*') {
			a = st.top();
			st.pop();
			b = st.top();
			st.pop();
			st.push(a * b);
		}
		else {
			st.push(atoi(s.c_str()));
		}
	}
	cout << st.top() << endl;
}


Measured memory_bytes: 3208
using System;
using System.Collections.Generic;
class Program
    {
        public static long Gcd(long a, long b) {
         if (a < b)
             // 引数を入替えて自分を呼び出す
             return Gcd(b, a);
         while (b != 0) {
             var remainder = a % b;
             a = b;
             b = remainder;
         }
         return a;
     }
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] s1 = Console.ReadLine().Split(' ');
            int[] d = new int[n];
            for (int i=0; i<n; i++)
            {
                d[i] = int.Parse(s1[i]);
            }
            Array.Sort(d);
            int ans = d[n/2] - d[n/2 - 1];
            Console.WriteLine(ans);

            
        }
    }
    //mcs Main.cs
    //mono Main.exe

Measured memory_bytes: 18656
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n, m; cin >> n >> m;
  vector<int>a(m,0);
  for(int i=0; i < n; i++){
    int x; cin >> x;
    for(int j=0; j < x; j++){
      int v; cin >> v;
      a[v-1] += 1;
    }
  }
  int cnt=0;
  for(int i=0; i<m; i++){
    if(a[i]==n)  cnt++;
  }
  cout << cnt << endl;
 }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define ll long long
#define ull unsigned long long
#define dd double
#define oo 1001007000
#define ff float
#define ooo 1000000100000000000
#define iii pair<ll,ll>
#define vii vector<ll>
#define viii vector<iii>
#define sss pair<str,str>
#define str string
#define sii set<ll>
#define siii set<iii>
#define st size_t
#define r0 return 0
#define pb push_back
#define sz size
using namespace std;

const char E='\n';
const int N=10005;
const int NN=1000000;
const ll md=998244353;


int main(){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    ll ans=0;
    for (int i=1;i<=n;i++){
        if (i%5!=0 && i%3!=0){
            ans+=i;
        }
    }
    cout << ans << E;
    r0;
}
/*














*/


Measured memory_bytes: 3612
/* -------------------------------- Template -------------------------------- */

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

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

template <typename T> T &chmin(T &a, const T &b) { return a = std::min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = std::max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

// template<typename T> constexpr T inf = [](){ assert(false); };
// template<> constexpr int inf<int> = 1e9;
// template<> constexpr ll inf<ll> = 1e18;
// template<> constexpr ld inf<ld> = 1e30;

struct yes_no : std::numpunct<char> {
  string_type do_truename()  const { return "Yes"; }
  string_type do_falsename() const { return "No"; }
};

void solve();

int main() {
  std::locale loc(std::locale(), new yes_no);
  std::cout << std::boolalpha << std::setprecision(12) << std::fixed;
  std::cout.imbue(loc);
  solve();
  return 0;
}

using namespace std;

/* -------------------------------- Library -------------------------------- */

/* ---------------------------------- Main ---------------------------------- */

int t[200000];

void solve() {
  int N;
  cin >> N;
  ll p = 0;
  REP(i,N) {
    int a, b;
    cin >> a >> b;
    p += a;
    ++t[p % 86400];
    ++t[p % 86400 + 86400];
    p += b;
  }
  REP(i,180000) t[i+1] += t[i];
  int res = 0;
  REP(i,86400) chmax(res, t[i + 10801] - t[i]);
  cout << res << endl;
  return;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
vector <int> m;
int fir,n;
int cnt[100011];
vector <int> v[100011];
void dfs(int now,int par)
{
	cnt[now]=1;
	m.push_back(now);
	if(n-1==now)
	fir=m[(m.size()+1)/2];
	for(int i=0;i<v[now].size();i++)
	{
		if(v[now][i]==par)
		continue;
		dfs(v[now][i],now);
		cnt[now]+=cnt[v[now][i]];
	}
	m.pop_back();
}
int main()
{
	cin >>n;
	for(int i=0;i<n-1;i++)
	{
		int x,y;
		cin >>x>>y;
		x--;
		y--;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	dfs(0,0);
	puts((cnt[fir]*2<n)?"Fennec":"Snuke");
	return 0;
}

Measured memory_bytes: 11256