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

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

    private static class Solver {
        private void solve(InputReader inp, PrintWriter out) {
            int n = inp.nextInt();
            int maximumMask = (1 << n) - 1;

            long MOD = 1000000007;
            long[] dp = new long[maximumMask + 1];
            dp[0] = 1;

            boolean[][] match = new boolean[n][n];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    match[i][j] = inp.nextInt() == 1;
                }
             }

            for (int i = 1; i <= n; i++) {
                int mask = 0;
                for (int j = 0; j < i; j++) mask = (mask << 1) | 1;

                while (mask <= maximumMask) {
                    for (int j = 0; j < n; j++) {
                        // if j'th position is a 1
                        if (((1 << j) & mask) > 0) {
                            int mask2 = mask ^ (1 << j);
                            if (match[j][i-1]) dp[mask] = (dp[mask] + dp[mask2]) % MOD;
                        }
                    }

                    // next mask with i bits
                    int c = mask & -mask;
                    int r = mask + c;
                    mask = (((r ^ mask) >> 2) / c) | r;
                }
            }
            out.print(dp[maximumMask]);
        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

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

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

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
    }
}




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


 


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

  long long a[n];

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

  sort(a,a+n);

  long long sum = 0;


  for(int i = 0 ; i < n - k ; i++)
  {
    sum += a[i];
  }

  cout <<sum << endl;

  

  return 0;
}


Measured memory_bytes: 1792
def main():
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    c = list(map(int, input().split()))
    
    ans = sum(b)
    for i in range(1, n):
        if a[i] - a[i - 1] == 1:
            ans += c[a[i - 1] - 1]
    
    print(ans)
    
    return 0

main()


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

long long N;
int mod = 1e9 + 7;
map<long long, int> mp;

int sum(long long n) {
    auto itr = mp.find(n);
    if (itr != mp.end()) return (*itr).second;
    
    if (n % 2) {
        return mp[n] = (2ll * sum(n / 2) + sum(n / 2 - 1)) % mod;
    } else {
        return mp[n] = (2ll * sum(n / 2 - 1) + sum(n / 2)) % mod;
    }
}

