akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	n, m := nextInt(), nextInt()

	num := make(map[int]int, n)
	for i := 0; i<m; i++ {
		s, c := nextInt(), nextInt()
		if v, ok := num[s]; ok {
			if v != c {
				fmt.Println("-1")
				return
			}
		}
		num[s] = c
	}

	//if v, ok := num[n]; ok {
	//	if v == 0 && len(num) == 1{
	//		fmt.Println(0)
	//		return
	//	}
	//}
	if v, ok := num[1]; ok {
		if v == 0 && n > 1{
			fmt.Println("-1")
			return
		}
	}

	for i := 1; i<=n; i++ {
		if v, ok := num[i]; ok {
			fmt.Print(v)
			continue
		}


		if i == 1 && n != 1{
			fmt.Print(1)
			continue
		}
		fmt.Print(0)
	}
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
const int MAX = 510000;
const int MOD = 1000000007;

     signed main(){
        int n,m,q;
        cin>>n>>m>>q;
        int dp[n][n];
        for(int i=0;i<n;i++)fill(dp[i],dp[i]+n,0);
        int l,r;
        for(int i=0;i<m;i++){
             cin>>l>>r;l--;r--;
             dp[l][r]++;
        }
        for(int i=n-2;i>=0;i--)for(int j=0;j<n;j++)dp[i][j]+=dp[i+1][j];
        for(int i=0;i<n;i++)for(int j=1;j<n;j++)dp[i][j]+=dp[i][j-1];

        for(int i=0;i<q;i++){
             cin>>l>>r;l--;r--;
             cout<<dp[l][r]<<endl;
        }
     }


 


 






    





      

        


Measured memory_bytes: 2816
import java.util.Scanner;
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        for(int i = 1; i <= n; i++){
            if(i % 3 == 0 || i % 10 == 3 || i >= 30 && i < 40 || i % 100 >= 30 && i % 100 <= 39 || i % 1000 >= 300 && i % 1000 <= 399 || i % 10000 >= 3000 && i % 10000 <= 3999) System.out.print(" " + i);
        }
        System.out.println();
    }
}


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

int main() {
    int n, k;
    string s;
    cin >> n >> k >> s;
    s[k-1] = s[k-1] + 32;
    cout << s;
}


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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  for (auto &e : h) cin >> e;
  sort(begin(h), end(h));
  int r = 1e9;
  for (int i = 0; i + k - 1 < n; i++) r = min(r, h[i + k - 1] - h[i]);
  cout << r << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define re register
#define inc(i,j,k) for(re int i=j;i<=k;i++)
#define ll long long
using namespace std;
const int mod=1e9+7;
const int N=5005;
ll qp(ll x,ll k){
	ll res=1;
	while(k){
		if(k&1) res=res*x%mod;
		k>>=1,x=x*x%mod;
	}
	return res;
}
int n,a,b;
ll f1[N],f2[N],f3[N],f4[N];
ll g1[N],g2[N];
int main() {
    scanf("%d%d%d",&n, &a, &b);
	if(a>b) swap(a,b);
	if(a==1) return printf("%lld\n", qp(2,n)),0;
	f1[1]=1;
    inc(i,2,b-1){
    	f1[i]=1;
    	inc(j,1,i-1) f1[i]=(f1[i]+f2[i-j])%mod;
    	inc(j,a,i-1) f2[i]=(f2[i]+f1[i-j])%mod;
    	inc(j,1,i-1) f3[i]=(f3[i]+f4[i-j])%mod;
    	if(i>=a) f4[i]=1;
    	inc(j,a,i-1) f4[i]=(f4[i]+f3[i-j])%mod;
	}
    inc(i,i,n){
    	if(i<b) g1[i]=(f1[i]+f3[i])%mod;
    	inc(j,1,min(b-1,i-1)) g1[i]=(g1[i]+g2[i-j]*f1[j])%mod;
    	if(i<a) g2[i]=1;
    	inc(j,1,min(a-1,i-1)) g2[i]=(g2[i]+g1[i-j])%mod;
    }	
	ll ans=(g1[n]+g2[n])%mod;
	inc(j,1,n-1) ans=(ans+g2[n-j]*f2[j])%mod;
    printf("%lld\n",(qp(2,n)-ans+mod)%mod);
}

Measured memory_bytes: 4036
n=int(input())
a=list(map(int,input().split()))
b=0
for _ in a:
    for i in range(n-1,0,-1):
        if a[i]<a[i-1]:
            a[i],a[i-1]=a[i-1],a[i]
            b+=1
print(*a)
print(b)


Measured memory_bytes: 5612
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define MMP(a, b, c) make_pair(make_pair(a, b), c)
#define MAX 1000000000
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define PI 3.14159265359

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

    string Q;
    cin >> Q;
    string answer = "";
    for(int i=0; i<Q.size(); i++){
        if(Q[i] != 'B') answer += Q[i];
        else if(answer.size() > 0){
            answer.erase(answer.end()-1);
        }
    }
    cout << answer << endl;
    
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;

class Program
{
    static void Main()
    {
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        new Program().solve();
        Console.Out.Flush();
    }
    Scanner cin = new Scanner();

