akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextInt();
		long b = sc.nextInt();

		final String POSITIVE = "Positive";
		final String NEGATIVE = "Negative";
		final String ZERO = "Zero";
		String ans = null;
		if (a > 0) {
			ans = POSITIVE;
		} else if (b >= 0) {
			ans = ZERO;
		} else if ( (b - a) % 2 == 0 ) {
			ans = NEGATIVE;
		} else {
			ans = POSITIVE;
		}
		System.out.println(ans);
	}
}


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

int N, D;
int X[11][11];

int main () {
  cin >> N >> D;
  rep(i,N)rep(j,D) cin >> X[i][j];

  int ans = 0;
  rep(i,N) {
    for(int j = i+1; j < N; j++) {
      int d2 = 0;
      rep(d,D) d2 += (X[i][d] - X[j][d]) * (X[i][d] - X[j][d]);
      int d = sqrt(d2);
      ans += (d*d == d2);
    }
  }

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


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

int main() {
	int a,b;
	cin>>a>>b;
	if(b == 1){
		cout<<0;
		return 0;
	}
	int ans = 1;
	b -= a;
	while(b>0){
		b -= a-1;
		ans++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,n,m) for(int i=n;i<=(int)(m);i++)
#define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
vector<int> dy={1,0,-1,0};
vector<int> dx={0,1,0,-1};
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

struct UnionFind {
    vector<int> data;
    UnionFind(int size): data(size,-1) {
    }
    
    int root(int x){
        return (data[x] < 0)? x : data[x]=root( data[x] );
    }
    
    bool unite(int x, int y){
        x=root(x);
        y=root(y);
        if( x != y ){
            if( data[y] < data[x] ) swap(x, y);
            data[x] += data[y];
            data[y] = x;
        }
        return x!=y;
    }
    
    bool find(int x, int y){
        return root(x) == root(y);
    }
    
    int size(int x){
        return -data[ root(x) ];
    }
};

int main(){
    int n,k;
    cin>>n>>k;
    int ans=0;
    rep(i,n) {
        int h;
        cin>>h;
        if(h>=k) ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 384
//やるだけ！ではない。(これがやるだけでお菓子の分割がやるだけでないなら考察をショートカットしすぎ。)
//(自分にとってはどっちも難しい＞＜)
#include<iostream>
#define int long long
using namespace std;

int n;
signed main() {
	while(cin >> n) {
		if (n < 1 || n > 30) break;
		int dp[31][31] = {0}, i, j;	//i=登った回数、j=今までに登った段数
		
		dp[0][0] = 1;
		for(i = 0; i < n; i++ ) {
			for(j = 0; j <= n; j++ ) {
				for(int k = 1; k <= 3; k++ ) {
					if ( j + k > n ) break;
					dp[i+1][j+k] += dp[i][j];
				}
			}
		}
		
		int ans = 0;
		for(i = 0; i < 31; i++ ) {
			ans += dp[i][n];
		}
		cout << (ans+(int)3649)/(int)3650 << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>
#include <math.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
inline double sq(double a) { return a*a; }

int main() {
    int n;
    scanf("%d", &n);
    int pf, pa, pt, px, py;
    double anst[2] = {-1, -1};
    double ansd[2] = {-1, -1};
    rep (i, n) {
        int f, a, t, x, y;
        scanf("%d%d%d%d%d", &f, &a, &t, &x, &y);
        if (i > 0 && t == pt && a != pa) {
            double d = sqrt(sq(x-px)+sq(y-py));
            double k = (f - pf) / 60.0;
            if (d > ansd[t] || (d == ansd[t] && k < anst[t])) {
                anst[t] = k;
                ansd[t] = d;
            }
        }
        pf = f; pa = a; pt = t; px = x; py = y;
    }
    rep (i, 2) printf("%.6f %.6f\n", ansd[i], anst[i]);
    return 0;
}

Measured memory_bytes: 1068
n, x = [int(item) for item in input().split()]
a = []
for i in range(n):
  a.append(int(input()))
a = sorted(a) 

ans = 0
for i in range(n):
  x -= a[i]
  ans += 1
  if x < 0:
    break

while x >= 0:
  x -= a[0]
  ans += 1
  
print(ans - 1)
  

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

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef pair<ll,pll> plpll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vector<int>> mat;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const int INF = 1<<30;
const ll mod = 1000000000 + 7;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

#define addm(X, Y) (X) = ((X) + ((Y) % mod) + mod) % mod

int n;
map<int, int> mp;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    rep(i, n) {
        int a;
        cin >>  a;
        if (mp[a] == 1) mp[a] = 0;
        else mp[a]++;
    }
    int ans = 0;
    for (auto p : mp) {
        if (p.se == 1) ans++;
    }
    cout << ans << endl;
}


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

#define sz(x) int(x.size())
#define pii pair<int, int>
#define Task "abc"
#define For(i, a, b) for(int i = (a), _b = (b); i <= b; ++i)
#define Debug(X) cout << #X << " = " << X << '\n'
#define All(x) (x).begin(), (x).end()
#define mp make_pair

typedef unsigned long long ull;
typedef long long ll;

const int maxn = 1e5 + 10;
const int inf = 0x3f3f3f3f;
const ll mod = 1e9 + 7;

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
//  freopen(Task".inp", "r", stdin);
//  freopen(Task".out", "w", stdout);
  int k; cin >> k;
  queue<ll> q;
  For(i, 1, 9) q.push(i);
  int cnt = 0;
  ll ans = 0;
  while (cnt < k){
    ans = q.front();
    q.pop();
    if (ans % 10 != 0) q.push(ans * 10 + (ans % 10 - 1));
    q.push(ans * 10 + ans % 10);
    if (ans % 10 != 9) q.push(ans * 10 + (ans % 10 + 1));
    ++cnt;
  }
  cout << ans;
}



Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s, t;
  bool x = true;
  cin >> s >> t;
  for(int i = 0; i < s.size(); i++){
    if(s.at(i) != t.at(i)){
      x = false;
      break;
    }
  }
  if(x == true)cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3628
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

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


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 10000


int main(){
  int n;
  int a[SIZE];
  int cc[SIZE] = {};
  int max_a = 0;
  
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d",a+i);
    cc[a[i]]++;
    max_a = max(max_a, a[i]);
  }

  if(cc[1] >= 2){
    if(n==2 && cc[1]==2){
      puts("Possible");
    }else{
      puts("Impossible");
    }

    return 0;
  }

  if(cc[max_a] < 2){
    puts("Impossible");
    return 0;
  }
  
  for(int i=1;i<=max_a/2;i++){
    if(i*2 == max_a){
      if(cc[max_a-i] < 1){
         puts("Impossible");
         return 0;
      }
      cc[max_a-i]--;
    }else{
      if(cc[max_a-i] < 2){
        puts("Impossible");
        return 0;
      }
      cc[max_a-i]-=2;
    }
  }
  
  for(int i=(max_a/2);max_a-i>0;i++){
    if(cc[max_a-i]){
      puts("Impossible");
      return 0;
    }
  }

  puts("Possible");
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int water(vector<int> flower){
    int left = 0;
    int right = 0;
    int len = flower.size();
    int lefts = 0;
    int rights = 0;
    while(right < len){
        if (right == len - 1){
            if (flower[right] == 0){
                if (right - 1 - left >= rights - lefts){
                    rights = right - 1;
                    lefts = left;
                }
                right++;
            }
            else{
                if (right - left >= rights - lefts){
                    rights = right;
                    lefts = left;
                }
                right++;
            }
        }
        else{
            if (flower[right] == 0){
                if (right - 1 - left >= rights - lefts){
                    rights = right - 1;
                    lefts = left;
                }
                right++;
                left = right;
            }
            else{
                right++;
            }
        }
    }
    int count = 0;
    rep(i,len){
        if (flower[i] == 0){
            count++;
        }
    }
    if (count == len){
        return 0;
    }
    vector<int> duplicate(len);
    rep(i,len){
        duplicate[i] = flower[i];
    }
    for (int i = lefts; i <= rights; i++){
        duplicate[i]--;
    }
    return 1 + water(duplicate);
}

int main(){
    int N;
    cin >> N;
    vector<int> vec(N);
    rep(i,N){
        cin >> vec[i];
    }
    cout << water(vec) << endl;
}


Measured memory_bytes: 4864
////////////////////////////////////////////////////////////////////
// This source code is for Visual Studio
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <stack>
#include <functional>
#include <iomanip>
#include <string>
#include <cstring>
#include <deque>
#include <math.h>

#define	numberof(a)	(sizeof(a) / sizeof(a[0]))
#define	INF		UINT64_MAX
#define Rep(i,n) for(int i = 0; i < (n); ++i )

using namespace std;

typedef vector< vector<int> > MAT;
typedef pair<int, int> PINT;
typedef long long ll;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int32_t s32;
typedef int64_t s64;

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int main()
{
	ll N = 0;
	ll cnt = 0;
	string ret = "No";

	cin >> N;

	vector<ll> a(N);
	vector<ll> b(N);
	ll sum_a = 0;
	ll sum_b = 0;

	Rep(i, N) {
		cin >> a[i];
		sum_a += a[i];
	}
	Rep(i, N) {
		cin >> b[i];
		sum_b += b[i];
	}
	
	cnt = sum_b - sum_a;

	if ( cnt < 0 ) {
		ret = "No";
	}
	else {
		ll min_cnt1 = 0;
		ll min_cnt2 = 0;

		Rep(i, N) {
			if ( a[i] > b[i] ) {
				min_cnt1 += (a[i] - b[i]);
			}
			else if (a[i] < b[i]) {
				min_cnt2 += ceil( ((double)b[i] - a[i]) / 2.0);
			}
		}

		ll min_cnt = max(min_cnt1, min_cnt2);
		if (cnt < min_cnt) {
			ret = "No";
		}
		else {
			ret = "Yes";
		}
	}

	cout << ret << endl;

	return 0;
}





Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>

long long max(long long A,long long B){
    return A>B?A:B;
}

long long min(long long A,long long B){
    return A<B?A:B;
}

long long roundup(long long A,long long B){
    return (A+B-1)/B;
}

int main(void){
    long long l,r,ans=1e9;
    scanf("%lld%lld",&l,&r);
    if (r-l>=2019){
        ans=0;
    }
    l=l%2019;
    r=r%2019;
    if (l>=r){
        ans=0;
    }
    for (long long i=l; i<=r; i++){
        for (long long j=i+1; j<=r; j++){
            ans=min(ans,(i*j)%2019);
        }
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

	int N;
	cin >> N;
	vector<int> A(N + 1);
	REP(i, N) { cin >> A[i]; }
	ll res = 0;
	REP(i, N) {
		res += A[i] / 2;
		if (A[i] % 2 && A[i + 1] > 0) {
			++res;
			--A[i + 1];
		}
	}
	cout << res << endl;

	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int MAX_N = 1e5 + 5;
const int MAX_L = 20; // ~ Log N
const long long MOD = 1e9 + 7;
const long long INF = 1e9 + 7;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;

#define LSOne(S) (S & (-S))
#define isBitSet(S, i) ((S >> i) & 1)




int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    
    string str;
    cin>>str;
    int ans=0;
    vector<int> a;
    for(int i=0;i<str.length();i++){
    	if(str[i] =='R'){
    		ans+=1;
		}
		else{
			a.push_back(ans);
			ans=0;
		} 
	}
	if(ans!=0)
	a.push_back(ans);
	sort(a.begin(),a.end());
	int n=a.size();
	cout<<a[n-1]<<endl;
	return 0;
        
}

Measured memory_bytes: 3652
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;
int main(){
  int a[3][3];
  int flag=0;
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cin>>a[i][j];
    }
  }
  int n;
  cin>>n;
  int b[n];
  for(int i=0;i<n;i++){
    cin>>b[i];
  }
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      int k=0;
      while(k<n){
        if(a[i][j]==b[k]){
          a[i][j]=0;
          break;
        }
        k++;
      }
    }
  }
  for(int i=0;i<3;i++){
    if(a[i][0]==a[i][1]&&a[i][0]==a[i][2]&&flag==0){
      cout<<"Yes"<<endl;
      flag=1;
      break;
    }
  }
  for(int i=0;i<3;i++){
    if(a[0][i]==a[1][i]&&a[0][i]==a[2][i]&&flag==0){
      cout<<"Yes"<<endl;
      flag=1;
      break;
    }
  }
  if(a[0][0]==a[1][1]&&a[1][1]==a[2][2]&&flag==0){
    cout<<"Yes"<<endl;
    flag=1;
  }
  if(a[0][2]==a[1][1]&&a[1][1]==a[2][0]&&flag==0){
    cout<<"Yes"<<endl;
    flag=1;
  }
  if(flag==0){
    cout<<"No"<<endl;
  }
}


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

int main () {
  int N, K, ans;
  cin >> N >> K;
  ans = 0;
  
  for (int i = 0; i < N; i++){
    int x, o, k;
    cin >> x;
    o = 2 * x;
    k = (K - x) * 2;
    if (o >= k) {
      ans += k;
    }
    else if (o < k) {
      ans += o;
    }
  }
  cout << ans << endl;
}

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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define ALL(v) (v).begin(), (v).end()
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO  cout << "NO"  << endl
#define No  cout << "No"  << endl

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    int N, L; cin >> N >> L;
    if(L < 0 && -L < N) cout << N*L + (N-1)*N/2 << endl;
    else if(L >= 0)
    {
        int ans = 0;
        for(int i = 1; i < N; i++) ans += L+i;
        cout << ans << endl;
    }
    else
    {
        int ans = 0;
        for(int i = 0; i < N-1; i++) ans += L+i;
        cout << ans << endl;
    }
} 
    
