akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define mp make_pair
#define pb push_back
#define ff first
#define ss second

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

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

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

int main(){
    string g;
    cin >> g;
    vector<string> ans = {
        "AKIHABARA",
        "AKIHABAR",
        "AKIHABRA",
        "AKIHABR",
        "AKIHBARA",
        "AKIHBAR",
        "AKIHBRA",
        "AKIHBR",
        "KIHABARA",
        "KIHABAR",
        "KIHABRA",
        "KIHABR",
        "KIHBARA",
        "KIHBAR",
        "KIHBRA",
        "KIHBR"
    };
    int ok = 0;
    for(int j = 0; j < ans.size(); j++){
        if(g == ans[j]) ok = 1;
    }
    if(ok){
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

}


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

const int N = 1e5+10;
const int INF = 1e18+10;
int h[N];
int dp[N];

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

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

  fill(dp,dp+N,INF);
  dp[0] = 0;
  for(int i = 0; i < n; i++){
    for(int j = 1; j <= k; j++){
      if(i+j < n) dp[i+j] = min(dp[i+j],dp[i] + abs(h[i+j]-h[i]));
    }
  }
  cout << dp[n-1] << endl;

  return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    vector<int> V(N);
    rep(i,0,N)cin >> V[i];
    sort(V.begin(), V.end());
    int mi = V[N/2-1];
    int ma = V[N/2];
    cout << ma - mi << endl;
}

Measured memory_bytes: 640
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	h := make([]int, n)
	for i := 0; i < n; i++ {
		h[i] = nextInt()
	}

	res := 0
	for {
		// すべての要素の高さが0になったら終了
		if maxElement(h) == 0 {
			break
		}

		// 区間分割する
		i := 0
		for i < n {
			if h[i] == 0 {
				i++
			} else {
				res++
				for i < n && h[i] > 0 {
					h[i]--
					i++
				}
			}

		}

	}

	fmt.Println(res)

	// res := make([]int, n)

	// left := 0
	// ans := 0
	// for {
	// 	// ?	fmt.Printf("%d回目 %+v\n", left, res)
	// 	if left == n {
	// 		break
	// 	}
	// 	if res[left] == h[left] {
	// 		left++
	// 	}

	// 	// var flag bool
	// 	for i := left; i < n; i++ {
	// 		if res[i] < h[i] {
	// 			res[i]++
	// 			// flag = true
	// 		} else {
	// 			break
	// 			// left++
	// 			// flag = false
	// 		}
	// 	}

	// 	ans++
	// if flag {
	// 	ans++
	// } else {
	// 	ans += h[left] - res[left]
	// 	res[left] += h[left] - res[left]
	// 	left++
	// }

	// }

	// fmt.Println(res)
	// fmt.Println(ans)
}