    List<int>[] G;
    int[] match;
    bool[] used;
    void solve()
    {
        int X = cin.nextint;
        int Y = cin.nextint;
        int E = cin.nextint;

        G = Enumerable.Range(0, X + Y).Select(i => new List<int>()).ToArray();

        for (int i = 0; i < E; i++)
        {
            var t = cin.scanint;
            G[t[0]].Add(t[1] + X);
            G[t[1] + X].Add(t[0]);
        }

        int res = 0;
        match = Enumerable.Repeat(-1, X + Y).ToArray();

        for (int i = 0; i < X + Y; i++)
        {
            if (match[i] < 0)
            {
                used = new bool[X + Y];
                if (dfs(i))
                {
                    res++;
                }
            }
        }

        Console.WriteLine(res);
    }
    bool dfs(int v)
    {
        used[v] = true;
        foreach (var u in G[v])
        {
            int w = match[u];
            if (w < 0 || !used[w] && dfs(w))
            {
                match[v] = u;
                match[u] = v;
                return true;
            }
        }
        return false;
    }
}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return Console.ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

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

int N;
int counts[8];

int main(){
    cin >> N;
    
    int unicount = 0;
    
    for(int i=0; i<N; i++){
        int r; cin >> r;
        if(r >= 3200)
            unicount++;
        else
            counts[r/400]++;
    }
    int s = 0;
    for(int i=0; i<8; i++){
        if(counts[i])
            s++;
    }
    if(s != 0){
        cout << s << " " << s+unicount << endl;
    }else{
        cout << 1 << " " << unicount << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
N = int(input())
C = {i:0 for i in range(1,N+1)}
for x in range(1,142):
    for y in range(1,142):
        for z in range(1,142):
            a = (x+y)**2+(y+z)**2+(z+x)**2
            if a%2==0 and a//2<=N:
                C[a//2] += 1
for i in range(1,N+1):
    print(C[i])

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

int main(void)
{
    using namespace std;

    for (int i = 0; i < 1200; i++) {
        char ch;
        scanf("%c", &ch);
        if ('a' <= ch && ch <= 'z') {
            printf("%c", (ch - 32));
        } else if ('A' <= ch && ch <= 'Z') {
            printf("%c", (ch + 32));
        } else {
            printf("%c", ch);
        }
        if (ch == '\n') {
            break;
        }
    }
}


Measured memory_bytes: 3140
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int C[N], S[N], F[N];
    rep(i, N-1) cin >> C[i] >> S[i] >> F[i];

    rep(i, N-1) {
        int T = 0;
        REP(j, i, N-2) {
            T = max(T, S[j]);
            T = T + (F[j] - T % F[j]) % F[j] + C[j];
            //dump(T);
        }
        cout << T << endl;
    }
    cout << 0 << endl;

    return 0;
}


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


int main(){
    string S;
    cin >> S;
    int count=0;
    int ans=0;
    for (int i = 0; i < S.size(); i++){
        int j=i;
        while(S[j]=='A' || S[j]=='C' || S[j]=='G' || S[j]=='T'){
            count++;
            j++;
        }
        ans=max(ans,count);
        count=0;

    }
    cout << ans << endl;
    

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 


////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////
P x[110000];
signed main(){
  int n,ans = 0;cin>>n;
  rep(i,n){
    int xx, l;cin>>xx>>l;
    x[i].first = xx + l;x[i].second = xx - l;
  }
  sort(x, x+n);
  int now = x[0].first;ans++;
  repd(i,1,n){
    if(x[i].second >= now){
      ans++;
      now = x[i].first;
    }
  }
  cout << ans << endl;
}



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

int main () {
  string S;
  cin >> S;
  
  int ans = 0;
  for (int i = 0; i < S.size(); i++) {
    if (S.at(i) == '+') {
      ans++; 
    }
    else {
      ans--;
    }
  }
    cout << ans << endl;
  }

Measured memory_bytes: 256
f_inf = float('inf')
N = int(input())
h = list(map(int, input().split(' ')))
h.append(f_inf)
h.append(f_inf)
dp = [f_inf for _ in range(N + 100)]
dp[0] = 0
for i in range(N-1):
  dp[i+1] = min(dp[i] + abs(h[i+1] - h[i]), dp[i+1])
  dp[i+2] = min(dp[i] + abs(h[i+2] - h[i]), dp[i+2])
print(dp[N-1])

Measured memory_bytes: 13976
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
    int n,r;
    scanf("%d%d",&n,&r);
    int ans;
    if(n<10) ans=r+100*(10-n);
    else ans=r;
    printf("%d\n",ans);
    return 0;
}


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

int s[100];
int top = 0;

void push(int v) {
  s[++top] = v;
}

int pop() {
  return s[top--];
}

int main(void) {
  int a, b;
  char v[10];

  while(scanf("%s ", v) != EOF) {
    if (v[0] == '+') {
      a = pop();
      b = pop();
      push(a + b);
    }
    else if (v[0] == '-') {
      a = pop();
      b = pop();
      push(b - a);
    }
    else if (v[0] == '*') {
      a = pop();
      b = pop();
      push(a * b);
    }
    else {
      push(atoi(v));
    }
  }

  printf("%d\n", pop());
 
  return 0;
}



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

typedef std::pair<int, int> pi;
int R, C, n;
std::vector<pi> v;
int get() {
	int x, y; std::cin >> x >> y;
	if (y == 0) return x;
	if (x == R) return R + y;
	if (y == C) return R * 2 + C - x;
	if (x == 0) return R * 2 + C * 2 - y;
	return -1;
}
int st[100010], top;
int main() {
	std::ios_base::sync_with_stdio(false), std::cin.tie(0);
	std::cin >> R >> C >> n;
	for (int i = 1, x, y; i <= n; ++i) {
		x = get(), y = get(); if (x > y) std::swap(x, y);
		if (x != -1 && y != -1) v.emplace_back(x, y);
	}
	std::sort(v.begin(), v.end());
	for (auto t : v) {
		while (top && t.first > st[top]) --top;
		if (top && t.second > st[top])
			return std::cout << "NO" << std::endl, 0;
		st[++top] = t.second;
	}
	std::cout << "YES" << std::endl;
	return 0;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define INF (1<<29)
#define all(c) (c).begin(),(c).end()
#define pb(c) push_back(c)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;


int main(){
  ios::sync_with_stdio(false);
  vector<P> v(4);

  for(int i = 0; i < 4; i++){
    cin >> v[i].first >> v[i].second;
  }

  for(int i = 0; i < 4; i++){
    if(v[i].first == 1) cout << v[i].second*6000 << endl;
    if(v[i].first == 2) cout << v[i].second*4000 << endl;
    if(v[i].first == 3) cout << v[i].second*3000 << endl;
    if(v[i].first == 4) cout << v[i].second*2000 << endl;
  }

}

Measured memory_bytes: 1200
#include<iostream>
#include<bits/stdc++.h>
#include<string>
using namespace std;
int main()
{
   char s[1000];
   cin>>s;
   int l,k=0,i,j,m=1;
   l=strlen(s);
   sort(s,s+l);
  // cout<<s<<endl;
   for(i=0;i<l-1;i++){
    if(s[i]==s[i+1]){
      m++;
    }
    else{
        if(m%2==0){
            m=1;
        }
        else{
                //cout<<i<<endl;
      //  cout<<m<<endl;
            cout<<"No"<<endl;
            return 0;
        }
    }
   }
   if(m%2==0){
     cout<<"Yes"<<endl;
   }
   else{
    cout<<"No"<<endl;
   }
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define INF (ll)1e18+4
#define md (ll)1e9+7
#define mx 10000000
#define mk make_pair
#define __builtin_popcountll(x) one(x)
#define pi pair<int,int>
#define ss second
#define ff first
#define pb emplace_back 
#define all(s) s.begin(),s.end()
#define rall(x) (x).rbegin(), (x).rend()
#define trav(x, a) for (auto& x: a)
#define fr(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=a;i>b;i--)
#define rf(i,a,b) for(int i=a;i>=b;i--)
#define sz(x) ((long long)x.size())
#define mez(s) memset(s,0,sizeof s)
#define mex(s) memset(s,-1,sizeof s)
#define metr(s) memset(s,true, sizeof s)
typedef vector<int> vi; 
typedef vector<ll>vl;
typedef map<int,int> mp;
typedef queue<int> que;
typedef vector<pi> vp;

void solve(){
  int n,x=0,y=0,d=0;
  cin>>n;;
  string st,s="";
  cin>>st;
  rep(i,0,n){
  	if(st[i]=='R')
  	x++;
  	else
  	y++;
  }
  rep(i,0,x)s+='R';
  rep(i,0,y){
  	s+='W';
  }
  rep(i,0,n){
  	if(st[i]!=s[i]){
  		d++;
	  }
  }
  cout<<d/2;
}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t=1;
   //cin>>t;
  while(t--){
  	solve();
  }
  return 0;
}

Measured memory_bytes: 3824
#include<stdio.h>
#include<string.h>
#define MAX 1000


int lcs(char*,char*);

int main(){
  int i,q;
  char X[MAX],Y[MAX];
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%s %s",X,Y);
    printf("%d\n",lcs(X,Y));
  }

  return 0;
}


int lcs(char *X,char *Y){
  int m,n,i,j,max=0;
  int c[MAX+1][MAX+1];
  m=strlen(X);
  n=strlen(Y);
  for(i=0;i<=m;i++)c[i][0]=0;
  for(j=0;j<=n;j++)c[0][j]=0;

  for(i=1;i<=m;i++){
    for(j=1;j<=n;j++){
      if(X[i-1]==Y[j-1]){
	c[i][j]=c[i-1][j-1]+1;
      }else if(c[i-1][j]>=c[i][j-1]){
	c[i][j]=c[i-1][j];
      }else{
	c[i][j]=c[i][j-1];
      }
      if(max<c[i][j])max=c[i][j];
    }
  }
  return max;
}



Measured memory_bytes: 5652
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <unordered_map> 
#include <map> 
#include <numeric>
#include <limits>
#include <utility>
#include <queue>
#include <random>
#include <bitset>
#include <memory>
using namespace std;
typedef long long LL;

int main() {
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    vector<int> xx(n);
    vector<int> yy(m);

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

    sort(xx.begin(), xx.end());
    sort(yy.begin(), yy.end());

    for (int i = -200; i < 200; i++) {
        if (x < i&&i <= y) {
            if (xx[n - 1] < i) {
                if (yy[0] >= i) {
                    cout << "No War" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "War" << endl;
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3

from collections import defaultdict
from heapq import heappush, heappop
import sys

sys.setrecursionlimit(10**6)
input = sys.stdin.buffer.readline
INF = 10 ** 9 + 1  # sys.maxsize # float("inf")


def debug(*x):
    print(*x)


def solve1(N, heights):
    heights += [INF]
    costs = [INF] * (N + 1)
    costs[0] = 0
    for i in range(N - 1):
        costs[i + 1] = min(
            costs[i + 1],
            costs[i] + abs(heights[i + 1] - heights[i]))
        costs[i + 2] = min(
            costs[i + 2],
            costs[i] + abs(heights[i + 2] - heights[i]))
    return costs[N - 1]


def solve2(N, heights):
    costs = [0] * N
    costs[0] = 0
    costs[1] = abs(heights[1] - heights[0])
    for i in range(2, N):
        costs[i] = min(
            costs[i - 2] + abs(heights[i] - heights[i - 2]),
            costs[i - 1] + abs(heights[i] - heights[i - 1]),
        )
    return costs[-1]


def solve(N, heights):
    costs = [None] * N
    costs[0] = 0
    costs[1] = abs(heights[1] - heights[0])

    def get_cost(i):
        if costs[i] != None:
            return costs[i]

        c = min(
            get_cost(i - 2) + abs(heights[i] - heights[i - 2]),
            get_cost(i - 1) + abs(heights[i] - heights[i - 1]),
        )
        costs[i] = c
        return c

    return get_cost(N - 1)


def main():
    N = int(input())
    heights = list(map(int, input().split()))
    print(solve(N, heights))


def _test():
    """
    >>> solve(4, [10, 30, 40, 20])
    30
    >>> solve(2, [10, 10])
    0
    >>> solve(6, [30, 10, 60, 10, 60, 50])
    40
    """
    import doctest
    doctest.testmod()


def as_input(s):
    "use in test, use given string as input file"
    import io
    global read, input
    f = io.StringIO(s.strip())
    input = f.readline
    read = f.read


USE_NUMBA = False
if (USE_NUMBA and sys.argv[-1] == 'ONLINE_JUDGE') or sys.argv[-1] == '-c':
    print("compiling")
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('solve', solve.__doc__.strip().split()[0])(solve)
    cc.compile()
    exit()
else:
    input = sys.stdin.buffer.readline
    read = sys.stdin.buffer.read

    if (USE_NUMBA and sys.argv[-1] != '-p') or sys.argv[-1] == "--numba":
        # -p: pure python mode
        # if not -p, import compiled module
        from my_module import solve  # pylint: disable=all
    elif sys.argv[-1] == "-t":
        _test()
        sys.exit()
    elif sys.argv[-1] != '-p' and len(sys.argv) == 2:
        # input given as file
        input_as_file = open(sys.argv[1])
        input = input_as_file.buffer.readline
        read = input_as_file.buffer.read

    main()


Measured memory_bytes: 70744
s = input()
n = len(s)
sum = 0
for i in range(1<<n-1):  # n-1ビット左シフト (つまりn-1=2だと4, n-1=3だと8)
    t = 0
    for j in range(n-1):
        if i & (1 << j):
            sum += int(''.join(s[t:j+1]))
            t = j+1
    sum += int(''.join(s[t:]))
print(sum)

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

using ll = long long;

int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	string s;
	cin >> s;
	vector<ll> freq(2 * s.size() + 4, 0);
	ll ans = 0;
	ll cur = s.size() + 1;
	freq[cur] = 1;
	vector<ll> ans_delta;
	vector<pair<ll, ll> > delta;
	vector<ll> cur_delta;
	for(char r : s){
		if(r == '('){
			cur++;
			cur_delta.push_back(1);
			delta.push_back({cur, 1});
			delta.push_back({cur, 0});
			freq[cur]++;
			ans_delta.push_back(0);
		} else if(r == ')'){
			delta.push_back({cur, -freq[cur]});
			freq[cur] = 0;
			cur--;
			cur_delta.push_back(-1);
			ans += freq[cur];
			ans_delta.push_back(freq[cur]);
			delta.push_back({cur, 1});
			freq[cur]++;
		} else if(r == '-'){
			cur -= cur_delta.back();
			cur_delta.pop_back();
			ans -= ans_delta.back();
			ans_delta.pop_back();
			freq[delta.back().first] -= delta.back().second;
			delta.pop_back();
			freq[delta.back().first] -= delta.back().second;
			delta.pop_back();
		} else assert(false);
		cout << ans << '\n';
	}
}


Measured memory_bytes: 18744
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,f,t=0,m=0,h;cin>>n;
    if(n==1)cout<<1;
    else {
    for(int i=2;i<=n;i++){
            h=i;
        while(h>0&&h%2==0){
                h/=2;
                t++;
        }
        if(t>m){
            m=t;
            f=i;
        }
        t=0;
    }
    cout<<f<<endl;
    }
   return 0;
   }





Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
main(){
  int n,m;
  cin>>n>>m;
  set<int>s;
  int a[n];
  for(int i=0;i<n;i++)cin>>a[i];
  reverse(a,a+n);
  for(int i=0;i<m&&i<n;i++){
    if(!s.count(a[i])){
      cout<<a[i]<<endl;
      s.insert(a[i]);
    }
  }
}

Measured memory_bytes: 6004
#include<stdio.h>

 
int main()
{
    int n, i, j, sum, min, a[1000];
     
    while(scanf("%d",&n))
    {
        if(n==0)
            break;
        else
        {
            for(i=0;i<n;i++)
                scanf("%d",&a[i]);
            min = 1000000;
            for(i=0;i<n-1;i++)
            {
                for(j=i+1;j<n;j++)
                {
                    sum = a[i]-a[j];
                    if(sum<0)
                        sum = sum * (-1);
                    if(min>sum)
                        min = sum;
                }
            }
            printf("%d\n",min);
        }
    }
    return 0;
}


Measured memory_bytes: 2040
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
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; }
long long weight[110];
long long value[110];
long long dp[110][100010];

int main() {
  int n,w; cin>>n>>w;
  for(long long i=0; i<n;i++){
    cin>>weight[i];
    cin>>value[i];
  }  
  for(int i=0;i<n;i++){
    for(int j=0;j<100010;j++){
      dp[i][j]=INF;
    }
  }
  dp[0][0]=0;
  for(int i=0;i<n;i++){
    for(int j=0;j<100010;j++){
      if(j-value[i]>=0)   dp[i+1][j]=min(dp[i][j-value[i]]+weight[i],dp[i][j]);
      else dp[i+1][j]=dp[i][j];
    }
  }
  long long ans=0;
  for(int i=0;i<100010;i++){
      if(dp[n][i]<=w) ans=i;
  }
  cout<<ans<<endl;
}


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


int main() {
    string w;
    cin >> w;

    vector<int> word(25, 0);

    for (int i = 0; i < w.size(); ++i) {
        ++word[w[i] - 'a'];
    }

    for (int i = 0; i < word.size(); ++i) {
        if (word[i] % 2 == 1) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
typedef long double ll ;

int main()
{
     
     long long n,k;
     cin >> n >> k;
     ll a[n],p[n];
     ll sum=0,maxi=-1;
     for(long long i=0; i<n; i++){
        cin >>a[i];
          p[i]=((a[i]*(a[i]+1))/2.0);
          p[i]/=a[i];
       }
     for(long long i=0; i<k; i++){
       sum+=p[i];
     }
     ll curr_sum=sum;
     for(long long i=k; i<n; i++){
       curr_sum+=p[i]-p[i-k];
       sum=max(sum,curr_sum);
     }
     
     printf("%.10Lf",sum);
    
     
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
long long const c=1e18;
int main()
{long long int n;
 cin>>n;
 vector<long long int>vec(n);
 for(long long int i=0;i<n;i++)
 {long long int k;
  cin>>k;
  if(k==0)
  {cout<<"0";
   return 0;}
  else
    vec[i]=k;
 }
 long long int prod=1;
 for(long long int i=0;i<n;i++)
 {if(vec[i]>c/prod)
 {cout<<"-1";
  return 0;}
  else if(prod>c)
  {cout<<"-1";
   return 0;}
  prod*=vec[i];}
 cout<<prod;
}

Measured memory_bytes: 4048
/*
 * B.cpp
 *
 *  Created on: 2017/06/18
 *      Author: aihara
 */

#include<bits/stdc++.h>
#define MYDEBUG
#ifdef MYDBUG
#define dbp(x) cout<<#x<<": "<<x<<endl
#else
#define dbp(x)
#endif
#define ll long long
#define rep(i,from,to) for(int i=from; i<to; ++i)
#define REP(i,from,to) for(int i=from; i<=to; ++i)

using namespace std;

const int MAX_N = 1000100;
bool vis[MAX_N];
int num[MAX_N];
string s;
int n;

string myitoa(int n) {
	string ret = "";
	while (n > 0) {
		ret = (char) ((n % 10) + '0') + ret;
		n /= 10;
	}
	if (ret == "") {
		return "0";
	} else {
		return ret;
	}
}

void solve() {
	while (cin >> s >> n, n) {
		memset(vis, 0, sizeof(vis));
		memset(num, 0, sizeof(num));
		int zeroes = max(0, n - (int) s.size());
		s += string(zeroes, '0');
		int i = 0;
		vis[atoi(s.c_str())] = true;
		num[atoi(s.c_str())] = i;
		i++;
		while (true) {
			string big = s, small = s;
			sort(big.rbegin(), big.rend());
			sort(small.begin(), small.end());
//			cout << "big: " << big << endl;
//			cout << "sma: " << small << endl;
			int bigN = atoi(big.c_str());
			int smaN = atoi(small.c_str());
			int diff = bigN - smaN;
			s = myitoa(diff);
			zeroes = max(0, n - (int) s.size());
			s += string(zeroes, '0');
//			cout << "diff: " << diff << endl << endl;
			if (diff < 0) {
				cout << "ERROR" << endl;
				return;
			}
			if (!vis[diff]) {
				vis[diff] = true;
				num[diff] = i;
			} else { //found duplicate
				int j = num[diff];
				printf("%d %d %d\n", j, diff, i - j);
				break;
			}
			i++;
		}
	}
}

int main() {
	solve();
//	char str[100];
//	itoa(123, str, 10);
//	cout << str << endl;
//	string st = str;
//	cout << st << endl;
//	cout << st.size() << endl;

}

Measured memory_bytes: 8092
#include <stdio.h>

int main (){
    int n;
    int sum = 0;
    int d[50];
    scanf("%d ",&n);
    for(int i= 0;i<n;i++){
        scanf("%d",&d[i]);
    }
    for(int i=0;i<n; i++){
        for (int j = i+1;j<n;j++){
            sum += d[i]*d[j];
           
        }
    }
    printf("%d",sum);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main(void) {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a, b, c;
	cin >> a >> b >> c;
	if (a + b + c >= 22) {
		cout << "bust" << endl;
	}
	else {
		cout << "win" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

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

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<endl
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SUM(vec) accumulate(all(vec),0LL)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;}
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);}
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;}
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;}

int ctoi(char c){return c - '0';}

bool isOk(ll key,ll value){
  return key >= value;
}

ll binary_search(vector<ll> a,ll key){
  ll ok = a.size()-1;
  ll ng = 0;

  while(abs(ok - ng) > 1){
    ll mid = (ok + ng) / 2;
    if(isOk(key,a[mid]))ok = mid;
    else ng = mid;
  }
  return ok;
}

bool isPrime(ll n) {
	for (int i = 2; n >= i * i; ++i) {
		if(!(n % i))return false;
	}
  return true;
}
vector<ll> primes(ll n){
  vector<ll> v(1,1);
  for (ll i = 2; n >= i * i; ++i) {
		if(!(n % i)){
      v.pb(i);
	  }
  }
  if(v.size()==1)v.pb(n);
  return v;
}


int main() {
  cin.tie(0); ios::sync_with_stdio(0);
  int n;cin>>n;
  string s;cin>>s;
  int k;cin>>k;
  char c = s[k-1];
  rep(i,n){
    if(s[i] != c)s[i] = '*';
  }
  print(s);
  return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <stack>
#include <unordered_map>
#include <queue>
using namespace std;

int main () {
	int n, m;
	cin >> n >> m;
	vector<int> v(m, 0);
	for (int i = 0; i < n; i++) {
		int k;
		cin >> k;
		for (int j = 0; j < k; j++) {
			int temp;
			cin >> temp;
			v[temp - 1]++;
		}
	}
	int res = 0;
	for (auto vv : v)
		if (vv == n)
			res++;
	cout << res;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int K = sc.nextInt();
		long[] a = new long[N + 1];
		long[] b = new long[M + 1];
		for (int i = 1; i <= N; i++) {
			a[i] = a[i - 1] + sc.nextInt();
		}
		for (int i = 1; i <= M; i++) {
			b[i] = b[i - 1] + sc.nextInt();
		}
		int max = 0;
		for (int i = 0, j = M; i <= N; i++) {
			while (j >= 0 && K < a[i] + b[j]) j--;
			if (j < 0) break;
			max = Math.max(max, i + j);
		}
		System.out.println(max);
	}
}


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

int main()
{
    string s;
    cin >> s;
    //cout << s[2] << s[3] << endl;
    if(s[2] == s[3] && s[4] == s[5])
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
a_list=[]
op_list=[]
b_list=[]
while True:
  a, op, b = input().split()
  if op == '?':
    break
  a = int(a)                   
  b = int(b)
  a_list.append(a)
  op_list.append(op)
  b_list.append(b)
  
for (alist, oplist, blist) in zip(a_list, op_list, b_list):
  if oplist == '+': 
       print(alist+blist)
  elif oplist == '-':
       print(alist-blist)
  elif oplist == '*':
       print(alist*blist)
  elif oplist == '/':
       print(alist//blist)


Measured memory_bytes: 5600
#include<stdio.h>
int main()
{
    long long n,sum=0,T,max,min;
    scanf("%lld",&T);
    for(int i=1; i<=T; i++)
    {
        scanf("%lld ",&n);
        if(i==1)
            max=min=n;
        if(max<n)
            max=n;
        else if(min>n)
            min=n;
        sum=sum+n;
    }
    printf("%d %d %lld\n",min,max,sum);
    return 0;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
#define rep(i,cc,n) for(i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,0,v.size()-1)cout << v[i] << " ";cout << endl;
#define mod 1000000007

using namespace std;
class CompareFirst
{
public:
  bool operator()(pair<int,int> n1,pair<int,int> n2) {
    return n1.first>n2.first; //>:desc <:asc
  }
};


int main(){

  int h,w,wl,hl,ws,hs,w1,w2,h1,h2;

  cin >> h >> w >> wl >> hl;
  ws = w - wl;
  hs = h - hl;
  if(ws > wl)swap(ws,wl);
  if(hs > hl)swap(hs,hl);
  int s[h][w]={0};

  int flg = 0;
  rep(h1,0,h){
    h2 = h - h1;
    rep(w1,0,w){
      w2 = w - w1;
      if(ws*h1 + wl*h2 == hs*w1 + hl*w2){
        flg = 1;
        break;
      }
    }
    if(flg)break;
  }
  if(!flg){
    puts("No");
    return 0;
  }

  int i,j,k,l;
  int wide[w] = {0};
  int height[h] = {0};

  rep(i,1,w){
    if(i <= w1)wide[i-1] = hs;
    else wide[i-1] = hl;
  }
  rep(i,1,h){
    if(i <= h1)height[i-1] = ws;
    else height[i-1] = wl;
  }
  /*
  rep(k,0,w-1)cout << wide[k] << " ";
  cout << endl;
  rep(k,0,h-1)cout << height[k] << " ";
  cout << endl;cout << endl;
  */
  
  rep(i,1,h){
    vector<int> out(w,0);
  //  if(height[i-1] > 0){
      rep(j,1,w){
        if(height[i-1] > 0 && wide[j-1] > 0){
          out[j-1] = 1;
          wide[j-1]--;
          height[i-1]--;
        }
      }
 //   }
    reverse(out.begin(),out.end());
    rep(k,0,w-2)cout << out[k];
    cout << out[w-1] << endl;
  }
/*
  cout << endl;
  cout << hs << endl;
  cout << hl << endl;
  cout << ws << endl;
  cout << wl << endl;
  */
  
//  printf("%.10f\n",ans);

  return 0;

}

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

int main(){
    int a, b, c, d; cin >> a >> b >> c >> d;
    while (a>0 && c>0){
        c-=b;
        if (c<=0) break;
        a-=d;
    }
    if (a>0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define ll                      long long int
#define fi                      first
#define se                      second
#define pb                      push_back
#define pbb                     pop_back
#define mp                      make_pair
#define pii     	            pair<int,int>
#define all(x)                  x.begin(), x.end()
#define mem(array, value)       memset(array, value, sizeof(array))
#define fastRead 	            ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#ifdef Lollipop
    #define line                    cout << "\n===================\n"
    #define trace(...)              __f( #__VA_ARGS__ , __VA_ARGS__ )
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cerr << name << " = " << arg1 << "\n";
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ',');
        cerr.write(names, comma - names) << " = " << arg1 << " , ";
    __f(comma + 1, args...);
    }
#else
    #define line
    #define trace(...)
#endif

const int nax = 2e5 + 5;
int ara[nax];
map<int, int> MP;

int main ()
{
    #ifdef Lollipop
        freopen ("input.txt", "r", stdin);
        //freopen ("output.txt", "w", stdout);
    #endif
    //fastRead;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> ara[i];
        MP[ara[i]]++;
    }
    bool flag = false;
    for (int i = 0; i < n; i++){
        if (MP[ara[i]] > 1){
            flag = true;
            break;
        }
    }
    if (flag){
        cout << "NO\n";
    }
    else{
        cout << "YES\n";
    }
    return 0;
}




Measured memory_bytes: 10368
def readinput():
    n=int(input())
    d=list(map(int,input().split()))
    return n,d

def main(n,d):
    ds=sorted(d)
    m=n//2
    if ds[m-1]==ds[m]:
        return 0
    else:
        return ds[m]-ds[m-1]

if __name__=='__main__':
    n,d=readinput()
    ans=main(n,d)
    print(ans)


Measured memory_bytes: 20612
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O0")
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
const ll mod = 1e9+7;
const ll INF = 1e18;
#define All(a) (a).begin(),(a).end()
#define Pi acos(-1)
using Graph = vector<vector<ll>>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  chrono::system_clock::time_point start,end;
  start = chrono::system_clock::now();

  ll n, h;
  cin >> n >> h;
  vector<ll> a(n);
  vector<ll> b(n);
  ll ans = 0;
  rep(i,n) {
    cin >> a[i] >> b[i];
  }
  sort(All(a));
  sort(All(b));
  ll A = a[n-1];
  for (ll i = n-1; i >= 0; --i) {
    if (A < b[i]) {
      h -= b[i];
      ++ans;
    }
    else {
      break;
    }
    if (h <= 0) {
      cout << ans << '\n';
      return 0;
    }
  }
  ans += (h+A-1)/A;
  cout << ans << '\n';

  end = chrono::system_clock::now();
  auto elapsed = chrono::duration_cast< chrono::milliseconds >(end - start).count();
  cerr << elapsed << "ms" << '\n';
}

Measured memory_bytes: 4788
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iomanip>


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define rep(i, a, b) for (int i=a; i<(b); i++)
#define rp(i, a) for (int i=0; i<(a); i++)
#define repd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rpd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(9);
    cout << std::fixed;

    ll a[3];
    rp(i,3) cin >> a[i];
    sort(a,a+3);
    cout << a[0] + a[1]<<endl;

    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main ()
{
    int a,b,k;
    cin>>a>>b;
    if((a+b)%2!=0){
        cout<<"IMPOSSIBLE";
    }
        else {
    k=(a+b)/2;


    cout<<k;
        }
    return 0;

}


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

using namespace std;

int main() {
	int r, g, b;
	cin >> r >> g >> b;
	if ((100 * r + 10 * g + b) % 4 == 0){
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

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

int main() {
  string S;
  cin >> S;

  if (S.size() < 26) {
    for (char c = 'a'; c <= 'z'; c++) {
      if (!count(S.begin(), S.end(), c)) return cout << S + c << "\n", 0;
    } 
  } else {
    if (S == "zyxwvutsrqponmlkjihgfedcba") return cout << -1 << "\n", 0;
    for (int i = S.size() - 1; i >= 0; i--) {
      do S.at(i)++;
      while (count(S.begin(), S.end() - 1, S.at(i)));
      if (S.at(i) <= 'z') return cout << S << "\n", 0;
      S.pop_back();
    }
  }
}

Measured memory_bytes: 256
N = int(input())
A = [int(_) for _ in input().split()]
m = min(A)
while m > 0:
    for i in range(0,len(A)):
        if A[i] != m:
            A[i] = A[i]%m
    z = A.count(0)
    A = sorted(A)[z:]
    m = A[0]
    if m == 1:
        break
    else:
        if [_%m for _ in A] == [0]*len(A):
            break
print(m)


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

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

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

int main() {
 int n,m;
  cin >> n;
 vector<string> blue(n);
  for(int i=0;i<n;i++){
   cin >>blue[i];
  }
  cin >> m;
  vector<string> red(m);
  for(int i=0;i<m;i++){
   cin >>red[i];
  }
  int ans=-1;
  for(int i=0;i<n;i++){
    int cntb=0,cntr=0;
  string s=blue[i];
    for(int j=i;j<n;j++){
     if(s==blue[j])cntb++;
    }

    for(int k=0;k<m;k++){
      if(s==red[k])cntr++;
    }

    ans=max(ans,cntb-cntr);
  }

  if(ans>=0)cout << ans << endl;
  else cout << '0' << endl;

}


Measured memory_bytes: 256
import java.awt.*;
import java.io.*;
import java.util.*;
 
public class Main {
	Scanner sc = new Scanner(System.in);
	public static void main(String[] args){
		new Main();
	}
	public Main(){
		new TestB().doIt();
	}
	class TestB{
		void doIt() {
			int N = Integer.parseInt(sc.next());
			long ans = 0;
			long A = Long.parseLong(sc.next());
			for(int i = 1;i < N;i++) {
				long B = Long.parseLong(sc.next());
				if(B - A < 0) {
					ans = ans + (A - B);
				}else {
					A = B;
				}
			}
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 58500
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF 1LL<<62
#define MAX 510000
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(), (x).rend()
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;
const int mod = 1e9 + 7;

int main(){
    ll n; cin >> n;
    vvl G(n);
    rep(i,n-1){
        ll a,b; cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    queue<ll> q;
    q.push(0);
    q.push(n-1);
    vl visit(n,0);
    visit[0] = 1;
    visit[n-1] = 2;
    while(!q.empty()){
        ll u = q.front(); q.pop();
        for(auto v : G[u]){
            if(visit[v] > 0) continue;
            visit[v] = visit[u];
            q.push(v);
        }
    }
    ll cnt = 0;
    rep(i,n){
        if(visit[i]==1) cnt++;
        else cnt--;
    }
    if(cnt>0) puts("Fennec");
    else puts("Snuke");
}

Measured memory_bytes: 7168
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

signed main(){
    ll n;
    cin >> n;
    ll a,b;
    cin >> a >> b;
    pair<ll, ll> ans[12];
    ans[0].first = a;
    ans[0].second = b;
    for(int i = 1; i < 12; i++){
        if(i % 2 == 1) a = a - b;
        else b = a + b;
        ans[i].first = a;
        ans[i].second = b;
    }
    cout << ans[n % 12].first << " " << ans[n % 12].second << endl;
    return 0;
}


Measured memory_bytes: 3120
using System;

class GuessMinNumber{
  static void Main(){
      
      var input = Console.ReadLine().Split(' ');
      var k = int.Parse(input[0]);
      int[] guess = new int[k];
      int sum = 0;
      int ans = -1;
      
      for(var i = 0; i < k ;i++){
          guess[i] = -1;
      }
      
      for(var i = 0; i < int.Parse(input[1]);i++){
          var number = Console.ReadLine().Split(' ');
          if(guess[int.Parse(number[0]) -1] == -1 || guess[int.Parse(number[0]) -1] == int.Parse(number[1])){
            guess[int.Parse(number[0]) -1] = int.Parse(number[1]) ;
          }else if(guess[int.Parse(number[0]) -1] != -1){
             // ans = -1;
              Console.WriteLine(ans);
              return;
          }else{
              Console.WriteLine(ans);
              return;
          }
      }
      
      for(var i = 0;i< guess.Length;i++){
          if(guess[i] == -1){
              if(i == 0 && guess.Length != 1){
                  guess[i] = 1;
              }else{
                  guess[i] = 0;
              }
          }
      }
      
         if(guess[0] != 0){
             for(var i = guess.Length; i > 0 ;i--){
                 sum  += guess[ guess.Length - i] * (int)Math.Pow(10,i-1); 
             }
             ans = sum;
         }else if(guess[0] == 0 && guess.Length == 1){
             ans = 0;
         }
      
      
      Console.WriteLine(ans);
  }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> t(N, 0);
  for (int i = 0; i < N; i++) cin >> t[i];
  int cur = 0;
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    cur = t[cur] - 1;
    cnt++;
    if (cur == 1) {
      cout << cnt << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}

Measured memory_bytes: 640
#[allow(unused)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused)]
macro_rules! out {
    ($x:expr) => {
        println!("{:?}", $x)
    };
}

fn main(){
    // have fun!
    input! {
        a1: usize,
        a2: usize,
        a3: usize
    }
    if (a1 + a2 + a3) >= 22{
        println!("bust");
    }else{
        println!("win");
    }
}



Measured memory_bytes: 4352
#![allow(unused_imports)]

use text_io::*;
use proconio::*;
use std::collections::*;
use std::process::exit;
use std::cmp::*;
use itertools::Itertools;

fn main() {
    input! {
    a:isize,
    b:isize,
    }
    println!("{}",if (a+11)%13>(b+11)%13{"Alice"}else if a==b{"Draw"}else{"Bob"})
}

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

using namespace std;

std::string solve(const std::vector<std::string>& ss) {
  std::array<int, 26> intersectCounts{};
  for (auto& count : intersectCounts) {
    count = INT_MAX;
  }

  for (const auto& s : ss) {
    std::array<int, 26> counts{};
    for (auto const c : s) {
      counts[c - 'a']++;
    }
    for (int i = 0; i < intersectCounts.size(); i++) {
      intersectCounts[i] = std::min(counts[i], intersectCounts[i]);
    }
  }
  std::string ret;
  for (int i = 0; i < intersectCounts.size(); i++) {
    auto count = intersectCounts[i];
    while (count--) {
      ret += ('a' + i);
    }
  }
  return ret;
}

int main() {
  int n;
  std::cin >> n;
  std::vector<std::string> ss(n);
  for (auto& s : ss) {
    std::cin >> s;
  }
  std::cout << solve(ss) << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define endl "\n"
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);

using namespace std;

const int N = 1e5+7;
int n,k;
vector<int> g[N];
int d[N],flag;
const int mod = 1e9+7;
int visited[N], fact[N];

int inv(int num, int exp)
{
	int calc = num, ans = 1;
	while(exp)
	{
		if(exp&1)
			ans = (ans*calc)%mod;
		calc = (calc*calc)%mod;
		exp>>=1;
	}
	return (ans%mod);
}

int perm(int x, int y)
{
	return (fact[x]*inv(fact[x-y],mod-2))%mod;
}

int32_t main()
{
	fast;

	fact[0] = 1;
	for(int i=1;i<=N;i++)
		fact[i] = (fact[i-1]*i)%mod;

	cin>>n>>k;
	for(int i=1;i<=n-1;i++)
	{
		int a,b;
		cin>>a>>b;
		g[a].push_back(b);
		g[b].push_back(a);
		d[a]++; d[b]++;
		if(d[a]>=k||d[b]>=k)
			flag++;
	}
	if(flag)
		return cout<<0, 0;

	int ans = k;
	ans = (ans*perm(k-1,d[1]))%mod;

	for(int i=2;i<=n;i++)
		if(d[i]>=2)
			ans = (ans*perm(k-2,d[i]-1))%mod;

	cout<<ans;
	return 0;
}

Measured memory_bytes: 8052