int main() 
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}

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

int main()
{
    int N;
    cin >> N;
    vector<vector<bool>> connect(N, vector<bool>(N, true));
    rep(i, N)connect[i][i] = false;
    N -= N % 2;
    rep(i, N)connect[i][N - 1 - i] = false;

    int cnt = 0;
    for (auto row : connect)for (auto col : row)if (col)cnt++;
    cout << cnt / 2 << endl;

    const int M = connect.size();
    rep(i, M)rep(j, M)if (i < j&&connect[i][j])cout << i + 1 << " " << j + 1 << endl;
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int com =0;
			int n = sc.nextInt();
			int x = sc.nextInt();
			if(n == 0 && x ==0)break;
			for(int i = 1; i <= n; i++) {
				for(int j = 1; j < i; j++) {
					for(int k = 1; k < j; k++) {
						if(i + j +  k == x) {
							com = com + 1;
						}else if(x < i + j + k ) {
							break;
						}

					}
				}
			}
			System.out.println(com);
		}
	}
}



Measured memory_bytes: 26796
#include<bits/stdc++.h>
using namespace std;
vector <int> adj[51];
int vi[51];
void dfs(int u,int x,int y)
{
	vi[u]=1;
	for (int j=0;j<adj[u].size();j++)
	{
		if (!vi[adj[u][j]])
		{
			if (u==x&&adj[u][j]==y)
			continue;
			dfs(adj[u][j],x,y);
		}
	}
}
int main()
{
	int n,m;
	cin>>n>>m;
	int ans=0;
	memset(vi,0,sizeof(vi));
	pair<int,int> a[m+1];
	for (int i=1;i<=m;i++)
	{
		int x,y;
		cin>>x>>y;
		adj[x].push_back(y);
		adj[y].push_back(x);
		a[i].first=x;
		a[i].second=y;
	}
	for (int i=1;i<=m;i++)
	{
		int x=a[i].first;
		int y=a[i].second;
		memset(vi,0,sizeof(vi));
		dfs(x,x,y);
		if (!vi[y])
		ans++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
//code by lynmisakura.wish to be accepted!
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

/***************************/
using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef vector<long long> vl;
typedef pair<ll, ll> pi;
typedef vector<pair<ll, ll> > vpi;

//const long long INF = 1LL << 55;

#define itn ll
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ss second
#define ff first
#define dup(x,y) ((x) + (y) - 1)/(y)
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()
#define Rep(n) for(ll i = 0;i < n;i++)
#define rep(i,n) for(ll i = 0;i < n;i++)
#define flush fflush(stdout)
#define rrep(i,n) for(ll i = n - 1;i >= 0;i--)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define ioboost cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20)
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll qp(ll a, ll b) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
ll qp(ll a, ll b, ll mo) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }

#define _GLIBCXX_DEBUG
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
const int MAX_N = 52;
int a[MAX_N];
long long dp[MAX_N][MAX_N][MAX_N*MAX_N];
int main(void){
    int n,A;cin >> n >> A;
    for (int i = 0; i < n; ++i)
    {
        cin >> a[i];
    }
    dp[0][0][0] = 1;
    for(int i = 0;i < n;i++){
        for(int j = 0;j <= n;j++){
            for(int k = 0;k <= 2500;k++){
                dp[i+1][j][k] += dp[i][j][k];
                if(k+a[i] <= 2500)dp[i+1][j+1][k+a[i]]+=dp[i][j][k];
            }
        }
    }
    long long ans = 0;
    for(int i = 1;i <= n;i++){
        ans += dp[n][i][i*A];
    }
    cout << ans << endl;
}


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

#define pb push_back
#define vi vector < int >
#define ii pair < int, int >
#define vii vector < pair < int, int > >
#define vvi vector < vector < int > >
#define ll long long
#define X first
#define Y second
#define mp make_pair
#define FOR( i, lo, hi ) for( int i = (lo);i < (hi);i++ )
#define DFOR( i, hi, lo ) for( int i = (hi);i >= (lo);i-- )
#define pqueue priority_queue

using namespace std;

const long long int MOD = 1e9 + 7;

ll ADD( ll a, ll b )
{
	return ( ( a % MOD ) + ( b % MOD ) ) % MOD;
}

ll SUB( ll a, ll b )
{
	return ( ( a % MOD ) - ( b % MOD ) + MOD ) % MOD;
}

ll MUL( ll a, ll b )
{
	return ( ( a % MOD ) * ( b % MOD ) ) % MOD;
}

ll POT( ll n, ll k )
{
	if ( k == 0 )
		return 1;

	ll ret = POT( n, k / 2 );
	ret = MUL( ret, ret );

	if ( k % 2 )
		return MUL( ret, n );
	return ret;
}

ll DIV( ll a, ll b )
{
	return MUL( a , POT( b, MOD - 2 ) );
}

bool isPrime( ll x )
{
	for ( ll i = 2;i <= sqrt( x ) + 1; ++i )
		if ( x % i )
			return false;
	return true;
}

string s;

int main()
{
	cin >> s;
	if ( s == "Sunny" )
		cout << "Cloudy\n";
	if ( s == "Cloudy" )
		cout << "Rainy\n";
	if ( s == "Rainy" )
		cout << "Sunny\n";
	return 0;
}


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

int charToInt(char c){
    char zero_num = '0';
    return (int)c - (int)zero_num;
}

signed main(){
    int N, M; cin>>N>>M;
    vec_int A(M), B(M);
    rep(i,M) cin>>A.at(i)>>B.at(i);

    dsu d(N);

    rep(i,M){
        d.merge(A.at(i)-1, B.at(i)-1);
    }


    cout<<d.groups().size()-1<<endl;





    return 0;
}

Measured memory_bytes: 9068
from fractions import gcd
a,b,c,d = [int(x) for x in input().split()]

def div(x, y, z):
    return x - (x // y) - (x // z) + (x // (y * z // gcd(y, z)))

ans = div(b, c, d) - div(a-1, c, d)
print(ans)

Measured memory_bytes: 5688
def digits_sum(n):
    s = 0
    while True:
        n, t = divmod(n, 10)
        s = s + t
        if n == 0:
            break
    return s


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

xs = {i: digits_sum(i) for i in range(1, N+1)}
ys = [i for i, y in xs.items() if A <= y and y <= B]
print(sum(ys))

Measured memory_bytes: 3900
#define _USE_MATH_DEFINES
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
#pragma endregion //#include
/////////

#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)4e18+20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	int N;
	cin>>N;
	vector<LL> L(N+1),R(N+1);
	for(int i=0;i<N;++i){
		cin>>L[i]>>R[i];
	}
	L[N]=0;
	R[N]=0;
	sort(L.begin(),L.end());
	sort(R.begin(),R.end());
	LL Lsum = 0;
	LL Rsum = 0;
	int Lpos=N;
	int Rpos=0;
	LL ans = 0;

	for(int k=1;k<=(N+1)/2;++k){
		if(Rpos==Lpos){
			LL res = Lsum-Rsum;
			ans = max(ans,res+L[Lpos]);
			ans = max(ans,res-R[Rpos]);
			break;
		}else if(Rpos>Lpos){
			break;
		}else{
			Lsum += L[Lpos];Lpos--;
			Rsum += R[Rpos];Rpos++;
		}
		ans = max(ans,Lsum-Rsum);
	}
	cout << ans*2 << endl;
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()


Measured memory_bytes: 1920
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	table := [][]int{ // abcdefgの順番の
	{1,1,1,1,1,1,0}, // 1
	{0,1,1,0,0,0,0}, // 2
	{1,1,0,1,1,0,1}, // 3
	{1,1,1,1,0,0,1}, // 4
	{0,1,1,0,0,1,1}, // 5
	{1,0,1,1,0,1,1}, // 6
	{1,0,1,1,1,1,1}, // 7
	{1,1,1,0,0,1,0}, // 8
	{1,1,1,1,1,1,1}, // 9
	{1,1,1,1,0,1,1}, // 10
	}
	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		if n == -1 {
			break
		}
		initial := []int{0,0,0,0,0,0,0}
		for i := 0; i < n; i++ {
			scanner.Scan()
			d, _ := strconv.Atoi(scanner.Text())
			for j := 6; j >= 0; j-- {
				fmt.Printf("%d", initial[j]^table[d][j])
				initial[j] = table[d][j]
			}
			fmt.Println()
		}
	}
}


