akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
vector<int>g[310000];
pair<int,int>z[110000];
int in[110000];
int st[110000];
int n;
int solve(int a,int b){
	if(a<n){
		if(~st[a]){
			if(st[a]>=b)return 0;
			else return 99999999;
		}
		return 1;
	}
	int um=0;
	int sum=0;
	for(int i=0;i<3;i++){
		int t=solve(g[a][i],b);
		um=max(t,um);
		sum+=t;
	}
	return min(99999999,sum-um);
}
int amari[110000];
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	n=a;
	for(int i=0;i<b;i++){
		int p,q;
		scanf("%d%d",&p,&q);
		q--;
		in[i]=q;
		z[i]=make_pair(p,-i);
	}
	for(int i=b;i<a;i++){
		int p;scanf("%d",&p);
		z[i]=make_pair(p,-i);
	}
	std::sort(z,z+a);
	int as=0;
	for(int i=0;i<a;i++)st[i]=-1;
	for(int i=0;i<a;i++){
		if(-z[i].second<b){
			st[in[-z[i].second]]=i;
		}else{
			amari[as++]=i;
		}
	}
	int sz=a;
	queue<int>Q;
	for(int i=0;i<a;i++)Q.push(i);
	while(Q.size()>1){
		int t1=Q.front();Q.pop();
		int t2=Q.front();Q.pop();
		int t3=Q.front();Q.pop();
		g[sz].push_back(t1);
		g[sz].push_back(t2);
		g[sz].push_back(t3);
		Q.push(sz);
		sz++;
	}
	int left=0;
	int right=a;
	while(left+1<right){
		int M=(left+right)/2;
		int use=solve(sz-1,M);
		int can=as-(lower_bound(amari,amari+as,M)-amari);
		if(use<=can)left=M;
		else right=M;
	}
	printf("%d\n",z[left].first);
}

Measured memory_bytes: 11572
while True:
    h, w = [int(s) for s in input().split()]
    if (h + w) == 0:
        break
    
    k = '#.'
    for i in range(h):
        s = k * (w // 2)
        if w % 2 == 1:
            s += k[:1]
        print(s)
        k = k[::-1]
    print()

Measured memory_bytes: 7760
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		int N = sc.nextInt();
		StringBuilder sb = new StringBuilder();
		if(N==0){
			out.println(0);
			out.flush();
			return;
		}
		while(N!=0){
			if(Math.abs(N%2) ==1){
				sb.append(1);
				N -= 1;
			}
			else sb.append(0);
			N /= -2;
		}
		out.println(sb.reverse().toString());
		out.flush();
	}

}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}

Measured memory_bytes: 21076
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 18;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-9;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<n;i++)
#define Se second
#define Fi first