int main() {
    mp[0] = 1; mp[1] = 2;
    cin >> N;
    cout << sum(N) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define maxn 500005
using namespace std;
inline int read()
{
	char x = getchar();
	int lin = 0, f = 1;
	while(x < '0' || x > '9')
	{
		if(x == '-') f = -1;
		x = getchar();
	}
    while(x >= '0' && x <= '9')
	{
		lin = lin * 10 + x - '0';
		x = getchar();
	}
	return lin * f;
}
#define PII pair<int,int>
#define fir first
#define sec second
#define ma(a,b) make_pair(a,b)
int ans,n,m,sz[maxn],x,y,red[maxn];
int main(){
	n = read(); m = read();
	for(int i = 1; i <= n; i++)
		sz[i] = 1;
	red[1] = 1;
	for(int i = 1; i <= m; i++)
	{
		x = read(); y = read();
		--sz[x];
		++sz[y];
		if(red[x]) red[y] = 1;
		if(!sz[x]) red[x] = 0;
	}
	for(int i = 1; i <= n; i++)
		ans += red[i];
	cout << ans;
}

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

int main(){
    int N, A; //1円玉の枚数がA、支払うのがN円
    cin >> N >> A;

    if (N % 500 <=A){
        cout <<"Yes" << endl;
        }

    else{
        cout << "No" << endl;
        }


}

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

int main(){
	int x;
	int ans = 1;
	cin >> x;
	
	for(int i=1;i<=x;i++){
		for(int j=2;j<=x;j++){
			if(pow(i,j) > x) break;
			if(pow(i,j) >= ans){
				ans = pow(i ,j);
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <stdio.h>
#include<limits.h>
#include<algorithm>
#include<queue>
#include<set>
#include<math.h>
#include<random>

#define lli long long int
#define MOD 1000000007

using namespace std;

long long int modpow(long long int a, long long int n) {
	if (n == 0)return 1;
	if (n == 1)return (a % MOD);

	long long int hanbun = n / 2;
	long long int amari = n % 2;

	long long int ans = (a * a) % MOD;
	ans = modpow(ans, hanbun);

	if (amari == 1)ans *= a;

	ans %= MOD;

	return ans;

}

long long int gcd(long long int a, long long int b) {
	if (a < b) {
		long long int tmp = a;
		a = b;
		b = tmp;
	}

	long long int amari = a % b;

	if (amari == 0)return b;

	return gcd(b, amari);
}

long long int lcm(long long int a, long long int b) {
	long long int ans = (a * b) % MOD;
	long long int wari = modpow(gcd(a, b), MOD - 2);
	ans = (ans * wari) % MOD;
	return ans;
}

long long int factElement[10000] = { 0 };

long long int factrial(int n) {

	if (factElement[n] != 0)return factElement[n];

	if (n == 0) {
		factElement[0] = 1;
		return factElement[n];
	}

	long long int ans = n * factrial(n - 1);
	factElement[n] = ans;
	return factElement[n];

}

struct SegmentTree {
private:
	int n;
	vector<long long int> node;
	int TANNI;

	long long int Func(long long int a, long long int b) {
		return min(a,b);
	}

public:
	//元配列ｖをセグメント木で表現する。
	SegmentTree(vector<long long int> v, long long int tanni) {
		//最下段のノード数は元配列のサイズ以上になる最小の2冪→これをｎとおく。
		//セグメント木全体で必要なノード数は2n-1個である。
		int sz = v.size();
		n = 1;
		while (n < sz)n *= 2;

		TANNI = tanni;
		node.resize(2 * n - 1, TANNI);

		//最下段に値を入れた後に、下の段から順番に値を入れる。
		//値を入れるには、自分の子の２値を参照すればよい。
		for (int i = 0; i < sz; i++)node[i + n - 1] = v[i];
		for (int i = n - 2; i >= 0; i--)node[i] = Func(node[2 * i + 1], node[2 * i + 2]);
	}

	void update(long long int x, long long int val) {
		//最下段のノードにアクセスする。
		x += (n - 1);

		//最下段のノードを更新したら、あとは親に上って更新していく。
		node[x] = val;

		while (x > 0) {
			x = (x - 1) / 2;
			node[x] = Func(node[2 * x + 1], node[2 * x + 2]);
		}
	}

	long long int getVal(int x) {
		x += (n - 1);
		return node[x];
	}

	long long int getAns(int a, int b, int k = 0, int l = 0, int r = -1) {
		//最初に呼び出された時の区間は[0,n)
		if (r < 0)r = n;

		//要求区間と対象区間が交わらない→単位元を返す。
		if (r <= a || b <= l) return TANNI;

		//要求区間が対象区間を完全に被覆する→対象区間を答えの計算に使う。
		if (a <= l && r <= b) return node[k];

		//要求区間が対象区間の一部を被覆→子をよびだす。
		//左の子をvl、右の子をvrとしている。
		//新しい対象区間は現在の対象区間を半分に割ったもの。
		int vl = getAns(a, b, 2 * k + 1, l, (l + r) / 2);
		int vr = getAns(a, b, 2 * k + 2, (l + r) / 2, r);
		return Func(vl, vr);


	}



};




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

	bool b = false;

	for (int i = 0; i < str.size(); i++) {
		if (str[i] == '7')b = true;


	}

	if (b) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	




	return 0;

}



Measured memory_bytes: 3600
// Created by sz
#include <bits/stdc++.h>
using namespace std;


int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin>>n;
    cout<<n*(n+1)/2<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
bool t[110][110];
int main(){
	int n,m,d;
	char z;
	cin>>n>>m>>d;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin>>z;
			if(z=='.')t[i][j]=true;
			else t[i][j]=false;
		}
	}
	d--;
	int ans=0;
	for(int i=0;i<n;i++){
		int cnt=0;
		for(int j=0;j<m;j++){
			if(t[i][j]==false){
				if(d<cnt)ans+=cnt-d;
				cnt=0;
			}
			else cnt++;
		}
		if(d<cnt)ans+=cnt-d;
	}
	for(int i=0;i<m;i++){
		int cnt=0;
		for(int j=0;j<n;j++){
			if(t[j][i]==false){
				if(d<cnt)ans+=cnt-d;
				cnt=0;
			}
			else cnt++;
		}
		if(d<cnt)ans+=cnt-d;
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;
 
int main() { /* ここに書く */
  
  long long A;
  string B;
  long long c1,c2,c3,C;
  long long ans;
  
  cin >> A >> B;
  
  c1 = B.at(0) - '0';
  //cout <<c1 <<endl;
  c1 = c1 * 100;
  c2 = B.at(2) - '0';
  c2 = c2 * 10;
  c3 = B.at(3) - '0';
  
  //cout << c1 << c2 << c3;
  
  C = c1 + c2 + c3;
  
  ans = A*C;
  ans = ans / 100;  
  
  cout << ans << endl;
  
}

Measured memory_bytes: 3632
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#define _GLIBCXX_DEBUG // check []
#define DIVISOR 1000000007

using namespace std;
typedef pair<int,int> pii;
typedef pair<int64_t, int64_t> pII;

template<typename T>
void cins(vector<T>& arr) { for(T& e: arr) cin >> e; }

#ifdef DEBUG
#define debug(fmt, ...) \
    printf("[debug: %s] " fmt, __func__, __VA_ARGS__)
#define ps(arr) \
    debug("size %ld: ", arr.size()); \
    for(auto e: arr) cout << e << " "; \
    cout << endl;
#else
#define debug(fmt, ...)
#define ps(arr)
#endif

#include <list>
int main(void) {
    string str;
    cin >> str;
    list<char> list;
    for(int i = 0; i < str.length(); i++) {
        list.push_back(str[i]);
    }
    int qs;
    cin >> qs;
    int dir = 1;
    for(int i = 0; i < qs; i++) {
        int type, pos;
        char ch;
        cin >> type;
        switch(type) {
            case 1:
                dir = -dir;
                break;
            case 2:
                {
                    cin >> pos; cin >> ch;
                    int is_head = (dir == 1 && pos == 1);
                    is_head |= (dir == -1 && pos == 2);
                    if(is_head) {
                        list.push_front(ch);
                    } else {
                        list.push_back(ch);
                    }
                }
                break;
            default:
                break;
        }
        ps(list);
    }
    if(dir == -1) reverse(list.begin(), list.end());
    for(auto it = list.begin(); it != list.end(); it++) {
        cout << *(it);
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 13056
#include<bits/stdc++.h>
#define N 25
using namespace std;
int n,a,l[N],r[N],par[N],sib[N],deg[N],dep[N],height[N],z[N];
bool used[N];

int dfs(int x,int d){
  dep[x]=d;
  if(l[x]==-1&&r[x]==-1)return 1;
  if(z[x]!=2)z[x]=1;
  if(l[x]!=-1)height[x]=max(height[x],dfs(l[x],d+1));
  if(r[x]!=-1)height[x]=max(height[x],dfs(r[x],d+1));
  return height[x]+1;
}

int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a;
    cin>>l[a]>>r[a];
    if(l[a]!=-1)deg[a]++,used[l[a]]=true,par[l[a]]=a,sib[l[a]]=r[a];
    if(r[a]!=-1)deg[a]++,used[r[a]]=true,par[r[a]]=a,sib[r[a]]=l[a];
  }
  for(int i=0;i<n;i++)
    if(!used[i])par[i]=-1,sib[i]=-1,z[i]=2,dfs(i,0);
  for(int i=0;i<n;i++){
    cout<<"node "<<i<<": parent = "<<par[i]<<", sibling = "<<sib[i];
    cout<<", degree = "<<deg[i]<<", depth = "<<dep[i]<<", height = "<<height[i];
    if(!z[i])cout<<", leaf"<<endl;
    if(z[i]==1)cout<<", internal node"<<endl;
    if(z[i]==2)cout<<", root"<<endl;
  }
  return 0;
}

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

int n;
struct P { double x, y;};
vector<P> p;

double dist(P a, P b) {
  double dx = a.x-b.x;
  double dy = a.y-b.y;
  return sqrt(dx*dx + dy*dy);
}
double f(double x, double y) {
  double res = 0;
  rep(i,n) {
    res = max(res, dist((P){x,y}, p[i]));
  }
  return res;
}

double g(double x) {
  double l = 0, r = 1000;
  rep(i,80) {
    double c1 = (l*2+r)/3;
    double c2 = (l+r*2)/3;
    if (f(x,c1) > f(x,c2)) l = c1; else r = c2;
  }
  return f(x,l);
}

int main() {
  cin >> n;
  p = vector<P>(n);
  rep(i,n) cin >> p[i].x >> p[i].y;

  double l = 0, r = 1000;
  rep(i,80) {
    double c1 = (l*2+r)/3;
    double c2 = (l+r*2)/3;
    if (g(c1) > g(c2)) l = c1; else r = c2;
  }

  double ans = g(l);
  printf("%.10f\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<utility>
using namespace std;
#define REP(i, a,b) for(i=a;i<b;i++) 
#define output(x) cout<<x<<endl;
typedef long long int ll;



int main()
{
	ll  i, j, k, l, m, sum, flag,ans,W,H,N;
	sum = 0;
	flag = 0;
	cin >> N;
	vector<ll>A(N);
	ll odd[100001] = {};
	ll even[100001] = {};
	ll odd1[100001] = {};
	ll even1[100001] = {};
	REP(i, 0, N) {
		cin >> A[i];
		if (i % 2 == 0) {
			even[A[i]]++;
			even1[A[i]]++;
		}
		else {
			odd[A[i]]++;
			odd1[A[i]]++;
		}
	}
	sort(even, even + 100001);
	sort(odd, odd + 100001);
	REP(i, 0, 100001) {
		if (even1[i] == even[100000]) {
			break;
		}
	}
	REP(j, 0, 100001) {
		if (odd1[j] == odd[100000]) {
			break;
		}
	}
	if (i == j) {
		ans = max(even[99999] + odd[100000], even[100000] + odd[99999]);
	}
	else
		ans = odd[100000] + even[100000];
	output(N - ans);
	
	
	//ソートしてある配列aの各要素の数を前から数え上げることで新しい配列lenに入れている
	return 0;
}



Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#include <algorithm>


int main(){
  int n;
  cin >> n;
  
  vector<int> p(n);
  for(int i = 0; i < n; i++){
    cin >> p[i];
  }
  int max_p = *max_element(p.begin(), p.end());
  int answer = accumulate(p.begin(), p.end(), 0) - max_p / 2;
  cout << answer << endl;
}

Measured memory_bytes: 256
n,k,q = map(int,input().split())
lis = [0 for i in range(n)]
for i in range(q):
  a = int(input())
  lis[a-1] += 1
for i in range(n):
  if lis[i] > q-k:
    print("Yes")
  else:
    print("No")

Measured memory_bytes: 4604
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;

int n;
double f[310][310][310];

double solve(int i, int j, int k)
{
    if (f[i][j][k] != -1) return f[i][j][k];
    if (i == 0 && j == 0 && k == 0) return f[i][j][k] = 0;
    
    double ans = 0;
    if (i > 0) ans += solve(i - 1, j, k)*i;
    if (j > 0) ans += solve(i + 1, j - 1, k)*j;
    if (k > 0) ans += solve(i, j + 1, k - 1)*k;
    
    ans = (ans + n)/(double)(i + j + k);
    
    return f[i][j][k] = ans;
}

int main()
{
    scanf("%d", &n);
    int x = 0, y = 0, z = 0;
    for (int i = 1; i <= n; ++i)
    {
        int tmp; scanf("%d", &tmp);
        if (tmp == 1) ++x;
        else if (tmp == 2) ++y;
        else ++z;
    }
    
    for (int i = 0; i <= n; ++i)
        for (int j = 0; j <= n; ++j)
            for (int k = 0; k <= n; ++k)
                f[i][j][k] = -1;
    printf("%.10f", solve(x, y, z));
}

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

using namespace std;

int main()
{
    long long n, k, ans = 1, f, t, aux , i;
    cin >> n >> k;
    if(n == 1)
    {
        cout << k << "\n";
        return 0;
    }
    for(i = 2 ; i * i < k ; i++)
    {
        if(k % i == 0)
        {
            f = i;
            t = 0;
            aux = k;
            while(aux % f == 0)
                t++, aux /= f;
            if(t >= n)
                ans = max(ans, i);
            t = 0;
            f = k / i;
            aux = k;
            while(aux % f == 0)
                t++, aux /= f;
            if(t >= n)
                ans = max(ans, i);
        }
    }
    if(1LL * i * i == k)
    {
        f = i;
        t = 0;
        aux = k;
        while(aux % f == 0)
            t++, aux /= f;
        if(t >= n)
            ans = max(ans, i);
    }
    cout << ans << "\n";
    return 0;
}


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

int main() {
        int N, Sum=0;
        cin >> N;

        for(int i=0; i<=(int)log10(N); i++)Sum+=(N/(int)pow(10,i))%10;

        if(N%Sum==0)cout << "Yes" << endl;
        else cout << "No" << endl;

        return 0;
}

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

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

constexpr ld eps = 1e-10;

constexpr int INF = 1e9;

constexpr int M = 1e9 + 7;

using graph = vector<vector<int>>;

int main() {
    string d;
    cin >> d;
    ll S = 0, P = 1;
    for(int i = 0; i < d.size(); ++i) {
        S += (d[i] - '0');
        P *= (d[i] - '0' + 1);
    }
    reverse(d.begin(), d.end());

    ll res = 0;
    map<tuple<int, ll, bool>, ll> dp; // (sum, prod, gt)
    dp[make_tuple(0, 1, false)] = 1;
    for(int i = 0; i < d.size(); ++i) {
        map<tuple<int, ll, bool>, ll> nxt;
        //cout << "i: " << i + 1 << endl;
        for(auto& t : dp) {
            int sum;
            ll prod;
            bool gt;
            tie(sum, prod, gt) = t.first;
            //cout << "t: " << sum << ' ' << prod << ' ' << gt << " -> dp: " << t.second << endl;
            for(int j = 0; j <= 9; ++j) {
                int ns = sum + j;
                ll np = prod * (j + 1);
                bool ngt = (i == 0 ? true : gt) && (d[i] - '0') == j || (d[i] - '0') < j;
                if(ns > S || ns == S && np > P) {
                    continue;
                }
                nxt[make_tuple(ns, np, ngt)] += dp[t.first];
                if(i + 1 == d.size()) {
                    if(ns < S || ns == S && np < P || ns == S && np == P && !ngt) {
                        //cout << "j: " << j << ' ' << ns << ' ' << np << ' ' << ngt << " -> " << dp[t.first] << endl;
                        res += t.second;
                    }
                }
            }
        }
        dp = move(nxt);
    }
    cout << res << endl;
}

Measured memory_bytes: 35040
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
#define int long long
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000000000000;

signed main(){
	string S;
	int A=0,B=0;
	cin>>S;
	REP(i,S.size()){
		if(S[i]=='0'){
			A++;
		}
		else{
			B++;
		}
	}
	cout<<S.size()-abs(A-B)<<endl;
	return 0;
}


Measured memory_bytes: 512
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let t: f64 = iterator.next().unwrap().parse().unwrap();
    let x: f64 = iterator.next().unwrap().parse().unwrap();

    let ans = t / x;
    return format!("{}", ans);
}


Measured memory_bytes: 2200
N = int(input())
a_ls = [int(i) for i in input().split()]
b_ls = [int(i) for i in input().split()]
c_ls = [int(i) for i in input().split()]

ans = sum(b_ls)

for i in range(N-1):
    key = a_ls[i]
    if key == a_ls[i+1] - 1:
        ans += c_ls[key-1]

print(ans)

Measured memory_bytes: 3064
/**
SXR0aXAkI0JwbXptI3FhI3Z3I293bCNqY2IjUG0jMCNicG0jVHFkcXZvLyNCcG0jQW10bjBhY2phcWFicXZvLyNNYm16dml0MSNWdyNhdGN1am16I2tpdiNhbXF9bSNQcXUjVnd6I0F0bW14MSNQcWEjaXptI2l0dCNicHF2b2EjUXYjYnBtI3BtaWRtdmEjaXZsI3d2I21pemJwMSNFcHcjcWEjYnBtem0ja2l2I3F2Ym16a21sbSNRdiNQcWEjeHptYW12a20jbXtrbXhiI0lhI3BtI3htenVxYmJtYnBHI1BtI3N2d2VtYnAjRXBpYiMraXh4bWl6bWJwI2J3I1BxYSNrem1pYmN6bWEjSWEsI0ptbnd6bSN3eiNJbmJteiN3eiNKbXBxdmwjYnBtdTEjVnd6I2FwaXR0I2JwbXwja3d1eGlhYSNJY29wYiN3biNwcWEjc3Z3ZXRtbG9tI017a214YiNpYSNQbSNlcXR0bWJwMSNQcWEjYnB6d3ZtI2x3YnAjbXtibXZsI1dkbXojYnBtI3BtaWRtdmEjSXZsI3d2I21pemJwLyNpdmwjUG0jbm1tdG1icCNWdyNuaWJxb2NtI3F2I29jaXpscXZvI0l2bCN4em1hbXpkcXZvI2JwbXUvI053eiNQbSNxYSNicG0jVXdhYiNQcW9wMSNCcG0jQWN4em11bSMrcXYjb3R3enwsMQ==
*/
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>

#define F first
#define S second
#define endl '\n'
#define deb(x) cout<<#x<<' '<<x<<endl;
#define pb push_back

/*
#ifdef IZI_KATKA
#define int __int64_t
#else
#define int __int64
#endif
*/

const long long MOD = 1e9 + 7;
const long long MAXN = 1e6 + 1;
using namespace std;

typedef long long ll;

long long readInt() {
    bool minus1 = false;
    long long result = 0;
    char ch;
    ch = getchar();
    while (true) {
        if (ch == '-') break;
        if (ch >= '0' && ch <= '9') break;
        ch = getchar();
    }
    if (ch == '-') minus1 = true; else result = ch-'0';
    while (true) {
        ch = getchar();
        if (ch < '0' || ch > '9') break;
        result = result*10 + (ch - '0');
    }
    if (minus1)
        return -result;
    else
        return result;
}

map <ll, int> cnt;


int main() {
	#ifdef IZI_KATKA
	assert(freopen("input", "r", stdin));
    assert(freopen("output", "w", stdout));
    #endif
    int n = readInt();
    ll ans = 0;
    ll sum = 0;
    cnt[0]++;
    for (int i = 1; i <= n; i++) {
    	sum += readInt();
    	ans += (cnt[sum]);
    	cnt[sum]++;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 12800
#include<bits/stdc++.h>
using namespace std;
int main()
{  
  int a,b,c;
  cin>>a>>b>>c;
  if(a==b)
  {
    if(a!=c)
      cout<<"Yes"<<endl;
    else
      cout<<"No"<<endl;
  }
  else if(a==c)
  {
    if(a!=b)
      cout<<"Yes"<<endl;
    else
      cout<<"No"<<endl;
  }
  else if(b==c)
  {
    if(b!=a)
      cout<<"Yes"<<endl;
    else
      cout<<"No"<<endl;
  }
  else
    cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,n,m) for(int i=n;i<m;i++)
#define elif else if
#define INF 1000000007
using namespace std;
int gcd(int a,int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int m,n,aa[110000][10],k,cnt=0,a,b;
pair<int,int> p[220000];
string s,ss[220000],x;
char c;
signed main(){
    cin>>a>>b;
    rep(i,1100){
        if(i*8/100==a&&i*10/100==b){
            cout<<i;
            return 0;
        }
    }
    cout<<-1;
}

Measured memory_bytes: 3968
#include <stdio.h>

int Sum(int n)
{
	int res = 0;
	while(n)
	{
		res += n%10;
		n = n/10;
	}
	return res;
}

int main()
{
	int n;
	scanf("%d", &n);
	if(n%Sum(n)==0)
		printf("Yes\n");
	else
		printf("No\n"); 
	return 0;
} 

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
using namespace std;

int main()
{
    fastio;
    int N, D, X;
    cin >> N >> D >> X;
    vector<int> As;
    copy_n(istream_iterator<int>(cin), N, back_inserter(As));
    vector<int> A_eats;
    transform(As.begin(), As.end(), back_inserter(A_eats),
              [D](int A) {
                  return (D - 1) / A + 1;
              });

    auto choco_num = X + accumulate(A_eats.begin(), A_eats.end(), 0);

    cout << choco_num << endl;

    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#pragma GCC optimize "trapv"
#define pb push_back
#define fi first
#define se second
#define all(container) container.begin(),container.end()
#define fast ios::sync_with_stdio(0); cin.tie(0)
#ifndef ONLINE_JUDGE
#include "debug.cpp"
#endif
#define int long long
const int mod = 1e9+7;  
int power(int a,int b) { if(b==0) return 1; int res = power(a,b/2); if(b&1) return res * res * a; else return res * res; }


int32_t main(){
    
  fast;
  int n; cin >> n;
  int ar[n] = {0};

  for(int i=0;i<n;i++) cin >> ar[i];

  int ans = 0;

  for(int i=1;i<n;i++){
    if(ar[i]<ar[i-1]){
      ans = ans + ar[i-1] - ar[i];
      ar[i] = ar[i-1];
    }
  }

  cout << ans << '\n';


  return 0;
}

Measured memory_bytes: 5176
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<queue>
#include<cstdio>
#include<string>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
#define inf 0x3f3f3f3f
using namespace std;

int main()
{
	int x, y;
	scanf("%d%d", &x, &y);
	long long  ans = 0;  
	for (int i = y + 1; i <= x; i++)
	{ 
		ans = ans + (i - y) * (x / i);     
		if (x % i - y >= 0) ans = ans + 1 + x % i - y; 
	}   
	if (y == 0) ans = ans - x; 
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <string>

using namespace std;

struct node {
	int left, right, per;
};

void preorder(int x, vector<node> &nd) {
	if (nd[x].left == -1 && nd[x].right == -1) cout << " " << x;
	else {
		cout << " " << x;
		if (nd[x].left != -1) preorder(nd[x].left, nd);
		if (nd[x].right != -1) preorder(nd[x].right, nd);
	}
}

void inorder(int x, vector<node> &nd) {
	if (nd[x].left == -1 && nd[x].right == -1) cout << " " << x;
	else {
		if (nd[x].left != -1) inorder(nd[x].left, nd);
		cout << " " << x;
		if (nd[x].right != -1) inorder(nd[x].right, nd);
	}
}

void postorder(int x, vector<node> &nd) {
	if (nd[x].left == -1 && nd[x].right == -1) cout << " " << x;
	else {
		if (nd[x].left != -1) postorder(nd[x].left, nd);
		if (nd[x].right != -1) postorder(nd[x].right, nd);
		cout << " " << x;
	}
}

int main() {
	int n, st = 0;
	cin >> n;
	vector<node> nd(n);
	for (int i = 0; i < n; i++) nd[i].per = -1;
	for (int i = 0; i < n; i++) {
		int id, left, right;
		cin >> id >> left >> right;
		nd[id].left = left;
		nd[id].right = right;
		if (left != -1) nd[left].per = id;
		if (right != -1) nd[right].per = id;
	}
	while (nd[st].per != -1) st = nd[st].per;
	cout << "Preorder" << endl;
	preorder(st, nd); 
	cout << endl;
	cout << "Inorder" << endl;
	inorder(st, nd);
	cout << endl;
	cout << "Postorder" << endl;
	postorder(st, nd);
	cout << endl;
}

//node 1: parent = 0, sibling = 4, degree = 2, depth = 1, height = 1, internal node

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

namespace AGC032
{
    class V
    {
        public int Id;
        public List<V> cnctList = new List<V>();

        public V(int id)
        {
            Id = id;
        }
    }

    class B032
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());

            List<V> vlist = new List<V>();
            V v1 = new V(1); V v2 = new V(2); V v3 = new V(3);
            vlist.Add(v1);vlist.Add(v2);vlist.Add(v3);
            v1.cnctList.Add(v3); v2.cnctList.Add(v3);
            v3.cnctList.Add(v1); v3.cnctList.Add(v2);

            int m = 2;
            int i = 4;
            while (i <= N)
            {
                if (i % 2 == 0)
                {
                    foreach (V v in vlist)
                    {
                        v.Id++;
                    }
                    V vn = new V(1);
                    foreach (V v in vlist)
                    {
                        if (v.Id != i)
                        {
                            vn.cnctList.Add(v);
                            v.cnctList.Add(vn);
                            m++;
                        }
                    }
                    vlist.Add(vn);
                }
                else
                {
                    V vn = new V(i);
                    foreach (V v in vlist)
                    {
                        vn.cnctList.Add(v);
                        v.cnctList.Add(vn);
                        m++;
                    }
                    vlist.Add(vn);
                }
                i++;
            }

            vlist = vlist.OrderBy(x => x.Id).ToList();

            Console.WriteLine(m);
            foreach(V v in vlist)
            {
                foreach(V vc in v.cnctList)
                {
                    if (vc.Id > v.Id)
                    {
                        Console.WriteLine(v.Id + " " + vc.Id);
                    }
                }
            }


        }

    }
}


Measured memory_bytes: 13396
// Problem : C - Multiplication 3
// Contest : AtCoder - AtCoder Beginner Contest 169
// URL : https://atcoder.jp/contests/abc169/tasks/abc169_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include "bits/stdc++.h"
using namespace std;
#define IOS { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define pb push_back
#define nl cout<<"\n"
#define endl "\n"
#define all(c) (c).begin(),(c).end()
#define trav(a,x) for(auto a = x.begin() ; a != x.end() ; a++)
#define rep(i,n) for(int (i) = 0 ; i < (n) ; i++)
#define lb lower_bound
#define ub upper_bound
#define f first
#define s second
typedef long long ll;
typedef unsigned long long ull ;
typedef long double ld;
inline ll max(ll a,ll b) {return ((a>b)?a:b);}
inline ll min(ll a,ll b) {return ((a>b)?b:a);}
inline ll gcd(ll a ,ll b) {if(b==0) return a;a%=b;return gcd(b,a);}
ll power(ll x, ll y) { if (y == 0) return 1;  ll a = power(x,y/2);if (y % 2 == 0) return a * a; else return x * a * a; }
ll powermod(ll x, ll ex , ll md) {ll ans = 1ll;while (ex > 0) {    if (ex & 1ll) ans = (ans * x) % md;    ex >>= 1ll;x = (x * x) % md;}return ans;}
const ll inf = 1e18 + 9;
const ll mod = 1e9 + 7;
const long double eps = 1e-9;
const ll N = 1e6 + 1;

void solve(){
	ld a , b;
	cin >> a >> b;
	ld p = a*b;
	ll x = p;
	cout << x << endl;
}
int main(){
    IOS;
    cout<<fixed<<setprecision(20);
    ll T=1;
    // cin>>T;
    ll t=0;
    while(t++<T){
        // cout<<"Case #"<<t<<":"<<' ';
        solve();
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}


Measured memory_bytes: 3808
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N,a,b,ans=0;
    cin >> N >> a >> b;
    for (int i=1;i<N+1;i++){
        int q=i%10,w=i%100/10,e=i%1000/100,r=i%10000/1000,t=i%100000/10000;
        if (q+w+e+r+t<=b && q+w+e+r+t>=a) ans=ans+i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int n,qc,x[51],y[51],z[51],rl[51];
double dx,dy,dz,sx,sy,sz,a,b,c,p,q,r;
long long int l[51],sum;
double t,lt;
int main(){
	cin >>n >>qc;
	for(int i=0;i<n;i++){
		cin >>x[i] >>y[i] >>z[i] >>rl[i] >>l[i];
	}
	for(int i=0;i<qc;i++){
		sum=0;
		cin >>sx >>sy >>sz >>dx >>dy >>dz;
		a=dx-sx;
		b=dy-sy;
		c=dz-sz;
		for(int j=0;j<n;j++){
			p=sx-x[j];
			q=sy-y[j];
			r=sz-z[j];
			t=-(a*p+b*q+c*r)/(a*a+b*b+c*c);
			if(t>1){
				t=1;
			}else if(t<0){
				t=0;
			}
			lt=(t*a+p)*(t*a+p)+(t*b+q)*(t*b+q)+(t*c+r)*(t*c+r);
			
			if(lt<=rl[j]*rl[j]+(0.0001))sum+=l[j];
			//cout <<t <<endl;
			//cout <<lt <<endl;
			
		}
		cout <<sum <<endl;
	}
}

Measured memory_bytes: 3224
#include<bits/stdc++.h>
using namespace std;
struct RMQ{
  static const int MAX_N = 1 << 17;
  int n,dat[2*MAX_N-1];
  RMQ(){}
  RMQ(int n_){init(n_);}
  void init(int n_){
    n=1;
    while(n<n_) n*=2;
    for(int i=0;i<2*n-1;i++) dat[i]=INT_MAX;
  }
  void update(int k,int a){
    k+=n-1;
    dat[k]=a;
    while(k>0){
      k=(k-1)/2;
      dat[k]=min(dat[k*2+1],dat[k*2+2]);
    }
  }
  int query(int a,int b,int k,int l,int r){
    if(r<=a||b<=l) return INT_MAX;
    if(a<=l&&r<=b) return dat[k];
    else{
      int vl=query(a,b,k*2+1,l,(l+r)/2);
      int vr=query(a,b,k*2+2,(l+r)/2,r);
      return min(vl,vr);
    }
  }
  int query(int a,int b){
    return query(a,b,0,0,n);
  }
};
int main(){
  int n,q;
  cin>>n>>q;
  RMQ rmq(n);
  for(int i=0;i<q;i++){
    int c,x,y;
    cin>>c>>x>>y;
    if(c) cout<<rmq.query(x,y+1)<<endl;
    else rmq.update(x,y);
  }
  return 0;
}
/*
verified on 2017/02/18
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_A
*/

Measured memory_bytes: 4112
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define rep(N) for (int i = 0; i < N; ++i)
#define Rep(a, b) for (int i = a; i < b; ++i)
#define For(i, N) for (int i = 0; i < N; ++i)
#define all(v) v.begin(), v.end()
#define rev(v) v.rbegin(), v.rend()
#define makei(N) int N; cin >> N;
#define makel(N) ll N; cin >> N;
#define makes(s) string s; cin >> s;
#define maked(d) double d; cin >> d;
#define makev(v, N) vi v(N); rep(N)cin >> v[i];
#define mod 1000000007
#define re return 0

using namespace std;
using ll = long long int;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using msi = map<string, int>;

template<typename T>
void say(T s) {
	cout << s << "\n";
}

template<typename T>
void say(vector<T> s) {
	auto itr = s.begin();
	cout << *(itr++);
	while (itr != s.end()) {
		cout << " " << *(itr++);
	}
	cout << "\n";
}

void yn(bool b) {
	if (b)say("Yes");
	else say("No");
}

void YN(bool b) {
	if (b)say("YES");
	else say("NO");
}
template<typename T>
void maxi(T &a, T &b) {
	a = max(a, b);
}

template<typename T>
void mini(T &a, T &b) {
	a = min(a, b);
}

int main() {
	makei(N);
	makev(x, N);
	vi y = x;
	sort(all(y));
	int ans1 = y[N / 2 - 1];
	int ans2 = y[N / 2];
	rep(N) {
		if (x[i] <= ans1) {
			say(ans2);
		}
		else {
			say(ans1);
		}
	}
}

Measured memory_bytes: 3712
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(12);

    int x;
    cin >> x;

    cout << (x ^ 1) << '\n';


    return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <string>

using namespace std;

int main(int argc, char *argv[]) {
	string s;
	cin >> s;

	s[0] = '2';
	s[1] = '0';
	s[2] = '1';
	s[3] = '8';

	cout << s << endl;

	return 0;
}

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second

template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class T>
istream& operator>>(istream& is, vector<T>& xs){
  for(auto& x: xs)
	is >> x;
  return is;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& xs){
  for(unsigned int i=0;i<xs.size();++i)
	os << (i?" ":"") << xs[i];
  return os;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}
void debug(istringstream&){}
template <char sep=',', class Head, class... Tail>
void debug(istringstream& iss, Head&& head, Tail&&... tail)
{
  string name;
  getline(iss, name, ',');
  cerr << sep << name << "=" << head;
  debug(iss, forward<Tail>(tail)...);
}
#define DEBUG(...) \
  do{ \
    istringstream ss(#__VA_ARGS__); \
    debug<' '>(ss, __VA_ARGS__); \
    cerr<<endl; \
  }while(0)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  int N, M;
  cin >> N >> M;

  map<int,set<PII>> s;
  REP(i,M){
    int x, y;
    cin >> x >> y;
    s[x].insert(MP(y,i));
  }

  VS ans(M);
  for(auto& ps: s){
    int i = 1;
    for(auto& p: ps.SS){
      stringstream ss;
      ss << setfill('0') << setw(6) << ps.FF;
      ss << setfill('0') << setw(6) << i++;
      ans[p.SS] = ss.str();
    }
  }

  REP(i,M) cout << ans[i] << endl;

  return 0;
}


Measured memory_bytes: 20992
#!/usr/bin/env python3
def main():
    _ = int(input())
    A = [int(x) for x in input().split()]
    mod = 10 ** 9 + 7

    sum_A = sum(A) % mod
    ans = 0
    for a in A:
        sum_A -= a
        if sum_A < 0:
            sum_A += mod
        ans += a * sum_A
        ans %= mod
    print(ans % mod)


if __name__ == '__main__':
    main()


Measured memory_bytes: 31456
N, K = map(int, input().split())
S = [list(map(int, input().split())) for _ in range(N)]

from operator import itemgetter
S.sort(key=itemgetter(0)) 

#timesは今何番目に大きいものを表しているか
times=0
#indexは今のインデックス
index=0

while True:
    hoge = times+S[index][1]
    if hoge < K:
        times += S[index][1]
    else:
        re =S[index][0]
        break
    index += 1

print(re)


Measured memory_bytes: 29144
#include <cstdio>
#include <vector>

#define PB push_back

using namespace std;

const int N = 1e5 + 500;

int n, K, sol, par[N];
vector < int > r[N];

int dfs(int x){
	int dep = 0;
	for(int y : r[x])
		dep = max(dep, dfs(y));
	if(dep == K - 1 && par[x] != 1)
		dep = -1, sol++;
	return dep + 1;
}

int main(){
	scanf("%d%d%d", &n, &K, &sol);
	sol = (sol != 1); par[1] = 1;
	for(int i = 2;i <= n;i++){
		int x; scanf("%d", &x);
		r[x].PB(i); par[i] = x;
	}
	dfs(1);
	printf("%d\n", sol);
}


Measured memory_bytes: 10752
num=STDIN.gets.to_i
bld=Array.new(4){Array.new(3){Array.new(10)}}

for ii in 0..3
for jj in 0..2
for kk in 0..9
        bld[ii][jj][kk]=0
end
end
end

for k in 0..num-1
    b,f,r,v=STDIN.gets.chomp.split.map{|v|v.to_i}
    bld[b-1][f-1][r-1]+=v
end

f=1
bld.each do |flr|
flr.each do |room|
room.each do |man|
        print " ",man
end
print "\n"
end
if f<4 then
print "####################\n"
end
f=f+1
end

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

public class Main {
    static final Scanner sc  = new Scanner(System.in);
    static final int MOD = (int) 1E9 + 7;
    static final int INF = Integer.MAX_VALUE;
    
    public static void main(String[] args) {
        char[] s = nchars(1, 0);
        char[] t = nchars(1, 0);
        solve(s, t);
    }
    
    static void solve(char[] s, char[] t) {
        int ls = s.length;
        int lt = t.length;
        
        int[][] len = new int[ls][lt];
                    
        for (int is = 1; is < ls; is++) {
            for (int it = 1; it < lt; it++) {
                if (s[is] == t[it])
                    len[is][it] = len[is-1][it-1] + 1;
                
                else if (len[is-1][it] >= len[is][it-1])
                    len[is][it] = len[is-1][it];
                
                else
                    len[is][it] = len[is][it-1];
            }
        }
        
        StringBuffer sb = new StringBuffer();
        int is = ls-1;
        int it = lt-1;
        while (is > 0 && it > 0) {
            if (s[is] == t[it]) {
                sb.append(s[is]);
                is--;
                it--;
            } else if (len[is][it] == len[is-1][it]) {
                is--;
            } else {
                it--;
            }
        }
        System.out.println(sb.reverse().toString());
    }
    
    static long max(long... longs) {
        return Arrays.stream(longs).max().getAsLong();
    }
    
    static long min(long... longs) {
        return Arrays.stream(longs).min().getAsLong();
    }

    private static long nlong() {
        return sc.nextLong();
    }

    private static int nint() {
        return sc.nextInt();
    }

    private static String nstr() {
        return sc.next();
    }

    private static char[] nchars() {
        return sc.next().toCharArray();
    }

    private static char[] nchars(int padL, int padR) {
        char[] temp = sc.next().toCharArray();
        char[] ret = new char[temp.length + padL + padR];
        System.arraycopy(temp, 0, ret, padL, temp.length);
        return ret;
    }

    private static int[] nints(int n) {
        return nints(n, 0, 0);
    }

    private static int[] nints(int n, int padL, int padR) {
        int[] a = new int[padL + n + padR];
        for (int i = 0; i < n; i++)
            a[padL + i] = nint();
        return a;
    }

    private static char[][] nchars2(int h, int w) {
        return nchars2(h, w, 0);
    }

    private static char[][] nchars2(int h, int w, int pad) {
        char[][] a2 = new char[h + pad * 2][w + pad * 2];
        for (int i = 0; i < h; i++)
            System.arraycopy(nchars(), 0, a2[pad + i], pad, w);
        return a2;
    }
}


Measured memory_bytes: 85068
#include <stdio.h>
int main(){
	int m,a,b,x,y,r,g,i;
	for(;scanf("%d%d%d%d",&m,&a,&b,&x)>3;){
		for(g=0,i=1;i<m;i++){
			scanf("%d",&y);
			if(a<=i&&i<=b && x-y>=g)g=x-y,r=i;
			x=y;
		}
		printf("%d\n",r);
	}
	return 0;
}

Measured memory_bytes: 600
n,k = map(int,input().split()) 
ans = 0

# bikkuri_n1 = math.factorial(n+1) % (10**9+7)

# bikkuri_k = math.factorial(k) % (10**9+7)

for i in range(k,n+2):
  
    small = i*(i-1)//2
    big = i*(2*n-i+1)//2
    
    ans += big-small+1
    ans %= (10**9+7)
    
  
    
print(ans)

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

using namespace std;
using ll = long long;

int main(void){
    ll N;
    cin >> N;
    vector<ll> v(3*N);
    for(auto& it : v) cin >> it;

    vector<ll> mx(N+1);
    vector<ll> mn(N+1);

    priority_queue<ll, vector<ll>, greater<ll>> left;
    priority_queue<ll, vector<ll>, less<ll>> right;
    ll tl=0, tr=0;
    
    for(ll i=0;i<N;i++) {
        tl += v[i];
        left.push(v[i]);
    }

    for(ll i=2*N; i<3*N; i++) {
        tr += v[i];
        right.push(v[i]);
    }

    mx[0] = tl;
    for(ll t=N; t<=2*N-1;t++){
        left.push(v[t]);
        ll x = left.top(); left.pop();
        mx[t-N+1] = mx[t-N+1-1] + v[t] - x;
    }

    mn[N] = tr;
    for(ll t=2*N-1; t>=N;t--){
        right.push(v[t]);
        ll x = right.top(); right.pop();
        mn[t-N] = mn[t-N+1] + v[t] - x;
    }

    ll ans = -1e18;

    for(int i=0;i<mx.size();i++){
        //cout << "mx: " << mx[i] << "mn: " << mn[i] << endl;
        ans = max(ans, mx[i]-mn[i]);
    }

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

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

int main(){
  int N, M;
  cin >> N >> M;

  vector<int> K(N);
  vector<vector<int>> A(N, vector<int>(M));
  bool all;
  int cnt = 0;

  for (int i = 0; i < N; i++){
    cin >> K.at(i);
    for (int j = 0; j < K.at(i); j++){  
      cin >> A.at(i).at(j);
    }
  }

  for (int i = 0; i < M; i++){
    all = true;
    for (int j = 0; j < N; j++){
      if (find(A.at(j).begin(), A.at(j).end(), i + 1) == A.at(j).end()) all = false; 
    }
    if (all){
      cnt += 1;
    }
  }

  cout << cnt << endl;
}

Measured memory_bytes: 3588
#include <stdio.h>
#define ll long long int
int main()
{
	ll a, b;
	while (~scanf("%lld%lld",&a,&b))
	{
		if ( a % b == 0 )
			printf("-1\n");
		else {
			for (int i = 2; i < 10000; i++)
			{
				if (a*i%b != 0)
				{
					printf("%lld\n", a*i);
					break;
				}
			}
		}
	}
}

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

typedef long double ld;
typedef long long ll;

const int inf = 1e9 + 1;
const ld pi = acos(-1);

using namespace std;

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    // freopen("input.txt", "r", stdin);
    cout << setprecision(20);
    int n;
    string s;

    cin >> s;
    n = s.size();
    vector<int> a(n + 1, 0);
    for (int i = n; i > 0; --i) {
        if (s[i - 1] == '>') {
            a[i - 1] = a[i] + 1;
        } else {
            a[i - 1] = 0;
        }
    }
    vector<int> b( n + 1, 0);
    for(int i=0;i<n;i++){
        if(s[i] == '<'){
            b[i+1] = b[i]+1;
        } else {
            b[i+1] = 0;
        }
    }
    ll ans =0 ;
    for(int i=0;i<n+1;i++){
        ans+=max(a[i],b[i]);
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 4764
// clang-format off
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i,n) for(ll i=n-1; i>=0; --i)
#define rrep1(i,n) for(ll i=n; i>0; --i)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define SORT_DESC(x) sort(all(x), greater<>())
#define pb push_back
#define mp make_pair
#define coutl cout<<fixed<<setprecision(10)
#define ANS(ans) cout<<ans<<endl;
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;}
const int INF = 1e9;
const ll LINF = 1e18;
// clang-format on
const string YES = "Yes";
const string NO = "No";

void solve(long long N, std::vector<long long> H) {
  ll min = 0;
  for (ll i = 1; i < N; i++) {
    if (min < H[i] - 1) {
      min = H[i] - 1;
    } else if (H[i] < min) {
      ANS(NO);
      return;
    }
  }
  ANS(YES);
}

int main() {
  long long N;
  scanf("%lld", &N);
  std::vector<long long> H(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &H[i]);
  }
  solve(N, std::move(H));
  return 0;
}


Measured memory_bytes: 1024