akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

const int MAXN = 100010;
int xs[MAXN], D, n, Q;
int R[MAXN][20], L[MAXN][20];
int main() {
	std::ios_base::sync_with_stdio(false), std::cin.tie(0);
	std::cin >> n;
	for (int i = 1; i <= n; ++i) std::cin >> xs[i];
	std::cin >> D >> Q;
	for (int i = 1; i <= n; ++i) {
		R[i][0] = std::upper_bound(xs + 1, xs + 1 + n, xs[i] + D) - xs - 1;
		L[i][0] = std::lower_bound(xs + 1, xs + 1 + n, xs[i] - D) - xs;
	}
	for (int i = 1; i < 20; ++i)
		for (int j = 1; j <= n; ++j)
			R[j][i] = R[R[j][i - 1]][i - 1], L[j][i] = L[L[j][i - 1]][i - 1];
	while (Q --> 0) {
		int x, y, t = 0; std::cin >> x >> y;
		if (x < y) {
		for (int i = 19; ~i; --i) if (R[x][i] < y) t += 1 << i, x = R[x][i];
		}
		else {
		for (int i = 19; ~i; --i) if (L[x][i] > y) t += 1 << i, x = L[x][i];
		}
		std::cout << t + 1 << '\n';
	}
	return 0;
}


Measured memory_bytes: 16896
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int n;
main()
{
	cin>>n;
	int k=1;
	for(;k*(k-1)<n*2;k++);
	if(k*(k-1)!=n*2)
	{
		cout<<"No"<<endl;
		return 0;
	}
	cout<<"Yes"<<endl<<k<<endl;
	vector<vector<int> >ans(k);
	int p=0,q=1;
	for(int i=1;i<=n;i++)
	{
		ans[p].push_back(i);
		ans[q].push_back(i);
		q++;
		if(q>=k)p++,q=p+1;
	}
	for(int i=0;i<k;i++)
	{
		cout<<k-1;
		for(int j=0;j<k-1;j++)cout<<" "<<ans[i][j];
		cout<<endl;
	}
}


Measured memory_bytes: 2304
N, K = map(int, input().split())
V = list(map(int, input().split()))
ans = 0
for A in range(min(N, K)+1):
    for B in range(min(N, K)+1-A):
        hand = V[:A]+V[N-B:]
        hand.sort()
        i = 0
        while i < K-A-B and i < len(hand) and hand[i] < 0:
            hand[i] = 0
            i += 1
        ans = max(ans, sum(hand))
print (ans)

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  vector<int> x(n);
  for(int i = 0; i < n; i++) cin >> x.at(i);
  
  int ans = 1e9;
  for(int i = 1; i <= 100; i++){
    int keep = 0;
    for(int j = 0; j < n; j++){
      keep += pow(x.at(j) - i, 2);
    }
    ans = min(ans, keep);
  }
  
  cout << ans << '\n';
}

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

using namespace std;
using ll = long long;
using ld = long double;

#define REP(i,n) for(ll i=0;i<(n);++i)
#define FOR(i,n,m) for(ll i=n; i<(m);i++)
#define eps  1e-5
using mat = vector<vector<ld>>;

vector<ld> gauss_jordan(mat A) {
	int n = A.size(), m = A[0].size();

	REP(i, n) {
		int piv = i;
		FOR(j, i, n) if (abs(A[j][i]) > abs(A[piv][i])) piv = j;
		swap(A[i], A[piv]);
		if (abs(A[i][i]) < eps) return vector<ld>();
		FOR(j, i + 1, m) A[i][j] /= A[i][i];
		//A[i][i] = 1;
		REP(j, n) {
			if (i != j) {
				FOR(k, i + 1, m) A[j][k] -= A[j][i] * A[i][k];
				//A[j][i] = 0;
			}
		}
	}

	vector<ld> x(n);
	REP(i, n)x[i] = -A[i][m - 1];
	//cout << "done" << endl;
	return x;
}

mat mul(mat a, mat b) {
	int n = a.size(), m = a[0].size(), l = b[0].size();
	assert(m == b.size());
	mat ret(n, vector<ld>(l, 0));
	REP(i, n) {
		REP(j, l) {
			REP(k, m) {
				ret[i][j] += a[i][k] * b[k][j];
			}
		}
	}
	return ret;
}
mat id(ll n) {
	mat ret(n, vector<ld>(n, 0));
	REP(i, n)ret[i][i] = 1;
	return ret;
}
mat pow(mat a, ll n) {

	if (n == 0)return id(a.size());
	mat d = pow(a, n / 2);
	mat tmp = mul(d, d);
	//cout << "#" << n << endl;
	if (n & 1)return mul(tmp, a);
	return tmp;
}

int main() {
	ll s, n, k;
	cin >> s >> n >> k;
	s = abs(s);
	if (n == 1) {
		if (s%k != 0) cout << -1 << endl;
		else cout << (long double)(s) / k << endl;
		return 0;
	}
	if (s == 0) {
		cout << 0 << endl;
		return 0;
	}

	vector<vector<ll>> dp(k + 1, vector<ll>(n*k + 1, 0));
	dp[0][0] = 1;

	REP(i, k) {
		REP(j, n*k + 1) {
			for (int l = 1; l <= n; ++l) {
				if (j >= l)dp[i + 1][j] += dp[i][j - l];
			}
		}
	}
	/*
	REP(i, n*k + 1)cout << dp[k][i] << " ";
	cout << endl;
	*/
	mat eq(n*k, vector<ld>(n*k + 1, 0));
	REP(i, n*k) {
		eq[i][n*k] = -pow(n, k);
		eq[i][i] = pow(n, k);
		FOR(j, k, n*k + 1) {
			if (j == i + 1) continue;
			if (j < i + 1)eq[i][i - j] -= dp[k][j];
			else eq[i][j - i - 2] -= dp[k][j];
			//eq[i][abs(i - (j - 1))] -= dp[k][j];
		}
	}
	/*
	REP(i, eq.size()) {
		REP(j, eq[i].size()) {
			cout << eq[i][j] << " ";
		}
		cout << endl;
	}*/
	vector<ld> e = gauss_jordan(eq);

	if (s <= n * k) {
		cout <<setprecision(100)<< (long double)e[s - 1] << endl;
		return 0;
	}

	mat c(n*k + 1, vector<ld>(n*k + 1, 0));
	REP(i, n*k - 1) {
		c[i + 1][i] = 1;
	}
	c[n*k][n*k] = 1;
	c[0][n*k] = 1;
	REP(i, n*k) {
		c[0][i] = dp[k][i+1] / pow(n, k);
	}

	mat coe = pow(c, s - n * k);

	mat tmp(n*k + 1);

	REP(i, n*k)tmp[i].push_back(e[n*k-i-1]);
	tmp.back().push_back(1);
	mat ret = mul(coe, tmp);
	cout << setprecision(100) << (long double)ret[0][0] << endl;
}