int in[15][15];
int main() {
	while (1) {
		int N, M, i, j, k, l, ii, jj;
		scanf("%d %d", &N, &M);
		if (!N) break;
		for (i = 1; i <= N; i++) for (j = 1; j <= M; j++) scanf("%d", &in[i][j]);

		int ans = 0;
		for (i = 1; i <= N; i++) {
			for (j = i + 2; j <= N; j++) {
				for (k = 1; k <= M; k++) {
					for (l = k + 2; l <= M; l++) {
						int mn = INF, mx = 0;
						for (ii = i; ii <= j; ii++) {
							for (jj = k; jj <= l; jj++) {
								if (ii == i || ii == j || jj == k || jj == l) mn = min(mn, in[ii][jj]);
								else mx = max(mx, in[ii][jj]);
							}
						}
						if (mn <= mx) continue;

						int s = 0;
						for (ii = i + 1; ii < j; ii++) for (jj = k + 1; jj < l; jj++) s += mn - in[ii][jj];
						ans = max(ans, s);
					}
				}
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 3196
N = int(input())
S = list(input())
#LCSRe i番目とj番目でそれぞれ終わるような共通文字列の長さ
#i < j であるi文字目とj文字目が等しいならLCSRe[i + 1][j + 1] = LCSRe[i][j] + 1
#res_lengthよりLCSReの更新した値が大なら、その時のindexをiへ、res_lengthも更新

def longestRepeatedSubstring(s): 
  n = len(s) 
  LCSRe = [[0 for _ in range(n + 1)] for _ in range(n + 1)] 
  res = "" 
  res_length = 0
  index = 0
  for i in range(1, n + 1): 
    for j in range(i + 1, n + 1): 
      if s[i - 1] == s[j - 1] and LCSRe[i - 1][j - 1] < j - i: 
        LCSRe[i][j] = LCSRe[i - 1][j - 1] + 1
        if LCSRe[i][j] > res_length: 
          res_length = LCSRe[i][j] 
          index = max(i, index) 
      else: 
        LCSRe[i][j] = 0
  #print(LCSRe)
  if res_length > 0: 
    for i in range(index - res_length + 1, index + 1): 
      res = res + s[i - 1] 
  return res_length
print(longestRepeatedSubstring(S))

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
#define ld long double
#define ll long long
#define mod 1000000007
#define IINF INT_MAX
#define INF 1LL << 30


int main() {
    int n; cin >> n;
    V<P<int, int> > a(n);
    for(int i = 0; i < n; i++){
        int x; cin >> x;
        a[i] = make_pair(x, i);
    }

    sort(ALL(a));
    for(int i = 0; i < n; i++){
        if(i != n -1) cout << a[i].second + 1 << ' ';
        else cout << a[i].second + 1 << endl;
    }

    return 0;
}


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

long long gcd(long long x, long long y){
    if(y==0) return x;
    return gcd(y,x%y);
}

int main(){
    int n;
    long long m;
    cin>>n>>m;
    vector<long long> a(n);
    for(int i=0;i<n;++i){
        cin>>a[i];
        a[i]/=2;
    }

    while(a[0]%2==0){
           for(int i=0;i<n;++i){
            if(a[i]%2!=0){
                cout<<0<<endl;
                return 0;
            }
            a[i]/=2;
        }
        m/=2;
    }

    for(int i=0;i<n;++i){
        if(a[i]%2==0){
            cout<<0<<endl;
            return 0;
        }
    }

    long long lcm=1;
    for(int i=0;i<n;++i){
        long long g=gcd(lcm,a[i]);
        lcm=lcm/g*a[i];
        if(lcm>m){
            cout<<0<<endl;
            return 0;
        }
    }

    cout<<(m/lcm+1)/2<<endl;
}

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

int main() {
	int n; cin >> n;
	string s; cin >> s;

	if (s.length() % 2 != 0) {
		cout << "No" << endl;
		return 0;
	}

	if (s.substr(0, s.length()/2) == (s.substr(s.length()/2))) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


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,Q;
		N=sc.nextInt();
		Q=sc.nextInt();
		sc.nextLine();
		String S = sc.nextLine();
		int[] dp = new int[100001];
		for(int i = 1; i<S.length();i++) {
			if(S.charAt(i)=='C' && S.charAt(i-1)=='A') {
				dp[i]=dp[i-1]+1;
			} else {
				dp[i]=dp[i-1];
			}
			//System.out.println(dp[i]);
		}
		for(int i = 0;i<Q;i++) {
			int l,r;
			l=sc.nextInt();
			r=sc.nextInt();
			System.out.println(dp[r-1]-dp[l-1]);
		}
	}
}


Measured memory_bytes: 64740
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P std::pair<int,int>
#define PiP std::pair<int,std::pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp std::make_pair
#define prique(T) std::priority_queue<T,vector<T>,greater<T>>
using namespace std;
template<class T> inline void chmax(T& a, T b) { a = std::max(a, b); }
template<class T> inline void chmin(T& a, T b) { a = std::min(a, b); }

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
int get_rand(int MIN, int MAX) {
	std::random_device rnd;
	std::mt19937 mt32(rnd());
	std::uniform_int_distribution<int>engine(MIN, MAX);
	return engine(mt32);
}
/*--------Library Zone!--------*/

int n, a[114514], b[114514], c[114514];
P p[114514], q[114514];
signed main() {
	cin >> n;
	rep(i, n) {
		cin >> a[i];
		p[i] = { a[i],i };
	}
	rep(i, n) {
		cin >> b[i];
		q[i] = { b[i],i };
	}
	sort(p, p + n);
	rep(i, n) {
		c[p[i].second] = i;
	}
	sort(q, q + n);
	rep(i, n) {
		if (q[i].first < p[i].first) {
			cout << "No" << endl; return 0;
		}
	}
	int now = q[0].second, cnt = 1;
	while (c[now]) {
		now = q[c[now]].second;
		cnt++;
	}
	if (cnt < n) {
		cout << "Yes" << endl; return 0;
	}
	rep(i, n - 1) {
		if (p[i + 1].first <= q[i].first) {
			cout << "Yes" << endl; return 0;
		}
	}
	cout << "No" << endl;
}


Measured memory_bytes: 6144
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <algorithm>

using namespace std;

int p = 1e9+7;

int N;
int dp[100008];

int main() {
    int K;
	scanf("%d%d", &N, &K);
    {
        int a;
        scanf("%d", &a);
        for(int k=0; k<=a; ++k) {
            dp[k] = 1;
        }
        for(int k=a+1; k<=K; ++k) {
            dp[k] = 0;
        }
    }
    for(int n=1; n<N; ++n) {
        int sum = 0;
        for(int k=0; k<=K; ++k) {
            sum += dp[k];
            if(p<=sum) sum -= p;
            dp[k] = sum;
        }
        int a;
        scanf("%d", &a);
        for(int k=K; a<k; --k) {
            int sum = p + dp[k] - dp[k-a-1];
            if(p<=sum) sum -= p;
            dp[k] = sum;
        }
    }
    printf("%d\n", dp[K]);
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <complex>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>
#include <iterator>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;

int main() {
    i64 n, m;
    cin >> n >> m;
    i64 s = 0;
    for (int i = 0; i < m; ++i) {
        i64 x;
        cin >> x;
        s += x;
    }
    n -= s;
    if (n < 0) n = -1;
    cout << n << endl;
    return 0;
}

Measured memory_bytes: 3676
use std::io;
use std::str::FromStr;

pub fn scan() -> String {
    let mut buf = String::new();
    let _ = io::stdin().read_line(&mut buf).unwrap();

    buf
}

fn main() {
    loop {
        let s = scan();
        let s: Vec<&str> = s.split(" ").collect();
        let n: i32 = i32::from_str(s[0].trim()).unwrap();
        let m: i32 = i32::from_str(s[1].trim()).unwrap();

        if n == 0 && m == 0 {
            break;
        }

        let s = scan();
        let s: Vec<&str> = s.split(" ").collect();

        let mut v: Vec<i32> = Vec::new();
        for i in 0..(s.len()) {
            v.push(i32::from_str(s[i].trim()).unwrap());
        }

        let mut sum = -1;
        for i in 0..(v.len()) {
            for j in 0..(v.len()) {
                if i == j {
                    continue;
                }
                if v[i] + v[j] <= m && v[i] + v[j] > sum {
                    sum = v[i] + v[j];
                }
            }
        }

        if sum < 0 {
            println!("NONE");
        } else {
            println!("{}", sum);
        }
    }
}



Measured memory_bytes: 5064
#include <cstdlib>
#include <functional>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <string>

#define ll long long int

using namespace std;

ll factorial(ll x) {
  if (x == 0) {
    return 1;
  }

  ll ret = 1;
  for (ll i = 1; i <= x; i++) {
    ret *= i;
  }
  return ret;
}

int main(int argc, char *argv[])
{
  ll N;
  cin >> N;

  ll a[N];

  for (ll i = 0; i < N; i++) {
    cin >> a[i];
  }

  ll sum = 0;

  for (ll i = 0; i < N; i++) {
    sum += a[i];
  }

  ll balance = round(sum / (float)N);

  ll min_cost = 0;
  for (ll i = 0; i < N; i++) {
    min_cost += pow(a[i] - balance, 2);
  }

  cout << min_cost;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main(void)
{
	using namespace std;

	int	a, b, k, i;

	cin >> a >> b >> k;
	i = a;
	while(i <= b){
		if(a+k > i || b-k < i){
			cout << i << endl;
		}
		i++;
	}

	return 0;
}


Measured memory_bytes: 256
import math
import sys

def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()

    
    array_result.append(data.split(" "))

    flg = 1

    try:


        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:


        return array_result





arr_data = getinputdata()

n = arr_data[0][0]
arr = arr_data[1]

#print(n,arr)

hash01={}

for v in arr:
    
    cnt =hash01.get(int(v),0)+1
    hash01[int(v)] = cnt
    
#print(hash01)

cnt=0

for k,v in hash01.items():
    
#    print(k,v)
    
    if(k>v):
        
        cnt+=v
        
    elif(k<v):
        
        cnt+=v-k
        
print(cnt)
        
        

Measured memory_bytes: 23372
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#define max(x,y)(x>y?x:y)
#define min(x,y)(x>y?y:x)
typedef long long int ll;
typedef unsigned long long int ull;
int asc_cmp(const void* X,const void* Y){int x=*(int*)X,y=*(int*)Y;if(x<y)return -1;else if(x==y)return 0;else return 1;}
int desc_cmp(const void* X,const void* Y){int x=*(int*)X,y=*(int*)Y;if(x<y)return 1;else if(x==y)return 0;else return -1;}
int main(){
    ll h;scanf("%lld",&h);
    if(h==1){
        printf("1\n");
        return 0;
    }
    ll x=1;
    ll ans=1;
    ll cnt=1;
    while(1){
        h/=2;
        cnt+=x*2;
        x*=2;
        if(h==1)break;
    }
    printf("%lld\n",cnt);

}

Measured memory_bytes: 128
import java.util.HashMap;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		HashMap<String, String> map = new HashMap<String, String>();

		String b = sc.next();

		map.put("A", "T");
		map.put("T", "A");
		map.put("G", "C");
		map.put("C", "G");

		System.out.println(map.get(b));
	}
}

Measured memory_bytes: 23636
#include<bits/stdc++.h>
using namespace std;
const int MAX=100;
const int INF=(1<<21);
const int WHI=0;
const int GRA=1;
const int BLA=2;

int n,M[MAX][MAX];

int prim(){
  int u,minv;
  int d[MAX],p[MAX],color[MAX];

  for(int i=0;i<n;i++){
    d[i]=INF;
    p[i]=-1;
    color[i]=WHI;
  }

  d[0]=0;
  while(1){
    minv=INF;
    u=-1;

    for(int i=0;i<n;i++){
      if(minv>d[i] && color[i]!=BLA){
	u=i;
	minv=d[i];
      }
    }

    if(u==-1){
      break;
    }

    color[u]=BLA;//ここで訪問に記録

    for(int v=0;v<n;v++){
      if(color[v]!=BLA && M[u][v]!=INF){//まだ行くところがある && u,vに辺が通っている
	if(M[u][v]<d[v]){
	  d[v]=M[u][v];
	  p[v]=u;
	  color[v]=GRA;
	}
      }
    }
  }
  int sum=0;
  for(int i=0;i<n;i++){
    if(p[i]!=-1){
      sum+=M[i][p[i]];
    }
  }
  return sum;
}

int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      int e;
      cin>>e;
      if(e==-1){
	M[i][j]=INF;
      }else{
	M[i][j]=e;
      }
    }
  }
  cout<<prim()<<endl;

  return 0;
}



