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

int N;
vector<int> s;

int main()
{
    cin >> N;
    s.resize(N);
    for (auto &v : s) cin >> v;

    vector<int> dp(10, -1);
    dp[0] = 0;
    for (auto v : s)
    {
        vector<int> dp_new = dp;
        for (int i=0; i<10; i++)
        {
            if (dp[(i-v+100)%10]>=0) dp_new[i] = max(dp[i], dp[(i-v+100)%10]+v);
        }
        if (dp[v%10] < 0) dp_new[v%10] = v + dp[0];
        dp = dp_new;
    }
    int max_ = 0;
    for (int i=1; i<=9; i++) max_ = max(max_, dp[i]);
    cout << max_ << endl;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author EDGE
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task160B solver = new Task160B();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task160B {
        public void solve(int testNumber, FastReader in, PrintWriter out) {
            long n = in.nextLong();
            long a = n / 500;
            long b = n - a * 500;
            long c = b / 5;
            long k = b - c * 5;
            long ans = a * 1000 + c * 5;
            out.println(ans);
        }

    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader(InputStream inputStream) {
            br = new BufferedReader(new
                    InputStreamReader(inputStream));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

    }
}



Measured memory_bytes: 22740
main = do
    getLine
    s <- getLine
    print $ countABC s

countABC :: String -> Integer
countABC (x:y:[]) = 0
countABC (x:y:z:xs)
    | x == 'A' && y == 'B' && z == 'C'  = 1 + countABC (y:z:xs)
    | otherwise                         = countABC (y:z:xs)


Measured memory_bytes: 380
#import<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long LL;
LL a,b,c,d,i,j,k,m,n;
string s;
main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>a>>b>>c>>d;
	if((a-1)/d<(c-1)/b)cout<<"No";
	else cout<<"Yes";
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
	int a, b;
	cin >> a >> b;
	int n = b - a;
	cout << n * (n + 1) / 2 - b << endl;

}

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

int main()
{
    int n,ans = 0,cnt = 0;
    string s;
    cin >> n >> s;
    for (int i = 0; i < n; i++)
    {
        if (s[i] == 'R')
            cnt++;
    }
    for (int i = 0; i< cnt; i++)
    {
        if (s[i] == 'W')
            ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = LLONG_MAX;

int main()
{
    int n, q;
    string s;
    cin >> n >> q >> s;
    vector<int> a(n + 1, 0);
    vector<int> l(q), r(q);
    for (int i = 0; i < q; i++)
    {
        cin >> l[i] >> r[i];
    }
    for (int i = 0; i < n; i++)
    {
        if (s[i] == 'C' && s[i - 1] == 'A')
        {
            a[i + 1] = a[i] + 1;
        }
        else
        {
            a[i + 1] = a[i];
        }
    }
    for (int i = 0; i < q; i++)
    {
        cout << (a[r[i]] - a[l[i]]) << endl;
    }
}


Measured memory_bytes: 2176
#include <algorithm>
#include <bits/stdc++.h>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0; i != n; ++i)
#define REPR(i, n) for(int i = n - 1; i != -1; --i)
#define FOR(i, a, b) for(int i = a; i != b; ++i)
#define RBF(i, n) for(auto &i : n)
#define ABS(n) (n < 0 ? -n : n)
#define MIN(a, b) (a < b ? a : b)
#define MAX(a, b) (a > b ? a : b)
#define IN(n) (cin >> n)
#define OUT(n) (cout << n << "\n")
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int N;
  IN(N);
  vector<pair<int,int>> X(N);
  REP(i,N){
    int a;
    cin >> a;
    X[i] = make_pair(a,i+1);
  }
  sort(ALL(X));
  REP(i,N) cout << X[i].second << " ";
  cout << endl;
}

Measured memory_bytes: 1664
def main():
    N, x, *a = map(int, open(0).read().split())
    ans = a[0] - x if x < a[0] else 0
    pre = min(a[0], x)
    for i in range(1, N):
        dif = pre + a[i] - x
        if 0 < dif:
            ans += dif
            a[i] -= dif
        pre = a[i]
    print(ans)
    return


main()


Measured memory_bytes: 14092
#include<stdio.h>
 
void swap(int* a,int* b){
  int tmp=*a;
  *a=*b;
  *b=tmp;
}
 
int Partition(int A[],int p,int r){
  int x = A[r];
  int i=p-1,j;
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i++;
      swap(&A[i],&A[j]);
    }
  }
  swap(&A[i+1],&A[r]);
  return i+1;
}
 
int main(){
  int n,i,x;
  int A[100000];
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&A[i]);
  x=Partition(A,0,n-1);
  for(i=0;i<n;i++){
    if(i)printf(" ");
    if(i==x)printf("[");
    printf("%d",A[i]);
    if(i==x)printf("]");
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 2112
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define MOD 1000000007
typedef long long int ll;
void llswap(ll *x,ll *y){ll temp;temp=*x;*x=*y;*y=temp;}
void swap(int *x,int *y){int tmp;tmp=*x;*x=*y;*y=tmp;}
int max(int x,int y){return x>y?x:y;}
int min(int x,int y){return x>y?y:x;}
ll llmax(ll x,ll y){return x>y?x:y;}
ll llmin(ll x,ll y){return x>y?y:x;}
int asc(const void *a,const void *b){return *(int*)a-*(int*)b;}
int desc(const void *a,const void *b){return *(int*)b-*(int*)a;}

int main(){
    int n,p[2000],pc[2000];

    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&p[i]);
        pc[i]=p[i];
    }
    qsort(pc,n,sizeof(int),asc);
    int cnt=0;
    for(int i=0;i<n;i++){
        if(pc[i]!=p[i]){
            cnt++;
        }    
    }
    if(cnt==2||cnt==0){
        printf("YES\n");
    }else{
        printf("NO\n");
    }
    return 0;



}

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

