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

struct Node {
    int key;
    Node *right, *left, *parent;
};

Node *root, *NIL;

Node * treeMinimum(Node *x) {
    while (x->left != NIL) x = x->left;
    return x;
}

Node * find(Node *u, int k) {
    while(u != NIL && k != u->key) {
        if (k < u->key) u = u->left;
        else u = u->right;
    }
    return u;
}

Node * treeSuccessor(Node *x) {
    if (x->right != NIL) return treeMinimum(x->right);
    Node *y = x->parent;
    while (y != NIL && x == y->right) {
        x = y;
        y = y->parent;
    }
    return y;
}

void treeDelete(Node *z) {
    Node *y; // 削除する対象
    Node *x; // y の子

    //削除する節点を決める
    if (z->left == NIL || z->right == NIL) y = z;
    else y = treeSuccessor(z);

    // y の子 x を決める
    if (y->left != NIL) {
        x = y ->left;
    } else {
        x = y->right;
    }

    if (x != NIL) {
        x->parent = y->parent;
    }

    if (y->parent == NIL) {
        root = x;
    } else {
        if (y == y->parent->left) {
            y->parent->left = x;
        } else {
            y->parent->right = x;
        }
    }

    if (y != z) {
        z->key = y->key;
    }

    free(y);
}

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

    z = (Node *)malloc(sizeof(Node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;

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

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

void inorder(Node *u) {
    if (u == NIL) return;
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
}
void preorder(Node *u) {
    if (u == NIL) return;
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
}

int main() {
    int n, i, x;
    string com;

    scanf("%d", &n);

    for (i = 0; i < n; i++) {
        cin >> com;
        if (com[0] == 'f') {
            scanf("%d", &x);
            Node *t = find(root, x);
            if (t != NIL) printf("yes\n");
            else printf("no\n");
        } else if (com == "insert"){
            scanf("%d", &x);
            insert(x);
        } else if (com == "print") {
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        } else if (com == "delete") {
            scanf("%d", &x);
            treeDelete(find(root, x));
        }
    }

    return 0;
}


Measured memory_bytes: 22036
n = int(input())
numbers = input()

lst = []
ans = []
for i in range(n):
  pin = ''
  if numbers[i] not in lst:
    pin += numbers[i]
    lst.append(pin)
    lst2 = []
    for j in range(i+1, n):
      pin += numbers[j]
      if pin[1] not in lst2:
        lst2.append(pin[1])
        lst3 = []
        for k in range(j+1, n):
          pin += numbers[k]
          if pin[2] not in lst3:
            lst3.append(pin[2])
            ans.append(pin)
          if ('0' in lst3) and ('1' in lst3) and ('2' in lst3) and ('3' in lst3) and ('4' in lst3) and ('5' in lst3) and ('6' in lst3) and ('7' in lst3) and ('8' in lst3) and ('9' in lst3):
            break
          pin = pin[0] + pin[1]
      if ('0' in lst2) and ('1' in lst2) and ('2' in lst2) and ('3' in lst2) and ('4' in lst2) and ('5' in lst2) and ('6' in lst2) and ('7' in lst2) and ('8' in lst2) and ('9' in lst2):
        break
      pin = pin[0]
    if ('0' in lst) and ('1' in lst) and ('2' in lst) and ('3' in lst) and ('4' in lst) and ('5' in lst) and ('6' in lst) and ('7' in lst) and ('8' in lst) and ('9' in lst):
      break
print(len(ans))

Measured memory_bytes: 9400
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
using ll = long long;
const ll mod = 1000000007;
const ll infi = 1000000000000000;
const ll md = 998244353;
using namespace std;
using vl = vector<ll>;
using pll =  pair<ll,ll>;

ll destroy(ll h){
    if(h == 1)
        return 1;
    else 
        return 1 + 2 * destroy(h/2);
}

void solve()
{   
    int h,n;
    cin>>h>>n;
    int a[n],b[n],ans[h+1+10000];
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i];
    }

    for(int i=0;i<h+10000;i++)
        ans[i] = mod;
    ans[h+10000] =0;    
    for(int i=h+10000;i>=0;i--){
        for(int j=0;j<n;j++){
            if(i + a[j] <= h+10000){
                ans[i] = min(ans[i] , ans[i+a[j]] + b[j]);
            }
        }
    }
    int fans = mod;
    for(int i=0;i<=10000;i++){
        fans  = min(fans , ans[i]);
    }
    cout<<fans;
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}

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

const int MAX_N = 100000;
int N, M, A[MAX_N], B[MAX_N];

pair<int, int> itv[MAX_N];

void solve() {
    for (int i = 0; i < M; i++) {
        itv[i].first = A[i];
        itv[i].second = B[i];
    }
    sort(itv, itv + M);

    int ans = 1, temp = itv[0].second;
    for (int i= 1; i < M; i++) {
        if (temp > itv[i].second) temp = itv[i].second;
        else if (temp <= itv[i].first) {
            ans++;
            temp = itv[i].second;
        }
    }

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

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

    for (int i = 0; i < M; i++) {
        cin >> A[i] >> B[i];
    }

    solve();
}

Measured memory_bytes: 1792
import sys

input = sys.stdin.buffer.readline
in_n = lambda: int(input())
in_nn = lambda: map(int, input().split())
in_s = lambda: input().rstrip().decode('utf-8')
in_map = lambda: [s == ord('.') for s in input() if s != ord('\n')]

MOD = 10**9 + 7
INF = 8 * 10**18


