akhauriyash/Code-Regression huggingface dataset:
//void _(){
//    int n;
//    cin >> n;
//    vi arr(n);
//    cin >> arr;
//    int k = 0;
//    rep(i,0,n-1)
//        if(abs(arr[i]) > abs(arr[k]))
//            k = i;
//    vpii ans;
//    ans.pb({k+1,k+1});
//    ans.pb({k+1,k+1});
//    if(arr[k] < 0){
//        if(n != k+1)
//            ans.pb({k+1,n});
//        for(int i = n-1; i >= 1; --i){
//            ans.pb({i+1,i});
//            if(i != k+1)
//                ans.pb({i,i});
//        }
//    }
//    else{
//        if(k+1 != 1)
//            ans.pb({k+1,1});
//        rep(i,2,n){
//            ans.pb({i-1,i});
//            if(i != k+1)
//                ans.pb({i,i});
//        }
//    }
//    print(sz(ans));
//    print(ans,"\n");
//}
#include <iomanip>
#include <vector>
#include <utility>
#include <iostream>
#include <string>
#define pb push_back
#define REP_INT(i,l,r) for(int i = l; i <= r; ++i)
#define GET_REP_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define rep(...) GET_REP_MACRO(__VA_ARGS__,REP_ANY,REP_INT)(__VA_ARGS__)
#define all(v) (v).begin(), (v).end()
#define sz(v) ll(v.size())
#define T1 template<typename T> static
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
template <typename F, typename S> static
ostream& operator<<(ostream& stream, const pair<F, S>& t){
    return stream << t.first << ' ' << t.second;
}
T1 ostream& operator<<(ostream& stream, const vector<T>& t);
T1 istream& read(T, T, istream& = cin);
T1 istream& operator>>(istream& stream, vector<T>& t){
    return read(all(t), stream);
}
T1 istream& read(T b, T e, istream& stream){
    for(T it = b; it != e; ++it)
        stream >> *it;
    return stream;
}
T1 void print(T x, string end = "\n"){
    cout << x << end;
}
T1 ostream& print(T b, T e, string sep = " ", ostream& stream = cout){
    for(T it = b; it != e; ++it){
        stream << *it;
        if(it + 1 != e)
            stream << sep;
    }
    return stream;
}
T1 void print(vector<T> arr, string sep = " "){
    if(arr.empty()){
        return;
    }
    print(arr.begin(), arr.end(), sep);
    cout << '\n';
}
void _(){
    int n;
    cin >> n;
    vi arr(n);
    cin >> arr;
    int k = 0;
    rep(i,0,n-1)
        if(abs(arr[i]) > abs(arr[k]))
            k = i;
    vpii ans;
    ans.pb({k+1,k+1});
    ans.pb({k+1,k+1});
    if(arr[k] < 0){
        if(n != k+1)
            ans.pb({k+1,n});
        for(int i = n-1; i >= 1; --i){
            ans.pb({i+1,i});
            if(i != k+1)
                ans.pb({i,i});
        }
    }
    else{
        if(k+1 != 1)
            ans.pb({k+1,1});
        rep(i,2,n){
            ans.pb({i-1,i});
            if(i != k+1)
                ans.pb({i,i});
        }
    }
    print(sz(ans));
    print(ans,"\n");
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
        _();
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int
main(void)
{
	char str[1001];
	char tmp[1001];
	char cmd[16];
	int a, b, q, l;

	scanf("%s %d", str, &q);

	for (int i = 0; i < q; i++) {
		scanf("%s", cmd);
		if (cmd[0] == 'p') {
			scanf("%d %d", &a, &b);
			l = b - a + 1;
			memcpy(tmp, str + a, l);
			tmp[l] = '\0';
			printf("%s\n", tmp);
		} else if (cmd[2] == 'v') {
			scanf("%d %d", &a, &b);
			l = b - a + 1;
			for (int j = 0; j <l; j++)
				tmp[j] = str[b - j];
			memcpy(str + a, tmp, l);
		} else if (cmd[2] == 'p') {
			scanf("%d %d %s", &a, &b, tmp);
			l = b - a + 1;
			memcpy(str + a, tmp, l);
		}
	}

	return 0;
}



Measured memory_bytes: 2136
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
long long n,k,ans;
int main()
{
    cin>>n>>k;
    if(!k)
    {
        cout<<n*n;
        return 0;
    }
    for(int i=k;i<=n;i++)  
    {  
        ans+=n/i*(i-k);  
        if(n%i>=k)  
            ans+=n%i-k+1;  
    }  
    cout<<ans;
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"

map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

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

  ll N;
  cin>>N;
  if(N==1){
    cout<<0<<endl;
    return 0;
  }

  auto M=prime_factor(N);
  ll ans=0;
  for(auto it:M){
    int i=1;
    while(it.second-i>=0){
      it.second-=i;
      ans++;
      i++;
    }
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 3604
#include <iostream>

#include <map>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>

using namespace std;

using ll = long long;
using ii = pair<ll, ll>;

int main()
{
    ios::sync_with_stdio(false);

    ll N, A, B;
    cin >> N >> A >> B;

    ll total = 0;

    ll last;
    cin >> last;

    while (--N)
    {
        ll next;
        cin >> next;

        auto dist = next - last;
//cout << "dist = " << dist << ", Adist = " << A*dist << endl;
        total += (A*dist) > B ? B : A*dist;
//cout << "new total = " << total << endl;
        last = next;
    }

    cout << total << endl;

    return 0;
}


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

typedef pair<int,int> p;
const int INF =1e5;
int R,C=5;
p b[100][100];
bool nb[100][100];
bool f(){
 bool ret = false;
 FOR(i,1,C-1)REP(j,R){
   nb[i][j]=false;
   if(b[i][j].first == INF)continue;
   if(b[i][j].second == b[i-1][j].second)
   if(b[i][j].second == b[i+1][j].second)
     ret = nb[i][j]=true;
 }
 FOR(i,1,C-1)REP(j,R){
    if(nb[i][j]){
       b[i-1][j]={INF,-1};
       b[i][j]={INF,-1};
       b[i+1][j]={INF,-1};   	   
   	}
 }
 REP(i,C){
   sort(b[i],b[i]+R); 
 }
 return ret;
}
int main(){
  while(cin>>R,R){
   REP(i,R)REP(j,C){
     int val;
     cin>>val;
     b[j][R-i-1]={R-i-1,val};
   }
   int ret = 0;
   REP(i,C)REP(j,R)if(b[i][j].second>-1)ret+=b[i][j].second;
   while(f());
   REP(i,C)REP(j,R)if(b[i][j].second>-1)ret-=b[i][j].second;
   cout<<ret<<endl;
  }
  
}


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

#define sz(x) (int)(x.size())
#define FOR(x,y,z) for(int x = y; x <= z; x++)
#define int long long

const int N = 1e5 + 2, inf = 1e18;

int32_t main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);  

    int animals, legs;
    cin >> animals >> legs;
    bool ans = false;
    FOR(i,0,animals){
        int one = i * 2 + 4 * (animals - i);
        int two = i * 4 + 4 * (animals - i);
        ans |= (one == legs) || (two == legs);
    }
    cout << (ans ? "Yes" : "No") << '\n';
}

Measured memory_bytes: 3692
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 111111111;
const int c_mINF = -111111111;
const int c_YET = -1;
const int c_Dx[4] = { 0,0,1,-1 };
const int c_Dy[4] = { 1,-1,0,0 };
const int c_div = 1000000007; //10^9 + 7



int main() {

	int N, A, B, C, D, X, H, W;
	char S[1000], T[1000];
	scanf("%d%d", &A, &B);
	

	if (A <= 9 && B <= 9) {
		printf("%d", A *B);
	}
	else {
		printf("-1");
	}
}



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

int main(){
    int N;
    ll K;
    cin >> N >> K;
    vector<int> A(N);
    for(int i=0; i<N; i++){
        cin >> A[i];
    }
    
    vector<int> s;
    vector<int> ord(N+1, -1);
    int T = 1, l = 0;
    {
        int v = 1;  //top
        while(ord[v] == -1){
            ord[v] = s.size();
            s.push_back(v);
            v = A[v-1];
        }
        l = ord[v];
        T = s.size() - ord[v];
    }

    if(K < l) cout << s[K] << endl;
    else{
        K -= l;
        K %= T;
        cout << s[l+K] << endl;
    }
    return 0;
}

Measured memory_bytes: 5844
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <algorithm>
#include <typeinfo>
#define _USE_MATH_DEFINES
#include <cmath>
#include <stack>
#include <queue>

using namespace std;

typedef struct Node {
    struct Node *prev;
    struct Node *next;
    int val;
} node;

// insert x
// delete x
// deleteFirst
// deleteLast


node* newNode(int val) {
    node *n = new(node);
    n->val = val;
    n->next = NULL;
    n->prev = NULL;
    return n;
}

// 7
// insert 1000000000
// insert 999999999
// deleteLast
// insert 1234566890
// insert 5
// deleteFirst
// insert 7
// delete 5

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

    // Doubly Linked List
    //  [] <-> [] <-> [] ... [] <-> []
    // head                        tail
    node *head = NULL;
    node *tail = NULL;
    string inst;
    int val;

    for (int i = 0; i < num; i++) {
        cin >> inst;
        if (inst == "insert") {
            cin >> val;
            node *n = newNode(val);

            if (head != NULL) {
                head->prev = n;
                n->next = head;
                head = n;
            } else {
                head = n;
                tail = n;
            }
        } else if (inst == "delete") {
            cin >> val;

            node *n = head;
            bool not_found = false;
            while (n->val != val) {                
                if (n == tail) {
                    not_found = true;
                    break;
                }
                n = n->next;
            }
            // 見つからなかった
            if (not_found) {
                continue;
            }

            if (n->prev != NULL && n->next != NULL) {
                n->prev->next = n->next;
                n->next->prev = n->prev;
            } else if (n->prev == NULL && n->next != NULL) {
                head = n->next;
                head->prev = NULL;
            } else if (n->prev != NULL && n->next == NULL) {
                tail = n->prev;
                tail->next = NULL;
            } else {
                head = NULL;
                tail = NULL;
            }
        } else if (inst == "deleteFirst") {
            if (head->next != NULL) {
                head = head->next;
                head->prev = NULL;
            } else {
                head = NULL;
                tail = NULL;
            }
        } else if (inst == "deleteLast") {
            if (tail->prev != NULL) {
                tail = tail->prev;
                tail->next = NULL;
            } else {
                head = NULL;
                tail = NULL;
            }      
        }
    }

    for (node *n = head; ; n = n->next) {
        if (n == tail) {
            cout << n->val << endl;
            break;
        } else {
            cout << n->val << " ";
        }
    }

    return 0;
}



