akhauriyash/Code-Regression huggingface dataset:
#include <string>
#include <vector>
#include <iostream>

using namespace std;
int main(){
  int n,q; cin >> n >> q;
  string s; cin >> s;
  vector<int> cnt(n+1);
  int sum=0;
  for(int i=0;i<n-1;i++){
    if(s[i]=='A' && s[i+1]=='C') {
      sum++;
    }
    cnt[i+1]+=sum;
  }
  cnt[n] = cnt[n-1];
  
  for(int i=0;i<q;i++){
    int l,r; cin >> l >> r;
    cout << cnt[--r]-cnt[--l] << endl;
  }
  return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <math.h>
#include <algorithm>

using namespace std;

int main(){
  int n;
  int d[100000] = {0};

  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> d[i];
  }
  sort(d,d+n);

  cout << d[n/2] - d[n/2 -1];
  return 0;
}


Measured memory_bytes: 768
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String s1 = sc.next();
		int n = s.length();
		int n1 = s1.length();
		if(n != n1) {
			System.out.println("NO");
			return;
		}
		for(int i = 0 ; i < n ; i++) {
			if(s.charAt(i) != s1.charAt(n1 - 1 - i)) {
				System.out.println("NO");
				return;
			}
		}
		System.out.println("YES");
	}
}

Measured memory_bytes: 21844
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

S, T = [sys.stdin.buffer.readline().decode().rstrip() for _ in range(2)]

def conv(s):
    cnt = 0
    num = {}
    ret = []
    for c in s:
        if c not in num:
            num[c] = cnt
            cnt += 1
        ret.append(num[c])
    return ret
ok = conv(S) == conv(T)
if ok:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 17228
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int s,count;
    cin>>s;
    count=1;
    if(s==1||s==2){
        cout<<4<<endl;
        return 0;
    }
    while(s!=4){
        if(s%2==0){
            s=s/2;
        }
        else if(s%2==1){
            s=3*s+1;
        }
        count++;
    }
    cout<<count+3<<endl;
}


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

int main(){
  int n,m,x,y;
  cin>>n>>m;
  int a[n];
  int b[n];
  for(int i=0; i<n; ++i){
    a[i]=1;
    b[i]=0;
  }
  b[0]=1;
  for(int i=0; i<m; ++i){
    cin>>x>>y;
    if(b[x-1]>0){
      if(a[x-1]>1){
        a[x-1]--;
        a[y-1]++;
        b[y-1]++;
      } else if(a[x-1]==1){
        a[x-1]=0;
        a[y-1]++;
        b[x-1]=0;
        b[y-1]++;
      }
    } else if(b[x-1]==0){
      a[x-1]--;
      a[y-1]++;
    }
  }
  int z;
  z=0;
  for(int i=0; i<n; ++i){
    if(b[i]>0) z++;
  }
  cout<<z<<endl;
  return 0;
}


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