func maxElement(a []int) int {
	max := a[0]
	for i := 1; i < len(a); i++ {
		if max < a[i] {
			max = a[i]
		}
	}
	return max
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define All(a) a.begin(),a.end()
#define INF 10*9+7

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

int main(){
  int k; cin >>k;
  int ans = 0;
  int cnt = 0;
  for(int a=1;a<=k;a++){
    for(int b=1;b<=k;b++){
      int tmp = gcd(a,b);
      for(int c=1;c<=k;c++){
        ans += gcd(tmp,c);
      }
    }
  }
  cout<< ans <<endl;
}


Measured memory_bytes: 3612
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using ll = long long;
#define rep(inc, bgn, end) for (int inc = bgn; inc < end; ++inc)
#define repe(inc, bgn, end) for (int inc = bgn; inc <= end; ++inc)

using namespace std;

#define PI 3.141592

int main() {
    int n, q;
    cin >> n >> q;

    string s;
    cin >> s;

    // vector<int> ac;
    vector<int> accnt(n);

    // n
    rep(i, 0, n) {
        if (s[i] == 'A' && s[i + 1] == 'C') {
            if (i == 0) {
                accnt[i] = 1;
            } else {
                accnt[i] = accnt[i - 1] + 1;
            }
        } else {
            if (i == 0) {
                accnt[i] = 0;
            } else {
                accnt[i] = accnt[i - 1];
            }
        }
    }

    // rep(i, 0, n) {
    //     cout << accnt[i];  //<< " ";
    // }

    // q
    rep(i, 0, q) {
        int l, r;
        cin >> l >> r;
        l--;
        r--;

        int cnt = accnt[r] - accnt[l] + 1;
        // lがacの間
        if (accnt[l - 1] == accnt[l]) {
            cnt--;
        }
        if (accnt[r - 1] != accnt[r]) {
            cnt--;
        }

        cout << cnt << endl;
    }

    return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define each(a,x) for(auto a : (x))
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) ((a) = min((a),(b)))
#define chmax(a,b) ((a) = max((a),(b)))
#define in_range(x,l,r) ((l)<=(x) && (x)<(r))
#define printvec(a) rep(i,a) cout << a[i] << " \n"[i+1==(a).size()];
#define fs first
#define sc second
#define em emplace
#define eb emplace_back
#define sz size()
#define MP make_pair
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;

const ll INF = 1e8;
const D EPS = 1e-8;
const ll MOD = 1e9+7;

int main(){
  ll n;
  cin >> n;
  vl a(n), acc(n+1,0);
  rep(i,n) cin >> a[i];
  sort(all(a));
  rep(i,n) acc[i+1] = acc[i] + a[i];

  rrep(i,n){
    if(acc[i]*2 < a[i]) {
      cout << n-i << endl;
      return 0;
    }
  }
  cout << n << endl;
}


Measured memory_bytes: 1920
import sys
def input():
    return sys.stdin.readline()[:-1]
  
def perm(n, k, p):
  ret = 1
  for i in range(n, n-k, -1):
    ret = (ret * i)%p
  return ret

def comb(n, k, p=1000000007):
  a = perm(n, k, p)
  b = perm(k, k, p)
  return (a*pow(b, p-2, p))%p

def main():
    mod = 1000000007
    n,a,b = map(int, input().split())
    ans = pow(2,n,mod) - 1 - comb(n,a) - comb(n,b)
    print(ans%mod)

if __name__ == "__main__":
    main() 

Measured memory_bytes: 3064
#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <set>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define lamsort(v,p) sort(v.begin(),v.end(),[](p a, p b){return a.num < b.num;});
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define INF 1e8
typedef long long ll;
using namespace std;

int main() {
    ll n; cin >> n;
    vector<ll> v(n);
    ll all = 0;
    rep(i,n) {
        cin >> v[i];
        all += v[i];
    }
    ll ans = 1LL<<60;
    ll left = 0;
    ll right = all;
    rep(i,n-1) {
        left += v[i];
        right -= v[i];
        ans = min(ans,max(left,right)-min(left,right));
    }
    cout << ans << endl;



    return 0;
}

Measured memory_bytes: 1792
from heapq import heappush, heappop
from string import digits
import sys
readline = sys.stdin.readline
write = sys.stdout.write
dd = ((-1, 0), (0, -1), (1, 0), (0, 1))

INF = 10**9
while 1:
    X, Y = map(int, readline().split())
    if X == Y == 0:
        break
    MP = [readline().split() for i in range(Y)]
    N = int(readline())
    I = [[] for i in range(10)]
    for i in range(N):
        g, d, s, e = map(int, readline().split())
        if s < e:
            I[g].append((i, d, s, e))
    for ss in I:
        ss.sort(key=lambda x: x[1])
    V = [0]*(1 << N)
    for state in range(1 << N):
        v = 0
        for ss in I:
            x = 0
            for i, d, s, e in ss:
                if state & (1 << i):
                    x = d
            v += x
        V[state] = v

    U = [[None]*X for i in range(Y)]
    sx = sy = 0
    for i in range(Y):
        for j in range(X):
            c = MP[i][j]
            if c in digits:
                continue
            if c == 'P':
                sy = i; sx = j
            s = set()
            for dx, dy in dd:
                nx = j + dx; ny = i + dy
                if not 0 <= nx < X or not 0 <= ny < Y:
                    continue
                c = MP[ny][nx]
                if c in digits:
                    for e in I[int(c)]:
                        s.add(e)
            U[i][j] = s

    D = [[[INF]*(1 << N) for i in range(X)] for j in range(Y)]
    que = [(0, 0, sx, sy)]
    D[sy][sx][0] = 0
    while que:
        cost, state, x, y = heappop(que)
        D0 = D[y][x]
        t = D0[state]
        if t < cost:
            continue
        for i, d, s, e in U[y][x]:
            if t < e and state & (1 << i) == 0:
                t0 = max(s, t)
                n_state = state | (1 << i)
                if t0 < D0[n_state]:
                    D0[n_state] = t0
                    heappush(que, (t0, n_state, x, y))
        for dx, dy in dd:
            nx = x + dx; ny = y + dy
            if not 0 <= nx < X or not 0 <= ny < Y or U[ny][nx] is None:
                continue
            if t+1 < D[ny][nx][state]:
                D[ny][nx][state] = t+1
                heappush(que, (t+1, state, nx, ny))
    ans = 0
    for x in range(X):
        for y in range(Y):
            D0 = D[y][x]
            for state in range(1 << N):
                if D0[state] < INF:
                    ans = max(ans, V[state])
    write("%d\n" % ans)



Measured memory_bytes: 8780
def ABC_43_B():
    s = input()
    t=[]

    for i in range(len(s)):
        if s[i] == '0':
            t.append('0')
        elif s[i] == '1':
            t.append('1')
        else:
            if len(t)==0:
                a=0
            else:
                del t[len(t)-1]

    print(''.join(t))



if __name__ == '__main__':

    ABC_43_B()

Measured memory_bytes: 3060
#include<stdio.h>

int main(void) {
    int sum = 0;

    int i, score;
    for(i = 0; i < 5; i++) {
        scanf("%d", &score);
        if(score >= 40) sum += score;
        else            sum += 40; 
    }   

    printf("%d\n", sum / 5);                                                                                                                                             

    return 0;
}

Measured memory_bytes: 600
#include <stdio.h>
#include <string.h>

#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <functional>

using namespace std;

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

    double t, x;
    cin >> t >> x;

    cout << t/x; 

    return 0;
}

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

int main() {
    int a,b,c,s=0;
    cin>>a>>b>>c;
    for(int i=a;i<b+1;i++){
      if(c%i==0)s++;
    }
    cout<<s<<endl;
}


Measured memory_bytes: 3112
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(int)>

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ENDL '\n'
#define print(i) std::cout << (i) << '\n'

#define int long long // at least int64 > 9*10^18
#define all(v) (v).begin(), (v).end()
/* libraries */

signed main() {
	int n;
	std::cin >> n;
	std::vector<std::vector<int> > t(n,std::vector<int>());
	rep(i,n-1) {
		int a,b;
		std::cin >> a >> b;
		a--;b--;
		t[a].emplace_back(b);
		t[b].emplace_back(a);
	}

	int v=0; // maxi
	int fmaxd=0; // first max
	std::vector<int> went(n,0);
	std::function<void(int,int)> dfs = [&] (int i, int d) {
		went[i]=true;
		if(fmaxd<d) {
			fmaxd = d;
			v = i;
		}
		for(auto to:t[i]) {
			if(!went[to]) {
				dfs(to,d+1);
			}
		}
	};
	dfs(0,0);
	rep(i,n) went[i] = false;
	dfs(v,0);
	if(fmaxd%3==1) {
		print("Second");
	} else {
		print("First");
	}

	return 0;
}


