akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;

public class Main {
  private static long solve(int n, long[] as) {
    long sum = 0;
    for (long a : as) {
      sum += a;
    }
    
    long subSum = 0;
    long answer = Long.MAX_VALUE;
    for (long a : as) {
      subSum += a;
      answer = Math.min(answer, Math.abs(sum - 2 * subSum));
    }
    return answer;
  }
  
  private static void execute(ContestReader reader, PrintWriter out) {
    int n = reader.nextInt();
    long[] as = reader.nextLong(n);
    out.println(solve(n, as));
  }
  
  public static void main(String[] args) {
    ContestReader reader = new ContestReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    execute(reader, out);
    out.flush();
  }
}

class ContestReader {
  private BufferedReader reader;
  private StringTokenizer tokenizer;
  
  ContestReader(InputStream in) {
    reader = new BufferedReader(new InputStreamReader(in));
  }
  
  public String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }
  
  public int nextInt() {
    return Integer.parseInt(next());
  }
  
  public long nextLong() {
    return Long.parseLong(next());
  }
  
  public double nextDouble() {
    return Double.parseDouble(next());
  }
  
  public String[] next(int n) {
    String[] array = new String[n];
    for (int i = 0; i < n; i++) {
      array[i] = next();
    }
    return array;
  }
  
  public int[] nextInt(int n) {
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextInt();
    }
    return array;
  }
  
  public long[] nextLong(int n) {
    long[] array = new long[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextLong();
    }
    return array;
  }
  
  public double[] nextDouble(int n) {
    double[] array = new double[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextDouble();
    }
    return array;
  }
  
  public char[] nextCharArray() {
    return next().toCharArray();
  }
  
  public int[][] nextInt(int n, int m) {
    int[][] matrix = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextInt();
      }
    }
    return matrix;
  }
  
  public long[][] nextLong(int n, int m) {
    long[][] matrix = new long[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextLong();
      }
    }
    return matrix;
  }
  
  public double[][] nextDouble(int n, int m) {
    double[][] matrix = new double[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextDouble();
      }
    }
    return matrix;
  }
  
  public char[][] nextCharArray(int n) {
    char[][] matrix = new char[n][];
    for (int i = 0; i < n; i++) {
      matrix[i] = next().toCharArray();
    }
    return matrix;
  }
}


Measured memory_bytes: 53076
from collections import deque

def permutation(n, k):
    s = 1
    for _ in range(k):
        s *= n
        s %= mod
        n -= 1
    return s

def bfs():
    global ans
    q = deque()
    q.append([1, 0])
    visit[1] = 1
    while q:
        x, y = q.popleft()
        a = 0
        for i in T[x]:
            if visit[i] == 0:
                q.append([i, 1])
                visit[i] = 1
                a += 1
        b = k - y - 1
        if b - a < 0:
            print(0)
            exit()
        ans *= permutation(b, a)
        ans %= mod
    return 

n, k = map(int, input().split())
T = [[] for _ in range(n + 1)]
visit = [0] * (n + 1)
mod = pow(10, 9) + 7
for _ in range(n - 1):
    a, b = map(int, input().split())
    T[a].append(b)
    T[b].append(a)
ans = k
bfs()
print(ans)

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

public class Main {
	int n, target;
	int ans = -1;
	boolean rejected = true;
	int nums[];
	int temp[] = new int[6];

	public void shred(int x, int num, int index) {
		for (int i = 10; i <= (num * 10); i *= 10) {
			int mod = num % i;
			temp[index] = mod;
			if (x + mod > n)
				break;
			if (num / i == 0) {
				if (x + mod > ans) {
					rejected = false;
					ans = x + mod;
					nums = Arrays.copyOf(temp, temp.length);
				} else if (x + mod == ans) {
					rejected = true;
				}
			} else {
				shred(x + mod, num / i, index + 1);
			}
			temp[index] = -1;
		}
	}

