akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 0
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	string A[] = { "dream","dreamer","erase","eraser" };
	rep(i, 0, 4)reverse(A[i].begin(), A[i].end());
	string S; cin >> S;
	reverse(S.begin(), S.end());
	rep(i, 0, S.size()) {
		bool flag = false;
		int cnt = 0;
		rep(j, 0, 4) {
			rep(k, 0, A[j].size()) {
				if (i + k >= S.size() || A[j][k] != S[i + k]) {
					cnt++;
					break;
				}
			}
			dump(cnt)dump(j);
			if (cnt != j + 1) {
				i += A[j].size() - 1;
				flag = true;
				break;
			}
		}
		if (flag == false) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 512
// Problem : F - Range Set Query
// Contest : AtCoder - AtCoder Beginner Contest 174
// URL : https://atcoder.jp/contests/abc174/tasks/abc174_f
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define int long long
#define db double
#define mod 1000000007
#define pb push_back
#define pp pair<int,int>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repe(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=b;i>=a;i--)
#define maxn 500005
#define ss second
#define ff first
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
int inv(int a, int b){
 return 1<a ? b - inv(b%a,a)*b/a : 1;
}
int n,q;
int arr[maxn];
int fen[maxn];
void update(int idx,int val)
{
	while(idx <= n)
	{
		fen[idx]+=val;
		idx+=(idx&-idx);
	}
}
int query(int idx)
{
	int tmp=0;
	while(idx > 0)
	{
		tmp+=fen[idx];
		idx-=(idx&-idx);
	}
	return tmp;
}
void solve()
{
	cin >> n >> q;
	rep(i,0,n)
	cin >> arr[i+1];
	vector<pair<pp,int> > v;
	//build(1,0,n-1);
	int i=0,m=q;
	while(q--)
	{
		int l,r;
		cin >> l >> r;
		v.pb({{l,r},i++});
	}
	sort(all(v));
	reverse(all(v));
	int j=0,mp[maxn]={0},ans[m];
	repr(i,1,n)
	{
		int col=arr[i];
		if(mp[col])
			update(mp[col],-1);
		update(i,1);
		mp[col]=i;
		while(j<v.size() and v[j].ff.ff == i)
		{
			int tmp = -query(i-1)+query(v[j].ff.ss);
			ans[v[j].ss]=tmp;
			j++;
		}
	}
	rep(i,0,m)
	cout << ans[i] <<"\n";
}
signed main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin >> t;
    while(t--)
    solve();
    return 0;
}


Measured memory_bytes: 31292
#include<bits/stdc++.h>
using namespace std;
typedef long long ll ;
const ll MOD=1e9 + 7 ;
const ll dx[4] = { -1,1,0,0 };
const ll dy[4] = { 0,0,-1,1 };
const ll MAX =  3e5 ;
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
long long gcd(long long  a, long long  b) { return (b == 0 ? a : gcd(b, a % b)); }
ll n , m  , k , Q , l , x , y, ans; string s;

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
   // freopen("test.in","r",stdin);
    ll h , w;
    cin>>n>>h>>w;
    if( h > n || w > n)
        return cout<<0 , 0;
    cout<<(n - h + 1)*(n - w + 1);


    return 0;
}


Measured memory_bytes: 256
import math
from collections import defaultdict


N = int(input())
n = N
#素因数分解
factor = defaultdict(lambda: 0)
tmp = int(math.sqrt(N))+1
for num in range(2,tmp):
    while N % num == 0:
        N //= num
        factor[num] += 1
if not factor and n!=1:
    factor[n] += 1
elif N != 1:
    factor[N] += 1



ans = 0
for num in factor:
    i = 1
    while True:
        factor[num] -= i
        if factor[num]<0:
            break
        ans += 1
        i+=1

print(ans)


Measured memory_bytes: 9484
import java.util.*;class Main{public static void main(String[]z){Scanner s=new Scanner(System.in);for(int n,m,r;(n=s.nextInt())>0;System.out.println(r)){List<int[]>x=new ArrayList<int[]>();for(r=0,m=s.nextInt();m-->0;)x.add(new int[]{s.nextInt(),s.nextInt(),s.nextInt()});Collections.sort(x,new Comparator<int[]>(){public int compare(int[]a,int[]b){return a[2]-b[2];}});U u=new U(n);for(int[]e:x)if(!u.s(e[0],e[1])){u.u(e[0],e[1]);r+=e[2];}}}static class U{int[] p,r;U(int n){p=new int[n];r=new int[n];for(int i=0;i<n;++i)p[i]=i;}int f(int x){return(p[x]==x)?x:(p[x]=f(p[x]));}void u(int x,int y){x=f(x);y=f(y);if(x==y)return;if(r[x]<r[y]){p[x]=y;}else{p[y]=x;if(r[x]==r[y])++r[x];}}boolean s(int x,int y){return f(x)==f(y);}}}

Measured memory_bytes: 12000
import java.util.List;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.stream.Collectors;

class Node {
    Integer id;
    Integer parentId;
    Integer depth;
    Integer type;
    List<Integer> childrenIds;
}


class Main {
    static Map<Integer, Node> nodes = new HashMap<>();

    static final Map<Integer, String> types = new HashMap<Integer, String>() {
      {
          put(1, "root");
          put(2, "internal node");
          put(3, "leaf");
      }
    };

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