Measured memory_bytes: 1076
t=[]
max_time=999
flg=False
for i in range(5):
    t.append(int(input()))
    if (t[i]%10)<max_time and (t[i]%10)!=0:
        max_time=(t[i]%10)
        flg=True
    if t[i]%10!=0:
        t[i]+=10-(t[i]%10)
if flg:
    print(sum(t)-(10-max_time))
else:
    print(sum(t))

Measured memory_bytes: 3064
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
MOD = 10**9 + 7

a,b,c = map(int,input().split())
if a <= c and c <= b:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3316
# coding: utf-8
import sys
 
inputline = list(input()) #1文字ずつ文字のリストに
akihabara = list("AKIHABARA")

# Aの数
count = 4

lineLength = len(akihabara) - len(inputline)
for i in range( len(inputline) ):
    if inputline[i] == "A":
      count -= 1
#print(count)
# 正解より文字数が多い、あるいは文字数が5文字以下のとき
if lineLength < 0 or len(inputline)+count < 9 :
    print("NO")
# 正解と文字数が同じとき
elif lineLength == 0:
    if inputline == akihabara:
        print("YES")
    else:
        print("NO")
# 正解より文字数が少ないとき

else:
    for i in range(9):
        if i == 8 and len(inputline)<9:
            inputline.append("A")
        elif inputline[i] != akihabara[i]:
            inputline.insert(i, "A")
            
    if inputline == akihabara:
        print("YES")
    else:
        print("NO")


