akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

#define loop(i,n)for(i=0;i<n;i++)
#define INF 1000000000
using ll = long long int;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;


#define MAX 100005


int main()
{
    IOS;
    //freopen("inputfile.txt","r",stdin);
  ll n;cin>>n;
  ll ar[n];
  ll count = 0;ll mi;
  for(ll i=0;i<n;i++)
  {
      ll x;cin>>x;
      if(i==0)mi = x;
      else if(x>mi)count++;
      else mi = x;
  }
  cout<<n-count<<endl;
    return 0;
}


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

int main()
{
	int n;
	cin >> n;
	long double ans = 0.0L;
	for(auto i = 0; i < n; ++i){
		long double x;
		string u;
		cin >> x >> u;
		if(u == "JPY") ans += x;
		else ans += (x * 380000);
	}
	cout << fixed << setprecision(8) << ans << endl;
	return 0;
}

Measured memory_bytes: 384
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>

//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else

//#endif

using namespace std;


typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

int dp[2010][2010];
int n,K;
vvint vv;

void dfs(int x,int pre){
	vint v(K+1);
	dp[x][0]=1;
	int h = 0;
	for(int y:vv[x]){
		if(y==pre) continue;
		dfs(y,x);
		rep(i,K+1){
			v[i] += dp[y][i];
		}
		reep(i,1,K+1){
			maxs(dp[x][i],dp[y][i-1]+1);
		}
	}
	rep(j,K){
		int a = min({K-j-2,j,K/2-1});
		for(int y:vv[x]){
			if(y==pre) continue;
			maxs(dp[x][j+1],dp[y][j]+v[a]-dp[y][a]+1);
		}
	}
	// cout<<"ver "<<x+1<<endl;
	reep(i,1,K+1){
		maxs(dp[x][i],dp[x][i-1]);
		// cout<<i<<" "<<dp[x][i]<<endl;
	}
}


void mainmain(){
	cin>>n>>K;
	vv = vvint(n);
	rep(i,n-1){
		int a,b;
		cin>>a>>b;
		a--,b--;
		vv[a].PB(b);
		vv[b].PB(a);
	}
	dfs(0,-1);
	int ans = 0;
	rep(i,n){
		maxs(ans,dp[i][K]);
	}
	cout<<n-ans<<endl;
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    mainmain();
}

Measured memory_bytes: 22624
#include <iostream>
#include <cmath>

using namespace std;