def main():

    a, b, c, d = in_nn()

    if abs(a - c) <= d or (abs(a - b) <= d and abs(b - c) <= d):
        print('Yes')
    else:
        print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 9132
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e15;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    int k;
    cin >> s >> k;
    k--;
    int idx = 0;
    rep(i, 0, s.size()){
        if(s[i] != '1'){
            idx = i; break;
        }
    }
    if(k < idx){
        cout << 1 << endl;
    }else{
        cout << s[idx] << endl;
    }
}

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] original_enemy = Console.ReadLine().Split();
            int enemy = int.Parse(original_enemy[0]);
            int special_attack = int.Parse(original_enemy[1]);

            string[] original_hp = Console.ReadLine().Split();
            long[] hp = original_hp.Select(long.Parse).OrderByDescending(x => x).ToArray();
            if (special_attack > hp.Length)
            {
                special_attack = hp.Length;
            }
            for (int i = 0; i < special_attack; i++)
            {
                hp[i] = 0;
            }
            Console.WriteLine(hp.Sum());
            Console.Read();
        }
    }
}

Measured memory_bytes: 40168
/**
 *      AGC 8 A
 *      author  : kyomukyomupurin
 *      created : 2018-10-10 17:42:43
**/

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int x, y; cin >> x >> y;

    if (x == y) cout << 0 << '\n';
    else if (abs(x) < abs(y)){
        if (x >= 0 && y >= 0) cout << y - x << '\n';
        else if (x <= 0 && y >= 0){
            if (x == 0) cout << y << '\n';
            else cout << 1 + y + x << '\n';
        }
        else if (x >= 0 && y <= 0) cout << 1 - x - y << '\n';
        else if (x <= 0 && y <= 0) {
            if (x == 0) cout << 1 - y << '\n';
            else cout << 2 + x - y << '\n';
        }
    }
    else if (abs(x) > abs(y)){
        if (x >= 0 && y >= 0) {
            if (y == 0) cout << 1 + x << '\n';
            else cout << 2 + x - y << '\n';
        }
        else if (x <= 0 && y >= 0) {
            if (y == 0) cout << y - x << '\n';
            else cout << 1 - x - y << '\n';
        }
        else if (x >= 0 && y <= 0) cout << 1 + x + y << '\n';
        else if (x <= 0 && y <= 0) cout << y - x << '\n';
    }
    else cout << 1 << '\n';
    
    return 0;
}

Measured memory_bytes: 256
function Main(input: string) {
    let splited = input.split('\n')[0];
    let A = parseInt(splited.split(' ')[0]);
    let B = parseInt(splited.split(' ')[1]);
    let K = parseInt(splited.split(' ')[2]);

    if (K >= A + B) {
        console.log('0 0');
    } else {
        if (K >= A) {
            console.log('0 ' + (B - (K - A)));
        } else {
            console.log(A - K + ' ' + B);
        }
    }

}

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

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

int main(){
    int N, m;
    cin >> N; //scanf("%d", &N);
    m = N % 10;
    if (m == 2 || m == 4 || m == 5 || m == 7 || m == 9)
        cout << "hon" << endl;
    else if (m == 0 || m == 1 || m == 6 || m == 8)
        cout << "pon" << endl;
    else
        cout << "bon" << endl;
    return 0;
}

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

#define fi first
#define se second

const int N = 6006;
const long long mod = 1e9 + 7;

using namespace std;


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

        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);

        int n;
        cin >> n;
        vector < int > A(100001, 0);
        vector < int > B(100001, 0);
        for(int i = 1; i <= n; i++){
                int x;
                cin >> x;
                if(i & 1){
                        A[x] += 1;
                } else{
                        B[x] += 1;
                }
        }
        vector < pair < int, int > > v, g;
        for(int i = 0; i < A.size(); i++){
                if(A[i] > 0){
                        v.push_back({A[i], i});
                }
        }
        for(int i = 0; i < B.size(); i++){
                if(B[i] > 0){
                        g.push_back({B[i], i});
                }
        }
        v.push_back({0, -1});
        v.push_back({0, -2});
        sort(v.begin(), v.end());
        sort(g.begin(), g.end());
        reverse(g.begin(), g.end());
        reverse(v.begin(), v.end());

        int res = 0;
        for(int i = 0; i < 2; i++){
                for(int j = 0; j < 2; j++){
                        if(v[i].se != g[j].se){
                                res = max(res, v[i].fi + g[j].fi);
                        }
                }
        }
        cout << n - res << "\n";
}


Measured memory_bytes: 2168
#include <iostream>

int main(int argc, char const *argv[])
{
    int N;
    std::cin >> N;
    int required = N / 1000;
    if(N % 1000 != 0) ++required;
    int rem = required * 1000 - N;
    std::cout << rem << '\n';
    return 0;
}


Measured memory_bytes: 3596
#include<iostream>
#include<stdlib.h>
//copy from http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=929835#1
using namespace std;
  
struct Node{
  int key;
  Node* next;
  Node* prev;
};
  
struct List{
  Node* nil;
  
  void init(){
    nil=(Node*)malloc(sizeof(Node));
    nil->next=nil;
    nil->prev=nil;
    nil->key=0;
  }
  
  Node* find(int key){
    for(Node* i=nil->next;i!=nil;i=i->next){
      if(i->key==key)return i;
    }
    return nil;
  }
  
  void insert(Node *x){
    x->next=nil->next;
    nil->next->prev=x;
    nil->next=x;
    x->prev=nil;
  }
   
  void add(int x){
    Node* p = (Node*)malloc(sizeof(Node));
    p->key=x;
    insert(p);
  }
    
  void delete_x(int key){
    Node* x=find(key);
    if(x==nil)return;
    x->prev->next=x->next;
    x->next->prev=x->prev;
    free(x);
  }
    
  void deleteFirst(){
    Node* x = nil->next;
    x->prev->next=x->next;
    x->next->prev=x->prev;
    free(x);
  }
    
  void deleteLast(){
    Node* x = nil->prev;
    x->prev->next=x->next;
    x->next->prev=x->prev;
    free(x);   
  }
  