Measured memory_bytes: 3088
#include<iostream>
#include<math.h>
using namespace std;

int main(){
    double v;
    while(cin>>v){
        double y = v*v/19.6;

        int i=1;
        for(;;){
            if(y<5*i-5) break;
            i++;
        }
        cout << i << endl;
    }


return 0;
}

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

typedef long long LL;

const int MAXN = 2e5 + 10, MAXL = 1e6 + 10;

int n;
int tmp[30];
std::string s[MAXN];

template <int N, int S>
struct Trie {
	int tot;
	int ed[N], ch[N][S];
	inline void insert(const std::string &s) {
		int u = 0;
		for (const auto &cur: s) {
			int v = cur - 'a';
			if (!ch[u][v]) ch[u][v] = ++tot;
			u = ch[u][v];
		}
		++ed[u];
	}
};
Trie <MAXL, 26> T;

int main() {
	std::ios::sync_with_stdio(0);
	std::cin.tie(0);
	std::cin >> n;
	for (int i = 1; i <= n; ++i) {
		std::cin >> s[i];
		std::reverse(s[i].begin(), s[i].end());
		T.insert(s[i]);
	}
	LL ans = 0;
	for (int i = 1; i <= n; ++i) {
		for (int j = 0; j < 26; ++j) tmp[j] = 0;
		for (const auto &cur: s[i]) ++tmp[cur - 'a'];
		int u = 0;
		for (const auto &cur: s[i]) {
			int v = cur - 'a';
			for (int j = 0; j < 26; ++j) tmp[j] && T.ch[u][j] && (ans += T.ed[T.ch[u][j]]);
			--tmp[v], u = T.ch[u][v];
		}
	}
	std::cout << ans - n << '\n';
	return 0;
}