Measured memory_bytes: 3064
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
 
const int N = 1e5 + 10 , M = 5e5+10 ,  MOD = 1e9+7;
const int OO = 0x3f3f3f3f;
const double EPS = 1e-3;
 
#define clr(arr,val) memset(arr , val , sizeof (arr))
#define loop(i,n) for(int i = 0;i < int(n);i++)
#define rloop(i,n) for(int i = int(n)-1;i >= 0;i--)
#define range(i,a,b) for(int i = int(a);i <= int(b);i++)
#define ALL(v) ((v).begin()) , ((v).end())
#define SZ(v)  ((int)((v).size()))
typedef pair <int,int> pii ;
typedef vector < pii > vii ;
typedef vector < int > vi;
int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[6]={2,1,-1,-2,-1,1};int dy[6]={0,1,1,0,-1,-1}; //Hexagonal Direction
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
 



int n , h[N];

 
int main()
{
	
   // ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
 
    
    scanf("%d", &n);
    for(int i = 0 ; i < n ; ++i){

        scanf("%d", h+i);
    }
    for(int i = n - 1; i > 0; i--) 
        if(h[i] < h[i-1]) 
            h[i-1] -= 1;

    
    for(int i = 1; i < n; i++) {

        if(h[i-1] > h[i])
            return cout << "No" << "\n", 0;
    }
    puts("Yes");

    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
struct data{
	int num,id;
}a[300002];
int n;
bool cmp(const data &x,const data &y)
{
	return x.num<y.num;
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i].num;
		a[i].id=i;
	}
	sort(a+1,a+n+1,cmp);
	int ans=0,q=1;
	for(int i=2;i<=n;i++)
	{
		if(a[i].id>a[i-1].id) q++;
		else
		{
			ans=max(ans,q);
			q=1;
		}
	}
	ans=max(ans,q);
	if(n==q) printf("0");
	else printf("%d",n-ans);
	return 0; 
}

Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int main(void)
{
  int a[5];
  for(int i=0;i<5;i++){
    cin >> a[i];
  }
  
  int min=9,rec;
  for(int i=0;i<5;i++){
    if(a[i] % 10 == 0){
      continue;
    }
    else if(a[i] % 10 < min){
      min = a[i] % 10;
      rec=i;
    }
  }
  int ans=0;
  for(int i=0;i<5;i++){
    if(a[i] % 10 == 0){
      ans+=a[i];
    }
    else if(a[i] % 10 != 0){
      if(i == rec){
        ans+=a[i];
      }
      else{
        a[i] /= 10;
        a[i]++;
        a[i] *= 10;
        ans+=a[i];
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

#define INF 99999999

void maxHeapipy(int);
void insert(int);
void increase(int,int);
int extract(void);

int S[200000000],H;

void maxHeapipy(int i)
{
  int left,right,max,a; /* aは交換用 */

  left = i*2;
  right = i*2+1;

  if(left <= H && S[left] > S[i]) {
    max = left;
  }else{
    max = i;
  }

  if(right <=H && S[right] > S[max])
    max = right;

  if(max != i) {
    a = S[i];
    S[i] = S[max];
    S[max] = a;
    maxHeapipy(max);
  }
}

void insert(int k)
{
  H++;
  S[H] = -INF;
  increase(H,k);
}

void increase(int i,int k)
{
  int t;
  
  if(k < S[i])
    return;
  S[H] = k;
  while(i > 1 && S[i/2] < S[i]) {
    t = S[i];
    S[i] = S[i/2];
    S[i/2] = t;
    i = i/2;
  }
}
    
    
int extract()
 {
   int maxim;
   if(H < 1)
     return -INF;
   maxim = S[1];
   S[1] = S[H--];
   maxHeapipy(1);
   return maxim;
 }

   
int main()
{
  int k;
  char mei[10];

  while(1){
    scanf("%s",mei);
    if(mei[0] == 'e' && mei[1] == 'n')
      break;
    if(mei[0] == 'i') {
      scanf("%d",&k);
      insert(k);
    }else{
      printf("%d\n",extract());
    }
  }

  return 0;
}



Measured memory_bytes: 5616
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
using namespace std;

const int MAX_N = 100005;
typedef long long LL;

class Person {
public:
  int A, B, C;
} p[MAX_N];

bool cmp(Person a, Person b) {
  return a.A - a.B < b.A - b.B;
}

int N, X, Y, Z;
LL res = 0;

priority_queue<int, vector<int>, greater<int> > q;
LL pre[MAX_N], suf[MAX_N];

int main() {
  scanf("%d%d%d", &X, &Y, &Z);
  N = X + Y + Z;
  for (int i = 1; i <= N; ++i)
    scanf("%d%d%d", &p[i].A, &p[i].B, &p[i].C);
  
  sort(p + 1, p + N + 1, cmp);

  for (int i = 1; i <= N; ++i)
    res += p[i].C, p[i].A -= p[i].C, p[i].B -= p[i].C;

  for (int i = 1; i <= N; ++i) {
    pre[i] = pre[i - 1] + p[i].B;
    q.push(p[i].B);
    if (q.size() > Y) pre[i] -= q.top(), q.pop();
  }

  while (!q.empty()) q.pop();

  for (int i = N; i; --i) {
    suf[i] = suf[i + 1] + p[i].A;
    q.push(p[i].A);
    if (q.size() > X) suf[i] -= q.top(), q.pop();
  }

  LL now = -0x3f3f3f3f3f3f3f3fLL;
  for (int i = Y; i <= N - X; ++i)
    now = max(now, pre[i] + suf[i + 1]);
  
  printf("%lld\n", res + now);
  return 0;
}


Measured memory_bytes: 3448
#include <iostream>
#include <string>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <ctime>
#include <cstdlib>


using namespace std;

int main() {
   

    int a,b;
    cin >> a >> b;
    cout << a/b << endl;
    cout << a%b << endl;
    cout << fixed << setprecision(20);
    cout << static_cast<long double>(a) / b << endl;

}



Measured memory_bytes: 3276
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<ll>;
using VV = vector<VI>;
using VS = vector<string>;

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

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,b) FOR(i, 0, b)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl

char flip(char c){
  if(c=='L'){
    return 'R';
  }else{
    return 'L';
  }
}

ll calc_happy(string s){
  ll L = s.size();
  ll happy = 0;
  rep(i, L-1){
    if(s[i]==s[i+1]) happy++;
  }
  return happy;
}

// 奇数番目、または偶数番目のみを最大K回swapさせてから幸せを計測
ll f(string t, ll offset, ll K){
  ll L = t.size();
  for(int i=offset; i<L; i+=2){
    if(K==0) break;
    t[i] = flip(t[i]);
    K--;
  }
  return calc_happy(t);
}

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

    // input
    ll N, K;
    cin >> N >> K;
    string s; cin >> s;
    
    ll initial_happy = calc_happy(s);

    stringstream ss;
    char last = '?';
    rep(i, N){
      char c = s[i];
      if(c!=last){
        ss << c;
        last = c;
      }
    }
    string t = ss.str();
    // t = "LRLRLR..." or "RLRLRL..." の形

    // 0, 2, 4, ...をひっくり返した場合
    ll plus = f(t, 0, K);

    // 1, 3, 5, ...をひっくり返した場合
    ll plus2 = f(t, 1, K);

    ll happy = initial_happy + max(plus, plus2);
    p(happy);

    return 0;
}

Measured memory_bytes: 848
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int a,b,c,sum=0;
  string s;
  cin>>a>>b>>s;
  s[b-1]+=32;
  cout<<s<<'\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define ll long long
#define coYes cout << "Yes" << endl
#define coYES cout << "YES" << endl
#define coyes cout << "yes" << endl
#define coNo cout << "No" << endl
#define coNO cout << "NO" << endl
#define cono cout << "no" << endl
#define BIT_FLAG_0 (1<<0) // 0000 0000 0000 0001
int gcd(int a, int b){ //最大公約数
    if(a%b == 0){
        return b;
    }else{
    return gcd(b, a%b);
    }
}

int main(){
    string s;
    cin >> s;
    if(s[s.length()-1]=='s'){
        cout << s << "es" << endl;
    }else{
        cout << s << "s" << endl;
    }
    return 0;
}

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

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

    int S, T;

    vector<tuple<int, int, bool>> query(2 * N);
    vector<int> X(N);
    for (int i = 0; i < N; i++)
    {
        cin >> S >> T;
        cin >> X[i];
        query[i] = make_tuple(S - X[i], i, true);
        query[i + N] = make_tuple(T - X[i], i, false);
    }
    sort(query.begin(), query.end());

    multiset<int> s;
    vector<int> time(1, -1);
    vector<int> ans(1, -1);
    for (auto q : query)
    {
        int t = get<0>(q);
        int idx = get<1>(q);
        if (get<2>(q))
        {
            s.insert(X[idx]);
        }
        else
        {
            s.erase(s.find(X[idx]));
        }
        time.push_back(t);
        if (s.empty())
        {
            ans.push_back(-1);
        }
        else
        {
            ans.push_back(*s.begin());
        }
    }
    time.push_back(1000000005);
    ans.push_back(-1);

    int D;
    for (int i = 0; i < Q; i++)
    {
        cin >> D;
        int l = 0;
        int r = time.size() - 1;
        while (r - l > 1)
        {
            int c = (l + r) / 2;
            if (time[c] <= D)
            {
                l = c;
            }
            else
            {
                r = c;
            }
        }
        cout << ans[l] << endl;
    }
}


Measured memory_bytes: 19168
#include <bits/stdc++.h>
#include <climits>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define srep(i, begin, end) for (__typeof(end) i = begin; i != end; i++)
#define si(x) int x = scanInt();
#define sll(x) LL x = scanLong();
#define sci(x) int x; scanf("%d", &x);
#define scll(x) LL x; scanf("%lld", &x);
#define pi(x) printf("%d ", x)
#define pll(x) printf("%lld ", x)
#define nl printf("\n")
#define clr(a) memset(a, 0, sizeof(a))
#define PB push_back
#define MP make_pair
using namespace std;
typedef unsigned int UI; // 32 bit integer
typedef long int LI; // 32 bit integer
typedef unsigned long int ULI; // 32 bit unsigned integer
typedef long long int LL; // 64 bit integer
typedef unsigned long long int  ULL; // 64 bit unsigned integer
typedef long double LD;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
const LL MOD = 1e9+7;

/* Fast I/O */
inline int scanInt() {
	int n = 0;
	char ch = getchar();
	int sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(int)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

inline LL scanLong() {
	LL n = 0;
	char ch = getchar();
	LL sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(LL)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

int main() {
	sll(n); sll(m);
	vector<PLL> price_count;
	rep(i, 0, n) {
		sll(a); sll(b);
		price_count.push_back(make_pair(a, b));
	}
	sort(price_count.begin(), price_count.end());
	LL curr = 0, idx = 0, total = 0;
	while(idx < n && curr < m) {
		LL bought = min(price_count[idx].second, m - curr);
		total += bought * price_count[idx].first;
		curr += bought;
		idx++;
	}
	pll(total); nl;
}


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

typedef long long ll;
typedef long double ld;
//#define int ll
//#define endl '\n'

// use unique(x) - removec consecutive items, returns vec.begin() + number of items
// for vector: sort(all(vec)); vec.erase(unique(all(vec)), vec.end());
// use iota(all(vec), 0) for filling a vector with 0,1,2...
// use fill(all(vec), 1) for filling a vector with 1,1,1...
// use rotate(vec.begin(), vec.begin() + 1, vec.end()) to rotate a vector | middle arg becomes first
// print number in binary -> cout << bitset<20>(n);

const int N=410;
const ll inf=1e18;
ll dp[N][N],sz[N][N];
ll a[N],p[N];
int n;

main(){
	cin.tie(0);cin.sync_with_stdio(0);
	cin>>n;
	for(int i=0;i<n;++i)cin>>a[i];
	for(int i=0;i<=n;++i)
		for(int j=0;j<=n;++j)
			dp[i][j]=inf;
	for(int i=0;i<n;++i)dp[i][i]=0;
	for(int i=1;i<=n;++i)p[i]=p[i-1]+a[i-1];
	for(int dist=1;dist<n;++dist)
		for(int st=0;st+dist<n;++st)
			for(int md=st;md<st+dist;++md)
				dp[st][st+dist]=min(dp[st][st+dist],dp[st][md]+dp[md+1][st+dist]+p[st+dist+1]-p[st]);
	cout<<dp[0][n-1]<<endl;
}


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

int main() {
  int N,x,ans;
  string s;
  cin>>N>>s;
  ans=0;
  x=0;
  for(int i=0;i<N;i++){
    if(s.at(i)=='I'){
      x++;
      if(x>ans){
        ans=x;
      }
    }
    else{
      x-=1;
    }
  }
  cout<<ans<<endl;
}

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

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー
#define inf (1<<29)             //1<<29でオーバーフロー

int main(int argc,char* argv[]){
    int n;
    cin >> n;

    vector<pair<string,int>> book(0),list(0);
    for(int i=0;i<n;i++){
        string s;
        int p;
        cin >> s >> p;
        list.push_back(make_pair(s,p));
        book.push_back(make_pair(s,100-p));
    }

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

    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(list[j].first==book[i].first && list[j].second==100-book[i].second){
                cout << j+1 << endl;
                break;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 3644
using System;
using System.Text;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
using System.IO;

class Solve
{
	const int mod = 1000000007;
	static void Main(string[] args)
	{
		var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
		Console.SetOut(sw);

		var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
		Array.Sort(input);
		Console.WriteLine(input[0] + input[1]);

		Console.Out.Flush();
	}
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int count = 0;
  for(int i = 0; i<N; i++){
    int a, b;
    cin >> a >> b;
    if(a==b){
      count++;
    }
    else{
      count = 0;
    }
    if(count==3){
      cout << "Yes" << endl;
      break;
    }
    if(i==N-1){
      cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e18;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int mod_pow(int x,int y) {
    int res = 1;
    while(y > 0) {
        if(y%2) {
            res = res*x%mod;
        }
        x = x*x%mod;
        y/=2;
    }
    return res;
}
int dp[5005][5005];
signed main() {
    int N;
    string S;
    cin >> N >> S;
    dp[0][0] = 1;
    for(int i = 0; i < N; i++) {
        for(int j = 0; j <= N; j++) {
            dp[i+1][max(0LL,j-1)] += dp[i][j];
            dp[i+1][j+1] += dp[i][j]*2;
            dp[i+1][max(0LL,j-1)] %= mod;
            dp[i+1][j+1] %= mod;
        }
    }

    cout << dp[N][S.size()]*mod_pow(mod_pow(2,S.size()),mod-2)%mod << endl;
}


Measured memory_bytes: 199132
#include<bits/stdc++.h>
using namespace std;
typedef long long int uli;
const int mx=(1<<15)+10;
bool criba[mx];
int primes[mx],np;
int cnt[mx+mx];
int main(){
   memset(criba,true,sizeof criba);
   criba[0]=criba[1]=false;
   for(int i=0;i<mx;i++){
      if(criba[i]){
         primes[np++]=i;
         for(int j=i+i;j<mx;j+=i){
            criba[j]=false;
         }
      }
   }
   for(int i=0;i<np;i++)
      for(int j=i;j<np;j++)
         cnt[primes[i]+primes[j]]++;
   int n;
   while(scanf("%d",&n)==1){
      if(n==0)break;
      printf("%d\n",cnt[n]);
   }
   return 0;
}

Measured memory_bytes: 1504
s = input()

if len(s) == 1:
  print(1)

else:
  n = len(s)
  dp = [[0,0] for _ in range(n)]
  dp[0][0] = 1
  dp[1][1] = 1
  
  if s[0]==s[1]:
    dp[1][0] = 1
  else:
    dp[1][0] = 2
    dp[1][1] = 1
    
  for i in range(2,n):
    dp[i][0] = dp[i-1][1]+1
    if s[i] != s[i-1]:
      dp[i][0] = max(dp[i][0], dp[i-1][0]+1)
    
    dp[i][1] = dp[i-2][0]+1
    if s[i-1:i+1] != s[i-2:i]:
      dp[i][1] = max(dp[i][1], dp[i-2][1]+1)
            
  print(max(dp[-1]))

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

int main() {
  int n;
  string s;
  cin >> n >> s;
  if (n%2==1){
    cout << "No" << endl;
  }
  else{
    int half=n/2;
    int check=1;
    for (int i; i<half; i++){
      if (s[i]!=s[i+half]){
        check=0;
      }
    }
    if (check==1){
      cout << "Yes" << endl;
    }
    else{
      cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 256
var
    n,a,b,s,l,k,i:longint;
begin
    readln(n,a,b);
    for i:=1 to n do
    begin
        k:=i;
        l:=0;
        while k>0 do
        begin
            inc(l,k mod 10);
            k:=k div 10;
        end;
        if (l>=a)and(l<=b) then inc(s,i);
    end;
    writeln(s);
end.
    

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

struct Node {
    bool visited;
    int position;
    vector<int> tos, costs;
};

void dfs(int pos, vector<Node>& nodes, int& mi, int& ma, bool& can) {
    nodes[pos].visited = true;
    for (int i = 0; i < nodes[pos].tos.size(); i++) {
        int nex = nodes[pos].tos[i];
        if (nodes[nex].visited == false) {
            nodes[nex].position = nodes[pos].position + nodes[pos].costs[i];
            mi = min(mi, nodes[nex].position);
            ma = max(ma, nodes[nex].position);
            if (ma - mi > 1e9) {
                can = false;
            } else {
                dfs(nex, nodes, mi, ma, can);
            }
        } else {
            if (nodes[pos].position + nodes[pos].costs[i] != nodes[nex].position) {
                can = false;
            }
        }
    }
}

int main() {
    int n, m;
    cin >> n >> m;
    vector<Node> nodes(n);
    for (int i = 0; i < n; i++) {
        nodes[i].visited = false;
    }
    for (int i = 0; i < m; i++) {
        int l, r, d;
        cin >> l >> r >> d;
        l--;
        r--;
        nodes[l].tos.push_back(r);
        nodes[r].tos.push_back(l);
        nodes[l].costs.push_back(d);
        nodes[r].costs.push_back(-d);
    }

    bool can = true;
    for (int i = 0; i < n; i++) {
        if (nodes[i].visited == false) {
            nodes[i].position = 0;
            int mi = 0, ma = 0;
            dfs(i, nodes, mi, ma, can);
        }
    }

    if (can) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 19456
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            int n = int.Parse(Console.ReadLine());

            for (int i = 0; i < n; i++)
            {
                string input = Console.ReadLine();

                char[] temp = input.ToCharArray();
                Array.Sort(temp);
                int min = int.Parse(new string(temp));
                Array.Reverse(temp);
                int max = int.Parse(new string(temp));

                sb.AppendLine((max - min).ToString());
            }
            Console.Write(sb);
        }
    }
}

Measured memory_bytes: 9292
#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>;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a.at(i);
    int a_max = 0;
    ll ans = 0;
    rep(i,n) {
        a_max = max(a_max, a.at(i));
        if (a.at(i) < a_max) ans += (ll) a_max - a.at(i);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4048
open Scanf
open Printf

let rec print_list a_list =
  match a_list with
    [] -> ()
  | fst::[] -> printf "%d" fst;print_newline()
  | fst::rest -> printf "%d " fst;print_list rest;;

let () =
  let _ = read_line() in
  let s2 = read_line() in
  let list_of_ints = List.map int_of_string (Str.split (Str.regexp " ") s2) in
  print_list @@ List.rev @@ list_of_ints;;

Measured memory_bytes: 2276
# D - Preparing Boxes

n = int(input())
a = list(int(x) for x in input().split())

ans = [0] * n

for i in range(n)[::-1]:
    tmp = 0
    j = 0
    while i+(i+1)*j<n:
        tmp += ans[i+(i+1)*j]
        j += 1
    if tmp%2==a[i]:
        continue
    else:
        ans[i] = 1

print(sum(ans))
if sum(ans)>0:
    print(' '.join(map(str, [i+1 for i, x in enumerate(ans) if x == 1])))



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

int main()
{
  int a, b;
  cin >> a >> b;

  if ((a % 2 == 0) || (b % 2 == 0))
  {
    cout << "Even" << endl;
  }
  else
  {
    cout << "Odd" << endl;
  }  

  return 0;
}


Measured memory_bytes: 256
public class Main {
	public static void main(String[] a){
		int temp;
		for(int i = 1; i < 10; i++){
			for(int k = 1; k < 10; k ++){
				temp = i * k;
				System.out.printf("%dx%d=%d\n", i, k, temp);
			}
		}
	}

}

Measured memory_bytes: 24812