Measured memory_bytes: 9100
n = int(input())
h = [int(x) for x in input().split()]

dp = [10**9] * n
dp[0] = 0

memo = dict()


def func(n):
    # for i in range(n):
    #     if i+1 < n:
    #         memo[(i, i+1)] = abs(h[i] - h[i+1])
    #     if i+2 < n:
    #         memo[(i, i+2)] = abs(h[i] - h[i+2])
    for i in range(1, n):
        if i - 1 >= 0:
            dp[i] = min(dp[i], dp[i-1] + abs(h[i-1] - h[i]))
        if i - 2 >= 0:
            dp[i] = min(dp[i], dp[i-2] + abs(h[i-2] - h[i]))

    return dp[-1]


if __name__ == "__main__":
    print(func(n))

Measured memory_bytes: 14052
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
using namespace std;
typedef long long ll;

#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++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF (1<<29)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

ll N,ans;

int main(){
    cin>>N;
    ll A[N+1],B[N];
    rep(i,N+1)cin>>A[i];
    rep(i,N)cin>>B[i];
    rep(i,N){
        if(A[i]<B[i]){
            ans+=A[i];
            B[i]-=A[i];
            if(A[i+1]<B[i]){
                ans+=A[i+1];
                A[i+1]=0;
            }
            else{
                ans+=B[i];
                A[i+1]-=B[i];
            }
        }
        else{
            ans+=B[i];
        }
    }
    out(ans);
    
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int MAX_N = 100010;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}

/*------------------------------------------------------------------*/
int main(){
    string s, t; cin >> s >> t;
    if(s.size() < t.size()){
        cout << "UNRESTORABLE" << endl;
        return 0; 
    }
    int ns = 0, nt = 0, ns_counter = 0;
    int begin_ns = -1;

    while(true){
        if(s[ns] == '?' or s[ns] == t[nt]){
            while(ns < s.size() and nt < t.size() and (s[ns] == '?' or s[ns] == t[nt])){
                ns++, nt++;
            }
        }
        if(nt == t.size()) begin_ns = ns - t.size();
        ns_counter++;
        ns = ns_counter, nt = 0;
        if(ns_counter == s.size()){
            if(begin_ns == -1){
                cout << "UNRESTORABLE" << endl;
                return 0; 
            }
            break;
        }
    }
    int j = 0;
    for(int i = begin_ns; i < begin_ns + t.size(); i++){
        s[i] = t[j];
        j++;
    }
    for(int i = 0; i < s.size(); i++){
        if(s[i] == '?') s[i] = 'a';
    }
    cout << s << endl;
}

Measured memory_bytes: 3616
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>

using namespace std;

int main(){

	int big_bonus,reg_bonus,glape,cherry,star,total,coin;

	while(true){
		scanf("%d %d %d %d %d %d",&big_bonus,&reg_bonus,&glape,&cherry,&star,&total);
		if(big_bonus == 0 && reg_bonus == 0 && glape == 0 && cherry == 0 && star == 0 && total == 0)break;

		coin = 100;
		coin -= 3*(total-(5*big_bonus+3*reg_bonus+star));
		coin += 15*(big_bonus+reg_bonus);
		coin += 7*glape+2*cherry;
		coin += 13*(5*big_bonus+3*reg_bonus);

		printf("%d\n",coin);
	}

	return 0;
}

Measured memory_bytes: 2704
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <map>
#include <iomanip>
#include <limits>
#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long ll;
using namespace std;

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

int main()
{
	int n;
	cin >> n;
	vector<pair<int, int>> a(n);
	rep(i, n) {
		cin >> a[i].first;
		a[i].second = i+1;
	}
	sort(a.begin(), a.end());
	rep(i, n) cout << a[i].second << ' ';
}

Measured memory_bytes: 1536
import java.util.*; 
class Main 
{
public static void main(String args[]) 
{
Scanner sc = new Scanner(System.in); 
String s = sc.nextLine(); 
String t = sc.nextLine(); 
int l= s.length(); 
int count=0; 
  
for(int i=0;i<l;i++) 
{
if(s.charAt(i)!=t.charAt(i)) 
{
count++;
}
} 
System.out.print(count);  
}  
}  

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

int main() {
	char a, b;
	cin >> a >> b;
	bool A = false, B = false;
	if (a == 'H') A = true;
	if (b == 'H') B = true;
	if (A ^ B) cout << 'D' << endl;
	else cout << 'H' << endl;
}

Measured memory_bytes: 256
package main

import "fmt"

