akhauriyash/Code-Regression huggingface dataset:
import Data.List

main = do
  n <- readLn
  as <- fmap (map read . words) getLine
  putStrLn $ unwords $ map show (solve n as)


solve :: Int -> [Int] -> [Int]
solve n xs =
  [m,r]
  where
    m = maximum xs
    m2 = m`div`2
    r = foldr f m (delete m xs)

    f a x | abs(m2-a) > abs(m2-x) = x
          | otherwise             = a

Measured memory_bytes: 33148
fun main(args: Array<String>) {
    val L = readInputLine().reversed().toCharArray()

    val mod = 1000000007L

    // dp[0:L未満 1:Lと一致 2:Lより大きい][n桁目での総数]
    val dp = Array(3) { LongArray(L.size) }

    when (L[0]) {
        '0' -> {
            // (0, 0)
            dp[1][0] = 1L
            // (1, 0), (0, 1)
            dp[2][0] = 2L
        }
        else -> {
            // (0, 0)
            dp[0][0] = 1L
            // (1, 0), (0, 1)
            dp[1][0] = 2L
        }
    }

    for (i in 1 until L.size) {
        when (L[i]) {
            '0' -> {
                // (0, 0)
                for (j in 0..2) {
                    dp[j][i] = dp[j][i - 1]
                }
                // (1, 0), (0, 1)
                for (j in 0..2) {
                    dp[2][i] += dp[j][i - 1] * 2L
                }
                dp[2][i] %= mod
            }
            else -> {
                // (0, 0)
                for (j in 0..2) {
                    dp[0][i] += dp[j][i - 1]
                }
                dp[0][i] %= mod
                // (1, 0), (0, 1)
                for (j in 0..2) {
                    dp[j][i] += dp[j][i - 1] * 2L
                    dp[j][i] %= mod
                }
            }
        }
    }

    println((dp[0][L.size - 1] + dp[1][L.size - 1]) % mod)
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 39832
n, l = map(int, input().split())
p_list = [l + i - 1 for i in range(1, n+1)]
s = sum(p_list)
if l <= 0 and l >= 1 - n: print(s)
elif l < 1 - n: print(s - p_list[-1])
else: print(s - p_list[0])

Measured memory_bytes: 3060
public class
Main
{
  public static void
  main (
    String[ ] args
    )
  {
    int i, j;

    for ( i = 1; i <= 9; ++i )
    for ( j = 1; j <= 9; ++j )
    {
      System.out.println ( i + "x" + j + "=" + ( i * j ) );
    }

    return ;
  }
}

Measured memory_bytes: 9244
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
    int n;
    double sum = 0,ave = 0,sigma;
    while(true){   
        scanf("%d",&n);
        if(n==0)break;
        int S[n]={0};
        REP(i,n){
            scanf("%d ",&S[i]);
            sum+=S[i];
        }
        ave=sum/n;
        REP(i,n){
            sigma +=(S[i]-ave)*(S[i]-ave);
        }
        sigma=sqrt(sigma/n);
        printf("%.8lf\n",sigma,ave);
        ave=0;sigma=0;sum=0;
    }
}


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

#define F first
#define S second

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

const int max_n = 111, inf = 1000111222;
const ll inff = 1000111222333444;

int l, r;

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin >> l >> r;
    if (r - l > 1000) {
        cout << 0 << endl;
        return 0;
    }
    int mn = inf;
    for (int i = l; i <= r; ++i) {
        for (int q = i + 1; q <= r; ++q) {
            mn = min(mn, int(1LL * i * q % 2019));
        }
    }
    cout << mn << endl;
    return 0;
}


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

using namespace std;
using ll = long long;
constexpr int mo = 1e9+7;
constexpr int  mod = mo;
constexpr int inf = 1<<30;
constexpr int mo2 = 998244353;
constexpr ll infl = 1ll<<60;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n;
    cin>>n;
    vector<vector<pair<int,bool>>> a(n);
    for(int i=0;i<n;++i){
        int ai;cin>>ai;
        for(int j=0;j<ai;++j){
            int x,y;cin>>x>>y;x--;
            a[i].push_back({x,y});
        }
    }
    int ma = 0;
    for(int i=0;i<(1<<n);++i){
        bool out = false;
        for(int j=0;j<n;++j){
            if(i>>j&1){
                for(auto &cur : a[j]){
                    if((cur.second)^((i>>(cur.first))&1) )out = true;
                }
            }
            if(out)break;
        }
        if(out)continue;
        ma = max(ma,__builtin_popcount(i));
    }
    cout << ma << endl;
    return 0;
}



Measured memory_bytes: 256
import scala.io.StdIn._
object Main extends App{
  val sc = new java.util.Scanner(System.in)
  var n = sc.nextInt
  val tlist = List.fill(n)(sc.nextInt)
  val m = sc.nextInt
  val plist = List.fill(m,2)(sc.nextInt)
  for(i<-0 to m-1){
    var sum=0
    for(j<-0 to n-1){
      if(plist(i)(0)==j+1){
       sum+=plist(i)(1)
      }
      else{
       sum+=tlist(j) 
      }
    }
    println(sum)
  }
}

Measured memory_bytes: 25924
n, k = map(int, input().split())