using namespace std;

template<typename tp> inline void read(tp &x) {
	x = 0; register char c = getchar(); register bool f = 0;
	for (; c < '0' || c > '9'; f |= (c == '-'), c = getchar());
	for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
	if (f) x = -x;
}

const int N = 205;

bool vis[N];
bool mp[N][N];
int color[N], n;

void dfs(int u) {
    int cr;
    vis[u] = 1;
    if (color[u] == 1) cr = 2; else cr = 1;
    for (int i = 1; i <= n; ++i) {
        if (mp[u][i]) {
            if (!vis[i]) {
                color[i] = cr;
                dfs(i);
            } else {
                if (color[i] != cr) {
                    puts("-1");
                    exit(0);
                }
            }
        }
    }
}

queue<int> q;
char s[N];

int fun (int u) {
    memset(vis, 0, sizeof vis);
    memset(color, 0, sizeof color);
    while (!q.empty()) {
        q.pop();
    }
    q.push(u);
    color[u] = 1;
    vis[u] = 1;
    while (!q.empty()) {
        int a = q.front();
        q.pop();
        for (int i = 1; i <= n; ++i) {
            if (mp[a][i] && vis[i] == 0) {
                vis[i] = 1;
                color[i] = color[a] + 1;
                q.push(i);
            }
        }
    }
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        ans = max(ans, color[i]);
    }
    return ans;
}

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        scanf("%s", s + 1);
        for (int j = 1; j <= n; ++j) {
            mp[i][j] = (s[j] - '0');
        }
    }
    memset(vis, 0, sizeof vis);
    color[1] = 1;
    dfs(1);
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        ans = max(ans, fun(i));
    }
    printf("%d", ans);
    return 0;
} 

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int a,b;
  char c;
  while(1){
    scanf("%d %c %d",&a,&c,&b);
    if(c == '?')break;
    switch (c){
    case '+':
      printf("%d\n",a+b);
      break;
    case '-':
      printf("%d\n",a-b);
      break;
    case '*':
      printf("%d\n",a*b);
      break;
    case '/':
      printf("%d\n",a/b);
      break;
    }
  }
  return 0;
} 

Measured memory_bytes: 600
def count(a,b):
  c = 0
  for i in set(a):
    if i in b:
      c += 1
  return c
n = int(input())
s = input()
lmax = 0
i = n-1
while i>=0:
  left = s[:i]
  right = s[i:]
  c = count(left,right)
  lmax = max(lmax,c)
  i-=1
print(lmax)

Measured memory_bytes: 3064
#!/usr/bin/env python
# -*- coding: utf-8 -*-

N = int(input())
A = list(map(int, input().split()))

n_rmv = 0
A.sort()
A.append(0)

i = 0
while i < len(A):
    if A[i] == 0: break
    try:
        tmp = A[i]
        if A[i+A[i]-1] != A[i]:
            while tmp == A[i]:
                n_rmv += 1
                i += 1
        else:
            i += A[i]
            while tmp == A[i]:
                n_rmv += 1
                i += 1
    except IndexError:
        n_rmv += len(A[i:-1])
        break
print(n_rmv)


Measured memory_bytes: 14492
import sys
input = sys.stdin.readline
import numpy as np
def print_ans(N, ar):
    """Test Case
    >>> print_ans(3, [1, 4, 3])
    4
    3
    4
    >>> print_ans(2, [5, 5])
    5
    5
    """
    ar = np.array(ar)
    ar_idx = np.argsort(ar)

    for i in range(N):
        for k in reversed(range(N)):
            if i != ar_idx[k]:
                print(ar[ar_idx[k]])
                break

if __name__ == '__main__':
    N = int(input().rstrip())
    ar = [int(input().rstrip()) for i in range(N)]
    print_ans(N, ar)


Measured memory_bytes: 24764
infty = 10**21
white = 0
gray = 1
black = 2
n = input()
m = [[0 for i in xrange(n)] for j in xrange(n)]
l = m
d = [0 for i in xrange(n)]
p = [0 for i in xrange(n)]
color = [0 for i in xrange(n)]


def prim():
    
    
    for i in xrange(n):
        d[i] = infty
        p[i] = -1
        color[i] = white

    d[0] = 0
    
    while True:
        minv = infty
        u = -1
        for i in xrange(n):
            if minv > d[i] and color[i] != black:
                u = i
                minv = d[i]
        if u == -1:
            break
        color[u] = black
        for v in xrange(n):
            if color[v] != black and m[u][v] != infty:
                if d[v] > m[u][v]:
                    d[v] = m[u][v]
                    p[v] = u
                    color[v] = gray
    sum = 0
    for i in xrange(n):
        if p[i] != -1:
            sum += m[i][p[i]]
    return sum