func solve() {
	var N int
	fmt.Scan(&N)
	ans := 1000000000

	for i := 0; i < N; i++ {
		var a int
		fmt.Scan(&a)
		po := 0
		for a%2 == 0 && a != 0 {
			po++
			a = a / 2
		}
		ans = min(ans, po)
	}
	fmt.Println(ans)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	solve()
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int mod = 1e9+7;

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct Edge{
    ll to, weight;
    Edge(ll t, ll w) : to(t), weight(w){}
};
using graph = vector<vector<ll>>;
using Graph = vector<vector<Edge>>;


ll gcd(ll a,ll b){
    if(b == 0){
        return a;
    }else{
        return gcd(b, a%b);
    }
}

ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

int main(){
    string s;
    cin>>s;
    ll x = 0, y = 0;
    for(ll i=0;i<s.size();++i){
        if(s[i] == 'p'){
            x++;
        }else if(s[i] == 'g'){
            y++;
        }
    }
    ll a = s.size() / 2;
    ll b = s.size() - a;
    ll ans = a - x;
    cout<<ans<<endl;

    return 0;
}

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

int main() {

    int a, b; cin >> a >> b;
    vector<int> d(3, 0);
    d[--a]++;
    d[--b]++;
    for (int i = 0; i < d.size(); i++) {
        if (d[i] == 0) cout << i + 1 << endl;
    }
    return 0;
}

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

b = [[0, 0]] * n
c = [0] * n

for i in range(n):
    b[i] = a[i], i + 1

b.sort(key=lambda x: x[0])

print(*[b[i][1] for i in range(n)])


Measured memory_bytes: 20800
#include <stdio.h>


int main (){
  int len , arr[100] , i ,j ,v, o;

    scanf("%d", &len);
    for ( i = 0; i < len; i++){
      scanf("%d", &arr[i]);
    }

    /*  
    insertionSort(A, N) // N個の要素を含む0-オリジンの配列A
2   for i が 1 から N-1 まで
3     v = A[i]
4     j = i - 1
5     while j >= 0 かつ A[j] > v
6       A[j+1] = A[j]
7       j--
8     A[j+1] = v

*/
    for (i = 0; i < len; i++){
      v = arr[i];
      j = i -1;
      while( j >= 0 && arr[j] > v){
	arr[j+1] =arr[j];
	j--;
      }
      arr[j+1] = v;
      for ( o =0 ; o < len; o++){
      printf("%d", arr[o]);
      if ( o < len -1) printf(" ");
      }
      printf("\n");
    }

    
    
return 0;
}



Measured memory_bytes: 2144
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
//#include<cstdio>
//#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

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


	//int N = getint(), W = getint();
	int N, W;
	cin >> N >> W;

	//ll dp[100001] = {};
	//rep(i, N) {
	//	int w;
	//	int v;
	//	cin >> w >> v;
	//	for (int j = W; j >= w; j--) {
	//		dp[j] = max(dp[j], dp[j - w] + v);
	//	}
	//}

	vector <long long> dp(W + 1);
	for (int i = 0; i < N; ++i)
	{
		int a, b;
		cin >> a >> b;
		for (int j = W; j >= a; --j)
			chmax(dp[j], dp[j - a] + b);
	}

	printf("%lld", dp[W]);

	Would you please return 0;
}

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

static const int maxm = 20;

struct EdgeType {
  int id, dest;
};

void dfs(const vector<vector<EdgeType>> &e, int x, vector<EdgeType> &prev) {
  for (int i = 0; i < e[x].size(); i++)
    if (prev[e[x][i].dest].dest == -1) {
      prev[e[x][i].dest].dest = x;
      prev[e[x][i].dest].id = e[x][i].id;
      dfs(e, e[x][i].dest, prev);
    }
}

vector<vector<bitset<maxm>>> find_all_paths(const vector<vector<EdgeType>> &e) {
  int n = e.size();
  vector<vector<bitset<maxm>>> paths(n);
  for (int i = 0; i < n; i++) {
    vector<EdgeType> prev(n);
    for (int j = 0; j < n; j++)
      prev[j].dest = -1;
    prev[i].dest = i;
    dfs(e, i, prev);

    paths[i] = vector<bitset<maxm>>(n);
    for (int j = 0; j < n; j++) {
      if (j == i) continue;

      int t = j;
      while (prev[t].dest != i) {
        paths[i][j][prev[t].id] = 1;
        t = prev[t].dest;
      }
      if (prev[t].dest != t) paths[i][j][prev[t].id] = 1;
    }
  }
  return paths;
}

