akhauriyash/Code-Regression huggingface dataset:
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
   
#include <x86intrin.h>
#include <bits/stdc++.h>   
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;

template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
     
#define F first
#define S second           
#define lb lower_bound               
#define ub upper_bound
#define pb push_back
#define pf push_front    
#define ppb pop_back
#define mp make_pair                                     
#define bpp __builtin_popcountll                                                                                        
#define sqr(x) ((x) * (x)) 
#define al 0x3F3F3F3F
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long
 
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
 
const int mod = (int)1e9 + 7;
const int N = (int)3e5 + 123;
const ll inf = (ll)1e18 + 1;

const double pi = acos (-1.0);
const double eps = 1e-7;                  
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

int n, a[N];
ll pref[N], ans = inf;

inline ll get (int l, int r) {
   return pref[r] - pref[l - 1];
}

inline void boost () {                    
   ios_base :: sync_with_stdio (NULL);
   cin.tie (NULL), cout.tie (NULL);          
}                                                     

inline void Solve () {
   cin >> n;
   for (int i = 1; i <= n; i ++) cin >> a[i], pref[i] = pref[i - 1] + a[i];
   int it1 = 1, it2 = 1;
   for (int i = 3; i <= n; i ++) {
      int l = 1, r = i - 2;
      while (it2 < i) it2 ++;
      while (it1 + 2 <= i - 1 && abs (get (1, it1 + 1) - get (it1 + 2, i - 1)) < abs (get (1, it1) - get (it1 + 1, i - 1))) it1 ++;
      while (it2 + 2 <= n && abs (get (i, it2 + 1) - get (it2 + 2, n)) < abs (get (i, it2) - get (it2 + 1, n))) it2 ++;
      ll B = get (1, it1);
      ll C = get (it1 + 1, i - 1);
      ll D = get (i, it2);
      ll E = get (it2 + 1, n);
      ans = min (ans, max (max (B, C), max (D, E)) - min (min (B, C), min (D, E)));
   }
   cout << ans;

}

main () {                                       
// freopen (".in", "r", stdin);    
// freopen (".out", "w", stdout);              
   boost ();
   int tt = 1;
   //cin >> tt;   
   while (tt --) {
      Solve ();
   }                                               
   return 0;      
}
                          

Measured memory_bytes: 2560
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())
m = 0
m = max(m, b-a)
m = max(m, c-a)
m = max(m, d-a)
m = max(m, e-a)
m = max(m, c-b)
m = max(m, d-b)
m = max(m, e-b)
m = max(m, d-c)
m = max(m, e-c)
m = max(m, e-d)
if m > k:
    print(":(")
else:
    print("Yay!")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int n,m,mapp[55][55],x[8]={1,1,1,-1,-1,-1,0,0},y[8]={0,1,-1,0,1,-1,1,-1};
inline int bfs(int a,int b){
	int cnt=0;
	for(register int i=0;i<8;i++){
		int l=a+x[i];
		int ll=b+y[i];
		if(l>=1&&l<=n&&ll>=1&&ll<=m){
			if(mapp[l][ll]=='#') cnt++;
		}
	}
	return cnt;
}
int main(){
	scanf("%d%d",&n,&m);
	for(register int i=1;i<=n;i++){
		for(register int j=1;j<=m;j++){
			scanf(" %c",&mapp[i][j]);
		}
	}
	for(register int i=1;i<=n;i++){
		for(register int j=1;j<=m;j++){
			if(mapp[i][j]=='#'){
				printf("#");
				continue;
			}
			printf("%d",bfs(i,j));
		}
		printf("\n");
	} 
}

Measured memory_bytes: 256
# 1行に1つの数字
n = int(input())
a = [input() for i in range(n)]

cnt = [0]*5

for x in a:
    if x[0] == "M": cnt[0] += 1
    if x[0] == "A": cnt[1] += 1
    if x[0] == "R": cnt[2] += 1
    if x[0] == "C": cnt[3] += 1
    if x[0] == "H": cnt[4] += 1
    
count = 0
for i in range(3):
    for j in range(i+1, 4):
        for k in range(j+1,5):
            count += cnt[i]*cnt[j]*cnt[k]

print(count)

Measured memory_bytes: 9776
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <unordered_map>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

//container util
//------------------------------------------
#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair

//repetition
//------------------------------------------
#define rep(i,n)  for(int i=0;i<(n);i++)


int main(){
    int n; cin>>n;
    vi h(n);
    rep(i, n)cin>>h[i];
    
    int dp[n];
    dp[0]=0;
    dp[1]=abs(h[1]-h[0]);
    for(int i=2;i<n;i++){
        dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout<<dp[n-1]<<endl;
    return 0;
}

Measured memory_bytes: 1024
x, n = map(int, input().split())
p = list(map(int, input().split()))

px = x + 1
mx = x - 1
if n == 0:
    print(x)
    exit()
elif x not in p:
    print(x)
    exit()

while True:
    if mx not in p:
        print(mx)
        exit()
    elif px not in p:
        print(px)
        exit()
    px += 1
    mx -= 1

Measured memory_bytes: 9144
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
#include <set>
using namespace std;
const int MOD = 1000000007;
const int INF = 1e9;
typedef long long ll;

int main(){
    string s;


    cin >> s;

    int n = s.length();

    int zero=0;
    int one=0;

    for(int i=0;i<n;i++){
        if(s[i]=='0'){
            zero++;
        }
        else{
            one++;
        }
    }

    int ans = 0;

    ans = n - abs(zero-one);

    cout << ans << endl;


}

Measured memory_bytes: 512
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        
           long a ;
           long b ;
           int i;
          
           
           for(i = 0;i<7;i++){
               a = scan.nextLong();
               b = scan.nextLong();
               System.out.println(a-b);
           }
           
        }

    }




