akhauriyash/Code-Regression huggingface dataset:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

N, M, Q = mi()
abcd = li2(Q)

#N = 10

a = '0' * N
m = str(M-1)
l = [a]
#for length in range(N):
while True:
    i = N-1
    while i >= 0 and a[i] == m:
        i -= 1
    if i == -1:
        break
    a = list(a)
    num = str(int(a[i]) + 1)
    a[i] = num
    if i !=N-1:
        for j in range(i+1, N):
            a[j] = num
    tmp = ''.join(a)
    l.append(tmp)


ans = 0
for num in l:
    cnt = 0
    num = list(map(int, list(num)))
    for i in range(Q):
        if num[abcd[i][1]-1] - num[abcd[i][0]-1] == abcd[i][2]:
            cnt += abcd[i][3]

    ans = max(ans, cnt)

print(ans)

Measured memory_bytes: 75292
#include<iostream>
#include<vector>
#include<queue>
#include<climits>
using namespace std;

const int INF = INT_MAX;

int main(){
    int n, m, s, t;
    cin >> n >> m >> s >> t;
    s--, t--;
    if(s > t){
        cout << 0 << endl;
        return 0;
    }
    vector<int> d(n);
    for(int i = 0; i < n; i++)  cin >> d[i];
    vector<int> v[n];
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        v[--a].push_back(--b);
    }
    vector<int> dp(n, INF);
    priority_queue<pair<int,int>> pq;
    for(int i = 0; i <= s; i++){
        for(int next : v[i])    pq.push({-d[next],next});
    }
    int to = s;
    while(!pq.empty()){
        auto p = pq.top();  pq.pop();
        int cost = -p.first, pos = p.second;
        if(cost >= dp[pos] || pos <= to) continue;
        dp[pos] = cost;
        if(pos >= t){
            cout << dp[pos] << endl;
            return 0;
        }
        while(to < pos){
            to++;
            for(int next : v[to]){
                int ncost = cost + d[next];
                if(dp[next] > ncost) pq.push({-ncost, next});
            }
        }
    }
}


Measured memory_bytes: 9152
import io.StdIn.readLine
import annotation.tailrec

object Main extends App {
  val (n, k) = readLine.split(" ") match {
    case Array(n, k) => (n.toInt, k.toLong)
  }
  val abs = List.fill(n)(readLine.split(" ").map(_.toInt) match {
    case Array(a, b) => (a, b)
  }).sortBy(_._1)

  println(solve(k, abs))

  @tailrec def solve(k: Long, abs: List[(Int, Int)]): Int = {
    val (a, b) = abs.head
    if (k <= b) a else solve(k - b, abs.tail)
  }
}


Measured memory_bytes: 78696
n = int(input())
A = [int(i) for i in input().split()]
B = []

for i in range(n):
    B.append(A[i] - i)

