akhauriyash/Code-Regression huggingface dataset:
/*L - Deque*/
#include <bits/stdc++.h>
using namespace std;

using Long = long long;

const Long INF = 4000000000000ll;

vector <Long> arr;
vector <vector <Long> > memo;
Long maxValue(int ini, int fin);

int main(){

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int tam;

	cin >> tam;

	arr = vector <Long> (tam);
	memo = vector <vector <Long> > (tam, vector <Long> (tam, INF));

	for (int i = 0; i < tam; ++i)
		cin >> arr[i];


	Long ans;

	ans = maxValue(0, tam - 1);

	cout << ans;

	return 0;
}

Long maxValue(int ini, int fin){

	if(ini > fin){
		return 0;
	}

	if(memo[ini][fin] != INF){
		return memo[ini][fin];
	}

	Long ans;

	ans = -maxValue(ini + 1, fin) + arr[ini];
	ans = max(ans, -maxValue(ini, fin - 1) + arr[fin]);

	memo[ini][fin] = ans;
	
	return ans;
}

Measured memory_bytes: 70912
using System;
using System.Collections.Generic;

class Program
{
    static readonly double INF = double.PositiveInfinity;

    static void Main(string[] args)
    {
        while (true)
        {
            int[] input = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            int N = input[0], M = input[1], P = input[2], A = input[3] - 1, B = input[4] - 1;
            if (N == 0) break;
            int[] nums = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            double[,] dist = new double[M, M];
            
            for (int i = 0; i < P; i++)
            {
                input = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
                dist[input[0] - 1, input[1] - 1] = input[2];
                dist[input[1] - 1, input[0] - 1] = input[2];
            }
            double[,] dp = new double[1 << N, M];
            for (int i = 0; i < (1 << N); i++)
                for (int j = 0; j < M; j++)
                    dp[i, j] = INF;
            dp[0, A] = 0;
            for (int mask = 0; mask < (1 << N); mask++)
                for (int use = 0; use < N; use++)
                {
                    if ((mask >> use & 1) == 1) continue;
                    for (int i = 0; i < M; i++)
                        for (int j = 0; j < M; j++)
                        {
                            if (dist[i, j] == 0) continue;
                            double cost = dp[mask, i] + dist[i, j] / nums[use];
                            int nextMask = mask | 1 << use;
                            dp[nextMask, j] = Math.Min(dp[nextMask, j], cost);
                        }
                }

            double ans = INF;
            for (int mask = 0; mask < (1 << N); mask++) ans = Math.Min(ans, dp[mask, B]);
            Console.WriteLine((ans == INF) ? "Impossible" : ans.ToString("f3"));
        }
    }
}

Measured memory_bytes: 6012
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <algorithm> 
using namespace std;

int main()
{   
    int n;
    cin >> n;
    int n1,n2;
    cin >> n1 >> n2;
    int i = 0;
    for(i = n; i < n2; i+=n){
        if(i + n > n2) break;
    }
    if(i <= n2 && i >=n1) cout << "OK" << endl;
    else cout << "NG" << endl;
    return 0;
}

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

using namespace std;

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
    return '"' + s + '"';
}

string to_string(const char* s) {
    return to_string((string) s);
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
    bool first = true;
    string res = "{";
    for (int i = 0; i < static_cast<int>(v.size()); i++) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}

template <size_t N>
string to_string(bitset<N> v) {
    string res = "";
    for (size_t i = 0; i < N; i++) {
        res += static_cast<char>('0' + v[i]);
    }
    return res;
}

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

//Auther: Arin Roday
#define vec vector
#define i64 long long
#define endl '\n'
#define sz(x) (x).size()
#define times(n) for(int i = 0; i < (n); ++i)

int main(){
   i64 a, b;
   cin >> a >> b;
   char t;
   cin >> t;
   i64 d;
   cin >> d;
   b = (b * 100) + d;
   i64 ans = a * b;
   ans = ans / 100;
   cout << ans << endl;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int a[4];
  cin >> a[0] >> a[1];
  a[2] = a[0] - 1;
  a[3] = a[1] - 1;
  sort(a, a + 4);
  cout << a[2] + a[3] << endl;
  return 0;
}