n = abs(n - ((n // k) - 1) * k)

ans = abs(n-k)
prev = 10**18 + 10
end = True
while end:
    ans = min(abs(ans-k), prev)
    if prev == ans:
        end = False
    prev = ans

print(ans)

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

using namespace std;

int main() {
    string A, B;
    cin >> A >> B;
    
    int sz = max(A.size(), B.size());
    for (int i = 0; i < sz - A.size(); i++) {
        A = "0" + A;
    }
    for (int i = 0; i < sz - B.size(); i++) {
        B = "0" + B;
    }
    if (A > B) cout << "GREATER\n";
    else if (A < B) cout << "LESS\n";
    else cout << "EQUAL\n";

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) std::begin(a), std::end(a)
#define RALL(a) std::rbegin(a), std::rend(a)
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

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

constexpr int dx[] = {-1, 0, 1, 0};
constexpr int dy[] = {0, -1, 0, 1};

template <typename T>
constexpr int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
constexpr int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T, typename U>
constexpr void chmax(T& m, U x) {
	m = max(m, x);
}

template <typename T, typename U>
constexpr void chmin(T& m, U x) {
	m = min(m, x);
}

template <typename T>
constexpr T square(T x) {
	return x * x;
}

// 終了判定
template <typename T,
		  typename enable_if<is_integral<T>::value>::type* = nullptr>
bool finds(T left, T right) {
	return right - left > 1;
}

// 終了判定(浮動小数)
template <typename T,
		  typename enable_if<is_floating_point<T>::value>::type* = nullptr>
bool finds(T left, T right) {
	return abs(right - left) > EPS;
}

// 二分探索
template <typename T>
pair<T, bool> bin_search(T left, T right, auto pred, auto f) {
	int i = 0;
	while(f(left, right)) {
		if(i > 200) {
			return make_pair(0, false);
		}
		T middle = (left + right) / 2;
		if(pred(middle)) {
			left = middle;
		} else {
			right = middle;
		}
		i++;
	}
	return make_pair(left, true);
}

int main() {
	ll x;
	cin >> x;
	for(ll b = -1000LL; b <= 1000LL; b++) {
		pair<ll, bool> searched = bin_search(
			-1000LL,
			1000LL,
			[&](ll a) { return a * a * a * a * a <= x + (b * b * b * b * b); },
			[&](ll l, ll r) {
				return l * l * l * l * l != x + (b * b * b * b * b);
			});
		if(searched.second) {
			cout << searched.first << " " << b << endl;
			break;
		}
	}
	return 0;
}


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

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

    long long G[N][3];
    for (int i = 0; i < N; i++) {
        cin >> G[i][0] >> G[i][1] >> G[i][2];
    }

    long long dp[N][3];
    dp[0][0] = G[0][0];
    dp[0][1] = G[0][1];
    dp[0][2] = G[0][2];
  
    for (int i = 1; i < N; i++) {
        dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + G[i][0];
        dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + G[i][1];
        dp[i][2] = max(dp[i - 1][1], dp[i - 1][0]) + G[i][2];
    }

    cout << max({dp[N - 1][0], dp[N - 1][1], dp[N - 1][2]}) << endl;
}

Measured memory_bytes: 4992
def gcd(a,b):
	while b:
		a,b=b, a%b
	return a
	
N,X=map(int, input().split())
x=list(map(int,input().split()))
x_d=[0]*N
x_d[0]=abs(X-x[0])
for i in range(N-1):
	x_d[i+1]=abs(x[i+1]-x[i])
	
temp=x_d[0]
least=temp
for i in range(N-1):
	if x_d[i+1] > temp:
		temp=gcd(x_d[i+1],temp)
	else:
		temp=gcd(temp, x_d[i+1])
		
	if temp < least:
		least=temp
		
print(least)

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

int main() {
	string O, E;
	cin >> O >> E;
	for (int i = 0;i < 2 * E.size();i+=2) {
		cout << O[i / 2] << E[i / 2];
	}
	if (O.size() > E.size()) {
		cout << O[O.size() - 1];
	}
	return 0;
}

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

using namespace std;


#define MAXN 1000000
typedef long long ll;
int main() {
  ll n, k;
  cin >> n >> k;
  ll ans = 0;
  for (ll b = k+1; b <= n; ++b) {
    ans += (n-k)/b*(b-k) + min(b-k, n-k-(n-k)/b*b+1) - (k==0);
  }
  cout << ans << endl;
  return 0;
}


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

/*
templates for competitive programming
type long long -> type ll 
define constants : EPS, INF, MOD, PI
define macros : REP, FOR, ALL, SORT, REVERSE
define number theory functions: qp(a, b), qp(a, b, mo), gcd(a, b)
define dx, dy
*/
   typedef long long ll;

   const double EPS = (1e-7);
   const int INF =(1e9);
   const double PI = (acos(-1));
   const int MOD = (int(1e9) + 7);

   #define REP(i, n) for(int i = 0; i < (int)(n); i++)
   #define FOR(i, a, b) for (int i = (a); i < (b); i++)
   #define ALL(x) (x).begin(),(x).end()
   #define SORT(x) sort((x).begin(), (x).end())
   #define REVERSE(x) reverse((x).begin(), (x).end())
   #define SZ(x) ((int)(x).size())


   #define dump(x) cerr<< #x << "= " << (x) << endl;

   int gcd(int a,int b){return b?gcd(b,a%b):a;};

   int dx[4]={1,0,-1,0};
   int dy[4]={0,1,0,-1};

int main() {
   cin.tie(0);
   ios::sync_with_stdio(false);
   // input
   ll n; cin >> n;
   vector<int> a(n); 
   REP(i, n) cin >> a[i];

   ll ans = 0;
   ll right = 0;
   ll sum = 0;
   REP(left, n){
       if (left > right){
           left = right;
           sum = 0;
       }
       while ((right < n) && ((sum ^ a[right]) == (sum + a[right]))){
           dump(sum ^ a[right])
           dump(sum + a[right])
           sum += a[right];
           right++;
       }
       dump(left)
       dump(right)
       ans += right - left;
       sum -= a[left];
   }
   cout << ans << endl;
}

Measured memory_bytes: 1024
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

x = int(input())

if x >= 1800:
    print(1)
elif x >= 1600:
    print(2)
elif x >= 1400:
    print(3)
elif x >= 1200:
    print(4)
elif x >= 1000:
    print(5)
elif x >= 800:
    print(6)
elif x >= 600:
    print(7)
elif x >= 400:
    print(8)


Measured memory_bytes: 9388
#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> a(n);
  rep(i, n) {
    cin >> a[i];
    a[i]--;
  }
  int ans = 0;
  rep(i, n) {
    ans += a[i];
  }
  cout << ans << endl;
  return 0;
}

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

int main()
{
    ll n, max_weight;
    cin >> n >> max_weight;
    vector<ll> profit(n+1);
    vector<ll> weight(n+1);
    for(ll i = 1; i <= n; i++)
    {
        cin >> weight[i];
        cin >> profit[i];
    }
    vector<vector<ll>> tab(n+1, vector<ll>(max_weight + 1));
    for(ll i = 1; i <= n; i++)
        for(ll j = 1; j <= max_weight; j++)
            if(j < weight[i])
                tab[i][j] = tab[i-1][j];
            else
                tab[i][j] = max(tab[i-1][j],(tab[i-1][j-weight[i]] + profit[i]));

    cout << tab[n][max_weight];
    return 0;
}


Measured memory_bytes: 83000
#include <stdio.h>
#include <math.h>

int main(void){
	int Q;
	long long A,B,num,C;
	int tmp,i;
	
	scanf("%d",&Q);
	for(i=0;i<Q;i++){
		scanf("%lld %lld",&A,&B);
		if(A>=B){
			tmp = A; A = B; B = tmp;
		}
		if(A==B || A+1==B){
			num = 2*A-2;
		}else{
			C = sqrt(A*B);
			if(C*C>=A*B)	C--;
			if(C*(C+1)>=A*B){
				num = 2*C-2;
			}else{
				num = 2*C-1;
			}
		}
		printf("%lld\n",num);
	}
	return 0;}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
#define int long long
#define MOD 1000000007
typedef vector<int> vi;
typedef pair<int,int> pi;
#define inf 1e18
#define For(i,a,b) for (int i = a; i < b; i++)
#define Rep(i,a,b) for (int i = a; i <= b; i++)
#define ps(x,y) fixed << setprecision(y) << x 
#define pb push_back 
#define mp make_pair 
 
int32_t main()
{
    fast;
    int x; cin >> x;
    int val = x % 11;
    if(val > 6) cout << x / 11 * 2 + 2;
    if(val == 0) cout << x / 11 * 2;
    else if(val <= 6) cout << x / 11 * 2 + 1;
    
    
    
    return 0;
}

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

int main() {
    int a, b, c;
    cin >> a >> b;
    string ans;
    ans = "No";

    if(b < 10) c = 10*a + b;
    else if (b < 100) c = 100*a + b;
    else if (b == 100) c = 1000*a + b;

    for(int i = 1; i < 320; i++) {
        if(c == i*i) {
            ans = "Yes";
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
ll llmax = LLONG_MAX;
string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alp = "abcdefghijklmnopqrstuvwxyz";
vi d1 = {1, 0, -1, 0}, d2 = {0, 1, 0, -1};
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << -1 << endl;}
void sorti(vi &a) {sort(a.begin(), a.end());}
void sortll(vll &a) {sort(a.begin(), a.end());}
void sorts(vs &a) {sort(a.begin(), a.end());}

int main() {
  ll n, k;
  cin >> n >> k;
  vll p(n);
  for (ll i = 0; i < n; i++) cin >> p[i];

  vector<long double> q(n);
  for (ll i = 0; i < n; i++) {
    q[i] = (long double)(p[i] + 1) / 2;
    if (i > 0) q[i] += q[i - 1];
  }
  priority_queue<long double> r;
  r.push(q[k - 1]);
  for (ll i = 1; i <= n - k; i++) {
    r.push(q[k - 1 + i] - q[i - 1]);
  }
  cout << fixed << setprecision(8) << r.top() << endl;
}

Measured memory_bytes: 11120
#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof x)
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Fod(i,b,a) for (int i=(b);i>=(a);i--)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
#define outval(x) cerr<<#x" = "<<x<<endl
#define outtag(x) cerr<<"-----------------"#x"-----------------\n"
#define outarr(a,L,R) cerr<<#a"["<<L<<".."<<R<<"] = ";\
                    For(_x,L,R) cerr<<a[_x]<<" ";cerr<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair <int,int> pii;
LL read(){
    LL x=0,f=0;
    char ch=getchar();
    while (!isdigit(ch))
        f=ch=='-',ch=getchar();
    while (isdigit(ch))
        x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
    return f?-x:x;
}
const int N=2005*2;
int n,m,k;
set <int> e[N];
int fa[N],depth[N];
void dfs(int x,int pre,int d){
	depth[x]=d,fa[x]=pre;
	for (auto y : e[x])
		if (y!=pre)
			dfs(y,x,d+1);
}
struct Link{
	int X,Y;
	int x,y;
	int del;
	vector <int> id;
}a[N];
vector <int> id[N];
void Ins(int x,int y,int i){
	if (depth[x]<depth[y])
		swap(x,y);
	while (depth[x]>depth[y])
		id[x].pb(i),x=fa[x];
	while (x!=y){
		id[x].pb(i),x=fa[x];
		id[y].pb(i),y=fa[y];
	}
	id[x].pb(i);
}
int vis[N][N];
int Calvis(int x,int a,int b,int pre=0){
	int c=0;
	for (auto y : e[x])
		if (y!=pre){
			int v=Calvis(y,a,b,x);
			c+=v;
			if (v>=2)
				vis[x][y]=vis[y][x]=1;
		}
	if (x==a)
		c++;
	if (x==b)
		c++;
	return c;
}
int main(){
	n=read(),m=k=read();
	For(i,1,n-1){
		int x=read(),y=read();
		e[x].insert(y),e[y].insert(x);
	}
	dfs(1,0,0);
	For(i,1,m){
		int x=a[i].x=a[i].X=read(),y=a[i].y=a[i].Y=read();
		a[i].id.pb(i);
		Ins(x,y,i);
	}
	int ans=0;
	For(_,1,n-1){
		int x=0;
		For(i,1,n)
			if (e[i].size()==1){
				x=i;
				break;
			}
		int y=*e[x].begin();
		vector <int> now;
		for (auto i : id[x])
			if (!a[i].del&&a[i].x!=a[i].y)
				now.pb(i);
		if (vis[x][y])
			ans+=2;
		else {
			if (now.size()>=2){
				int i=now[0],j=now[1];
				if (a[i].y!=x){
					swap(a[i].x,a[i].y);
					for (auto k : a[i].id)
						swap(a[k].X,a[k].Y);
				}
				if (a[j].x!=x){
					swap(a[j].x,a[j].y);
					for (auto k : a[j].id)
						swap(a[k].X,a[k].Y);
				}
				assert(a[i].y==x&&a[j].x==x);
				Calvis(x,a[i].x,a[j].y);
				k++;
				a[k].x=a[i].x;
				a[k].y=a[j].y;
				a[i].del=a[j].del=1;
				for (auto v : a[i].id)
					a[k].id.pb(v);
				for (auto v : a[j].id)
					a[k].id.pb(v);
				Ins(a[k].x,a[k].y,k);
				ans+=2;
			}
			else
				ans+=now.size();
		}
		for (auto i : now)
			(x==a[i].x?a[i].x:a[i].y)=y;
		e[x].erase(y),e[y].erase(x);
	}
	cout<<ans<<endl;
	For(i,1,m)
		printf("%d %d\n",a[i].X,a[i].Y);
	return 0;
}

Measured memory_bytes: 37248
#include<iostream>
using namespace std;
int main()
{
    char n[4];
    cin>>n;
    for(int i=0;i<3;i++)
    {
        if(n[i]=='1') cout<<9; 
        else if(n[i]=='9') cout<<1;
        else cout<<n[i];
    }
    cout<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int n,c[101]={0},i,j,a[4],s,t=0,o,g;
	scanf("%d",&n);
	for(i=1;i<=n*(n-1)/2;i++){
		for(j=0;j<4;j++){
			scanf("%d",&a[j]);
			}
		if(a[2]>a[3]){
			c[a[0]]+=3;
		}
		else if(a[2]==a[3]){
			c[a[0]]+=1;
			c[a[1]]+=1;
		}
		else{
			c[a[1]]+=3;
		}
	}
	for(i=1;i<=n;i++){
		c[i]+=1000;
	}
	for(i=1;i<=n;i++){
		for(j=1;j<=n;j++){
			if(t<=c[j]){
				t=c[j];
				s=j;
			}
		}
		if(o==c[s]){
			c[s]=g;
			t=0;
			s=0;
		}
		else{
			o=c[s];
			c[s]=i;
			g=i;
			t=0;
			s=0;
		}
	}
	for(i=1;i<=n;i++){
		printf("%d\n",c[i]);
	}
	return 0;
}

Measured memory_bytes: 600
import numpy as np

MOD = 998244353

N, S = map(int, input().split(' '))
A = (0, *map(int, input().split(' ')))

dp = np.zeros(shape=(N + 1, S + 1), dtype=int)
dp[0][0] = 1

for i in range(1, N + 1):
    a = A[i]
    dp[i] = 2 * dp[i - 1] % MOD
    dp[i][a:] += dp[i - 1][:-a]
    dp[i] %= MOD

print(dp[N][S])


Measured memory_bytes: 96780
fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(' ').map(String::toLong)
    val aList = readLine()!!.split(' ').map(String::toLong)
    val cumSum = mutableListOf(0L)
    aList.forEach { cumSum.add(cumSum.last() + it) }
    val modMap = mutableMapOf<Long, Long>()
    cumSum.forEach { modMap[it % m] = (modMap[it % m] ?:0L) + 1L }
    var ans = 0L
    for ((key, value) in modMap) {
        ans += (value * (value - 1)) / 2
    }
    println(ans)
}

Measured memory_bytes: 61796
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<ll,ll>
#define PP pair<P,P>
using namespace std;

int main(){
    int a[5];
    rep(i,5){
        cin >> a[i];
        if(a[i]==0){
            cout << i+1 << endl;
            return 0;
        }
    }

return 0;
}



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

int main() {
  int N, A, B;
  
  cin >> N >> A >> B;
  
  int p1 = A * N;
  int p2 = B;
  
  if (p1 < p2) {
    cout << p1 << endl;
  }
  else {
    cout << p2 << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include <cstdlib>

using namespace std;

int main(){

	string a,b;
	cin >> a >> b;

	if(a.size()>b.size()){
		cout << "GREATER"<< endl;
		return 0;
	}
	else if(b.size()>a.size()){
		cout << "LESS" <<endl;
		return 0;
	}

	else{
		for(int i = 0; i < a.size(); i++){

			if((int)a.front() > (int)b.front()){
				cout << "GREATER"<< endl;
				return 0;
			}
			else if((int)a.front() < (int)b.front()){
				cout << "LESS" <<endl;
				return 0;
			}
			 a.erase(1 ,1);
			 b.erase(1 ,1);

		}
	}
	cout << "EQUAL" <<endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

 int A,B,K,M;
 
 
 int main(){

  cin >> A >> B >> K;
  
  M = min (A, B);
  
  for (int i = M; i >=1; --i) {
   if (A% i == 0 && B% i== 0) {
    --K;
    if (K == 0) cout << i << endl;
    }
  }

 return 0;
}	

Measured memory_bytes: 256
/*
 * Aizu Online Judge
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author yoshkur
 */
public class Main {

	/**
	 * @param args the command line arguments
	 */
	public static void main(String[] args) {
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			InputData inputData = new InputData();
			inputData.setDataFromLines(br);
			inputData.setValues();
			Processing processing = new Processing(inputData);
			System.out.println(processing.getResult());

		} catch (IOException | NumberFormatException e) {
			System.err.println(e.getLocalizedMessage());
		}
	}
}

class InputData {

	public static final String SEPARATOR = " ";

	private List<String> rows = new ArrayList<>();
	private String row;
	private List<RowValues> rowValues = new ArrayList<>();

	public InputData() {
	}

	public void setDataFromLine(BufferedReader br) throws IOException {
		this.row = br.readLine().trim();
	}

	public void setDataFromLines(BufferedReader br) throws IOException {
		String line;
		while ((line = br.readLine()) != null) {
			this.rows.add(line.trim());
		}
	}

	public void setValues() {
		for (String str : this.rows) {
			RowValues rowValue = new RowValues();
			String[] values = str.split(InputData.SEPARATOR);
			rowValue.setNum0(Integer.valueOf(values[0]));
			rowValue.setNum1(Integer.valueOf(values[1]));
			this.rowValues.add(rowValue);
		}

	}

	public List<RowValues> getRowValues() {
		return rowValues;
	}

	public void setRowValues(List<RowValues> rowValues) {
		this.rowValues = rowValues;
	}
}

class RowValues {

	Integer num0;
	Integer num1;

	public Integer getNum0() {
		return num0;
	}

	public void setNum0(Integer num0) {
		this.num0 = num0;
	}

	public Integer getNum1() {
		return num1;
	}

	public void setNum1(Integer num1) {
		this.num1 = num1;
	}

	public void sort() {
		if (this.num0 > this.num1) {
			Integer temp = this.num0;
			this.num0 = this.num1;
			this.num1 = temp;
		}
	}
}

class Processing {

	private static final String RETCODE = System.getProperty("line.separator");

	private InputData inputData;

	public Processing(InputData inputData) {
		this.inputData = inputData;
	}

	public String getResult() {
		String result = null;
		StringBuilder sb = new StringBuilder();
		for (RowValues rowValue : this.inputData.getRowValues()) {
			if (rowValue.getNum0() == 0 && rowValue.getNum1() == 0) {
				break;
			}
			rowValue.sort();
			sb.append(rowValue.getNum0());
			sb.append(InputData.SEPARATOR);
			sb.append(rowValue.getNum1());
			sb.append(RETCODE);
		}
		result = sb.toString().trim();
		return result;
	}
}

Measured memory_bytes: 27100
while n = gets.to_i
  break if n == 0
  h1 = Hash.new
  n.times do
    a = gets.split
    s = a.shift
    h1[s] = a.map(&:to_i)
    h1[s].shift
  end
  t = Hash.new(0)
  h1.each_value do |x|
    x.each { |v| t[v] += 1 }
  end
  h2 = Hash.new
  h1.each do |name, i|
    h2[name] = 0
    i.each { |j| h2[name] += n-t[j]+1 }
  end
  ans = h2.sort.sort_by { |k, v| v }.shift
  puts ans[1].to_s << " " << ans[0]
end

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

int main(void)
{
    long long N;
    string S;

    cin >> N;
    cin >> S;

    long long cnt[26];
	for (int i = 0; i < 26; ++i) {
		cnt[i] = 0;
	}
  
    for(int i=0; i<N; ++i)
    {
        cnt[S[i]-'a']++;
    }

    const long long MOD = 1000000007;

	long long ans = 1;
	for (int i = 0; i < 26; ++i) {
		ans = ans * (1 + cnt[i]) % MOD;
	}
    ans = (ans - 1) % MOD;
	cout << ans << endl;

    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const int INF = 2000000000;
using namespace std;

class Edge {
    public:
        int to, cost;
        Edge(int to, int cost) : to(to), cost(cost) { }
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

int prim(const Graph &g, int s = 0) {
    int n = g.size();
    int total = 0;

    vector<bool> visited(n);
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;
    //priority_queue<pair<int, int> > q;

    q.push(make_pair(0,s));
    while (not q.empty()) {
        pair<int, int> u = q.top(); q.pop();
        if (visited[u.second]) continue;
        total += u.first;
        visited[u.second] = true;
        for(auto it : g[u.second]) {
            if (not visited[it.to]) q.push(make_pair(it.cost, it.to));
        }
    }
    return total;
}

int main(){
    int v, e;
    cin >> v >> e;

    Graph g(v);
    rep(i,e){
        int a, b, c;
        cin >> a >> b >> c;
        g[a].emplace_back(b,c);
        g[b].emplace_back(a,c);
    }
    cout << prim(g) << endl;
}

Measured memory_bytes: 6804
N, M, C= gets.split.map(&:to_i)

b = gets.split.map(&:to_i)

A = Array.new( N ).map{ gets.split.map(&:to_i)  }

ans = 0

A.each do |a|
  
  f = C
  
  M.times do |i|
    f += a[i] * b[i]
  end
  
  ans += 1 if f > 0
end

p ans




Measured memory_bytes: 1788
import java.util.Scanner;
import java.util.Arrays;
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.LinkedList;

public class Main {

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int s[] = new int[N];
        int ans = 0;
        for (int i = 0; i < N; i++) {
            s[i] = sc.nextInt();
            ans += s[i];
        }
        if (ans % 10 != 0) {
            System.out.println(ans);
            return;
        } else {
            Arrays.sort(s);
            for (int i = 0; i < N; i++) {
                if (s[i] % 10 != 0) {
                    ans -= s[i];
                    System.out.println(ans);
                    return;
                }
            }
            System.out.println("0");
            return;

        }

    }
}


Measured memory_bytes: 21844
/**Bismillahir Rahmanir Rahim.**/
/*
         Md.Fagun Molla
         18ICTCSE006
         BSMRSTU(SHIICT)
*/
#include <bits/stdc++.h>
using namespace std;
#define  gcd(a,b)         __gcd(a,b)
#define  lcm(a,b)         (a*b)/gcd(a,b)
#define  ll               long long
#define  vi               std::vector<int>
#define  pb               push_back
#define  MAX              100007
#define  End              return 0;
#define                   pi acos(-1)


int main () {
    ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);
    int T=1;//  cin>>T;
    while(T--){
        ll a,b;
        cin>>a>>b;
        if(a<=b) cout<<"unsafe"<<endl;
        else cout<<"safe"<<endl;
    }
    End
}
/* pray for me
Do before die
*/


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

double N, A, B;
std::vector<double> h(100000);

template <class Function>
double binarySearch(double lb, double ub, Function check) {
	assert(lb <= ub);
	double d = ub - lb;
	for (int i = 0; i < 100; i++) {
		d /= 2;
		if (check(lb + d)) lb += d;
	}
	return lb;
}

int main() {
	
	std::cin >> N >> A >> B;
	for (int i = 0; i < N; i++)
		std::cin >> h[i];

	auto itr = std::max_element(h.begin(), h.end());
	int ans = std::round((binarySearch(0, std::ceil(*itr / B), 
		[](int num) {
		int add = A - B;
		int cnt = 0;
		for (auto& p : h) {
			if ((p - B*num) > 0)
				cnt += std::ceil((p - B*num) / add);
			if (cnt > num) 
				return true;
		}
		return false;
	})));

	std::cout << ans << std::endl;

	return 0;
}

Measured memory_bytes: 1280
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 999999999


int main(){
    vector<int> val,odd;
    for(int i=1;i*(i+1)*(i+2)<=6000000;i++){
        int x = (i*(i+1)*(i+2))/6;
        val.pb(x);
        if(x%2==1)odd.pb(x);
    }
    
    int dp[1000001],dp_odd[1000001];
    rep(i,1000001)dp[i] = INF,dp_odd[i]=INF;
    dp[0] = 0,dp_odd[0] = 0;
//    cout<<val.size()<<" "<<odd.size()<<endl;
    for(int i=1;i<=1000000;i++){
        for(int j=0;j<val.size();j++){
            if(i-val[j]>=0) dp[i] = min(dp[i] , dp[i-val[j]]+1);
        }
        for(int j=0;j<odd.size();j++){
            if(i-odd[j]>=0) dp_odd[i] = min(dp_odd[i] , dp_odd[i-odd[j]]+1);
        }
    }
    
    int n;
    while(cin>>n&&n){
        cout<<dp[n]<<" "<<dp_odd[n]<<endl;
    }

}

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

int digit(int n, int p){
    int counter = 0;
    while (n >= 1){
        n /= p;
        counter++;
    }
    return counter;
}

vector<int> binary(int n){
    int d = digit(n, 2);
    vector<int> binary(3);
    for (int i = 0; i < d; i++){
        if (n % 2 == 1){
            binary.at(2 - i) = 1;
            n = (n - 1) /2;
        }
        else n /= 2;
    }
    return binary;
}

int main(){
    
    int N;
    cin >> N;
    
    vector<int> Nvec(4);
    int n = N;
    for (int i = 0; i < 4; i++){
        int a = n % 10;
        Nvec.at(3 - i) = a;
        n = (n - a) / 10;
    }
    
    vector<int> condition(3);
    
    for (int i = 0; i < 8; i++){
        condition = binary(i);
        int sum = Nvec.at(0);
        for (int j = 0; j < 3; j++){
            if (condition.at(j) == 1){
                sum += Nvec.at(j + 1);
            }
            else {
                sum -= Nvec.at(j + 1);
            }
        }
        if (sum == 7){
            cout << Nvec.at(0);
            for (int k = 0; k < 3; k++){
                if (condition.at(k) == 1){
                    cout << '+';
                }
                else {
                    cout << '-';
                }
                cout << Nvec.at(k + 1);
            }
            cout << '=' << sum << endl;
            break;
        }
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#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;
const int mod = 1000000007;

const int MAXN = 1005;
const int MAXV = MAXN * (MAXN - 1) / 2;
vector<int> to[MAXV];
int id[MAXN][MAXN];
int toId(int i, int j) {
  if(i > j) swap(i, j);
  return id[i][j];
}

bool visited[MAXV];
bool calculated[MAXV];
int dp[MAXV];
int dfs(int v) {
  if (visited[v]) {
    if (!calculated[v]) return -1;
    return dp[v];
  }

  visited[v] = true;
  dp[v] = 1;
  for (int u : to[v]) {
    int res = dfs(u);
    if(res == -1) return -1;
    dp[v] = max(dp[v], res + 1);
  }
  calculated[v] = true;
  return dp[v];
}

int main() {
  int n;
  cin >> n;
  vector<vector<int>> a(n, vector<int>(n - 1));
  rep(i, n)rep(j, n - 1) {
    cin >> a[i][j];
    --a[i][j];
  }

  int V = 0;
  rep(i, n)rep(j, n) {
    if(i < j) id[i][j] = V++;
  }

  rep(i, n) {
    rep(j, n - 1) {
      a[i][j] = toId(i, a[i][j]);
    }
    rep(j, n - 2) {
      to[a[i][j + 1]].push_back(a[i][j]);
    }
  }

  int ans = 0;
  rep(i, V) {
    int res = dfs(i);
    if(res == -1) {
      puts("-1");
      return 0;
    }
    ans = max(ans, res);
  }
  cout << ans << endl;
}

Measured memory_bytes: 38528
import math
A,B,H,M=[int(i) for i in input().split()]
thetaH=2.0*math.pi*(H+M/60)/12
thetaM=2.0*math.pi*M/60

L2=(A*math.cos(thetaH)-B*math.cos(thetaM))**2+(A*math.sin(thetaH)-B*math.sin(thetaM))**2
L=math.sqrt(L2)

print(L)


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

using namespace std;

int main(){

    string S;
    cin >> S;
    
    int n = S.length();
    
    vector<int> N(n);
    
    int ansA = 0;
    int ansB = 0;
    int b = 0;
    
 
    for (int i = 0; i < n; i++) {
        N[i] = (int)(S[i] - '0');
    }
    
    for (int i = 0; i < n; i++) {
        if (N[i] == b) {
            ansA += 1;
        }
        if (b == 0) {
            b = 1;
        }else{
            b = 0;
        }
    }
    
    b = 1;
    
    for (int i = 0; i < n; i++) {
        if (N[i] == b) {
            ansB += 1;
        }
        if (b == 0) {
            b = 1;
        }else{
            b = 0;
        }
    }
    
    if (ansA >= ansB) {
        cout << ansB << endl;
    }else{
        cout << ansA << endl;
    }
    
    
    
    
    
    return 0;
    
}

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

    return arr


def solve(N):
    fact = factorization(N)
    ans = 0

    if N == 1:
        print(0)
        return

    for f in fact:
        s, c = f
        i = 1
        while True:
            if c >= i:
                c -= i
                ans += 1
            else:
                break
            i += 1
    print(ans)


if __name__ == '__main__':
    N = int(input())
    solve(N)


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

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x)// cerr << #x << " : " << x << '\n'; 
using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;

const ld PI = 3.14159265359;

const ll MOD = (ll) (1ll << 63);
const ll MAXN = (ll) 1e3 + 10;
const ll N = 1e5 + 100;
const ll INF = (ll) 3215;
const ld EPS = (ld) 1e-8;
const ll LOG = 20;

pll adj[] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
ll dis[MAXN][MAXN];
queue<pll> q;
ll r1, r2, c1, c2, h, w;

void check(){
	if((r1 <= 0) or (r2 > h) or (c1 <= 0) or (c2 > w)) {
		cout << "NO";
		exit(0);
	}
}
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	memset(dis, 31, sizeof dis);
	ll n;
	cin >> h >> w >> n;
	char x;
	
	cin >> r1 >> c1;
	str a, b;
	cin >> a >> b;
	swap(r1, c1);
	ll st = 0, en = w + 1 ;
	for(int i = n - 1; i >= 0; i--){
		debug(st);
		debug(en);
		if(b[i] == 'L') en ++;
		if(b[i] == 'R') st --;
		st = max(st, 0ll);
		en = min(en, w + 1ll);
		en = max(en, st + 1);
		if(st + 1 == en) break;
		if(a[i] == 'R') en --;
		if(a[i] == 'L') st ++;
		st = max(st, 0ll);
		en = min(en, w + 1ll);
		en = max(en, st + 1);
		if(st + 1 == en) break;
		
	}
	debug(st);
	debug(en);
	if( !((r1 > st) and (r1 < en)) ) return cout << "NO", 0;
	debug("salam");
	st = 0, en = h + 1 ;
	for(int i = n - 1; i >= 0; i--){
		if(b[i] == 'U') en ++;
		if(b[i] == 'D') st --;
		st = max(st, 0ll);
		en = min(en, h + 1ll);
		en = max(en, st + 1);
		if(st + 1 == en) break;
		if(a[i] == 'D') en --;
		if(a[i] == 'U') st ++;
		st = max(st, 0ll);
		en = min(en, h + 1ll);
		en = max(en, st + 1);
		if(st + 1 == en) break;
	}
	
	debug(st);debug(en);
	if( !((c1 > st) and (c1 < en)) ) return cout << "NO", 0;
	cout << "YES";
	return 0;
}

/*
                                 ____              ,----..               ,----..
   ,---,                       ,'  , `.           /   /   \             /   /   \
  '  .' \                   ,-+-,.' _ |          /   .     :           /   .     :
 /  ;    '.              ,-+-. ;   , ||         .   /   ;.  \         .   /   ;.  \
:  :       \            ,--.'|'   |  ;|        .   ;   /  ` ;        .   ;   /  ` ;
:  |   /\   \          |   |  ,', |  ':        ;   |  ; \ ; |        ;   |  ; \ ; |
|  :  ' ;.   :         |   | /  | |  ||        |   :  | ; | '        |   :  | ; | '
|  |  ;/  \   \        '   | :  | :  |,        .   |  ' ' ' :        .   |  ' ' ' :
'  :  | \  \ ,'        ;   . |  ; |--'         '   ;  \; /  |        '   ;  \; /  |
|  |  '  '--'          |   : |  | ,             \   \  ',  /          \   \  ',  /
|  :  :                |   : '  |/               ;   :    /            ;   :    /
|  | ,'                ;   | |`-'                 \   \ .'              \   \ .'
`--''                  |   ;/                      `---`                 `---`
                       '---'

*/




Measured memory_bytes: 8856
fun main(args: Array<String>) {
    val (N, K, Q) = readInputLine().split(" ").map { it.toInt() }
    
    val ans = IntArray(N)
    
    for (i in 1..Q) {
        val answer = readInputLine().toInt() - 1
        ans[answer]++
    }
    
    for (i in 0 until N) {
        if (ans[i] + K > Q) {
            println("Yes")
        } else {
            println("No")
        }
    }
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 46284
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: u32,
        a: u32,
        b: u32
    }
    let ans = (0..n + 1)
        .filter(|i| {
            let sum = i.to_string().chars().map(|c| c.to_digit(10).unwrap()).sum();
            a <= sum && sum <= b
        })
        .sum::<u32>();
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int n;
ll m;
ll a[100001],sa[100002];
int main(){
    ll ans=0;
    cin>>n>>m;
    rep(i,n) cin>>a[i];
    sort(a,a+n);
    rep(i,n) sa[i+1]=sa[i]+a[i];
    int lb=1,ub=200001;
    while(ub-lb>1){
        int mid=(ub+lb)/2;
        ll ss=0,tm=0;
        rep(i,n){
            int ti=lower_bound(a,a+n,mid-a[i])-a;
            tm+=n-ti;
            ss+=a[i]*(n-ti)+sa[n]-sa[ti];
        }
        if(tm>=m) lb=mid,ans=ss-(tm-m)*lb;
        else ub=mid;
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std; 

int n, m; 
int dp[105][105], a[105][105]; 

int main() {
    scanf("%d %d", &n, &m); 
    for (int i = 1; i <= n; i++) {
        char s[105]; 
        scanf("%s", s + 1); 
        for (int j = 1; j <= m; j++) {
            a[i][j] = (s[j] == '.'); 
        }
    }
    dp[1][1] = a[1][1] == 0; 
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (i == 1 && j == 1) continue ; 
            dp[i][j] = 1e9; 
            if (a[i][j] == 0) {
                if (i > 1) dp[i][j] = min(dp[i][j], dp[i - 1][j] + ((a[i][j] == 0) & (a[i][j] != a[i - 1][j]))); 
                if (j > 1) dp[i][j] = min(dp[i][j], dp[i][j - 1] + ((a[i][j] == 0) & (a[i][j] != a[i][j - 1]))); 
            }   
            else {
                if (i > 1) dp[i][j] = min(dp[i][j], dp[i - 1][j]); 
                if (j > 1) dp[i][j] = min(dp[i][j], dp[i][j - 1]); 
            }
        }
    }
    printf("%d\n", dp[n][m]); 
    return 0; 
}

Measured memory_bytes: 384
//BISMILLAHHIR RAHMANIR RAHIM
#include<bits/stdc++.h>
using namespace std;
typedef long long int            ll;
typedef unsigned long long int   ull;
#define min3(a,b,c)              min(a,min(b,c))
#define F                        first
#define S                        second
#define PB                       push_back
#define MP                       make_pair
#define PI                       2*acos(0.0)
#define REP(i,a,b)               for(int i = a; i<=b; i++)
int main()
{
    int a,b,mn;
    cin>>a>>b;
    mn=min(a,b);
    if(mn==a){
        for(int i=0; i<b; i++){
            cout<<mn;
        }
    }
    else {
        for(int i=0; i<a; i++){
            cout<<mn;
        }
    }
    return  0;

}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
count = 0
mult = 1
for i in range(N):
    if i==0:
        if A[i]%2==0:
            count+=3**(N-1)
            mult *= 2
        else:
            count+=2*3**(N-1)
        continue
    if A[i]%2==0:
        count += mult*3**(N-i-1)
        mult *= 2
    else:
        count += mult*2*3**(N-i-1)


print(count)

Measured memory_bytes: 3064
#include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long

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

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

    cout << ans << endl;
}


Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>
#include <cmath>

using namespace std;



int main(int argc, const char * argv[]) {


    double a,b;
    cin >> a >> b;
    
    int c;
    cin >> c;
    
    double ang;
    ang = 2*M_PI * c/360;

    //面積
    double s;
    s= 0.5 * a * b * sin(ang);
    printf("%5f\n",s);
    
    //周の長さ
    double L;
    L = a + b + sqrt(a*a + b*b - 2*a*b*cos(ang));
    printf("%5f\n",L);
    //    cout << d << endl;
 
    //高さ
    double h;
    h = b * sin(ang);
    printf("%5f\n",h);
    
    return 0;
}



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

#define int long long
#define MAX_N (200005)
#define INF (1LL<<60)
#define EPS (1e-7)
#define DEBUG(x) cerr << #x <<":"<< x << endl;
#define DEBUGVC(x) cerr << #x <<": "; for(auto p:(x)) cerr << p <<" "; cerr << endl;
#define DEBUGVCP(x) for(auto p:(x)) cerr << #x <<": "<< p.first <<", "<< p.second << endl;
#define DEBUG2(x, y) cerr << #x <<" : "<< x <<", "<< #y <<" : "<< y << endl;
#define DEBUG3(x, y, z) cerr << #x <<" : "<< x <<", "<< #y <<" : "<< y <<", "<< #z <<" : "<< z << endl;
const int MOD = (int)1e9+7;
#define P pair<int,int>


signed main() {
    int x, a;
    cin >> x >> a;

    if(x < a) cout << 0 << endl;
    else cout << 10 << endl;
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long 
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back 
#define mp make_pair
#define inf 2000000009
#define mod 1000000007
using namespace std;

int main()
{ 
    fast;
    ll n,k;
    cin>>n>>k;
  string s1;
  cin>>s1;

vector<bool> s(n);
for(ll i=0;i<s1.size();i++)
	s[i]=(s1[i]=='R');

 
ll step=0,i=1;

  while(step<k and i<n)
  {
  	if(s[i]==s[i-1])
  		i++;
  	else
  	{ step++;

  		bool find=s[i];
  		ll j=i+1;

  		while(j<n and s[j]==find)
  			j++;
  		
  		for(ll k=i;k<j;k++)
  			s[k]=1-s[k];

  		ll sz=(j-i)/2;

  		for(ll k=i;k<i+sz;k++)
  			swap(s[k],s[sz+k]);

  		i=j;
  	}
  }

ll ans=0;
  for(ll i=1;i<n;i++)
  	if(s[i]==s[i-1])
  		ans++;
  	cout<<ans<<endl;
}


Measured memory_bytes: 512
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ll long long int
#define pb push_back
#define mp make_pair
#define ld long double
#define sz(a) (ll)(a).size()

typedef tree<pair<ll,ll> ,null_type,less<pair<ll,ll> >,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//K-th smallest
//cout << k << "kth smallest: " << *A.find_by_order(k-1) << endl;
//NO OF ELEMENTS < X
//cout << "No of elements less than " << X << " are " << A.order_of_key(X) << endl;

ll n, dp[100005], a[100005];

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

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

Measured memory_bytes: 1792
A = int(input())
B = int(input())
C = int(input())
X = int(input())
#A,B,C,X = 2,2,2,100
ans = 0

for a in range(0,A+1):
	for b in range(0,B+1):
		for c in range(0,C+1):
			if a * 500 + b * 100 + c * 50 == X: 
				ans = ans + 1

print(ans)

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

int a[16], x[16][16], y[16][16];
bool m[16];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        for(int j = 0; j < a[i]; j++){
            cin >> x[i][j] >> y[i][j];
            x[i][j]--;
        }
    }
    int ans = 0;
    for(int i = 0; i < (1 << n); i++){
        int cnt = 0;
        bool ok = true;
        for(int j = 0; j < n; j++){
            m[j] = false;
            if(i >> j & 1){
                cnt++;
                m[j] = true;
            }
        }
        for(int j = 0; j < n; j++){
            if(m[j]){
                for(int k = 0; k < a[j]; k++){
                    if(y[j][k] == 1 && !m[x[j][k]]) ok = false;
                    if(y[j][k] == 0 && m[x[j][k]]) ok = false;
                }
            }
        }
        if(!ok) continue;
        ans = max(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256