for i in xrange(n):
    for j in xrange(n):
        if j == 0:
            l[i] = map(int,raw_input().split())
        if l[i][j] == -1:
            m[i][j] = infty
        else:
            m[i][j] = l[i][j]
print prim()

Measured memory_bytes: 6472
import numpy as np
n=int(input())
A=list(map(int,input().split()))
cnt=[0]*(10**6+10)
for i in A:
    cnt[i]+=1


if np.gcd.reduce(A) !=1:
    print("not coprime");exit()
elif np.all([sum(cnt[i::i])<=1 for i in range(2,10**6+1)]):
    print("pairwise coprime")
else:
    print("setwise coprime")


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

int main() {
  using pii = pair<int,int>;
  int H, W;
  cin >> H >> W;
  char s[H][W];
  int d[H][W];
  int dy[4]={0,1,0,-1}, dx[4]={1,0,-1,0};
  int w=0;
  for(int i=0;i<H;i++) {
    for(int j=0;j<W;j++) {
      cin >> s[i][j];
      if(s[i][j]=='.') w++;
      d[i][j]=-1;
    }
  }
  queue<pii> que;
  que.push(pii(0,0));
  d[0][0]=1;
  while(que.size()) {
    pii p=que.front();
    que.pop();
    if(p==pii(H-1,W-1)) break;
    for(int i=0;i<4;i++) {
      int ny=p.first+dy[i], nx=p.second+dx[i];
      if(0<=ny&&ny<H&&0<=nx&&nx<W&&s[ny][nx]=='.'&&d[ny][nx]==-1) {
        que.push(pii(ny,nx));
        d[ny][nx]=d[p.first][p.second]+1;
      }
    }
  }
  if(d[H-1][W-1]!=-1) cout << w-d[H-1][W-1] << endl;
  else cout << -1 << endl;
}


Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main(){
  int cnt[101]={0};
  int num,max = 0;
  while(cin >> num){
	cnt[num]++;
	if(cnt[num] > max) max = cnt[num];
  }
  for(int i=1;i<101;i++){
	if(cnt[i] == max)
	  cout << i << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define t_times int t; cin >> t; while(t--)
#define parr(a, n) for(int __i = 0; __i < (int )n; __i++) cout << a[__i] << ' '; cout << '\n'
#define fr(i, p, n) for(int i = (int )p; i < (int )n; i++)
#define frn(i, p, n) for(int i = (int )p; i <= (int )n; i++)
#define rev(i, n, p) for(int i = (int )n; i >= (int )p; i--)
#define all(c) (c).begin(), (c).end()
#define sci(n) scanf("%d", &n)
#define scl(n) scanf("%lld", &n)
#define prin(n) printf("%d\n", n)
#define prln(n) printf("%lld\n", n)
#define mp make_pair
#define F first
#define S second
#define pb push_back
#define bp __builtin_popcount
typedef long long int LL;
typedef unsigned long long ULL;
typedef unsigned int uint;
typedef pair< int, int> ii;
typedef vector< int> vi;

const int mod = 1e9 + 7;
const LL INF = 9e18 + 2e17;
const int inf = 2e9;
const int N = 1e5 + 22;
const double eps = 1e-10;
const double PI = 3.14159265;

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

void _solve() {
    cin >> n;
    fr(i, 0, n) cin >> a[i];
    dp[0] = 0, dp[1] = abs(a[1] - a[0]);
    fr(i, 2, n) 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];
}
int main() {
    fastio;
    //t_times
    _solve();
    return 0;
}




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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using P = pair<ll, ll>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 62;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};