Measured memory_bytes: 256
(defun collector (function lst); listの各要素を数えるコレクタ 10^7くらいまで
  (if lst
      (let* ((ans '())
             (mem (cons (car lst) 1)))
        (mapcar (lambda (k)
                  (if (funcall function k (car mem))
                      (incf (cdr mem))
                      (progn (push mem ans)
                             (setf mem (cons k 1))))) (cdr lst))
        (push mem ans)
        ans)
      '()))



(defun relu (n)
  (if (minusp n) 0 n))
(let* ((n (read))
       (m (loop :repeat n :collect (read)))
       (ms (sort (copy-seq m) #'<))
       (mr (collector #'= ms))
       (arr (make-array 1000000 :element-type 'fixnum :initial-element -1))
       (memarr (make-array (list 1000000 2) :element-type 'fixnum :initial-element -1))
       (mem (loop :for (aj . dj) :in mr
                  :collect (relu (floor (* dj (1- dj)) 2))))
       (mema (loop :for (aj . dj) :in mr
                   :do (setf (aref memarr aj 0) (relu (floor (* (1- dj) (- dj 2)) 2)))
                   :do (setf (aref memarr aj 1) (relu (floor (* dj (1- dj)) 2)))
                   ))
       (mems (reduce #'+ mem)))
  (loop :for k :in m
        :do(if (= -1 (aref arr k))
               (format t "~A~%" (setf (aref arr k) (+ mems (- (aref memarr k 1)) (aref memarr k 0))))
               (format t "~A~%" (aref arr k)))))


Measured memory_bytes: 66916
#include<bits/stdc++.h>
using namespace std;
#define P pair<int,int>
int main(){
    int n;
    cin>>n;
    vector<int> vec;
    int sum=0;
    for(int i=0;i<n;i++){
        int t;
        cin>>t;
        vec.push_back(t);
        sum+=t;
    }
    int m;
    cin>>m;
    int ans=sum;
    for(int i=0;i<m;i++){
        P t;
        cin>>t.first>>t.second;
        cout<<sum+t.second-vec[t.first-1]<<endl;
    }
    return 0;
}

Measured memory_bytes: 384
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)
#define REPIT(i,x) for(auto i{(x).begin()}; i != (x).end(); i++) 

#define PB push_back
#define MP make_pair
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef double dbl;
typedef vector<bool> Vb;
typedef vector<char> Vc;
typedef vector<double> Vd;
typedef vector<int> Vi;
typedef vector<ll> Vl;
typedef vector<string> Vs;
typedef vector<vector<int>> VVi;
typedef vector<vector<ll>> VVl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
inline void swap(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
inline void swap(int& a, int& b) { a ^= b; b ^= a; a ^= b; }
inline void YES() { cout << "YES" << endl; } inline void Yes() { cout << "Yes" << endl; }
inline void NO() { cout << "NO" << endl; } inline void No() { cout << "No" << endl; }

const int inf = 1 << 30;
const ll linf = 1LL << 60;
const int MOD = 1000000007;

using G = vector<vector<int>>;
typedef tuple<int, int, int> tup;

G g;
int n, m, start, goal;
Vl d, k, kk;
ll z = 0;

void debug();

void init()
{
	cin >> n >> m;
	g.resize(n);
	d.resize(n, linf);
	k.resize(n, linf);
	kk.resize(n, linf);

	REP(i, m)
	{
		int a, b; cin >> a >> b; --a; --b;
		g[a].push_back(b);
	}

	cin >> start >> goal;
	--start; --goal;
	d[start] = 0;
}

void bfs()
{
	// tup < d, vertex >
	priority_queue<pli> qk, qkk, qkkp;

	for (int u : g[start])
	{
		chmin(k[u], z);
		qk.push(pli(z, u));
	}

	while (!qk.empty())
	{
		while (!qk.empty())
		{
			ll c = qk.top().first;
			int v = qk.top().second;
			qk.pop();

			for (int u : g[v])
				if (chmin(kk[u], c))
					qkk.push(pli(c, u));
		}

		while (!qkk.empty())
		{
			ll c = qkk.top().first;
			int v = qkk.top().second;
			qkk.pop();

			for (int u : g[v])
				if (chmin(d[u], c + 1))
					qkkp.push(pli(d[u], u));
		}

		while (!qkkp.empty())
		{
			int v = qkkp.top().second;
			qkkp.pop();

			for (int u : g[v])
				if (chmin(k[u], d[v]))
					qk.push(pli(d[v], u));
		}
	}

}

int main()
{
	init();

	bfs();

	if (d[goal] == linf)
		cout << -1 << endl;
	else
		cout << d[goal] << endl;

}


void debug()
{
	cout << " d : ";
	REP(i, n)
		cout << setw(3) << d[i];
	cout << endl;

	cout << " k : ";
	REP(i, n)
		cout << setw(3) << k[i];
	cout << endl;

	cout << "kk : ";
	REP(i, n)
		cout << setw(3) << kk[i];
	cout << endl;

}

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

typedef long long ll;
const ll InF = 1e15;
// ll mod = 1000000007;

int main() {
  int n;
  cin>>n;
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    int a;
    cin>>a;
    ans += a - 1;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
#include <set>
#include <queue>
using namespace std;
typedef long long ll;

void solve() {
	ll n; cin >> n;
	long double cur; cin >> cur;
	cout << ll(n * cur);

}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	// int t; cin >> t;
	// while (t--)
	solve();


}

Measured memory_bytes: 3772
import java.util.*;
import java.lang.*;

public class Main
{
	public static void main(String args[])
	{
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int a[]=new int [n];
		int temp=0;
		long ans=0;
		for(int i=0;i<n;i++)
		{
			a[i]=sc.nextInt();
		}
		temp=a[0];
		for(int i=1;i<n;i++)
		{
			if(a[i]<=temp)
				ans=ans+Math.abs(a[i]-temp);
			else
				temp=a[i];
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 61140
/*
               _____
              /     \
              vvvvvvv  /|__/|
                 I   /O,O   |
                 I /_____   |      /|/|
                J|/^ ^ ^ \  |    /00  |    _//|
                 |^ ^ ^ ^ |W|   |/^^\ |   /oo |
                  \m___m__|_|    \m_m_|   \mm_|


 */
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

#define fori(a, r) for(long long int a = 0; a < (r); ++a)
#define forI(a, r) for(long long int a = 1; a <= (r); ++a)

#define ff first
#define ss second
#define pll pair<ll, ll>

//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("unroll-loops")

using namespace std;
typedef long long int ll;
typedef long double ld;
typedef long long ull;

#define pt pair<ll, ll>
#define x first
#define y second

pt dxy[] = {{1,  0},
            {0,  1},
            {-1, 0},
            {0,  -1}};
const long long MAXN = 10 * 1000 + 100, MOD = 1e9 + 7, INF = ((1ll << 60) - 1) * 2 + 1;

//mt19937 random(time(0));

ll n, m;
ll c[4];

void solve() {
    cin >> n;
    ll ans = 0;
    fori(i, n){
        string s;
        cin >> s;
        ll type = ((s[0] == 'B') << 1) | (s.back() == 'A');
        for(ll i = 0; i + 1 < s.size(); ++i){
            if(s[i] == 'A' && s[i + 1] == 'B') ++ans;
        }
        ++c[type];
    }
    ll oA = c[1];
    ll Bo = c[2];
    ll BA = c[3];
    if(BA != 0 && oA != 0){
        --oA;
        ++ans;
    }
    if(BA != 0 && Bo != 0){
        --Bo;
        ++ans;
    }
    ans += min(oA, Bo);

    if(BA > 0) ans += BA - 1;

    cout << ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#define DEBUG0
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    solve();
    //another();
}

Measured memory_bytes: 3148
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define itrep(it, a) for(it = (a).begin(); it != (a).end(); it++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
#define INF (1 << 30)
using namespace std;

const int N = 100005;

int main(){
    int n, m;
    int of_bolls[N], contains_red[N] = {0};
    rep(i,N) of_bolls[i] = 1;
    contains_red[1] = 1;

    cin >> n >> m;
    rep(i,m){
        int x, y;
        cin >> x >> y;
        if(of_bolls[x] > 1 && contains_red[x] == 1){
            contains_red[y] = 1;
        }else if(contains_red[x] == 1){
            contains_red[x] = 0;
            contains_red[y] = 1;
        }
        of_bolls[x]--;
        of_bolls[y]++;
        //range(i,1,n + 1) cout << of_bolls[i];
        //cout << endl;
        //range(i,1,n + 1) cout << contains_red[i];
        //cout << endl;
    }
    int sum = 0;
    range(i,1,n + 1) if(contains_red[i]) sum++;
    cout << sum << endl;
}


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

int main() {        
    int n, m, x;
    cin >> n >> m >> x;
    vector<int> v(n + 1, 0);
    for (int i = 0; i < m; i++) {
        int a;
        cin >> a;
        v[a]++;
    }
    for (int i = 1; i <= n; i++) {
        v[i] += v[i - 1];
    }
    cout << min(v[x], v[n] - v[x]) << endl;
}


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

int main() {
  int N, Y, c, i, j, aa = -1, bb = -1, cc = -1;
  cin >> N >> Y;
  for (int i = 0; i <= N; i++) {
    for (int j = 0; i + j <= N; j++) {
      c = N - i - j;
      if (i*10000 + j*5000 + c*1000 == Y) {
        aa = i, bb = j, cc = c;
      }
    }
  }
  cout << aa << " " << bb << " " << cc << endl;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  int maxn = 0;
  map<string, int> mp;
  for (int i = 0; i < N; i++) {
    string s;
    cin >> s;
    mp[s]++;
    maxn = max(maxn, mp[s]);
  }
  for (auto m : mp) {
    if (m.second == maxn) cout << m.first << '\n';
  }
  return 0;
}


Measured memory_bytes: 23808
/*                        ______
 _______   /\     |``\   |        |  /
    |     /  \    |__/   |____    |/
    |    / _ _\   |  \   |        |\
    |   /      \  |   \  |______  |  \

            Dept. of CSE
        Comilla  University

*/
#include<bits/stdc++.h>
#define pi 2*acos(0.0)
#define ll long long
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Node struct node
#define spc " "
#define  E  2.71828182845904523536
#define pb push_back
#define pp pop_back
#define valid(nx,ny) nx>=0 && nx<n && ny>=0 && ny<m
#define ee endl
#define pii pair<int,int>
#define infinity 10000000000000000
#define mod 1000000007
int fx[]={0,0,+1,-1};
int fy[]={+1,-1,0,0};

using namespace std;
///check n=1;
///check corner case;
const int maX=1e5+1;
vector<ll>Graph[maX],cost[maX];
ll visit[maX];
ll x[10];
ll y[10];

int main()
{
    ll n,i,j=0,cc,cc1,k=0;
    string str;
    cin>>str;
    n=str.size();
    if(str[0]=='0')cc=0;
    else cc=1;
    if(cc==0)cc1=1,k=1;
    else cc1=0,k=1;
    for(i=1;i<n;i++){
        if(cc==0){
            if(str[i]=='0'){
                j++;cc=1;
            }
            cc=1;
        }
        else{
            if(str[i]=='1'){
                j++;cc=0;
               
            }
            cc=0;
        }
    }
    for(i=1;i<n;i++){
        if(cc1==0){
            if(str[i]=='0')k++,cc1=1;
            cc1=1;
        }
        else{
            if(str[i]=='1')k++,cc1=0;
            cc1=0;
        }
    }
    cout<<min(j,k)<<endl;
return 0;
}


Measured memory_bytes: 5120
#include<stdio.h>
int main(){
    int a,b,c=1;
    while(scanf("%d %d",&a,&b)!=EOF){
        c=0;
        for(int i=1;i<1000001;i=i*10){
            if((a+b)/i==0){
                break;
            }
            c++;
        }
        printf("%d\n",c);
    }
    return 0;
}

Measured memory_bytes: 1028
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		String rezult;
		rezult = "No";
		int aPlusbOfSuuti = Integer.parseInt(a + b);
		for(int num = 1;num <= 1000;num++){
			if(aPlusbOfSuuti == num*num){
				rezult = "Yes";
				break;
			}
		}
		System.out.println(rezult);
	}

}


Measured memory_bytes: 22612
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define el '\n'
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repi(i, a, b) for (int i = a; i >= b; i--)
#define vi vector<int>
#define vb vector<bool>
#define vll vector<ll>
#define vii vector<pii>
#define vvi vector<vector<int>>
#define vvii vector<vector<pii>>
#define vvll vector<vector<ll>>
#define umap unordered_map
#define uset unordered_set
#ifdef LOCAL
#define debug(fmt, ...) printf(fmt, ##__VA_ARGS__)
#define debugrep(i, a, b) for (int i = a; i < b; i++)
#define check(...) assert(__VA_ARGS__)
#else
#define debug(fmt, ...)
#define debugrep(i, a, b)
#define check(...)
#endif

const int MODULO = 998244353;

int power(int base, int exp) {
    if (exp == 0) {
        return 1;
    }
    if (exp == 1) {
        return base;
    }
    int half = power(base, exp / 2);
    if (exp % 2 == 0) {
        return (ll)half * half % MODULO;
    } else {
        return (ll)half * half % MODULO * base % MODULO;
    }
}

int extgcd(int a, int b, int &x, int &y) {
    if (a == 0) {
        x = 0;
        y = 1;
        return b;
    }
    int x1, y1;
    int d = extgcd(b % a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return d;
}

int invmod(int a, int m) {
    int x, y;
    int g = extgcd(a, m, x, y);
    if (g != 1) {
        return -1;
    } else {
        x = (x % m + m) % m;
        return x;
    }
}

int mul(int a, int b) {
    // if ((ll)a * b % MODULO < 0) {
    //     debug("a=%d,b=%d,a*b=%d\n", a, b, (ll)a * b % MODULO);
    // }
    check((ll)a * b % MODULO >= 0);
    return (ll)a * b % MODULO;
}

int add(int a, int b) {
    check((a + b) % MODULO >= 0);
    return (a + b) % MODULO;
}

vi fac, fnv;

void prepare() {
    fac = vi(2e5 + 1, 0);
    fnv = vi(2e5 + 1, 0);
    fac[1] = fnv[1] = 1;
    rep(i, 2, fac.size()) {
        fac[i] = mul(i, fac[i - 1]);
        check(fac[i] >= 0);
        int inv = invmod(i, MODULO);
        check(inv >= 0);
        fnv[i] = mul(inv, fnv[i - 1]);
        check(fnv[i] >= 0);
        check(mul(fac[i], fnv[i]) == 1);
    }
}

int c(int total, int choose) {
    if (total < choose) {
        debug("here");
        return 0;
    }
    if (total == choose || choose == 0) {
        return 1;
    }
    return mul(mul(fac[total], fnv[choose]), fnv[total - choose]);
}

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

    int n, m, k;
    cin >> n >> m >> k;
    int ans = 0;
    prepare();
    rep(k1, 0, k + 1) {
        int ans1 = mul(c(n - 1, k1), mul(m, power(m - 1, n - 1 - k1)));
        debug("k1=%d,ans1=%d\n", k1, ans1);
        ans = add(ans, ans1);
    }
    cout << ans;
}


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

class Main {

  int n;
  int k;
  int[] t = new int[100000];

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

  private int check(int maxLoad) {
    int i = 0;
    for (int j = 0; j < k; j++) {
      int s = 0;
      while (s + t[i] <= maxLoad) {
        s += t[i];
        i++;
        if (i == n) {
          return n;
        }
      }
    }
    return i;
  }

  public void solve() {
    Scanner sc = new Scanner(System.in);
    n = sc.nextInt();
    k = sc.nextInt();
    for (int i = 0; i < n; i++) {
      t[i] = sc.nextInt();
    }
    int left = 0;
    int right = n * Arrays.stream(t).max().orElse(0);
    while (right - left > 1) {
      int mid = (left + right) / 2;
      int v = check(mid);
      if (v >= n) {
        right = mid;
      } else {
        left = mid;
      }
    }
    System.out.println(right);
  }
}


Measured memory_bytes: 73660
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		final int N = sc.nextInt();
		final int M = sc.nextInt();
		final int X = sc.nextInt();
		final int Y = sc.nextInt();
		int[] x = new int[N+1];
		int[] y = new int[M+1];
		int max_x = X;
		for (int i = 0; i < N; i++) {
			x[i] = sc.nextInt();
			max_x = Math.max(max_x, x[i]);
		}
		int min_y = Y;
		for (int i = 0; i < M; i++) {
			y[i] = sc.nextInt();
			min_y = Math.min(min_y, y[i]);
		}
		if (max_x < min_y) {
			System.out.println("No War");
		} else {
			System.out.println("War");
		}
	}
}

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

	public static void main(String[] args) {

		
		Scanner input = new Scanner(System.in);
		
		long a = input.nextLong();
		long b = input.nextLong();
		
		if((a+b)%2==0)
			System.out.println((a+b)/2);
		else
			System.out.println("IMPOSSIBLE");
		
		
	}
	
	
}


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

typedef long long ll;
#define vec vector<int>
#define vecll vector<ll>
#define vpair vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n)   for(int i=(int)0; i<(int)n; i++)
#define llrep(i,n)   for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n) for(int i=(int)m; i<(int)n; i++)
#define all(var)     (var).begin(), (var).end()
#define prt(var)     cout << var << endl
#define prt_dbl(i,var) cout<<fixed<<setprecision(i)<<var<<endl;

int main(){
  ll N;
  vecll V(200001,0);
  cin>>N;
  vec A(N);
  llrep(i,N){
    cin>>A.at(i);
    V.at(A.at(i)-1)++;
  }
ll total = 0;
  llrep(i,200001){
    if(V.at(i)>1){
      total+= V.at(i)*(V.at(i)-1)/2;
    }
  }
//  cout<<total<<endl;
  llrep(i,N){
    if(V.at(A.at(i)-1)>1){
      cout<<total-V.at(A.at(i)-1)+1<<endl;
    }else{
      cout<<total<<endl;
    }

  }


}


Measured memory_bytes: 4992
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define F first
#define S second
#define _sz(x) (int)x.size()

using namespace std ;
using ll = long long ;
using ld = long double ;
using pii = pair <int , int> ;

const int N = 300 + 10 , mod = 1e9 + 7 ;
int n , m , ans ;
int dp[N][N][N] ;
vector <pii> vec[N] ;

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

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

	cin >> n >> m ;

	for (int i = 0 , l , r , x ; i < m ; i ++) {
		cin >> l >> r >> x ;
		vec[r].push_back({l , x}) ;
	}

	dp[0][0][0] = 1 ;
	for (int a = 0 ; a <= n ; a ++)
		for (int b = 0 ; b <= n ; b ++)
			for (int c = 0 ; c <= n ; c ++) {
				int i = max(max(a , b) , c) ;

				for (pii p : vec[i]) {
					int l = p.F , x = p.S ;

					int num = (a >= l) + (b >= l) + (c >= l) ;

					if (num != x) {
						dp[a][b][c] = 0 ;
						break ;
					}
				}

				add(dp[i + 1][b][c] , dp[a][b][c]) ;
				add(dp[a][i + 1][c] , dp[a][b][c]) ;
				add(dp[a][b][i + 1] , dp[a][b][c]) ;


				if (i == n) add(ans , dp[a][b][c]) ; 
		}

	cout << ans << '\n' ;
}


Measured memory_bytes: 114944
n = int(input())
if n%2 == 0:
	partsum = n+1
	parts = [[i,n+1-i] for i in range(1,n//2+1)]
	m = (n-2)*n//2
else:
	partsum = n
	parts = [[n]]+[[i,n-i] for i in range(1, (n+1)//2)]
	m = (n-3)*(n-1)//2 + n-1

print(m)
for i,p in enumerate(parts):
	for j,q in enumerate(parts):
		if i<=j:
			continue
		# i>jのとき
		for a in p:
			for b in q:
				print(a,b)

Measured memory_bytes: 3632
#include <iostream>
using namespace std;
int N,K,sum=0,a[200004],d[200004];
int main() {
	cin >> N >> K;
	for (int i=1; i<=N; i++) {
        cin >> a[i];
        d[i] = d[i-1] + a[i];
    }
	for (int i=K; i<=N; i++) {
        sum = max(sum, d[i]-d[i-K]);
    }
	printf("%.12lf\n", (double)(sum+K) / 2.0);
}

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

#define FILE_IN "pviz.in"
#define FILE_OUT "pviz.out"
#define ofile freopen(FILE_IN,"r",stdin);freopen(FILE_OUT,"w",stdout)
#define fio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define nfio cin.tie(0);cout.tie(0)
#define max(x,y) (((x)>(y))?(x):(y))
#define min(x,y) (((x)<(y))?(x):(y))
#define ord(a,b,c) ((a>=b)and(b>=c))
#define MOD (ll(998244353))
#define MAX 300001
#define mag 320
#define p1 first
#define p2 second.first
#define p3 second.second
#define pow2(x) (ll(1)<<x)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<int,pii> piii;
#define endl "\n"

#define ALL(A) (A).begin(), (A).end()
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

 

long long fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int 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(int n, int 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(void){
    ios::sync_with_stdio(0);
    cin.tie(0);
    COMinit();
 
    ll N,A,B,K;
    cin >> N >> A >> B >> K;
    ll ans = 0;
    for(ll i=0;i<=N;i++){
        ll np = A*i;
        if(np>K)break;
        if( (K-np) % B == 0 ){
            ans += COM(N,i) * COM(N,(K-np)/B);
            ans %= MOD;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 7296
#include <iostream>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <cstdlib>
using namespace std;

int main() {
	string S;
	string s[10];
	int x = 0;
	int res = 0;

	cin >> S;
	for (int i = 0; i < S.size() - 2; ++i) s[i] = S.substr(i, 3);

	for (int i = 0; i < S.size() - 2; ++i) {
		if (abs(753 - x) > abs(753 - stoi(s[i]))) x = stoi(s[i]);
	}
	res = abs(753 - x);
	cout << res << endl;
}


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

const [a, b]: number[] = fs.readFileSync('/dev/stdin', 'utf8').trim().split(' ').map(Number);


function main(): string {
    if (a === b) return 'Draw';
    if (a === 1) return 'Alice';
    if (b === 1) return 'Bob';
    if (a > b) {
        return 'Alice';
    } else {
        return 'Bob';
    }
}

console.log(main());

Measured memory_bytes: 29660
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second
int m,n;
bool sea[100][100];
int maxi = 0;

void dfs(int i , int j,int d){
    maxi = max(d,maxi);
    sea[i][j] = false;
    REP(k,4){
        int x = i + dx[k];int y = j + dy[k];
        if((0 <= x && x < n && 0 <= y && y < m) && sea[x][y]){
            dfs(x,y,d + 1);
        }
    }
    sea[i][j] = true;
}
int main(){
    while(true){
        maxi = 0;
        cin >> m >> n;
        if(m == 0 && n == 0)
            break;
        REP(i,n)
            REP(j,m)
            scanf("%d",&sea[i][j]);
        REP(i,n){
            REP(j,m){
                if(sea[i][j])
                    dfs(i,j,1);
            }
        }
        printf("%d\n", maxi);
    }
    return 0;
}

Measured memory_bytes: 3232
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int inf = 1001001001;

vector<vector<int>> g;
vector<int> seen;
int dfs(int i){
  int cnt = 0;
  for(auto j : g[i]) {
    if(seen[j] == 1) continue;
    seen[j] = 1;
    cnt++;// count itseld
    cnt += dfs(j); // count next node
    
  }
  return cnt;
}
  
int main(){
  int n,m;
  cin >> n >> m;
  g.resize(n);
  rep(i,n) g[i].resize(0);
  seen.resize(n,0);
  rep(i,m){
    int a, b;
    cin >> a >> b;
    a--; b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  int ans = 1;
  rep(i,n) {
    ans = max(ans, dfs(i));
  }
  cout << ans << endl;
}


Measured memory_bytes: 24200
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,M,X,Y;
  cin>>N>>M>>X>>Y;
  int x[N];
  int y[M];
  int mi = 100000;
  int ma = -10000;
  for(int i = 0;i<N;i++){
    cin >> x[i];
    if(x[i]>ma){
      ma = x[i];
    }
  }
  for(int i = 0;i<M;i++){
    cin >> y[i];
    if(y[i]<mi){
      mi = y[i];
    }
  }
  bool t = 0;
  for(int k = ma+1;k<=mi;k++){
    if(X<k&&k<=Y){
      cout << "No War" << endl;
      t = 1;
      break;
    }
  }
  if(t == 0){
    cout << "War" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int i, j, k, a[3];

	scanf("%d %d %d", &a[0], &a[1], &a[2]);

	for(i=0;i<2;i++)
	{
		for(j=0;j<2;j++)
		{
			if(a[j] > a[j+1])
			{
				k = a[j];
				a[j] = a[j+1];
				a[j+1] = k;
			}
		}
	}

	printf("%d %d %d\n", a[0], a[1], a[2]);

	return 0;
}

Measured memory_bytes: 596
import java.io.File;
import java.io.IOException;
import java.util.*;
 
public class Main {
 
	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner sc = new Scanner(file);
		
		Scanner sc = new Scanner(System.in);
		
		int x = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		System.out.println((Math.abs(x-a) < Math.abs(x-b)) ? "A" : "B");
	}
}

Measured memory_bytes: 25172
#include<bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;

int N, M; 
vector<bool> seen;
int ans;

bool check(){
    bool res = true;
    for(int i = 0; i < N; i++)
      if(!seen[i]) res = false;
    return res;
}

// 深さ優先探索
void dfs(const Graph &G, int v) {
    seen[v] = true; // v を訪問済にする
  
    if(check()) ans++;

    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue; // next_v が探索済だったらスルー
        dfs(G, next_v); // 再帰的に探索
        seen[next_v] = false;
    }
}

int main() {
    // 頂点数と辺数
    cin >> N >> M;

    // グラフ入力受取 (ここでは無向グラフを想定)
    Graph G(N);
    for (int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
    }
  
    ans = 0;

    // 頂点 0 をスタートとした探索
    seen.assign(N, false); // 全頂点を「未訪問」に初期化
    dfs(G, 0);
  
    cout << ans << endl;  
    return 0;
}

Measured memory_bytes: 256
N=int(input())
happiness=[tuple(map(int,input().split())) for _ in range(N)]

ans=[[0,0,0] for i in range(N+1)]

for i in range(1,N+1):
    for j in range(3):
        for k in range(3):
            if j!=k:
                ans[i][k]=max(ans[i][k],ans[i-1][j]+happiness[i-1][k])

print(max(ans[N]))


Measured memory_bytes: 40180
#include <iostream>
#include <iosfwd>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <cassert>
#include <cctype>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <sstream>
#include <complex>
#include <fstream>
#include <functional>
#include <numeric>
#include <utility>
#include <algorithm>
#include <assert.h>
#include <unordered_map>
#include<unordered_set>
#include <random>
#include <ctime>
#include <chrono>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define se second
#define fi first
#define pai acos(-1)
#define fn(i,x) for(i=0;i<x;i++)
#define fs(i,s,x) for(i=s;i<x;i++)
#define fr(i,x,s) for(i=x;i>=s;i--)
#define fit(itr,s) for(itr=s.begin();itr!=s.end();itr++)
#define W while
#define pp pair<ll,ll>
#define ppi pair<int,int>
#define vl vector<ll>
#define vll vector<pp >
#define vi vector<int>
#define vii vector<ppi>
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
#define debug4(x,y,z,w) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<endl;
#define boost  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
const int MAX=2e5+1;
const ll MM=1e16;
const ll mod=1e9+7;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};

ll expo(ll x,ll n,ll M=mod)
{
    ll ans=1;
    while(n>0)
    {
        if(n&1){ans=(ans*x)%M;}
                x=(x*x)%M;
                n>>=1;
    }
    return ans;
}


void solve()
{
    ll n,m,i,j,k;
    string s;
    cin>>s;
    cout<<s.substr(0,3)<<endl;
}

int main()
{
  boost;
  ll t=1;
 // cin>>t;
  while(t--)
  {
      solve();
  }
}


Measured memory_bytes: 3656
let nil = -1

type tree = { mutable parent : int; mutable child : int; mutable bro : int; mutable depth : int }

let make () = { parent = nil; child = nil; bro = nil; depth = nil }

let set_depth t n =
  let rec root i =
    if i = n then nil
    else if t.(i).parent = nil then i
    else root (i + 1) in
  let rec doit i d =
    t.(i).depth <- d;
    if t.(i).bro <> nil then doit t.(i).bro d;
    if t.(i).child <> nil then doit t.(i).child (d + 1) in
  doit (root 0) 0

let print_tree t =
  let rec print_children i c =
    if c <> nil then begin
      if c <> t.(i).child then print_string ", ";
      print_int c;
      print_children i t.(c).bro
    end in
  t |> Array.iteri (fun i _ ->
    "node " ^ string_of_int i ^ ": parent = " ^ string_of_int t.(i).parent ^ ", depth = "
      ^ string_of_int t.(i).depth ^
      (if t.(i).parent = nil then ", root, ["
       else if t.(i).child = nil then ", leaf, ["
       else ", internal node, [")
    |> print_string;
    print_children i t.(i).child;
    print_string "]\n")

let () =
  let n = Scanf.scanf "%d " (fun i -> i) in
  let t = Array.init n (fun _ -> make ()) in
  for _ = 0 to n - 1 do
    let (id, k) = Scanf.scanf "%d %d " (fun id k -> (id, k)) in
    let left_child = ref 0 in
    for i = 0 to k - 1 do
      let c = Scanf.scanf "%d " (fun i -> i) in
      t.(c).parent <- id;
      if i = 0 then t.(id).child <- c
      else t.(!left_child).bro <- c;
      left_child := c;
    done;
  done;
  set_depth t n;
  print_tree t

Measured memory_bytes: 13324
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

map<int64_t, int> PrimeFactorization(int64_t n) {
	assert(n > 0);
	map<int64_t, int> mp;
	if(n == 1) {
		mp[1] = 1;
		return mp;
	}
	int64_t i = 2;
	while(n > 1) {
		if(n < i * i) {
			mp[n]++;
			return mp;
		}
		if(n % i == 0) {
			n /= i;
			mp[i]++;
		} else {
			i++;
		}
	}
	return mp;
}

bool pri[1000010];
int main() {
	int n; cin >> n;
	int a[n]; rep(i,n) cin >> a[i];
	bool se = false;
	int s = a[0];
	for(int i = 1; i < n; ++i) {
		s = gcd(s, a[i]);
	}
	if(s == 1) {
		se = true;
	}
	bool pa = true;
	rep(i,n) {
		auto mp = PrimeFactorization(a[i]);
		for(auto e : mp) {
			if(e.first == 1) continue;
			if(pri[e.first]) pa = false;
			pri[e.first] = true;
		}
	}
	if(pa) {
		cout << "pairwise coprime" << '\n';
	} else if(se) {
		cout << "setwise coprime" << '\n';
	} else {
		cout << "not coprime" << '\n';
	}
	return 0;
}

Measured memory_bytes: 8324
#include <bits/stdc++.h>
using namespace std;
constexpr long long MOD = 1000000007;
using ll = long long;
int main() {
ll r;
cin >> r;
if (r < 1200) cout << "ABC" << endl;
else if(r<2800)
    cout << "ARC" << endl;
else
    cout << "AGC" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#define REP(i, a, n) for(int i = ((int) a); i < ((int) n); i++)
using namespace std;
typedef long long ll;
typedef vector<ll> vec;

class UnionFind {
  vector<int> a;
public:
  UnionFind(int n) { REP(i, 0, n) a.push_back(i); }
  int find(int i) { return a[i] == i ? i : (a[i] = find(a[i])); }
  void unite(int i, int j) { a[find(i)] = find(j); }
  bool same(int i, int j) { return find(i) == find(j); }
};

string S;
int p;

ll num() {
  int val = 0;
  while('0' <= S[p] && S[p] <= '9') val = val * 10 + (S[p++] - '0');
  return val;
}

vec expr() {
  vector<vec> n;
  vector<char> op;
  while(p < S.length() && S[p] != ')') {
    if(S[p] == '+' || S[p] == '-' || S[p] == '*' || S[p] == '/') {
      op.push_back(S[p++]);
    } else if(S[p] == '(') {
      p++;
      n.push_back(expr());
      p++;
    } else {
      vec u;
      u.push_back(num());
      n.push_back(u);
    }
  }

  int idx[20];
  REP(i, 0, op.size()) idx[i] = i;
  vec ret;
  do {
    UnionFind uf(n.size());
    vec d[20];
    REP(i, 0, n.size()) d[i] = n[i];
    REP(i, 0, op.size()) {
      vec n1 = d[uf.find(idx[i])];
      vec n2 = d[uf.find(idx[i] + 1)];
      vec res;
      REP(j, 0, n1.size()) REP(k, 0, n2.size()) {
        int val;
        if(op[idx[i]] == '/' && n2[k] == 0) continue;
        switch(op[idx[i]]) {
          case '+': val = n1[j] + n2[k]; break;
          case '-': val = n1[j] - n2[k]; break;
          case '*': val = n1[j] * n2[k]; break;
          case '/': val = n1[j] / n2[k]; break;
        }
        res.push_back(val);
      }
      uf.unite(idx[i], idx[i] + 1);
      d[uf.find(idx[i])] = res;
    }
    REP(i, 0, d[uf.find(0)].size()) ret.push_back(d[uf.find(0)][i]);
  } while(next_permutation(idx, idx + op.size()));
  sort(ret.begin(), ret.end());
  ret.erase(unique(ret.begin(), ret.end()), ret.end());

  return ret;
}

int main(void) {
  while(cin >> S, S != "#") {
    p = 0;
    cout << expr().size() << endl;
  }
  return 0;
}

Measured memory_bytes: 9652
#include <stdio.h>
#include <math.h>
int main()
{
    long long num;
    int n,i;
    while(scanf("%d",&n)!=EOF)
    {
        num=1;
        for(i=1;i<=n;i++)
        {
            num=num*i;
            num=num%(long long)(1e9+7);
        }
        printf("%lld\n",num);
    }
    return 0;
}

Measured memory_bytes: 128
n = int(input())
a = list(map(int, input().split()))
a.sort()

b = [True for i in range(a[-1]+1)]

ans = 0

for i, j in enumerate(a):
    if b[j]:
        t = 1
        while j*t < len(b):
            b[j*t] = False
            t += 1
        
        if i == n-1:
            ans += 1
        elif j != a[i+1]:
            ans += 1
        
print(ans)


Measured memory_bytes: 32240
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(int argc, char const *argv[])
{
    int n, m; cin >> n >> m;
    if (n>=m) {
        cout << 0 << endl;
    } else {
        vector<int> x(m, 0);
        for(int i=0;i<m;++i) {
            cin >> x[i];
        }
        sort(x.begin(), x.end());
        for(int i=0;i<m-1;++i) {
            x[i] = x[i+1]-x[i];
        }
        x.erase(x.end()-1);
        sort(x.begin(), x.end());
        for(int i=1;i<m-n;++i) {
            x[0] += x[i];
        }
        cout << x[0] << endl;
    }
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
static const long long MOD = 1000000000+7;
static const double PI = 3.141592653589793;
vector<long long> vecmodfact(2,1);

long long modpow(long long x, long long n, long long mod = 0) {
  if (mod == 0) {
      long long res=1;
    while (n > 0) {
      if (n%2 == 1) {
        res = ( res*x );
      }
      x = (x*x);
      n /= 2;
    }
    return res;
  }

  long long res=1;
  while (n > 0) {
    if (n%2 == 1) {
      res = ( res*x ) % mod;
    }
    x = (x*x) % mod;
    n /= 2;
  }
  return res;
}

long long modinverse(long long x, long long mod) {
  // mod must be prime number.
  return modpow(x, mod-2, mod);
}

long long modfact(long long n, long long mod) {
  if (vecmodfact.size()-1 >= n) return vecmodfact.at(n);
  int i=vecmodfact.size();
  vecmodfact.resize(n+1);
  for (; i<=vecmodfact.size()-1; i++) {
    vecmodfact.at(i) = vecmodfact.at(i-1)*i % mod;
  }
  return vecmodfact.at(n);
}

long long modcomb(long long m, long long n, long long mod){
  if (m < n || n < 0) return 0;
  if (n == 0 || n == m) return 1;
  long long ans = modfact(m,mod) * modinverse(modfact(n,mod), mod) % mod;
  ans = ans * modinverse(modfact(m-n,mod), mod) % mod;
  return ans;
}



int main() {
  long long n;
  cin >> n;

  if (n==1) {
    cout << 0 << endl;
    return 0;
  }
  long long m=n;

  long long ans=0;

  map<long long, long long> ma;
  for (long long i=2; i*i<=n; i++) {
    while (true) {
      if (m%i==0) {
        ma[i]++;
        m /= i;
      }
      else break;
    }
  }
  if (m!=1) ma[m]=1;

//  for (auto iter=ma.begin(); iter != ma.end(); iter++) {
//    cout << iter->first << " " << iter->second << endl;
//  }
  m = n;
  for (auto iter=ma.begin(); iter != ma.end(); iter++) {
    long long p=iter->first;
    long long d=p;
    long long e=iter->second;
    for (int i=1; i<=e; i++) {
      if (m%d==0) {
        ans++;
        m /= d;
        d *= p;
      }
      else break;
    }
  }

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

Measured memory_bytes: 3600
#include<iostream>
#include<algorithm>
#include<cstring>
#include<queue>
#include<vector>

using namespace std;

const int MAX=200;

int V;//number of vertex
vector<int> G[MAX];
int match[MAX];
bool used[MAX];

void add_edge(int u,int v)
{
	G[u].push_back(v);
	G[v].push_back(u);
	return;
}

bool dfs(int v)
{
	used[v]=true;
	for(int i=0;i<G[v].size();i++)
	{
		int u=G[v][i],w=match[u];
		if(w<0||!used[w]&&dfs(w))
		{
			match[v]=u;
			match[u]=v;
			return true;
		}
	}
	return false;
}

int bipartite_matching()
{
	int res=0;
	memset(match,-1,sizeof(match));
	for(int v=0;v<V;v++)
	{
		if(match[v]<0)
		{
			memset(used,0,sizeof(used));
			if(dfs(v))res++;
		}
	}
	return res;
}

int main()
{
	int E,X,Y;cin>>X>>Y>>E;
	V=X+Y;
	int u,v;
	for(int i=0;i<E;i++)
	{
		cin>>u>>v;
		v+=X;
		add_edge(u,v);
	}
	cout<<bipartite_matching()<<endl;
	return 0;
}

Measured memory_bytes: 3260
# coding: utf-8

N, M, C = map(int, input().split())
B = [int(b) for b in input().split()]
Ai = [[int(aij) for aij in input().split()] for _ in range(N)]

counter = 0
for ai in Ai:
    if sum(a * b for a, b in zip(ai, B)) + C > 0:
        counter += 1

print(counter)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})
 
#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
 
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
 
    int N; ll C;
    cin >> N >> C;
 
    vll x(N); vi v(N);
    vll pref(N + 1);
    for (int i = 0; i < N; i++) {
        cin >> x[i] >> v[i];
        pref[i + 1] = pref[i] + v[i];
    }
 
    vll rtL(N + 1), rtR(N + 1);
    for (int i = 0; i < N; i++) {
        rtL[i] = pref[i+1] - 2 * x[i];
        rtR[i] = pref[N] - pref[i] - 2 * (C - x[i]);
    }
 
    vll left(N + 1), right(N + 1);
    for (int i = 0; i < N; i++) {
        left[i] = max(rtL[i], i ? left[i-1] : 0);
    }
    for (int i = N - 1; i >= 0; i--) {
        right[i] = max(rtR[i], right[i+1]);
    }
 
    ll ans = 0;
    for (int i = 0; i < N; i++) {
        ans = max(ans, rtL[i] + x[i] + right[i+1]);
        ans = max(ans, rtR[i] + C - x[i] + (i ? left[i-1] : 0));
    }
    cout << ans << endl;
 
    return 0;
}

Measured memory_bytes: 5376
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
using namespace std;
int main()
{
  int n;
  cin>>n;
  if(n==1) cout<<"Hello World"<<endl;
  else
  {
    int a,b;
    cin>>a>>b;
    cout<<a+b<<endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
using namespace std;
int32_t main(){
    int m,n;
    cin>>m>>n;
    char a[m+1][n+1];
    for(int i=1;i<=m;i++){
        for(int j=1;j<=n;j++){
            cin>>a[i][j];
        }
    }
    int dp[m+1][n+1];
    memset(dp,0,sizeof dp);
    for(int i=1;i<=n;i++){
        if(a[1][i]=='#'){
            break;
        }
        dp[1][i]=1;
    }
    for(int i=1;i<=m;i++){
        if(a[i][1]=='#'){
            break;
        }
        dp[i][1]=1;
    }
    for(int i=2;i<=m;i++){
        for(int j=2;j<=n;j++){
            if(a[i][j]=='#'){
                continue;
            }
            dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
        }
    }
    cout<<dp[m][n]<<endl;
	return 0;
}


Measured memory_bytes: 9088