int main(){
    int a, b;
    cin >> a >> b;
    if(a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) cout << "Possible" << endl;
    else cout << "Impossible" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 long long i = 0;
 long long X,sum;
  sum = 100;
  cin >> X;
  while (1) {
    sum += sum/100;
    i++;
    if (sum >= X){
      break;
    }
  }
  cout << i << endl;
  return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using ld = long double;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const long double PI = acos(-1.0L);
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  char x, y;
  cin >> x >> y;
  if (x > y)
    cout << '>' << endl;
  else if (x < y)
    cout << '<' << endl;
  else
    cout << '=' << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>

using namespace std;
typedef long long ll;
int n, p, a[100000], u[200001] = {};
string s;
ll ans;
int main() {
  cin >> n >> p >> s;
  if (p == 2 || p == 5) {
    for (int i = 0; i < n; i++) {
      if ((s[i] - '0') % p == 0) {
        ans += (ll)(i + 1);
      }
    }
  } else {
    int num = 1;
    u[n - 1] = s[n - 1] - '0';
    u[n - 1] %= p;
    a[u[n - 1]]++;
    if (u[n - 1] == 0) {
      ans++;
    }
    for (int i = n - 2; i >= 0; i--) {
      num *= 10;
      num %= p;
      u[i] = u[i + 1] + num * (s[i] - '0');
      u[i] %= p;
      if (u[i] == 0) {
        ans++;
      }
      ans += (ll)a[u[i]];
      a[u[i]]++;
    }
  }
  printf("%lld\n", ans);
}

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

typedef struct _Node {
  int key;
  struct _Node *next, *prev;
} Node;

Node *nil;

Node* listSearch(int key) {
  Node *cur = nil->next;
  while(cur != nil && cur->key != key) {
    cur = cur->next;
  }
  return cur;
}

void init(void) {
  nil = (Node *)malloc(sizeof(Node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(void) {
  Node *cur = nil->next;
  int isf = 0;
  while(1) {
    if(cur == nil) break;
    if(isf++>0) printf(" ");
    printf("%d",cur->key);
    cur = cur->next;
  }
  printf("\n");
}

void deleteNode(Node *t) {
  if(t==nil) return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst(void) {
  deleteNode(nil->next);
}

void deleteLast(void) {
  deleteNode(nil->prev);
}

void deleteKey(int key) {
  deleteNode(listSearch(key));
}

void insert(int key) {
  Node *x = (Node *)malloc(sizeof(Node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

int main(void) {
  int key, n, i;
  char com[20];
  scanf("%d", &n);
  init();
  for(i=0;i<n;i++) {
    scanf("%s%d",com, &key);
    if (com[0] == 'i') insert(key);
    else if(com[0] == 'd') {
      if(strlen(com) > 6) {
        if(com[6] == 'F')
          deleteFirst();
        else if(com[6] == 'L') deleteLast();
      } else deleteKey(key);
    }
  }
  printList();
  return 0;
}


Measured memory_bytes: 33048
h,w,n = map(int,input().split())
d = {}
for i in range(n):
    a,b = map(int,input().split())
    a,b = a-1,b-1

    am1_f = a-1 > 0
    ap1_f = a+1 < h-1
    bm1_f = b-1 > 0
    bp1_f = b+1 < w-1
    a_f = a > 0 and a < h-1
    b_f = b > 0 and b < w-1

    am1 = a-1
    ap1 = a+1
    bm1 = b-1
    bp1 = b+1

    if am1_f:
        baseid = am1 * w
        if b_f:
            pid = baseid + b

            if pid not in d:
                d[pid] = 1
            else:
                d[pid] += 1

        if bm1_f:
            pid = baseid + bm1
            if pid not in d:
                d[pid] = 1
            else:
                d[pid] += 1

        if bp1_f:
            pid = baseid + bp1
            if pid not in d:
                d[pid] = 1
            else:
                d[pid] += 1

    if ap1_f:
        baseid = ap1*w
        if b_f:
            pid = baseid + b

            if pid not in d:
                d[pid] = 1
            else:
                d[pid] += 1

        if bm1_f:
            pid = baseid + bm1
            if pid not in d:
                d[pid] = 1
            else:
                d[pid] += 1

        if bp1_f:
            pid = baseid + bp1
            if pid not in d:
                d[pid] = 1
            else:
                d[pid] += 1
    if a_f:

        baseid = a * w
        if b_f:
            pid = baseid + b
            if pid not in d:
                d[pid] = 1
            else:
                d[pid] += 1

        if bm1_f:
            pid = baseid + bm1
            if pid not in d:
                d[pid] = 1
            else:
                d[pid] += 1

        if bp1_f:
            pid = baseid + bp1
            if pid not in d:
                d[pid] = 1
            else:
                d[pid] += 1
    # print(d)

ans = [0 for i in range(10)]

for val in d.values():
    ans[val] += 1

ans[0] = (h-2)*(w-2)-sum(ans)

for a in ans:
    print(a)


Measured memory_bytes: 190428
#include <bits/stdc++.h>
#define rep(i, a) for (ll i = 0; i < (a); ++i)
#define pb push_back
#define all(v) v.begin(),v.end()
#define sort_1(v) sort(v.begin(),v.end())
#define sort_2(v) sort(v.begin(),v.end(),greater<ll>())
#define reverse(v) reverse(v.begin(),v.end())
typedef long long ll;
typedef long double la;
using namespace std;

int main(){
    int n;
    cin >> n;
    int a[n][10];
    vector<int> b,c;
    rep(i,n)rep(j,10){
        cin >> a[i][j];
    }
    b.pb(0);
    c.pb(0);
    rep(i,n){
        bool flag = true;
        rep(j,10){
            int p1 = b[b.size()-1];
            int p2 = c[c.size()-1];
            int p = a[i][j];
            if(p < p1 && p < p2){
                cout << "NO" << endl;
                flag = false;
                break;
            }else if(p < p1 && p > p2){
                c.pb(p);
            }else if(p > p1 && p < p2){
                b.pb(p);
            }else{
                if(p1 < p2){
                    c.pb(p);
                }else{
                    b.pb(p);
                }
            }
        }
        if(flag){
            cout << "YES" << endl;
        }
        b.clear();
        c.clear();
        b.pb(0);
        c.pb(0);
    }
}


Measured memory_bytes: 3120
#include <stdio.h>

int main(){
  int a, b;
  char op;

  while(scanf("%d%s%d", &a, &op, &b)){
    switch(op){
      case '?':
        return 0;
        break;
      case '+':
        printf("%d\n", a + b);
        break;
      case '-':
        printf("%d\n", a - b);
        break;
      case '*':
        printf("%d\n", a * b);
        break;
      case '/':
        printf("%d\n", a / b);
        break;
    }
  }

}

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

int main()
{
  int k;
  cin >> k;
  int ans = 0;
  for (int a = 1; a <= k; a++) {
    for (int b = 1; b <= k; b++) {
      for (int c = 1; c <= k; c++) {
	ans += gcd(a, gcd(b, c));
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3596
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N, K = map(int, readline().split())
    ans = K*((K-1)**(N-1))
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using ll = long long;
using namespace std;

const double pi = acos(-1);

pair <double, double> rotate(int x, int y, int degree, double d) {
   double theta = (2 * pi / 360) * degree;
   double x_ = x * cos (theta) - y * sin(theta);
   double y_ = x * sin (theta) + y * cos(theta);
   x_ *= d;
   y_ *= d;
   return {x_, y_};
}

const double eps = 1e-3;

int near(double x) {
   for(int i = (int)(x - 2); i < (int)(x + 2); i++) {
      if(abs(i - x) < eps) {
         return i;
      }
   }
   return 0;
}
void solve() {
   string s;
   int a, b;
   cin >> a >> b >> s;

   bool ok = true;
   ok &= s[a] == '-';
   for(int i = 0; i < s.length(); i++) {
      if(i == a)
         continue;
      else ok &= s[i] >= '0' && s[i] <= '9';
   } 
   cout << (ok?"Yes":"No") << endl;
}

int main() {
   cin.tie(0);
   cin.sync_with_stdio(0);
   int testcase = 1;
   // cin >> testcase;

   for(int i = 0; i < testcase; i++) {
      solve();
   } 
   return 0;
}


Measured memory_bytes: 3592
// Created by Tanuj Jain
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
bool ispalin(string& st, int l, int h)
{
	int low=l;
	int high=h;
	bool flag=false;
	while(low<high)
	{
		//cout<<st.at(low)<<" "<<st.at(high)<<endl;
		if(st.at(low)!=st.at(high))
		{
			return false;
		}
		else
		{
			low++;
			high--;
		}
	}
	return true;
}
int main()
{
	ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

	//#ifndef ONLINE_JUDGE
	//freopen("inputf.in","r",stdin);
	//freopen("outputf.in","w",stdout);
	//#endif

	string input;
	cin>>input;
	//cout<<input;
	bool f1=ispalin(input,0,input.size()-1);
	//cout<<f1<<endl;
	bool f2=ispalin(input,0,(input.size()-1)/2-1);
	//cout<<f2<<endl;
	bool f3=ispalin(input,(input.size()+3)/2-1,input.size()-1);
	//cout<<f3<<endl;

	
	if(f1 && f2 && f3)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
		
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    long long N, A[200005], S[200005], m, x, i;
    scanf("%lld", &N);
    S[0]=0;
    for (i=1; i<=N; i++) {
        scanf("%lld", &A[i]);
        S[i]=S[i-1]+A[i];
        // printf("%lld ", S[i]);
    }
    // printf("\n");
    m=S[N];
    for (i=1; i<=N; i++) {
        x=S[N]-2*S[i];
        if (x<0) x=-x;
        if (x<m) m=x;
    }
    printf("%lld", m);
    return 0;
}


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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  for (int i = 0; i < 100; i++) {
    C -= B;
    if (C <= 0) {
      cout << "Yes" << endl;
      break;
    }
    A -= D;
    if (A <= 0) {
      cout << "No" << endl;
      break;
    }
  }
}


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

// splice を含めてLListを自前実装する
typedef struct node{
  struct node *next;
  int data;
} Node;
class List{
  Node *top, *btm;
public:
  List(){
    top = btm = NULL;
  }
  void insert(int x){
    Node *node = new Node;
    node->next = NULL;
    node->data = x;
    if (top==NULL){
      top = node;
    } else {
      btm->next = node;
    }
    btm = node;
  }
  void insert(List *l){
    if (top==NULL){
      top = l->top;
    } else {
      btm->next = l->top;
    }
    btm = l->btm;
  }
  void dump(){
    Node *p = top;
    if (p) cout << p->data;
    else{
      cout << endl; return;
    }
    for (p = p->next; p; p = p->next){
      cout << " " << p->data;
    }
    cout << endl;
  }
  void splice(List *l){
    this->insert(l);
    l->top = l->btm = NULL;
  }
};

int main(void){
  vector<List*> vlp;
  int n,q,qtype,s,t,x;
  
  cin >> n >> q;
  for (int i=0; i<n; i++){
    List *lp = new List();
    vlp.push_back(lp);
  }
  for (int i=0; i<q; i++){
    cin >> qtype;
    switch (qtype){
      case 0: // insert t x
        cin >> t >> x;
 //       cout << "ins: " << t << " " << x << endl;
        vlp[t]->insert(x);
        break;
      case 1: // dump t
        cin >> t;
 //       cout << "dmp: " << t << endl;
        vlp[t]->dump();
        break;
      case 2: // splice s t
        cin >> s >> t;
 //       cout << "spl: " << s << " " << t << endl;
        vlp[t]->splice(vlp[s]);
        break;
    }
  }
  return 0;
}


Measured memory_bytes: 18740
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List
import Data.Ord

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    n <- getInt
    as <- getIntList
    print . g $ f as

f [] = []
f (a:[]) = EQ : []
f (a:b:as)= (compare a b) : f (b:as)

g [] = 0
g as | null gs || null ls = 1
     | length lts > length gts = 1 + g (tail gs)
     | otherwise = 1 + g (tail ls)
    where (lts, gs) = span (/= GT) as
          (gts, ls) = span (/= LT) as

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

const int MOD = 1e9 + 7, N = 201000;

namespace {
  int Add(int x, int y) { return (x += y) >= MOD ? x - MOD : x; }
  int Dec(int x, int y) { return (x -= y) < 0 ? x + MOD : x; }
}

int n, tmp[N], l[N], r[N], f[N], s[N];
pair<int, int> a[N];
vector<int> vec[N];

int main(void) {
  scanf("%d", &n);
  for(int i = 1; i <= n; i++) {
    scanf("%d%d", &a[i].first, &a[i].second);
    tmp[i] = a[i].second;
  }
  sort(a + 1, a + n + 1);
  sort(tmp + 1, tmp + n + 1);
  for(int i = 1; i <= n; i++)
    a[i].second = lower_bound(tmp + 1, tmp + n + 1, a[i].second) - tmp;
  for(int i = 1; i <= n; i++)
    r[i] = max(r[i - 1], a[i].second);
  l[n + 1] = 1e9;
  for(int i = n; i >= 1; i--)
    l[i] = min(l[i + 1], a[i].second);

  for(int i = 1; i <= n; i++)
    vec[r[i]].push_back(l[i]);

  f[0] = s[0] = 1;
  for(int i = 1; i <= n; i++) {
    for(int v : vec[i]) {
      s[i] = Add(s[i - 1], f[i]);
      f[i] = Add(f[i], Dec(s[i], v >= 2 ? s[v - 2] : 0));
    }
    s[i] = Add(s[i - 1], f[i]);
  }
  cout << f[n] << endl;
  return 0;
}


Measured memory_bytes: 16640
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int b[100001];

int main(int argc, const char * argv[]) {
    
    int n,h;
    
    scanf("%d %d",&n,&h);
    
    int ma = 0;
    
    for(int i=0,a;i<n;i++){
        scanf("%d %d",&a,&b[i]);
        if(ma < a)  ma = a;
        
    }
    
    sort(b,b+n);
    int ans = 0;
    
    for(int i=n-1;i>=0;i--){
        if(ma > b[i]){
            break;
        }else{
            h = h - b[i];
            ans++;
            if(h<=0){
                printf("%d\n",ans);
                return 0;
            }
        }
    }
    
    if(h%ma != 0) ans+=1;
    
    
    printf("%d\n",ans + h/ma);
    
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
  int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;
  int dc = c * 2;
  int ans = 0;
  if(dc <= a + b){
    if(x < y){
      ans += dc * x;
      if(dc <= b) ans += dc *(y-x);
      else ans += b *(y-x);
    }else{
      ans += dc * y;
      if(dc <= a) ans += dc * (x-y);
      else ans += a * (x - y);
    }
  }else{
    ans += x * a;
    ans += y * b;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    string S;
    cin >> S;
    // < < < < < <
    // > > > > > >
    vector<int>A(S.size()+1);
    vector<int>B(S.size()+1);
    for(int i = 0; i < S.size(); i++) {
        if(S[i] == '<') {
            A[i+1] = A[i]+1;
        }
        if(S[S.size()-i-1] == '>') {
            B[S.size()-i-1] = B[S.size()-i]+1;
        }
    }
    int ans = 0;
    for(int i = 0; i <= S.size(); i++) {
        ans+=max(A[i],B[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 11576
//Heaplax
//别让自己后悔
#include<bits/stdc++.h>
#define N 200001
#define int long long
#define LOG(x) cerr<<#x<<" = "<<x<<endl
#define add_edge(u,v) nxt[++cnt]=head[u],head[u]=cnt,to[cnt]=v
#define open(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
char ch;bool fs;void re(int& x)
{
	while(ch=getchar(),ch<33);
	if(ch=='-')fs=1,x=0;else fs=0,x=ch-48;
	while(ch=getchar(),ch>33)x=x*10+ch-48;
	if(fs)x=-x;
}
using namespace std;
char s[N+5];
int n,ans,all,fa[N];
int f1[N];//父亲不到i的子树最远距离
int f2[N];//i到所有点最长距离
int f3[N];//i到i的子树的最长距离
int f4[N];//i到i的子树的第二长距离
int f5[N];//i到子树一个关键点的子树最长距离最小值
int f6[N];//i的子树里有几个关键点
int cnt,head[N],nxt[N+N],to[N+N];
void dfs1(int u)
{
	f5[u]=n;
	if(s[u]=='1')f6[u]=1;
	for(int i=head[u],v;i;i=nxt[i])
		if((v=to[i]) != fa[u])
		{
			fa[v]=u;
			dfs1(v);
			if(f6[v])f5[u]=min(f5[u],f3[v]+1);
			f6[u]+=f6[v];
			if(f3[v]+1>f3[u])
				f4[u]=f3[u],f3[u]=f3[v]+1;
			else if(f3[v]+1>f4[u])
				f4[u]=f3[v]+1;
		}
}
void dfs2(int u)
{
	f2[u]=max(f3[u],f1[u]+(u!=1));
	int d=min(f2[u]-1,f3[u]+1),t=f5[u];
	if(f6[u]!=all)t=min(t,f1[u]+1);
	if(s[u]=='1')t=0;
	for(int i=head[u],v;i;i=nxt[i])
		if((v=to[i]) != fa[u])
		{
			f1[v]=max(f1[u]+(u!=1),f3[v]+1==f3[u]?f4[u]:f3[u]);
			d=min(d,f1[v]+1);
			dfs2(v);
		}
	// LOG(u);LOG(d);
	ans+=max(0ll,d-t+1);
}
main()
{
	re(n);
	for(int i=1,u,v;i<n;++i)
	{
		re(u),re(v);
		add_edge(u,v);
		add_edge(v,u);
	}
	scanf("%s",s+1);
	for(int i=1;i<=n;++i)
		all+=s[i]-'0';
	if(!all)return puts("0"),0;
	dfs1(1);
	dfs2(1);
	printf("%lld\n",++ans);
}


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


int main() {
	int w, a, b;
	cin >> w >> a >> b;
	if ((b <= a + w && a <= b) || (b <= a && a <= b + w)) {
		cout << 0 << endl;
		return 0;
	}

	if (a + w < b) {
		cout << abs(b - a - w) << endl;
		return 0;
	}

	if (b + w < a) {
		cout << abs(a - b - w) << endl;
		return 0;
	}
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<queue>
#include<stack>
#include<iomanip>
#include<cstring>
#include<string>
#include<set>

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

using namespace std;
using ll = long long int;

const ll INF = 1<<30;
const ll LINF = 1LL<<60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(void) {
    int n; cin >> n;
    vector<int> a(n);
    REP(i, n) cin >> a[i];
    sort(ALL(a));
    reverse(ALL(a));
    ll ans = 0;
    for (int i = 0; i < n / 2 + n % 2; i++) {
        ans += a[i];
    }
    for (int i = 1; i < n / 2; i++) {
        ans += a[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 4048
#include <iostream>
#include <cmath>
#include <numeric>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <algorithm>
using namespace std;

bool A[100010];
int B[100010];

int main() {
    int N, M;
    cin >> N >> M;

    fill(&A[0], &A[100010], false);
    fill(&B[0], &B[100010], 0);
    int P = 0;
    int Q = 0;

    for (int i = 1; i <= M; i++) {
        int p;
        string s;
        cin >> p >> s;

        if (!A[p] && s == "AC") {
            A[p] = true;
            Q++;
        }
        else if (!A[p] && s == "WA") {
            B[p]++;
        }
    }

    int ans = 0;

    for (int i = 1; i <= N; i++) {
        if (A[i]) ans += B[i];
    }

    cout << Q << " " << ans << endl;

    return 0;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/




#define no "No"
#define yes "Yes"
int N, A[101010];
//---------------------------------------------------------------------------------------------------
string solve() {
    int mi = 101010, ma = 0;
    rep(i, 0, N) mi = min(mi, A[i]), ma = max(ma, A[i]);

    if (2 <= ma - mi) return no;
    else if (ma - mi == 1) {
        int cnt = 0;
        rep(i, 0, N) if (A[i] == mi) cnt++;
        if (cnt < ma && 2 * (ma - cnt) <= N - cnt) return yes;
        return no;
    } else {
        if (ma * 2 <= N || ma == N - 1) return yes;
        return no;
    }
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;
    rep(i, 0, N) cin >> A[i];
    cout << solve() << endl;
}

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

const int N = 200000;
const int oo = 0x3f3f3f3f;

int n;
int a[N + 5], size[N + 5];
stack<pair<int*, int> > stk;

struct BIT {
#define lowbit(x) (x & -x)
    int c[N + 5]; 

    void clear() { memset(c, ~oo, sizeof c); }
    void modify(int x, int y) {
        while(x <= n) {
            if(c[x] < y) {
                stk.emplace(c + x, c[x]); 
            }
            c[x] = max(c[x], y);
            x += lowbit(x);
        }
    }

    int query(int x) {
        int res = c[N + 1];
        while(x > 0) {
            res = max(res, c[x]);
            x -= lowbit(x);
        }
        return res;
    }
};

BIT bit[2];
bool vis[N + 5];
vector<int> key;

bool chk(int A, int B, int x, int y, int c) {
    int t;
    t = B - A + c;
    if((t >= 0) && bit[t & 1].query(n - x) >= t) return true;
    t = A - B + c;
    if((t >= 0) && bit[t & 1].query(n - y) >= t) return true;
    return false;
}

int main() {

    scanf("%d", &n);
    for(int i = 1; i <= n; ++i) {
        scanf("%d", a + i);

        if(key.empty() || a[i] > key.back()) {
            vis[i] = true;
            key.push_back(a[i]);
        }
    }

    bit[1].clear();
    for(int i = n; i >= 1; --i) {
        size[i] = stk.size();
        if(vis[i]) {
            bit[0].modify(n - a[i] + 1, bit[0].query(n - a[i]) + 2);
            bit[1].modify(n - a[i] + 1, bit[1].query(n - a[i]) + 2);
        } else {
            bit[0].modify(n - a[i] + 1, bit[1].query(n - a[i]) + 1);
            bit[1].modify(n - a[i] + 1, bit[0].query(n - a[i]) + 1);
        }
    }

    int c = key.size();
    if(bit[c & 1].query(n) < c) return puts("-1"), 0;

    int A = 0, B = 0, x = 0, y = 0;

    for(int i = 1; i <= n; ++i) {
        c -= vis[i];
        while((int) stk.size() > size[i]) {
            *stk.top().first = stk.top().second;
            stk.pop();
        }

        int nx = x, nA = A;
        if(a[i] > x) ++ A, x = a[i];
        
        if(chk(A, B, x, y, c)) {
            putchar('0');
            continue;
        }

        putchar('1');
        x = nx, A = nA;
        if(a[i] > y) ++ B, y = a[i];
    }

    return 0;
}


Measured memory_bytes: 65128
N = gets.to_i
S = gets.chomp.chars
Q = gets.to_i
qu = []
Q.times{
  qu << gets.chomp.split(" ")
}

s = Hash.new{|h, k| h[k] = []}
(0...N).each{|i|
  s[S[i]] << (i+1)
}

ans = Array.new(26)
qu.each{|f, a, b|
  if f == '1' then
    a_i = a.to_i
    if S[a_i-1] != b then
      idx = s[S[a_i-1]].bsearch_index{|x| x >= a_i}
      s[S[a_i-1]].delete_at(idx)
      S[a_i-1] = b
      idx = s[b].bsearch_index{|x| x >= a_i}
      idx.nil? ? s[b] << a_i : s[b].insert(idx, a_i)
    end
  else
    l, r = [a.to_i, b.to_i]
    (0..25).each{|i|
      i_l = s[(97+i).chr].bsearch_index{|x| x >= l}
      i_r = s[(97+i).chr].bsearch_index{|x| x > r}
      if i_l.nil? then
        ans[i] = 0
      elsif i_r.nil? then
        ans[i] = s[(97+i).chr].size - i_l
      else
        ans[i] = i_r - i_l
      end
    }
    puts ans.count{|i| i > 0}
  end
}


Measured memory_bytes: 53564
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>

int main(){
	int n;
	std::vector<long long> aList;

	std::cin>>n;
	
	aList.resize(n);
	for(int i=0; i<n; i++)
		std::cin>>aList[i];

	long long sum=0;
	long long maxHeight=aList[0];

	for(int i=1; i< n; i++){
		if(maxHeight<= aList[i])
			maxHeight= aList[i];		
		else
			sum+= maxHeight- aList[i];		
	}

	std::cout<<sum<<std::endl;

	return 0;
}

Measured memory_bytes: 4752
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <cstdio>
#include <numeric>
#include <queue>

using namespace std;

using ll=long long;

ll N;
ll K;
ll A[200005];

ll used[200005];

ll sim(ll num, ll s)
{
    for(ll i = 0;i < num;i++)
    {
        s = A[s];
    }
    return s;
}

int main()
{
    cin >> N >> K;
    for(int i = 0;i < N;i++)
    {
        cin >> A[i];
        A[i]--;
    }


    if(A[0] == 0)
    {
        cout << 0+1 << endl;
        return 0;
    }

    ll cur = 0;
    ll prev = -1;
    while(used[cur] != 1)
    {
        used[cur] = 1;
        prev = cur;
        cur = A[cur];
    }
    ll x = cur;
    ll y = prev;

    cur = 0;
    ll cnt1 = 0;
    while(cur != x)
    {
        cur = A[cur];
        cnt1++;
    }
    cur = 0;
    ll cnt2 = 0;
    while(cur != y)
    {
        cur = A[cur];
        cnt2++;
    }

    ll ans = 0;
    if(K <= cnt1)
    {
        ans = sim(K, 0);
    }
    else
    {
        ll res = K - cnt1;
        res = res % (cnt2 - cnt1 + 1);
        ans = sim(res, x);
    }
    cout << ans + 1 << endl;
   return 0;
}

Measured memory_bytes: 6288
#include<stdio.h>
#include<string.h>
int main() {
	char n[100];
	int l,i;
	gets(n);
	l=strlen(n);
	if(n[0]=='7'||n[1]=='7'||n[2]=='7')
	printf("Yes\n");
	else
	printf("No\n");
	return 0;
}


Measured memory_bytes: 1532
#include <iostream>
#include <vector>


using namespace std;


void atcoder_beginner_contest999()
{
  string n;
  cin >> n;

  for (int i = 0; i < n.size(); ++i)
  {
    if (n[i] == '1') n[i] = '9';
    else if (n[i] == '9') n[i] = '1';
  }
  cout << n << "\n";
}


void programming_education()
{
  int n;
  cin >> n;
  
  if (n == 1)
  {
    cout << "Hello World\n";
    return;
  }
  else
  {
    int a, b;
    cin >> a >> b;
    cout << a + b << "\n";
  }
}

void discount_fare()
{
  int x, y;
  cin >> x >> y;

  cout << x + y / 2 << "\n";
}


void A_114()
{
  int x;
  cin >> x;

  if (x == 3 || x == 5 || x == 7) cout << "YES\n";
  else cout << "NO\n";
}



int main()
{
  //atcoder_beginner_contest999();
  //programming_education();
  //discount_fare();
  A_114();
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
class Program
{
 
    static void Main()
    {
      string[] A = Console.ReadLine().Split(' ');
      int H1 = int.Parse(A[0]);
      int M1 = int.Parse(A[1]);
   	  int H2 = int.Parse(A[2]);
      int M2 = int.Parse(A[3]);
      int K = int.Parse(A[4]);
      
      int HM1 = H1 * 60 +M1;
      int HM2 = H2 * 60 +M2 - K;
      
      int Ans = HM1 - HM2;
      
      if(Ans < 0)
      {
        Ans=Ans*-1;
      }
      
      Console.WriteLine(Ans);
      
    }
}

Measured memory_bytes: 27464
#include<bits/stdc++.h>
#define HohleFeuerwerke using namespace std
HohleFeuerwerke;
int n;
int r;
int main()
{
	ios::sync_with_stdio(false);
	cout.tie(0);cin.tie(0);
	cin>>n>>r;
	if(n<=10) cout<<r+100*(10-n)<<endl;
	else cout<<r<<endl;
	return 0;
}

Measured memory_bytes: 256
//Exam and Wizard

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define irep(i,a) for(auto i = a.begin(); i != a.end(); ++i)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using p = pair<ll, string>;
using garph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

signed main (){
    int n;cin>>n;
    vecrep(n,a,int);
    vecrep(n,b,int);
    vector<int>ama;
    rep(i,0,n){
        if(a[i]>b[i])ama.pb(a[i]-b[i]);
    }
    sort(range(ama),greater<int>());
    int aac = accumulate(range(a),0LL);
    int bac = accumulate(range(b),0LL);
    if(aac<bac){
        cout<<-1<<nnn;
        return 0;
    }
    int ans = 0;
    int tari = 0;
    rep(i,0,n){
        if(a[i]<b[i]){
            tari+=b[i]-a[i];
            ans++;
        }
    }
    for(int i = 0;tari>0;i++){
        tari-=ama[i];
        ans++;
    }
    cout<<ans<<nnn;
    return 0;
}

Measured memory_bytes: 2428
use proconio::input;

fn main() {
    input! {
        n: usize,
        m: usize,
        ab: [(i64, i64); n],
        cd: [(i64, i64); m],
    };

    for &(a_i, b_i) in ab.iter() {
        let mut min_dist = 1_000_000_000_000_000_i64;
        let mut x = 0;
        for (i, &(c_i, d_i)) in cd.iter().enumerate() {
            let dist = (a_i - c_i).abs() + (b_i - d_i).abs();
            if dist < min_dist {
                min_dist = dist;
                x = i + 1;
            }
        }
        println!("{}", x);
    }
}


Measured memory_bytes: 2132
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    bool flag = true;
    while(n--){
        int tmp;
        cin >> tmp;
        if(!(tmp%2)){
            if(tmp%3&&tmp%5)flag = false;
        }
    }
    string a ="APPROVED";
    string b = "DENIED";
    if(flag)cout << a << endl;
    else cout << b << endl;
}

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

int main() {
  int a, b, ans = 0;
  cin >> a >> b;
  if (a > 8 || b > 8) {
    cout << ":(";
    return 0;
  } else {
    cout << "Yay!";
    return 0;
  }

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int x = Integer.parseInt(sc.next());

        // 主処理
        int div = x / 100;
        int remain = x % 100;
        int result = remain <= 5 * div ? 1 : 0;

        // 出力
        System.out.println(result);
        sc.close();
    }
}


Measured memory_bytes: 23764
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>

#define _GLIBCXX_DEBUG
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t a,p;
    cin >> a >> p;
    cout << (3*a + p)/2 << endl;
    
}


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

int main()
{
    int n;
    cin >> n;
    
    vector<int> a(n), tab(n, 1e9);
    
    for( int i = 0; i < n; i++ )
        cin >> a[i];
        
    tab[0] = 0;
    tab[1] = abs(a[1] - a[0]);
    
    if ( n == 2 ){
        cout << tab[1] << endl;
        return 0;
    }
    
    for ( int i = 2; i < n; i++ ){
        for( int j = i - 1; j >= i - 2; j-- ){
            tab[i] = min( tab[i], abs( a[i] - a[j] ) + tab[j] );
        }    
    }
    
    cout << tab[n - 1] << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int n,a[100500],ans=0;
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    int j=a[1],tot=1;
    a[n+1]=-1;
    for(int i=2;i<=n+1;i++){
        if(a[i]!=j){
            if(tot>1){
                ans+=tot/2;
            }
            j=a[i],tot=1;
        }
        else{
            if(a[i]==j){
                tot++;
            }
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
def solve(n, k, a):
    S = set()
    x = 1
    S.add(x)
    loop_start = -1
    d = -1
    for i in range(n):
        x = a[x-1]
        if x in S:
            loop_start = x
            d = i+1
            break
        S.add(x)
    in_loop = False
    x, T = 1, 0
    for i in range(n):
        if x == loop_start:
            if in_loop:
                break
            in_loop = True
        if in_loop:
            T += 1
        x = a[x-1]
    if k > n:
        k = (k - d) % T + d
    x = 1
    for i in range(k):
        x = a[x-1]
    return x

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


Measured memory_bytes: 32404
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

const int N = (int)3e5;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  ret *= kaijo(n); ret %= MOD;
  ret *= gyaku_kaijo(r); ret %= MOD;
  ret *= gyaku_kaijo(n-r); ret %= MOD;
  return ret;
}


int main(void){
  ll x,y;cin>>x>>y;
  ll ans = 0;
  if(x<=1){
    ans+= 1e5;
  }
  if(x<=2){
    ans+=1e5;
  }
  if(x<=3){
    ans+=1e5;
  }
  if(y<=1){
    ans+=1e5;
  }
  if(y<=2){
    ans+=1e5;
  }
  if(y<=3){
    ans+=1e5;
  }
  if(x==1&&y==1){
    ans+=4e5;
  }
  cout<<ans<<endl;
  return 0;
}


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

N = H+W+10
MOD = 10**9+7

fac = [1,1] + [0]*N
finv = [1,1] + [0]*N
inv = [0,1] + [0]*N
for i in range(2,N+2):
    fac[i] = fac[i-1] * i % MOD
    inv[i] = -inv[MOD%i] * (MOD // i) % MOD
    finv[i] = finv[i-1] * inv[i] % MOD

def ncr(n,r):
    if n < r: return 0
    if n < 0 or r < 0: return 0
    return fac[n] * (finv[r] * finv[n-r] % MOD) % MOD

ans = 0
for i in range(W-B):
    ans += ncr(H-1-A+B+i, H-1-A) * ncr(A-1+W-1-B-i, A-1)
    ans %= MOD
print(ans)

Measured memory_bytes: 28376
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define rrep(i, n) for(int i=((int)(n));i>0;i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)	
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define REVSORT(c) SORT(c);REVERSE(c)
#define ALL(x) (x).begin(),(x).end()
#define INF 1e9
const long long MOD = 1000000007;
typedef long long ll;

int main(){
	int N;
	ll cnt;
	cin >> N;
	map<string, ll> C;
	rep(i, N){
		string S;
		cin >> S;
		SORT(S);
		if(C.count(S)){
			cnt += C[S];
			C[S]++;
		} else {
			C[S] = 1;
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,ac=0,wa=0,tle=0,re=0;
	cin >> n;
  	string s;
	while(n--)
	{
		cin >> s;
		if(s=="AC")
			ac++;
		else if(s=="WA")
			wa++;
		else if(s=="TLE")
			tle++;
		else if(s=="RE")
			re++;
	}
	cout << "AC x " << ac << '\n';
	cout << "WA x " << wa << '\n';
	cout << "TLE x " << tle << '\n';
	cout << "RE x " << re << '\n';

}

Measured memory_bytes: 3636
#include <iostream>

using namespace std;

struct state {
    int w, e, n, s, t, b;
} s;

void West() {
    state t = s;
    s.t = t.e, s.e = t.b, s.b = t.w, s.w = t.t;
};

void East() {
    state t = s;
    s.t = t.w, s.e = t.t, s.b = t.e, s.w = t.b;
}

void North() {
    state t = s;
    s.t = t.s, s.n = t.t, s.b = t.n, s.s = t.b;
}

void South() {
    state t = s;
    s.t = t.n, s.n = t.b, s.b = t.s, s.s = t.t;
}

void Left() {
    state t = s;
    s.n = t.e, s.e = t.s, s.s = t.w, s.w = t.n;
}

void Right() {
    state t = s;
    s.n = t.w, s.e = t.n, s.s = t.e, s.w = t.s;
}

int main() {
    int n;
    while (cin >> n) {
        s.w = 4; s.e = 3; s.n = 5; s.s = 2; s.t = 1; s.b = 6;
        if (n == 0) break;
        int sum = 1;
        for (int i = 0; i < n; i++) {
            string cmd; cin >> cmd;
            if (cmd == "West") {
                West();
            } else if (cmd == "East") {
                East();
            } else if (cmd == "North") {
                North();
            } else if (cmd == "South") {
                South();
            } else if (cmd == "Left") {
                Left();
            } else if (cmd == "Right") {
                Right();
            }
            sum += s.t;
        }
        cout << sum << endl;
    }
    return 0;
}

Measured memory_bytes: 0
#dt = {} for i in x: dt[i] = dt.get(i,0)+1
ipnl = lambda n: [int(input()) for _ in range(n)]
inp = lambda :int(input())
ip = lambda :[int(w) for w in input().split()]

from math import sqrt 
def count(n):
    return (-1 + sqrt(1 + 8 * n)) // 2
def pfact(num):
    from math import sqrt
    dt = {}
    while num%2==0:
        dt[2] = dt.get(2,0) + 1
        num //= 2
    for i in range(3,int(sqrt(num))+1,2):
        while num%i==0:
            dt[i] = dt.get(i,0) + 1
            num //= i
    if num>2:
        dt[num] = dt.get(num,0) + 1
    return dt
n = inp()
dt = pfact(n)
ctr = 0
for i in list(dt.values()):
    ctr += int(count(i))
print(ctr)

Measured memory_bytes: 63416
N, K = map(int, input().split())
V = list(map(int, input().split()))


ret = -1 * 10**7 * 50 

for left in range(K+1):
    for right in range(K-left+1):
        if left + right > N:
            continue

        disposable = K - right - left
        
        chosen = V[:left] +  V[N - right:]
        chosen.sort()
        chosen_count = sum(chosen)

        dispoase_value = 0
        for i in range(disposable):
            if i >= len(chosen):
                break
            if chosen[i] >= 0:
                break
            dispoase_value += chosen[i]


        val = chosen_count - dispoase_value

        ret = max(ret, val)

print(ret)






Measured memory_bytes: 41192
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
 
typedef long long ll;
typedef long double ld;
 
#define REP(i,a,n) for(int (i)=(a); (i)<(int)(n); (i)++)
#define rep(i,n) REP(i,0,n)
#define vec vector 

const ll large_P = 1e9 + 7;


int main(){
  int a, b;
  cin >> a >> b;
  
  if(a < b) rep(i, b) cout << a;
  else rep(i, a) cout << b;
}

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

const int N = 500005;
int n, q;
string s;
int st[4*N];

void build(int idx, int l, int r) {
	if(l == r) {
		st[idx] = (1 << (int)(s[l] - 'a'));
		return;
	}

	int lc = idx<<1, rc = lc+1;
	build(lc, l, (l+r)/2);
	build(rc, (l+r)/2+1, r);
	st[idx] = st[lc] | st[rc];
}

void update(int idx, int l, int r, int pos, char c) {
	if(r < pos || pos < l) return;
	if(l == r && l == pos) {
		st[idx] = (1 << (int)(c - 'a'));
		return;
	}

	int lc = idx<<1, rc = lc+1;
	update(lc, l, (l+r)/2, pos, c);
	update(rc, (l+r)/2+1, r, pos, c);
	st[idx] = st[lc] | st[rc];
}

int query(int idx, int l, int r, int x, int y) {
	if(r < x || y < l) return 0;
	if(x <= l && r <= y) return st[idx];

	int lc = idx<<1, rc = lc+1;
	int sl = query(lc, l, (l+r)/2, x, y);
	int sr = query(rc, (l+r)/2+1, r, x, y);
	return sl | sr;
}

int main() {
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	cin >> n >> s;

	build(1, 0, n-1);

	cin >> q;
	while(q--) {
		int op; cin >> op;
		if(op == 1) {
			int i; char c; cin >> i >> c;
			update(1, 0, n-1, i-1, c);
		} else {
			int l, r; cin >> l >> r;
			int x = query(1, 0, n-1, l-1, r-1);
			cout << __builtin_popcount(x) << '\n';
		}
	}

	return 0;
}

Measured memory_bytes: 7068
n,k = map(int,input().split())
d=[0 for i in range(k+1)]
a=[[0 for i in range(101)] for i in range(k+1)]
for i in range(1,k+1):
    d[i]=int(input())
    l = list(input().split())
    for j in range(1,d[i]+1):
        a[i][j]=int(l[j-1])
lis=[i for i in range(1,n+1)]
for i in range(1,k+1):
    for j in range(1,d[i]+1):
        for m in lis:
            if a[i][j]==m:
                try:
                    lis.remove(m)
                except:
                    continue
print(len(lis))

Measured memory_bytes: 9212
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>

#define REP(i,n) for(long long i=0;i<n;++i)
#define REPR(i,n) for(long long i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(long long i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(v) {for(long long sitr=0;sitr<v.size();++sitr){cin>>v[sitr];}}

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

using namespace std;

typedef pair<int,int> pii;


int main(){

  while(true){

    llong R;
    cin >> R;

    if(R == 0) break;

    llong L1[500][500], L2[500][500];
    llong w[2], h[2], x[2], y[2];


    cin >> w[0] >> h[0] >> x[0] >> y[0];
    x[0]--; y[0]--;
    REP(i,h[0]){
      REP(j,w[0]){
        cin >> L1[i][j];
      }
    }

    cin >> w[1] >> h[1] >> x[1] >> y[1];
    x[1]--; y[1]--;
    REP(i,h[1]){
      REP(j,w[1]){
        cin >> L2[i][j];
      }
    }

    llong max_level1 = 0, max_level2 = 0;
    vector<llong> rec1, rec2;
    rec1.push_back(0);
    rec2.push_back(0);
    
    bool used[500][500] = {};
    using Elem = tuple<llong, int, int>;
    priority_queue<Elem, vector<Elem>, greater<Elem> > que;

    que.emplace(1, x[0], y[0]);
    used[y[0]][x[0]] = true;

    while(que.size()) {
      llong level; int X, Y; tie(level, X, Y) = que.top(); que.pop();
      if(level > max_level1) max_level1 = level;
      rec1.push_back(max_level1);

      REP(i,4){
        if(X + dx[i] >= 0 && X + dx[i] < w[0] && Y + dy[i] >= 0 && Y + dy[i] < h[0]){
          if(!used[Y+dy[i]][X+dx[i]]){
            used[Y+dy[i]][X+dx[i]] = true;
            que.emplace(L1[Y+dy[i]][X+dx[i]], X+dx[i], Y+dy[i]);
          }
        }
      }
    }

    memset(used, 0, sizeof(used));    

    que.emplace(1, x[1], y[1]);
    used[y[1]][x[1]] = true;

    while(que.size()) {
      llong level; int X, Y; tie(level, X, Y) = que.top(); que.pop();
      if(level > max_level2) max_level2 = level;
      rec2.push_back(max_level2);

      REP(i,4){
        if(X + dx[i] >= 0 && X + dx[i] < w[1] && Y + dy[i] >= 0 && Y + dy[i] < h[1]){
          if(!used[Y+dy[i]][X+dx[i]]){
            used[Y+dy[i]][X+dx[i]] = true;
            que.emplace(L2[Y+dy[i]][X+dx[i]], X+dx[i], Y+dy[i]);
          }
        }
      }
    }

    llong ans = 1LL << 60;
    REP(i,R+1){
      if(i >= rec1.size()) continue;
      if(R-i >= rec2.size()) continue;
      ans = min(ans, rec1[i] + rec2[R-i]);
    }
    cout << ans << endl;
  }


  return 0;
}




Measured memory_bytes: 13344
def rec(all_list,num,sl):
    if len(sl)==1:
        all_list.append(num+sl)
        return

    for i,s in enumerate(sl):
        rec(all_list,num+s,sl[:i]+sl[i+1:])

N=int(input())
P=input()[::2]
Q=input()[::2]


all_list=[]

NN=""
for i in range(N):
    NN+=str(i+1)

rec(all_list,"",NN)

for i,s in enumerate(all_list):
    if P==s:
        a=i+1
    
    if Q==s:
        b=i+1

print(abs(a-b))


Measured memory_bytes: 6040