int main()
{
  ll a, b; cin >> a >> b;
  cout << a*b/__gcd(a, b) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <climits>
using namespace std;

int main(int argc, char **argv)
{
	cin.tie(NULL);

	int N;
	cin >> N;

	int x[N], y[N], h[N];

	int i;
	for (i = 0; i < N; i++)
	{
		cin >> x[i] >> y[i] >> h[i];
	}

	for (i = 0; i <= 100; i++)
	{
		for (int j = 0; j <= 100; j++)
		{
			long long ch = 0;
			long long limit = LONG_MAX;
			int k = 0;
			for (k = 0; k < N; k++)
			{
				if (h[k] == 0)
				{
					int tmp_limit = abs(x[k]-i) + abs(y[k] - j);
					if (ch > tmp_limit)
					{
						break;
					}
					if (tmp_limit < limit)
					{
						limit = tmp_limit;
					}
				}
				else 
				{
					if (ch == 0)
					{
						ch = abs(x[k] - i) + abs(y[k] - j) + h[k];

					}
					else if (ch != (abs(x[k] - i) + abs(y[k] - j) + h[k]))
					{
						break;
					}

					if ((ch > limit) || (ch < 1) )
					{
						break;
					}
				}
				
			}
			if (k >= N)
			{
				cout << i << " " << j << " " << ch << endl;
				return 0;
			}
			//cout << i << " " << j << " " << ch << endl;
		}

	}
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
bool n[101];
int m,a;
int main() {
	cin>>m;
	for (int i=1;i<=m;i++)
	cin>>a,n[a]=1;
	int ans=0;
	for (int i=1;i<=100;i++)
	if (n[i]) ans++;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n, c := scanInt(), scanInt()
	x := make([]int, n)
	v := make([]int, n)
	for i := 0; i < n; i++ {
		x[i], v[i] = scanInt(), scanInt()
	}

	memo1 := make([][2]int, n+1)
	now := 0
	for i := 0; i < n; i++ {
		now += v[i]
		if now-x[i] > memo1[i][0] {
			memo1[i+1] = [2]int{now - x[i], x[i]}
		} else {
			memo1[i+1] = memo1[i]
		}
	}
	memo2 := make([][2]int, n+1)
	now = 0
	for i := 0; i < n; i++ {
		now += v[n-1-i]
		if now-c+x[n-1-i] > memo2[i][0] {
			memo2[i+1] = [2]int{now - c + x[n-1-i], c - x[n-1-i]}
		} else {
			memo2[i+1] = memo2[i]
		}
	}

	ans := 0
	for i := 0; i <= n; i++ {
		ans = max(ans, memo1[i][0]+memo2[n-i][0]-min(memo1[i][1], memo2[n-i][1]))
	}
	fmt.Fprintln(wr, ans)

}


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

long count(long a){
  long c=0;
  while(a%2==0){
    a=a/2;
    c++;
  }
  return c;
}


int main() {
  long N;
  cin>>N;
  vector<long> A(N);
  for(int i=0;i<N;i++){
    cin>>A.at(i);
  }
  long ans=0;
  for(int i=0;i<N;i++){
    ans+=count(A.at(i));
  }
 // ans=count(2);
  cout<<ans;
}

Measured memory_bytes: 384
#pragma GCC optimize("Ofast")
#include <set>
#include <map>
#include <cmath>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define yzh 2333333
#define bql 2147483647
using namespace std;
int a,b,t;
int main()
{
	fast;
	cin>>a>>b>>t;
	cout<<t/a*b<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <iomanip>
using namespace std;
 
int main(){
    int a, b;
    char op;
    
    while (1){
        cin >> a >> op >> b;
        if ( op == '?' ){
            break;
        }
        
        if ( op == '+' ){
            cout << a + b << endl;
        } else if ( op == '-' ){
            cout << a - b << endl;
        } else if ( op == '*' ){
            cout << a * b << endl;
        } else if ( op == '/' ){
            cout << a / b << endl;
        } else {
            
        }
       
    }
    
    
   return 0;		 
}



Measured memory_bytes: 3084
#include <stdio.h>

int main() {

  int a,b,c;

  a = b = c= 0;

  scanf("%d %d %d",&a,&b,&c);

  if(a==1 && b == 1 && c == 0) printf("Open\n");
  else if(a == 0 && b == 0 && c == 1) printf("Open\n");
  else printf("Close\n");

  return 0;

}

Measured memory_bytes: 584
def isprime(x):
    if x == 2:
        return True

    if x < 2 or x % 2 == 0:
        return False

    i = 3
    while i <= x ** 0.5:
        if x % i == 0:
            return False
        i = i + 2

    return True

count = 0
n = int(input())
for i in range(n):
    x = int(input())
    if isprime(x):
        count += 1
print(count)


Measured memory_bytes: 5668
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <fstream>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <time.h>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) (min(a,b) <= (x) && (x) <= max(a,b)) //hei
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 998244353LL
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589


#define izryt bool
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
	std::fill((T*)array, (T*)(array + N), val);
}
pll Dir[4] = {
	{ -1 ,0 },{ 0 , 1 },{ 1 ,0 },{ 0 ,-1 }
};

//[a, b)
#define Getsum(ar, a,b) (ar[b] - ar[a])
#define INF 10000000000000000LL
#define chmax(a,b) a = max(a,b)
#define chmin(a,b) a = min(a,b)

struct Edge {
	int from, to;
	ll w;
	bool operator<(const Edge& rhs) const {
		return MP(w, MP(from, to)) < MP(rhs.w, MP(rhs.from, rhs.to));
	}

};
typedef vector<vector<Edge>> Graph;

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



ll mod_pow(ll x, ll n, ll mod) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x %mod;
		x = x * x%mod;
		n >>= 1;
	}
	return res;
}