        int n = sc.nextInt();
        for (int i = 0; i < n; i++) {
            Integer id = sc.nextInt();
            int m = sc.nextInt();

            Node node = nodes.get(id);
            if (node == null) {
                node = new Node();
                node.id = id;
                node.type = 1;
                node.depth = 0;
                node.parentId = -1;
                nodes.put(id, node);
            } else if (m != 0) {
                node.type = 2;
            } else {
                node.type = 3;
            }

            Node parentNode = nodes.get(node.parentId);
            if (parentNode != null) {
                node.depth = parentNode.depth + 1;
            }

            List<Integer> childrenIds = new ArrayList<>();

            for (int j = 0; j < m; j++) {
                Integer childrenId = sc.nextInt();
                Node childrenNode = nodes.get(childrenId);
                if (childrenNode == null) {
                    childrenNode = new Node();
                    childrenNode.id = childrenId;
                    nodes.put(childrenId, childrenNode);
                }
                childrenNode.parentId = node.id;
                childrenNode.depth = new Integer(node.depth.intValue() + 1);
                if (childrenNode.childrenIds == null || childrenNode.childrenIds.isEmpty()) {
                    childrenNode.type = 3;
                } else {
                    childrenNode.type = 2;
                }
                childrenIds.add(childrenId);
            }
            node.childrenIds = childrenIds;
        }

        for (Integer i = 0; i < n; i++) {
            Node node = nodes.get(i);
            System.out.printf("node %d: parent = %d, depth = %d, %s, [%s]\n",
                    node.id,
                    node.parentId,
                    node.depth,
                    types.get(node.type),
                    node.childrenIds.stream().map(elm -> elm.toString()).collect(Collectors.joining(", ")));
        }
    }
}



Measured memory_bytes: 195228
n,m=[int(x) for x in input().split()]
path=[]
d=[[float("inf") for _ in [0]*n] for _2 in [0]*n]
for _ in [0]*m:
    a,b,c=[int(x) for x in input().split()]
    path.append((a-1,b-1,c))
    d[a-1][b-1]=d[b-1][a-1]=c
from itertools import product
for k,i,j in product(range(n),range(n),range(n)):
    if d[i][j]>d[i][k]+d[k][j]:
        d[i][j]=d[i][k]+d[k][j]
ans=0
for a,b,c in path:
    if d[a][b]!=c:
        ans+=1
print(ans)

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

using namespace std;

string s;

void solve() {
    int max_z = 0;
    int min_a = 0;
    for (int i = 0; i < int(s.size()); ++i) {
        if (s[i] == 'A') {
            min_a = i;
            break;
        }
    }
    for (int i = int(s.size()); i > 0; i--) {
        if (s[i] == 'Z') {
            max_z = i;
            break;
        }
    }
    printf("%d", max_z - min_a + 1);
}

int main() {
    cin >> s;
    solve();
    return 0;
}

Measured memory_bytes: 3884
#!/usr/bin/env python
"""AtCoder Beginner Contest 169: B - 
https://atcoder.jp/contests/abc169/tasks/abc169_b
"""

__author__ = 'bugttle <bugttle@gmail.com>'


def calc(As):
    MAX = 10 ** 18
    ans = 1
    for n in As:
        if n == 0:
            return 0
        ans *= n
        if MAX < ans:
            return -1
    return ans

def main():
    N = int(input())
    As = list(map(int, input().split()))
            
    if As.count(0) != 0:
        print(0)
    else:
        print(calc(As))

if __name__ == '__main__':
    main()


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

using namespace std;

int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    long a=-1,b=-1;
    for(long i=0;i<s.length()-2;i++){
        if(s[i]==s[i+1] || s[i]==s[i+2] || s[i+1]==s[i+2]){
            a=i+1;
            b=i+3;
            break;
        }
    }
    if(s.length()==2 && s[0]==s[1]){
        a=1;
        b=2;
    }
    cout<<a<<' '<<b;
    return 0;
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;

//wierd debugging stuff
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << "\n" ; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
//end of weird debugging stuff
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()
 
#define F_OR(i, a, b, s) for (int i = (a); ((s) > 0 ? i < (b) : i > (b)); i += (s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define fo(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define foe(i,x) for(auto& i: x)
#define ar array
#define pb push_back
#define vt vector
#define F first
#define S second

template<class T> bool umin(T& a,const T& b){return b<a?a=b,1:0;}
template<class T> bool umax(T& a,const T& b){return b>a?a=b,1:0;}

template<class A> void read(vt<A>& v);
template<class A, size_t S> void read(ar<A, S>& a);
template<class T> void read(T& x) {cin>>x;}
void read(double& d) {string t;read(t);	d=stod(t);}
void read(long double& d) {	string t;read(t);d=stold(t);}
template<class H, class... T> void read(H& h, T&... t) {read(h);read(t...);}
template<class A> void read(vt<A>& x) {	foe(a, x)read(a);}
int nxt(){int a;read(a);return a;}   // iota(all(v),0); genrate(all(v),nxt);