Measured memory_bytes: 115468
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int N = 1e+5+3;
const int mo = 1e+9+7;

int a[N];
int n,m;
struct matrix{
	LL a[4][4];
	LL* operator[](int x){return a[x];}
}tr1,tr2,ans;
matrix operator *(matrix a,matrix b){
	matrix c;
	fo(i,0,3)c[i][0]=c[i][1]=c[i][2]=c[i][3]=0;
	fo(i,0,3)fo(j,0,3)c[i][j]=(a[i][0]*b[0][j]+a[i][1]*b[1][j]+a[i][2]*b[2][j]+a[i][3]*b[3][j])%mo;
	return c;
}

void quickmi(matrix &ans,matrix x,int tim){
	for(;tim;tim/=2,x=x*x)
	if(tim&1)ans=ans*x;
}

int main(){
	n=get();m=get();
	fo(i,1,m)a[i]=get();
	ans[0][0]=ans[0][1]=ans[0][2]=ans[0][3]=1;
	
	tr1[0][0]=tr1[0][1]=tr1[0][2]=tr1[0][3]=1;
	tr1[1][1]=tr1[1][3]=1;
	tr1[2][2]=tr1[2][3]=1;
	tr1[3][3]=2;
	tr1[3][0]=tr1[3][1]=tr1[3][2]=1;
	
	tr2[0][0]=tr2[0][1]=tr2[0][2]=tr2[0][3]=1;
	tr2[1][1]=tr2[1][3]=1;
	tr2[2][2]=tr2[2][3]=1;
	tr2[3][3]=1;
	
	int w=1;
	fo(i,1,m){
		quickmi(ans,tr1,a[i]-w);
		ans=ans*tr2;
		w=a[i]+1;
	}
	quickmi(ans,tr1,n-w);
	printf("%lld\n",ans[0][3]);
	return 0;
}

Measured memory_bytes: 640
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int N = scanner.nextInt();
    long[] T = new long[N];
    for (int i = 0; i < N; i++) {
      T[i] = scanner.nextLong();
    }

    long ans = 1;
    for (int i = 0; i < N; i++) {
      ans = lcm(ans, T[i]);
    }

    System.out.printf("%d", ans);
  }

  public static long gcd(long a, long b) {
    if (b == 0) {
      return a;
    }
    return gcd(b, a % b);
  }

  public static long lcm(long a, long b) {
    return a / gcd(a, b) * b;
  }
}

Measured memory_bytes: 22868
N = int(input())
a = []
for i in range(N):
  a.append(list(map(int, input().split())))

dp = [[0, 0, 0] for _ in range(N)]

if N==0:
  print(max(a[0]))
else:
  dp[0] = a[0]
  for i in range(1, N):
    dp[i][0] = a[i][0] + max(dp[i-1][1], dp[i-1][2])
    dp[i][1] = a[i][1] + max(dp[i-1][0], dp[i-1][2])
    dp[i][2] = a[i][2] + max(dp[i-1][1], dp[i-1][0])

print(max(dp[N-1]))

Measured memory_bytes: 47384
import java.util.*

fun main(args: Array<String>) {
    Program().solve()
}

class Program {
    fun solve() {
        val sc = MyScanner()
        val (n, k) = sc.intList()
        val a = sc.intList().filter { it < k }.sorted()

        fun c(i: Int, j: Int) = i * k + j

        // k以上 必要
        // iが必要 -> i以上も必要
        // i以外で良くない集合、iを足すと良い集合になる
        // できるなら必要
        val front = BitSet((a.size + 1) * k)
        front[c(0, 0)] = true
        for (i in a.indices) {
            for (j in 0 until k) {
                if (front[c(i, j)]) {
                    if (j + a[i] < k) {
                        front[c(i + 1, j + a[i])] = true
                    }
                    front[c(i + 1, j)] = true
                }
            }
        }

        val back = BitSet((a.size + 1) * k)
        back[c(a.size, 0)] = true
        for (i in a.size downTo 1) {
            for (j in 0 until k) {
                if (back[c(i, j)]) {
                    if (j + a[i - 1] < k) {
                        back[c(i - 1, j + a[i - 1])] = true
                    }
                    back[c(i - 1, j)] = true
                }
            }
        }

        var ok = a.size
        var ng = -1
        while (ok - ng > 1) {
            val mid = (ok + ng) / 2
            val f = mutableListOf<Int>()
            val b = mutableListOf<Int>()
            for (i in 0 until k) {
                if (front[c(mid, i)]) f.add(i)
                if (back[c(mid + 1, i)]) b.add(i)
            }
            var flag = false
            for (i in f.indices) {
                var ok2 = 0
                var ng2 = b.size
                while (ng2 - ok2 > 1) {
                    val mid2 = (ok2 + ng2) / 2
                    if (f[i] + b[mid2] < k) ok2 = mid2
                    else ng2 = mid2
                }
                if (f[i] + b[ok2] + a[mid] >= k) {
                    flag = true
                    break
                }
            }

            if (flag) ok = mid
            else ng = mid
        }

        println(ok)
    }
}

class MyScanner {
    private var ptr = 0
    private var l = listOf<String>()