signed main(void) {

	int n;
	int cou[100001] = {};
	cin >> n;
	REP(i, n) {
		int d;
		cin >> d;
		cou[d]++;
		if (i != 0 && d == 0) {
			cout << 0 << endl;
			return 0;
		}

	}

	int sum = 1;
	ll ans = 1;


	rep(i, 1, 100001) {
		if (cou[i - 1] == 0) ans = 0;

		ans *= mod_pow(cou[i-1],cou[i],MODU);
		ans = ans % MODU;

		sum += cou[i];
		if (sum == n) break;
	}

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

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

int num[100002];

int main() {
	int n;
	
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a, b;
		cin >> a >> b;
		num[a - 1]++;
		num[b]--;
	}
	for (int i = 1; i < 100002; i++) {
		num[i] += num[i - 1];
	}
	
	for (int i = 100001; i >= 0; i--) {
		if (num[i] >= i) {
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}

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

int main(){
    ll ans=0;
    ll N,K;cin>>N>>K;
    for(int i=1;i<N+1;i++){
        int j = 0;
        ll tg = i*pow(2,j);
        while(tg<K){
            tg *= 2;
            j++;
        }
        ans += (1.0/N)*pow(0.5,j);
    }
    cout<<fixed<<setprecision(10)<<ans;
    return 0;
}

Measured memory_bytes: 256
def solve(s)
  m = {}
  s.split('').each do |i|
    v = m.key?(i) ? m[i] : 0
    m.merge!({i => v + 1})
  end

  m.each do |_, v|
    return 'No' if v != 2
  end

  'Yes'
end

def main
  stdin = STDIN.gets
  s = stdin.strip!
  puts solve(s)
end

main

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

const int Maxn = 200005;
int n, ct, cnt, top, a[Maxn], head[Maxn], ans[Maxn], val[Maxn];
pair <int, int> sta[Maxn];
struct edg
{
	int nxt, to;
} edge[2 * Maxn];
void add(int x, int y)
{
	edge[++cnt] = (edg){head[x], y};
	head[x] = cnt;
}
void dfs(int u, int fa)
{
	int pos = lower_bound(val + 1, val + 1 + ct, a[u]) - val;
	bool added = pos == ct + 1;
	if (added) ct++;
	ans[u] = ct;
	sta[++top] = make_pair(pos, val[pos]);
	val[pos] = a[u];
	for (int i = head[u]; i; i = edge[i].nxt)
	{
		int to = edge[i].to;
		if (to != fa)
			dfs(to, u);
	}
	val[sta[top].first] = sta[top].second, top--;
	if (added) ct--;
}
int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
		scanf("%d", &a[i]);
	for (int i = 1; i < n; i++)
	{
		int x, y;
		scanf("%d%d", &x, &y);
		add(x, y), add(y, x);
	}
	dfs(1, 0);
	for (int i = 1; i <= n; i++)
		printf("%d\n", ans[i]);
	return 0;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> P(N);
  for (int i = 0; i < N; i++) cin >> P.at(i);
  sort(P.begin(), P.end());
  int ans = 0;
  for (int i = 0; i < K; i++) ans += P.at(i);
  cout << ans << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define SZ(v) int((v).size())
#define ALL(vec) begin(vec), end(vec)
using namespace std;
typedef long long i64;
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
  stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
string to_string(char c) { return "'" + string(1, c) + "'";}
string to_string(string s) { return '"' + s + '"';}
string to_string(const char* s) { return to_string((string) s);}
template<typename A> string to_string(A);
template<typename A, typename B> string to_string(pair<A, B> p){
  return "(" + to_string(p.first) + ": " + to_string(p.second) + ")";}
template<typename A> string to_string(A v) {bool f = false; string r = "{"; 
  for (auto x: v) {if (f) r += ", "; r += to_string(x); f = true;} return r += "}";}
template<typename A> string to_string(vector<vector<A>> v) {string r; 
  for (auto x: v) r += "\n" + to_string(x); return r;}
void err(istream_iterator<string>) { cerr << endl; }
template<typename T,typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " =: " << to_string(a) << "; "; err(++it, args...); }
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
int const MOD = 1e9 + 7;
long long const INF = 1e18 + 42;
/*************************************/
const int N = 82, M = 7000, S = 2 * M + 42;
int dp[N][N][S];
int a[N][N];
int b[N][N];

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> a[i][j];
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> b[i][j];
      a[i][j] -= b[i][j];
      b[i][j] = -a[i][j];
    }
  }
  dp[0][0][M + a[0][0]] = 1;
  dp[0][0][M + b[0][0]] = 1;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (i + 1 < n) {
        for (int k = 0; k < S; ++k) {
          if (k + a[i + 1][j] < S && k + a[i + 1][j] >= 0) {
            dp[i + 1][j][k + a[i + 1][j]] |= dp[i][j][k];
          }
          if (k + b[i + 1][j] < S && k + b[i + 1][j] >= 0) {
            dp[i + 1][j][k + b[i + 1][j]] |= dp[i][j][k];
          }
        }
      }
      if (j + 1 < m) {
        for (int k = 0; k < S; ++k) {
          if (k + a[i][j + 1] < S && k + a[i][j + 1] >= 0) {
            dp[i][j + 1][k + a[i][j + 1]] |= dp[i][j][k];
          }
          if (k + b[i][j + 1] < S && k + b[i][j + 1] >= 0) {
            dp[i][j + 1][k + b[i][j + 1]] |= dp[i][j][k];
          }
        }
      }
    }
  }
  int ans = MOD;
  for (int k = 0; k < S; ++k) {
    if (dp[n - 1][m - 1][k]) {
      uin(ans, abs(k - M));
      //~ error(k - M);
    }
  }
  kek(ans);
  
  return 0;
}


Measured memory_bytes: 360704
from itertools import accumulate
n,k = list(map(int, input().split()))
a = list(range(0,n+1))
bleft = list(accumulate(a))
bright = list(accumulate(reversed(a)))
ans = 0
mo = 10**9 + 7
for i in range(k-1,n+1):
    ans = (ans + bright[i] - bleft[i] + 1) % mo