int main() {
  int n;
  scanf("%d", &n);
  vector<vector<EdgeType>> e(n);
  for (int i = 1; i < n; i++) {
    int a, b;
    scanf("%d %d", &a, &b);

    EdgeType e1, e2;
    e1.id = i;
    e1.dest = b - 1;
    e[a - 1].push_back(e1);
    e2.id = i;
    e2.dest = a - 1;
    e[b - 1].push_back(e2);
  }

  auto paths = find_all_paths(e);

  int m;
  scanf("%d", &m);
  vector<int> u(m), v(m);
  for (int i = 0; i < m; i++)
    scanf("%d %d", &u[i], &v[i]);

  long long ans = 0;
  for (int i = 0; i < (1 << m); i++) {
    int t = i, x = 0;
    bitset<maxm> s;
    for (int j = 0; j < m; j++) {
      x = x ^ (t & 1);
      if (t & 1) {
        s |= paths[u[j] - 1][v[j] - 1];
      }
      t >>= 1;
    }

    if (x & 1)
      ans -= 1LL << (n - s.count() - 1);
    else
      ans += 1LL << (n - s.count() - 1);
  }

  printf("%lld\n", ans);

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define PI 3.14159265358979323846
#define int64 long long
#define uint64 unsigned long long
using namespace std;

int main()
{
	string ss;
	cin >> ss;
	reverse(ss.begin(), ss.end());
	for(int64 ii = 0;ii < ss.length();ii++)
	{
		if(ss[ii] == 'r')
		{
			if(ss.substr(ii, 7) == "remaerd")
			{
				ii += 6;
			}
			else if(ss.substr(ii, 6) == "resare")
			{
				ii += 5;
			}
			else
			{
				cout << "NO" << endl;
				return 0;
			}
		}
		else if(ss[ii] == 'm')
		{
			if(ss.substr(ii, 5) == "maerd")
			{
				ii += 4;
			}
			else
			{
				cout << "NO" << endl;
				return 0;
			}
		}
		else if(ss[ii] == 'e')
		{
			if(ss.substr(ii, 5) == "esare")
			{
				ii += 4;
			}
			else
			{
				cout << "NO" << endl;
				return 0;
			}
		}
		else
		{
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;
}

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


int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  rep(i,n) cin >> d[i];
  set<int> values;
  rep(i,n){
    values.insert(d[i]);
  }
  cout << values.size() << endl;
  return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cerr << #x << " = " << (x) << endl;
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = 1e9;
const double pi = acos(-1.0);

void vec_print(vector<int> v) {
	int vsize = v.size();
	rep(i, vsize) {
		cout << v[i];
		printf(i == vsize - 1 ? "\n" : " ");
	}
}

int main() {
	int n; cin >> n;
	rep(i, n) {
		int r, t; cin >> r >> t;

		VI vr, vt;
		vr.pb(r / 100);
		if (r % 100)vr.pb(r / 100 + 1);
		vt.pb(t / 30);
		if (t % 30)vt.pb(t / 30 + 1);

		VI print;
		for (auto a : vr)for (auto b : vt)print.pb(a + b * 5);
		sort(all(print));
		vec_print(print);
	}
}


Measured memory_bytes: 3260
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		string[] input = Console.ReadLine().Split(' ');
		int n = int.Parse(input[0]);
		int m = int.Parse(input[1]);
		long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
    Array.Sort(nums);
    long[] differences = new long[m-1];
    for(int i = 1; i < m; i++)
    {
      differences[i-1] = nums[i] - nums[i-1];
      //Console.WriteLine(differences[i-1]);
    }
    Array.Sort(differences);
    long answer = 0;
    for(int i = 0; i < m-n; i++)
    {
      //Console.WriteLine(answer);
      answer += differences[i];
    }

		Console.WriteLine(answer);
	}
}

Measured memory_bytes: 19680
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(){
	int h, w;
	while(cin >> h >> w, h+w){
		vector<string> v(h);
		for(int i=0; i< h; i++) cin >> v[i];

		int ret = 0;
		for(int i=0; i < v.size(); i++)for(int j=0; j< v[0].size(); j++)if(v[i][j] != '*'){
			int x = i, y = j;
			while(y+1 < w && v[x][y+1] != '*') y++;
			ret = max(ret, (x-i+1)*(y-j+1));
			while(x+1 < h){
				int c = -100;
				for(int k=j; k <= y; k++) if(v[x+1][k] == '*'){c = k-1; break;}
				if(j <= c || c == -100){
					x++;
					if(c != -100) y = c;
					ret = max(ret, (x-i+1)*(y-j+1));
				}
				else break;
			}
		}
		cout << ret << endl;
	}
}

Measured memory_bytes: 1344
import math


def Primes(n):
    Prime = []
    Table = list(range(2, n))
    for k in range(2, int(math.sqrt(n-1))+1):
        if k == Table[0]:
            Prime.append(Table[0])
            Table = [i for i in Table if i % k]
    return Prime + Table if n > 2 else []


n = int(input())
mod = 10**9+7
ans = 1

for p in Primes(n+1):
    m = 0
    for k in range(2, n+1):
        for _ in range(10):
            if k % p == 0:
                m += 1
                k = k // p
            else:
                break
    ans *= 1+m
print(ans % mod)


Measured memory_bytes: 3064
N = int(input())
c = input()

num_r = 0
for i in range(N) :
  if c[i] == 'R' :
    num_r += 1
    
ans = 0
for i in range(num_r, N) :
  if c[i] == 'R' :
    ans += 1
    
print(ans)

Measured memory_bytes: 9256
#include <bits/stdc++.h>
#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 ALL(v) v.begin(), v.end()
#define MAX(a, b, c) max(max(a, b), c)
using namespace std;

int main(){
  int n;
  scanf("%d",&n);
  int a[n];
  REP(i,n) scanf("%d",&a[i]);

  int cnt = 0;
  FOR(i,1,n-1){
    int b[3] ={ a[i-1], a[i], a[i+1]};
    sort(b, b+3);
    if(b[1] == a[i]) cnt++;
  }
  
  printf("%d\n",cnt);

}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

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

int main() {
  while (true) {
    int h, w;
    cin >> h >> w;
    if (h == 0 && w == 0) break;
    int rh = 160, rw = 160;
    rep (ww, 160) rep (hh, ww) if (ww > 0 && hh > 0) {
      if (h * h + w * w > hh * hh + ww * ww) continue;
      if (h * h + w * w == hh * hh + ww * ww && h >= hh) continue;
      if (rh * rh + rw * rw < hh * hh + ww * ww) continue;
      if (rh * rh + rw * rw == hh * hh + ww * ww && rh < hh) continue;
      rh = hh;
      rw = ww;
    }
    cout << rh << " " << rw << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>

template <class T, class U>
inline bool chmin(T &lhs, const U &rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

template <class T, class U>
inline bool chmax(T &lhs, const U &rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

int main() {
  int N;
  std::cin >> N;
  std::vector<int> T(N);
  for (int &x: T) {
    std::cin >> x;
  }
  int sum = std::accumulate(T.cbegin(), T.cend(), 0);
  int Q;
  std::cin >> Q;
  while (Q--) {
    int p, x;
    std::cin >> p >> x;
    --p;
    std::cout << sum + x - T[p] << '\n';
  }
  return 0;
}


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

using namespace std;

#define llong long long int
#define ldouble long double
#define ternary(condition, x, y) ((condition) ? x : y) 
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) x.begin(), x.end()
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)

const static long long int MOD = 1000000000 + 7;
const static int dy[] = {0, 1, 0, -1};
const static int dx[] = {1, 0, -1, 0};

#define CMAX 51
int noinit = 1;
llong memo[CMAX][CMAX];
template<typename T> llong combination_memo(T a, T b) {
    if (noinit) {
        for (int i = 0; i < CMAX; ++i) {
            for (int j = 0; j < CMAX; ++j) {
                memo[i][j] = -1;
            }
        }
        noinit = 0;
    }

    if (b == 0 || a == b) return 1;
    if (0 <= memo[a][b]) return memo[a][b];

    return memo[a][b] = combination_memo(a - 1, b - 1) + combination_memo(a - 1, b);
}

int main (int argc, char *argv[]) {
    cin.tie(0); 
    ios::sync_with_stdio(false);

    llong n, a, b;
    cin >> n >> a >> b;
    vector<llong> V(n);
    rep(i, n) {
        cin >> V[i];
    }

    sort(all(V), greater<llong>());
    ldouble max_ave = 0;
    rep(i, a) {
        max_ave += (ldouble)V[i];
    }
    max_ave /= a;

    llong choice = 0;
    llong x = 0, y = 0;
    if (V[a - 1] == V[0]) {
        for (int i = 0; i < n; ++i) {
            if (V[i] == V[a - 1]) ++x;
        }
        
        for (llong i = a ; i <= min(b, x); ++i) {
            choice += combination_memo(x, i);
            //cout << x << " " << i << " " << combination_memo(x, i) << endl;
        }
    } else {
        for (int i = 0; i < n; ++i) {
            if (V[i] == V[a - 1]) ++x;
        }

        for (int i = 0; i < a; ++i) {
            if (V[i] == V[a - 1]) ++y;
        }

        choice = combination_memo(x, y);
    }

    cout.precision(20);
    cout << fixed << max_ave << endl;
    cout << choice << endl;

    return 0;
}

Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))
ans = 0
cnt = 0

for i in range(n - 1):
    if h[i] >= h[i + 1]:
        cnt += 1
    else:
        if cnt > ans:
            ans = cnt
        cnt = 0
if cnt > ans:
    ans = cnt

print(ans)

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

int main()
{
  int N, ans;
  string s;
  vector<int> sum_WtoE(300000), sum_EtoW(300000);

  cin >> N >> s;
  if (s[0] == 'W')
    sum_WtoE[0] = 1;
  else
    sum_WtoE[0] = 0;
  if (s[N - 1] == 'E')
    sum_EtoW[0] = 1;
  else
    sum_EtoW[0] = 0;
  for (int i = 1; i < N - 1; i++)
  {
    if (s[i] == 'W')
      sum_WtoE[i] = sum_WtoE[i - 1] + 1;
    else
      sum_WtoE[i] = sum_WtoE[i - 1];
    if (s[N - 1 - i] == 'E')
      sum_EtoW[i] = sum_EtoW[i - 1] + 1;
    else
      sum_EtoW[i] = sum_EtoW[i - 1];
  }
  ans = sum_EtoW[N - 2];
  for (int i = 0; i < N - 2; i++)
    ans = min(ans, sum_WtoE[i] + sum_EtoW[N - 3 - i]);
  ans = min(ans, sum_WtoE[N - 2]);
  cout << ans << endl;
}

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

#define N 1000
#define Q 150

int dp[N][N];

int match(char m, char n){
	if(m==n) return 1;
	else return 0;
}

int max(int a, int b, int c){
	int max = a;
	if(max<b) max = b;
	if(max<c) max = c;

	return max;
}

int main(void)
{
	int i, j, k, q, m, n, cnt;
	char X[N], Y[N];
	int Z[N];

	scanf("%d", &q);

	for(k=0; k<q; k++){
		scanf("%s", X); m = strlen(X);
		scanf("%s", Y); n = strlen(Y);

		// 初期化

		cnt = 0;

		for(i=0; i<m; i++){
			for(j=0; j<n; j++){
				dp[i][j] = 0;
			}
		}

		for(i=0; i<m; i++){
			if(cnt == 0 && match(X[i], Y[0])){
				cnt++;
			}
			dp[i][0] = cnt;
		}
		
		cnt = 0;

		for(j=0; j<n; j++){
			if(cnt == 0 && match(X[0], Y[j])){
				cnt++;
			}
			dp[0][j] = cnt;
		}

		//初期化終わり

		for(i=1; i<m; i++){
			for(j=1; j<n; j++){
				dp[i][j] = max(dp[i-1][j-1] + match(X[i], Y[j]), dp[i][j-1], dp[i-1][j]);
			}
		}

		Z[k] = dp[m-1][n-1];
	}

	for(i=0; i<q; i++){
		printf("%d\n", Z[i]);
	}

	return 0;
}


Measured memory_bytes: 5616
#include<bits/stdc++.h>
using namespace std;
char s[1000001];
int main(){
	int i;
	scanf("%s",s);
	for(i=0;i<strlen(s)-2;i++)
		if(s[i]==s[i+1]&&s[i]==s[i+2]){printf("Yes\n");break;}
	if(i==strlen(s)-2)printf("No\n");
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <cstring>
#include <string>
#include <cctype>
#include <cassert>
#include <queue>
#include <unordered_set>
#include <unordered_map>

using namespace std;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,b,e) for(int i = (b); i <= (e); i++)
#define INF (1001001001)
#define EPS (1e-15)

#define pr(x) do{cerr << (#x) << " = " << (x) << endl;}while(0)
#define pri(x,i) do{cerr << (#x) << "[" << i << "] = " << (x[i]) << endl;}while(0)
#define pra(x) do{rep(__i,(x).size()) pri(x,__i);}while(0)
#define pran(x,n) do{rep(__i,n) pri(x,__i);}while(0)
#define pral(x) do{cerr << (#x) << " =";rep(__i,(x).size()) cerr<<" "<<(x[__i]);cerr<<endl;}while(0)
#define prar(x,b,e) do{repr(__i,b,e) pri(x,__i);}while(0)

typedef long long ll;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;

template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class T,size_t n> ostream& operator<<(ostream &os, const array<T,n> &t) {os<<"{"; rep(i,n) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class T> inline bool CHMAX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool CHMIN(T &l,const T &r){return l>r?l=r,1:0;}

ll MOD = 1000000007;

function<void(int,int)> tensi_no_3p=[&](int v,int d){
};

int in() {
	int a;
	scanf("%d ", &a);
	return a;
}

int main() {
	int A, B, C, X, Y;
	cin >> A >> B >> C >> X >> Y;
	int cost = 0;
	if (2 * C <= A) {
		cost += X * 2 * C;
		Y = max(0, Y - X);
		X = 0;
	}
	if (2 * C <= B) {
		cost += Y * 2 * C;
		X = max(0, X - Y);
		Y = 0;
	}
	if (2 * C <= A + B) {
		cost += min(X, Y) * 2 * C;
		int hoge = min(X, Y);
		X -= hoge;
		Y -= hoge;
	}
	cost += X * A;
	cost += Y * B;
	cout << cost << endl;
	return 0;
}


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


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 30;
const ll INFL = 1LL<<60;
const ll mod = 1000000007;		




int main() {

	int a, b;
	cin >> a >> b;

	if (a == b)cout << a * 2 << endl;
	else cout << max(a, b) * 2 - 1 << endl;



	return 0;
}

Measured memory_bytes: 256
from operator import itemgetter

N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
B = [list(map(int, input().split())) for _ in range(M)]
B.append([1, 0])
B.sort(key=itemgetter(1), reverse=True)
nsum = 0
i = 0
j = 0
jc = 0
while jc < N:
    if A[i] > B[j][1]:
        nsum += A[i]
        i += 1
        jc += 1
    else:
        if B[j][0] >= N - jc:
            nsum += (N - jc) * B[j][1]
            break
        else:
            nsum += B[j][0] * B[j][1]
            jc += B[j][0]
            j += 1
print(nsum)

Measured memory_bytes: 32972
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
const ll INF = 1LL<<60;
const int INT_INF = 1e9;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

int n;
ll a[200010];

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

    ll top[200010], bottom[200010];
    top[0] = a[0], bottom[n-1] = a[n-1];
    for (int i = 1; i < n; i++) {
        top[i] = top[i-1] + a[i];
    }
    for (int i = n-2; i >= 0; i--) {
        bottom[i] = bottom[i+1] + a[i];
    }

    ll ans = INF;
    for (int i = 0; i < n-1; i++) {
        ll tmp = abs(top[i] - bottom[i+1]);
        if (tmp < ans) ans = tmp;
    }
    cout << ans << endl;
}


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

int main() {
	int N, A, B, a = 0, b = 0;
	string S;
	cin >> N >> A >> B >> S;
	for (char& i : S) {
		if ('a' == i) {
			if (A + B > a + b) {
				++a;
				cout << "Yes";
			}
			else cout << "No";
		}
		else if ('b' == i) {
			if (A + B > a + b && B > b) {
				++b;
				cout << "Yes";
			}
			else cout << "No";
		}
		else cout << "No";
		cout << endl;
	}
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int D;
    cin >> D;
    vector<int>c(26);
    for(int i = 0; i < 26; i++) {
        cin >> c[i];
    }
    vector<vector<int>>s(D,vector<int>(26));
    for(int i = 0; i < D; i++) {
        for(int j = 0; j < 26; j++) {
            cin >> s[i][j];
        }
    }
    vector<int>t(D);
    for(int i = 0; i < D; i++) {
        t[i] = rand()%26+1;
    }
    int ans = 0;
    vector<int>Last(26);
    for(int i = 0; i < D; i++) {
        ans+=s[i][t[i]-1];
        Last[t[i]-1] = i+1;
        for(int j = 0; j < 26; j++) {
            ans-=c[j]*(i+1-Last[j]);
        }
    }
    int M = 2000000;
    vector<P>horyuu;
    int cnt = 0;
    for(int i = 0; i < M; i++) {
        int d = rand()%D+1;
        int q = rand()%26+1;
        int ord = ans;
        int X = 0;
        int Y = 0;
        int A = 0;
        int B = 0;
        ans+=s[d-1][q-1]-s[d-1][t[d-1]-1];
        for(int j = 0; j < D; j++) {
            if(t[j] == t[d-1]) {
                if(j == d-1) {
                    Y = j+1;
                }
                else {
                    X = j+1;
                }
                A = j+1;
            }
            if(t[j] == q) {
                Y = j+1;
                B = j+1;
            }
            ans-=c[t[d-1]-1]*(j+1-X)-c[t[d-1]-1]*(j+1-A);
            ans+=c[q-1]*(j+1-B)-c[q-1]*(j+1-Y);
        }
        if(ans >= ord) {
            ord = ans;
            horyuu.push_back({d,q});
            cnt++;
        }
        else {
            ans = ord;
        }
        if(cnt == 3) {
            cnt = 0;
            t[horyuu[2].first-1] = horyuu[2].second;
            horyuu = {};
        }
    }
    for(int i = 0; i < D; i++) {
        cout << t[i] << "\n";
    }
}

Measured memory_bytes: 3656
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
  int N = sc.nextInt();
  int[] c = new int[3*(N-1)];
  for(int i = 0;i < 3*(N-1);i++){
    c[i] = sc.nextInt();
  }
   for(int j = 0;j < 3*(N-1);j += 3){
	  int sum = 0;
  for(int i = j;i < 3*(N-1);i += 3){
    if(sum < c[i+1]){
      sum = c[i+1] + c[i];
    }
    else if(sum%c[i+2] == 0){
      sum += c[i];
    }
    else{
      sum += c[i+2] - sum%c[i+2] + c[i];
    }
  }
  System.out.println(sum);
  }
  System.out.println("0");
}}