  void output(){
    int flg=0;
    for(Node* i=nil->next;i!=nil;i=i->next){
      if(flg)cout<<' ';
      cout<<i->key;
      flg=1;
    }
    cout<<endl;
  }
};
  
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  List list;
  list.init();
  int n,x;
  string str;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>str;
    if(str=="insert"){
      cin>>x;
      list.add(x);
    }else if(str=="delete"){
      cin>>x;
      list.delete_x(x);
    }else if(str=="deleteFirst"){
      list.deleteFirst();
    }else {
      list.deleteLast();
    }
  }
  //cout<<'-'<<endl;
  list.output();
}


Measured memory_bytes: 34292
N,*H=`dd`.split.map &:to_i;B=[0]*-~M=2**18;N.times{|i|j=k=H[i];r=0;1while(r<B[j]&&r=B[j];j&=j-1)>0;1until(B[k]=[B[k],r+H[N+i]].max;k+=k&-k)>M};p B[M]

Measured memory_bytes: 55848
import java.util.Arrays;
import java.util.Scanner;

public class Main implements Runnable {

    private static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Thread(null, new Main(), "", 128 * 1024 * 1024).start();
    }

    public void run() {
        int n = sc.nextInt();
        int ary[] = new int[n];
        int srt[] = new int[n];

        for (int i = 0; i < n; i++) {
            ary[i] = sc.nextInt();
            srt[i] = ary[i];
        }

        Arrays.sort(srt);
        int a = srt[(n - 1) / 2];
        int b = srt[n / 2];

        for (int i = 0; i < n; i++) {
            System.out.println(ary[i] <= a ? b : a);
        }
    }
}


Measured memory_bytes: 97144
#include <bits/stdc++.h>
using namespace std;
int main () {
    string s, t;
    cin >> s >> t;
    int n = s.size();
    map<char, set<char>> x, y;
    for (int i = 0; i < n; i++) {
        x[t[i]].insert(s[i]);
        y[s[i]].insert(t[i]);
        if (x[t[i]].size() != 1 || y[s[i]].size() != 1) {
            puts("No");
            return 0;
        }
    }
    puts("Yes");
}

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

int main(){
  ll A,B,K;
  cin>>A>>B>>K;
  if(K<=A){
    A-=K;
  }else if(K<A+B){
    B-=K-A;
    A=0;
  }else{
    A=B=0;
  }
  cout<<A<<" "<<B<<endl;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define INF      (int)1e9
#define MOD      (int)1e9+7
using namespace std;
typedef long long     llong;
typedef pair<int,int> pii;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;

int main(){
	string s,t;
	cin>>s>>t;
	string ss=s+s;
	
	vvi p(26);
	REP(i,ss.size()) p[ss[i]-'a'].push_back(i);
	
	llong ans=0;
	int now=0;
	REP(i,t.size()){
		//cout<<ans<<' '<<now<<endl;//!!!
		if(p[t[i]-'a'].size()==0){
			cout<<-1<<endl;
			return 0;
		}
		auto itr=lower_bound(ALL(p[t[i]-'a']),now);
		ans+=*itr-now+1;
		now=*itr+1;
		REP(j,2) if(now>=s.size()) now-=s.size();
	}
	
	cout<<ans<<endl;
	return 0;
}//解説参考.

Measured memory_bytes: 1980
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        var sol = new Solve();
        sol.Exec();
    }
}

class Solve
{
    public void Exec()
    {
        var N = int.Parse(Console.ReadLine());
        var X = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var move = new long[N][];
        for (var i = 0; i < N; i++)
        {
            move[i] = new long[100];
            for (var p = 1; p <= 100; p++)
            {
                move[i][p-1] = (long) Math.Pow(X[i] - p, 2);
            }
        }

        var ans = long.MaxValue;
        for (var i = 1; i <= 100; i++)
        {
            var sum = 0L;
            for (var j = 0; j < N; j++)
            {
                sum += move[j][i - 1];
            }

            ans = Math.Min(ans, sum);
        }

        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 13396
n,m=map(int,input().split())
ans=0
k=[]
def func(n,s,i):
    global ans
    if n==0:
        c=0
        for j in range(m):
            cnt=0
            for a in range(1,len(k[j])):
                if s[k[j][a]-1]==1:
                    cnt+=1
            if cnt%2==p[j]:
                c+=1
        if c==m:
            ans=ans+1
    else:
        for j in range(2):
            if j==0:
                s[i-1]=0
                func(n-1,s,i+1)
            else:
                s[i-1]=1
                func(n-1,s,i+1)

for i in range(m):
    K=list(map(int,input().split()))
    k.append(K)
p=list(map(int,input().split()))
func(n,[0]*n,0)
print(ans)


Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
#include<utility>//pair
#include<queue>//queue,priority_queue
#include<deque>//double_ended queue
using namespace std;
typedef pair<int,int> P;//Pでpair<-,->を表す。
typedef long long LL; 
LL MOD=1000000007;
#include<iomanip>

int main()
{
    cout<<setprecision(15);
    LL l;
    cin>>l;
    l=l*l*l;
    LL r=l%27;
    LL q=l/27;
    double ans=r/27.0;
    int q2=q%10;
    ans=ans+q2;
    q=q/10;
    cout<<q<<ans<<endl;
    return 0;   
}

Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		HashSet<Integer> set = new HashSet<Integer>();
		for(int i = 1; i<=N; i++) {
			int n = sc.nextInt();
			if(set.contains(n)) set.remove(n);
			else set.add(n);
		}
		
		System.out.println(set.size());
	}

}