Measured memory_bytes: 37388
import sys
sys.setrecursionlimit(10**6)


def main(input, print):
    N = int(input())
    C = list(input().strip())
    last = N
    ans = 0
    for i in range(N):
        if C[i] == 'W':
            has_r = False
            for j in reversed(range(i+1, last)):
                if C[j] == 'R':
                    ans += 1
                    last = j
                    has_r = True
                    break
            if not has_r:
                break
    print(ans)


if __name__ == '__main__':
    main(sys.stdin.readline, print)


Measured memory_bytes: 77496
def main():
    N, T = map(int, input().split())
    ab = [tuple(map(int, input().split())) for i in range(N)]
    ab.sort(key=lambda x: x[0])
    t = ab[-1][0]
    dp = [-1]*(T+t+1)
    dp[0] = 0
    for a, b in ab:
        for i in range(T-1, -1, -1):
            if dp[i] < 0:
                continue
            if dp[i+a] < dp[i]+b:
                dp[i+a] = dp[i]+b
    ans = max(dp)
    print(ans)
main()


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

int main(){
  int n;
  cin >> n;
  int c0,c1,c2,c3;
  c0 = c1 = c2 = c3 = 0;
  for (int i = 0; i < n; i++){
    string s;
    cin >> s;
    if (s == "AC") c0++;
    else if (s == "WA") c1++;
    else if (s == "TLE") c2++;
    else if (s == "RE") c3++;
  }
  cout << "AC x " << c0 << endl;
  cout << "WA x " << c1 << endl;
  cout << "TLE x " << c2 << endl;
  cout << "RE x " << c3 << endl;
}