Measured memory_bytes: 26768
s = input()
if s == 'SUN':
  print(7)
elif s == 'SAT':
  print(1)
elif s == 'MON':
  print(6)
elif s == 'TUE':
  print(5)
elif s==  'WED':
  print(4)
elif s == 'THU':
  print(3)
else:
  print(2)

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

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

    int ans = 1;
    rep(i, N - 1) {
        if (S[i] != S[i + 1]) ans++;
    }

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


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main(){
    int n; cin >> n;
    string s; cin >> s;
    int ans = 0;

    for(int i = 1; i < n; i++){
        int count  = 0;
        for(char c = 'a'; c <= 'z'; ++c){
            bool left = false;
            bool right = false;

            for(int j = 0; j < i; j++){
                if(s[j] == c)left = true;
            }
            for(int j = i; j < n; j++){
                if(s[j] == c)right = true;
            }
            if(left && right)count++;
        }
        if(ans < count)ans = count;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <utility>
#include <string>
#include <stack>
#include <regex>
#include <numeric>
#include <queue>
#include <set>

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;

int main(int argc, char const *argv[])
{
  while (true)
  {
    ll n;
    cin >> n;
    if (n == 0)
      break;
    vector<ll> w(n + 1);
    REP(i, n)
    {
      cin >> w[i + 1];
    }
    vector<vector<ll>> dp(n + 2, vector<ll>(n + 2));
    REP(i, n)
    {
      for (ll b = 1; b <= n - i; b++)
      {
        ll t = b + i;
        if (dp[b + 1][t - 1] == t - b - 1 && abs(w[b] - w[t]) <= 1)
          dp[b][t] = dp[b + 1][t - 1] + 2;
        ll maxi = 0;
        for (ll mid = b; mid < t; mid++)
        {
          dp[b][t] = max(dp[b][t], dp[b][mid] + dp[mid + 1][t]);
        }
      }
    }
    cout << dp[1][n] << endl;
  }
  return 0;
}



Measured memory_bytes: 3696
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()

    N = NI()
    t = LI()
    v = LI() + [0]
    p = [0] * (N+1)

    for i in range(N):
        p[i+1] = min(p[i]+t[i],v[i],v[i+1])
        j = i
        while p[j] > p[j+1] + t[j] and j > 0:
            p[j] = min(v[j],p[j+1]+t[j])
            j -= 1
    ans = 0
    for i in range(N):
        s1 = v[i] - p[i]
        s2 = v[i] - p[i+1]
        ans += v[i] * t[i] - s1 * s1 / 2 - s2 * s2 / 2
        if s1 + s2 > t[i]:
            ans += (s1 + s2 - t[i]) ** 2 / 4
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 38736
#include <bits/stdc++.h>
#define ll long long
#define ii pair<ll, ll>
#define MAX 1000
#define MOD 1000000007

using namespace std;

bitset<1010> bs;

vector<ll> primes;

void gera(){
  bs.set();
  bs[0] = bs[1] = 0;
  for(ll i = 2; i <= MAX; ++i){
    if(bs[i]){
      primes.push_back(i);
      for(ll j = i * i; j <= MAX; j += i) bs[j] = 0;
    }
  }
}

int main(){
  gera();

  ll N;
  cin >> N;
  vector<ll> v(primes.size(), 0);

  ll res = 1;
  for(ll j = 2; j <= N; ++j){
    for(ll i = 0; primes[i] <= j && i < (ll) primes.size(); ++i){
      if(j % primes[i] == 0){
        // printf("Divide por %lld (%lld)\n", primes[i], res);
        ll tot = 0, num = j;
        while(num % primes[i] == 0){
          tot++;
          num /= primes[i];
        }

        v[i] += tot;
        // res = (res * (tot + 1))%MOD;
      }
    }
  }

  for(ll i = 0; i < (ll) primes.size(); ++i){
    res = (res * (v[i] + 1))%MOD;
  }

  cout << res << endl;



	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int(i)=1;i<=(n);i++)
int ans=0,kt,n;
int ntp,nbtm,nmdl;

void count(int tp, int btm, int mdl, int keta){
  if(keta==1 && btm && tp==btm) ans++;
  if(keta==2 && btm){
    if(kt!=keta) ans++;
    else if(n>=btm*10+tp) ans++;
  }
  if(keta>=3 && btm){
    if(kt!=keta) ans+=pow(10,keta-2);
    else{
      if(ntp>btm) ans+=pow(10,keta-2);
      else if(ntp<btm) ans+=0;
      else{
        if(nbtm>=tp) ans+=nmdl+1;
        else ans+=nmdl;
      }
    }
  }
  //cout<<" ans:"<<ans<<endl;
}

int main(){
  cin>>n;
  kt=log10(n)+1;
  ntp=n/(int)pow(10,kt-1),nbtm=n%10,nmdl=(n%(int)pow(10,kt-1))/10;

  REP(i,n){
    int ikt=log10(i)+1, tp=i/(int)pow(10,ikt-1),btm=i%10,mdl=(i%(int)pow(10,ikt-1))/10;
    //cout<<"i:"<<i<<" "<<tp<<" "<<mdl<<" "<<btm<<endl;
    REP(j,kt) count(tp, btm, mdl, j);
  }

  cout<<ans;
}

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

int INF = 1e9;

int main(){
    int H, N;
    cin >> H >> N;
    int a[N], b[N];
    for(int i = 0; i < N; i++) cin >> a[i] >> b[i];

    vector<int> dp(H + 1, INF); //dp[j] := jの体力を減らすための魔力の最小値 ans = dp[H];
    dp[0] = 0;
    for(int i = 0; i < N; i++){
        for(int j = 0; j <= H; j++){
            if(dp[j] != INF){
                int nx = j + a[i];
                if(nx > H){
                    dp[H] = min(dp[H], dp[j] + b[i]);
                } else {
                    dp[nx] = min(dp[nx], dp[j] + b[i]);
                }
            }
        }
    }

    cout << dp[H] << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <sstream>
#include <utility>
#include <deque>
#include <numeric>
#include <map>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
 
using namespace std;
 
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
 
int main () {
	ll N, M;
    cin >> N >> M;
	map<ll,ll> mp;
	ll S = 0;
	ll tmp;
	rep (i,N) {
		cin >> tmp;
		tmp = tmp % M;
		S = (S + tmp) % M;
		mp[S]++;
	}
	ll ans = mp[0];
	for (auto p : mp) {
		ll n = p.second;
		ans += n*(n-1)/2;
	}
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4224
#include <stdio.h>
#define max(X, Y) ((X) > (Y) ? (X) : (Y))
#define ceil_div(X, Y) ((X) / (Y) + ((X) % (Y) ? 1 : 0))

int main()
{
	long long n;
	long long x, y; x = y = 1;
	long long t, a;

	scanf("%lld", &n);
	for (int i = 0; i < n; i++) {
		scanf("%lld %lld", &t, &a);

		// mt >= x, ma >= y
		// m >= x / t, m >= y / a

		long long m = max(ceil_div(x, t), ceil_div(y, a));

		x = m * t;
		y = m * a;
	}

	printf("%lld\n", x + y);

	return 0;
}


Measured memory_bytes: 128
n=int(input())
lst=list(map(int,input().split()))
aa=sum(lst) % (10**9+7)
# print(sum(lst) % (10**9+7) )
new_lst=[]
temp_1=aa
for i in range(n-1):
    temp_1-=lst[i]
    new_lst.append(temp_1)
# print(new_lst)

tem=0
for i in range(n-1):
    tem+=(lst[i] )*new_lst[i]
        # print(tem)
print(tem % (10**9 +7))


Measured memory_bytes: 31320
/*input
10 587586158 185430194
894597290 708587790
680395892 306946994
590262034 785368612
922328576 106880540
847058850 326169610
936315062 193149191
702035777 223363392
11672949 146832978
779291680 334178158
615808191 701464268
*/
#include <bits/stdc++.h>
using namespace std;

int main() {
    long long int n, a, b, ans = 0;
    
    cin >> n >> a >> b;
    for (int i = 1; i <= n; i++) {
        long long int x, y;
        cin >> x >> y;

        if (a <= x && y >= b) ans++;
    }
    cout << ans << '\n';
    return 0;
}

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

using namespace std;

int main()
{
  string s;
  cin>>s;
  	if(s=="SUN")cout<<"7"<<endl;
    else if(s=="SAT")cout<<"1"<<endl;
    else if(s=="FRI")cout<<"2"<<endl;
    else if(s=="THU")cout<<"3"<<endl;
    else if(s=="WED")cout<<"4"<<endl;
    else if(s=="TUE")cout<<"5"<<endl;
    else cout<<"6"<<endl;
  	return 0;
}

Measured memory_bytes: 256
n = int(input())
ac = 0
wa = 0
tle = 0
re = 0

for i in range(n):
    a = str(input())
    if a == 'AC':
        ac += 1
    if a == 'WA':
        wa += 1
    if a == 'TLE':
        tle += 1
    if a == 'RE':
        re += 1

print('AC x',ac)
print('WA x',wa)
print('TLE x',tle)
print('RE x',re)

Measured memory_bytes: 9208
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
// #include<deque>
// #include<multiset>
// #include<bitset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

int n;
int a[212345];

ll dp[212345][5];

// smin, smax {{{
// clang-format off
template < class T, class U > inline void smin(T &a, const U &b) { a = a < (T) b ? a : b; }
template < class T, class U > inline void smax(T &a, const U &b) { a = a < (T) b ? b : a; }
// clang-format on
// }}}


int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  cin >> n;
  for(int i = 0; i < n; i++) cin >> a[i];
  for(int i = 0; i < n; i++) {
    for(int k = 0; k < 5; k++) dp[i+1][k] = 1e18;
    for(int j = 0; j < 5; j++) {
      for(int k = j; k < 5; k++) {
        ll x = 0;
        if(a[i] == 0) {
          if(k == 1 || k == 3) x = 2;
          else if(k == 2) x = 1;
        } else {
          if(k == 0 || k == 4) x = a[i];
          else if(k % 2 == a[i] % 2) x = 1;
        }
        smin(dp[i + 1][k], dp[i][j] + x);
      }
    }
  }
  ll ans = 1e18;
  for(int k = 0; k < 5; k++) smin(ans, dp[n][k]);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 9216
#include<cstdio>
int main(){
  char c[105];
  int a,b;
  while(scanf("%s",c),c[0]!='0'){
    a=0;
    b=0;
    for(int i=1;c[i]!='\0';i++){
      if(c[i] == 'A') a++;
      if(c[i] == 'B') b++;
    }
    if(a > b) a++;
    if(b > a) b++;
    printf("%d %d\n",a,b);
  }
  return(0);
}



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

int main() {
    string a, b;
    int n;
    cin >> n >> a >> b;
    rep(i, n) {
        cout << a[i] << b[i];
    }
    puts("");
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<algorithm>
#include<iostream>
#include<map>
using namespace std;

int N;
string wa[10]={ "",
		".,!? ",
		"abc",
		"def",
		"ghi",
		"jkl",
		"mno",
		"pqrs",
		"tuv",
		"wxyz"};
vector<char> ans;
int main(){
  cin >> N;
  for(int t=0;t<N;t++){
    string s;
    cin >> s;
    int pr = 0;
    int jd = 0;
    ans.clear();
    for(int i=0;i<(int)s.size();i++){
      int id = s[i]-'0';
      if( id == 0 ){
	//	cout << wa[pr][jd] << endl;
	if( pr!=0 ) ans.push_back(wa[pr][jd]);
      } else if( pr != id ){
	jd = 0;
      } else {
	jd = (jd+1)%(int)wa[id].size();
      }
      pr = id;
    }
    for(int i=0;i<(int)ans.size();i++){
      cout << ans[i];
    }
    cout << endl;
  }
}

Measured memory_bytes: 1228
import java.util.Scanner;

public class Main
{
    public static void main(String[] args)
    {
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        sc.nextLine();
        String s=sc.nextLine();
        if (a<3200)
            System.out.println("red");
        else {
            System.out.println(s);
        }
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define int long long
#define INF 1145141919810364364
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int n;
int ans;

signed main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		if (i % 3 && i % 5)ans += i;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3592