    fun next(): String {
        while (l.size <= ptr) {
            l = readLine()!!.split(' ')
            ptr = 0
        }
        return l[ptr++]
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextDouble() = next().toDouble()
    fun nextCharArray() = next().toCharArray()
    fun nextChar() = next()[0]

    fun list(): List<String> {
        ptr = l.size
        return readLine()!!.split(' ')
    }

    fun intList() = list().map { s -> s.toInt() }
    fun longList() = list().map { s -> s.toLong() }
    fun doubleList() = list().map { s -> s.toDouble() }

    fun array() = list().toTypedArray()
    fun intArray() = intList().toIntArray()
    fun longArray() = longList().toLongArray()
    fun doubleArray() = doubleList().toDoubleArray()
}


Measured memory_bytes: 52328
#include <bits/stdc++.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF LLONG_MAX/5
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
int x[100000];
signed main(){
	int a,b,c,d,e,ans=0;
	string s;
	cin>>a>>b>>c>>d>>e>>s;
	f(i,a){
		if(i<b){
			if(s[i]=='r'){
				x[i]=2;
				ans+=e;
			}
			if(s[i]=='s'){
				x[i]=0;
				ans+=c;
			}
			if(s[i]=='p'){
				x[i]=1;
				ans+=d;
			}
		}
		else{
			if(s[i]!=s[i-b]||x[i-b]==3){
				if(s[i]=='r'){
				x[i]=2;
				ans+=e;
				}
				if(s[i]=='s'){
					x[i]=0;
					ans+=c;
				}
				if(s[i]=='p'){
					x[i]=1;
					ans+=d;
				}
			}
			else x[i]=3;
		}
	}
	cout<<ans<<endl;
}


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

int N,K,A[110],grundy[100010] = {};
int main(){
	cin >> N >> K;
	int ma = 0;
	for(int i=1;i<=N;i++){
		cin >> A[i];
	}
	set<int> s;
	for(int j=1;j<=K;j++){
		for(int i=1;i<=N;i++){
			if(A[i]<=j) s.insert(grundy[j-A[i]]);
		}
		int g = 0;
		while(s.count(g)!=0) g++;
		grundy[j] = g;
		s.clear();
	}
	cout << (grundy[K]!=0? "First":"Second") << endl;
}

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

int main()
{
   int a,b;
   scanf("%d%d",&a,&b);
   if (a==b){printf("Draw");}

   else if (a==13&&b==1){
    printf("Bob");
   }else if(a==1&&b==13){printf("Alice");}
   else if(a>b)  {printf("Alice");}
   else if (b>a){printf("Bob");}
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
using namespace std;
using Graph = vector<vector<int>>;

void dfs(int p, int c, long long sum, Graph & G, vector<int> & cnt) {
	cnt[c] += sum;
	for (auto & v : G[c]) {
		if (v != p) dfs(c, v, cnt[c], G, cnt);
	}
}

int main(void) {
	int N, Q; cin >> N >> Q;
	Graph G(N);
	rep(i, N-1) {
		int a, b; cin >> a >> b;
		a--, b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}

	vector<int> cnt(N);
	rep(i, Q) {
		int p, x; cin >> p >> x;
		p--;
		cnt[p] += x;
	}
	
	dfs(-1, 0, 0, G, cnt);
	
	rep(i, N) {
		if (i) printf(" ");
		printf("%d", cnt[i]);
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 29696
N, M = map(int, input().split())
A = [list(reversed(list(map(int, input().split())))) for _ in range(N)]

res = N
removed = [0 for _ in range(M)]

while not all(removed):
    S = [0 for _ in range(M)]
    for a in A:
        S[a[-1] - 1] += 1
    res = min(res, max(S))
    x = S.index(max(S))
    removed[x] = 1
    for a in A:
        while a and removed[a[-1] - 1]:
            a.pop()

print(res)

Measured memory_bytes: 4296
N, S = map(int, input().split())
A = list(map(int, input().split()))

MOD = 998244353

def solution(A, S):
    N = len(A)
    
    dp = [[0]*(S+1) for _ in range(N+1)]
    dp[0][0] = 1
    for i in range(1, N+1):
        for j in range(S+1):
            dp[i][j] += 2*dp[i-1][j]
            dp[i][j] %= MOD
            if j >= A[i-1]:
                dp[i][j] += dp[i-1][j-A[i-1]]
                dp[i][j] %= MOD
    return dp[N][S]

print(solution(A, S))

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

// int/long:		-2,147,483,648 - 2,147,483,648 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<29)
//536,870,912

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

#define	MOD 1000000007

int	main() {
	int A, B;
	cin >>A >>B;
	A +=B;
	if (A>=10)
		cout <<"error" <<endl;
	else
		cout <<A <<endl;
	return 0;
}



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

struct UnionFind{
    vector<int> par;
    vector<int> rank;  // height of tree
    UnionFind(int m) : par(m), rank(m) {
        for(int i = 0; i < m; i++){
            par[i] = i;
            rank[i] = 0;
        }
    }
    int root(int x) {
        return x == par[x] ? x : par[x] = root(par[x]);
    }
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    void unite(int x, int y) {
        if(same(x, y)) return;
        if(rank[x] < rank[y]) {
            par[root(x)] = root(y);  // make y above
        } else {
            par[root(y)] = root(x);
            if(rank[x] == rank[y]) ++rank[x];
        }
    }
};

int main() {
    int N, M; cin >> N >> M;
    auto uf = UnionFind(N);
    for (int i = 0; i < M; ++i) {
        int a, b; cin >> a >> b; --a; --b;
        uf.unite(a, b);
    }
    unordered_map<int, int> root_size;
    for (int n = 0; n < N; ++n) {
        root_size[uf.root(n)]++;
    }
    int ans = 0;
    for (const auto& [k, v]: root_size) {
        ans = max(ans, v);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 12912
/**
 *    created by : PawPaw       
**/

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

using namespace __gnu_pbds;  
using namespace std;

typedef tree<int, null_type, less<int>, rb_tree_tag,  
        tree_order_statistics_node_update>  
        ordered_set;  

#define F(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define RF(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define LL long long
#define PHI acos(-1)
#define EPS 0.000000001
#define N 100001
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define FbO find_by_order
#define OoK order_of_key

vector<int> prime;
bool isprime[N+3];

void sieve(){
  fill(isprime, isprime+N, true);
  F(i, 2, N){
    if(isprime[i]){
      if(i % 5 == 1) prime.PB(i);
      if(prime.size() == 55) break;
      for(LL j = (LL)(i*i) ; j <= N ; j += i)
        isprime[j] = false;
    }
  }
}

int solve(){
  sieve();
  int n;
  cin >> n;
  F(i, 0, n-1){
    if(i) cout << " ";
    cout << prime[i];
  }
  cout << endl;
  return 0;
}

void fun(){
  int t = 1;
  // cin >> t;
  while(t--) solve();
} 

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

  fun();
  return 0;
}

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

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()

Int INF = 1e18;
int inf = 1e9;
Int mod = 1e9+7;

int main() {
    Int n, p;
    cin >> n >> p;
    string s;
    cin >> s;
    Int res = 0;
    if (p == 2) {
        for (Int i = 0; i < n; i++) {
            Int x = s[i] - '0';
            if (x % 2 == 0) {
                res += i + 1;
            }
        }
    }
    else if (p == 5) {
        for (Int i = 0; i < n; i++) {
            Int x = s[i] - '0';
            if (x % 5 == 0) {
                res += i + 1;
            }
        }
    }
    else {
        map<Int, Int> mp;
        mp[0]++;
        Int mul = 1;
        Int t = 0;
        for (Int i = n - 1; i >= 0; i--) {
            Int x = s[i] - '0';
            t = (t + x * mul) % p;
            res += mp[t];
            mp[t]++;
            mul = mul * 10 % p;
        }
    }
    dump(res);
    return 0;
}


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

const int mod = 1000*1000*1000+7;

void add_self(int& a, int b) {
	a += b;
	if(a >= mod) {
		a -= mod;
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	string s;
	cin >> s;
	int n = s.length();
	vector<int> dp(13);
	dp[0] = 1;
	for(int i = 0; i < n; i++) {
		vector<int> new_dp(13);
		if(s[i] == '?') {
			for(int d = 0; d < 10; d++) {
				for(int j = 0; j < 13; j++) {
					add_self(new_dp[(10*j+d)%13], dp[j]);
				}
			}
		} else {
			int d = s[i] - '0';
			for(int j = 0; j < 13; j++) {
				new_dp[(10*j + d) % 13] = dp[j];
			}
		}
		
		swap(dp, new_dp);
	}
	
	cout << dp[5] << endl;
}


Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main{
	public static void main(String[] args)throws IOException{
		BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
		int a=Integer.parseInt(br.readLine());
		int Sum=a*a*a;
		System.out.println(Sum);
	}
}

Measured memory_bytes: 24344
# AtCoder Beginner Contest 175
# B - Making Triangle

N=int(input())
L=list(map(int,input().split()))
L.sort()

ans=0

for i in range (N):
    for j in range (i+1,N):
        for k in range (j+1,N):
            if L[i]+L[j]>L[k] and L[i]<L[j]<L[k]:
                ans+=1

print(ans)

Measured memory_bytes: 9156
import itertools
import math

N,M=map(int,input().split())
if N==M==1 or N==M==0:
  print(0)
  exit()
if N==0:
  even=0
  odd=math.factorial(M)/(math.factorial(M-2)*2)
  print(int(odd+even))
  exit()
if M==0:
  odd=0
  even=math.factorial(N)/(math.factorial(N-2)*2)
  print(int(odd+even))
  exit()
if N==1 or M==1:
  even=math.factorial(N)/2
  odd=math.factorial(M)/2
  print(int(odd+even))
  exit()

even=math.factorial(N)/(math.factorial(N-2)*2)
odd=math.factorial(M)/(math.factorial(M-2)*2)
print(int(odd+even))

Measured memory_bytes: 3064
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int[] num = new int[6];
		int up=0;
		for(int i=0;i<6;i++){
			num[i]=sc.nextInt();
		}
		Dice d = new Dice(num);
		String or=sc.next();
		char[] ar = or.toCharArray();
		for(int i=0;i<or.length();i++){
			if(ar[i]=='E'){
				d.tE();
				//System.out.println("E"+d.up);
			}else if(ar[i]=='N'){
				d.tN();
				//System.out.println("N"+d.up);
			}else if(ar[i]=='S'){
				d.tS();
				//System.out.println("S"+d.up);
			}else if(ar[i]=='W'){
				d.tW();
				//System.out.println("W"+d.up);
			}
		}
		System.out.println(num[d.up]);
	}
}

class Dice{
	static int[] label=new int[6];
	Dice(int[] a){
		for(int i=0;i<6;i++){
			label[i]=a[i];
		}
	}
	static int up=0,fr=1,ri=2;
	
	void tE(){
		int t=up;
		up=5-ri;
		ri=t;
	}
	
	void tW(){
		int t=up;
		up=ri;
		ri=5-t;
	}
	
	void tN(){
		int t=up;
		up=fr;
		fr=5-t;
	}
	
	void tS(){
		int t=up;
		up=5-fr;
		fr=t;
	}
}

Measured memory_bytes: 26364
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define f(t) for(ll i=0;i<t;i++)
#define ll long long int
#define ld long double
#define umpl unordered_map<ll,ll> 
#define vl vector<ll>
#define vld vector<ld>
#define vvl vector<vl>
#define pb push_back
#define mod 998244353
#define inf 1e18
#define pcout(x,p) cout<<fixed<<setprecision(p)<<x
#define all(a) a.begin(),a.end()
#define endl "\n"

inline ll mul(ll a, ll b){ return (a * 1ll * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c >= mod) c -= mod; return c; }
inline ll max(ll a, ll b){return a>b?a:b;}
inline ll min(ll a, ll b){return a<b?a:b;}
inline ll ceil(ll a,ll b){if(a%b==0)return a/b;else return a/b+1;}
inline ll mo(ll a,ll b){if(b<0){b=abs(b)%mod;b=a-b;return (b<0)?b+mod:b;}else{return (a+b)%mod;}}
inline ll pow(ll a,ll b){if(b==0){return 1;}else{if(b%2==0){ll temp=pow(a,b/2);return temp*temp;}
else{return a*pow(a,b-1);}}}

struct comp { 
    template<class T1,class T2,class T3,class T4>
    bool operator()(const pair<T1,T2> &p1,const pair<T3,T4> &p2){
        return p1.first<p2.first;
    }
};
const ll N=1e7+5;
ll spf[N];
const ll nax=N;

void sieve() { 
    spf[1] = 1; 
    for (ll i=2; i<nax; i++) spf[i] = i; 
    for (ll i=4; i<nax; i+=2) spf[i] = 2; 
    for (ll i=3; i*i<nax; i++) { 
        if (spf[i] == i) { 
            for (ll j=i*i; j<nax; j+=i) 
                if (spf[j]==j) 
                    spf[j] = i; 
        } 
    } 
} 

int main(){
	sieve();
	ll n;cin>>n;
	ll ans=0;
	for(ll i=1;i<=n;i++){
		ll sum=1,x=i;
		while(x>1){
			ll t=spf[x],temp=0;
			while((x%t)==0){
				temp++;x=x/t;
			}
			sum=sum*(temp+1);
		}
		ans+=(i*sum);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 81772
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int[] H = new int[N];

		for (int i=0; i<N; i++){
			H[i] = sc.nextInt();
		}
		int move = 0;
		int ans = 0;
		for (int i=0; i<N-1; i++){
			if (H[i] >= H[i+1]){
				move++;
			} else {
				ans = Math.max(move, ans);
				move = 0;
			}
		}
		ans = Math.max(move, ans);
		System.out.println(ans);
	}

}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int A, B; cin >> A >> B;
  string res;
  A*B%2==0 ? res = "No" : res = "Yes";
  cout << res << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define forn(low,high,i) for(i=low;i<high;i++)
#define forrev(high,low,i) for(i = high; i>= low;i--)                                 //g++ template.cpp -o template.exe
#define zeroes(x) memset(x,0,sizeof(x))                                        //all elements to 0  |  \
#define all(x) (x).begin(), (x).end()
typedef long long int ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod =1e9+7;
const ll maxn=100000;







bool sortbysec(const pair<int,int> &a,                         //sorting of elements wrt second
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
} 

bool sortinrev(const pair<int,int> &a,                   //sorting in descending wrt first 
               const pair<int,int> &b) 
{ 
       return (a.first > b.first); 
} 
bool sortinrevsec(const pair<int,int> &a,                  //sorting in dsc wrt second
               const pair<int,int> &b) 
{ 
       return (a.second > b.second); 
} 




int main()
{
  ll n;
  cin>>n;
  if(n>=400 && n<600)
  {
    cout<<"8";

  }
  if(n>=600 && n<800)
  {
    cout<<"7";

  }
  if(n>=800 && n<1000)
  {
    cout<<"6";

  }
  if(n>=1000 && n<1200)
  {
    cout<<"5";

  }
  if(n>=1200 && n<1400)
  {
    cout<<"4";

  }
  if(n>=1400 && n<1600)
  {
    cout<<"3";

  }
  if(n>=1600 && n<1800)
  {
    cout<<"2";

  }
  if(n>=1800 && n<2000)
  {
    cout<<"1";

  }
  
  return 0;
}

Measured memory_bytes: 3632
#include<iostream>

using namespace std;

string str;

int deny[3] = {2,1,0};
int mult[3][3] = {{0,0,0},
		  {0,1,1},
		  {0,1,2}};

int add[3][3] = {{0,1,2},
		 {1,1,2},
		 {2,2,2}};

string make(string s, int p, int q, int r){
  for(int i = 0; i < s.length(); i++){
    if(s[i] == 'P') s[i] = p+'0';
    if(s[i] == 'Q') s[i] = q+'0';
    if(s[i] == 'R') s[i] = r+'0';
  }

  return s;
}

int solve(string s){
  if(s.length() == 1) return s[0]-'0';

  //cout << s << endl;

  if(s[0] == '-'){
    string next = "";
    for(int i = 1; i < s.length(); i++)
      next+=s[i];
    return deny[solve(next)];
  }

  if(s[0] == '('){
    string a = "", b = "";
    int pos = 1;

    int par = 0;

    while(s[pos] != '*' && s[pos] != '+' || par){
      a += s[pos];
      if(s[pos] == '(') par++;
      if(s[pos] == ')') par--;
      pos++;
    }

    int ismul = false;
    if(s[pos++] == '*') ismul = true;

    while(pos < s.length()-1){
      b += s[pos++];
    }
   
    if(ismul) return mult[solve(a)][solve(b)];
    else return add[solve(a)][solve(b)];
  }
}

int main(){
  while(cin >> str && str != "."){
    int ans = 0;
   
    for(int P = 0; P <= 2; P++)
      for(int Q = 0; Q <= 2; Q++)
	for(int R = 0; R <= 2; R++){
	  string s = make(str,P,Q,R);
	  if(solve(s) == 2) ans++;
	}

    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1200
void solve();

int main() {
	solve();
	return 0;
}

//////////////////////////////////////////////////
//////////////////////////////////////////////////
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
using namespace std;

vector<long double> A;
int N;

void solve() {
	cin >> N;
	A.resize(N);
	for (int n = 0; n < N; n++) {
		cin >> A[n];
	}
	long double ans = 0;
	for (int n = 0; n < N; n++) {
		A[n] = 1 / A[n];
		ans += A[n];
	}
	cout << setprecision(12) << 1 / ans << endl;
	return;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.Arrays;
public class Main{
    public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int []a = new int [n];
      long sum =0;
      long []count = new long [100001];
      for(int i=0;i<n;i++){
        a[i] = sc.nextInt();
        count[a[i]]++;
        sum += a[i];
      }
      
      int q = sc.nextInt();
      long []ans = new long[q];
  
      for(int i=0;i<q;i++){
        int b = sc.nextInt();
        int c = sc.nextInt();
        
        sum -= count[b]*b;
        sum += count[b]*c;
        ans[i] = sum;
        count[c] += count[b];
        count[b] =0;
        
      }
      for(int i=0;i<q;i++){
        System.out.println(ans[i]);
      }



     

      
    }
}

Measured memory_bytes: 52484
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
template<typename T> auto compare = [](T x, T y) -> bool{return (x < y);};
const int MOD = 1000000007;

signed main(){
    long double N, M, d;
    cin >> N >> M >> d;
    if(d == 0) printf("%.10Lf\n",(M - 1) / N);
    else printf("%.10Lf\n",(2 * (N - d) * (M - 1)) / (N * N));
    return 0;
}			

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

int main() {
  int N = 0, K = 0;
  cin >> N >> K;
  
  int value = 1;

  for( int i = 0; i < N; ++i ){
    if( value * 2 < value + K ){
      value *= 2;
    }else{
      value += K;
    }
  }
  cout << value << endl;
}


Measured memory_bytes: 3580
using namespace std;
#include<bits/stdc++.h>
#define int long long
#define pb push_back 
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define repa(i,a,b) for (int i=a; i<=b; i++)
#define repd(i,b,a) for (int i=b; i>=a; i--)
#define endl "\n"
//debugging
#define debug1(a) cout<<#a<<" = "<<(a)<<endl;
#define debug2(a,b) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;
#define debug3(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;
#define debug4(a,b,c,d) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<", "<<#d<<" = "<<(d)<<endl;

const int N = 1e+6+5;
int big = 1e+18+3;
int mod = 1e+9+7;

signed main()
{
    IOS;
    double R;

    cin>>R;

    cout<<fixed<<setprecision(20)<<2*3.14159265358979*R<<endl;    
    
}

Measured memory_bytes: 3800
#include <bits/stdc++.h>
#define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define all(x) (x).begin(), (x).end()
#define print(x) cout << (x) << endl;

typedef long long ll;
const ll INF = 99999999999999;
const ll MOD = 1000000007;

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll lcm(ll number1, ll number2)
{
    return number1 * number2 / gcd(number1, number2);
}
template <class T>
bool contain(const std::string &s, const T &v)
{
    // contain(to_string(N), '3')
    return s.find(v) != std::string::npos;
}

int ctoi(char c)
{
    if (c >= '0' && c <= '9')
        return c - '0';
    return 0;
}
using namespace std;

void transpose(vector<vector<char>> &b)
{
    if (b.size() == 0)
        return;

    vector<vector<char>> trans_vec(b[0].size(), vector<char>());

    for (int i = 0; i < b.size(); i++)
    {
        for (int j = 0; j < b[i].size(); j++)
        {
            trans_vec[j].push_back(b[i][j]);
        }
    }

    b = trans_vec; // <--- reassign here
}

// C++ゆるさねえリスト
// accumulate(all(a), 0LL);
// 二分探索

int main()
{

    int n = 0;
    string s, t;

    cin >> n >> s >> t;
    rep(i, n)
    {
        cout << s[i] << t[i];
    }

    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
ll ans = 0;
const ll mo = 1000000007;
const ll MAX = 1010000;
const ll MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit()
{
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (ll i = 2; i < MAX; i++)
  {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
long long COM(ll n, ll k)
{
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main()
{
ll x , y ;
cin >> x >> y ;
COMinit();
if((x+y)%3!=0){
cout << ans << endl;
return 0;
}
ll kai=(x+y)/3;
x-=kai;
y-=kai;
ans=COM(x+y,x);
cout << ans << endl;
return 0;
}

Measured memory_bytes: 23936
import math
N = int(input())
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(cnt)

    if temp!=1:
        arr.append(1)

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

    return arr
A = factorization(N)
if N == 1:
    print(0)
else:
    for i in range(len(A)):
        if A[i] == 1:
            A[i] = 1
        else:
            s = (-1+int(math.sqrt(1+8*A[i])))/2
            A[i] = int(s)
    print(int(sum(A)))
    

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

int slove(int n,int k,int s){
  if(s<0 || k<0)
    return 0;

  if(s == 0 && k == 0){
    return 1;
  }
  int ans = 0;
  for(int i=n;i>0;i--){
    ans+=slove(i-1,k-1,s-i);
  }
  return ans;
}

int main(){
  int s,n,k,ans;
  while(cin>>n>>k>>s,n){
    ans = slove(n,k,s);
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
A = []

for _ in range(N):
    A.append(list(map(int, input().split())))

ans = 0

for i in range(N):
    total = 0
    for j in range(M):
        total += A[i][j]*B[j]
    if (total > C * (-1)):
        ans += 1

print(ans)


Measured memory_bytes: 3060