void solve()
{
	int n;
	cin >> n;
	while(n--)
	{
		int h, m;
		char c;
		cin >> h >> c >> m;
		double hour_hand = h * 30.0 + m / 2.0;
		double minute_hand = m * 6.0;
		double min_diff = min(fabs(hour_hand - minute_hand), 360 - fabs(hour_hand - minute_hand));
		if(min_diff < 30)
		{
			cout << "alert" << endl;
		}
		else if(min_diff < 90)
		{
			cout << "warning" << endl;
		}
		else
		{
			cout << "safe" << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1152
public class Main {

  private static void solve() {
    int n = ni();
    int k = ni();
    int[] a = na(n);
    long left = 0;
    long right = (long) 1e10;

    while (right - left > 1) {
      long x = (left + right) / 2;

      long now = 0;
      for (int v : a) {
        now += (v + x - 1) / x - 1;
      }

      if (now <= k) {
        right = x;
      } else {
        left = x;
      }
    }
    System.out.println(right);
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

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

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 56400
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;

// hanbun-zenrekkyo
class Program
{
    static void Main()
    {
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        new Program().solve();
        Console.Out.Flush();
    }
    Scanner cin = new Scanner();

    int N;
    long V;
    void solve()
    {
        N = cin.nextint;
        V = cin.nextlong;

        var A = cin.scanlong;
        var B = cin.scanlong;
        var C = cin.scanlong;
        var D = cin.scanlong;

        var T = new List<long>();
        for (int i = 0; i < N; i++)
        {
            for (int j = 0; j < N; j++)
            {
                var m = A[i] + B[j];
                if (m > V - 2) continue;
                T.Add(m);
            }
        }
        var S = T.ToArray();
        Array.Sort(S);

        long ans = 0;
        for (int i = 0; i < N; i++)
        {
            for (int j = 0; j < N; j++)
            {
                var m = C[i] + D[j];
                if (m > V - 2) continue;
                ans += UpperBound(S, V - m) - LowerBound(S, V - m);
            }
        }

        Console.WriteLine(ans);
    }


    int UpperBound(long[] arr, long val)
    {
        int low = 0, high = arr.Length;
        int mid;

        while (low < high)
        {
            mid = ((high - low) >> 1) + low;
            if (arr[mid] <= val) low = mid + 1;
            else high = mid;
        }
        return low;
    }

    int LowerBound(long[] arr, long val)
    {
        int low = 0, high = arr.Length;
        int mid;

        while (low < high)
        {
            mid = ((high - low) >> 1) + low;
            if (arr[mid] < val) low = mid + 1;
            else high = mid;
        }
        return low;
    }

}


class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return Console.ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 28544
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define REP(i, b, n) for (Int i = b; i < Int(n); i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;
using Int = long long;
Int inf = 1000000000000000001LL;
using vi = vector<Int>;
using vvi = vector<vi>;

Int GCD(Int a, Int b){
    if(b==0) return a;
    if(a < b) return GCD(b, a);
    unsigned r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

int main() {
    Int N,M;
    cin >> N>>M;
    Int ans =0;

    if(N<M){
        vi X = vi(M);
        rep(i,M){
            cin >> X[i];
        }

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

        vi L;
        rep(i,M-1){
            L.push_back(X[i+1]-X[i]);
        }

        sort(L.begin(), L.end(), greater<>());
        Int Ltotal = 0;
        rep(i,N-1){
            Ltotal += L[i];
        }
        ans = (X[M-1]-X[0]) - Ltotal;
    }

    cout << ans;
    return 0;
}

Measured memory_bytes: 2168
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long n,i,k,m,x,y,ans=0;
  cin>>n>>k;
  priority_queue<int>qu;
  for(i=0;i<n;i++)
  {
    cin>>x;
    qu.push(x);
  }
  for(i=0;i<k;i++)
  {
    x=qu.top();
    qu.pop();
    qu.push(x/2);
  }
  for(i=0;i<n;i++)
    {
      ans+=qu.top();
      qu.pop();
    }
    cout<<ans<<endl;
}

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

// グローバル変数
ll n, m, x;
vector<ll> a;

// 関数プロトタイプ
void input();
void solve();

int main(void)
{
    input();
    solve();  
}

// 標準入力
void input() {
    cin >> n >> m >> x;
    a.resize(m);
    for (int i = 0; i < m;i++) {
        cin >> a[i];
    }
}

void solve() {
    int bef = 0;
    int aft = 0;
    for (int i = 0; i < m;i++) {
        if(a[i]<x) {
            bef++;
        }
        if(a[i]>x) {
            aft++;
        }
    }
    cout << min(bef, aft) << endl;
}

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

int32_t main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);

	int n, ans = 0; cin >> n;
	vector<int> a(n);

	for (auto &i: a) cin >> i;

	int dp[n + 1][n + 1] = {-1};

	for (int i = n; i >= 0; --i)
		for (int j = i + 1; j <= n; ++j) {
			int temp = 1e15;
			for (int k = i; k <= j; ++k)
				dp[i][j] += a[k - 1];
			for (int k = i; k < j; ++k)
				temp = min(temp, dp[i][k] + dp[k + 1][j]);
			dp[i][j] += temp;
		}

	cout << dp[1][n] << "\n";
	
	return 0;
}

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

int main() {
    int a, b;
    char op;
    while (1){
        cin >> a >> op >> b;
        if (op == '?') break;
        
        if (op == '+') {
            printf("%d\n", a + b);
        }else if (op == '-'){
            printf("%d\n", a - b);
        }else if (op == '*'){
            printf("%d\n", a * b);
        }else if (op == '/'){
            printf("%d\n", a / b);
        }
    }
    return 0;
    
}

Measured memory_bytes: 3224
#include <iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;

int main()
{
    char a[100],b[100],c[100];
    int n,m;
    scanf("%s %s",a,b);
    cin>>n>>m;
    scanf("%s",c);
    if(strcmp(a,c)==0)
        cout<<n-1<<" "<<m;
    else
        cout<<n<<" "<<m-1;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define PB push_back
#define POP pop_back()
#define PII pair<int,int>
#define FI first
#define SE second
#define ULL unsigned long long
using namespace std;
const int INF=0x3f3f3f3f;
const double pi=acos(-1),eps=1e-8;
const int maxn=1<<17;
const int N=1e6+10,M=4e7+10;
int n,m;
char a[N];
int main()
{
    cin>>a+1;
    n=strlen(a+1);
    for(int i=1;i<=n;i+=2){
        if(a[i]!='h'||a[i+1]!='i'){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes";
    return 0;
}
/*
*/


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }


using namespace std;

int main(){
    int N, M;
    cin >> N >> M;
    ll A[2][N], B[2][N], C[2][N];
    rep(i, N) {
        ll a, b, c;
        cin >> A[0][i] >> B[0][i] >> C[0][i];
        A[1][i] = -A[0][i];
        B[1][i] = -B[0][i];
        C[1][i] = -C[0][i];
    }

    ll Z[N];
    ll ans = 0;
    rep(i, 2) {
        rep(j, 2) {
            rep(k, 2) {
               rep(l, N) {
                   Z[l] = A[i][l] + B[j][l] + C[k][l];
               }
               sort(Z, Z+N);
               reverse(Z, Z+N);
               ll tmp = 0;
               rep(i, M) {
                    tmp += Z[i];
               }
               chmax(ans, tmp);
            }
        }

    }
    cout << ans << endl;

}

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

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	long long int n, a, b; cin >> n >> a >> b;
	cout << (n / (a + b))*a + min(a, n % (a + b)) << endl;
	return 0;

}


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

int main() {
    int n;
    cin >> n;
    vector<int> R(n);
    for(int i=0; i<n; i++) cin >> R[i];

    int minr = min(R[0], R[1]);
    int ans = R[1] - R[0];
    for(int i=2; i<n; i++) {
        ans = max(ans, R[i] - minr);
        minr = min(minr, R[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3552
#include<iostream>
#include<cstdio>
#include<vector>
#include<cstring>
using namespace std;

int n,m;

int main(void){
	while(1){
		cin >> n >> m;
		if(n==0 && m==0)break;
		vector<int> v(20);
		vector<int> a(20),c(20),p(20);
		for(int i=0;i<3;i++){
			int k;
			cin >> k;
			for(int j=0;j<k;j++){
				int num;
				cin >> num;
				v[num]=i;
			}
		}
		p[n]=2;
		a[n]=v[n];
		c[n]=2-v[n];
		for(int i=n;i>1;i--){
			p[i-1]=3*p[i]+2;
			if(v[i-1]==0){
				a[i-1]=a[i];
				c[i-1]=c[i]+2*p[i]+2;
			}
			if(v[i-1]==1){
				a[i-1]=c[i]+p[i]+1;
				c[i-1]=a[i]+p[i]+1;
			}
			if(v[i-1]==2){
				a[i-1]=a[i]+2*p[i]+2;
				c[i-1]=c[i];
			}
		}
		int res=min(a[1],c[1]);
		if(m<res)cout << "-1" << endl;
		else cout << res << endl;
	}
    return 0;
}

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

int main() {
    int H, W;
    cin >> H >> W;
    
    vector<string> mat(H);
    for (int i = 0; i < H; i++){
        string v = "";
        cin >> v;
        mat.at(i) = v;
    }
    
    vector<string> ans(H+2);
    string sharps = "";
    
    for (int j = 0; j < W+2; j++){
        sharps += '#';
    }
    
    ans.at(0) = sharps;
    ans.at(H+1) = sharps;
    
    for (int i = 1; i < H+1; i++){
        string v = "#";
        v += mat.at(i-1);
        v += '#';
        ans.at(i) = v;
    }
    
    for (int i =0; i < H+2; i++){
        cout << ans.at(i) << endl;
    }
}


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

#define ll long long

int main(){

    int X;
    int i,j,k,l;
    int count=0,count_n=0,count_m=0;
    bool flag = false;
    int ans=0;

    cin >> X;    

    int val;
    int max = 0;

    if(X <= 3){
        cout << "1" << endl;
        return 0;
    }

    for(i=X;i>=2;i--){
        val = i;
        for(j=2;j<i;j++){
            while(val % j == 0){
                val /= j;
                if(val == 1){
                    if(max < i)max = i;
                }
            }
            val = i;
        }
    }

    cout << max << endl;

}

Measured memory_bytes: 764
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1000000007
typedef long long ll;
const int INF32 = 2147483647;
const ll INF64  = 9223372036854775807;
using namespace std;

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

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

    int N, W;
    cin >> N >> W;
    vector<int> w(N), v(W);
    REP(i, N) cin >> w[i] >> v[i];

    ll dp[N + 1][W + 1] = {};
    REP(i, N) {
        REP(sum, W + 1) {
            if (sum - w[i] >= 0) {
                chmax(dp[i + 1][sum], dp[i][sum - w[i]] + v[i]);
            }
            chmax(dp[i + 1][sum], dp[i][sum]);
        }
    }

    cout << dp[N][W] << endl;
    return 0;
}

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

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

#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const double PI = 3.1415926535;
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;

int main(){
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector<ll>p(a), q(b), res, r;
    rep(i, 0, a)cin >> p[i];
    rep(i, 0, b)cin >> q[i];
    rep(i, 0, c){
        ll r2;
        cin >> r2;
        r.push_back(r2);
    }
    sort(p.begin(),p.end(),greater<ll>());
    sort(q.begin(),q.end(),greater<ll>());
    sort(r.begin(),r.end(),greater<ll>());
    ll ans = 0;
    rep(i, 0, x)res.push_back(p[i]);
    rep(i, 0, y)res.push_back(q[i]);
    rep(i, 0, c)res.push_back(r[i]);
    sort(res.begin(),res.end(),greater<ll>());
    rep(i, 0, x+y)ans += res[i];
    cout << ans << endl;
}

Measured memory_bytes: 9716
using System;

namespace ConsoleApp2
{
    public class Program
    {
        static void Main(string[] args)
        {
            int s, w;

            var buf = Console.ReadLine().Split(' ');
            s = int.Parse(buf[0]);
            w = int.Parse(buf[1]);

            if (s <= w)
            {
                Console.WriteLine("unsafe");
            }
            else
            {
                Console.WriteLine("safe");
            }
        }
    }
}


Measured memory_bytes: 17864
using System;

class Program
{
    static void Main(string[] args)
    {
        string s = Console.ReadLine();
        int cnt = 0;
        int cnt_max = 0;
        for (int i = 0; i < s.Length; i++)
        {
            if (s[i] == 'T') { cnt++; }
            else { cnt--; }
            cnt_max = Math.Max(cnt, cnt_max);
        }

        Console.WriteLine(cnt_max * 2);
    }
}


Measured memory_bytes: 3544
// Problem : D - I hate Factorization
// Contest : AtCoder - AtCoder Beginner Contest 166
// URL : https://atcoder.jp/contests/abc166/tasks/abc166_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define db long double
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define mi map<int,int>
#define ml map<ll,ll>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define MAX 4294967295
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define MAXN 15000005
#define inf 1e10
#define PI acos(-1.0)
#define int long long

int x;
int m[2001];

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    cin>>x;
    m[1000] = 0;
    for(int i=1;i<=1000;i++){
        int t = pow(i,5);
        m[i+1000] = t;
        m[1000-i] = -t; 
    }
    for(int i=0;i<=2000;i++){
        for(int j=0;j<=2000;j++){
            if(m[i]-m[j] == x){
                cout<<i-1000<<" "<<j-1000<<endl;
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 4056
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}

void main()
{
  int a, b, c, d, e, f; readV(a, b, c, d, e, f);

  auto nu = 0, de = a*100;
  foreach (o1; 0..f/100/a+1)
    foreach (o2; 0..(f/100-o1*a)/b+1) {
      auto w = (o1*a+o2*b)*100, s = min(f-w, w/100*e);
      foreach (o3; 0..s/c+1) {
        auto o4 = (s-o3*c)/d;
        auto t = o3*c+o4*d;

        if (nu*(w+t) < de*t) {
          nu = t;
          de = w+t;
        }
      }
    }

  writeln(de, " ", nu);
}


Measured memory_bytes: 256
from collections import defaultdict
d = defaultdict(int)
n, m = map(int, input().split())
ac = set()
for i in range(m):
  p, s = map(str, input().split())
  if s == 'AC':
    ac.add(p)
  elif s == 'WA' and p not in ac:
    d[p] += 1
for e in d.keys():
  if e not in ac:
    d[e] = 0
pn = d.values()
print(len(list(ac)), sum(pn))

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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
#define MP make_pair
ll MOD = 1e9+7;
//ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }
void answer1(bool x){
  if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void answer2(bool x){
  if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void answer3(bool x){
  if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void answer(bool x, ll y, ll z){
  if(x) cout<<y<<endl;else cout<<z<<endl;}   


int main(){
  ll i, j;
  //ll n;
  //cin >> n;
  ll a, b, c;
  cin >> a >> b;
  //string s; cin >> s;
  ll result = 0;
  bool judge = true;
  answer(b>=a,a,a-1);

  /*
  vector<ll> a(n);
  for(i=0;i<n;i++)
    cin >> a[i];
  //for(i=0;<n;i++)
  */





  return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var K, X int
	fmt.Scanf("%d", &K)
	fmt.Scanf("%d", &X)

	min :=  X-(K-1)
	if min < -1000000 {
		min = -1000000
	}

	max := X+(K-1)
	if max > 1000000 {
		max = 1000000
	}

	for i := min; i <= max; i++ {
		fmt.Println(i)
	}
}


Measured memory_bytes: 512
x,y,a,b,c=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
p2=p[:x]
q2=q[:y]
num=p2+q2
num.sort()
ans=sum(num)
cnt=ans
for i in range(min(x+y,c)):
    cnt+=r[i]-num[i]
    ans=max(ans,cnt)
print(ans)


Measured memory_bytes: 29144
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define Clear(a) a = decltype(a)()
#define all(a) a.begin(),a.end()
#define vec vector
typedef long long ll;
typedef pair<ll,ll> P;
//const ll big=998244353;
const ll big=1000000007LL;
const ll INF=1e18;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
if(x<y)return x;
else return y;
}
ll expm(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (expm(x,y-1)*x)%big;
    ll t=expm(x,y/2);
    return (t*t)%big;
}
ll exp(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||y==0)return x;
    if(y%2==1)return exp(x,y-1)*x;
    ll t=exp(x,y/2);
    return t*t;
}
ll inv(ll x){
    return expm(x,big-2);
}


int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    /*--------------------------------*/

    int n;cin >> n;
    vec<ll> a(n);
    rep(i,n)cin >> a[i];
    ll M=0;
    ll ans=0;
    rep(i,n){
        if(M>a[i]){
            ans+=M-a[i];
        }else M=a[i];

    }
    cout << ans << endl;
}

Measured memory_bytes: 4780
using System;
using System.Linq;

class D
{
	static int[] Read() => Console.ReadLine().Split().Select(int.Parse).ToArray();
	static void Main()
	{
		var h = Read();
		int n = h[0], x = h[1];
		var s = Read().OrderBy(v => -v).ToArray();

		var dp = new MInt[n + 1, x + 1];
		dp[0, x] = 1;

		for (int i = 1; i <= n; i++)
			for (int j = 0; j <= x; j++)
			{
				var c = dp[i - 1, j];
				if (c.V == 0) continue;

				dp[i, j % s[i - 1]] += c;
				dp[i, j] += c * (n - i);
			}
		Console.WriteLine(Enumerable.Range(0, x + 1).Aggregate((MInt)0, (v, j) => v + j * dp[n, j]));
	}
}

struct MInt
{
	const int M = 1000000007;
	public long V;
	public MInt(long v) { V = (v %= M) < 0 ? v + M : v; }
	public override string ToString() => $"{V}";

	public static implicit operator MInt(long v) => new MInt(v);
	public static MInt operator +(MInt x, MInt y) => x.V + y.V;
	public static MInt operator *(MInt x, MInt y) => x.V * y.V;
}


Measured memory_bytes: 75836
H, W = gets.split.map(&:to_i)
cost = []
10.times do |i|
    cost[i] = gets.split.map(&:to_i)
end
as = []
H.times do |i|
    as.concat(gets.split.map(&:to_i))
end

10.times do |k|
    10.times do |i|
        10.times do |j|
            ck = cost[i][k] + cost[k][j]
            cost[i][j] = ck if cost[i][j] > ck
        end
    end
end

sum = 0
as.each do |a|
    next if a == -1
    sum += cost[a][1]
end

print sum

Measured memory_bytes: 2684
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

vector<vector<int>> g;
vector<int> dp;
void dfs(int u, int p) {
    if (~dp[u]) return ;
    dp[u] = 0;
    for (int v: g[u]) if (v != p) {
        dfs(v, u);
        chmax(dp[u], dp[v] + 1);
    }
}

int main() {
    int n, m; cin >> n >> m;
    g.resize(n);
    while (m--) {
        int x, y; cin >> x >> y; x--, y--;
        g[x].emplace_back(y);
    }
    dp.assign(n, -1);
    for (int i = 0; i < n; i++) dfs(i, -1);
    cout << *max_element(dp.begin(), dp.end()) << endl;
    return 0;
}

Measured memory_bytes: 8832
#include <stdio.h>
#include <string.h>
#include <algorithm>
#define rep(i,st,ed) for (int i=st;i<=ed;++i)
#define fill(x,t) memset(x,t,sizeof(x))

const int INF=0x3f3f3f3f;
const int N=200005;

int a[N],rec[N];

int main(void) {
	int n; scanf("%d",&n);
	rep(i,1,n) scanf("%d",&a[i]);
	int mx1=0,mx2=0,r1,r2;
	for (int i=1;i<=n;i+=2) rec[a[i]]++;
	for (int i=1;i<=n;i+=2) {
		if (rec[a[i]]>rec[mx1]||rec[a[i]]==rec[mx1]&&a[i]!=mx1) mx2=mx1,mx1=a[i];
		else if (rec[a[i]]>rec[mx2]&&a[i]!=mx1) mx2=a[i];
	}
	r1=rec[mx1],r2=rec[mx2];
	int mx3=0,mx4=0,r3,r4;
	fill(rec,0);
	for (int i=2;i<=n;i+=2) rec[a[i]]++;
	for (int i=2;i<=n;i+=2) {
		if (rec[a[i]]>rec[mx3]||rec[a[i]]==rec[mx3]&&a[i]!=mx3) mx4=mx3,mx3=a[i];
		else if (rec[a[i]]>rec[mx4]&&a[i]!=mx3) mx4=a[i];
	}
	r3=rec[mx3],r4=rec[mx4];
	int ans=INF;
	if (mx1!=mx3) ans=std:: min(ans,n-r1-r3);
	if (mx1!=mx4) ans=std:: min(ans,n-r1-r4);
	if (mx2!=mx3) ans=std:: min(ans,n-r2-r3);
	if (mx2!=mx4) ans=std:: min(ans,n-r2-r4);
	if (ans==INF) ans=n/2;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1280
#include <stdio.h>

int main(void)
{
	int w1=0,h1=0,w2,h2,n,x,y,a,i,s;
	scanf("%d%d%d",&w2,&h2,&n);
	for(i=0;i<n;i++){
		scanf("%d%d%d",&x,&y,&a);
		if(a==1&&x>w1)w1=x;
		if(a==2&&w2>x)w2=x;
		if(a==3&&y>h1)h1=y;
		if(a==4&&h2>y)h2=y;
	}
	printf("%d",(w2-w1)*(h2-h1)>0&&w2-w1>0&&h2-h1>0?(w2-w1)*(h2-h1):0);
	return 0;
}

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

#define rep(i,j,n) for(int i=j;i<n;++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(), i.rend()
#define INF 1e9
#define LINF 1e18
const int mod = 1e9 + 7;

typedef long long i64;
typedef pair<int, int> pi;

template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;

i64 gcd(i64 n, i64 m) {return (m == 0? n : gcd(m, n % m));}
i64 lcd(i64 n, i64 m) {return (n / gcd(n, m) * m);}
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

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

	int h, w, n;
	cin >> h >> w >> n;

	cout << (n / max(h, w)) + !!(n % max(h, w)) << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)


{


 int length = 0;


 int height = 0;


 int area = 0;


 int cir = 0;





 scanf("%d %d",&length,&height);


 area = length*height;


 cir = length*2 + height*2;





 printf("%d %d\n",area,cir);
 




return 0;


}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
int main(){
  string str;
  cin >> str;
  bool n=false,w=false,s=false,e=false;
  for(int i=0;i<str.size();i++){
    if(str[i]=='N') n=true;
    if(str[i]=='W') w=true;
    if(str[i]=='S') s=true;
    if(str[i]=='E') e=true;
  }
  if((n^s)||(w^e)) cout << "No" << endl;
  else cout << "Yes" << endl;
  return 0;
}


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

using namespace std;

typedef long long ll;

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

  while(true){
      ll n,q;cin>>n>>q;
      if(n==0&&q==0) break;
      std::vector<string> ename;
      std::vector<ll> eyear,wyear;
      for(int i=0;i<n;i++){
          string s;ll a,b;
          cin>>s>>a>>b;
          ename.push_back(s);
          eyear.push_back(a);
          wyear.push_back(b);
      }
      for(int i=0;i<q;i++){
          ll y;cin>>y;
          bool flag=false;
          for(int j=0;j<n;j++){
              int st=wyear[j]-eyear[j]+1;
              if(st<=y&&y<=wyear[j]){
                  cout<<ename[j]<<" "<<y-st+1<<endl;
                  flag=true;
                  break;
              }
          }
          if(!flag) cout<<"Unknown"<<endl;
      }
  }
  return 0;
}

Measured memory_bytes: 3272
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::Read;
#[allow(dead_code)]
fn getline() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok().unwrap();
    ret
}
fn get_word() -> String {
    let mut stdin = std::io::stdin();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}

#[allow(dead_code)]
fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }

const MOD: i64 = 1_000_000_007;

fn solve() {
    let n: usize = get();
    let ni = n as i64;
    let mut dp = vec![0; n + 1];
    let mut acc = vec![0; n + 1];
    dp[0] = 1;
    dp[1] = ni;
    acc[0] = 1;
    acc[1] = 1 + ni;
    for i in 2 .. n + 1 {
        let mut tot = (ni - 1) * (ni - 1) % MOD;
        tot += dp[i - 1];
        if i >= 3 {
            tot = (tot + acc[i - 3]) % MOD;
        }
        tot += (n + 1 - i) as i64;
        dp[i] = tot % MOD;
        acc[i] = (acc[i - 1] + tot) % MOD;
    }
    println!("{}", dp[n]);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 24956
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define l long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define M1 1000000007
#define M2 998244353

#define fl(i,a,b)  for(ll i=a;i<b;i++)
#define bfl(i,a,b) for(ll i=b-1;i>=a;i--)
#define f(i,n)     for(int i=0;i<n;i++)
#define bf(i,n)    for(int i=n-1;i>=0;i--)


#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl

#define bn "\n"

//------------------------------------------------------------------------ 
// #define V(a) vector<a>
// #define vt() vector< tuple < int ,int ,int > > ;
// #define vector< int ,int > pv;
// vector< pair <int,int> > vect;


//------------------------------------------------------------------------

ll modI(ll a,ll m);
ll gcd(ll a,ll b);
ll powM(ll x,ll y,ll m);
ll swap(ll a,ll b);

void swap(ll& a,ll& b)
{
    ll tp=a;
    a=b;
    b=tp;
}

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

ll powM(ll x,ll y,ll m)
{
    ll ans=1,r=1;
    x%=m;
    while(r>0&&r<=y)
    {
        if(r&y)
        {
            ans*=x;
            ans%=m;
        }
        r<<=1;
        x*=x;
        x%=m;
    }
    return ans;
}
 
ll modI(ll a, ll m)
{
    ll m0=m,y=0,x=1;
    if(m==1) return 0;
    while(a>1)
    {
        ll q=a/m;
        ll t=m;
        m=a%m;
        a=t;
        t=y;
        y=x-q*y;
        x=t;
    }
    if(x<0) x+=m0;
    return x;
}

//---------------------------------------------------------------------------

// variable = Expression1 ? Expression2 : Expression3
// max = (n1 > n2) ? n1 : n2; 
// (n>m) ? cout<<"True"<<endl:cout<<"false"<<endl ;

// ---------------------------------------------------------------------------	

// int n;cin>>n;int a[n];for(int i=0;i<n;i++)cin>>a[i];    
// for(int i=0;i<n;i++)cout<<a[i];
// int a,b;cin>>a>>b;   

//----------------------------------------------------------------------------

// vector< tuple < int ,int ,int > > tv;
// vector< int ,int > pv;


//----------------------------------------------------------------------------


int main() {
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
	int tt=1;
   // cin>>tt;
	while(tt--)
	{
	   int x,y;
	   cin>>x>>y;
	   fl(i,0,x+1)
	   {
	      if(i*2 + (x-i)*4 == y)
	      {
	          cout<<"Yes"<<bn;return 0;
	      }
	   }
	   cout<<"No"<<bn;
	   
	    
	}
	
	return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	int k;
	cin>>k;
	ll sum=0;
	for(int i=1; i<=k; i++)
	{
		for(int j=1; j<=k; j++)
		{
			for(int x=1; x<=k; x++)
			{
				int num1=__gcd(i,j);
				num1=__gcd(num1,x);
				sum+=num1;
			}
		}
	}
	cout<<sum;
	return 0;	
}

Measured memory_bytes: 3612
import sys

# sys.stdin = open('c1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def pgcd(a, b):
    while a % b != 0:
        a, b = b, a % b
    return b


def ppcm(a, b):
    return (a * b) // pgcd(a, b)


def main():
    n = read_int()
    t = [read_int() for i in range(n)]
    res = 1
    for i in t:
        res = ppcm(res, i)
    print(res)


main()


Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<numeric>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<bitset>
#include<random>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 1LL << 61;
const ll mod = 1000000007LL;
//const ll mod = 998244353LL;

ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok;
ll dx[9] = { 0,1,0,-1,0,1,1,-1,-1 }, dy[9] = { 0,0,1,0,-1,1,-1,1,-1 };
#define endl '\n'
#pragma endregion
#define MAX 222222






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



  cin >> n;
  cout << 180 * (n - 2) << endl;







  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int cf[100010],n,m,l,r,a[100010],ans;
int main() {
	scanf("%d %d",&n,&m);
	for(int i=1;i<=m;i++) {
		scanf("%d %d",&l,&r);
		cf[r+1]--;
		cf[l]++;
	}
	a[0]=cf[0];
	for(int i=1;i<=n;i++) {
		a[i]=a[i-1]+cf[i];
		if(a[i]==m)
		    ans++;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 1024
//
//  ROIGold.cpp
//  Main calisma
//
//  Created by Rakhman on 05/02/2019.
//  Copyright © 2019 Rakhman. All rights reserved.
//

#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <iterator>

#define ios ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0);
#define S second
#define F first
#define pb push_back
#define nl '\n'
#define NL cout << '\n';
#define EX exit(0)
#define all(s) s.begin(), s.end()
#define FOR(i, start, finish, k) for(int i = start; i <= finish; i += k)

const int MXN = 1e6 + 200;
const long long MNN = 4e2 + 200;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
const int OO = 1e9 + 500;

typedef long long llong;
typedef unsigned long long ullong;

using namespace std;

int n;
llong a[MXN], pr[MXN], dp[MNN][MNN];

llong get(llong l, llong r){
    if(dp[l][r] != -1) return dp[l][r];
    if(r - l == 1) return dp[l][r] = a[l] + a[r];
    if(r - l == 0) return dp[l][r] = 0;
    llong mn = INF;
    for(int i = l; i < r; i++){
        mn = min(get(l, i) + get(i + 1, r), mn);
    }
    return dp[l][r] = (mn + pr[r] - pr[l - 1]);
}

int main () {
    ios;
    memset(dp, -1, sizeof(dp));
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        pr[i] = pr[i - 1] + a[i];
    }
    cout << get(1, n);
}


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

#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = 1; i <= n; i++)
#define drep(i, n) for(int i = n-1; i >= 0; i--)
#define srep(i, s, t) for (int i = s; i < t; i++)
#define vi vector<int>
#define P pair<ll, ll>
using namespace std;
int mod = 1'000'000'000 + 7;
struct edge {
    int to;
    ll cost;
};

void COME_LET_THE_GAMES_BEGIN() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(20);
}

namespace prime {
    vector<bool> is_not_prime{1, 1, 0};

    void make_is_not_prime(int N) {
        int l = is_not_prime.size();
        if (l >= N + 1) {
            return;
        }
        is_not_prime.resize(N + 1);
        for (int i = 2; i <= N; i++) {
            if (!is_not_prime[i]) {
                for (int j = max(((l + i - 1) / i) * i, i + i); j <= N; j += i) {
                    is_not_prime[j] = 1;
                }
            }
        }
    }

    vector<ll> list(ll a, ll b) {
        //{a, b)
        a = max(2LL, a);
        set<ll> st;
        for (ll i = a; i < b; i++) {
            st.insert(i);
        }
        ll l = sqrt(b);
        make_is_not_prime(l);
        for (ll i = 2; i <= l; i++) {
            if (!is_not_prime[i]) {
                for (ll j = max(((a + i - 1) / i) * i, i + i); j < b; j += i) {
                    st.erase(j);
                }
            }
        }
        vector<ll> res;
        for (auto x:st) {
            res.push_back(x);
        }
        return res;
    }

    bool is_prime(ll N) {
        if (N == 2) return true;
        for (int i = 2, j = sqrt(N) + 1; i <= j; i++) {
            if (N % i == 0)return false;
        }
        return N >= 2;
    }

    vector<pair<ll, ll>> integer_factorization(ll N) {
        vector<pair<ll, ll>> res;
        auto s = list(0, N + 1);
        for (ll p:s) {
            if (N < p) {
                break;
            }
            ll r = 0;
            for (int i = 0;; i++) {
                if (N % p == 0) {
                    N /= p;
                    r++;
                } else {
                    break;
                }
            }
            if (r) {
                res.push_back(make_pair(p, r));
            }
        }
        return res;
    }
}

int main() {
    COME_LET_THE_GAMES_BEGIN();
    ll N;
    cin >> N;
    ll s[1000] = {};
    rrep(i, N) {
        for (auto x:prime::integer_factorization(i)) {
            s[x.first] += x.second;
        }
    }
    ll ans = 1;
    for (int i = 0; i < 1000; i++) {
        ans *= s[i] + 1;
        ans %= mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
int main(void){
int N,i,sum=0;
scanf("%d",&N);
char S1[N][101],S2[101];
int A1[N];
for (i=0;i<N;i++){
scanf("%s" "%d",S1[i], &A1[i]);
sum=sum+A1[i];
}
scanf("%s", S2);
for (i=0;i<N;i++){
	sum=sum-A1[i];
	if(strcmp(S1[i],S2)==0){
		break;
	}
}
printf("%d",sum);
}

Measured memory_bytes: 128
import java.util.*;
public class Main 
{
	public static void main(String[] args) 
	{
		Scanner stdIn = new Scanner(System.in);
		while(stdIn.hasNext())
		{
			int b = stdIn.nextInt();
			if(b == 1)
			{
				break;
			}
			boolean flag[] = new boolean[300001];
			int i = 1;
			System.out.print(b + ":");
			while(true)
			{
				int x = 7 * i - 1;
				if(x > b)
				{
					break;
				}
				if(!flag[x] && b % x == 0)
				{
					System.out.print(" " + x);
					for(int j = x; j <= b; j += x)
					{
						flag[j] = true;
					}
				}
				int y = 7 * i + 1;
				if(y > b)
				{
					break;
				}
				if(!flag[y] && b % y == 0)
				{
					System.out.print(" " + y);
					for(int j = y; j <= b; j += y)
					{
						flag[j] = true;
					}
				}
				++i;
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 12000
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] cnt = new int[10000+1];
        for (int x = 1; x <= 100; x++) {
            for (int y = 1; y <= 100; y++) {
                for (int z = 1; z <= 100; z++) {
                    int f = x*x+y*y+z*z+x*y+y*z+z*x;
                    if (f <= 10000) cnt[f]++;
                }
            }
        }
        StringBuilder ans = new StringBuilder();
        for (int i = 1; i <= N; i++) {
            ans.append(cnt[i]).append('\n');
        }
        System.out.print(ans);
    }
}


Measured memory_bytes: 36040
#include <iostream>
#include <algorithm>
#include <climits>
#include <fstream>
using namespace std;

constexpr int MAX_N = 1 << 17;
int n, dat[2 * MAX_N -1];

//セグ木をINT_MAXで初期化
//簡単のため、要素数を2^n >= n_となるようにしている
int init(int n_){
  n = 1;
  while(n < n_){
    n *= 2;
  }
  for(int i=0; i< 2*n - 1; i++) dat[i] = INT_MAX;

  return n;
}

//k番目(0-indexed)をaに更新
void update(int k, int a){
  k += n-1;
  dat[k] = a;
  while(k > 0){
    k = (k-1) / 2;
    dat[k] = min(dat[2*k + 1], dat[2*k + 2]);
  }
}

int query(int a, int b, int k, int l, int r){
  if(r <= a || b <= l) return INT_MAX;

  if(a <= l && r<= b) return dat[k];
  else{
    int v1 = query(a, b, k*2 + 1, l, (l+r) / 2);
    int v2 = query(a, b, k*2 + 2, (l+r) / 2, r);
    return min(v1, v2);
  }
}

int main(){
  //ifstream fin("in.txt");
  int n, q; cin >> n >> q;

  n = init(n);

  for(int i=0; i<q; i++){
    int op, x, y; cin >> op >> x >> y;

    if(op == 0){
      update(x, y);
    }
    else if(op == 1){
      cout << query(x, y+1, 0, 0, n) << endl;
    }
  }
  
  return 0;
}



Measured memory_bytes: 4104