print(ans)
    


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll W, a, b;
    cin >> W >> a >> b;
    cout << max(0LL, max(a, b) - min(a, b) - W) << endl;
    return 0;
}


Measured memory_bytes: 3596
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
const ll N=1e9+7;
int main()
{
    ll n;
    scanf("%I64d",&n);
    ll sum=1;
    for(ll i=1;i<=n;i++)
    {
        sum*=i;
        sum%=N;
    }
    printf("%I64d\n",sum);
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
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;
	cin >> N;
	char c;

	ll dp0 = 0;
	ll dp1 = -1e18;
	cin >> dp0;
	bool hajimete = 0;
	ll purasu = 0;

	rep(i, N - 1) {
		int a;
		cin >> c >> a;

		if (hajimete == 0) {
			if (c == '+') {
				dp0 += a;
			}
			else {
				hajimete = 1;
				dp0 -= a;
			}
		}
		else {
			if (c == '+') {
				purasu += a;
			}
			else {
				dp1 = max(dp1 + purasu + a, dp0 + a - purasu);
				dp0 += purasu - a;
				purasu = 0;
			}
		}
	}
	co(max(dp0, dp1) + purasu);

	Would you please return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<sstream>
#include<cmath>
#include<vector>
#include<iomanip>
#include<map>
#include<set>
#include<queue>
#include<deque>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < n;i++)
int main() {
	int n, sum = 0,ans =0;cin >> n;vector<int> a(n);
	rep(i, n) {
		cin >> a[i];sum = 0;
		while (a[i] % 2 == 0) {
			sum++;
			a[i] /= 2;
		}
		ans += sum;
	}
	cout << ans << endl;
}

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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<double> vd;
typedef vector<vd> vdd;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);

template <typename First>
void debug_print_in(First first){
  cerr << first << endl;
  return;
}

template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}

void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