Measured memory_bytes: 25216
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        InputStreamScanner in = new InputStreamScanner(System.in);
        new Main().solve(in, out);
        out.flush();
    }

    private void solve(InputStreamScanner in, PrintWriter out) {
        String a = in.next();
        String b = in.next();
        BigDecimal x = new BigDecimal(a);
        BigDecimal y = new BigDecimal(b);
        out.println(x.multiply(y).setScale(0, RoundingMode.DOWN));
    }

    static class InputStreamScanner {

        private InputStream in;

        private byte[] buf = new byte[1024];
        private int len = 0;
        private int off = 0;

        InputStreamScanner(InputStream in)	{
            this.in = in;
        }

        String next() {
            StringBuilder sb = new StringBuilder();
            for (int b = skip(); !isSpace(b);){
                sb.appendCodePoint(b);
                b = read();
            }
            return sb.toString();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        char nextChar() {
            return (char)skip();
        }

        int skip() {
            for (int b; (b = read()) != -1;) {
                if (!isSpace(b)) {
                    return b;
                }
            }
            return -1;
        }

        private boolean isSpace(int c) {
            return c < 33 || c > 126;
        }

        private int read() {
            if (len == -1) {
                throw new InputMismatchException("End of Input");
            }
            if (off >= len){
                off = 0;
                try {
                    len = in.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException(e.getMessage());
                }
                if (len <= 0) {
                    return -1;
                }
            }
            return buf[off++];
        }
    }
}


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

#pragma region Macro
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v) sort(v.begin(), v.end())
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define vvi vector<vector<int>>
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#pragma endregion

#pragma region Debug
void debug_out() { cout << endl; }

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

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
#pragma endregion

// コンパイル時、エイリアス「debug」を使用 --> マクロが使えるように

void solve(){
	#define int ll
	#define ALL(a) (a).begin(),(a).end()
	// ここに処理を記述
	// コンパイル時はエイリアス「gpp」--> c++17でコンパイル
	int x, n;
	cin >> x >> n;
	if(!n){
		cout << x << endl;
		return;
	}
	vi p(n);
	rep(i,n){
		cin >> p[i];
	}
	sort(p.begin(), p.end());

	int left = x;
	int right = x;
	while(left > -1 || right < 102){
		if(!binary_search(ALL(p), left)){
			cout << left << endl;
			return;
		}
		left--;
		if(!binary_search(ALL(p), right)){
			cout << right << endl;
			return;
		}
		right++;
	}
	/*
	int start;
	rep(i,n){
		if(x <= p[i]){
			start = i-1;
			break;
		}
	}
	if(x - p[start] != 1){
		cout << x-1 << endl;
		return;
	}
	int right = start + 1;
	if(p[right] != x){
		cout << x << endl;
	}
	right++;
	int left = start;
	while(right < p.size() && left >= 0){
		if(left >= 0){
			if(abs(p[left] - p[left + 1]) != 1 ){
				cout << p[left + 1] - 1 << endl;
				return;
			}
			left--;
		}
		if(right < p.size()){
			if(abs(p[right] - p[right - 1]) != 1){
				cout << p[right - 1] + 1 << endl;
				return;
			}
			right++;
		}
	}

	debug(left, right);
	int j_l, j_r;
	if(left < 0){
		left++;
		j_l = p[left] - 1;
	}
	else{
		if(abs(p[left] - p[left + 1]) != 1 ){
			j_l = p[left] - 1;
		}
		else{
			j_l = 1e9+7;
		}
	}
	if(right >= p.size()){
		right--;
		j_r = p[right] + 1;
	}
	else{
		if(abs(p[right] - p[right - 1]) != 1){
			j_r = p[right] + 1;
		}
		else{
			j_r = 1e9+7;
		}
	}

	debug(j_l, j_r);
	int judge = min(abs(j_r - x),abs(j_l - x));
	if(judge == abs(j_l - x)){
		cout << j_l << endl;
	}
	else{
		cout << j_r << endl;
	}
	*/
}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	
	solve();
	return 0;
}

Measured memory_bytes: 3616
#define _GLIBCXX_DEBUG
#pragma GCC diagnostic ignored "-Wsign-compare"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < int(n); ++i)

void solve() {
    string S;
    cin >> S;
    int ans = 0;
    int cur = 0;
    for (auto &e : S) {
        if (e == 'A' || e == 'G' || e == 'C' || e == 'T') {
            cur++;
            ans = max(ans, cur);
        } else {
            cur = 0;
        }
    }
    cout << ans << "\n";
}
int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    static int MOD = 1000000007;
	static int INF = Integer.MAX_VALUE;
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Long a = sc.nextLong();
        Long b = sc.nextLong();
        Long k = sc.nextLong();

        if (a >= 1 && a >= k) {
            a = a - k;
        } 
        else if (a >= 1 && a < k) {
            k = k - a;
            a = (long)0;
            if (b >= k) {
                b = b - k;
            } else {
                b = (long)0;
            }
        }
        else if (a < 1) {
            if (b >= k) {
                b = b - k;
            } else {
                b = (long)0;
            }
        }
        
        System.out.println(a + " " + b);
    }
}

Measured memory_bytes: 23124
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#include<map>
#include<string>
#include<set>
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << endl
typedef long long ll;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
 
using namespace std;