// no change 
const ll MOD = 1e9+7;  
int mx = 1e6+1;
int n,k;
void Titan(){
	read(n,k);
	fo(n){
		string s;
		cin >> s;
		cout << s << endl << s << endl;
	}
	
	
	
	
}

	

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int T = 1;
	//cin >> T;		//cmt if one test case
    fo(T){
		//cout << "Case #" << i+1 << ": " ;
		Titan();
	}
}
/*///////////////////////////////////////////////////////////
Important Notes : 
* check long long 
* check base cases
* do not loose Hope
* if case fails on 2nd test case maybe some cases are missing check them
* do not sit idle
* try to do it using pen/paper.
*/


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

const int N = 105;
const int M = 1e5 + 5;

long long dp[N][M];
int n, w;
int a[N], b[N];

void read() {
  scanf("%d %d", &n, &w);
  for (int i = 0 ; i < n ; i++) {
    scanf("%d %d", &a[i], &b[i]);
  }
}

long long solve(int pos, int sisa) {
  if (sisa < 0) return -4e18;
  if (pos == n) return 0;

  long long &ret = dp[pos][sisa];
  if (ret != -1) return ret;

  ret = max(solve(pos+1, sisa), b[pos] + solve(pos+1, sisa - a[pos]));
  return ret;
}

long long work() {
  memset(dp, -1, sizeof dp);
  return solve(0, w);
}

int main() {
  read();
  cout << work() << endl;
  return 0;
}

Measured memory_bytes: 82304
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>  // accumulate
#include <string>
#include <utility>  // pair
#include <vector>
#include <queue>

using namespace std;
using ll = long long;

ll N, M;
vector<vector<ll>> G;
map<ll, ll> memo;

ll search(ll from) {
    if (memo.find(from) != memo.end()) {
        return memo[from];
    }
    ll m = 0;
    for (const auto to : G[from]) {
        m = max(m, search(to) + 1);
    }
    return memo[from] = m;
}

int main() {
    cin >> N >> M;
    G.resize(N + 1);
    for (ll i = 0; i < M; i++) {
        ll x, y; cin >> x >> y;
        G[x].emplace_back(y);
    }
    ll m = 0;
    for (ll i = 1; i <= N; i++) {
        m = max(m, search(i));
    }
    cout << m << endl;
    return 0;
}

Measured memory_bytes: 15360
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>

using namespace std;

#define ll long long

ll fact(ll n)
{
    if (n <= 1)
    {
        return 1;
    }
    return n * fact(n - 1);
}

void solve()
{
    ll N;
    cin >> N;
    vector<ll> x(N);
    vector<ll> y(N);
    map<pair<ll, ll>, double> memo;

    vector<int> v;
    for (ll i = 0; i < N; i++)
    {
        cin >> x.at(i) >> y.at(i);
        v.push_back(i);
    }

    double count = 0;
    do
    {
        for (ll i = 1; i < N; i++)
        {
            auto pair = make_pair(v.at(i), v.at(i - 1));
            auto pair2 = make_pair(v.at(i - 1), v.at(i));

            if (memo[pair] == (ll)NULL)
            {
                memo[pair2] = memo[pair] = sqrt(pow(x.at(pair.first) - x.at(pair.second), 2) + pow(y.at(pair.first) - y.at(pair.second), 2));
                count += memo[pair];
            }
            else
            {
                count += memo[pair];
            }
        }
    } while (next_permutation(v.begin(), v.end()));
    cout << fixed << setprecision(6) << count / fact(N) << endl;

    return;
}

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


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

int main() {
  int N;
  cin >> N;
  
  int first = 0;
  int second = 0;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    
    if (A.at(i) > first) {
      second = first;
      first = A.at(i);
    } else if (A.at(i) > second) {
      second = A.at(i);
    }
  }
  
  for (int i = 0; i < N; i++) {
    if (A.at(i) == first) {
      cout << second << endl;
    } else {
      cout << first << endl;
    }
  }
  
  return 0;
}

Measured memory_bytes: 2432
def main():
    N = int(input())
    S = [int(input()) for i in range(N)]

    ans = sum(S)
    if str(ans)[-1] == '0':
        s = sorted(S)
        for i in s:
            if str(i)[-1] != '0':
                ans -= i
                break
        else:
            ans = 0

    print(ans)

main()


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