template <typename First>
void OUT(First first){
  cout << first << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template<class t, class u> void chmax(t&a,u b){if(a<b)a=b;};
template<class t, class u> void chmin(t&a,u b){if(a>b)a=b;};
int popcount(int t){return __builtin_popcount(t);} //GCC
int popcount(ll t){return __builtin_popcountll(t);} //GCC

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i,MAT.size()){
    REP(j,MAT[i].size()){
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

ll H, N;
vector<pair<double, pair<ll, ll>>> AB_copy;
vector<pair<ll, ll>> AB;
vvll dp;

ll search(ll index, ll H){
  //fprintf(stderr, "%lld %lld\n", index, H);
  if(H<0) return 0;
  if(index>=N) return INFLL;
  if(H==0) return 0;
  if(dp[index][H]<INFLL) return dp[index][H];
  ll A = AB[index].first;
  ll B = AB[index].second;
  ll tmp1 = B+search(index, H-A);
  ll tmp2 = search(index+1, H);
  //fprintf(stderr, "TMP %lld %lld\n", tmp1, tmp2);
  dp[index][H] = tmp1;
  chmin(dp[index][H], tmp2);
  //fprintf(stderr, "%lld %lld %lld\n", index, H, dp[H]);
  return dp[index][H];
}

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  IN(H, N);
  AB.resize(N);
  AB_copy.resize(N);
  dp.resize(N, vll(H+1, INFLL));
  REP(i,N){
    ll A, B;
    IN(A, B);
    AB_copy[i] = make_pair((double)A/(double)B, make_pair(A, B));
  }

  sort(ALL(AB_copy));
  reverse(ALL(AB_copy));
  REP(i,N){
    AB[i] = AB_copy[i].second;
    //fprintf(stderr, "%lld %lld\n", AB[i].first, AB[i].second);
  }

  OUT(search(0, H));

  return 0;
}

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

int main(){

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

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
char s1[105], s2[105];
bool flag = 0;

bool cmp(char x, char y) {
	return x > y;
}

int main() {
	while(~scanf("%s %s", s1, s2)) {
		int l1 = strlen(s1);
		int l2 = strlen(s2);
		sort(s1, s1 + l1);
		sort(s2, s2 + l2, cmp);
		for(int i = 0; ; i++) {
			if(s1[i] < s2[i]) {
				flag = 1;
				break;
			}
			else if(s1[i] > s2[i]) break;
			if(s1[i] == 0 && s2[i] != 0) {
				flag = 1;
				break;
			}
			else if(s2[i] == 0) break;
		}
		if(flag) puts("Yes");
		else puts("No");
	}
	return 0;
}

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

using namespace std;
typedef long long ll;
#define rep(i, n, s) for (int i = s; i < (int)(n); i++)

ll calcNumOfCombination(ll n, ll r) {
    ll num = 1;
    for (ll i = 1; i <= r; i++) {
        num = num * (n - i + 1) / i;
    }
    return num;
}

int main() {
    int n, m;
    cin >> n >> m;
    int a[n];
    int sum = 0;
    rep(i, n, 0) {
        cin >> a[i];
        sum += a[i];
    }

    sort(a, a + n);

    double limit = sum * (1.0 / (4 * m));

    for (int j = n - 1; j >= 0; j--) {
        if (a[j] >= limit) {
            m--;
        }
    }

    if (m <= 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll n, x, s;
  in2(n, x);
  s = 0;
  vector<ll> a(n);
  rep(i, n)
    in(a[i]);
  if(a[0] > x){
    s = a[0] - x;
    a[0] = x;
  }
  rep(i, n - 1){
    if(a[i] + a[i + 1] > x){
      s = s + (a[i] + a[i + 1] - x);
      a[i + 1] = x - a[i];
    }
  }
  out(s);
  memi;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define MAXN 404
#define pii pair<int, int>
#define pb push_back
typedef long long ll;

using namespace std;

ll n, a[MAXN], dp[MAXN][MAXN], pre[MAXN];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    cin >> n;
    for(int i = 0; i < n; i++){
    	cin >> a[i];
    	pre[i] = a[i];
    	if(i > 0) pre[i] += pre[i - 1];
    }
    for(int s = 2; s <= n; s++){
    	for(int i = 0; i <= n - s; i++){
    		dp[i][s] = 1e17;
    		for(int j = 1; j < s; j++){
    			ll t = 0;
    			t += dp[i][j];
    			t += dp[i + j][s - j];
    			t += pre[i + s - 1] - pre[i] + a[i];
    			dp[i][s] = min(dp[i][s], t);
    		}
    	}
    }
    cout << dp[0][n];
}

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

#define ld long double
#define ll long long int
#define ull unsigned long long int
#define vi vector<int>
#define vl vector<ll>
#define vvi vector< vector<int> >
#define vvl vector< vector<ll> >
#define repd(i, a, b) for (int i=(a);i<(b);i++)
#define rep(i, n) repd(i,0,n)
#define ALL(v) v.begin(), v.end()
#define INF 1e9

using namespace std;

/**
 * calculate GCD(greatest common divisor)
 * @param a
 * @param b
 * @return
 */
unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

/**
 * change minimum
 * @tparam T
 * @param a
 * @param b
 * @return bool
 */
template<class T>
inline bool changeMinimum(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

/**
 * change maximum
 * @tparam T
 * @param a
 * @param b
 * @return bool
 */
template<class T>
inline bool changeMaximum(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

/**
 * output answer
 * @tparam T
 * @param answer
 * @return
 */
template<typename T>
T output(T answer) {
    cout << answer << endl;
    return 0;
}

/** ----from here ---------------------------------------------------------- */

int main() {
    string T;



    cin >> T;
    int N =T.size();

//    vector<string> a(N, 0);


    for (int i = 0; i < N; ++i) {
        char c = T[i];
        if(c=='?'){
            T[i] = 'D';
        }
    }

    cout << T << endl;


}

Measured memory_bytes: 3756
#include<stdio.h>
int main()
{
    int n,x=1,a=0;
    int i = 1;
    scanf("%d",&n);

    do{
        x = i;
        if (x % 3 == 0){
            printf(" %d",i);
            a = 1;
        }
        if (a==0){
            do{
                if (x % 10 == 3){
                	printf(" %d",i);
                    break;
                }
                x /= 10;

            } while (x);
        }
        else{
            a = 0;
        }
    } while (++i<=n);
    printf("\n");
    return 0;
}



Measured memory_bytes: 2760
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}


std::vector<int> ud[225816][2],lr[225816][2],ul[410410][2],ur[410410][2],dl[410410][2],dr[410410][2];
std::vector<int>::iterator itr;

int main(void){
	int n,i,j,x,y,ans=INF;
	char u;
	std::cin >> n;
	for(i=0; i<n; ++i){
		std::cin >> x >> y >> u;
		switch(u){
			case 'U':
			ud[x][0].push_back(y);
			ul[x-y+200000][0].push_back(x);
			ur[x+y][0].push_back(y);
			break;
			case 'D':
			ud[x][1].push_back(y);
			dr[x-y+200000][1].push_back(x);
			dl[x+y][1].push_back(y);
			break;
			case 'L':
			lr[y][1].push_back(x);
			ul[x-y+200000][1].push_back(x);
			dl[x+y][0].push_back(y);
			break;
			case 'R':
			lr[y][0].push_back(x);
			dr[x-y+200000][0].push_back(x);
			ur[x+y][1].push_back(y);
			break;
		}
	}
	for(i=0; i<=200000; ++i){
		std::sort(ud[i][1].begin(),ud[i][1].end());
		for(j=0; j<ud[i][0].l_ength(); ++j){
			itr = std::lower_bound(ud[i][1].begin(),ud[i][1].end(),ud[i][0][j]);
			if(itr==ud[i][1].end()){
				continue;
			}
			ans = std::min(ans,(*itr-ud[i][0][j])*5);
		}
		std::sort(lr[i][1].begin(),lr[i][1].end());
		for(j=0; j<lr[i][0].l_ength(); ++j){
			itr = std::lower_bound(lr[i][1].begin(),lr[i][1].end(),lr[i][0][j]);
			if(itr==lr[i][1].end()){
				continue;
			}
			ans = std::min(ans,(*itr-lr[i][0][j])*5);
		}
	}
	for(i=0; i<=400000; ++i){
		std::sort(ul[i][1].begin(),ul[i][1].end());
		for(j=0; j<ul[i][0].l_ength(); ++j){
			itr = std::lower_bound(ul[i][1].begin(),ul[i][1].end(),ul[i][0][j]);
			if(itr==ul[i][1].end()){
				continue;
			}
			ans = std::min(ans,(*itr-ul[i][0][j])*10);
		}
		std::sort(ur[i][1].begin(),ur[i][1].end());
		for(j=0; j<ur[i][0].l_ength(); ++j){
			itr = std::lower_bound(ur[i][1].begin(),ur[i][1].end(),ur[i][0][j]);
			if(itr==ur[i][1].end()){
				continue;
			}
			ans = std::min(ans,(*itr-ur[i][0][j])*10);
		}
		std::sort(dl[i][1].begin(),dl[i][1].end());
		for(j=0; j<dl[i][0].l_ength(); ++j){
			itr = std::lower_bound(dl[i][1].begin(),dl[i][1].end(),dl[i][0][j]);
			if(itr==dl[i][1].end()){
				continue;
			}
			ans = std::min(ans,(*itr-dl[i][0][j])*10);
		}
		std::sort(dr[i][1].begin(),dr[i][1].end());
		for(j=0; j<dr[i][0].l_ength(); ++j){
			itr = std::lower_bound(dr[i][1].begin(),dr[i][1].end(),dr[i][0][j]);
			if(itr==dr[i][1].end()){
				continue;
			}
			ans = std::min(ans,(*itr-dr[i][0][j])*10);
		}
	}
	if(ans<INF){
		std::cout << ans << std::endl;
	}else{
		std::cout << "SAFE" << std::endl;
	}
	return 0;
}


Measured memory_bytes: 120312
#include<bits/stdc++.h>
using namespace std;
int n;
int a[200100];
bool b[200100];
bool check(int mid){
	for(int i=1;i<=2*n-1;i++)
		b[i]=(a[i]<=mid);
	for(int i=0;i<n-1;i++){
		if(b[n-i]==1&&b[n-i-1]==1||b[n+i]==1&&b[n+i+1]==1)
			return 1;
		if(b[n-i]==0&&b[n-i-1]==0||b[n+i]==0&&b[n+i+1]==0)
			return 0;
	}
	return b[1];
}
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	for(int i=1;i<=2*n-1;i++)
		cin>>a[i];
	int le=0;
	int ri=2*n-1;
	while(le!=ri){
		int mi=(le+ri)/2;
		if(check(mi))
			ri=mi;
		else
			le=mi+1;
	}
	cout<<le<<endl;
	return 0;
}


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

typedef long long LL;

int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> X(M);

    if (N >= M) {
        cout << 0;
        return 0;
    }
    for (int i = 0; i < M; i++)
    {
        cin >> X[i];
    }

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

    vector<int> dist_X(M - 1);
    for (int i = 0; i < M - 1; i++)
    {
        dist_X[i] = abs(X[i] - X[i + 1]);
    }

    sort(dist_X.begin(), dist_X.end());
    LL out = 0;
    for (int i = 0; i < M - 1 - (N - 1);i++)
        out += dist_X[i];

    cout << out;
    return 0;
}


Measured memory_bytes: 1024
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);

	static void solve() {
		double[] a = new double[4];
		double[] b = new double[4];
		for (int i=0; i<4; i++) {
			a[i] = in.nextDouble();
		}
		for (int i=0; i<4; i++) {
			b[i] = in.nextDouble();
		}

		if (a[0] > b[2] || a[2] < b[0] || a[1] > b[3] || a[3] < b[1]) {
			out.println("NO");
		} else {
			out.println("YES");
		}
	}

	public static void main(String[] args) {
		long start = System.currentTimeMillis();

		while(in.hasNext()) solve();
		out.flush();

		long end = System.currentTimeMillis();
		//trace(end-start + "ms");
		in.close();
		out.close();
	}

	static void trace(Object... o) { System.out.println(Arrays.deepToString(o));}
}