int main(){
    int N;  cin >> N;
    vector<int> v(N);
    for(int i=0; i<N; i++)  cin >> v[i];
    sort(all(v));
    vector<int> c(1000001,0), d(1000001,0);
    for(int i=0; i<N; i++){
        int a = v[i];
        if(c[a] == 0 && d[a] == 0){
            for(int j=a+a; j<1000001; j+=a)   c[j] = 1;
            d[a] = 1;
        }
    }
    for(int i=1; i<N; i++) if(v[i] == v[i-1])  c[v[i]] = 1;

    int cnt = 0;
    for(int i=0; i<N; i++) if(c[v[i]] == 0) cnt++;
    print(cnt);
}

Measured memory_bytes: 11980
#include <cstring>
#include <iostream>
#include <map>
#include <vector>
#define OFFSET 100

using namespace std;
typedef long long ll;

int d[300][300];

int main() {
  int n;
  cin >> n;
  vector<ll> a;
  vector<int> vt, vf;
  memset(d, 0, sizeof(0));
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    int m = s.size();
    int j = 0;
    while (j < m && s[j] != '.')
      j++;
    if (j == m) {
      a.emplace_back(stoll(s));
      vt.emplace_back(0);
      vf.emplace_back(0);
    } else {
      a.emplace_back(stoll(s.substr(0, j) + s.substr(j + 1, m - j - 1)));
      vt.emplace_back(j + 1 - m);
      vf.emplace_back(j + 1 - m);
    }
    ll p = a[i];
    while (p % 2 == 0) {
      vt[i]++;
      p /= 2;
    }
    while (p % 5 == 0) {
      vf[i]++;
      p /= 5;
    }
    d[vt[i] + OFFSET][vf[i] + OFFSET]++;
  }
  for (int i = 0; i < 300; ++i)
    for (int j = 298; j >= 0; --j)
      d[i][j] += d[i][j + 1];
  ll ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = -vt[i] + OFFSET; j < 300; ++j)
      ans += d[j][-vf[i] + OFFSET];
    if (vt[i] >= 0 && vf[i] >= 0)
      ans--;
  }
  printf("%lld", ans / 2);
}

Measured memory_bytes: 8132
//初項をa, 項数をnとして式を立てて, aについて解くと嬉しい。nは2 * sqrt(b)くらいまで考えれば十分。
//l+…+rではなくて、a+…+(a+n-1)を考えたくなる理由：(1) nの範囲が小さい, (2) 計算しやすい（線形っぽい分解）
#include <iostream>
#define int long long
using namespace std;