int main(){
    string S;
    cin >> S;
    int N;
    N = S.size();
    
    while(N > 0){
        if(S[N-1] == 'm' && S[N-2] == 'a'&& S[N-3] == 'e'&& S[N-4] == 'r'&& S[N-5] == 'd') N -= 5;
        else if(S[N-1] == 'r' && S[N-2] == 'e' && S[N-3] == 'm' && S[N-4] == 'a'&& S[N-5] == 'e'&& S[N-6] == 'r'&& S[N-7] == 'd') N -= 7;
        else if(S[N-1] == 'r' && S[N-2] == 'e' && S[N-3] == 's' && S[N-4] == 'a'&& S[N-5] == 'r'&& S[N-6] == 'e') N -= 6;
        else if(S[N-1] == 'e' && S[N-2] == 's' && S[N-3] == 'a' && S[N-4] == 'r'&& S[N-5] == 'e') N -= 5;
        else break;
    }
    if(N == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n;
    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;

int FindSumOfDigits(int n){
  int sum = 0;
  while(n > 0){
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

int main(){
  int n, a, b;
  cin >> n >> a >> b;
  int total = 0;
  for(int i = 1; i <= n; i++){
    int sum = FindSumOfDigits(i);
    if(sum >= a && sum <= b){
      total += i;
    }
  }
  cout << total << endl;
}

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

int main(){
    int n, k;
    cin >> n >> k;
    int ans = 0;
    int x;
    for (int i = 0; i < n; i++){
        cin >> x;
        if (x >= k) ans++;
    }
    cout << ans << endl;
}

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

#define sz(v) (int)v.size()
using ll = long long;

const int N = 1e5+10;

int n, M;
vector<int> g[N];

ll down[N];

void dfs(int u, int f) {
  down[u] = 1;
  for(int v : g[u]) if(v != f) {
    dfs(v, u);
    down[u] *= (down[v] + 1);
    down[u] %= M;
  }
}

int par[N];
ll pre[N], suf[N], up[N];

void dfs1(int u, int f) {
  par[u] = f;
  ll res = 1;
  for(int i = 0; i < sz(g[u]); i++) {
    if(g[u][i] == f) continue;
    pre[g[u][i]] = res;

    res *= (down[g[u][i]] + 1);
    res %= M;
  }
  res = 1;
  for(int i = sz(g[u]) - 1; i >= 0; i--) {
    if(g[u][i] == f) continue;
    suf[g[u][i]] = res;

    res *= (down[g[u][i]] + 1);
    res %= M;
  }
  for(int v : g[u]) if(v != f) dfs1(v, u);
}

void dfs2(int u, int f) {
  if(f == 0) up[u] = 1;
  else up[u] = (up[f] * (pre[u] * suf[u] % M) + 1) % M;
  for(int v : g[u]) if(v != f) dfs2(v, u);
}

int main() {
  scanf("%d %d", &n, &M);
  for(int i = 1; i < n; i++) {
    int u, v; scanf("%d %d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  down[0] = down[n + 1] = 1;
  dfs(1, 0);
  dfs1(1, 0);
  dfs2(1, 0);

  for(int i = 1; i <= n; i++) printf("%lld\n", down[i] * up[i] % M);
  return 0;
}

Measured memory_bytes: 18268
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int a,b;
    cin >> a >> b;
    cout << (a-1) * (b-1) << endl;
}

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

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<random>
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7, INF = 1e18;

lint N, K, H[302];
lint dp[303][301]; //dp[見た地点][使ったKの数] = 必要な手数の最小値

int main() {
	cin >> N >> K;
	H[0] = 0;
	H[N + 1] = 0;
	REP(i, N) {
		cin >> H[i + 1];
	}
	REP(i, N + 2) {
		REP(j, K + 1) {
			dp[i][j] = INF;
		}
	}
	dp[0][0] = 0;
	REP(i, N + 2) {
		REP(j, K + 1) {
			//使うKの数
			REP(k, K - j + 1) {
				if (i + k + 1 > N + 1) continue;
				if (H[i] > H[i + k + 1]) chmin(dp[i + k + 1][j + k], dp[i][j]);
				else chmin(dp[i + k + 1][j + k], dp[i][j] + (H[i + k + 1] - H[i]));
			}
		}
	}
	lint ans = INF;
	REP(i, K + 1) {
		chmin(ans, dp[N + 1][i]);
	}
	cout << ans << endl;
}


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

namespace CS.Solve1
{
    class Program
    {
        static void Main(string[] args)
        {
            var givenN = int.Parse(Console.ReadLine());
            var givenA = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var result = Calc.Result(givenA);
            
            Console.WriteLine(result);
        }
    }

    public class Calc
    {
        public static int Result(int[] givenA)
        {
            var count = 0;
            var tmp = givenA.Where(x => x % 2 == 0).ToArray();
            while (tmp.Count() > 0)
            {
                count += tmp.Count();
                tmp = tmp.Select(x => x / 2).Where(x => x % 2 == 0).ToArray();
            }
            return count;
        }
    }
}


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

int main() {
	int H,A;
  	cin>> H >> A;
  	
  	if(H%A==0){
  		cout<<H/A<<endl;
    }  
 	else{
     	cout<<H/A+1<<endl; 
    }
      
      
}

Measured memory_bytes: 256
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;


typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define PB push_back
#define ITR ::iterator


#define MOD 1000000009LL
#define EPS 1e-8


int z = 35;

int main(){
	vector<string> v(40, string(40, 'Y'));
	for(int i = 0; i < 40; ++i){
		v[i][i] = 'N';
	}
	for(int i = 0; i < z; ++i)
	for(int j = 0; j < z; ++j){
		v[i][j] = 'N';
	}
	cout << "40\n";
	for(int i = 0; i < 40; ++i){
		cout << v[i] << '\n';
	}
}

Measured memory_bytes: 1148
program main
implicit None
	integer(8)::n,m,i,p=0,q=0
	integer(8),allocatable::a(:),b(:)
	
	read*,n,m
	allocate(a(n),b(n))
	
	do i =1,n
		read*,a(i),b(i)
	enddo
	
	call h2(a,b,n)
	
	do i =1,n
		if(m-q <= b(i))then
			p = p + a(i)*(m-q)
			exit
		endif
		q = q+b(i)
		p = p+a(i)*b(i)
	enddo
	
	print"(i0)",p
end program main

subroutine h2(a,b,n)
implicit None
	integer(8)::a(n),b(n),x,y
	integer(8)::n,i,ie,i0,i1,i2
	
	do i = n/2,1,-1
		x = a(i);y = b(i);ie = n + 1; i0 = i; i1 = i0 * 2
		do while(i1 < ie)
			i2 = i1 + 1
			if(i2 < ie .and. a(i1) < a(i2)) i1 = i2
			if(a(i1) > x)then
				a(i0) = a(i1);a(i1) = x
				b(i0) = b(i1);b(i1) = y
				else
				exit
			endif
			i0 = i1;i1 = i0 *2
		enddo
	enddo
	do ie = n,2,-1
		x = a(ie);y = b(ie)
		a(ie) = a(1);b(ie) = b(1)
		a(1) = x;b(1) = y
		i0 =1;i1 =2
		do while(i1 <ie)
			i2 = i1 +1
			if(i2 < ie .and. a(i1) < a(i2)) i1 = i2
			if(a(i1) > x)then
				a(i0) = a(i1);a(i1) = x
				b(i0) = b(i1);b(i1) = y
				else
				exit
			endif
			i0 = i1;i1 = i0 *2
		enddo
	enddo
end subroutine h2

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
 
typedef long long ll;
typedef long double ld;
 
#define REP(i,a,n) for(int (i)=(a); (i)<(int)(n); (i)++)
#define rep(i,n) REP(i,0,n)
#define vec vector 

const ll large_P = 1e9 + 7;


int main(){
  char c;
  cin >> c;
  
  char res = c + ('b' - 'a');
  cout << res;
}

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

using ll = long long;
#define ld long double
#define ull unsigned long long int

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  // (i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define ret return

typedef pair<int, int>    pii;
typedef vector<int>       vi;
typedef vector<vi>        vii;
typedef vector<long long> vl;

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    // cout << fixed << setprecision(5);

    // 入力
    int n;
    cin >> n;
    char s[n];
    int  cntY = 0;
    rep(i, n) {
        cin >> s[i];
        if (s[i] == 'Y') {
            cntY = 1;
        }
    }

    // 処理
    // 出力
    cout << (cntY == 1 ? "Four" : "Three") << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.util.function.*;
import java.math.*;
public class Main {
    public static void main(String[] args){
		Scanner s = new Scanner(System.in);
		int L = Integer.valueOf(s.next());
		int R = Integer.valueOf(s.next());
		int d = Integer.valueOf(s.next());
		
		int ret = 0;
		for(int i = L; i <=R; i++) {
			if(i % d == 0) {
				ret++;
			}
		}
		
		System.out.println(ret);
	}
}

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

typedef long long int ll;
typedef long double ld;

#define nn "\n"


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

    int k,a,b,i,cnt=0,ans=0,flag=0;
    cin>>k;
    cin>>a>>b;
    for(i=a;i<=b;i++){
        if(i%k==0){
            flag=1;
            break;
        }
    }
    if(flag){
        cout<<"OK"<<nn;
    }
    else{
        cout<<"NG"<<nn;
    }


    //cout<<"Case "<<cn<<": "<<"good"<<endl;
    return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define MOD 1000000007
ll fact[200005];
#define eps 1e-9
#define INF 1e17
#define N 200005
inline ll mul(ll a,ll b){
  a=(a+MOD)%MOD;
  b=(b+MOD)%MOD;
  ll c=a*b;
  c=(c+MOD)%MOD;
  return c;
}
ll power(ll a,ll b,ll c){
  ll ans=1;
  while(b){
    if(b&1){
      ans=mul(ans,a);
    }
    a=mul(a,a);
    b=b/2;
  }
  return ans;
 }
ll min(ll a,ll b){return a<b?a:b;}
ll max(ll a,ll b){return a>b?a:b;}
int main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        string s; cin>>s;
        if(s=="ABC")cout<<"ARC";
        else cout<<"ABC";
        return 0;
}


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

int main(){
  long long n,k,q;
  cin >> n >> k >> q;
  vector<long long> point(n,k-q);
  for (int i = 0;i < q;i++){
    long long a;
    cin >> a;
    a--;
    point[a]++;
  }

  for (int i = 0;i < n;i++){
    if (point[i] <= 0) cout << "No" << endl;
    else cout << "Yes" << endl;
  }
}

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

class Main{
	public static void main(String[] args){
		Scanner scanner = new Scanner(System.in);
		double a_1 = scanner.nextDouble();
		double b_1 = scanner.nextDouble();
		double a_2 = scanner.nextDouble();
		double b_2 = scanner.nextDouble();

		double x = (a_1 - a_2) *  (a_1 - a_2) + (b_1 - b_2) *  (b_1 - b_2);

		System.out.println(String.format("%.5f",Math.sqrt(x)));
	}
}

Measured memory_bytes: 28288
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
typedef long long int ll;
using namespace std;

//_____________________________________________________________
#define MAX_NODE 1000000

struct tree{
  ll number;
  std::vector<int> c;
  std::vector<int> child;
  ll point=0;
};

std::vector<tree> T(MAX_NODE+1);
std::vector<int> check_init(MAX_NODE+1,0);

void tree_(int num){
  if(check_init[num]==0){
    check_init[num]=1;
    for(int i=0;i<T[num].c.size();i++) {
      if(check_init[T[num].c[i]]==0)T[num].child.push_back(T[num].c[i]);
      tree_(T[num].c[i]);
    }
  }
}
std::vector<ll> ans;
void tree_init(ll N){
  for(int i=1;i<=MAX_NODE;i++) {
    T[i].number=i;
    T[i].point=0;
  }
  for(int i=0;i<N+1;i++) ans.push_back(0);
  tree_(1);
}

void check(ll s, ll P){
  P+=T[s].point;
  ans[s]=P;
  for(int i=0;i<T[s].child.size();i++){
    check(T[s].child[i], P);
  }
}
int main(int argc, char const *argv[]) {
  ll N, Q, a, b, p, x;
  std::cin >> N >> Q;
  for(int i=0;i<N-1;i++){
    std::cin >> a >> b;
    T[a].c.push_back(b);
    T[b].c.push_back(a);
  }
  tree_init(N);
  for(int i=0;i<Q;i++){
    std::cin >> p >> x;
    T[p].point+=x;
  }
  check(1, 0);
  for(int i=1;i<=N;i++) std::cout << ans[i] << (i==N?"\n":" ");
  return 0;
}


Measured memory_bytes: 89076
using System;
using System.Collections;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Threading.Tasks;

class Program
{
	//Main
	static void Main(string[] args)
	{
		//読み込む
		int N = int.Parse(Console.ReadLine());
		long[] An = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

		long mod = 1000000007;

		//累積和を計算
		long[] accum = new long[N];
		accum[0] = An[0] % mod;

		for(int i=1; i<N; i++){
			accum[i] = accum[i-1] + (An[i]%mod);
			accum[i] %= mod;
		}

		long ans = 0;
		//順に計算
		for(int i=0; i<N; i++){
			long right = (accum[N-1] - accum[i]) % mod;
			long prod = (An[i]%mod) * right;
			ans += (prod%mod);
			ans %= mod;
		}

		if(ans < 0){
			ans += mod;
		}

		Console.WriteLine(ans);
	}
}



Measured memory_bytes: 45232
// AOJ 2317 Class Representative Witch
// 2018.4.11 bal4u

#include <stdio.h>
#include <stdlib.h>

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0, c = getchar_unlocked();
	do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
	return n;
}

int N, M;
int s[100002], t[100002];
int p[100002], a[100002];
int even[100002], odd[100002];

// 見つからなければ、小さい要素のうちの最大を返す
int bisearch_LE(int x)
{
	int m, l = 0, r = M;

    while (l < r) {
        m = (l+r) >> 1;
//		if (p[m] == x) return m;
        if (p[m] < x) l = m + 1; else r = m;
    }
	return l-1;
}

// 見つからなければ、大きい要素のうちの最小を返す
int bisearch_GE(int x)
{
	int m, l = 0, r = M;

    while (l < r) {
        m = (l+r) >> 1;
        if (p[m] < x) l = m + 1; else r = m;
    }
	return l;
}

int cmp(int *a, int *b) { return *a - *b; }

int main()
{
	int i, j, k, mi, ma, f;
	long long ans;

	N = in(), M = in()+1;
	for (i = 0; i < N; i++) s[i] = in(), t[i] = in();
	p[0] = 0;
	for (i = 1; i < M; i++) p[i] = in();
	qsort(p, M, sizeof(int), cmp);
	p[M++] = 1000000002;
	for (i = 1; i < M; i++) a[i] = p[i]-p[i-1];

	even[0] = 0;
	for (i = 1; i < M; i++) {
		if (i & 1) odd [i] = odd [i-1]+a[i], even[i] = even[i-1];
		else       even[i] = even[i-1]+a[i], odd [i] = odd [i-1];
	}

	ans = 0;
	for (i = 0; i < N; i++) {
		if (s[i] < t[i]) f = 0, mi = s[i], ma = t[i];
		else             f = 1, ma = s[i], mi = t[i];
		if (f) {
			j = bisearch_LE(ma), k = bisearch_GE(mi);
			if (p[k] >= ma) ans += ma-mi;
			else {
				ans += ma-p[j];
				if ((k&1) ^ (j&1)) ans += p[k++]-mi;
				if (j&1) ans += even[j]-even[k];
				else     ans += odd [j]-odd [k];
			}
		} else {
			j = bisearch_GE(mi), k = bisearch_LE(ma);
			if (p[j] >= ma) ans += ma-mi;
			else {
				ans += p[j]-mi;
				if ((k&1) ^ (j&1)) ans += ma-p[k];
				if (j&1) ans += odd [k]-odd [j+1];
				else     ans += even[k]-even[j+1];
			}
		}
	}
	printf("%lld\n", ans);
	return 0;
}



Measured memory_bytes: 4188
import math
 
def is_prime(n):
    for i in range(2, int(math.sqrt(n))+1):
        if n % i == 0:
            return False
    return True
 
def main():
    X = int(input())
    while True:
        result = is_prime(X)
        if result:
            print(X)
            exit()
        X +=1
 
if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<stdio.h>
int main()
{
	int n;
	scanf("%d", &n);
	int i;
	int a[200005];
	for (i = 0; i < n; i++)
		scanf("%d", &a[i]);
	int max1, max2;
	max1 = 0;
	for (i = 0; i < n; i++)
		if (a[max1] < a[i])
			max1 = i;
	if (max1 == 0)max2 = 1;
	else max2 = 0;
	for (i = 0; i < n; i++)
		if (i != max1)
			if (a[max2] < a[i])
				max2 = i;
	for (i = 0; i < n; i++)
	{
		if (i != max1)
			printf("%d\n", a[max1]);
		else
			printf("%d\n", a[max2]);
	}
	return 0;
}

Measured memory_bytes: 2304
#include <iostream>
#include <queue>

using namespace std;

int main(){
    int A, B;
    cin >> A >> B;
    priority_queue<int> que;
    que.push(A);
    que.push(B);
    
    int ans = 0;
    for(int i = 0; i < 2; i++){
        int temp = que.top();
        que.pop();
        ans += temp--;
        que.push(temp);
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define up_b upper_bound
#define low_b lower_bound
#define nl '\n'

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

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

const int N=2e5+11;
const int M=3e6+11;
const int W=1e3+11;
const int inf=1e9;
const ll INF=1e18;
const ll mod=1e9+7;
const ld EPS=1e-9;

int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0),cout.tie(0);
  int a,b;
  cin>>a>>b;
  if(a>b)cout<<"safe";
  else cout<<"unsafe";
}


Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath> //abs();
using namespace std;

int main(void)
{
    long long int a,b,c,d,i,j,k,n,x[10];
    string s1,s2,s3;
    char C[5];

    cin >> s1 >> s2 >> s3;

    if(s1.at(s1.size()-1)==s2.at(0) && s2.at(s2.size()-1)==s3.at(0)) cout << "YES"; 
    else cout << "NO";
    return 0;
}

Measured memory_bytes: 384
eval"N,*A="+`dd`.split*?,
b=A.pop N
c=(b+b)[A.map{|x|(b.bsearch_index{_1>x}||N)-A.bsearch_index{_1>=x}}.max,N]
puts A.any?{_1==c[~-$.+=1]}?:No:[:Yes,c]

Measured memory_bytes: 89412
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
//#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define MOD 2011
int H,W;
int LEFT;
string table[20];

int parse(int top,int bottom);
int expr(int base,int top,int bottom);
int find_base(int top,int bottom);
int term(int base,int top,int bottom);
int factor(int base,int top,int bottom);
int powexpr(int base,int top,int bottom);
int primary(int base,int top,int bottom);

int pow_mod(int A, int N)
{
	if(N == 0){

		return 1;

	}else if(N%2 == 1){

		return (A*pow_mod(A,N-1))%MOD;

	}else{
		int tmp = pow_mod(A,N/2);
		return (tmp*tmp)%MOD;
	}
}

int primary(int base,int top,int bottom){

	if(table[base][LEFT] == '(' && table[base][LEFT+1] == '.'){

		LEFT += 2;
		int ret = expr(base,top,bottom);
		LEFT += 2;
		return ret;

	}else{
		int ret = table[base][LEFT]-'0';
		LEFT += 1;
		return ret;
	}
}

bool is_digit(char ch){
	return ch >= '0' && ch <= '9';
}

int powexpr(int base,int top,int bottom){

	int ret = primary(base,top,bottom),tmp;

	if(base-1 >= top && LEFT < W && is_digit(table[base-1][LEFT])){

		tmp = table[base-1][LEFT]-'0';
		LEFT += 1;
		return pow_mod(ret,tmp);

	}else{
		return ret;
	}
}

int factor(int base,int top,int bottom){

	if(table[base][LEFT] == '-'){
		if(table[base][LEFT+1] == '.'){

			LEFT += 2;
			int ret = factor(base,top,bottom);
			return (MOD-ret)%MOD;

		}else{

			int pre = LEFT;
			int tmp = parse(top,base);
			LEFT = pre;
			int tmp2 = parse(base+1,bottom);
			LEFT = pre;
			while(LEFT < W && table[base][LEFT] == '-'){
				LEFT += 1;
			}
			return (tmp*pow_mod(tmp2,MOD-2))%MOD;
		}

	}else{
		return powexpr(base,top,bottom);
	}
}

int term(int base,int top,int bottom){

	int ret = factor(base,top,bottom),tmp;

	while(LEFT+2 < W && table[base][LEFT] == '.' && table[base][LEFT+1] == '*' && table[base][LEFT+2] == '.'){

		LEFT += 3;
		tmp = factor(base,top,bottom);

		ret *= tmp;
		ret %= MOD;
	}
	return ret;
}

bool is_op(char ch){

	return ch == '+' || ch == '-';
}


int expr(int base,int top,int bottom){

	int ret = term(base,top,bottom),tmp;
	char op;

	while(LEFT+2 < W && table[base][LEFT] == '.' && is_op(table[base][LEFT+1]) && table[base][LEFT+2] == '.'){
		op = table[base][LEFT+1];
		LEFT += 3;
		tmp = term(base,top,bottom);

		if(op == '+'){
			ret += tmp;
			ret %= MOD;
		}else{
			ret = (ret-tmp+MOD)%MOD;
		}
	}
	return ret;
}

int find_base(int top,int bottom){

	//左端から順に、縦に見ていく
	for(; LEFT < W; LEFT++){
		for(int row = top; row < bottom; row++){
			if(table[row][LEFT] != '.'){
					return row;
			}
		}
	}
	return -1;
}

int parse(int top,int bottom){

	return expr(find_base(top,bottom),top,bottom);
}

void func(){

	for(int row = 0; row < H; row++){
		cin >> table[row];
	}

	for(W = 0; table[0][W] != '\0'; W++);

	LEFT = 0;
	printf("%d\n",parse(0,H));
}

int main(){

	while(true){
		scanf("%d",&H);
		if(H == 0)break;

		func();
	}

	return 0;
}



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

    bool ans = false;
    rep(i, 26){
        if((n-7*i)%4 == 0 && (n-7*i) >= 0){
            ans = true;
            break;
        }
    }
    if(ans){
        cout << "Yes";
    }
    else{
        cout << "No";
    }

    return 0;
}

Measured memory_bytes: 256
// ------------------------------------
// Date:2018/ 3/27
// Problem:D - すぬけ君の塗り絵 i.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e9 + 1;

ll H, W, N;
map< pair< int, int >, ll > cnt;

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

  cin >> H >> W >> N;
  REP(i, N) {
    CIN(a, b);
    a--; b--;
    FOR(hi, -1, 2) {
      FOR(wi, -1, 2) {
	if (0 < hi + a and hi + a < H - 1 and
	    0 < wi + b and wi + b < W - 1) {
	  cnt[make_pair(hi + a, wi + b)]++;
	}
      }
    }
  }

  vector< ll > ans(10, 0ll);
  ans[0] = (H - 2) * (W - 2);
  EACH(c, cnt) {
    /*
    debug(c.first.first);
    debug(c.first.second);
    debug(c.second);
    */
    ans[c.second]++;
    ans[0]--;
  }

  EACH(a, ans) {
    cout << a << endl;
  }

  return 0;
}



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

#define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	print_tuple<Cdr...>(os,t);
	os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int main()
{
	for(int n,m;cin>>n>>m&&n|m;){
		string s; cin>>s;
		vi ls(m),rs(m);
		rep(i,m) cin>>ls[i]>>rs[i],ls[i]--;

		{
			vector<tuple<int,int>> ts;
			int pl=-1,pr=-1;
			rep(i,m) if(pr<rs[i]){
				if(pl<ls[i])
					ts.emplace_back(ls[i],rs[i]);
				else
					ts.back()=mt(ls[i],rs[i]);
				tie(pl,pr)=ts.back();
			}
			int first=get<0>(ts[0]),last=get<1>(ts.back());
			s=s.substr(first,last-first);
			n=s.size();
			m=ts.size();
			ls.resize(m),rs.resize(m);
			rep(i,m){
				tie(ls[i],rs[i])=ts[i];
				ls[i]-=first,rs[i]-=first;
			}
		}

		vi zcount(n+1),ocount(n+1);
		rep(i,n){
			zcount[i+1]=zcount[i];
			ocount[i+1]=ocount[i];
			(s[i]=='0'?zcount:ocount)[i+1]++;
		}

		vvi dp(n+1,vi(n+1));  // [文字数]['1'の使用回数]
		dp[0][0]=1;

		ls.push_back(n);
		rep(k,m){
			repi(i,ls[k],min(rs[k],ls[k+1]))
				rep(j,i+1){
					if(i+1-j<=zcount[rs[k]])
						(dp[i+1][j]+=dp[i][j])%=MOD;
					if(j+1<=ocount[rs[k]])
						(dp[i+1][j+1]+=dp[i][j])%=MOD;
				}
			repi(i,rs[k],ls[k+1])
				rep(j,i+1){
					if(s[i]=='0')
						(dp[i+1][j]+=dp[i][j])%=MOD;
					else
						(dp[i+1][j+1]+=dp[i][j])%=MOD;
				}
		}

		cout<<dp[n][ocount[n]]<<endl;
	}
}


Measured memory_bytes: 35584
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define V vector<int>
#define ll long long
using namespace std;


int main() {
    int n; cin >> n;
    int h[n];
    rep(i, 0, n) cin >> h[i];

    int cnt = 0, ans = 0;
    rep(i, 0, n-1){
        if(h[i] >= h[i+1]){
            cnt++;
        }else{
            cnt = 0;
        }
        ans = max(ans, cnt);
    }

    cout << ans << "\n";
}

Measured memory_bytes: 640
import java.util.Scanner;

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

		while (true) {
			int n = scan.nextInt();
			int a = scan.nextInt();
			int b = scan.nextInt();
			int c = scan.nextInt();
			int x = scan.nextInt();
			int[] y = new int[n];
			int[] yCheck = new int[n];
			int count = 0;

			if (n == 0 && a == 0 && b == 0 && c == 0 && x == 0)
				break;

			for (int i = 0; i < n; i++) {
				y[i] = scan.nextInt();
			}

			int place=0;
			
			while (true) {

					if (y[place] == x) {
						yCheck[place] = 1;
						place++;
					}
				

				if (count > 10000) {
					count = -1;
					break;
				}

				if (place>=n)
					break;

				x = (a * x + b) % c;
				
				count++;

			}

			System.out.println(count);
		}

		scan.close();
	}

}

Measured memory_bytes: 31732