	public void run() {
		Scanner in = new Scanner(System.in);
		while (true) {
			ans = -1;
			Arrays.fill(temp, -1);
			n = in.nextInt();
			target = in.nextInt();
			if ((n | target) == 0)
				break;
			shred(0, target, 0);
			if (ans == -1)
				System.out.println("error");
			else if (rejected)
				System.out.println("rejected");
			else {
				System.out.print(ans);
				for (int i = nums.length - 1; i >= 0; i--) {
					if (nums[i] == -1)
						continue;
					System.out.print(" " + nums[i]);
				}
				System.out.println();
			}
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

}

Measured memory_bytes: 20328
fun main() {

    val n = readLine()

    val list=n!!.toString().split("").filter { it != "" }

    var sn=0

    for(i in list.indices){
        sn += list[i].toInt()
    }

    if ((n.toInt() % sn)==0) println("Yes")
    else println("No")

}

Measured memory_bytes: 39472
#include <iostream>
#include <vector>
#include <cmath>
#include <typeinfo>
#include <set>
#include <bitset>
#include <map>
#include <numeric>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(){
    int a, b;
    cin >> a >> b;
    cout << max(a-2*b, 0) << endl;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef tuple<int, int> duo;
const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
const int Mod = 1000000000 + 0;
//{{{ templates
#define TT_ template<typename T>inline
#define TTF_ template<typename T,typename F>inline
TT_ T sq(T x){return x*x;}
TT_ T In(){T x;cin>>x;return x;}
TT_ void Out(T&x){cout<<x;}
TT_ void sort(T&v){sort(begin(v),end(v));}
TT_ void revs(T&v){reverse(begin(v),end(v));}
TT_ void uniq(T&v){sort(v);v.erase(unique(begin(v),end(v)),end(v));}
TT_ int ubnd(T&v,typename T::value_type x){return upper_bound(begin(v),end(v),x)-begin(v);}
TT_ int lbnd(T&v,typename T::value_type x){return lower_bound(begin(v),end(v),x)-begin(v);}
TTF_ void inpt(T&v,int n,F f){for(v.reserve(n);n--;v.emplace_back(f()));}
TTF_ void show(T&v,F f,string d=" ",string e="\n"){int i=0;for(auto&x:v)i++&&(cout<<d),f(x);cout<<e;}
TT_ typename T::iterator minel(T&v){return min_element(begin(v),end(v));}
TT_ typename T::iterator maxel(T&v){return max_element(begin(v),end(v));}

inline void fast_io(){ios_base::sync_with_stdio(0);cin.tie(0);}
inline int in(){int x;scanf("%d",&x);return x;}
inline ll pow_mod(ll a,ll k,ll m){ll r=1;for(;k>0;a=a*a%m,k>>=1)if(k&1)r=r*a%m;return r;}
inline ll mod_inv(ll a,ll p){return pow_mod(a,p-2,p);}
//}}} priority_queue queue deque front stringstream max_element min_element insert count make_tuple

int main()
{
  while (int N = in()){
    int S[64][32] = {};
    for (int i = 0; i < N; i++){
      for (int d = in(); d--; ){
        S[i][in()] = 1;
      }
    }
    bool ok = false;
    ll tr[64] = {};
    for (int i = 0; i < N; i++) tr[i] = 1ll << i;
    for (int d = 1; d <= 30; d++){
      for (int i = 0; i < N; i++){
        if (!S[i][d]) continue;
        for (int j = 0; j < N; j++){
          if (S[j][d]){
            tr[i] |= tr[j];
            tr[j] |= tr[i];
          }
        }
      }
      for (int i = 0; i < N; i++){
        if (tr[i] == (1ll << N) - 1){
          ok = true;
          printf("%d\n", d);
          goto END;
        }
      }
    }
    printf("-1\n");
END:;
  }

  return 0;
}

Measured memory_bytes: 1180
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
  
N = int(input())

P = factorization(N)

flag = 0

for i in range(len(P)):
  for j in range(40):
    P[i][1] = P[i][1] - (j + 1)
    if P[i][1] >= 0:
      flag += 1
    else:
      break
if N == 1:
  print(0)
else:
  print(flag) 

Measured memory_bytes: 9504
n,k,i=int(input()),1,2
v=n+1
p=print
while k*2<v:k*=2
if-n&k:p("No");exit()
p("Yes",v,3)
while i<n:p(1,i,i,i+1,1,v+i,v+i,n+i);i+=2
if~n&1:p(n,v+k,n+n,n^k)

Measured memory_bytes: 9264
#include<iostream>
#include<string>
using namespace std;
int main() {
	string str;
	cin >> str;
	int pa, pz;
	int i=0;
	while (str[i] != 'A')++i;
	pa = i;
	i = str.size() - 1;
	while (str[i] != 'Z')--i;
	pz = i;
	cout << pz - pa + 1 << endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <list>
#include <cctype>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)

struct dice{
    ll p[7];
};

int main(){
    dice d;
    rep(i,6) cin >> d.p[i+1];
    ll q;
    cin >> q;
    rep(i,q){
        ll u,f;
        cin >> u >> f;
        rep(j,6) if(u == d.p[j+1]) u=j+1;
        rep(j,6) if(f == d.p[j+1]) f=j+1;
        if(u==1 && f==2) cout << d.p[3] << endl;
        if(u==1 && f==3) cout << d.p[5] << endl;
        if(u==1 && f==5) cout << d.p[4] << endl;
        if(u==1 && f==4) cout << d.p[2] << endl;
        if(u==2 && f==1) cout << d.p[4] << endl;
        if(u==2 && f==4) cout << d.p[6] << endl;
        if(u==2 && f==6) cout << d.p[3] << endl;
        if(u==2 && f==3) cout << d.p[1] << endl;
        if(u==3 && f==5) cout << d.p[1] << endl;
        if(u==3 && f==1) cout << d.p[2] << endl;
        if(u==3 && f==2) cout << d.p[6] << endl;
        if(u==3 && f==6) cout << d.p[5] << endl;
        if(u==4 && f==2) cout << d.p[1] << endl;
        if(u==4 && f==1) cout << d.p[5] << endl;
        if(u==4 && f==5) cout << d.p[6] << endl;
        if(u==4 && f==6) cout << d.p[2] << endl;
        if(u==5 && f==1) cout << d.p[3] << endl;
        if(u==5 && f==3) cout << d.p[6] << endl;
        if(u==5 && f==6) cout << d.p[4] << endl;
        if(u==5 && f==4) cout << d.p[1] << endl;
        if(u==6 && f==3) cout << d.p[2] << endl;
        if(u==6 && f==2) cout << d.p[4] << endl;
        if(u==6 && f==4) cout << d.p[5] << endl;
        if(u==6 && f==5) cout << d.p[3] << endl;
    }
}


Measured memory_bytes: 3120
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

// Sort
type Val struct {
	id, num int
}
type ByNum []Val

func (a ByNum) Len() int           { return len(a) }
func (a ByNum) Less(i, j int) bool { return a[i].num < a[j].num }
func (a ByNum) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N, X := sc.nextInt(), sc.nextInt()
	M := sc.nextIntSlice(N)
	sort.Ints(M)
	ans := 0
	for _, n := range M {
		X -= n
		ans++
	}
	for {
		if M[0] <= X {
			X -= M[0]
			ans++
		} else {
			break
		}
	}

	fmt.Fprintln(wtr, ans)
	wtr.Flush()
}


Measured memory_bytes: 640
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using System.Text.RegularExpressions;
using System.Text;
using System;

class Program
{
    static void Main(string[] args)
    {
        string s = Console.ReadLine();
        int ans = 0;
        for(int i = 0; i < s.Length; i++)
        {
            if(s[i] == '-')
            {
                ans--;
            }
            else
            {
                ans++;
            }
        }
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 11220
#include <bits/stdc++.h>
using namespace std;
#define rapido ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define mod 1000000007

int32_t main()
{
   rapido;
  int n;cin>>n;
  string ans="";
  while(n>0)
  {
      int d=n%26;
      if(d==0)
      d=26;
      ans+=(char)(d+'a'-1);
      n=n-d;
      n=n/26;
  }
  reverse(ans.begin(),ans.end());
  cout<<ans<<endl;
}


Measured memory_bytes: 3608
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#define LL long long
#define inl inline
#define re register
#define MAXN 101000
using namespace std;
int n;
int a[MAXN];
int t,p,l,r,ans;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	t=a[n]/2;//大于等于t  小于等于t 
	l=lower_bound(a+1,a+n,t)-a,r=l-1;
	if(a[n]&1)
	{
		if(min(abs(t-a[l]),abs(t+1-a[l]))<min(abs(t-a[r]),abs(t+1-a[r])))ans=a[l];
		else ans=a[r];
	}
	else
	{
		if(abs(t-a[l])<abs(t-a[r]))ans=a[l];
		else ans=a[r];
	}
	printf("%d %d",a[n],ans);
	return 0;
}



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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// ====================================================================

int main() {
  int s,w;
  cin >> s >> w;
  if(s > w){
    cout << "safe" << endl;
  }else{
    cout << "unsafe" << endl;
  }
}


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

int main() {
  int a, b;
  cin >> a >> b;
  
  if (a * b == (((a * b) /2) * 2)) {
    cout << "Even" << endl;
  }
  
   else { 
     cout << "Odd" << endl;
      }
      

}

Measured memory_bytes: 256
#include<cstdio>
#define MAX 10000
#define NIL -1

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

Node T[MAX];
int n, D[MAX], H[MAX];

void setDepth(int u, int d) {
  if ( u == NIL ) return;
  D[u] = d;
  setDepth(T[u].left, d + 1);
  setDepth(T[u].right, d + 1);
}

int setHeight(int u) {
  int h1 = 0, h2 = 0;
  if ( T[u].left != NIL )
    h1 = setHeight(T[u].left) + 1;
  if ( T[u].right != NIL )
    h2 = setHeight(T[u].right) + 1;
  return H[u] = ( h1 > h2 ? h1 : h2);
}

int getSibling(int u) {
  if ( T[u].parent == NIL ) return NIL;
  if ( T[T[u].parent].left != u && T[T[u].parent].left != NIL )
    return T[T[u].parent].left;
  if ( T[T[u].parent].right != u && T[T[u].parent].right != NIL )
    return T[T[u].parent].right;
  return NIL;
}

void print(int u) {
  printf("node %d: ", u);
  printf("parent = %d, ", T[u].parent);
  printf("sibling = %d, ", getSibling(u));
  int deg = 0;
  if ( T[u].left != NIL ) deg++;
  if ( T[u].right != NIL ) deg++;
  printf("degree = %d, ", deg);
  printf("depth = %d, ", D[u]);
  printf("height = %d, ", H[u]);

  if ( T[u].parent == NIL )
    printf("root\n");
  else if ( T[u].left == NIL && T[u].right == NIL )
    printf("leaf\n");
  else
    printf("internal node\n");
}

int main() {
  int v, l, r, root = 0;
  scanf("%d", &n);

  for ( int i = 0; i < n; i++ ) T[i].parent = NIL;

  for ( int i = 0; i < n; i++ ) {
    scanf("%d %d %d", &v, &l, &r);
    T[v].left = l;
    T[v].right = r;
    if ( l != NIL ) T[l].parent = v;
    if ( r != NIL ) T[r].parent = v;
  }

  for ( int i = 0; i < n; i++ ) if ( T[i].parent == NIL ) root = i;

  setDepth(root, 0);
  setHeight(root);

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

  return 0;
}


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

using namespace std;
#define ll long long
const int N=2e5+5;
int a[N];
bool ball[N];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    vector<int>ans;
    int cnt=0;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int i=n;i>=1;i--)
    {
        int sum=0;
        for(int j=i+i;j<=n;j+=i)
                sum+=ball[j];
        sum%=2;
        if(sum!=a[i])
            ball[i]=1,cnt++;
    }
    cout<<cnt<<endl;
    for(int i=1;i<=n;i++)
        if(ball[i])
            cout<<i<<" ";
    cout<<endl;
    return 0;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
using ll=long long;
using P=pair<ll,ll>;
using PP=tuple<ll,ll,ll>;
using S=multiset<ll>;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
void decimal(int x){cout<<fixed<<setprecision(x);}
//ll GCD(ll a,ll b){if(b==0) return a; return GCD(b,a%b);}
//ll LCM(ll a,ll b){return(a/GCD(a,b))*(b/GCD(a,b))*GCD(a,b);}
ll POW(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*POW(a,b-1)%mod;ll k=POW(a,b/2);return k*k%mod;}
vi calc(ll x){vi res;while(x>0){res.eb(x%10);x/=10;}reverse(all(res));return res;}

void solve() {
  ll x; cin>>x;
  REP(i,-1000,1000){
    REP(j,-1000,1000){
      if(pow(i,5)-pow(j,5)==x){
        cout<<i<<" "<<j<<endl;
        return;
      }
    }
  }
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
}


Measured memory_bytes: 4084
import Control.Monad
import Control.Applicative
import Data.List
import Data.Char
import Data.Maybe

main = interact $ unlines . map (show_rp . listToMaybe . expressions . filter isDigit) . init . lines

expressions ns = filter (\rp -> eval_rp rp == 10) $ concat $ (map exps op_combs) <*> num_combs
 where
  exps [op1,op2,op3] [n1,n2,n3,n4] =
   [[n1,n2,n3,n4,op1,op2,op3],
    [n1,n2,n3,op1,op2,n4,op3],
    [n1,n2,n3,op1,n4,op2,op3],
    [n1,n2,op1,n3,n4,op2,op3],
    [n1,n2,op1,n3,op2,n4,op3]]  
  op_combs = replicateM 3 "+-*"
  num_combs = permutations ns

eval_rp = eval_rp' []
 where
  eval_rp' acc [] = head acc
  eval_rp' acc (x:xs)
   | elem x ['1'..'9'] = eval_rp' (read [x] : acc) xs
   | x == '+' = eval_rp' (head (tail acc) + (head acc) : (tail (tail acc))) xs
   | x == '-' = eval_rp' (head (tail acc) - (head acc) : (tail (tail acc))) xs
   | x == '*' = eval_rp' (head (tail acc) * (head acc) : (tail (tail acc))) xs

show_rp = show_rp' []
 where
  show_rp' _ Nothing = "0"
  show_rp' acc (Just []) = head acc
  show_rp' acc (Just (c:cs))
   | elem c ['1'..'9'] = show_rp' ([c] : acc) (Just cs)
   | otherwise = show_rp' (("(" ++ head (tail acc) ++ [c] ++ head acc ++ ")") : (tail (tail acc))) (Just cs)
 

Measured memory_bytes: 4548
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int n,m;
  cin >> n >> m;
  vector<int> x(m);
  rep(i,n){
    int k;
    cin >> k;
    rep(kk,k){
      int a;
      cin >> a;
      x[a-1]++;
    }
  }
  int ans = 0;
  rep(i,m) if(x[i]==n) ++ans;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
using ll = long long;
template<typename T> using v2 = vector<vector<T>>;
template<typename T> inline v2<T> fill(int r, int c, const T& t){ return v2<T>(r, vector<T>(c, t)); }
#define F first
#define S second

void solve(){
    string s;
    cin >> s;
    int sum = 0;
    for(char c : s){
        sum += c-'0';
    }

    cout << (sum%9==0 ? "Yes\n" : "No\n");
}

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

Measured memory_bytes: 3696
#include<bits/stdc++.h>
using namespace std;
 
#define ff              first
#define ss              second
#define ll              long long
#define dd				double
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define vll				vector<long long>
#define vpii			vector<pair<int,int>>
#define vpll			vector<pair<long long,long long>>
#define vvi				vector<vector<int>>
#define vvl				vector<vector<long long>>
#define mii             map<int,int>
#define mll  			map<long long,long long>
#define umii			unordered_map<int,int>
#define umll			unordered_map<long long,long long>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define rep(i,n)		for(int i=0;i<n;i++)
#define rep2(i,a,b)		for(int i=a;i<b;i++)
#define rev(i,n)		for(int i=n;i>=0;i--)
#define rev2(i,a,b)		for(int i=a;i>=b;i--)
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define inf             9e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define fio				ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl			'\n'
#define all(x)			x.begin(),x.end()
#define d0(x)			cout <<x<<" "
#define d1(x)			cout <<x<<endl
#define d2(x,y)			cout <<x<<" "<<y<<endl
#define d3(x,y,z)		cout <<x<<" "<<y<<" "<<z<<endl
#define d4(x,y,z,w)		cout <<x<<" "<<y<<" "<<z<<" "<<w<<endl
const ll mod=1e9+7;
const dd pi=M_PI;
const ll MOD=998244353;
void i_o()
{
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	#endif
} 
ll helper(string& s){
	ll n=s.length();
	if(n<=3) return 0;
	ll mo=2019;
	umll m;
	ll ans=0;
	reverse(all(s));
	ll pow[n+2];
	pow[0]=1;
	rep2(i,1,n+2) pow[i]=(pow[i-1]*10)%mo;
	ll curr=s[0]-'0';
	m[0]=1,m[curr]++;
	rep2(i,1,n){
		curr=(curr+(s[i]-'0')*pow[i])%mo;
		ans+=m[curr];
		m[curr]++;
	}
	return ans;
}
int main()
{
	fio
   	i_o();
   	string s;
   	cin>>s;
   	cout <<helper(s);
   	

    
	return 0;
}



Measured memory_bytes: 5352
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define in(x,y,h,w) if(0<=x&&x<h&&0<=y&&y<w)
#define y0 y12345
#define y1 y54321

#ifdef LOCAL
#define debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;using vvint = vector<vector<int>>;
using vll = vector<ll>;using vvll = vector<vector<ll>>;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b;return 1;}return 0;}
template <class T>void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	debug("debug test\n");
   	int n,m;cin>>n>>m;
	cout << 6-n-m << endl;
	return 0;
}


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