Measured memory_bytes: 62972
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int m;
    cin >> m;
    REP (i, m) {
        string s;
        cin >> s;
        int n = s.size();
        set<string> st;
        FOR (i, 1, n) {
            string t = s.substr(0, i), revT = t;
            string u = s.substr(i), revU = u;
            reverse(revT.begin(), revT.end());
            reverse(revU.begin(), revU.end());
            st.emplace(t + u);
            st.emplace(t + revU);
            st.emplace(u + t);
            st.emplace(u + revT);
            st.emplace(revT + u);
            st.emplace(revT + revU);
            st.emplace(revU + t);
            st.emplace(revU + revT);
        }
        cout << st.size() << endl;
    }
}


Measured memory_bytes: 3204
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define debug(x) cerr << "[(" << __LINE__ << ") " << (#x) << "]: " << x << endl;

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

    int n;
    cin >> n;

    int x, y, z, a, b, c;
    int dp[3] = {};

    for (int i=0; i<n; i++) {
        cin >> x >> y >> z;
        
        a = max(dp[1], dp[2]) + x;
        b = max(dp[0], dp[2]) + y;
        c = max(dp[0], dp[1]) + z;

        dp[0] = a;
        dp[1] = b;
        dp[2] = c;
    }

    cout << max({dp[0], dp[1], dp[2]}) << "\n";
}


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

using ll = long long;
using namespace std;
const int INFint = 2e9+1;
const ll INFll = 2e18+1;
ll MOD=1e9+7;


int main(){
  int N,M,X;
  cin>>N>>M>>X;
  int C[20],A[20][20];
  for(int i(0);i<N;i++){
    cin>>C[i];
    for(int j(0);j<M;j++){
      cin>>A[i][j];
    }
  }
  int ans(1e9);
  for(int bit(0);bit<(1<<N);bit++){
    int rikai[20] = {0};
    int kakaku = 0;
    for(int i(0);i<N;i++){
      if (((bit>>i) & 1)){
        kakaku += C[i];
        for(int j(0);j<M;j++){
          rikai[j] += A[i][j];
        }
      }
    }
    bool flag = true;
    for(int i(0);i<M;i++){
      if(rikai[i] < X){
        flag = false;
      }
    }
    if(flag){
      //cout << kakaku << endl;
      ans = min(ans,kakaku);
    }
  }

  if(ans == 1e9){
    cout << -1 << endl;
  }else{
    cout << ans << endl;
  }
  return 0;
}



Measured memory_bytes: 3636
fun main() {
    val n = nextInt()
    val list = nextIntList().sorted()

    var res = 0L
    (1 until n).forEach {
        res += list[list.lastIndex - it.div(2)]
    }
    println(res)
}

// # Utils
// ## Input
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = next().split(" ").map(String::toInt)
fun nextLongList() = next().split(" ").map(String::toLong)
fun nextDoubleList() = next().split(" ").map(String::toDouble)

// ## Array
inline fun <reified T> sizedArray(size: Int, default: T) = Array(size) { default }

// ## mod^-1
//    [NOTE] CANNOT use this for 0, mod, 2mod, 3mod ...(return wrong value)
fun modinv(num: Long, mod: Long): Long {
    var a = num
    var b = mod
    var u = 1L
    var v = 0L
    while (b > 0) {
        val t = a.div(b)
        a -= t * b
        a = b.also { b = a } // swap a and b
        u -= t * v
        u = v.also { v = u } // swap u and v
    }
    u %= mod
    if (u < 0) u += mod
    return u
}

Measured memory_bytes: 65188
#include <bits/stdc++.h>
using namespace std;
#define trace1(a) cout << a << 'n';
#define trace2(a, b) cout << a << ' ' << b << 'n';
#define trace3(a, b, c) cout << a << ' ' << b << ' ' << c << 'n';
#define trace4(a, b, c, d) cout << a << ' ' << b << ' ' << c << ' ' << d << 'n';
#define trace5(a, b, c, d, e) cout << a << ' ' << b << ' ' << c << ' ' << d << ' ' << e << 'n';
#define trace6(a, b, c, d, e, f) cout << a << ' ' << b << ' ' << c << ' ' << d << ' ' << e << ' ' << f << 'n';
#define range(n) for(int i = 0; i < n; i++)
#define printArr(harry, tam) range(tam) cout << harry[i] << " n"[i == tam -1];
#define maxn -2000000 //negative value to break code and force you to put right constraint
#define mod 1000000007
#define md(x) (x) % mod;
#define sc scanf
#define pr printf
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ps push
#define prt(x) cout << (#x) << " is " << (x) << endl
#define EPS 1e-9
#define INF 1000000000
#define INFd 1e9
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
typedef vector<double> vd;

int main(){
    set<ll> s;
    ll a,b;
    cin>>a>>b;
    map<ll,ll> m;
    for(ll i=2;i*i<=a;i++)
    {
        if(a%i==0)
        {
          m[i]++;
          while(a%i==0)
          {
            a=a/i;
          }
        }
    }
    if(a>1)
      m[a]++;
    ll cnt=0;
    a=b;
      for(ll i=2;i*i<=a;i++)
      {
          if(a%i==0)
          {
            if(m[i])
                cnt++;
            while(a%i==0)
            {
              a=a/i;
            }
          }
      }
      if(a>1&&m[a])
        cnt++;

      cout<<cnt+1;
   return 0;
}


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

int main() {
  int s; cin >> s;
  set<int> st; st.insert(s);
  while (1) {
    if (s & 1) s = 3*s + 1;
    else s /= 2;
    if (st.count(s)) {
      cout << st.size() + 1 << endl;
      break;
    }
    st.insert(s);
  }
  return 0;
}


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