Measured memory_bytes: 3604
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
int main(){
  int n,m,d[11][10010],ans,t,a;
  while(cin>>n>>m&&n&&m){
    rep(i,n)rep(j,m)cin>>d[i][j];
    ans=0;
    rep(i,1<<n){
      t=0;
      rep(j,m){
        a=0;
        rep(k,n)a+=(d[k][j]+!!(i&(1<<k)))%2;
        t+=max(a,n-a);
      }
      ans=max(ans,t);
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 1552
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int w = s.nextInt();
        int[] weights = new int[n];
        long[] values = new long[n];

        for (int i = 0; i < n; i++) {
            weights[i] = s.nextInt();
            values[i] = s.nextInt();

        }
        long res = knapsack(weights, values, 0, w, new long[n + 1][w + 1]);
        System.out.println(res);
    }

    private static long knapsack(int[] weights, long[] values, int si, int w, long[][] dp) {
        if (si == weights.length) {
            return 0;
        }
        if (dp[si][w] != 0) {
            return dp[si][w];
        }
        long rr = knapsack(weights, values, si + 1, w, dp);

        if (weights[si] <= w) {
            long cr = knapsack(weights, values, si + 1, w - weights[si], dp) + values[si];
            rr = Math.max(rr, cr);
        }

        dp[si][w] = rr;
        return rr;

    }
}


Measured memory_bytes: 140856
n,a,b = map(int,input().split())

if (b-a) % 2 == 0:
	ans = (b-a) // 2
else:
	if a-1 < n-b:
		ans = b-1
		x = b-(a-1)-1
		ans = min(ans, a + (x-1) // 2)
	else:
		ans = n-a
		x = a + (n-b) + 1
		ans = min(ans, (n-b) + 1 + (n-x) // 2)

print(ans)


Measured memory_bytes: 3060
#include <iostream>
using namespace std;
typedef long long LL;
int main(){
    int N,M;
    cin >>N>>M;
    if(abs(N-M)>1)cout<<0<<endl;
    else{
        LL a=1,b=1;
        for(int i=1;i<N+1;i++){
            a=a*i%1000000007;
        }
        for(int i=1;i<M+1;i++){
            b=b*i%1000000007;
        }
        if(M==N)cout<<a*b%1000000007*2%1000000007<<endl;
        else cout<<(a*b)%1000000007<<endl;
    }
}

Measured memory_bytes: 256
class UnionFind():
  def __init__(self, N):
    self.par = [i for i in range(N)]
 
  def root(self, x):
    if self.par[x] == x:
      return x
    else:
      self.par[x] = self.root(self.par[x])
      return self.par[x]
  
  def unite(self, x, y):
    self.par[self.root(y)] = self.root(x)
    
  def same(self, x, y):
    return self.root(x) == self.root(y)

N, M = map(int, input().split())
p = list(map(int, input().split()))
uf = UnionFind(N)

for i in range(M):
  x, y = map(int, input().split())
  uf.unite(x-1, y-1)
  
r = 0
for i in range(N):
  r += uf.same(i, p[i] - 1)
print(r)

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

int gcd(long long a, long long b) { return b != 0 ? gcd(b, a % b) : a; }
// cout << fixed << setprecision(10);
// vector<vector<int>> vec(H, vector<int>(W))    // int H*W

int main() {
    int A, B;
    cin >> A >> B;
    int ans = 0;
    int current = 1;
    while(current < B){
        current += A-1;
        ans++;
    }

    cout << ans << endl;
}

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

int main()
{
  int a , b , c , X , x , y , z;
  cin >> X ;
  x = X / 500 ;
  a = x ;
  y = X % 500 ;
  b = y ;
  z = b / 5 ;
  c = z ; 
  cout << a*1000 + c*5 << endl ;

return 0;
}


Measured memory_bytes: 256
//{{{
#include<algorithm>
#include<cmath>
#include<deque>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(printde) FUNC(printdbe) FUNC(printdwe) FUNC(printdu) FUNC(printe) FUNC(printe0);
#endif
template <template <class T, class = std::allocator<T>> class V, class E>
istream& operator >> (istream& in, V<E>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<ll> as(n + 1); cin >> as;
    vector<ll> mas(n + 1);
    ll num = 1;
    for(int i = 0; i <= n; i++){
        if(num == 0 || num < as[i]){
            cout << -1 << '\n';
            return 0;
        }
        num = min(num, (ll)1e16);
        mas[i] = num;
        num = (num - as[i]) * 2;
        // num = num * 2 - as[i];
    }
    printde(as);
    printde(mas);
    ll ans = 0, prev = 0;
    for(int i = n; i >= 0; i--){
        prev = min(mas[i], as[i] + prev);
        ans += prev;
        // ans += min(mas[i], as[i]);
        printde(i, prev, ans);
    }
    cout << ans << '\n';
    // int ans = (1 << (n + 1)) - 1;
    // for(int i = 0; i <= n; i++){
    //     int a; cin >> a;
    //     ans -= a * ((1 << (n - i + 1)) - 2);
    //     printde(i, a, ans);
    // }
    // cout << ans << '\n';
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using i64 = long long;

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

    std::vector<std::tuple<int, int, int>> es;
    std::vector<std::pair<int, int>> w;
    for (int i = 0; i < m; i++) {
        int p, q, c;
      	scanf("%d%d%d", &p, &q, &c);
        --p; --q;
        es.emplace_back(p, q, c);
        w.emplace_back(p, c);
        w.emplace_back(q, c);
    }

    std::sort(w.begin(), w.end());
    w.erase(std::unique(w.begin(), w.end()), w.end());

    auto get = [&](int v, int c) {
        return n + std::lower_bound(w.begin(), w.end(), std::make_pair(v, c)) - w.begin();
    };

    std::vector<std::vector<std::pair<int, int>>> g(w.size() + n);
    for (const auto &e : w) {
        int v = get(e.first, e.second);
        g[e.first].emplace_back(v, 1);
        g[v].emplace_back(e.first, 0);
    }
    for (const auto &e : es) {
        auto p = std::get<0>(e), q = std::get<1>(e), c = std::get<2>(e);
        int pv = get(p, c), qv = get(q, c);
        g[pv].emplace_back(qv, 0);
        g[qv].emplace_back(pv, 0);
    }

    constexpr int inf = std::numeric_limits<int>::max() / 2;
    std::vector<int> dist(g.size(), inf);
    std::deque<int> q { 0 };
    dist[0] = 0;
    while (!q.empty()) {
        int v = q.front();
        q.pop_front();
        for (auto to : g[v]) {
            if (dist[to.first] <= dist[v] + to.second) continue;
            dist[to.first] = dist[v] + to.second;
            if (to.second) q.push_back(to.first);
            else q.push_front(to.first);
        }
    }

	printf("%d\n", dist[n - 1] == inf ? -1 : dist[n - 1]);
  
    return 0;
}


Measured memory_bytes: 38656
let m = 1039999

let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let to_x = Array.make 128 0

let to_key s =
  let ret = ref 0 in
  let p = ref 1 in
  for i = 0 to String.length s - 1 do
    ret := !ret + !p * (to_x.(Char.code s.[i]));
    p := 5 * !p;
  done;
  !ret

let to_h1 k = k mod m
let to_h2 k = 1 + (k mod (m - 1))

let insert s t =
  let k = to_key s in
  let h1 = to_h1 k in
  let h2 = to_h2 k in
  let rec doit i =
    let h = (h1 + h2*i) mod m in
    if t.(h) = s then ()
    else if t.(h) = "\000" then t.(h) <- s
    else doit (i + 1) in
  doit 0

let find s t =
  let k = to_key s in
  let h1 = to_h1 k in
  let h2 = to_h2 k in
  let rec doit i =
    let h = (h1 + h2*i) mod m in
    if t.(h) = s then true
    else if t.(h) = "\000" then false
    else doit (i + 1) in
  doit 0

let () =
  to_x.(Char.code 'A') <- 1;
  to_x.(Char.code 'C') <- 2;
  to_x.(Char.code 'G') <- 3;
  to_x.(Char.code 'T') <- 4;
  let n = read_int () in
  let t = Array.make m "\000" in
  for _ = 0 to n - 1 do
    match split_on_char ' ' (read_line ()) with
    | ["find"; s] -> print_endline (if find s t then "yes" else "no")
    | [_; s] -> insert s t
    | _ -> assert false
  done

Measured memory_bytes: 20708
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>

using namespace std;

int main() {
  int a[5], k;
  for (int i = 0; i < 5; i++) {
    cin >> a[i];
  }
  cin >> k;
  
  for (int i = 0; i + 1 < 5; i++) {
    for (int j = i + 1; j < 5; j++) {
      if (a[j] - a[i] > k) {
        cout << ":(\n";
        return 0;
      }
    }
  }
  cout << "Yay!\n";
}

Measured memory_bytes: 256
#D
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BandC = [list(map(int, input().split())) for _ in range(Q)]

temp = [0] * (10 ** 5 + 1)
for i in range(N):
    temp[A[i]] += 1
    
s = sum(A)

for i in range(Q):
    num = BandC[i][0]
    num_temp = temp[BandC[i][0]]
    temp[BandC[i][0]] = 0
    temp[BandC[i][1]] += num_temp
    s = s - BandC[i][0] * num_temp + BandC[i][1] * num_temp
    print(s)

Measured memory_bytes: 32292
use proconio::input;
use proconio::marker::{Bytes, Chars, Isize1, Usize1};

fn main() {
    input! {
        n: usize,
        x: usize,
        t: usize
    }

    let ans = if n%x == 0 {t*(n/x)} else {t*(n/x)+t};

    println!("{}",ans)
}

Measured memory_bytes: 2148
from collections import deque

N, M = map(int, input().split())

tree = dict(zip([i for i in range(N)], [[] for i in range(N)]))
for i in range(M):
  X, Y, Z = map(int, input().split())
  tree[X-1].append(Y-1)
  tree[Y-1].append(X-1)


ans = 0
is_used = [False]*N
for i in range(N):
  if is_used[i]:
    continue
  
  ans += 1
  is_used[i] = True
  d = deque([i])
  while d:
    node = d.pop()
    children = tree[node]
    for child in children:
      if is_used[child]:
        continue
      
      is_used[child] = True
      d.append(child)

print(ans)

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

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


Measured memory_bytes: 3084
# 1対1なので決めていく
s, t = input(), input()
sd, td = {}, {}
for i in range(len(s)):
    if t[i] not in td and s[i] not in sd:
        sd[s[i]] = t[i]
        td[t[i]] = s[i]
    elif t[i] in td and s[i] in sd and td[t[i]] == s[i] and sd[s[i]] == t[i]:
        continue
    else:
        print("No")
        exit()
print("Yes")


Measured memory_bytes: 3632
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    cur = A
    for _ in range(K):
        prev = cur
        cur = [0] * N
        pls = [0] * (N+1)
        for i in range(N):
            l = max(i - prev[i], 0)
            r = min(i + prev[i], N-1)
            pls[l] += 1
            pls[r+1] -= 1
        num = 0
        for i in range(N):
            num += pls[i]
            cur[i] = num
        same = True
        for i in range(N):
            if cur[i] != prev[i]:
                same = False
                break
        if same:
            break
    print(*cur)


if __name__ == "__main__":
    main()


Measured memory_bytes: 164208
#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define INF 999999999
using namespace std;

typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

void shortestPath(const Graph &g, int s,
    vector<Weight> &dist, vector<int> &prev) {
  int n = g.size();
  dist.assign(n, INF); dist[s] = 0;
  prev.assign(n, -1);
  priority_queue<Edge> Q; // "e < f" <=> "e.weight > f.weight"
  for (Q.push(Edge(-2, s, 0)); !Q.empty(); ) {
    Edge e = Q.top(); Q.pop();
    if (prev[e.dst] != -1) continue;
    prev[e.dst] = e.src;
    FOR(f,g[e.dst]) {
      if (dist[f->dst] > e.weight+f->weight) {
        dist[f->dst] = e.weight+f->weight;
        Q.push(Edge(f->src, f->dst, e.weight+f->weight));
      }
    }
  }
}

int main(){
	int r,i,V,E,s,t,e;
	//for(scanf("%d",&T);T;putchar(--T?' ':'\n')){
		scanf("%d%d%d",&V,&E,&r);
		Graph g(V);
		vector<Weight> dist;
		vector<int> prev;
		for(;E--;)scanf("%d%d%d",&s,&t,&e),g[s].push_back(Edge(s,t,e));
		shortestPath(g,r,dist,prev);
		for(i=0;i<V;i++){
			if(dist[i]>=INF)puts("INF");
			else printf("%d\n",dist[i]);
		}
	//}
}

Measured memory_bytes: 14540
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

using pi = pair<int,int>;

const int N = 600*600;
set<int> G[N];

vector<pi> solve(){
    int n,D[2];
    cin >>n;
    rep(i,2) cin >>D[i];

    vector<pi> aa[2];
    rep(i,2*n)rep(j,2*n){
        int dist = i*i + j*j;
        rep(k,2)if(dist == D[k]) aa[k].pb({i,j});
    }

    auto ID = [&](int y, int x){
        return 2*n*y + x;
    };

    auto IN = [&](int y, int x){
        return 0<=y && y<2*n && 0<=x && x<2*n;
    };

    int V = 2*n*2*n;
    vector<int> X(V);

    rep(AA,2){
        rep(i,N) G[i].clear();

        rep(i,2*n)rep(j,2*n){
            for(pi a:aa[AA]){
                for(int p=-1; p<=1; p+=2)for(int q=-1; q<=1; q+=2){
                    int y = i+a.fi*p, x = j+a.se*q;
                    if(IN(x,y)) G[ID(i,j)].insert(ID(y,x));
                }
            }
        }

        const int INF = 19191919;
        vector<int> d(V, INF);
        rep(i,V)if(d[i]==INF){
            vector<int> cc;
            queue<int> que;

            d[i] = 0;
            cc.pb(i);
            que.push(i);
            while(!que.empty()){
                int now = que.front();
                que.pop();
                for(int nx:G[now]){
                    if(d[nx] > d[now]+1){
                        d[nx] = d[now]+1;
                        cc.pb(nx);
                        que.push(nx);
                    }
                }
            }

            for(int j:cc){
                if(d[j]%2==1) X[j] |= (1<<AA);
            }
        }
    }

    int ct[4]={};
    rep(i,V) ++ct[X[i]];

    int idx = -1;
    rep(i,4)if(ct[i]>=n*n) idx = i;
    assert(idx != -1);

    vector<pi> ans;
    rep(i,V) if(X[i]==idx) ans.pb({i/(2*n), i%(2*n)});
    ans.resize(n*n);
    return ans;
}

int main(){
    vector<pi> ans = solve();
    for(const auto &p:ans) printf("%d %d\n", p.fi, p.se);
    return 0;
}


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

int main(){ 
    int n;
    cin >> n;
    double ans;
    if(n %2==0){
        ans = 1/2;
        cout << 0.5 << endl;
    }
    else {
        ans = n/2 +1;
        ans /= n;
        cout << ans << endl;
    }
 }

Measured memory_bytes: 256
main = do
    getLine
    d <- readLn
    ns <- getLine
    print $ sum $ map (f d) $ map read (words ns)
      where
        f :: Int -> Int -> Int
        f ds p
          | (ds - p) < (p - 0) = 2 * (ds - p)
          | otherwise          = 2 * p

Measured memory_bytes: 1020
#include<iostream>
#include<string>
using namespace std;
int main(){
  int ans = 0;
  string num;
  cin >> num;
  for(int i = 0; i < num.length(); ++i){
    if(num[i] == '1'){
      ans += 1;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace  std;
int main()
{
  int n;cin>>n;
int a[n];
for(int i=0;i<n;i++)cin>>a[i];
sort(a,a+n);
double s  = ((double)a[0]+a[1])/2;
for(int i=2;i<n;i++)
{
s=(s+a[i])/2.0;}
cout<<fixed<<setprecision(6)<<s;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define pii pair<int, int>
#define keep_calm_and_become_orange ios_base::sync_with_stdio(0)
#define utochka_po_imeni_jonathan_livingston cin.tie(0)
 
using namespace std;
 
void yes() {
    cout << "YES" << endl;
}
 
void no() {
    cout << "NO" << endl;
}
 
long long bp(long long a, long long p, long long mod) {
    if (p == 0) {
        return 1ll;
    } else if (p % 2 == 1) {
        return bp(a, p - 1, mod) * a % mod;
    } else {
        long long res = bp(a, p / 2, mod);
        return res * res % mod;
    }
}

const long long mod = 1e9 + 7;

void solve(int qq) { 
    int n; string s;
    cin >> n >> s;
    vector<vector<long long> > dp(n + 1, vector<long long>(n + 1, 0));
    dp[1][1] = 1;
    for (int len = 2; len <= n; len++) {
        for (int i = 1; i < len; i++) {
            dp[len - 1][i] += dp[len - 1][i - 1];
            dp[len - 1][i] %= mod;
        }
        for (int last = 1; last <= len; last++) {
            int l, r;
            if (s[len - 2] == '>') {
                l = last;
                r = len - 1;
            } else {
                l = 1;
                r = last - 1;
            }
            if (l <= r) {
                dp[len][last] += (dp[len - 1][r] - dp[len - 1][l - 1] + mod);
                dp[len][last] %= mod;
            }
        }
    }
    long long ans = 0;
    for (int last = 1; last <= n; last++) {
        ans += dp[n][last];
        ans %= mod;
    }
    cout << ans << endl;
}   
 
int main()
{
    keep_calm_and_become_orange;
    utochka_po_imeni_jonathan_livingston;
 
    int t; t = 1;
    for (int i = 1; i <= t; i++) {
        solve(i);
    }
    return 0;
}

Measured memory_bytes: 70784
#include<bits/stdc++.h>
#define pi 3.14159
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
const int N = 2e7 + 9, M = 1e7, OO = 0x3f3f3f3f;
int n, array1[100010];
bool checked[100010];
int main() {
    int i,j;
    scanf("%d",&n);
    for(i=0;i<n;++i){
        scanf("%d",&array1[i]);
    }
    int ans = 0;
    for(i=0;i<n;++i) {
        if(!checked[i]) {
        checked[i] = true;
        for(j=i+1;j<n;++j) {
            if(array1[j - 1] < array1[j])
                break;
            checked[j] = true;
            ans=max(ans,j-i);
        }
        }
    }
printf("%d",ans);
}

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

vector< vector< vector<long long> > > dp;
vector< vector<long long> > items;
int R,C,K;

void step(int i,int j,int k){
    if(j<C){
        if((items.at(i).at(j+1)>0)&&(k<=2)){
            dp.at(i).at(j+1).at(k+1)=max(dp.at(i).at(j+1).at(k+1),dp.at(i).at(j).at(k)+items.at(i).at(j+1));
        }
        dp.at(i).at(j+1).at(k)=max(dp.at(i).at(j+1).at(k),dp.at(i).at(j).at(k));
    }
    if(i<R){
        if(items.at(i+1).at(j)>0){
            dp.at(i+1).at(j).at(1)=max(dp.at(i+1).at(j).at(1),dp.at(i).at(j).at(k)+items.at(i+1).at(j));
        }
        dp.at(i+1).at(j).at(0)=max(dp.at(i+1).at(j).at(0),dp.at(i).at(j).at(k));
    }
}

int main(){
    cin >> R >> C >> K;
    dp=vector< vector< vector<long long> > >(R+1,vector< vector<long long> >(C+1,vector<long long>(4,0)));
    items=vector< vector<long long> >(R+1,vector<long long>(C+1,0));
    for(int i=0;i<K;i++){
        int r,c,v; cin >> r >> c >> v;
        items.at(r).at(c)=v;
    }
    for(int i=0;i<=R;i++){
        for(int j=0;j<=C;j++){
            for(int k=0;k<=3;k++){
                step(i,j,k);
            }
        }
    }
    long long ans=0;
    for(int k=0;k<=3;k++){
        ans=max(ans,dp.at(R).at(C).at(k));
    }
    cout << ans << endl;
}

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


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


int main(){
    ll N,X; cin>>N>>X;
    vector<ll> x(N);
    for (ll i = 0; i < N; i++){
        cin>>x[i]; //都市の座標
        x[i]=abs(X-x[i]);
    }
    ll ans=gcd(x[0],x[1]);
    for (ll i = 2; i < N; i++){
        ans=gcd(ans,x[i]);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3976
#include<stdio.h>
int main()
{

  long long int s,i,j,temp,a[20];
  for(i=0;i<10;i++)
  scanf("%lld",&a[i]);
    for(i=0;i<10;i++)
    {
        for(j=i+1;j<10;j++)
        {
           if(a[i]<a[j])
           {
               temp=a[i];
              a[i]=a[j];
              a[j]=temp;
           }
      }
  }
  for(i=0;i<3;i++)
    printf("%lld\n",a[i]);

  return 0;
}

Measured memory_bytes: 600
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
const int N=100005;
int n,m,i,j,k,c[N],sum[N],p[N];
char s[N];
vector<int> vct[N];
int find(int x)
{
	return !p[x]?x:p[x]=find(p[x]);
}
int main()
{
	scanf("%s",s+1);
	m=strlen(s+1);
	for(i=1;i<=m/2;++i)
		c[i]=(s[m-i+1]-s[i]+26)%26;
	scanf("%d",&n);
	for(i=1;i<=n;++i)
	{
		scanf("%d%d",&j,&k);
		if(j==m-k+1)
			continue;
		if(k<=m/2)
			vct[j].push_back(k);
		else if(j>m/2)
			vct[m-k+1].push_back(min(m/2,m-j+1));
		else if(j<=m-k)
			vct[j].push_back(m-k);
		else
		{
			j=m-j+1,k=m-k+1;
			swap(j,k);
			vct[j].push_back(m-k);
		}
	}
	for(i=m/2+1;i>=1;--i)
		sum[i]=(c[i]=(c[i]-c[i-1]+26)%26);
	for(i=1;i<=m/2;++i)
		for(j=vct[i].size()-1;j>=0;--j)
		{
			if(find(i)!=find(vct[i][j]+1))
			{
				sum[find(vct[i][j]+1)]=(sum[find(vct[i][j]+1)]+sum[find(i)])%26;
				p[find(i)]=find(vct[i][j]+1);
			}
		}
	for(i=1;i<=m/2+1;++i)
		if(find(i)==i&&sum[i])
		{
			printf("NO");
			return 0;
		}
	printf("YES");
	return 0;
}


Measured memory_bytes: 4608
from collections import Counter 
import itertools

N = int(input())
D = list(map(int, input().split()))
D.append(12)
M = Counter(D)
if max(M.values()) > 2:
    print(0)
elif 0 in D:
    print(0)
elif N > 11:
    print(1)
else:
    D.remove(12)
    D = [[x, 24-x] for x in D]
    generator = list(itertools.product([0, 1], repeat=N))
    D_gen = [[D[i][g[i]] for i in range(N)] for g in generator]
    ans = 0
    for d in D_gen:
        if len(set(d)) < N:
            pass
        else:
            tmp = [0] + sorted(d) + [24]
            s = 13
            for i in range(N+1):
                s = min(s, tmp[i+1]-tmp[i])
            ans = max(ans, s)
    print(ans)


Measured memory_bytes: 41200
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
ll mod = 1000000007;

const int N = 100;
const int INF = (1 << 21);

int n, M[N][N];
int d[N];

void bfs(int s) {
    queue<int> Q;
    Q.push(s);
    rep(i, n) {
        d[i] = INF;
    }
    d[s] = 0;
    int u;
    while( !Q.empty() ) {
        u = Q.front();
        Q.pop();
        rep(v, n) {
            if(M[u][v] == 0) {
                continue;
            }
            if(d[v] != INF) {
                continue;
            }
            d[v] = d[u] + 1;
            Q.push(v);
        }
    }

    rep(i, n) {
        cout << i+1 << " " << ( (d[i] == INF) ? (-1) : d[i] ) << endl;
    }
}

int main() {
    int u, k, v;

    cin >> n;
    rep(i, n) {
        rep(j, n) {
            M[i][j] = 0;
        }
    }

    rep(i, n) {
        cin >> u >> k;
        u--;
        rep(j, k) {
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }

    bfs(0);
    
    return 0;
}


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

const int MAX = 500000, MS = 2;
const long long mod[] = {999999937LL, 1000000007LL}, base = 9973;
struct rolling_hash {
    int n;
    vector<long long> hs[MS], pw[MS];
    rolling_hash(){}
    rolling_hash(const string &s) {
        n = s.size();
        for (int i = 0; i < MS; i++) {
            hs[i].assign(n+1,0);
            pw[i].assign(n+1,0);
            hs[i][0] = 0;
            pw[i][0] = 1;
            for (int j = 0; j < n; j++) {
                pw[i][j+1] = pw[i][j]*base%mod[i];
                hs[i][j+1] = (hs[i][j]*base+s[j])%mod[i];
            }
        }
    }

    long long hash(int l, int r, int i) { return ((hs[i][r]-hs[i][l]*pw[i][r-l])%mod[i]+mod[i])%mod[i]; }

    bool match(int l1, int r1, int l2, int r2) {
        bool ret = 1;
        for (int i = 0; i < MS; i++) ret &= hash(l1,r1,i)==hash(l2,r2,i);
        return ret;
    }

    bool match(int l, int r, long long h[]) {
        bool ret = 1;
        for (int i = 0; i < MS; i++) ret &= hash(l,r,i)==h[i];
        return ret;
    }
};

int main(void){
    int n;
    cin >> n;
    vector<ll> a(n), b(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];

    string sa, sb; //2倍文字列
    rep(i,n){
        ostringstream sout;
        sout << setfill('0') << setw(10) << (a[i] ^ a[(i+1)%n]);
        sa += sout.str();
        sout.str("");
        sout << setfill('0') << setw(10) << (b[i] ^ b[(i+1)%n]);
        sb += sout.str();
    }
    rolling_hash ra(sa+sa), rb(sb);
    rep(k,n){
        if (ra.hash(k*10, k*10 + n*10, 0) == rb.hash(0, n*10, 0)) {
            cout << k << " " << (a[k] ^ b[0]) << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 198116
import java.io.*;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int a[] = new int[10];
		int b[] = new int[3];
		b[0]=b[1]=b[2]=0;
		for(int i = 0;i <=9;i++){
			 String s = br.readLine();	 
			a[i] = Integer.parseInt(s);
		}
		java.util.Arrays.sort(a);
		for(int i = 9;i >=7;i--){
			System.out.println(a[i]);
		}
		System.exit(0);
	}
}

Measured memory_bytes: 9320
input_data = STDIN.gets
input_array = input_data.split(" ")
w = input_array[0].to_i
h = input_array[1].to_i
x = input_array[2].to_i
y = input_array[3].to_i
r = input_array[4].to_i

if (x+r <= w) && (x-r >= 0) then
  if (y+r <= h) && (y-r >= 0) then
    print "Yes\n"
  else
    print "No\n"
  end
else
  print "No\n"
end

Measured memory_bytes: 8668
while n = gets.to_i
    exit if n==0
    top= 1
    front = 2
    side = 3
    sum = 1

    n.times do
        dr = gets.chomp!
        t = top
        f = front
        s =  side

        case dr
        when "North" then
            top = f
            front = 7- t
        when  "East" then
            side = t
            top = 7 - s
        when "West" then
            top = s
            side = 7 - t
        when "South" then
            front = t
            top = 7 - f
        when "Right" then
            front = s
            side = 7 - f
        when "Left" then
            side = f
            front = 7 - s
        else
        end
        
        sum += top
    end

    puts "#{sum}\n"
end



Measured memory_bytes: 6880
import math
N=int(input())
A=list(map(int,input().split()))

B=[A[i]-i for i in range(N)]
B.sort()
temp=0

if N%2==0:
  ans = B[N//2]
  ans2= B[N//2 -1]
  temp=0
  for j in range(N):
    temp+= abs(B[j] - ans)
  temp2=0
  for j in range(N):
    temp2+= abs(B[j] - ans2)
  ans= min(temp,temp2)
else:
  ans = B[N//2]
  temp=0
  for j in range(N):
    temp+= abs(B[j] - ans )
  ans=temp
print(ans)



Measured memory_bytes: 26608
N = int(input())
s = [int(input()) for i in range(N)]
s_shadow = [i for i in s if i % 10 != 0]
ans = sum(s)

if ans % 10 == 0:
    if len(s_shadow) == 0:
        ans = 0
    
    else:
        s_can = sorted([ans-i for i in s_shadow])
        ans = s_can[-1]
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n, m, ans = 0;
  cin >> n >> m;
  vector<int> v(n);
  vector<vector<bool>> graph(n, vector<bool> (n,0));
  for(int i=0; i<n; i++) v[i] = i;
  for(int i=0; i<m; i++){
    int a, b;
    cin >> a >> b;
    graph[--a][--b] = true;
    graph[b][a] = true;
  }
  do{
    bool flag = true;
    for(int i=1; i<n; i++) flag &= graph[v[i-1]][v[i]];
    ans += flag;
  }while(next_permutation(v.begin() + 1, v.end()));
  cout << ans << endl;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define int ll
#define upto(a, b, i) for(int i = (a),b_ =(b); i <= b_; ++i)
#define uptil(a, b, i) for(int i = (a),b_ =(b); i < b_; ++i)
#define downto(a, b, i) for(int i = (a),b_ =(b); i >= b_; --i)
#define downtil(a, b, i) for(int i = (a),b_ =(b); i > b_; --i)
#define times(n, i) uptil(0, (n), i)
#define rtimes(n, i) downto((n) - 1,0, i)
#define size(a) ((int)(a).size())
#define ln << endl
#define sp << " "

template<class T> using vec = vector<T>;
template<class T> using vvec = vec<vec<T>>;

constexpr int mod = 1e9 + 7;

void solve() {
  int N,M; cin>>N>>M;
  vec<int> S(N), T(M);
  times(N, i) cin>>S[i];
  times(M, j) cin>>T[j];

  vvec<int> dp(N+1, vec<int>(M+1, 1));

  upto(1, N, i) upto(1, M, j) {
    dp[i][j] = (dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1] * (S[i-1] != T[j-1]) + mod) % mod;
  }
  cout << dp[N][M] ln;
}

signed main() {
  cout << fixed << setprecision(20);
  cerr << fixed << setprecision(6);
  solve();
  return 0;
}


Measured memory_bytes: 31616
#include<iostream>
#include<string>
using namespace std;
int main(){
    string s,ans = "";
    cin >> s;
    for(int i=0;i<s.length();i++){
        if(s[i] == 'B'){
            if(! ans.empty()) ans.pop_back();
        }
        else{
            ans.push_back(s[i]);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 764
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int k = sc.nextInt();
        Set<String> set = new HashSet<>();
        for (int i = 0; i < s.length(); i++) {
            int offset = i + 1;
            for (int j = offset; j < Math.min(s.length() + 1, offset + k + 1); j++) {
                set.add(s.substring(i, j));
            }
        }
        List<String> list = new ArrayList<>(set);
        Collections.sort(list);
        System.out.println(list.get(k - 1));
        sc.close();
    }
}

Measured memory_bytes: 40716
#include<iostream>
#define N 45
using namespace std;

int A[N];
int main(){
    int i,n;
    cin>>n;
    A[0]=1; A[1]=1;
    for(int i=2;i<=n;i++){
        A[i]=A[i-2]+A[i-1];
    }
    cout<<A[n]<<endl;
    return 0;
}



Measured memory_bytes: 3120
#include <bits/stdc++.h>
#define Mashu cout << "UUZ ate it." << endl
#define RE register int
#define ll long long
using namespace std;

template <typename T> void read(T &x){
	int f = 1; x = 0; char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}

int main(){
	int a, b;
	cin >> a >> b;
	int mx = max(a, b);
	int n;
	cin >> n;
	if (n % mx == 0){
		cout << n / mx << endl;
	}
	else cout << n / mx + 1 << endl;
	return 0;
	Mashu;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    long n, q, count = 1, a = 1;
    scanf("%ld %ld", &n, &q);
    a *= q;
    while (n >= a)
    {
        count++;
        a *= q;
    }
    printf("%ld\n", count);

    return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <utility>
#include <vector>
#include <string>
#include <tuple>
#include <algorithm>
using namespace std;

#define gcu getchar_unlocked
#define pcu putchar_unlocked
#define _il inline
#define _in _il int in
#define _sc _il bool scan
template <typename T>
T in(int c){T n=0;bool m=false;if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0');return m?-n:n;} //&&c<='9'
_in() {return in<int>(gcu());}
template <typename T>
T scan(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
_sc(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
template <typename H,typename... T> _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _vo _il void out
#define _vl _il void outl
template <typename T>
_vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
_vo(const char *s){while(*s)pcu(*s++);}
_vo(char c){pcu(c);}
_vo(string &s){for (char c: s) pcu(c);}
_vo(string s){for (char c: s) pcu(c);}
template <typename H,typename... T> _vo(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename T> _vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
_vl(){out('\n');}
template <typename... T> _vl(T&&... t){out(move(t)...);outl();}

int main() {
	vector<tuple<int, int, char, long, string>> v(in());
	for (auto &t: v) {
		int v, w;
		char c;
		long d;
		string s;
		scan(v, w, c, d, s);
		t = make_tuple(v, w, c, d, s);
	}
	sort(v.begin(), v.end());
	for (auto t: v)
		outl((int) get<0>(t), ' ', get<1>(t), ' ', get<2>(t), ' ', get<3>(t), ' ', get<4>(t));
}


Measured memory_bytes: 11684
class in{struct It{int it;const bool rev;explicit constexpr It(int it_, bool rev=false):it(it_),rev(rev){}int operator*(){return it;}bool operator!=(It& r){return it!=r.it;}void operator++(){rev?--it:++it;}};const It i,n;public:explicit constexpr in(int n):i(0),n(n<0?0:n){}explicit constexpr in(int i,int n):i(i,n<i),n(n){}const It& begin(){return i;}const It& end(){return n;}};

#include <bits/stdc++.h>
using namespace std;

using i64 = long long;

const i64 MOD = 1000000007;
map<pair<i64, i64>, i64> memo;
i64 calc(i64 s, i64 x) {
    auto cur = make_pair(s, x);
    for(auto it = memo.find(cur); it != memo.end();) return it->second;
    if(s == 0LL || x == 0LL) return 1LL;
    i64 res = 0LL;
    res += calc(s / 2LL, x / 2LL);
    if(s > 0LL && x > 0LL)
        res += calc((s - 1LL) / 2LL, (x - 1LL) / 2LL);
    if(s > 1LL)
        res += calc((s - 2LL) / 2LL, x / 2LL);
    res %= MOD;
    return memo[cur] = res;
}
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    i64 n;
    cin >> n;
    cout << calc(n, n) << endl;
    return 0;
}

Measured memory_bytes: 256