int main(void){
  int n,N;
  vector<int> v(10);
  cin >> N;
  REP(n,N){
    int i;
    bool flg = true;
    REP(i,v.size()) cin >> v[i];
    int max = 0,min = 0;
    REP(i,v.size()){
      if(max<v[i]) max = v[i];
      else if(min<v[i]) min = v[i];
      else{
        flg = false;
        break;
      }
    }
    if(flg) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  return 0;
}



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

#define inf 0x3f3f3f3f

using namespace std;

typedef long long ll;

const ll mod = 998244353;

int i, j;
string s;
int n;
vector<int> p;
void solve() {
  cin >> n;
  p.resize(n + 1);
  for (i = 1; i <= n; ++i) cin >> p[i];
  vector<int> order(p);
  sort(order.begin() + 1, order.end());
  int diff = 0;
  for (i = 1; i <= n; ++i) {
    if (p[i] != order[i]) {
      diff += 1;
      if (diff > 2) {
        puts("NO");
        return;
      }
    }
  }
  puts("YES");
  return;
}

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

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

int main() {
  string s;
  cin >> s;
  bool a=s[0]=='R';
  bool b=s.at(1)=='R';
  bool c=s.at(2)=='R';
 
  if(a and b and c)
  cout <<3<< endl;
  else if((a and b) or (b and c))
    cout<<2<<endl;
  else if(a or b or c)
    cout<<1<<endl; 
  else
    cout<<0<<endl;
  
}


Measured memory_bytes: 3584
/*
ID: learnin7
TASK: test
LANG: C++                 
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include<bits/stdc++.h>

/*  Macros from Endagorion */
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;


int main(){
        
    ios_base::sync_with_stdio(0);
    
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    //fin >> a >> b;
    //fout << a+b << endl;
    i64 a,b,x;
    cin>>a>>b>>x;
    i64 start = ceil(a/(long double)x);
    i64 end = floor(b/(long double)x);
    //cout<<start<<" "<<end<<endl;
    if(start>end)   cout<<0<<endl;
    else            cout<<end-start+1<<endl;
    return 0;
}



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

using namespace std;

typedef long long ll;

const int maxn = 2e5 + 100, inf = 2e9 + 100;

ll n, c, k;

ll a[maxn];

int main()
{
    #ifdef ONPC
    ifstream cin("a.in");
    ofstream cout("a.out");
    #endif // ONPC
    ios::sync_with_stdio(0);
    cin >> n >> c >> k;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    sort(a, a + n);
    ll last = a[0], ilast = 0;
    ll answer = 1;
    for (int i = 1; i < n; i++){
        if (last + k < a[i] || i - ilast + 1 > c){
            answer++, last = a[i], ilast = i;
        }
    }
    cout << answer;
}


Measured memory_bytes: 1024
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = list(input())

ans = 0
for i in range(n):
    if t[i] == 'r':
        ans += p
        if i+k < n and t[i+k] == 'r':
            t[i+k] = '0'
    elif t[i] == 's':
        ans += r
        if i+k < n and t[i+k] == 's':
            t[i+k] = '0'
    elif t[i] == 'p':
        ans += s
        if i+k < n and t[i+k] == 'p':
            t[i+k] = '0'
print(ans)

Measured memory_bytes: 4152
# For taking integer inputs.
import math


def inp():
    return(int(input()))


# For taking List inputs.
def inlist():
    return(list(map(int, input().split())))


# For taking string inputs. Actually it returns a List of Characters, instead of a string, which is easier to use in Python, because in Python, Strings are Immutable.
def instr():
    s = input()
    return(list(s[:len(s)]))


# For taking space seperated integer variable inputs.
def invr():
    return(map(int, input().split()))


def prime_factors(n):
    factors = set()

    for i in range(2, int(math.sqrt(n+1)+1)):
        while n % i == 0:
            factors.add(i)
            n = int(n/i)
    if n >= 2:
        factors.add(n)
    return factors


n = inp()

fac = prime_factors(n)
res = 0
for f in fac:
    i = 1
    while n % f**i == 0:
        res += 1
        #print(f**i, n)
        n = n // (f**i)

        i += 1
print(res)


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

# input N
n = int(input())
a = [0] * (n+1)

s = 1
for i in range(2, n+1):
    for j in range(2, i):
        if i % j == 0:
            break
    else:
        for k in range(2, n+1):
            while k >= i:
                if k % i == 0:
                    a[i] += 1
                    k /= i
                else:
                    break

for i in range(2, n+1):
    if a[i] != 0:
        a[i] += 1
        s *= a[i]

print(s % (pow(10, 9) + 7))


Measured memory_bytes: 3064
#include<stdio.h>

int main(void){
        int i,j,r,c,s[102][102]={};

        scanf("%d %d",&r,&c);

        for(i=1; i<=r; i++)
                for(j=1; j<=c; j++){
                        scanf(" %d",&s[i][j]);
                        s[i][c+1] += s[i][j];
                }
        for(j=1; j<=c+1; j++)
                for(i=1; i<=r; i++)
                        s[r+1][j] += s[i][j];

        for(i=1; i<=r+1; i++){
                for(j=1; j<=c+1; j++){
                        printf("%d",s[i][j]);
                        if(j!=c+1) putchar(' ');
                }
                putchar('\n');
        }
        return 0;
}

Measured memory_bytes: 652
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}


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

    int n;
    cin>>n;
    vi a(n);
    map<int,int> mp;
    rep(i,n){
        cin>>a[i];
        mp[a[i]]++;
    }

    int ans=0;
    for(P p:mp){
        ans+=p.S*(p.S-1)/2;
    }

    rep(i,n){
        int b=mp[a[i]];
        int x=b*(b-1)/2;
        int y=(b-1)*(b-2)/2;
        cout<<ans-x+y<<endl;
    }


}

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