int main(){
    int n;
    cin >> n;
    int d[100010];

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

    sort(d, d+n);

    int ans = 0;
    int p = 0;

    d[n] = 334334;

    for(int i = 0;i < 100010;i++){
        while(d[p] == i) p++;
        if(p == n-p){
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vpii=vector<pii>;


void max_u(int&m, int v)
{
	if(m<v) m=v;
}

int main(void)
{
	int n, k;
	char sa[100000+4], *s=sa+1;
	while(scanf("%d%d\n%[01]", &n, &k, s)==3)
	{
		vpii vl;

		int p='1';
		int l=0;
		int t=0;
		for(int i=0;i<n;i++)
		{
			if(p!=s[i])
			{
				vl.push_back(make_pair(t, t+l));
				l=1;
				t=i;
			}
			else
			{
				l++;
			}
			p=s[i];
		}
		vl.push_back(make_pair(t, t+l));

		int ck=k*2;
		if(ck>vl.size()) ck=vl.size();

		vl.push_back(make_pair(n, n));
		vl.push_back(make_pair(n, n));
/*
		for(auto mvl:vl)
		{
			printf("[%d,%d],", mvl.first, mvl.second);
		}
		printf("\n");
*/
		int ans=-1;
		for(int i=0;i+ck<vl.size();i+=2)
		{
			max_u(ans, vl[i+ck].second-vl[i].first);
		}
		printf("%d\n", ans);
	}
	return 0;
}


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

using namespace std;

void showStack(vector<int> A){
	for (int i = 0; i < A.size(); i++){
		cout << A[i] << " ";
	}
	cout << endl;
}

int main(){
	vector<int> A;
	string input;

	while (cin >> input){
		if (input[0] == '+'){
			int m = A[A.size() - 1];
			A.pop_back();
			int n = A[A.size() - 1];
			A.pop_back();
			A.push_back(m + n);
		}
		else if (input[0] == '-'){
			int m = A[A.size() - 1];
			A.pop_back();
			int n = A[A.size() - 1];
			A.pop_back();
			A.push_back(n - m);
		}
		else if (input[0] == '*'){
			int m = A[A.size() - 1];
			A.pop_back();
			int n = A[A.size() - 1];
			A.pop_back();
			A.push_back(m * n);
		}
		else{
			A.push_back(stoi(input));
		}
	}

	cout << A[0] << endl;

	return 0;
}

Measured memory_bytes: 3204
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <unordered_set>
#include <algorithm>
#include <cctype>
#define rep(x,y,z) for(long long x=y;x<z;++x)
#define dwn(x,y,z) for(long long x=y;x>z;--x)
using namespace std;

typedef long long ll;

int main() {
    ll n, W;
    cin >> n >> W;
    vector<ll> w(n), v(n);
    for (ll i = 0; i < n; i++) {
        cin >> w[i] >> v[i];
    }
    vector<vector<ll>> res(n);
    for (auto& x: res) {
        x.resize(W + 1);
    }
    for (ll j = 1; j <= W; j++) {
        if (j >= w[0]) {
            res[0][j] = v[0];
        }
    }
    for (ll i = 1; i < n; i++) {
        for (ll j = 1; j <= W; j++) {
            res[i][j] = res[i - 1][j];
            ll tmp = 0;
            if (j - w[i] >= 0) {
                tmp = res[i - 1][j - w[i]] + v[i];
            }
            if (tmp > res[i][j]) res[i][j] = tmp;
        }
    }
    cout << res[n - 1][W] << endl;
    return 0;
}


Measured memory_bytes: 78592
import math
import numpy as np
N=int(input())
H=list(map(int,input().split(' ')))

d=np.diff(H)
count=0
max_=0
for x in d:
  if x<=0:
    count+=1
    if max_<count:
      max_=count
  else:
    count=0

print(max_)


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

/* */

int main(){

    int n, m, sum;
    cin >> n >> m ;
    sum = 0;
    // **************************************
    int a[m];
    for(int i=0; i<m; i++) {
        cin >> a[i];
        sum += a[i];
    }
    // **************************************
    
    if(n - sum >= 0){
        cout << n-sum << endl;
    }else{
        cout << -1 << endl;
    }


    return 0;
}

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

int main(){
  int N,K,j,ans;
  ans=0;
 cin>>N>>K;
  vector<int>c(N);
  for(int i=0;i<N;i++){
cin>>c[i];
  }
    for(int i=0;i<N;i++){
  if(c[i]==1){
    i=j;
    break;
  }
  } 
ans+=j/(K-1)+(N-j-1)/(K-1);
  if(j%(K-1)!=0){
    ans++;
  }
   if((N-j-1)%(K-1)!=0){
    ans++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 640
N = int(input())
S = list(map(int, input().split()))
A = {}
t = 0
ans = 0
for s in S:
    t+=s
    if t == 0:
        ans+=1
    if t in A:
        A[t]+=1
        ans+=A[t]
    else:
        A[t]=0

print(ans)

Measured memory_bytes: 39564
#include "bits/stdc++.h"
using namespace std;
#define mod 1000000007
#define ll long long
#define cases ll t;cin>>t;while(t--)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)


int main(){
    //fast;
    ll i,j,n,k,m,x,y,cnt=1;
    cin>>k;
        vector<ll> v;
        for(i=1;i<10;i++){
            v.push_back(i);
        }
        if(k<11) {cout<<k;return 0;}
        ll ans;
        while(i<k){
            j=0;
            vector<ll> tmp;
            while(i<=k && j<(ll)v.size()){
                x=v[j];
                y=x%10;
                if(y-1>=0){
                    tmp.push_back(x*10+(y-1));
                    i++;
                }
                if(i>k) break;

                if(y>=0){
                    tmp.push_back(x*10+y);
                    i++;
                }
                if(i>k) break;

                if(y+1<10){
                    tmp.push_back(x*10+(y+1));
                    i++;
                }
                j++;
            }
            bool chk=false;
            if(j==v.size()){chk=true;tmp.push_back(v[j-1]*10+10);}
            ans=tmp[(ll)tmp.size()-1];
            v.resize(0);
            ll zz=(ll)tmp.size();
            if(chk) zz--;
            for(j=0;j<zz;j++){
                v.push_back(tmp[j]);
                //cout<<tmp[j]<<" ";
            }
        }
        //cout<<"\n";
        cout<<ans<<"\n";


    return 0;
}


Measured memory_bytes: 1280
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<map>
using namespace std;
const double EP = 1e-8;
struct P{
    double x,y;
}p[55];
int n;
bool compare(P a,P b){
    if(a.x==b.x)return a.y<b.y;
    return a.x<b.x;
}
struct pp{
    map<double,double>aa;
}cc;
int main(){
    map<struct pp,int> bb;
    scanf("%d",&n);
    if(n==1){
        cout<<1<<endl;
        return 0;
    }
    for(int i=0;i<n;i++){
        scanf("%lf%lf",&p[i].x,&p[i].y);
    }
    sort(p,p+n,compare);
    int ans=-1;
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            int cnt=0;
            if(i==j)continue;
            double xx=p[j].x-p[i].x;
            double yy=p[j].y-p[i].y;
            for(int h=0;h<n-1;h++){
                for(int g=h+1;g<n;g++){
                    if(p[g].x-p[h].x==xx&&p[g].y-p[h].y==yy){
                        cnt++;
                    }
                }
            }
            //cout<<cnt<<endl;
            ans=max(ans,cnt);
        }
    }
    cout<<n-ans<<endl;
    return 0;
}


Measured memory_bytes: 256
import math

n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

r_1 = 0
r_2 = 0
r_3 = 0
r_inf = 0

for i in range(n):
    r_1 += abs(x[i]-y[i]) 
print(r_1)

for i in range(n):
    r_2 += (x[i]-y[i])**2
r_2 = math.sqrt(r_2)
print(r_2)

for i in range(n):
    r_3 += abs(x[i]-y[i])**3
r_3 = math.pow(r_3, (1.0/3.0))
print(r_3)

for i in range(n):
    r_inf = max(abs(x[i]-y[i]), r_inf)
print(r_inf)




Measured memory_bytes: 5692
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()

l = 0
r = N
print(0, flush=True)
retl = input()
if retl == "Vacant": exit()
print(N-1, flush=True)
retr = input()
if retr == "Vacant": exit()
while l+1 != r:
	m = (l+r)//2
	print(m, flush=True)
	retm = input()
	if retm == "Vacant": exit()
	if (l-m)%2 == 0 and retl == retm or (l-m)%2 == 1 and retl != retm:
		l = m
		retl = retm
	else:
		r = m
		retr = retm

print(l, flush=True)
_ = input()


Measured memory_bytes: 5800
h,w = map(int, input().split())
grid = [list(input()) for i in range(h)]
error = False
for i in range(h):
    for j in range(w):
        if grid[i][j] == "#":
            if i > 0 and grid[i-1][j] == "B":
                grid[i][j] = "B"
            elif j > 0 and grid[i][j-1] == "B":
                grid[i][j] = "B"
            elif i < h-1 and (grid[i+1][j] == "B" or grid[i+1][j] == "#"):
                grid[i][j] = "B"
                grid[i+1][j] = "B"
            elif j < w-1 and (grid[i][j+1] == "B" or grid[i][j+1] == "#"):
                grid[i][j] = "B"
                grid[i][j+1] = "B"
            else:
                error = True
                break
    if error == True:
        break
if error == True:
    print("No")
else:
    print("Yes")


Measured memory_bytes: 3064
using System;

namespace ITP1_7_D
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int n = int.Parse(input[0]);
            int m = int.Parse(input[1]);
            int l = int.Parse(input[2]);

            int[,] tbl_a = new int[n,m];
            int[,] tbl_b = new int[m,l];
            //A
            for (int j=0; j<n; j++)
            {
                string[] tmp = Console.ReadLine().Split(' ');

                for (int k=0; k<m; k++)
                {
                    tbl_a[j, k] = int.Parse(tmp[k]);
                }
            }

            //B
            for (int p=0; p<m; p++)
            {
                string[] tmp2 = Console.ReadLine().Split(' ');

                for (int q=0; q<l; q++)
                {
                    tbl_b[p, q] = int.Parse(tmp2[q]);
                } 
            }

            //A*B
            for (int r=0; r<n; r++)
            {
                for (int s=0; s<l; s++)
                {
                    long value = 0;
                    for (int t=0; t<m; t++)
                    {
                        value += tbl_a[r, t] * tbl_b[t, s];
                    }

                    if (s != (l - 1))
                    {
                        Console.Write("{0} ", value);
                    }
                    else
                    {
                        Console.Write(value);
                        Console.WriteLine();
                    }
                }
            }
        }
    }
}