B.sort()
mid = B[len(B)//2]

ans = 0
for i in range(n):
    ans += abs(A[i] - (mid + i))
    
print(ans)

Measured memory_bytes: 26180
#include <stdio.h>
int main() {
	char t, s;
	char cups[3] = {1, 0, 0};
	while (scanf(" %c,%c ", &t, &s) != EOF) {
		cups[t - 'A'] ^= cups[s - 'A'];
		cups[s - 'A'] ^= cups[t - 'A'];
		cups[t - 'A'] ^= cups[s - 'A'];
	}
	if (cups[0])
		puts("A");
	else if (cups[1])
		puts("B");
	else
		puts("C");
	return 0;
}

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

int main()
{
	int d, n, m, k, res;
	while (cin >> d, d) {
		res = 0;
		cin >> n >> m;
		vector<int> D(n + 1, 0);
		D[n] = d;
		for (int i = 1; i < n; i++) {
			cin >> D[i];
		}
		sort(D.begin(), D.end());
		for (int i = 0; i < m; i++) {
			cin >> k;
			int lb = lower_bound(D.begin(), D.end(), k) - D.begin();
			if (lb != 0) {
				res += min(k - D[lb - 1], D[lb] - k);
			}
		}
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 3348
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;

int main(void) {
	int K, N;
	cin >> K >> N;
	vector<int> vec(N);
	for (int i = 0; i < N; i++) cin >> vec.at(i);
	sort(vec.begin(), vec.end());
	int mTmp = vec.at(0) + (K - vec.at(N - 1));
	long long ans = mTmp;
	for (int i = 0; i < N-1; i++) {
		ans += vec.at(i + 1) - vec.at(i);
		mTmp = max(vec.at(i + 1)-vec.at(i), mTmp);
	}
	cout << ans-mTmp << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int N;
    vector<int> d;
    int tmp;
    cin >> N;
    FOR(i,0,N){
        cin >> tmp;
        d.push_back(tmp);
    }
    sort(d.begin(),d.end());
    tmp =1;
    FOR(i,1,N){
        if(d[i-1] != d[i]) tmp++;
    }
    cout << tmp;
    return 0;
}

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


char s[N];
int ans;
int main(){
    scanf("%s",s);
    for(int i=0;i<3;i++){
    if(s[i]=='1')ans++;
    }
    printf("%d",ans);
}

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

const int mod = 1e9 + 7;

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

	long long ans = 1;
	if (abs(n - m) >= 0 && abs(n - m) <= 1) {
		for (int i = n; i > 1; i--) {
			ans *= i; ans %= mod;
		}
		for (int i = m; i > 1; i--) {
			ans *= i; ans %= mod;
		}
		if (n == m)ans *= 2, ans %= mod;
	}
	else ans = 0;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n,card1,card2,P1=0,P2=0;
  while(1){
    cin >> n;
    if(n==0){
      break;
    }
    for(int i=0;i<n;i++){
      cin >> card1 >> card2;
      if(card1>card2){
	P1=P1+card1+card2;
      }
      else if(card2>card1){
	P2=P2+card1+card2;
      }
      else if(card1==card2){
	P1=P1+card1;
	P2=P2+card2;
      }
    }
    cout << P1 << " " << P2 << endl;
    P1=0;
    P2=0;
  }
  return (0);
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int K, N;
  cin >> K >> N;
  vector <int> A(N);
  
  for(int i = 0; i < N; i++){
    cin >> A.at(i);
  }
  
  vector <int> B(N);
 
  for(int i = 0; i < N-1; i++){
    B.at(i) = A.at(i+1) - A.at(i);
  }
  
  B.at(N-1) = A.at(0) + K - A.at(N-1);
  
  sort(B.begin(), B.end());
  int ans = 0;
  for(int i = 0; i < N-1; i++){
    ans += B.at(i);
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 1920
#include<iostream>
#include<iomanip>

int main(){
  long N;
  std::cin >> N;
  long r = N;
  long count = 0;
  while(r > 9){
    r /= 10;
    count++;
  }
  long square = 1, root = 1;
  for(long i = 0; i < count; i++){
    square *= 10;
    if(i % 2 == 1) root *= 10;
  }
  if(count % 2 == 1){
    square *= 9.0 / 10;
    root *= 3;
  }
  if(N >= 9 * square){
    square *= 9;
    root *= 3;
  }else if(N >= 4 * square){
    square *= 4;
    root *= 2;
  }
  long nextS = square;
  while(nextS <= N){
    square = nextS;
    nextS += 2 * root + 1;
    root += 1;
  }
  std::cout << std::fixed;
  std::cout << std::setprecision(10) << square << std::endl;
}

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

const int INF = (int)1e9;

struct Edge {
  int src, dst, cost;
  Edge(int src_, int dst_, int cost_) : src(src_), dst(dst_), cost(cost_) { }
};

int main() {
  for(int C, N, M, S, T; cin >> C >> N >> M >> S >> T, C || N || M || S || T; ) {
    --S, --T;
    vector<Edge> G;
    for(int i = 0; i < M; ++i) {
      int a, b, f; cin >> a >> b >> f;
      --a, --b;
      G.emplace_back(a, b, f);
      G.emplace_back(b, a, f);
    }
    int D[N][C + 1];
    for(int i = 0; i < N; ++i)
      for(int j = 0; j <= C; ++j)
        D[i][j] = INF;
    D[S][C] = 0;
    while(true) {
      bool update = false;
      for(const Edge &e : G) {
        for(int j = 0; j <= C; ++j) {
          if(D[e.dst][j] > D[e.src][j] + e.cost) {
            D[e.dst][j] = D[e.src][j] + e.cost;
            update = true;
          }
          if(j > 0 && D[e.dst][j - 1] > D[e.src][j] + e.cost / 2) {
            D[e.dst][j - 1] = D[e.src][j] + e.cost / 2;
            update = true;
          }
        }
      }
      if(!update) break;
    }
    int ans = INF;
    for(int j = 0; j <= C; ++j) {
      ans = min(ans, D[T][j]);
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1224
n=int(input())

count=0
for i in range(1,10):
  if n%i==0:
    s=n//i
    s=str(s)
    if len(s)==1:
      count+=1
    else:
      count+=0
  else:
    count+=0
if count>=1:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
 
long long comb(int t, int a){
  long long c = 1;
  for(int i = 0; i < a; i++) c = c*(t-i)/(i+1);
  return c;
}

int main(){
  int n, a, b, i, s, t;
  double ave = 0;
  long long v[55], ans = 0;
  scanf("%d%d%d", &n, &a, &b);
  for(i = 0; i < n; i++){
    scanf("%lld", &v[i]);
  }
  sort(v, v+n, greater<long long>());
  for(i = 0; i < a; i++) ave += v[i];
  ave /= a;
  printf("%f\n", ave);
  
  for(i = 0; ; i++) if(v[i] == v[a-1]) break;
  s = i;
  for(i = a; i < n; i++) if(v[i] != v[a-1]) break;
  t = i;
  
  if(!(s)) for(i = a; i <= b; i++) ans += comb(t, i);
  else ans = comb(t-s, a-s);
  
  printf("%lld\n", ans);
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main()
{
  int n0, n1;
  string s;
  cin >> s;
  size_t size = s.length();
  n0=0;
  for (int i=0; i<size; ++i){
    if(s[i]=='0'){
      n0++;
    }
  }
  n1=size-n0;
  cout << 2*min(n0,n1);
  return 0;
}

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

int main(){

    int h=0,w,n;
    string s;

    int d[100];

    cin >> n;

    vector<int> vec(n) ;
    for(int i=0;i<n;i++) cin >> d[i];
    
    for(int i=0;i<n;i++) vec[i] = d[i];

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

    for(int i=0;i<n;i++){
        if (vec[i] != vec[i+1])
            h++;
    }






    int a;

    a=1;

    /* for(int i=0;i<vec.size();i++){
        cout << vec[i] << endl;

    }*/

        cout << h << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<utility>
#include<numeric>
#include<cmath>

using namespace std;

int main()
{
    int N, a, b, c;
    cin >> N >> a >> b >> c;
    string S,S1;
    vector<string> ans;

    if(a+b+c == 0){
        cout << "No" << endl;
        return 0;
    }

    cin >> S1;

    for(int i=0;i<N;++i){
        S = S1;
        if(i!=N-1){
            cin >> S1;
        }else{
            S1 == "END";
        }

        if(S=="AB"){
            if(a == 1 and b == 1 and c == 0 and S1 == "BC"){
                ans.push_back("B");
                a -= 1;
                b += 1;
            }else if(a == 1 and b == 1 and c == 0 and S1 == "AC"){
                ans.push_back("A");
                a += 1;
                b -= 1;
            }else if(a<=b){
                ans.push_back("A");
                a += 1;
                b -= 1;
            }else{
                ans.push_back("B");
                a -= 1;
                b += 1;
            }

        }else if(S=="AC"){
            if(a == 1 and b == 0 and c == 1 and S1 == "AB"){
                ans.push_back("A");
                a += 1;
                c -= 1;
            }else if(a == 1 and b == 0 and c == 1 and S1 == "BC"){
                ans.push_back("C");
                a -= 1;
                c += 1;
            }else if(a<=c){
                ans.push_back("A");
                a += 1;
                c -= 1;
            }else{
                ans.push_back("C");
                a -= 1;
                c += 1;
            }

        }else if(S=="BC"){
            if(a == 0 and b == 1 and c == 1 and S1 == "AB"){
                ans.push_back("B");
                b += 1;
                c -= 1;
            }else if(a == 0 and b == 1 and c == 1 and S1 == "AC"){
                ans.push_back("C");
                b -= 1;
                c += 1;
            }else if(b<=c){
                ans.push_back("B");
                b += 1;
                c -= 1;
            }else{
                ans.push_back("C");
                b -= 1;
                c += 1;
            }
        }

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

    cout << "Yes" << endl;
    for(auto s:ans){
        cout << s << endl;
    }
       

    return 0;
}


Measured memory_bytes: 7436
fun main(args: Array<String>) = println(run {
    val a = (1..3).map { readLine()!!.split(" ").map { it.toInt() } }.flatten()
    val n = readLine()!!.toInt()
    val b = (1..n).map { readLine()!!.toInt() }
    
    val hit = BooleanArray(9)
    b.forEach {
        val i = a.indexOf(it)
        if(i != -1 ) hit[i] = true
    }
    
    listOf(
            hit[0] && hit[1] && hit[2],
            hit[3] && hit[4] && hit[5],
            hit[6] && hit[7] && hit[8],
            hit[0] && hit[3] && hit[6],
            hit[1] && hit[4] && hit[7],
            hit[2] && hit[5] && hit[8],
            hit[0] && hit[4] && hit[8],
            hit[2] && hit[4] && hit[6]
    ).any { it }.let { if (it) "Yes" else "No" }
})

Measured memory_bytes: 37980
#include<iostream>
using namespace std;
int main(){

    char a[3];
    int count=0;

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


    for(int i=0;i<3;i++){
        if(a[i]=='1'){
            count=count+1;
            }
    }

    cout << count <<endl;




    return 0;
}

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

#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FILL0(x) memset(x,0,sizeof(x))

using namespace std;

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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
 

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

 
    int N;
    cin >> N;
    N%=10;

    if(N==2||N==4||N==5||N==7||N==9)
    {
        cout << "hon" << endl;
    }
    if(N==0||N==1||N==6||N==8)
    {
        cout << "pon" << endl;
    }
    if(N==3)
    {
        cout << "bon" << endl;
    }

 

 

    return 0;
}



Measured memory_bytes: 3600
n = int(input())
a = list(map(int,input().split()))

p = [0] * n
minv = 1e9
for i in range(n):
  minv = min(minv, a[i])
  p[i] = minv

ans = 0
for i in range(n):
  if a[i] <= p[i]:
    ans += 1

print(ans)

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

int Selection_Sort(int A[], int N){
    int cnt=0;
    for (int i=0; i<N-1; i++){
        int min=A[i];//先頭の値を暫定の最小値として初期化する
        int k=i;//先頭の位置を保存する
        for (int j=i+1; j<N; j++){
            //
            if(min>A[j]){
                min=A[j];
                k=j;
            }
        }
        //交換するアルゴリズム
        if(A[i]!=A[k]){
            swap(A[i],A[k]);
            cnt++;
        }
    }
    return cnt;
}

int main(){
    int N; cin >> N;
    int A[101];
    int ans;
    rep(i,N) cin >> A[i];
    ans=Selection_Sort(A,N);
    rep(i,N-1) cout << A[i] << " ";
    cout << A[N-1] << endl;
    
    cout << ans << endl;
}


Measured memory_bytes: 3092
#define _USE_MATH_DEFINES
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cctype>
#include<climits>
#include<cmath>
#include<cstdio>
#include<deque>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

int c(int a) {
	if (a == 2)return 1;
	if (a % 2 == 0)return 0;
	for (int i = 3; i <= sqrt(a); i += 2)
		if (a%i == 0)
			return 0;
	return 1;
}

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

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

#define ff              first
#define ss              second
#define ll             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<ll,ll>
#define vi              vector<ll>
#define mii             map<ll,ll>
#define pqb             priority_queue<ll>
#define pqs             priority_queue<ll,vi,greater<ll> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            ll x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)


ll solve(ll n,vector<ll>v,ll k){
    ll op1,op2;
    vector<ll>dp(n+1);
dp[1]=0;
for(int i=2;i<=n;i++)
{
    dp[i]=INT_MAX;
    for(int j=i-1;j>=1&&(i-j)<=k;j--)
    {
        dp[i]=min(dp[i],abs(v[i]-v[j])+dp[j]);
    }
}

return dp[n];

}

int main()
{
    FIO;
    ll a,b,c,d,e,f=0,sum=0,ans,ck=0,m,n,k,p,q,r,t,add=0,x,y,z;
    string s;

    cin>>n>>k;
    vector<ll>v(n+1);
    for(int i=1;i<=n;i++){cin>>v[i];}
    ans=solve(n,v,k);
    cout<<ans<<endl;



    return 0;
}

Measured memory_bytes: 5552
#include<stdio.h>
 int main(void)
 {
     char c;

     scanf("%c",&c);

     if(c=='a') { printf("vowel\n"); return 0; }
     if(c=='i') { printf("vowel\n"); return 0; }
     if(c=='u') { printf("vowel\n"); return 0; }
     if(c=='e') { printf("vowel\n"); return 0; }
     if(c=='o') { printf("vowel\n"); return 0; }
     else { printf("consonant\n"); return 0; }
 }


Measured memory_bytes: 128
#include <stdio.h>

int main() {
	int i = 0, k = 0, n, car[100] = {0}, out[100] = {0};
	while(scanf("%d", &n)!= EOF) {
		if(n == 0) {
			i--;
			out[k] = car[i];
			k++;
		} else {
			car[i] = n;
			i++;
		}
	}
	for(i = 0; i < k; i++) printf("%d\n", out[i]);
	return 0;
}

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

#define int long long
const int N = 1000005;

signed main() {
    int a,b,c;
    cin>>a>>b>>c;
    if(c-a-b>=0) cout<<(4ll*a*b<(c-a-b)*(c-a-b)?"Yes":"No");
    else cout<<"No";
}



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

using namespace std;


int main(void)
{
    int N;
    cin >> N;
    vector<int64_t> L(87);
    L.at(0) = 2;
    L.at(1) = 1;
    for(int i = 2; i<87; i++)
    {
        L.at(i) = L.at(i-1) + L.at(i-2);
    }

    cout << L.at(N) << endl;

}



Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int x, a, b, i, ans, cnt;

    scanf("%d", &x);
    scanf("%d", &a);
    scanf("%d", &b);

    ans = x - a;
    cnt = ans / b;

    for(i=0; i<cnt; i++){
        ans = ans - b;
    }

    printf("%d\n", ans);

    return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

class Program
{
    public void Proc()
    {
        Reader.IsDebug = false;
        int[] inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();

        int result = 2;
        if (inpt[0] != inpt[1])
        {
            if (inpt[0] == 1)
            {
                result = 0;
            }
            else if(inpt[1] == 1)
            {
                result = 1;
            }
            else if(inpt[0] > inpt[1])
            {
                result = 0;
            }
            else
            {
                result = 1;
            }
        }
        string[] tmp = new string[] { "Alice", "Bob", "Draw" };
        Console.WriteLine(tmp[result]);        

    }


    public class Reader
    {
        public static bool IsDebug = true;
        private static String PlainInput = @"



8 6


";
        private static System.IO.StringReader Sr = null;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (Sr == null)
                {
                    Sr = new System.IO.StringReader(PlainInput.Trim());
                }
                return Sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
    }
    static void Main()
    {
        Program prg = new Program();
        prg.Proc();
    }
}

Measured memory_bytes: 13396
s = input()
t = input()
sUsed = ""
tUsed = ""
buf = []
flag = 0
while len(s) > 0 and len(t) > 0:
    s0 = s[0]
    t0 = t[0]
    sUsed += s0
    buf = [i for i,x in enumerate(s) if x == s0]
    s = s.replace(s0,"")
    if t0 in tUsed and len(tUsed) > 0:
        flag = 1
    if not buf == [i for i,x in enumerate(t) if x == t0]:
        flag = 1
    tUsed += t0
    t = t.replace(t0,"")
    buf.clear()
    if flag == 1:
        break
if flag == 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 11548
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();


int main() {
    ll n;
    cin >> n;
    vector<ll> arr(n, 0);
    for(int i = 0; i < n; i++) {
        cin >> arr[i];
    }
    ll acc = accumulate(arr.begin(), arr.end(), 0LL);
    ll step_sum = (1+n) * n / 2;
    if (acc % step_sum != 0) {
        cout << "NO" << endl;
    } else {
        ll cnt = acc / step_sum;
        ll ans = 0;
        arr.push_back(arr[0]);
        for(int i = 1; i <= n; i++) {
            ll goal = arr[i-1] + cnt;
            if (arr[i] > goal) {
                cout << "NO" << endl;
                return 0;
            } else {
                if ((goal - arr[i]) % n != 0) {
                    cout << "NO" << endl;
                    return 0;
                } else {
                    ans += (goal - arr[i]) / n;
                }
            }
        }
        if (cnt == ans)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
    return 0;
}




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

int main(void){
    
    int i,j,k,N,M,temp;
    scanf("%d %d",&N,&M);
    if(M == 0){
        if(N==1){
        printf("%d",0);
        exit(0);
        }
        else if(N==2){
            printf("%d",10);
            exit(0);
        }
        else {
            printf("%d",100);
            exit(0);
        }
    }
    int sarr[M],carr[M],ans[N];
    for(i=0 ;i<M ;i++){
        scanf("%d %d",&sarr[i],&carr[i]);
    }
    for(i=0 ;i<M ; i++){
        if((sarr[i]==1 && carr[i]==0) && N !=1) {
            printf("%d",-1);
            exit(0);
        }
    }
    for(i=0 ;i<M ; i++){
        for(j=i+1 ; j<M ;j++){
                if(sarr[i] == sarr[j]){
                    if(carr[i] != carr[j]) {
                        printf("%d",-1);
                        exit(0);
                    }
                }
        }
    }
    for(j=1;j<N+1;j++){
        for(i=0 ;i<M ; i++){
            if(sarr[i]==j){
                ans[j-1]= carr[i];
                break;
            }
            else{
                if(i == M-1){
                    if(j == 1){
                        if(N == 1){
                            ans[j-1] =0;
                        }
                        else{
                            ans[j-1] =1;
                        }
                    }
                    else{
                        ans[j-1] =0;
                    }
                }
            }
        }
    }
    temp =0;
    for(i=0;i<N;i++){
        k=1;
        for(j=0; j<N-i-1;j++){
            k *= 10;
        }
        temp += ans[i] * k;
    }
    printf("%d",temp); 
    return 0;   
}



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

#define  pf                  printf
#define  sc                  scanf
#define  PI                  2*acos(0.0)
#define  fast                ios_base::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define  mem(a,b)            memset(a, b, sizeof(a) )
#define  gcd(a,b)            __gcd(a,b)
#define  lcm(a,b)            (a*(b/gcd(a,b)))
#define  MAX                 1234567899
#define  mod                 1000000007
#define  all(v)              (v).begin(),(v).end()
#define  vSort(v)            sort(all(v))
#define  maxSort(v)          sort(all(v),greater<int>())
#define  Unique(v)           v.erase(unique(all(v)),v.end())
#define  sqr(x)              ((x)*(x))
#define  qube(x)             ((x)*(x)*(x))
#define  deci(n)             cout<<fixed<<setprecision(n)
#define  sci(n)              sc("%d",&(n))
#define  scii(x,y)           sc("%d %d",&(x),&(y))
#define  scl(x)              sc("%lld",&(x))
#define  scll(x,y)           sc("%lld %lld",&(x),&(y))
#define  vi                  vector<int>
#define  hi                  pf(" HI \n")
#define  pp                  pair<int,int>
#define  pb(x)               push_back(x)
#define  mp(x,y)             make_pair(x,y)
#define  F                   first
#define  S                   second
#define  check(n,pos)        (n & (1<<(pos)))
#define  biton(n,pos)        (n  (1<<(pos)))
#define  bitoff(n,pos)       (n & ~(1<<(pos)))
typedef  long long int       lli;
typedef  unsigned long long int ulli;
int dx4[] = { 0, 0, -1, 1 } ;
int dy4[] = { -1, 1, 0, 0 } ;
bool valid( int r, int c, int x, int y )
{
    if( x >= 1 && x <= r && y >= 1 && y <= c ) return 1 ;
    return 0 ;
}

using namespace std;
int ans[1000000+2][4];
int main ()
{
    int n;
    cin >> n;
    int a,b,c;
    for(int i=1; i<=n; i++)
    {
        cin >> a>> b >> c;
        ans[i][0]=a;
        ans[i][1]=b;
        ans[i][2]=c;
    }
    for(int i=n-1; i>=1; i--)
    {
        ans[i][0]= ans[i][0]+max(ans[i+1][1],ans[i+1][2]);
        ans[i][1]= ans[i][1]+max(ans[i+1][0],ans[i+1][2]);
        ans[i][2]= ans[i][2]+max(ans[i+1][1],ans[i+1][0]);
    }
    cout << max(ans[1][0],max(ans[1][1],ans[1][2]))<<endl;

    return 0;
}



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

int main() {
    int a, b, c, d, e, k; cin >> a >> b >> c >> d >> e >> k;
    /*
    int a[10];
    for (int i=0; i<5; i++) {
        cin >> a[i];
    }

    bool res = true;
    int k; cin >> k;
    for (int i=0; i<5; i++) {
        if (a[i+1] - a[i] > k) {
            res = false;
        }
    }

    if (res) cout << "Yay!" << endl;
    else cout << ":(" << endl;
    */

    int maxv = max({a, b, c, d, e});
    int minv = min({a, b, c, d, e});
    if (maxv - minv <= k) {
        cout << "Yay!" << endl;
    }

    else cout << ":(" << endl;



    return 0;
}




Measured memory_bytes: 256
A,B = map(str,input().split())
A = int(A)
if B[-2] == ".":
    B = B[:-2] + B[-1] + "0"
elif B[-3] == ".":
    B = B[:-3] + B[-2:]
else:
    B = B + "00"

B = int(B)
ans = str(A*B)

if len(ans) <= 2:
    print("0")
else:
    print(ans[:-2])

Measured memory_bytes: 9204
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, a[ohara], b[ohara], c, d, tmp, m, h, w, x, y, k, q, out;
V g[ohara], kae[ohara];
ll cou[ohara];
ld dp_mae[1000][1000], he[1000];
ld ans;
ll dat[1000];

void uku() {
  ld dp[n + 10] = {};
  rrrep(j, n - 2, 0) {
    rep(k, Size(g[j])) {
      ll to = g[j][k];
      dp[j] += dp[to];
    }
    dp[j] /= (ld)Size(g[j]);
    dp[j] += 1.0;
  }
  ans = dp[0];
}

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

  cin >> n >> m;
  rep(i, m) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
    g[a[i]].p_b(b[i]);
  }

  uku();

  rep(i, n - 1) {
    if (Size(g[i]) == 1) continue;
    ld dp[n + 10] = {};
    rrrep(j, n - 2, 0) {
      ld usitapunikiakunwara = -1.0;
      rep(k, Size(g[j])) {
        ll to = g[j][k];
        dp[j] += dp[to];
        if (usitapunikiakunwara <= dp[to]) usitapunikiakunwara = dp[to];
      }
      if (i == j) {
        dp[j] -= usitapunikiakunwara;
        dp[j] /= (ld)(Size(g[j]) - 1.0);
      } else {
        dp[j] /= (ld)Size(g[j]);
      }
      dp[j] += 1.0;
    }
    if (ans >= dp[0]) {
      ans = dp[0];
    }
  }
  doublecout(ans);
  return 0;
}


Measured memory_bytes: 55808
import java.util.*;

public class Main {

  static Scanner scan = new Scanner(System.in);

  static long d = (long) Math.pow(10, 9) + 7;
  public static void main(String[] args) {
    long n = scan.nextInt();
    long k = scan.nextInt();

    long sum = 1;
    for (long i = k; i <= n; i++) {
      sum += calc(n) - calc(n - i) - calc(i - 1) + 1;
      // System.out.println(calc(n) - calc(n - i) - calc(i - 1) + 1);
      sum %= d;
    }

    System.out.print(sum);
  }

  static long calc(long n) {
    return n * (n + 1) / 2;
  }
}

Measured memory_bytes: 27168
#include <bits/stdc++.h>
#define ld double
#define ull unsigned long long
#define ll long long
#define pii pair <int, int>
#define iiii pair <int, pii >
#define mp make_pair
#define INF 1000000000
#define rep(i, x) for(int (i) = 0; (i) < (x); (i)++)
inline int getint() {
  int x = 0, p = 1; char c = getchar();
  while (c <= 32) c = getchar();
  if (c == 45) p = -p, c = getchar();
  while (c > 32) x = x * 10 + c - 48, c = getchar();
  return x * p;
}
using namespace std;
const int mod = 1e9 + 7;
inline void reduce(int &x) { x += x >> 31 & mod; }
inline int mul(int x, int y) { return 1ll * x * y % mod; }
//ruogu_alter
//
int main() {
  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  if (k <= a) return !printf("%lld\n", k);
  if (k <= a + b) return !printf("%lld\n", a);
  k -= a + b;
  printf("%lld\n", a - k);
  return 0;
}


Measured memory_bytes: 3692
#include <stdio.h>
#include <vector>

int N, M;
std::vector<int> G[100004];
int x[100004];

int getPath(int i) {
	if (i >= N)
		return 0;
	if (x[i] != 0)
		return x[i];
	int max = 0;
	int cur;
	int size = G[i].size();
	for (int y = 0; y < size; y++) {
		cur = getPath(G[i][y]) + 1;
		if (cur > max)
			max = cur;
	}
	x[i] = max;
	return max;
}

int longestPath() {
	int max = 0;
	int cur = 0;
	for (int i = 0; i < N; i++) {
		cur = getPath(i);
		if (cur > max)
			max = cur;
	}
	return max;
}

int main()
{
	scanf("%d %d", &N, &M);
	int x, y;
	for (int i = 0; i < M; i++) {
		scanf("%d %d", &x, &y);
		G[x-1].push_back(y-1);
	}
	printf("%d", longestPath());
}

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

using namespace std;
using p=pair<int,int>;
typedef long long ll;

int main() {
  int n,m;
  cin >> n >> m ;
  int k=n*(n-1)/2;
  int f=m*(m-1)/2;
  cout << k+f << endl;
  return 0;

}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
ll ans=0;
int n;
int i;
int main()
{
 ll n,a,b;
 cin>>n>>a>>b;
 ll bei=n/(a+b);
 n-=bei*(a+b);
ans+=bei*a;
ans+=min(n,a);
cout<<ans<<endl;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define PB push_back
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
const ll INF = (1ll << 60);
typedef pair<ll,ll> pii;

ll editDistance(string s1,string s2){
  ll l1=s1.length(),l2=s2.length();
  vvi dp(l1+1,vi(l2+1));
  REP(i,l1+1) dp[i][0]=i;
  REP(i,l2+1) dp[0][i]=i;
  FOR(i,1,l1+1) FOR(j,1,l2+1){
    dp[i][j]=min(dp[i][j-1],dp[i-1][j])+1;
    if(s1[i-1]==s2[j-1]) dp[i][j]=min(dp[i][j],dp[i-1][j-1]);
    else dp[i][j]=min(dp[i][j],dp[i-1][j-1]+1);
  }
  return dp[l1][l2];
}

int main(){
  string s1,s2; cin>>s1>>s2;
  cout<<editDistance(s1,s2)<<endl;
}

Measured memory_bytes: 10716
def main():
    from collections import deque
    N = int(input())
    A = sorted(int(input()) for _ in range(N))

    ans1 = 0
    ans2 = 0
    if N & 1:
        #W型
        a1 = sum(A[N//2+2:])*2+A[N//2+1]+A[N//2]-sum(A[:N//2])*2
        #M型
        a2 = sum(A[N//2+1:])*2-A[N//2]-A[N//2-1]-sum(A[:N//2-1])*2
        print(max(a1,a2))
    else:
        print(sum(A[N//2+1:])*2-sum(A[:N//2-1])*2-A[N//2-1]+A[N//2])










main()

Measured memory_bytes: 82244
K, N = map(int, input().split())
A = list(map(int, input().split()))

D = []
for i in range(N):
    if i == 0:
        D.append(A[i] + K - A[N-1])
    else:
        D.append(A[i] - A[i-1])

print(K - max(D))

Measured memory_bytes: 86140
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <string.h>
#include<iomanip>
#include <iterator>
#include <locale>

#define all(a) a.begin(),a.end()
#define VV(T) vector<vector< T > >
#define rep(i,N) for(int i = 0; i <N; i++)
#define repsg(i,s,g) for(int i = s; i <g; i++)
#define name(x) #x
using namespace std;


const int INF = 10000000;
const long long INFL = (1LL<<40);
const int MOD = pow(10,9)+7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll,LL;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pLL;


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) is >> x;
    return is;
}
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
    for(int i=0; i<vec.size(); i++){
        os << vec[i] << ( i+1 == vec.size() ? "" : " " );
    }
    return os;
}

template< typename T >
struct edge{
    int src, to;T cost;
    edge(int to,T cost) :src(-1),to(to),cost(cost){}
    edge(int src, int to, T cost) :src(src),to(to),cost(cost){}edge
    &operator=(const int &x){
        to =x;
        return *this;
    }
    operator int() const{ return to;}
};

double dist (double a, double b,  double c, double d){
    
    return sqrt((a-c)*(a-c) + (b-d)*(b-d));
    
}

int main() {
    int n;cin>>n;
    vector<int> T(n);cin>>T;
    int m;cin>>m;
    vector<pii> dr(m);
    for(auto i = 0;i<m;i++){
        cin >>dr[i].first >>dr[i].second;
    }
    
    for(auto i=0;i<m;i++){
        int time=0;
        for(auto j=0;j<n;j++){
            if(dr[i].first == j+1) time+=dr[i].second;
            else time+=T[j];
        }
        cout << time << endl;
    }
    
    return 0;
}







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

int main() {
	int N; cin >> N;
	vector<int>A(N + 1), B(N);
	for (auto&& X : A)cin >> X;
	for (auto&& X : B)cin >> X;

	long long sum = 0;
	for (int i = 0; i < A.size() - 1; i++) {
		sum += min(A[i] + A[i + 1], B[i]);
		int tmp = min(A[i], B[i]);
		A[i] -= tmp, B[i] -= tmp;
		A[i + 1] -= min(A[i + 1], B[i]);
	}
	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 1024
import Control.Monad
import Data.List

mul17 xs [] = []
mul17 xs (a:as) = [map (sum . zipWith (*) a) xs] ++ mul17 xs as

main = do
  [n, m, l] <- return . map (\x -> read x :: Int) . words =<< getLine
  a <- replicateM n $ return . map (\x -> read x :: Int) . words =<< getLine
  b <- replicateM m $ return . map (\x -> read x :: Int) . words =<< getLine
  mapM_ (\x -> putStrLn $ unwords . map show $ x) $ transpose $ mul17 a (transpose b)

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

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

    vector<int> a(n + 2);
    for (int i = 0; i < n; i++) cin >> a[i + 1];
    a[0] = a[n + 1] = -1;

    int cnt = 0;
    for (int i = 1; i < n; i++) {
        if (a[i] == i) {
            swap(a[i], a[i + 1]);
            cnt++;
        }
    }
    cout << cnt + (a[n] == n) << endl;

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	string ans="";
	while(n!=0){
		if(n%2!=0){
			n--;
			ans='1'+ans;
		}
		else{
			ans='0'+ans;
		}
		n/=-2;
	}
	if(ans=="") ans="0";
	cout << ans << endl;
}

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

int main() {

	ll n, m; cin >> n >> m;
	vector<pair<ll, ll>> pa;
	ll sum = 0;
	for (ll i = 0; i < n; i++) {
		ll a; cin >> a;
		pa.push_back({ a,1 });
	}
	for (ll i = 0; i < m; i++) {
		ll b, c; cin >> b >> c;
		pa.push_back({ c,b });
	}
	sort(pa.begin(), pa.end(), greater<pair<ll, ll>>());
	ll ans = 0;
	ll cnt = 0;
	while (true) {
		if (pa[cnt].second <= n) {
			ans += pa[cnt].first * pa[cnt].second;
			n -= pa[cnt].second;
		}
		else {
			ans += pa[cnt].first * n;
			break;
		}		
		cnt++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 7388
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <functional>
#include <sstream>
#include <bitset>
using namespace std;

typedef long long ll;

int main() {
  ll A,B;
  cin>>A>>B;
  ll C;
  if (A%2 == 0) {
    if (B%2 == 0) {
      if ((B-A)/2%2 == 0) cout<<B<<endl;
      else cout<<(B^1)<<endl;
    } else {
      if ((B+1-A)/2%2 == 0) cout<<0<<endl;
      else cout<<1<<endl;
    }
  } else {
    if (B%2 == 0) {
      if ((B-1-A)/2%2 == 0) cout<<(A^B)<<endl;
      else cout<<(A^B^1)<<endl;
    } else {
      if ((B-A+1)/2%2 == 0) cout<<A<<endl;
      else cout<<(1^A)<<endl;
    }
  }
  return 0;
}

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

int pow_mod(int a, int b, int c){ // a < 10^5
    if(b == 0) return 1;
    else if(b % 2 == 1) return a * pow_mod(a, b - 1, c) % c;
    else{
        int d = pow_mod(a, b / 2, c);
        return d * d % c;
    }
}

int main(){
    string S;
    cin >> S;
    vector<int> intS;
    for(char c : S) intS.push_back(c - 48);
    reverse(intS.begin(), intS.end());
    int Ssize = intS.size();
    vector<int> dp(Ssize);
    vector<int> rem(2019, 0);
    rem.at(0)++;
    dp.at(0) = intS.at(0);
    rem.at(intS.at(0))++;
    for(int i=1; i<Ssize; i++){
        int work = intS.at(i) * pow_mod(10, i, 2019);
        work = (work + dp.at(i - 1)) % 2019;
        dp.at(i) = work;
        rem.at(work)++;
    }
    int64_t cnt = 0;
    for(int i=0; i<2019; i++){
        int r = rem.at(i);
        if(r != 0)cnt += r * (r - 1) / 2;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 4960
# -*- coding: utf-8 -*-

S = input()

s0 = ''
s1 = ''
for i in range(len(S)):
    if i % 2 == 0:
        s0 += '0'
        s1 += '1'
    else:
        s0 += '1'
        s1 += '0'

change_number_0 = 0
change_number_1 = 0
for i in range(len(S)):
    if S[i] != s0[i]:
        change_number_0 += 1
    if S[i] != s1[i]:
        change_number_1 += 1

if change_number_0 > change_number_1:
    print (change_number_1)
else:
    print (change_number_0)

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

int main() {
    int a, b, c, x;
    cin >> a >> b >> c >> x;
    int count = 0;
    for (int i = 0; i <= a; i++) {
        for (int j = 0; j <= b; j++) {
            for (int k = 0; k <= c; k++) {
                if (500 * i + 100 * j + 50 * k == x) {
                    count++;
                }
            }
        }
    }
    cout << count << endl;
    return 0;
}


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

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int dp[3010][3010];

int main() {
  string s, t;
  cin >> s >> t;
  int n = s.size();
  int m = t.size();
  REP(i, n) REP(j, m) {
    if (s[i] == t[j]) {
      dp[i + 1][j + 1] = dp[i][j] + 1;
    } else {
      dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);
    }
  }
  string ans = "";
  int i = n, j = m;
  while (i && j) {
    if (dp[i][j] == dp[i - 1][j]) {
      i--;
    } else if (dp[i][j] == dp[i][j - 1]) {
      j--;
    } else {
      ans = s[i - 1] + ans;
      i--, j--;
    }
  }
  cout << ans << endl;
  return 0;
}

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

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

/* debugging */
#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cout << name << ": " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<"| ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif


#define boost ios::sync_with_stdio(0); cin.tie(0);
#define int long long

const int N = 1e5 + 10;
const int mod = 1e9 + 7;

int32_t main(){
    boost;
  
    //code
    string s;
    cin >> s;
    int n = (int) s.size();

    int t[n+2] , th[n+2];
    t[0] = th[0] = 1;

    for(int i = 1 ; i <= n+1 ; ++i){
    	t[i] = (t[i-1]*2)%mod;
    	th[i] = (th[i-1]*3)%mod;
    }

    int c = 0 , ans = 0;
    for(int i = 0 ; i < n ; ++i){
    	if(s[i] == '1'){
    		ans += ((t[c]%mod) * (th[n-i-1]%mod))%mod;
    		ans %= mod;
    		c++;
    	}
    }
    ans += t[c];
    ans %= mod;

    cout << ans;
    return 0;
}

Measured memory_bytes: 2000
using System;
using System.IO;
using System.Collections.Generic;

namespace ARC093D
{
    public class Program
    {
        void Solve(StreamScanner ss, StreamWriter sw)
        {
            //---------------------------------
            var A = ss.Next(int.Parse);
            var B = ss.Next(int.Parse);

            var h = 50;
            var w = 100;

            var ret = new char[h, w];

            for (var i = 0; i < h; i++)
            for (var j = 0; j < h; j++)
            {
                ret[i, j] = '#';
                ret[i, j + h] = '.';
            }

            for (var i = 1; i < h - 1; i += 2)
            for (var j = 1; j < h - 1; j += 2)
            {
                A--;
                B--;
                if (A > 0) ret[i, j] = '.';
                if (B > 0) ret[i, j + h] = '#';
            }

            sw.WriteLine($"{h} {w}");
            for (var i = 0; i < h; i++)
            {
                for (var j = 0; j < w; j++) sw.Write(ret[i, j]);
                sw.WriteLine();
            }
            //---------------------------------
        }

        static void Main()
        {
            var ss = new StreamScanner(new StreamReader(Console.OpenStandardInput()));
            var sw = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
            new Program().Solve(ss, sw);
            sw.Flush();
        }

        static readonly Func<string, string> String = s => s;
    }

    public class StreamScanner
    {
        static readonly char[] Sep = {' '};
        readonly Queue<string> buffer = new Queue<string>();
        readonly TextReader textReader;

        public StreamScanner(TextReader textReader)
        {
            this.textReader = textReader;
        }

        public T Next<T>(Func<string, T> parser)
        {
            if (buffer.Count != 0) return parser(buffer.Dequeue());
            var nextStrings = textReader.ReadLine().Split(Sep, StringSplitOptions.RemoveEmptyEntries);
            foreach (var nextString in nextStrings) buffer.Enqueue(nextString);
            return Next(parser);
        }

        public T[] Next<T>(Func<string, T> parser, int x)
        {
            var ret = new T[x];
            for (var i = 0; i < x; ++i) ret[i] = Next(parser);
            return ret;
        }

        public T[][] Next<T>(Func<string, T> parser, int x, int y)
        {
            var ret = new T[y][];
            for (var i = 0; i < y; ++i) ret[i] = Next(parser, x);
            return ret;
        }
    }
}

Measured memory_bytes: 13376
import java.io.InputStreamReader
import java.io.BufferedReader

fun main(args: Array<String>) {
  val br = BufferedReader(InputStreamReader(System.`in`))
  val (A, B, C, D) = br.use { it.readLine().split(" ").map { it.toInt() } }

  val ans = BooleanArray(101, { i ->
      i in A..B-1 && i in C..D-1
    })
    .fold(0) { acc, isPushed ->
      if(isPushed) acc + 1
      else acc
    }

  println(ans)
}

Measured memory_bytes: 35904
#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))

int reach(const vector<vector<int>>& db, int day, int now) {
	int e = 0;
	while (day > 0) {
		if (day & 1)now = db[e][now];
		e++;
		day >>= 1;
	}
	return now;
}

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

	const int D = log2(N) + 1;
	vector<vector<int>> db(D, vector<int>(N));
	rep(i, N)db[0][i] = upper_bound(x.begin(), x.end(), x[i] + L) - x.begin() - 1;
	rep(d, D - 1)rep(i, N) {
		int next = db[d][i];// 2^d
		db[d + 1][i] = db[d][next];// 2^d + 2^d
	}

	// output
	rep(i, Q) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		if (a > b)swap(a, b);

		int l = 0, r = N;
		while (r - l > 1) {
			int mid = (l + r) / 2;
			if (b <= reach(db, mid, a))r = mid;
			else l = mid;
		}
		cout << r << endl;
	}

	return 0;
}


Measured memory_bytes: 9464
#include <bits/stdc++.h>
using namespace std;
   
/* {{{ */
#define CL(N) cout << N << endl
#define DCT(N) cout << "debug " << N << endl
#define REP(i, N) for (int i = 0; i < N; i++)
/* }}} */
   
int main()
{
    double  a, b, c;
           
    cin >> a >> b >> c;
               
    double q = M_PI * c / 180;
                   
    printf("%f\n", a * b / 2 * sin(q));
    printf("%f\n", a + b + sqrt(a * a + b * b - 2 * a * b * cos(q)));
    printf("%f\n", b * sin(q));
 
    return (0);
}

Measured memory_bytes: 3476
#include<stdio.h>
#include<stdlib.h>
int main(){
  int n,i,j;
  int **A;
  int id,num,col;
  scanf("%d",&n);

  A=malloc(sizeof(int *)*n);//二次元配列の動的確保
  for(i=0;i<n;i++){
    A[i]=malloc(sizeof(int)*n);
  }
  for(j=0;j<n;j++){//0に初期化
    for(i=0;i<n;i++){
      A[i][j]=0;
    }
  }
  for(i=0;i<n;i++){//入力
    scanf("%d%d",&id,&num);
    for(j=0;j<num;j++){
      scanf("%d",&col);
      A[id-1][col-1]=1;
    }
  }
  for(j=0;j<n;j++){//出力
    printf("%d",A[j][0]);
    for(i=1;i<n;i++){
      printf(" %d",A[j][i]);
    }
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2048
import sys
S = input()

if S[0] == S[1]:
    print(1, 2)
    sys.exit()

N = len(S)
for n in range(N - 2):
    if S[n] == S[n + 1]:
        print(n + 1, n + 2)
        sys.exit()
    elif S[n] == S[n + 2]:
        print(n + 1, n + 3)
        sys.exit()
print(-1, -1)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int fact(int n){
  int ans=1;
  rep(i,n)ans=ans*(i+1);
  return ans;
}

int main(){    
  int n,a,b; cin>>n;
  
  vector<int> v(n);
  rep(i,n) v[i] = i+1;
  
  int memo=0;
  vector<vector<int>> jis(fact(n), vector<int>(n));

  do {    
    rep(i,n) jis[memo][i]=v[i];
    memo++;
  } while(next_permutation(v.begin(), v.end()));
  
  vector<int> p(n);
  rep(i,n) cin>>p[i];

  rep(i,fact(n)) if(p==jis[i]) a=i;
     
  rep(i,n) cin>>p[i];
  rep(i,fact(n))if(p==jis[i]) b=i;

  cout<<abs(a-b)<<endl;
}

Measured memory_bytes: 3072