int main() {
  int n;
  cin>>n;
  
  vector<int> t(n);
  for(int i=0;i<n;i++){
    cin>>t.at(i);
  }
  
  int m;
  cin>>m;
  
  for(int i=0;i<m;i++){
    int p,x;
    cin>>p>>x;
    p--;
    int temp=t.at(p);
    t.at(p)=x;
    int sum=accumulate(t.begin(),t.end(),0);
    cout<<sum<<endl;
    t.at(p)=temp;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int r, g, b, n;
    cin >> r >> g >> b >> n;
    int ans = 0;
    for (int i = 0; i <= 3000; i++) {
        if (i*r > n) continue;
        for (int j = 0; j <= 3000; j++) {
            if (i*r+j*g > n) continue;
            int rem = n - (i*r+j*g);
            if (rem % b == 0) ans++;
        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 3652
N=int(input())
A=list(map(int,input().split()))
print(*A)
for i in range(1, N):
    v=A[i]
    j=i-1
    while j>=0 and A[j]>v:
        A[j+1]=A[j]
        j-=1
    A[j+1]=v
    print(*A)


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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

//arrow
inline int AR(int x, int y)
{
    if(x==1 && y==0) return 0;
    return 1;
}

int formula(string s)
{
    if(s.size()==1) return s[0]-'0';
    if(s[0]=='-') return !formula(s.substr(1));

    //bracket
    string t=s.substr(1,s.size()-2);

    int idx=0;
    int br=0;
    while(idx<t.size())
    {
        if(t[idx]=='(') ++br;
        if(t[idx]==')') --br;

        if(br==0)
        {
            if(t[idx]=='*')
            {
                string x=t.substr(0,idx);
                string y=t.substr(idx+1);
                return formula(x)&formula(y);
            }
            else if(t[idx]=='+')
            {
                string x=t.substr(0,idx);
                string y=t.substr(idx+1);
                return formula(x)|formula(y);
            }
            else if(idx+1<t.size() && t[idx]=='-' && t[idx+1]=='>')
            {
                string x=t.substr(0,idx);
                string y=t.substr(idx+2);
                return AR(formula(x),formula(y));
            }
        }

        ++idx;
    }

    return 0;
}

int main()
{
    string eq;
    while(cin >>eq,(eq!="#"))
    {
        //variables
        set<char> vars;
        rep(i,eq.size())
        {
            if('a'<=eq[i] && eq[i]<='k')
            {
                if(vars.find(eq[i])==vars.end()) vars.insert(eq[i]);
            }
        }

        //cut equation to 2 formulae
        int e=0;
        while(e<eq.size() && eq[e]!='=') ++e;
        string x=eq.substr(0,e), y=eq.substr(e+1);

        //translate "T"(1) and "F"(0)
        rep(i,x.size())
        {
            if(x[i]=='T') x[i]='1';
            if(x[i]=='F') x[i]='0';
        }
        rep(i,y.size())
        {
            if(y[i]=='T') y[i]='1';
            if(y[i]=='F') y[i]='0';
        }

        int n=vars.size();
        bool ok=true;
        rep(mask,1<<n)
        {
            //image
            map<char,int> im;

            int ct=0;
            for(const auto &x : vars)
            {
                im[x]=(mask>>ct&1);
                ++ct;
            }

            //translation
            string nx=x,ny=y;
            rep(i,nx.size())
            {
                if('a'<=nx[i] && nx[i]<='k') nx[i]=im[nx[i]]+'0';
            }
            rep(i,ny.size())
            {
                if('a'<=ny[i] && ny[i]<='k') ny[i]=im[ny[i]]+'0';
            }

            if(formula(nx)!=formula(ny))
            {
                ok=false;
                break;
            }
        }

        string ans="NO";
        if(ok) ans="YES";
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3688
#include<iostream>
using namespace std;
int main()
{
	string s;
  	cin>>s;
  	int a=0,b=0;
  	for(int i=0;i<3;i++)
    {
      if(s[i]=='A')
      {
        a++;
      }
      else
      {
        b++;
      }
    }
  	if(a>0&&b>0)
    {
      cout<<"Yes";
    }
  	else
    {
      cout<<"No";
    }
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }

    static class Task {
        String S;
        int former, latter;

        boolean canBeMonth(int n) {
            return 1 <= n && n <= 12;
        }

        boolean canBeYear(int n) {
            return 0 <= n && n <= 99;
        }

        void solve(InputReader in, PrintWriter out) {
            // write your code here
            S = in.next();
            former = Integer.parseInt(S.substring(0, 2));
            latter = Integer.parseInt(S.substring(2, 4));

            if (canBeMonth(former) && canBeMonth(latter)) {
                out.println("AMBIGUOUS");
            } else if (!canBeMonth(former) && !canBeMonth(latter)) {
                out.println("NA");
            } else if (canBeMonth(former)) {
                out.println("MMYY");
            } else if (canBeMonth(latter)) {
                out.println("YYMM");
            } else {
                out.println("NA");
            }
        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] nextIntArray(int size) {
            int[] arr = new int[size];
            for (int i = 0; i < size; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }
    }
}


Measured memory_bytes: 21076
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

typedef pair<int,int> intpair;
typedef pair< intpair,intpair > intpairpair;
typedef pair< intpair,intpairpair > Line;

const int INF = 999999999;

vector< Line > line;

int n,m,h,k;

int solve(int t){
	int r = -1;
	int p = t;
	for(int i=0;i<line.size();i++){
		if(line[i].first.second == p){
			p += 1;
		}else if(line[i].first.second + 1 == p){
			p -= 1;
		}
	}
	return p;
}

int main(){
	int self;
	int a,b,c,d;
	while(1){
		scanf("%d %d %d %d",&n,&m,&h,&k);
		
		if(!n && !m && !h && !k){ break; }
		vector<int> low(n),vpt(n),vno(n);

		for(int i=0;i<n;i++){
			scanf("%d",&self);
			low[i] = self;
			vno[i] = i;
		}
		
		vpt = low;
		line.clear();
		for(int i=0;i<m;i++){
			scanf("%d %d",&a,&b);
			line.push_back( Line(intpair(b,a - 1),intpairpair(intpair(0,0),intpair(0,0) ) ) );
		}
		
		sort(line.begin(),line.end());
		for(int i=0;i<line.size();i++){
			a = line[i].first.second;
			b = a + 1;
			//printf("%d, %d-%d\n",line[i].first.first,a,b);
			line[i].second.first.first = vno[a];
			line[i].second.second.first = vno[b];
			self = vno[a];
			vno[a] = vno[b];
			vno[b] = self;
		}
		for(int i =line.size() - 1;i >= 0;i--){
			a = line[i].first.second;
			b = a + 1;
			line[i].second.first.second = vpt[a];
			line[i].second.second.second = vpt[b];
			self = vpt[a];
			vpt[a] = vpt[b];
			vpt[b] = self;
		}
		int min = 0;
		Line minline;
		for(int i=0;i<line.size();i++){
			if(line[i].second.first.first < k && line[i].second.second.first >= k){
				if(line[i].second.first.second < line[i].second.second.second){
					a = line[i].second.second.second - line[i].second.first.second;
					if(a > min){
						min = a;
						minline = line[i];
					}
				}
			}
			if(line[i].second.first.first >= k && line[i].second.second.first < k){
				if(line[i].second.first.second > line[i].second.second.second){
					a = line[i].second.first.second - line[i].second.second.second;
					if(a > min){
						min = a;
						minline = line[i];
					}
				}
			}
		}
		//printf("min:%d\n",min);
		if(min != 0){
			//printf("erace:(%d-%d),(%d %d),(%d %d)\n",minline.first.first,minline.first.second,
			//			minline.second.first.first,minline.second.first.second,
			//			minline.second.second.first,minline.second.second.second
			//			);
			line.erase( remove(line.begin(),line.end(),minline),line.end() );
		}
		sort(line.begin(),line.end());
		int ans = 0;
		for(int i=0;i<k;i++){
			a = solve(i);
			//printf("%d : %d,%d\n",i,a,low[a]);
			ans += low[a];
		}
		printf("%d\n",ans);
	}
}

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

vector<vector<int>> G;
vector<int> dp;
vector<bool> seen;
vector<int> order;

void rec(int v) {
    seen[v] = true;
    for (auto nv : G[v]) {
        if (seen[nv])
            continue;
        rec(nv);
    }
    order.push_back(v);
}

int main() {
    int N, M;
    cin >> N >> M;
    G.assign(N, vector<int>());
    seen.assign(N, false);
    dp.assign(N, 0);

    rep(i, M) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
    }

    rep(v, N) {
        if (seen[v])
            continue;
        rec(v);
    }
    reverse(all(order));
    for (auto v : order) {
        for (auto nv : G[v]) {
            dp[nv] = max(dp[nv], dp[v] + 1);
        }
    }
  
  int res = *max_element(all(dp));
  cout << res << endl;
}

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

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;

    int sum = 0;
    vector<int> a(100000);
    rep(i,n) {
        int num;
        cin >> num;
        if(num > 100000) ++sum;
        else {
            --num;
            ++a[num];
        }
    }

    for(int i = 0; i <= 100000; ++i) {
        if(a[i] < i+1) sum += a[i];
        else sum += (a[i] - (i+1));
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3692
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

#define REP(i, n) for(int i = 0; i < (int)(n); i++)


int main() {

    int M, D;
    cin >> M >> D;
    ll ans = 0;
    for(int m = 1; m <= M; m++)for(int d = 1; d <= D; d++){
        int a = d / 10;
        int b = d % 10;
        if (a >= 2 && b >= 2 && a * b == m) ans++;
    }
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
#include <iostream>

int N;
int A[201];

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

  std::cin >> N;
  for (int i = 0; i <N; ++i) std::cin >> A[i];

  int res = 0;

  while(true){
    bool exist_odd = false;
    for(int i = 0; i < N; ++i){
      if (A[i] % 2 != 0) exist_odd = true;
    }
    if (exist_odd) break;

    for (int i = 0; i < N; ++i){
      A[i] /= 2;
    }
    ++res;
  }
  std::cout << res << '\n';
}


Measured memory_bytes: 256
n = int(input())
a_list = sorted([int(i) for i in input().split()])

if a_list[0] == 0:
  print(0)
else:
  ans = 1
  for i in a_list:
    ans *= i
    if ans > 10**18:
      ans = -1
      break
  print(ans)

Measured memory_bytes: 21668
#include <iostream>

using namespace std;

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

    int size = stoi(K);
    int length = static_cast<int>(S.length());
    if(size < length)
    {
         S = S.substr(0, size);
         S += "...";
    }
    cout << S << endl;
    return 0;
}

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

struct E
{
	int w;
	int l;
	int r;
};

vector<E> D;

int getw(char * str)
{
	int w = 0;
	while (1)
	{
		w *= 5;
		switch(*str++)
		{
		case 'A': w += 1; break;
		case 'C': w += 2; break;
		case 'G': w += 3; break;
		case 'T': w += 4; break;
		default: return w/5;
		}
	}
}

int find(int w)
{
	int c = 0;
	while (1)
	{
		auto e = D[c];
		if (e.w == w) return -1;
		auto p = c;
		if (e.w < w) c = e.r;
		else c = e.l;
		if (!c) return p;
	}
}

 int main()
{
	E e = {0};
	D.push_back(e);
	D.push_back(e);
	int n;
	cin >> n;
	char inst[16];
	char str[16];
	while(n--)
	{
		cin >> inst >> str;
		int w = getw(str);
		int k = find(w);
		if (inst[0] == 'i')
		{
			if (k>=0)
			{
				E e = { w, 0, 0};
				auto & p = D[k];
				int kk = D.size();
				if (p.w < w) p.r = kk;
				else p.l = kk;
				D.push_back(e);
			}
		}
		else
		{
			cout << (k >= 0? "no" : "yes") << endl;
		}
	}
}

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

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
	    int n = scan.nextInt();
	    int m = scan.nextInt();
	    long lr[][]=new long[m][2];
	    for(int i=0;i<m;i++) {
	    	lr[i][0]=scan.nextLong();
	    	lr[i][1]=scan.nextLong();
	    }
	    scan.close();
	    long min=0;
	    long max=n;
	    for(int i=0;i<m;i++) {
	    	if( lr[i][0] > min ) min = lr[i][0];
	    	if( lr[i][1] < max ) max = lr[i][1];
	    }

	    System.out.println((min<=max)? max-min+1:"0");

	}

}


Measured memory_bytes: 92532
N,C,K = [int(hoge) for hoge in input().split()]
ans = 0
time = -float("inf")
bus = 0
Ts = sorted([int(input()) for i in range(N)])
for T in Ts:
    if (T > time + K) or bus==C:
        ans += 1
        time = T
        bus = 1
    else:
        bus += 1
print(ans)

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

int main(){
    int N;
    cin >> N;
    string S;
    cin >> S;
    string T = S.substr(0, N);
    string U = S.substr(N, N);
    reverse(U.begin(), U.end());
    //cout << T << endl << U << endl;
    
    unordered_map<string, ll> um1(0), um2(0);
    
    for (int i = 0; i < (1 << N); i++) {
        string a="", b="";
        for (int j = 0; j < N; j++) {
            if (((i >> j) & 1) == 0) a += T[j];
            else b += T[j];
        }
        um1[a + "_" + b]++;
    }
    
    ll ans = 0;
    
    for (int i = 0; i < (1 << N); i++) {
        string a="", b="";
        for (int j = 0; j < N; j++) {
            if (((i >> j) & 1) == 0) a += U[j];
            else b += U[j];
        }
        ans += um1[a + "_" + b];
    }
    cout << ans << endl;
    return 0;
}

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


int main() {
  int A, B;
  char op;

  cin >> A >> op >> B;

  if(op == '+'){
    cout << A + B << endl;
  }
  else if(op == '-'){
    cout << A - B << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256