Measured memory_bytes: 9576
class Node:
	def __init__(self, value):
		self.value = value
		self.next = None

class SimpleQueue:
	def __init__(self):
		self.size = 0
		self.head = None
		self.tail = None
		return

	def enqueue(self, value):
		node = Node(value)
		if self.head == None:
			self.head = node
			self.tail = node
		else:
			self.tail.next = node
			self.tail = node
		self.size += 1

	def dequeue(self):
		if self.is_empty() == True:
			return None
		node = self.head
		self.head = self.head.next
		if self.head == None:
			self.tail = None
		self.size -= 1
		return node.value

	def peek(self):
		if self.is_empty() == True:
			return None
		return self.head.value

	def get_size(self):
		return self.size

	def is_empty(self):
		return self.size == 0

	def __str__(self):
		str_ = '['
		current = self.head
		while current != None:
			str_ += str(current.value)
			current = current.next
			if current != None:
				str_ += ', '
		str_ += ']['
		if self.tail != None:
			str_ += str(self.tail.value)
		str_ += ']'
		return str_

class Process:
	def __init__(self, name, time):
		self.name = name
		self.time = int(time)

	def set_time(self, time):
		self.time = time

n, q = map(int, input().split())
myqueue = SimpleQueue()
for i in range(n):
	name, time = map(str, input().split())
	myqueue.enqueue(Process(name, time))