Measured memory_bytes: 29020
// 6/13
// 3-2-3. 反転
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;

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

int H, W;
vector<string> field;

int main() {
    cin >> H >> W;
    field.resize(H);
    rep(h, H) cin >> field[h];

    int res = 0;

    for (int sh = 0; sh < H; sh++) {
        for (int sw = 0; sw < W; sw++) {
            vector<vector<int>> dist(H, vector<int>(W, -1));
            queue<P> que;

            if (field[sh][sw] == '#') continue;

            dist[sh][sw] = 0;
            que.push({sh, sw});

            while (!que.empty()) {
                P p = que.front();
                que.pop();

                rep(i, 4) {
                    int nh = p.first + dx[i];
                    int nw = p.second + dy[i];

                    if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue;

                    if (dist[nh][nw] != -1) continue;
                    if (field[nh][nw] == '#') continue;

                    dist[nh][nw] = dist[p.first][p.second] + 1;
                    que.push({nh, nw});
                }                

                // cout << que.size() << endl;
            }

            // int max_dist = 0;
            rep(h, H) {
                rep(w, W) {
                    // max_dist = max(max_dist, dist[h][w]);
                    res = max(res, dist[h][w]);
                } 
            }

            // cout << res << endl;
        }
    }

    cout << res << endl;
}

Measured memory_bytes: 256