Measured memory_bytes: 26260
"use strict"
function Main(input) {
  input = input.trim().split(' ').map(Number);
  let h = input[0];
  let a = input[1];

  let ans = 0;
  while(h>0){
    h = h-a
    ++ans;
  }

  console.log(ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 22080
#include <iostream>
#include <cstring>
#include <vector>
#include <set>
#include <list>
#include <map>
#include <deque>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
#define for1(i,n) for (ll i=0;i<(n);i++)
#define for2(i,m,n) for (ll i=(m);i<(n);i++)
#define for3(i,m,n,d) for (ll i=(m);i<(n);i+=(d))
#define DEBUG 0

void solve()
{
    ll N;
    vll D;
    cin >> N;
    for1(i,N) {
        ll d;
        cin >> d;
        D.push_back(d);
    }
    sort(D.begin(),D.end());

    ll N2 = N / 2;
    if (D[N2-1] == D[N2]) {
        cout << 0 << endl;
    } else {
        cout << D[N2] - D[N2-1] << endl;
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    do {
        solve();
    } while (DEBUG);
}


Measured memory_bytes: 1400
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

N,M = LI()

print(N*(N-1)//2 + M*(M-1)//2)

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;


long long c[5005][5005];
void init(int n){
    c[0][0] = 1;
    for ( int i = 0; i < n; i++ ){
        for ( int j = 0; j <= i; j++ ){
            c[i][j] %= MOD;
            c[i+1][j] += c[i][j];
            c[i+1][j+1] += c[i][j];
        }
    }
}
long long comb(long long n, long long k){
    return c[n][k];
}

int main(){
    init(5000);
    int N, K; cin >> N >> K;
    int red = N-K, blue = K;


    long long ans = 1;
    for( int i = 1; i <= K; i++ ){
        ans *= comb( red+1 , i );
        ans *= comb( blue - 1 , i - 1 );
        ans %= MOD;

        cout << ans << endl;
        ans = 1;
    }
}


Measured memory_bytes: 193920
#include<iostream>
using namespace std;
 
int main() {  
  int c[9];
  for(int i=0;i<9;i++){
    cin>>c[i];
  }
  int a2_a=(c[3]-c[0])-(c[4]-c[1]);
  int a2_b=(c[4]-c[1])-(c[5]-c[2]);
  int a3_a=(c[6]-c[0])-(c[7]-c[1]);
  int a3_b=(c[7]-c[1])-(c[8]-c[2]);
  
  if(a2_a==0&&a2_b==0&&a3_a==0&&a3_b==0)cout<< "Yes";
  else cout<<"No";
  
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		SC sc = new SC(System.in);
		int[] hrs=new int[13];
		Arrays.fill(hrs,0);
		int N=sc.nextInt();
		int [] times=new int[N+1];
		times[0]=0;
		for(int i=0; i<N; i++) {
			times[i+1]=sc.nextInt();
			hrs[times[i+1]]++;
		}
		/*
		 *
		 * 0時がある時点で最大が12時間。まぁという感じ
		 *
		 */
		int syurui=0;
		for(int i=0; i<=12; i++) {
			if(hrs[i]>0) {
				syurui++;
			}
		}
		for(int i=0; i<13; i++) {
			if(hrs[i]>2) {
				pl(0);
				System.exit(0);
			}
		}//同じ時差が3人以上いると、鳩ノ巣理論で0

		int determined=0;
		for(int i=0; i<13; i++) {
			if(hrs[i]==2) {
				determined++;
			}
		}
		int[] d=new int[determined];
		int cnt=0;
		for(int i=0; i<13; i++) {
			if(hrs[i]==2) {
				d[cnt]=i;
				cnt++;
			}
		}
		int[] calc=new int[N-determined];
		int counter=0;
		for(int i=0; i<13; i++) {
			if(hrs[i]==1) {
				calc[counter]=i;
				counter++;
			}
		}
		int[] locked=new int[determined*2+1];
		locked[0]=0;
		for(int i=0; i<determined; i++) {
			for(int j=0; j<2; j++) {
				locked[i*2+1]=d[i];
				locked[i*2+2]=24-d[i];
			}
		}
		int p=1;
		for(int i=0; i<N-determined; i++) {
			p*=2;
		}
		int[] sum=new int[N+1];
		int maxi=0;
		for(int i=0; i<p; i++) {
			for(int j=0; j<determined*2+1; j++) {
				sum[j]=locked[j];
			}
			int tmp=i;
			for(int j=0; j<N-determined*2; j++) {
				if(tmp%2==0) {
					sum[determined*2+1+j]=calc[j];
				}
				if(tmp%2==1) {
					sum[determined*2+1+j]=24-calc[j];
				}
				tmp/=2;
			}
			Arrays.sort(sum);
			int dif=24;
			for(int j=1; j<=N; j++) {
				dif=Math.min(dif, sum[j]-sum[j-1]);
			}
			dif=Math.min(dif, 24-sum[N]);
			maxi=Math.max(maxi, dif);
		}
		pl(maxi);
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
}

Measured memory_bytes: 22996
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include<math.h>

using namespace std;

int main() {
	int n;
	cin >> n;
	while (n!=0) {
		double s[1000] = {}, sum = 0,a = 0;
		for (int i = 0; i < n; i++) {
			cin >> s[i];
			sum += s[i];
		}
		for (int i = 0; i < n; i++)a += (s[i] - sum/n) * (s[i] - sum/n)/n;
		printf("%.8lf\n", sqrt(a));
		cin >> n;
	}
}


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

bool binary_search(int arr[], int begin, int end, int key)
{
	while(end > begin)
	{
		int middle = begin + ((end - begin) / 2);
		if (arr[middle] > key)
		{
			end = middle;
		}
		else if (arr[middle] < key)
		{
			begin = middle+1;
		}
		else
		{
			return true;
		}
	}
	return false;
}

int main ()
{
	//輸入
	int n, q;
	cin >> n;
	int S[n+1];
	for (int i = 0;i < n;i++)
	{
		cin >> S[i];
	}
	cin >> q;
	int T[q+1];
	for (int i = 0;i < q;i++)
	{
		cin >> T[i];
	}
	
	int C = 0; //ans
	//處理
	for (int i = 0;i < q;i++)
	{
		if (binary_search(S, 0, n, T[i]))
		{
			C++;
		}
	}
	
	//輸出 
	cout << C << endl;
	return 0;
}


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

int main(){
	int n;
	cin>>n;
	
	vector<int> L(n);
	for(int i=0;i<n;i++) cin>>L.at(i);
	
	sort(L.begin(),L.end());
	
	int sum=0;
	for(int i=0;i<n-1;i++) sum += L.at(i);
	
	if(L.at(n-1)>=sum) cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
}

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


signed main(){
	string s;
	int K, r[30] = {}, size, ma;
	vector<string> vs;
	set<string> ss;
	
	cin>>s;
	
	size = s.size();
	
	cin>>K;
	
	ma = min(size, K+1);
	
	rep(i, ma){
		for(int j = 0; i+j< size; j++){
			string temp;
			for(int k = 0; k <= i; k++){
				temp +=s[j+k];
			}
			// cout<<i<<" "<<temp<<endl;
			
			if(ss.count(temp) == 0){
				vs.push_back(temp);
				ss.insert(temp);
			}
		}
	}
	sort(vs.begin(), vs.end());

	cout<<vs[K-1]<<endl;
	
	return 0;
}


Measured memory_bytes: 2300
# coding:utf-8

import sys
from collections import defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7
dy = (0, -1, 0, 1)
dx = (1, 0, -1, 0)

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()


N, K = LI()
A = LI()

CA = [0]
for a in A:
    CA.append(CA[-1] + a)

sum_sub_array = defaultdict(int)
for l in range(N):
    for r in range(l + 1, N + 1):
        sub_sum = CA[r] - CA[l]
        sum_sub_array[sub_sum] += 1

ans = 0
for i in range(40)[::-1]:
    bit = 1 << i
    remain = 0
    new_sum_sub = {}
    for v, cnt in sum_sub_array.items():
        if v & bit > 0:
            remain += cnt
            new_sum_sub[v] = cnt

    if remain >= K:
        sum_sub_array = new_sum_sub
        ans |= bit

print(ans)


Measured memory_bytes: 56284
#include <cstdio>
#include <algorithm>
int N;
long long a[100001], b[100001], K, C, O;
long long L[10000001];
int T[10000001], ls[10000001], rs[10000001], n, root;
long long G(int x)
{
	int p = 1, l = 1, r = K;
	while (p && !T[p])
	{
		int m = l + r >> 1;
		if (x <= m)
			p = ls[p], r = m;
		else
			p = rs[p], l = m + 1;
	}
	return p ? L[p] + r - x : 0;
}
long long ANS(int p, int l, int r)
{
	if (!p)
		return 0;
	if (T[p])
		return L[p];
	int m = l + r >> 1;
	return std::min(ANS(ls[p], l, m), ANS(rs[p], m + 1, r));
}
void P(int &p, int l, int r, int L, int R, long long w)
{
	if (!p)
		p = ++n;
	if (L <= l && r <= R)
	{
		T[p] = 1;
		::L[p] = w + R - r;
		return;
	}
	int m = l + r >> 1;
	if (T[p])
	{
		if (!ls[p])
			ls[p] = ++n;
		if (!rs[p])
			rs[p] = ++n;
		T[ls[p]] = T[rs[p]] = 1;
		::L[ls[p]] = ::L[p] + r - m;
		::L[rs[p]] = ::L[p];
		T[p] = 0;
	}
	if (L <= m)
		P(ls[p], l, m, L, R, w);
	if (R > m)
		P(rs[p], m + 1, r, L, R, w);
}
int main()
{
	scanf("%d%lld", &N, &K);
	C = K;
	for (int i = 1; i <= N; i++)
	{
		scanf("%lld%lld", a + i, b + i);
		if (b[i] == 2)
			C = (C + a[i] + a[i] - 1) % K + 1;
		else
		{
			if (a[i] << 1 > K)
			{
				puts("-1");
				return 0;
			}
			int E = C;
			C = (C + a[i] + a[i] - 1) % K + 1;
			long long w = G(C);
			if (E < C)
				P(root, 1, K, E + 1, C, w);
			else
			{
				P(root, 1, K, 1, C, w);
				if (E < K)
					P(root, 1, K, E + 1, K, w + C);
			}
		}
	}
	O = ANS(1, 1, K);
	for (int i = 1; i <= N; i++)
		O += a[i] << 1;
	printf("%lld\n", O);
	return 0;
}


Measured memory_bytes: 53632
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    scanf("%d%d",&n,&k);
    string s;
    cin >> s;
    deque<int> dq;
    for (int i = 0; i < n; i++){
        dq.push_back(s[i]=='A'?0:1);
    }
    int flip = 0;
    int num = min(2*n,k);
    if (k > num){
        if ((n & 1) == 0){
            for (int i = 0; i < n; i++){
                printf("%c",(i&1)?'A':'B');
            }
        }
        else{
            k -= num;
            printf("%c",(k&1)?'A':'B');
            for (int i = 1; i < n; i++){
                printf("%c",(i&1)?'B':'A');
            }
        }
        return 0;
    }
    for (int i = 0; i < num; i++){
        if ((dq[0]^flip) == 0) {
            //printf("flip front %d %d\n",dq[0],flip);
            dq[0] ^= 1;
        }
        else{
            //printf("rotate");
            dq.pop_front();
            flip ^= 1;
            dq.push_back(flip);
        }
    }
    for (int i = 0; i < n; i++){
        printf("%c",(dq[i]^flip)?'B':'A');
    }
}


Measured memory_bytes: 1540
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = n;i >= m;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define ALL(n) n.begin(),n.end()

int main() {
	char s[4] = {};
	string a;
	REP(i, 4)cin >> s[i];
	cin >> a;
	REP(i, 4)cout << s[i];
	cout <<" " << a << endl;

}

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

using namespace std;

const int N = 105, MAX_W = 1e5 + 5;
int n, W;
long long dp[2][MAX_W];

int main () {
    scanf("%d %d", &n, &W);
    for (int i = 1; i <= n; ++i) {
        int w, v; scanf("%d %d", &w, &v);
        int lst = i & 1, nxt = lst ^ 1;
        for (int j = 0; j <= W; ++j) {
            dp[nxt][j] = dp[lst][j];
            if (j >= w) dp[nxt][j] = max(dp[nxt][j], dp[lst][j - w] + v);
        }
    }

    long long ans = 0;
    for (int i = 0; i <= W; ++i) ans = max(ans, dp[n & 1 ^ 1][i]);

    cout << ans;

    return 0;
}


Measured memory_bytes: 1792
# cook your dish here
import math 
for _ in range(1):
    a,b,h,m = map(float,input().split())
    theta1 = ((2*math.pi)*(h*60.00++m))/(12.00*60.00)
    theta2 = ((2*math.pi)*(h*60.00++m))/(60.00)
    theta = theta2 - theta1 
    theta %= (2*math.pi)
    print('%.20f'%math.sqrt(a*a+b*b-2*a*b*math.cos(theta)))
    
    
    

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

#define MAX_N 100000

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

  string s, t;
  cin >> s >> t;

  ll ls = s.size();
  ll lt = t.size();
  //front is s counter.
  vector<vll> sMap(26, vll(MAX_N + 1, 0));
  REP(i, ls){
    ll pt = s[i] - 'a';
    ll ct = sMap[pt][0];
    sMap[pt][ct+1] = i;
    sMap[pt][0]++;
  }

  bool sFlag = true;
  REP(i, lt){
    if(sMap[t[i]-'a'][0] == 0)
      sFlag = false;
  }

  if(!sFlag){
    cout << -1 << endl;
    return 0;
  }



  vll tMap(lt, 0);
  tMap[0] = sMap[t[0]-'a'][1];

  for(ll i = 1; i < lt; i++){
    sFlag = true;
    ll pt = t[i] - 'a';
    ll ct = sMap[pt][0];

    if(sMap[pt][ct] <= tMap[i-1]){
      tMap[i] = sMap[pt][1];
      continue;
    }


    ll ok = ct;
    ll ng = 0;
    while(ok - ng > 1){
      ll mid = (ok+ng)/2;
      if(sMap[pt][mid] > tMap[i-1])
        ok = mid;
      else
        ng = mid;
    }

    tMap[i] = sMap[pt][ok];
  }

  REP(i, lt-1){
    if(tMap[i+1] <= tMap[i])
      tMap[i+1] += ls * ((tMap[i]-tMap[i+1])/ls + 1);
    //cout << tMap[i+1] << endl;
  }

  cout << tMap[lt-1]+1 << endl;
}




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

long long int fastexpo(long long int a, long long int b)
{
    long long int ans = 1;
    while (b)
    {
        if (b & 1)
            ans = (ans * a) % mod;
        b = b / 2;
        a = (a * a) % mod;
    }
    return ans;
}
ll div1[10000007];

bool vis[10000007]; //vis1[10000007];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int n;
    cin >> n;
    int j = 1;
    div1[2] = 2;
    for (int i = 2; i <= n; i++)
    {

        if (vis[i * j] == 0)
            while (i * j <= n)
            {
                //div1[i] = i;
                div1[i * j] = i;
                vis[i * j] = 1;
                j++;
            }
        j = 1;
    }
    // cerr << "ckid"
    //    << "\n";
    //  cout << vis[15] << "\n";
    vector<ll> vec;
    ll max1 = 0;
    ll ans = 1;
    for (int i = 2; i <= n; i++)
    {
        if (!vis[i])
            ans += 2 * i;
        else
        {
            //cout << i << "\n";
            ll p = i;
            ll sum = 1;

            map<ll, ll> cm;
            vector<ll> vec;
            while (p > 1)
            {
                int k = div1[p];
                p /= div1[p];

                vec.push_back(k);
            }
            max1 = max(max1, (ll)vec.size());
            for (int j : vec)
                ++cm[j];
            for (auto &dup : cm)
                sum *= (dup.second + 1);
            // cout << sum << "\n";
            ans += i * (sum);
        }
    }

    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 91496
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
ll n,k;
ll h[100001];
ll dp[100001];

ll jump()
{
    dp[1] = 0;
    for(int i=1; i<=n; i++)
    {
        for(ll j=1; j<=k && (i+j)<=n; j++)
        {
            dp[i+j] =  min(dp[i+j], dp[i]+ abs(h[i]-h[i+j]));
        }
    }
    //cout<<dp[1];
    return dp[n];
}

int main()
{
    cin>>n>>k;
    //cout<<n<<k<<"\n";
    for(int i=1; i<=100000; i++)
        dp[i] = INT_MAX;

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

    cout<<jump()<<"\n";

    return 0;
}


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

namespace ABC_Training
{
    public class Program
    {
        static void Main(string[] args)
        {
            var nk = Console.ReadLine().Split(' ');
            var n = int.Parse(nk[0]);
            var k = int.Parse(nk[1]);

            var ans = 1;

            while (n >= k)
            {
                n = n / k;
                ans++;
            }
            Console.WriteLine(ans);
        }
    }
}


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

int main(){
  int k,x;
  cin>> k >> x;
  
  for(int i = x-k+1; i <= x+k-1; i++) cout << i << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <string>    
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
ll h, w, n, sr, sc;
string s, t;

int main(){
	cin >> h >> w >> n >> sr >> sc >> s >> t;
	
	ll dp[4];
	dp[0] = 0;
	dp[1] = 0;
	dp[2] = 0;
	dp[3] = 0;
	
	string ans = "YES";
	for(ll i = n-1; i >= 0; i--){
		if(s[i] == 'L'){dp[0]++;}
		if(s[i] == 'R'){dp[1]++;}
		if(s[i] == 'U'){dp[2]++;}
		if(s[i] == 'D'){dp[3]++;}
		
		if(dp[0]+dp[1] >= w || dp[2]+dp[3] >= h){
			ans = "NO";
			break;
		}
		if(i != 0){
			if(t[i-1] == 'L'){dp[1] = max(dp[1]-1, 0LL);}
			if(t[i-1] == 'R'){dp[0] = max(dp[0]-1, 0LL);}
			if(t[i-1] == 'U'){dp[3] = max(dp[3]-1, 0LL);}
			if(t[i-1] == 'D'){dp[2] = max(dp[2]-1, 0LL);}
		}
	}
	if(sc <= dp[0] || w-sc+1 <= dp[1] || sr <= dp[2] || h-sr+1 <= dp[3]){
		ans = "NO";
	}

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

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

int n, q, a, b;
int x[100000], sum;

int main() {
	cin >> n >> q;
	for (int i = 0; i < q; i++) {
		cin >> a >> b;
		for (int j = a; j < b; j++) {
			x[j] = 1;
		}
	}
	for (int i = 0; i < n; i++) {
		sum += 1 + x[i] * 2;
	}
	cout << sum + 1 << endl;
	return 0;
}

Measured memory_bytes: 1172
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;

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

const int MAXN = 500+10;
int a[MAXN][MAXN];
int b[MAXN][MAXN];
int ans[MAXN][MAXN];

void init(){
	memset(a,0,sizeof(a));
	memset(b,0,sizeof(b));
	memset(ans,0,sizeof(ans));
}
int main() {
    int n,m,q;
    scanf("%d %d %d",&n,&m,&q);
    init();
    for(int i=0;i<m;i++){
        int l,r;
        scanf("%d %d",&l,&r);
        a[l][r]++;
    }
    
    for(int j=1;j<=n;j++){
        b[j][j]=a[j][j];
        for(int i=j-1;i>=1;i--){
          b[i][j]=b[i+1][j]+a[i][j];  
        }
    }
    
    for(int i=1;i<=n;i++){
        ans[i][i]=a[i][i];
        for(int j=i+1;j<=n;j++){
            ans[i][j]=ans[i][j-1]+b[i][j];
        }
    }
    while(q--){
        int li,ri;
        scanf("%d %d",&li,&ri);
        printf("%d\n",ans[li][ri]);
    }
    return 0;
}

Measured memory_bytes: 3968
#include "bits/stdc++.h"
using namespace std;
const int maxn = 200200;
const int mod = 1000000007;
int main(){
  map<char, int> u;
  string s;
  long long ans = 0;
  int n; 
  cin >> n >> s;
  for(int i = 0; i < n; i++){
    u[s[i]]++;
  }
  ans = 1;
  for(auto it : u){
    ans *= it.second + 1;
    ans %= mod;
  }
  ans += mod - 1;
  ans %= mod;
  cout << ans << endl;
  return 0;
}


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

char F[10][10];

int main(){
  int H, W, K;
  cin >> H >> W >> K;
  rep(i, H){
    rep(j, W){
      cin >> F[i][j];
    }
  }

  int ans = 0;

  // bit全探索の開始
  // 外側はH
  rep(bits_H, 1<<H){
    // hを選ぶかどうか
    bool flag_H[H];
    rep(h, H){
      // bits_Hに順列の情報が入っている
      if (bits_H & (1<<h)) flag_H[h] = true;
      else flag_H[h] = false;
    }
    // 内側はW
    rep(bits_W, 1<<W){
        // Fを破壊しないようにコピーGを毎回作成する
        char G[10][10];
        rep(h, H){
          rep(w, W){
            G[h][w] = F[h][w];
          }
        }

        // wを選ぶかどうか
        bool flag_W[W];
        rep(w, W){
          // bits_Wに順列の情報が入っている
          if (bits_W & (1<<w)) flag_W[w] = true;
          else flag_W[w] = false;
        }

      // bitsの情報に応じてコピーしたGを条件通りに書き換えていく
      rep(h, H){
        if (flag_H[h]==true)
        rep(w, W){
          G[h][w] = '-';
        }
      }
      rep(w, W){
        if (flag_W[w]==true)
        rep(h, H){
          G[h][w] = '-';
        }
      }

      // #の個数が条件に一致するかどうかを調べる
      int check = 0;
      rep(h, H){
        rep(w, W){
          if (G[h][w] == '#') check++;
        }
      }
      // もし条件に合っていればansを1増やす
      if (check==K) ans++;
    }
  }
  cout << ans << endl;
}

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

int main()
{
    int n, k;

    while( cin >> n >> k )
    {
        if( n + k == 0 )
            break;

        bool a[n+1];
        for( int i = 0; i <= n; i++ )
            a[i] = 0;

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

        int m = 0, cnt1 = 0, cnt2 = 0;
        if( a[0] )
        {
            for( int i = 1; i <= n; i++ )
            {
                if( !a[i] )
                {
                    int j = i + 1;
                    while( j <= n && a[j] )
                    {
                        cnt2++;
                        j++;
                    }
                    m = max( m, cnt1 + cnt2 + 1 );
                    cnt1 = cnt2;
                    cnt2 = 0;
                    i = j - 1;
                }
                else
                    cnt1++;
            }
            if( cnt1 > 0 )
                m = max( m, cnt1 + 1 );
        }
        else
        {
            for( int i = 1; i <= n; i++ )
            {
                if( !a[i] )
                {
                    m = max( m, cnt1 );
                    cnt1 = 0;
                }
                else
                    cnt1++;
            }
        }
        cout << m << endl;
    }

    return 0;
}


Measured memory_bytes: 3148
n = int(input())
s = str(input())
A = [0]
cum = 0
ans = ''
for i in range(n):
    if s[i] == '(':
        cum += 1
    else:
        cum -= 1
    if cum == -1:
        ans = '('+ans
        ans += s[i]
        cum = 0
    else:
        ans += s[i]
else:
    if cum > 0:
        ans += ')'*cum
print(ans)

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

int main() {
  int n;
  cin >> n;
  vector<vector<P>> g(n);
  rep(i,n-1){
    int u,v,w;
    cin >> u >> v >> w;
    --u; --v; w%=2;
    g[u].emplace_back(v,w);
    g[v].emplace_back(u,w);
  }

  vector<int> ans(n,-1);
  ans[0] = 0;
  queue<int> q;
  q.emplace(0);
  while (!q.empty()){
    int v = q.front(); q.pop();
    for(P p:g[v]){
      int u = p.first, w = p.second;
      if(ans[u]!=-1) continue;
      if(w==1){
        ans[u] = ans[v]^1;
      }else{
        ans[u] = ans[v];
      }
      q.emplace(u);
    }
  }
  rep(i,n) printf("%d\n",ans[i]);
}

Measured memory_bytes: 6784
package main

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

func main() {
	stdin := bufio.NewScanner(os.Stdin)
	stdin.Scan()
	text := strings.Split(stdin.Text(), " ")
	out := Run(text)
	fmt.Println(out)
}

func Run(data []string) string {
	var (
		a, _ = strconv.ParseInt(data[0], 10, 64)
		p, _ = strconv.ParseInt(data[1], 10, 64)
	)
	ret := ((a * 3) + p) / 2
	return strconv.FormatInt(ret, 10)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define MAX_H 2000
#define MAX_W 2000

vector<string> floor_map(MAX_H);
vector<vector<int>> right_lighted(MAX_H, vector<int>(MAX_W));
vector<vector<int>> left_lighted(MAX_H, vector<int>(MAX_W));
vector<vector<int>> up_lighted(MAX_H, vector<int>(MAX_W));
vector<vector<int>> down_lighted(MAX_H, vector<int>(MAX_W));

int main(){
  int high, wide;
  cin >> high >> wide;
  for(int h = 0; h < high; h++){
    cin >> floor_map[h];
  }
  
  //search right
  int count = 0;
  for(int h = 0; h < high; h++){
    for(int w = 0; w < wide; w++){
      if(floor_map[h][wide-1-w] == '#')
        right_lighted[h][wide-1-w] = 0;
      else if(w == 0)
        right_lighted[h][wide-1-w] = 1;
      else
        right_lighted[h][wide-1-w] = right_lighted[h][wide-w] + 1;
    }
  }
  
  //search left
  for(int h = 0; h < high; h++){
    for(int w = 0; w < wide; w++){
      if(floor_map[h][w] == '#')
        left_lighted[h][w] = 0;
      else if(w == 0)
        left_lighted[h][w] = 1;
      else
        left_lighted[h][w] = left_lighted[h][w-1] + 1;
    }
  }
  
  //search up
  for(int w = 0; w < wide; w++){
    for(int h = 0; h < high; h++){
      if(floor_map[h][w] == '#')
        up_lighted[h][w] = 0;
      else if(h == 0)
        up_lighted[h][w] = 1;
      else
        up_lighted[h][w] = up_lighted[h-1][w] + 1;
    }
  }
  
  //search down
  for(int w = 0; w < wide; w++){
    for(int h = 0; h < high; h++){
      if(floor_map[high-1-h][w] == '#')
        down_lighted[high-1-h][w] = 0;
      else if(h == 0)
        down_lighted[high-1-h][w] = 1;
      else
        down_lighted[high-1-h][w] = down_lighted[high-h][w] + 1;
    }
  }
  
  int sum = 0;
  int sum_max = 0;
  for(int h = 0; h < high; h++){
    for(int w = 0; w < wide; w++){
      sum = right_lighted[h][w] + left_lighted[h][w] \
        + up_lighted[h][w] + down_lighted[h][w] - 3;
      if(sum_max < sum)
        sum_max = sum;
    }
  }

    cout << sum_max << endl;
}




Measured memory_bytes: 67200
#include <stdio.h>

int cmpfunc (const void * a, const void * b)
{
   return ( *(int*)a - *(int*)b );
}

int main()
{
    int a[4], b, c, ans=0, i, j, k, max, max2, max3;
    scanf("%d %d %d", &a[0], &a[1], &a[2]);

    qsort (a, 3, sizeof(int), cmpfunc);
    max = a[2];
    max2= a[1];
    max3= a[0];
    ans = max - max2;
    max3 += ans;
    if ((max - max3)%2 != 0)
    {
        ans = ans +((max-max3)/2)+2;
   //     printf("Here 1\n");
    }
    else
    {
        ans = ans + ((max-max3)/2);
   //     printf("Here 2\n");
    }
    printf("%d", ans);
    return 0;

}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main (void)
{
 int ans = 700;
  string s;
  
  cin >> s;

  for(int i = 0;i < 3;i++){
    if(s[i] == 'o'){
      ans += 100;
    }
  }

  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 256
# import itertools
# import math
# import sys
# sys.setrecursionlimit(500*500)
# import numpy as np
# import heapq
# from collections import deque
# import sympy

N = int(input())
# S = input()
# n, *a = map(int, open(0))
# N, M = map(int, input().split())
A = list(map(int, input().split()))
# B = list(map(int, input().split()))
# tree = [[] for _ in range(N + 1)]
# B_C = [list(map(int,input().split())) for _ in range(M)]
# S = input()

# B_C = sorted(B_C, reverse=True, key=lambda x:x[1])
# all_cases = list(itertools.permutations(P))
# a = list(itertools.combinations_with_replacement(range(1, M + 1), N))
# itertools.product((0,1), repeat=n)

# A = np.array(A)
# cum_A = np.cumsum(A)
# cum_A = np.insert(cum_A, 0, 0)

# def dfs(tree, s):
#     for l in tree[s]:
#         if depth[l[0]] == -1:
#             depth[l[0]] = depth[s] + l[1]
#             dfs(tree, l[0])
# dfs(tree, 1)

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

A.insert(0, 0)
B = [0] * (N + 1)

for i in range(N, 0, -1):
    j = 1
    cnt = 0
    while(i * j <= N):
        cnt += B[i * j]
        j += 1
    flg = cnt % 2
    if A[i] != flg:
        B[i] = 1

# print(B)
print(sum(B))
for i, b in enumerate(B):
    if b == 1:
        print(i)

Measured memory_bytes: 12336
#include <iostream>
#include <vector>
#include <algorithm>
#include <complex>
using namespace std;
int main(void){
    int N;
    double T,A;
    int H[1001];
    vector<double> diff;
    cin>>N>>T>>A;
    
    for(int i=0;i<N;i++){
        cin>>H[i];
        diff.emplace_back(abs(T-0.006*H[i]-A));
    }
    int min=min_element(diff.begin(),diff.end())-diff.begin();
    
    printf("%d",min+1);
    
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){

    int W,H,x,y,r;

    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
    if(0<=(x-r) && (x+r)<=W && 0<=(y-r) && (y+r)<=H) {
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 2112
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s,t;
    cin>>s>>t;

    int l1=s.size();
    int l2=t.size();

    int dp[l1+1][l2+1];

    for(int i=0;i<=l2;i++)
    {
        dp[0][i]=0;
    }
    for(int i=0;i<=l1;i++)
    {
        dp[i][0]=0;
    }

    for(int i=1;i<=l1;i++)
    {
        for(int j=1;j<=l2;j++)
        {
            if(s[i-1]==t[j-1])
            {
                dp[i][j]=1+dp[i-1][j-1];
                //cout<<i<<", "<<j<<" "<<dp[i][j]<<endl;
            }
            else
            {
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
                //cout<<i<<", "<<j<<" "<<dp[i][j]<<endl;
            }
        }
    }

    vector<char>common;

    int i=l1;
    int j=l2;
    while(i>0 && j>0)
    {

        if(s[i-1]==t[j-1])
        {
            common.push_back(s[i-1]);
            i--;
            j--;
        }
        else
        {
            if(dp[i][j]==dp[i-1][j])
            {
                i--;
            }
            else
            {
                j--;
            }
        }
    }
    for(int i=common.size()-1;i>=0;i--)
        cout<<common[i];
    return 0;
}


Measured memory_bytes: 35456
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
const ll MOD=1000000007;

int main() {
    int N,T;
    cin >> N >> T;
    vector<int> A(N);
    rep(i,N){
        cin >> A[i];
    }
    vector<int> B(N);
    B[N-1]=A[N-1];
    for (int i=N-2;i>=0;i--){
        B[i]=max(B[i+1],A[i]);
    }
    rep(i,N){
        B[i]-=A[i];
    }
    map<int,int> m;
    int M=0;
    rep(i,N){
        M=max(M,B[i]);
        m[B[i]]++;
    }
    cout << m[M] << endl;
}

Measured memory_bytes: 5760
def priority_push(array:, num:)
  index = array.bsearch_index { |i| i > num}
  if index.nil?
    array.push(num)
  else
    array.insert(index, num)
  end
end

N = gets.to_i
arr = gets.split.map(&:to_i)
arr = arr.sort

while arr.count > 1
  a = arr.shift
  b = arr.shift
  priority_push(array: arr, num: Rational(a + b, 2))
end

puts arr[0].to_f

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 2e3+10;
const int MOD = 1e9+7;
int a[maxn] , b[maxn];
LL dp[maxn][maxn];
int main()
{
  int n,m;
  scanf("%d%d",&n,&m);
  for(int i = 1 ; i <= n ; i++) scanf("%d",&a[i]);
  for(int i = 1 ; i <= m ; i++) scanf("%d",&b[i]);
  for(int i = 0 ; i <= n ; i++) dp[i][0] = 1;
  for(int i = 0 ; i <= m ; i++) dp[0][i] = 1;
  for(int i = 1 ; i <= n ; i++)
  {
    for(int j = 1 ; j <= m ; j++)
    {
      dp[i][j] = ((dp[i-1][j] + dp[i][j-1]) % MOD - dp[i-1][j-1]) % MOD;
      if(a[i] == b[j])
      {
        dp[i][j] = (dp[i][j] + dp[i-1][j-1]) % MOD;
      }
    }
  }
  cout<<((dp[n][m] % MOD) + MOD) % MOD<<endl;
}

Measured memory_bytes: 31744
#include <iostream>
#include <cstdio>
using namespace std;
int main() {
    long long X;
    cin >> X;
    int time = 0;
    long long cur = 100;
    while (cur < X) {
        ++time;
        cur = cur + cur / 100;
    }
    cout << time << endl;
    return 0;
}


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

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

  vector<int> d;
  int x;
  for(int i = 0; i < N; i++){
    cin >> x;
    d.push_back(x);
  }

  sort(d.begin(), d.end());

  int cnt = 1;
  for(int i = 1; i < N; i++){
    if(d[i - 1] < d[i]) cnt++;
  }

  cout << cnt << endl;

  return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
constexpr int MOD = 1000000007;

int mod(const ll &x){
    return x > 0 ? x % MOD : (x+MOD) % MOD;
}

int modm(const ll &x,const ll &m){
    return (x % MOD) * (m % MOD) % MOD;
}

int modpow(ll x, ll p) {
    int ret = 1;
    while(p > 0) {
        if (p & 1) ret = modm(ret,x);
        x = modm(x,x);
        p >>= 1;
    }
    return ret;
}

// x * modinv(d)
int modd(ll x,ll d) {
    return modm(x,modpow(d,MOD-2));
}

int main(void)
{
    IOS
    const int C = 26;
    int n; cin >> n;
    string s; cin >> s;
    vector<int> a(C);
    REP(i,n) a[s[i] - 'a']++;
    ll ans = 1;
    REP(i,C) ans = modm(ans,a[i]+1);
    ans = mod(ans-1);

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long n,m,i,j,k;
    long long t;
    long long a[7];
    for(i=0;i<5;i++){
        cin>>a[i];
    }
    cin>>k;
    for(i=0;i<4;i++){
        for(j=i+1;j<5;j++){
            if(abs(a[i]-a[j])>k){
                cout<<":("<<endl;
                return 0;

            }
        }
    }
    cout<<"Yay!"<<endl;

}


Measured memory_bytes: 256
import java.util.*;
import static java.lang.System.*;

public class Main {
	public static void main(String[] args) {
	    Scanner sc = new Scanner(in);
	    int A = sc.nextInt(), B = sc.nextInt(), K = sc.nextInt();
	    Set<Integer> set = new HashSet<>();
	    
	    for (int i=0; i<Math.min(K,B-A+1); i++) {
	        set.add(A+i);
	        set.add(B-i);
	    }
	    ArrayList<Integer> list = new ArrayList<Integer>(set);
	    Collections.sort(list);
	    for (int j=0; j<list.size(); j++)
	        out.println(list.get(j));
	}
}

Measured memory_bytes: 36024
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>
#include<random>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, -1, 0, 1};
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

const int MAXN = 100100;
int cnt[MAXN];
bool flag[MAXN];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    for (int i = 0; i < N; i++) {
        cnt[i] = 1;
    }
    flag[0] = true;
    for (int i = 0; i < M; i++) {
        int x, y;
        cin >> x >> y;
        x--; y--;
        cnt[y]++;
        if (flag[x]) flag[y] = true;
        cnt[x]--;
        if (cnt[x] == 0) flag[x] = false;
    }
    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (flag[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 768
//#define TEST
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
class Program{
    static void Main(){
        int n = int.Parse(Console.ReadLine());
        long[] a = Console.ReadLine().Split().Select(long.Parse).ToArray();
        long[] b = Console.ReadLine().Split().Select(long.Parse).ToArray();;
        if (a.Sum() < b.Sum()){
            Console.WriteLine(-1);
            return;
        }
        Pair[] p = new Pair[n];
        for (int i = 0;i < n;i++)
            p[i] = new Pair(a[i],b[i]);
        Comparer c = new Comparer();
        Array.Sort(p,c);
        int d = n;
        for (int i = 0;i < n;i++){
            if (p[i].a - p[i].b < 0){
                d = i;
                break;
            }
        }
#if TEST
        Console.WriteLine(d);
#endif
        int s = 0;
        while (d < n){
            long gs = p[s].a - p[s].b;
            p[s].a = p[s].b;
            if (gs > p[d].b - p[d].a){
                gs -= p[d].b - p[d].a;
                p[d].a = p[d].b;
                d++;
            }
            else if (gs < p[d].b - p[d].a){
                p[d].a += gs;
                gs = 0;
                s++;
            }
            else{
                p[d].a = p[d].b;
                gs = 0;
                s++;
                d++;
            }
            p[s].a += gs;
        }
        D(p);
        int ans = 0;
        for (int i = 0;i < n;i++)
            if (p[i].a != p[i].a_save)
                ans++;
        Console.WriteLine(ans);
    }
    [Conditional("TEST")]
    static void D(Pair[] p){
        foreach (var pa in p)
            Console.Write("{0} ",pa.a_save);
        Console.WriteLine();
        foreach (var pa in p)
            Console.Write("{0} ",pa.b);
        Console.WriteLine();
        foreach (var pa in p)
            Console.Write("{0} ",pa.a);
        Console.WriteLine();
    }
}
struct Pair{
    public long a_save;
    public long a;
    public long b;
    public Pair(long a,long b){
        this.a_save = a;
        this.a = a;
        this.b = b;
    }
}
class Comparer : IComparer<Pair>{
    public int Compare(Pair p1, Pair p2){
        long q1 = p1.a - p1.b;
        long q2 = p2.a - p2.b;
        if (q1 > q2) return -1;
        if (q1 < q2) return 1;
        return 0;
    }
}

Measured memory_bytes: 37812
A1=list(map(int,input().split()))
A2=list(map(int,input().split()))
A3=list(map(int,input().split()))
n = int(input())
B = [int(input()) for i in range(n)]
A = [A1,A2,A3]
ans = [[0,0,0],[0,0,0],[0,0,0]]
for b in B:
  for i in range(3):
    for j in range(3):
      if A[i][j] == b:
        ans[i][j] = 1
for i in range(3):
  if ans[i][0] and ans[i][1] and ans[i][2]:
    print("Yes")
    quit()
  if ans[0][i] and ans[1][i] and ans[2][i]:
    print("Yes")
    quit()
if ans[0][0] and ans[1][1] and ans[2][2]:
  print("Yes")
  quit()
if ans[0][2] and ans[1][1] and ans[2][0]:
  print("Yes")
  quit()
print("No")

Measured memory_bytes: 9228
v[50],p,n;f(X){for(;n<X;n+=v[p++]);n=50*(n-X);}main(s){for(;n=atoi(gets(v));printf("%d\n",s)){for(p=s=0;p<n;v[++p]=strlen(gets(v+n)));for(;n;)n=0,p=++s,f(5),f(7),f(5),f(7),f(7);}}

Measured memory_bytes: 532