time_elapsed = 0
while myqueue.is_empty() != True:
	process = myqueue.dequeue()
	time = process.time
	if time > q:
		process.set_time(time - q)
		time_elapsed += q
		myqueue.enqueue(process)
	else:
		time_elapsed += time
		print(process.name + ' ' + str(time_elapsed))



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

using namespace std;

//State
//dp[i][k]: The number of ways of coloring the subtree rooted
// at i can be colored with i being colored white(k=0) or i being colored black(k=1)

//Initialization
//For all nodes i with no children(leaf nodes) dp[i][0] = 1 and dp[i][1]=1

//Transitions: If root is white the children can be ehite or black but if root is black children must be white
//dp[parent][0] = max(dp[child1][0],dp[child1][1]) + max(dp[child2][0],dp[child2][1]) + max(dp[child3][0],dp[child3][1])
//dp[parent][1] = dp[child1][0] + dp[child2][0] +dp[child3][0]

//Order of Evaluation
//DFS

//Answer
//dp[root][0]+dp[root][1] Sum this over all connected components

//Time Complexity: O(N)

const long long mod = 1e9+7;
long long dp[100005][2] = {0};
long long visited[100005] = {false};
vector<vector<long long>> adjList(100005, vector<long long>(0));
long long N;

void dfs(long long node, long long parent){
	vector<long long> children = adjList[node];
	visited[node] = true;
	long long numChild = children.size();
	if(numChild==0 || (numChild==1 && children[0]==parent)){
		dp[node][0] = 1;
		dp[node][1] = 1;
		return;
	}
	long long temp1 = 1;
	long long temp2 = 1;
	for(long long child: children){
		if(child != parent && !visited[child]){
			dfs(child, node);
			temp1 = ((temp1 % mod)*((dp[child][0] + dp[child][1]) % mod)) % mod;
			temp2 = (temp2*dp[child][0]) % mod;
		}
	}
	dp[node][0] = temp1;
	dp[node][1] = temp2;
}

int main(){
	cin >> N;
	long long x, y;
	for(long long i=1; i<N; i++){
		cin >> x >> y;
		x = x-1;
		y = y-1;
		adjList[x].push_back(y);
		adjList[y].push_back(x);
	}

	long long root = 0;
	dfs(root, -1);
	cout << (dp[root][0]+dp[root][1]) % mod << endl;
}












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

int main(){
	#ifndef ONLINE_JUDGE
	    // for getting input from input.txt
	    freopen("input.txt", "r", stdin);
	    // for writing output to output.txt
	    freopen("output.txt", "w", stdout);
	#endif

	string username1, username2;
	cin >> username1;
	cin >> username2;
	if(username2.size() > username1.size()+1){
		cout << "No";
		return 0;
	}
	for(int i=0;i<username2.size() - 1;i++){
		// cout << username1[i] << username2[i];
		if(username1[i]!=username2[i]){
			cout << "No";
			return 0;
		}
	}
	cout << "Yes";
	return 0;
}

Measured memory_bytes: 3628
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long mod = 100000;
const long long inf = 1ll << 61;
typedef pair<int, int> P;
typedef pair<int,P> PP;
typedef pair<int,PP> PPP;
struct edge { int to;  int cost; };

int solve(int a) {
	int res = 0;
	rep(i, 50) {
		int shu = 1ll << (i + 1);//0...01...1
		int cnt = 0;
		cnt += (shu / 2)*(a / shu);
		cnt += max(0ll, (a%shu) - (shu / 2)+1);
		cnt &= 1;
		res += cnt << i;
	}
	return res;
}

signed main() {
	int a, b; cin >> a >> b;
	cout << (solve(b) ^ solve(a - 1)) << endl;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		
		int n  = sc.nextInt();
		
		double r = 2. * Math.PI * (double)n ;
		System.out.println(r);
	}
	
	
}

Measured memory_bytes: 27188
#include <iostream>
#include <math.h>
#include <cstdio>
#include <utility>
#include <queue>
#include <vector>
#include <algorithm>

using namespace std;

int n,x;

int main() {
  
  while(1){
  
   cin>>n>>x;
  
   if(n==0) break;
   
   int ans=0;
   
   for(int i=n; i>=3; i--){
     
     for(int j=1; j<=i-1; j++){
       
         if(j>=x-i-j){
         break;
         }
       
       if(x-i-j<=i-1){
         ans++;
         }
         
       }
       
     }
     
     cout<<ans<<endl;
  
  }
    
}

Measured memory_bytes: 1160
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Date;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		PrimeNumberGenerator png = new PrimeNumberGenerator();
		int count = 0;

		for(int i = 0; i < n; i++){

			int m = Integer.parseInt(br.readLine());


			if(png.isPrime(m)){
					//System.out.println(i);
				count++;
			}


		}
		System.out.println(count);
	}

}

class PrimeNumberGenerator {
	private boolean[] isPrime= new boolean[100000001];

	public PrimeNumberGenerator() {
		//Date from = new Date();
		Arrays.fill(isPrime, true);

		isPrime[0] = false;
		isPrime[1] = false;
		isPrime[2] = true;

		for(int i = 3; i <= Math.sqrt( isPrime.length ); i+=2){
			/*
			if(i % 2 == 0){
				isPrime[i] = false;
				continue;
			}
			*/

			if(isPrime[i] == false){
				continue;
			}

			for(int j = i * 2; j <= isPrime.length - 1; j += i){
				isPrime[j] = false;
			}
		}
		//Date to = new Date();
		//System.out.println("init takes "+ (to.getTime() - from.getTime())+ "milli sec");
	}