signed main() {
	int b;
	while (cin >> b) {
		if (b == 0) break;
		
		int n;
		for (n = 50000; n > 0; n--) {
			int na = b - n * (n - 1) / 2;
			if (na < n || na % n != 0) continue;
			int a = na / n;
			cout << a << " " << n << endl;
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
int n,m;
char s[105][105];
int dp[105][105][2];
inline int read(register int x=0,register char ch=getchar(),register int f=0){
	for(;!isdigit(ch);ch=getchar()) f=ch=='-';
	for(; isdigit(ch);ch=getchar()) x=(x<<1)+(x<<3)+(ch^48);
	return f?-x:x;
}
int main(){
	n=read(); m=read();
	for(int i=1;i<=n;++i) scanf("%s",s[i]+1);
	for(int i=1;i<=n;++i) for(int j=1;j<=m;++j) dp[i][j][0]=dp[i][j][1]=n+m+3;
	if(s[1][1]=='.') dp[1][1][0]=0;
	else dp[1][1][1]=1;
	for(int i=1;i<=n;++i) for(int j=1;j<=m;++j){
		if(s[i+1][j]=='.'){
			dp[i+1][j][0]=min(dp[i+1][j][0],dp[i][j][0]);
			dp[i+1][j][0]=min(dp[i+1][j][0],dp[i][j][1]);
		}
		else{
			dp[i+1][j][1]=min(dp[i+1][j][1],dp[i][j][0]+1);
			dp[i+1][j][1]=min(dp[i+1][j][1],dp[i][j][1]);
		}
		if(s[i][j+1]=='.'){
			dp[i][j+1][0]=min(dp[i][j+1][0],dp[i][j][0]);
			dp[i][j+1][0]=min(dp[i][j+1][0],dp[i][j][1]);
		}
		else{
			dp[i][j+1][1]=min(dp[i][j+1][1],dp[i][j][0]+1);
			dp[i][j+1][1]=min(dp[i][j+1][1],dp[i][j][1]);
		}
	}
	printf("%d\n",min(dp[n][m][0],dp[n][m][1]));
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
using vi  = vector<int>;
#define _GLIBCXX_DEBUG
#define IO_STREAM cin.tie(0);ios::sync_with_stdio(false)
#define all(x) x.begin(),x.end()
#define rep(i,sta,end) for(int i=sta;i<end;++i)
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back
const ll INF = 1000000000000000;
const ll MOD = 1000000007;
const double PI = acos(-1);
//||
#define DBG(a,b,c,d) //cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<endl
//DBG("","","","");

int main(){
	IO_STREAM;
	int N;	cin>>N;
	vi d(N);
	rep(i,0,N){
		cin>>d[i];
	}
	int ans=0;
	rep(i,0,N){
		rep(j,0,N){
			if(i!=j)	ans+=d[i]*d[j];
		}
	}
	ans/=2;
	cout<<ans<<endl;
	return 0;
}


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

const int MAX_N = 1<<17;

long long n,dat[2*MAX_N-1];

//?????????
void init(int n_){
  //????´???°n???2???????????????
  n=1;
  while(n<n_)n*=2;
  for(int i=0;i<2*n-1;i++)dat[i]=0;
}

void update(int a,int b,int k,int l,int r,int x){
  if(r<=a||b<=l)return;
  if(a<=l&&r<=b)dat[k]+=x*(r-l);
  else{
    dat[k*2+1]+=dat[k]/2;
    dat[k*2+2]+=dat[k]/2;
    dat[k]=0;
    update(a,b,k*2+1,l,(l+r)/2,x);
    update(a,b,k*2+2,(l+r)/2,r,x);
  }
}

int find(int a,int b,int k,int l,int r){
  if(r<=a||b<=l)return 0;
  if(a<=l&&r<=b)return dat[k];
  else{
    dat[k*2+1]+=dat[k]/2;
    dat[k*2+2]+=dat[k]/2;
    dat[k]=0;
    return find(a,b,k*2+1,l,(l+r)/2)+find(a,b,k*2+2,(l+r)/2,r);
  }
}

int main(){
  int q;
  cin>>n>>q;
  
  init(n);
  int u,s,t,x;
  for(int i=0;i<q;i++){
    cin>>u;
    if(!u){
      cin>>s>>t>>x;
      s--,t--;
      update(s,t+1,0,0,n,x);
    }else{
      cin>>s;
      s--;
      cout<<find(s,s+1,0,0,n)<<endl;
    }
  }
  
  return 0;
}

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

typedef long long lli;
const double eps = 1e-8;

struct P {
  double x, y, z;
  P() {}
  P(double x, double y, double z) : x(x), y(y), z(z) {}
};

P operator + (const P &a, const P &b) {
  return P(a.x + b.x, a.y + b.y, a.z + b.z);
}
P operator - (const P &a, const P &b) {
  return P(a.x - b.x, a.y - b.y, a.z - b.z);
}
P operator * (const P &a, const double &d) {
  return P(a.x * d, a.y * d, a.z * d);
}
P operator * (const double &d, const P &a) {
  return a * d;
}
P operator / (const P &a, const double &d) {
  return P(a.x / d, a.y / d, a.z / d);
}
P operator / (const double &d, const P &a) {
  return a / d;
}
P& operator += (P &a, const P &b) {
  return a = a + b;
}
P& operator -= (P &a, const P &b) {
  return a = a - b;
}
P& operator *= (P &a, const double &d) {
  return a = a * d;
}
P& operator /= (P &a, const double &d) {
  return a = a / d;
}

double dot(P a, P b) {
  return a.x * b.x + a.y * b.y + a.z * b.z;
}

double norm(P a) {
  return dot(a, a);
}

double abs(P a) {
  return sqrt(norm(a));
}

P project(P s1, P s2, P p) {
  P base = s2 - s1;
  double t = dot(p - s1, base)/norm(base);
  return s1 + base*t;
}

double getDistanceLP(P s1, P s2, P p) {
  return abs(p - project(s1, s2, p));
}

double getDistanceSP(P s1, P s2, P p) {
  if(dot(s2 - s1, p - s1) < 0.0) return abs(p - s1);
  if(dot(s1 - s2, p - s2) < 0.0) return abs(p - s2);
  return getDistanceLP(s1, s2, p);
}

int main() {
  for(int N, Q; cin >> N >> Q; ) {
    vector<P> ps(N);
    vector<double> rs(N);
    vector<lli> ls(N);
    for(int i = 0; i < N; ++i) {
      cin >> ps[i].x >> ps[i].y >> ps[i].z
          >> rs[i] >> ls[i];
    }
    while(Q--) {
      P s, d;
      cin >> s.x >> s.y >> s.z
          >> d.x >> d.y >> d.z;
      lli sum = 0;
      for(int i = 0; i < N; ++i) {
        double dist = getDistanceSP(s, d, ps[i]);
        if(dist < rs[i] + eps) sum += ls[i];
      }
      cout << sum << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1232
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Split
namespace util {

std::vector< std::string > split(std::string s, char delimiter)
{
  std::vector< std::string > vs;
  std::string sub;
  for (auto c : s) {
    if (c == delimiter) vs.push_back(sub), sub.clear();
    else sub += c;
  }
  vs.push_back(sub);
  return vs;
}

} // namespace util

// Minimum, Maximum
template<class T> T minimum(T head, T tail) { return std::min(head, tail); }
template<class H, class... T> H minimum(H head, T... tail) { return std::min(head, minimum(tail...)); }
template<class T> T maximum(T head, T tail) { return std::max(head, tail); }
template<class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); }

// Output
template<class T, class S> std::ostream& operator << (std::ostream& os, std::pair<T, S> p)
{
  return os << "(" << p.first << " " << p.second << ")";
}

template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  //os << v[0]; for (ll i = 1; i < (ll)v.size(); i++){ os << " " << v[i]; }
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::map< T, S > m)
{
  ll i = 0; for (auto p : m){ os << " [" << i << "]" << p.first << "->" << p.second; i++;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

// GCD, LCM
ll gcd(ll a, ll b) {
  while (b != 0) { a %= b; std::swap(a, b); }
  return a;
}
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

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

  ll A, B;
  std::cin >> A >> B;

  ll ans = -1;
  for (ll i = 1; i < 10000; ++i) {
    ll X = i * 0.08;
    ll Y = i * 0.1;
    if (X == A && Y == B) {
      ans = i;
      break;
    }
  }
  print(ans);
  return 0;
}


Measured memory_bytes: 256
s = int(input())
ans = [s]
flag = True
while (flag):
    if not(ans[-1] % 2):
        ans.append(int(ans[-1] / 2))
    else:
        ans.append(3 * ans[-1] + 1)
    if ans.count(ans[-1]) == 2:
        flag = False
        print(len(ans))


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
const int MAX = 1000005;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main(){
  ll m,k;
  cin >> m >> k;
  ll c = 1<<m;
  if(c<=k){
    cout << -1 << endl;
    return 0;
  }
  else{
    if(m==0 && k==0){
      cout << 0 << " " << 0 << endl;
      return 0;
    }
    if(m==1 && k==0){
      cout << 0 << " " << 0 << " " << 1 << " " << 1 << endl;
      return 0;
    }
    if(m>=2){
      for(int i=0;i<c;i++){
        if(i!=k) cout << i << " ";
      }
      cout << k << " ";
      for(int i=c-1;i>=0;i--){
        if(i!=k) cout << i << " ";
      }
      cout << k << endl;
      return 0;
    } 
    else cout << -1 << endl;
  }
  return 0;
}

Measured memory_bytes: 1792
S=input()
n=len(S)-1
ans=0
for i in range(2**n):
    tmp=S
    cnt=0
    for j in range(n):
        if (i>>j)&1:
            tmp=tmp[:j+1+cnt]+" "+tmp[j+1+cnt:]
            cnt+=1
    ans+=sum(list(map(int,tmp.split(" "))))
print(ans)

Measured memory_bytes: 9088
#include<stdio.h>

int len;
char word[12];
void input_me(){
	len=0;
	char c,Word[12],End[]="END_OF_TEXT";
	while((c=getchar())!=EOF)
		if(len<11&&c-'A'>-1)
			Word[len++]=c;	
		else break;
	Word[len]='\0';
	if(strcmp(Word,End)==0)
		{strcpy(word,End); return;}
	else
		for(int i=0;i<len;++i)
			Word[i]=tolower(Word[i]);
	strcpy(word,Word);
}
int main(){
//	freopen("datain.txt","r",stdin);
	int num=0,tag;
	char W[11],end[]="END_OF_TEXT";
	scanf("%s",W);
	do{
		input_me();
		if(strcmp(word,W)==0) ++num;}
	while(strcmp(word,end));
	printf("%d\n",num);
	return 0;
}


Measured memory_bytes: 2112
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val s = (0 until n).map { sc.nextInt() }
    println(answer063cAlt(n, s))
}

fun answer063cAlt(n: Int, s: List<Int>): Int {
    val dp = (0 until n).map { IntArray(n + 1) { 0 } }
    for (i in 1 until n + 1) {
        dp[0][i] = s[0]
    }
    for (i in 1 until n) {
        for (j in 0 until n + 1) {
            if (i == j) {
                dp[i][j] = dp[i - 1][j]
            } else {
                dp[i][j] = dp[i - 1][j] + s[i]
            }
        }
    }
    var max = 0
    dp[n - 1].forEach {
        if (it % 10 != 0) max = Math.max(max, it)
    }
    return max
}


Measured memory_bytes: 29596
def r;gets.split.map &:to_i;end
def rr(n);n.times.map{r};end

class UnionFind
  def initialize(n, &block)
    @par = Array.new(n,&:itself)
    @rank = Array.new(n,1)
    instance_eval(&block) if block_given?
  end

  def root(a)
    par = @par[a]
    a == par ? a : @par[a] = root(par)
  end

  def unite(a,b)
    a = root(a); b = root(b)
    return if a == b

    if @rank[a] < @rank[b]
      @par[a] = b
      @rank[b] += @rank[a]
    else
      @par[b] = a
      @rank[a] += @rank[b]
    end
  end

  def same(a,b)
    root(a) == root(b)
  end

  def roots
    @par.map{|a|root(a)}
  end

  def rank(a)
    @rank[root(a)]
  end
end

N,M = r
BR = M.times.map{gets.split.map{|v|v.to_i - 1}}
BR.reverse!

conn = N*(N-1)/2
ANS = []
ANS << conn

UnionFind.new(N) do
  BR.each do |a,b|
    unless same(a,b)
      x = rank(a)
      y = rank(b)
      conn -= x * y
    end
    ANS << conn
    unite(a,b)
  end
end
ANS.pop
ANS.reverse!
ANS.each do |a|
  puts a
end

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

const int mod = 1000000007;
int dp[100005][2];

int main() {
  string s;
  cin >> s;
  int n = s.size();
  dp[0][0] = 1;
  rep(i, n){
    if(s[i] == '0'){
      dp[i+1][0] = dp[i][0];
      dp[i+1][1] = dp[i][1];
    }else{
      dp[i+1][1] = (dp[i][0] + dp[i][1]) % mod;
    }
    if(s[i] == '0'){
      (dp[i+1][1] += dp[i][1]*2 % mod) %= mod;
    }else{
      (dp[i+1][0] += dp[i][0]*2 % mod) %= mod;
      (dp[i+1][1] += dp[i][1]*2 % mod) %= mod;
    }
  }
  int ans = (dp[n][0] + dp[n][1]) % mod;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4512
headB = 0
tailA = 0
both = 0
c = 0
for i in range(int(input())):
    t = input()
    if t[0] =='B' and t[-1]=='A':
        both+=1
    elif t[0] == 'B':
        headB+=1
    elif t[-1] == 'A':
        tailA +=1
    c+=t.count('AB')
if both>0:
    if tailA+headB>0:
        if tailA:
            c+=1
            tailA-=1
        if headB:
            c+=1
            headB-=1
        c+=min(headB,tailA)
        c+=both-1
    else:
        c+=both-1
else:
    c+=min(tailA,headB)
print(c)

Measured memory_bytes: 3064
import java.io.*;
import java.util.*;


public class Main {

    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        InputReader.OutputWriter out = new InputReader.OutputWriter(outputStream);


        int n = in.nextInt();
        int m = in.nextInt();
        int mod = 1_000_000_000 + 7;
        int [] a = new int[n];
        for (int i = 0; i < m; i++) {
            a[in.nextInt() - 1] = 1;
        }
        if(n == 1) {
            out.println(1);
            out.flush();
            return;
        }
        int [] dp = new int[n];
        if(a[0] == 1) {
            if(a[1] != 1) {
                dp[1] = 1;
            }
        }
        else {
            if(a[1] == 1) dp[1] = 0;
            else {
                dp[0] = 1;
                dp[1] = 2;
            }
        }
        for (int i = 2; i < n; i++) {
            dp[i] = (dp[i-1] + dp[i-2])%mod;
            if (a[i] == 1) {
                dp[i] = 0;
            }
        }
        
        out.println(dp[n-1]);
        out.flush();
    }

}

class InputReader extends BufferedReader {
    StringTokenizer tokenizer;

    public InputReader(InputStream inputStream) {
        super(new InputStreamReader(inputStream), 32768);
    }

    public InputReader(String filename) {
        super(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(filename)));
    }

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

    public Integer nextInt() {
        return Integer.valueOf(next());
    }
    public Long nextLong() {return  Long.valueOf(next());}

    static class OutputWriter extends PrintWriter {
        public OutputWriter(OutputStream outputStream) {
            super(outputStream);
        }

        public OutputWriter(Writer writer) {
            super(writer);
        }

        public OutputWriter(String filename) throws FileNotFoundException {
            super(filename);
        }

        public void close() {
            super.close();
        }
    }
}


Measured memory_bytes: 34396
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<Int> b(n);
  for(Int i=0;i<n;i++) cin>>b[i],b[i]--;
  vector<Int> ans;
  for(Int i=n-1;i>=0;i--){
    Int flg=0;
    for(Int j=i;j>=0;j--){
      if(j==b[j]){
        flg=1;
        ans.emplace_back(j);
        b.erase(b.begin()+j);
        break;
      }
    }
    if(!flg){
      cout<<-1<<endl;
      return 0;
    }
  }  
  reverse(ans.begin(),ans.end());
  for(Int x:ans) cout<<x+1<<endl;  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int mp[100005];
    int n;
    cin >> n;
    int ar[n];
    memset(mp, 0, sizeof mp);
    long long s = 0LL;
    for (int i = 0; i < n; i++) cin >> ar[i], mp[ar[i]]++, s += ar[i];
    int q;
    cin >> q;
    while(q--){
        int a, b;
        cin >> a >> b;
        int dif = b - a;
        s += dif * mp[a];
        cout << s << endl;
        mp[b] += mp[a], mp[a] = 0;
    }
}

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

nmax = max(a)
target = nmax/2

cur = a[0] if a[0] != nmax else a[1]
curdiff = abs(cur-target)

for i in range(n):
    if a[i] == nmax:
        continue

    diff = abs(a[i]-target)

    if diff < curdiff:
        curdiff = diff
        cur = a[i]

print(nmax, cur)

Measured memory_bytes: 19728
N, M = map(int, input().split())
steps = [True] * (N + 1)
for _ in range(M):
    steps[int(input())] = False
dp = [0] * (N + 1)
dp[0] = 1
for prev in range(N):
    for now in range(prev + 1, min(N, prev + 2) + 1):
        if steps[now]:
            dp[now] += dp[prev]
            dp[now] %= 10 ** 9 + 7
print(dp[N])


Measured memory_bytes: 7700
/* 
    AtCoder Beginner Contest 082
    A:Round Up the Mean
    
*/

#include <iostream>
using namespace std;

int main(void)
{
    int a, b;
    double avg;
    cin >> a >> b;
    int sum = a + b;
    // avg = (a + b) / 2;
    // avg = int(avg) + 1;
    // cout << avg << endl;
    
    if (sum % 2 == 0)
    {
        cout << sum / 2 << endl;
    }
    else
    {
        cout << sum / 2 + 1 << endl;
    }
}

Measured memory_bytes: 256
def findProductSum(A, n): 
      
    # calculating array sum (a1 + a2 ... + an) 
    array_sum = 0
    for i in range(0, n, 1): 
        array_sum = array_sum + A[i] 
  
    # calcualting square of array sum 
    # (a1 + a2 + ... + an)^2 
    array_sum_square = array_sum * array_sum 
  
    # calcualting a1^2 + a2^2 + ... + an^2 
    individual_square_sum = 0
    for i in range(0, n, 1): 
        individual_square_sum += A[i] * A[i] 
  
    # required sum is (array_sum_square - 
    # individual_square_sum) / 2 
    temp=int(array_sum_square - 
            individual_square_sum) 
    temp=temp//2
    return temp%1000000007








n = int(input())
l = list(map(int, input().split()))
print(findProductSum(l,n))	
	

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

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

  int n = s.size();
  int zero = 0;
  rep(i, n) {
    if (s[i] == '0') {
      zero++;
    }
  }
  int one = n - zero;
  int ans = min(zero, one) * 2;
  cout << ans << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
 
template <class T1, class T2>
ostream& operator << (ostream& out, const pair <T1, T2> p)
{
        out << '(' << p.first << ',' << p.second << ')';
            return out;
}
 
template <class T1, class T2>
istream& operator >> (istream& in, pair<T1, T2> &p)
{
        in >> p.first >> p.second;
            return in;
}
 
template <class T>
istream& operator >> (istream& in, vector<T> &v)
{
        for (T &x : v)
                    in >> x;
            return in;
}
 
template <class T>
ostream& operator << (ostream& out, const vector<vector<T> > &v)
{
        for (const vector<T> &x : v)
                    out << x << '\n';
            return out;
}
 
template <class T>
ostream& operator << (ostream& out, const vector<T> &v)
{
        for (const T &x : v)
                    out << x << ' ';
            return out;
}

template <class T>
ostream& operator << (ostream& out,const set<T> &s)
{
        for (const T &x : s)
                out << x << ' ';
            return out;
}
 
 
#define ll long long
#define lf long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef pair <ll,ll > ii;
typedef vector <ll> vi;
typedef vector <ii> vii;
typedef vector <bool> vb;
typedef vector <vector <ll> > vv;
typedef vector <vector <vector<ll> > > vvv;
typedef vector <string> vs;
typedef vector <lf> vf;
#define sz(x) (ll)(x).size()
#define tr1(x) cerr << #x << ": " << x << nl
#define tr2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << nl
#define tr3(x,y,z) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<nl
#define tr4(x,y,z,w) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<" | "<<#w<<": "<<w<<nl
#define trv(a) cerr<<#a<<": ";for(ll zz=0;zz<sz(a);zz++) cerr<<a[zz]<<" ";cerr<<nl
#define trset(s) cerr<<#s<<": ";for(auto &i:s) cerr<<i<<" ";cerr<<nl
#define epsilon 0.00000001L
#define inf 9999999999999999ll// ~ 10^16
#define nl endl
#define all(x) x.begin(), x.end()
#define r_all(x) x.rbegin(), x.rend()
#define fast()  ios_base::sync_with_stdio(false);cin.tie(NULL)
#define mod 1000000007ll
#define modulo 998244353ll
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}



int main()
{
    fast();
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    vv dp(c+1,vi (d+1,0));
    dp[a][b]=1;
    for(ll i=a;i<=c;i++)
    {
        for(ll j=b;j<=d;j++)
        {
            if(i==a && j==b)
                continue;
            dp[i][j]=(dp[i-1][j]*j+dp[i][j-1]*i-dp[i-1][j-1]*(i-1)*(j-1)%modulo+modulo)%modulo;
        }
    }
    cout<<dp[c][d]<<nl;
}


Measured memory_bytes: 73636
import sys
input = sys.stdin.readline

L = str(int(input()))
N = len(L)
MOD = 10**9 + 7

smaller = [0] * N
not_smaller = [0] * N

smaller[0] = 1
not_smaller[0] = 2

for i in range(1, N):
    if L[i] == "1":
        smaller[i] = 3 * smaller[i - 1] + not_smaller[i - 1]
        not_smaller[i] = 2 * not_smaller[i - 1]
    elif L[i] == "0":
        smaller[i] = 3 * smaller[i - 1]
        not_smaller[i] = not_smaller[i - 1]

    smaller[i] %= MOD
    not_smaller[i] %= MOD

ans = (smaller[-1] + not_smaller[-1]) % MOD
print(ans)


Measured memory_bytes: 75040
# -*- coding: utf-8 -*-
k = int(input())

tmp = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(tmp[k-1])


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second

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


int main() {
	int r, a;
	while (cin >> r >> a && r > 0 && a > 0) {
		vi d(4, 0), e(4, 0), n(10, 0);
		rep(i, 4) {
			d[i] = r % 10;
			e[i] = a % 10;
			n[r % 10]++;
			r /= 10;
			a /= 10;
		}
		int b = 0, h = 0;
		rep(i, 4) {
			if (d[i] == e[i])b++;
			else if (n[e[i]] > 0)h++;
		}
		cout << b << " " << h << endl;
	}
}

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

int main() {
  int a,b,c;
  int n,m;
  int ans;
  cin >> a >> b >> c;
  n = max(a,b);
  m = max(n,c);
  ans = (a*b*c) / (m*2);
  cout << ans << endl;  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define DEBUG(x)           cout << '>' << #x << ':' << x << endl;
#define forn(i,n)          for(int i=0;i<(int)n;++i)
#define for1(i,n)          for(int i=1;i<=(int)n;++i)
#define forr(i,n)          for(int i=(int)n-1;i>=0;--i)
#define forre(i,a,b)       for(int i=(int)b;i>=(int)a;--i)
#define fore(i,a,b)        for(int i=(int)a;i<=(int)b;++i)
#define input(arr,n)       for(int i=0;i<n;i++)cin>>arr[i]
#define output(arr,n)      for(int i=0;i<n;i++)cout<<arr[i]<<" "
#define for_each(arr)      for(auto& it:arr)cout<<it<<" "
#define ff                 first
#define ss                 second
#define PI                 acos(-1.0)
#define all(a)             a.begin(),a.end()
#define rall(a)            a.rbegin(),a.rend()
#define Unique(a)          sort(all(a)),a.erase(unique(all(a)),a.end())
#define pb(x)              push_back(x)
#define eb(x)              emplace_back(x) 
#define ppb(x)             pop_back(x)
#define pf(x)              push_front(x)
#define ppf(x)             pop_front(x)
#define in(x,y)            insert({x,y})
#define Sort(a)            sort(a.begin(),a.end())
#define mem(arr,a)         memset(arr,a,sizeof arr)
#define ins(a)             insert(a)
#define max2(a,b)          max(a,b)
#define max3(a,b,c)        max(a,max(b,c))
#define max4(a,b,c,d)      max(a,max3(b,c,d))
#define min2(a,b)          min(a,b)
#define min3(a,b,c)        min(a,min(b,c))
#define min4(a,b,c,d)      min(a,min3(b,c,d))
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<char> vc;
typedef vector<double> vd;
/*inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void Set(int & n, int b) { n |= two(b); }
inline void Reset(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }*/
/*int fx[]= {0,0,1,-1,-1,1,-1,1};
int fy[]= {1,-1,0,0,-1,1,1,-1};
int fx1[]={0,1,1,1,0,-1,-1,-1};
int fy1[]={1,1,0,-1,-1,-1,0,1};*/

ll a,b,c,n,ans,cn1,cn2,cn3,t;
string s,s1,s2;


int main()
{
    FIO;
/*    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/
    
    cin>>n;
    cin>>s;
    for(int i=0;i<n;i++){
    	if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C'){
    		++cn1;
    		i+=2;
    	}
    }
    cout<<cn1<<endl;
    

    
   	
    #ifdef ONLINE_JUDGE
    cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<"s.\n";
    #endif
   return 0;
}
 

Measured memory_bytes: 256