	public boolean isPrime(int index){
		if(index % 2 == 0 && index != 2){
			return false;
		}
		return isPrime[index];
	}
}

Measured memory_bytes: 127568
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    x=I()
    if x:
        print(0)
    else:
        print(1)

main()


Measured memory_bytes: 61816
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
const lint MOD =1000000007;
const lint MAX = 10000000;
using Graph =vector<vector<lint>>;

 
lint fac[MAX], finv[MAX], inv[MAX];

void COMinit() // 二項係数を求める時は前処理としてCOMinit()をする
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return 0;
        }
    }

    // 素数である
    return 1;
}
  lint lcm(lint a,lint b){
      return a/__gcd(a,b)*b;
  }

  int main(){
    lint N;
    lint ans=0;
    cin>>N;
    pair<string,lint> x[N];
    rep(i,N){
            string s;
            lint g;
            cin>>s>>g;
            x[i]=make_pair(s,g);
            ans+=g;
    }
    string X;
    cin>>X;
    rep(i,N){
        string s;
        lint g;
        tie(s,g)=x[i];
        if(s!=X)ans-=g;
        else if(s==X){
            ans-=g;
            break;
        }
    }
cout<<ans;
  }
  

Measured memory_bytes: 256
import * as fs from 'fs';

export class Reader {
    lines: string[];
    currentLine: number;

    constructor() {
        this.lines = fs.readFileSync("/dev/stdin", "utf8").trim().split("\n");
        this.currentLine = 0;
    }

    readLine(): string {
        return this.lines[this.currentLine++];
    }

	readChars(): string[] {
		let S = this.readLine();
		return new Array(S.length).fill(null).map((_, i) => S.charAt(i));
	}

    readInt(): number {
        return Number(this.readLine());
    }

    readInts(): number[] {
        return this.readLine().split(" ").map(Number);
    }
}

let reader = new Reader();
let N = reader.readInt();
let C: number[] = []
let dp: number[] = new Array(N).fill(0);
dp[0] = 1;

for(let i=0; i<N; i++) {
	C.push(reader.readInt());
}

let prefix: number[] = new Array(200001).fill(0);
prefix[C[0]] = 1;
let modulo = 1000000007;

for(let i=1; i<N; i++) {
	dp[i] = dp[i-1];
	if (C[i] != C[i-1]) {
		dp[i] = (dp[i]+prefix[C[i]])%modulo;
		prefix[C[i]] = (prefix[C[i]]+dp[i-1])%modulo;
	}
}

console.log(dp[N-1]);


Measured memory_bytes: 53688
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
using namespace std;

string s;
string solve(int l, int r) {
    int pos = l;
    string ret = "";
    for(pos=l; pos<r; pos++) {
        int cnt = 0;
        while(s[pos] == '-' || s[pos] == '+') {
            if(s[pos] == '-') cnt = (cnt - 1 + 26) % 26;
            if(s[pos] == '+') cnt = (cnt + 1 + 26) % 26;
            pos++;
        }
        if(isalpha(s[pos])) {
            char c = (char)('A' + (s[pos] - 'A' + cnt) % 26);
            ret += c;
        }
        else if(s[pos] == '?') ret += 'A';
        else if(s[pos] == '[') {
            int par = 0, tmp_l = pos+1;
            while(1) {
                if(s[pos] == '[') par++;
                if(s[pos] == ']') {
                    par--;
                    if(par == 0) {
                        int tmp_r = pos;
                        string tmp = solve(tmp_l, tmp_r);
                        reverse(tmp.begin(), tmp.end());
                        ret += tmp;
                        break;
                    }
                }
                pos++;
            }
        }
    }
    return ret;
}

int main() {
    while(cin >> s) {
        if(s == ".") break;
        int N = s.length();
        cout << solve(0, N) << endl;
    }
    return 0;
}


Measured memory_bytes: 3144
#include<iostream>
using namespace std;
int main()
{
    char w,x,y,z;
    cin>>w>>x>>y>>z;
    if (w==x&&y==z&&w!=y&&w!=z){cout<<"Yes";}
    else if(w==y&&x==z&&w!=x&&w!=z){cout<<"Yes";}
    else if(x==y&&w==z&&x!=w&&x!=z){cout<<"Yes";}
    else{cout<<"No";}


    return 0;

}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	
    public static void main(String[] args){
    	
        final Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        boolean[][] ju = new boolean[n+1][n+1];
        
        for(int i=0;i<n+1;i++){
            Arrays.fill(ju[i],false);
        }
        
        ArrayList<ArrayList<Integer>> gr = new ArrayList<ArrayList<Integer>>();
        
        for(int i=0;i<2;i++){
            gr.add(new ArrayList<Integer>());
        }
        
        for(int i=0;i<n;i++){
            int u = sc.nextInt();
            int k = sc.nextInt();
            for(int j=0;j<k;j++){
                int v = sc.nextInt();
                ju[u][v] = true;
            }
        }
         
        int[] d = new int[n+1];
        Arrays.fill(d,-1);
        d[1] = 0;
         
        for(int i=0;i<n;i++){
            for(int k=1;k<=n;k++){
                if(d[k]==i){
                    for(int j=1;j<=n;j++){
                        if(ju[k][j] && d[j]==-1){
                            d[j] = d[k] + 1;
                        }
                    }
                }
            }
        }
         
        for(int i=1;i<=n;i++){
            System.out.println(i+" "+d[i]);
        }
    }
}

Measured memory_bytes: 20868