akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main {
    public static void main(String args []){
        Scanner sc = new Scanner(System.in);
        int N  = sc.nextInt();
        int [] X = new int[N];
        int [] Y = new int[N];
        double sum = 0;
        int time = 1;
        int n =1;
        for(int i=N-1;i>0;i--) time*=i;
        for(int i=N;i>0;i--) n*=i;
        time*=2;
        for(int i=0;i<N;i++){
            X[i] = sc.nextInt();
            Y[i] = sc.nextInt();
        }
        for(int i=0;i<N;i++){
            for(int j=i+1;j<N;j++){
                double x = Math.pow(X[i]-X[j],2);
                double y = Math.pow(Y[i]-Y[j],2);
                double dis = Math.sqrt(x+y)*time;
                sum+=dis;
            }
        }
        sum/=n;
        System.out.println(sum);
    }
}

Measured memory_bytes: 21844
n = int(input())
a_list = input().split()
a_int = [int(a) for a in a_list]

ans = 1
flg_over_max = False
if(0 in a_int):
    print(0)
else:
    for a in a_int:
        ans *= a
        
        if(ans > 1000000000000000000):
            flg_over_max = True
            break
        
    if(flg_over_max):
        print(-1)
    else:
        print(ans)

Measured memory_bytes: 21660
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int	main(void)
{
	int arr_A[3][3] = {{0,0,0},{0,0,0},{0,0,0}};
	int check[3][3] = {{0,0,0},{0,0,0},{0,0,0}};
	int N;
	int index = 0;
	scanf("%d %d %d", &arr_A[0][0], &arr_A[0][1], &arr_A[0][2]);
	scanf("%d %d %d", &arr_A[1][0], &arr_A[1][1], &arr_A[1][2]);
	scanf("%d %d %d", &arr_A[2][0], &arr_A[2][1], &arr_A[2][2]);
	scanf("%d",&N);
	if (N < 3)
	{
		printf("No\n");
		return(0);
	}
	
	int arr_b[N];
	while (index < N)
	{
		scanf("%d", &arr_b[index]);
		index++;
	}

	int i =0;
	int j =0;
	int cnt=0;
	index =0;
	while (index < N)
	{
		i =0;
		while (i <3)
		{
			j =0;
			while (j <3)
			{
				if(arr_A[i][j] == arr_b[index])
				{
					check[i][j] = 1;
					cnt++;
				}
				j++;
			}
			i++;
		}
		index++;
	}
	if(cnt <3 )
	{
		printf("No\n");
		return (0);
	}
	i =0;
	j =0;
	while (i <3)
	{
		cnt =0;
		j = 0;
		while(j <3)
		{
			cnt = check[i][j] + cnt;
			j++;
		}
		if (cnt == 3)
		{
			printf("Yes\n");
			return (0);
		}
		i++;
	}
	i=0;
	j=0;
	cnt=0;
	while (i <3)
	{
		cnt =0;
		j = 0;
		while(j <3)
		{
			cnt = check[j][i] + cnt;
			j++;
		}
		if (cnt == 3)
		{
			printf("Yes\n");
			return (0);
		}
		i++;
	}

	if(check[0][0]+check[1][1]+check[2][2] == 3 || check[0][2]+check[1][1]+check[2][0] ==3)
	{
		printf("Yes\n");
		return (0);
	}
	printf("No\n");
	return (0);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<pair<int, int>> ans;
  rep(i, n){
    rep2(j, i+1, n){
      int ii = i+1, jj = j+1;
      if(n % 2 == 0){
        if(ii + jj == n+1) continue;
      }else{
        if(ii + jj == n) continue;
      }
      ans.push_back(make_pair(ii, jj));
    }
  }
  cout << ans.size() << endl;
  for(auto p : ans){
    cout << p.first << " " << p.second << endl;
  }
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
const int maxn=1e5+5;

int main()
{
    int n,l;
    cin>>n>>l;
    char a[105][105];
    char c[105];
    for(int i=0;i<n;i++)
    {
        scanf("%s",a[i]);
    }
    for(int i=0;i<n-1;i++)
        for(int j=0;j<n-1-i;j++)
    {
        if(strcmp(a[j],a[j+1])>0)
        {
         strcpy(c,a[j+1]);
         strcpy(a[j+1],a[j]);
         strcpy(a[j],c);
        }
    }
    string ch;
    for(int i=0;i<n;i++)
        ch+=a[i];
    cout<<ch<<endl;
    return 0;
}


Measured memory_bytes: 256
n,x,y = map(int,input().split())
dic = {}
for i in range(1,n):
    dic[i] = 0
for i in range(n):
    for j in range(i+1,n):
        kyori = min(j-i,abs(x-1-i) + 1 + abs(y-1-j), abs(y-1-i) + 1 + abs(x-1-j))
        dic[kyori] +=1
for i in dic.values():
    print(i)

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(n) begin(n),end(n)
using ll = long long;
using P = pair<int,int>;
const int dx[4] = {0, 0, 1, -1};
const int dy[4] = {1, -1, 0, 0};
const int INF = 1e9;

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    int sh, sw, gh, gw;
    cin >> sh >> sw >> gh >> gw;
    sh--, sw--, gh--, gw--;
    rep(i,h) cin >> s[i];
    deque<P> q;
    vector<vector<int>> dist(h, vector<int>(w, INF));
    dist[sh][sw]=0;
    q.emplace_back(sh, sw);
    while(!q.empty()){
        int y = q.front().first;
        int x = q.front().second;
        int m = dist[y][x];
        q.pop_front();
        rep(i,4){
            int nh = y + dy[i];
            int nw = x + dx[i];
            if(nh >= h || nw >= w || nh < 0 || nw < 0) continue;
            if(s[nh][nw]=='#') continue;
            if(dist[nh][nw]<=m) continue;
            dist[nh][nw] = m;
            q.emplace_front(nh, nw);
        }
        for(int i = -2; i <= 2; ++i){
            for(int j = -2; j <= 2; ++j){
                int nh = i + y;
                int nw = j + x;
                if(nh >= h || nw >= w || nh < 0 || nw < 0) continue;
                if(s[nh][nw]=='#') continue;
                if(dist[nh][nw]<=m+1) continue;
                dist[nh][nw] = m+1;
                q.emplace_back(nh, nw);
            }
        }
    }
    if(dist[gh][gw]==INF) cout << -1 << endl;
    else cout << dist[gh][gw] << endl;
    return 0;
}

Measured memory_bytes: 9504
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,s,n) for (int i = (s); i < (n); ++i)
#define rrep(i,n,g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define len(x) (int)(x).size()
#define dup(x,y) (((x)+(y)-1)/(y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int n;
  cin >> n;
  int ans = 0;
  rep(a,1,n+1) {
    int b = (n - 1)/a;
    ans += b;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3644
N = int(input())
A = [0] + list(map(int, input().split())) + [0]

s = 0
for i in range(N + 1):
    s += abs(A[i] - A[i + 1])

for i in range(N):
    a, b, c = A[i], A[i + 1], A[i + 2]
    print(s + abs(c-a) - (abs(a-b)+abs(b-c)))


Measured memory_bytes: 13920
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1<<18;
struct po{int l,r;};
int n;
po dat[2*MAX_N-1];

void init(int n_){
  n=1;
  while(n<n_)n*=2;
  for(int i=0;i<2*n-1;i++)dat[i]=(po){0,0};
}

void compute(int k,po t){
  if(t.r==0)return;
  if(dat[k].r==0) dat[k]=t;
  else if(dat[k].r==t.l-1)dat[k].r=t.r;
  else dat[k]=(po){-1,-1};
}

void query(int a,int b,int x,int k=0,int l=0,int r=n){
  if(r<=a||b<=l)return ;
  if(a<=l&&r<=b){
    compute(k,(po){x,x});
    return ;
  }
  
  int left=k*2+1,right=k*2+2;
  compute(left,dat[k]);
  compute(right,dat[k]);
  dat[k]=(po){0,0};

  query(a,b,x,left,l,(l+r)/2);
  query(a,b,x,right,(l+r)/2,r);
}

int main(){
  int N,k;
  cin>>n>>k;
  N=n;
  init(n);

  int q;
  cin>>q;
  while(q--){
    int l,r,x;
    cin>>l>>r>>x;
    query(l-1,r,x);
  }
  
  int ans=0;
  for(int i=0;i<N;i++){
    query(i,i+1,k+1);
    ans+=(dat[i+n-1].l==1&&dat[i+n-1].r==k+1);
  }
  cout <<ans<<endl;
  return 0;
}

Measured memory_bytes: 7204
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
#include <queue>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = 1e9 + 7;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> way = {6, 7, 8, 9, 5, 4, 3, 2, 1, 0};
    for(int i = 0; i < n; i++)
    {
        int s, g; cin >> s >> g;
        if(s < g)
        {
            for(int i = s; i <= g; i++)
            {
                if(i != s) cout << " ";
                cout << i;
            }
        }
        else if(s <= 5 and g <= 5)
        {
            for(int i = s; i >= g; i--)
            {
                if(i != s) cout << " ";
                cout << i;
            }
        }
        else
        {
            int pos = s - 6;
            vector<int> ans;
            while(true)
            {
                ans.push_back(way[pos]);
                if(way[pos] == g) break;
                pos++;
                if(pos >= way.size())
                {
                    for(int i = 1; i <= g; i++) ans.push_back(i);
                    break;
                }
            }
            for(int i = 0; i < ans.size(); i++)
            {
                if(i) cout << " ";
                cout << ans[i];
            }
        }
        cout << endl;
    }
    return 0;
}




Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,s,f) for(i=s;i<f;i++)
#define print(v) for(auto &z:v) cout<<z<<' ';cout<<'\n'
#define db cout<<"db: "
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define B begin()
#define E end()
#define all(v) v.B,v.E
#define sz(v) (int)((v).size())
#define vi vector<int>
#define vii vector<pair<int,int>>
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define clk1 clock_t start_time=clock()
#define clk2 cout<<(clock()-start_time)/(double)CLOCKS_PER_SEC
#define clean(arr) memset(arr,0,sizeof(arr))
#define mod 1000000007
#define mod2 998244353
#define space 100005
//<<fixed << setprecision(9)

int main()
{
    int n,i,j,t;
    boost;

    cin>>n;
    int arr[n];
    for(i=0;i<n;i++)cin>>arr[i];
    ll sum = accumulate(arr,arr+n,0ll);
    sum%=mod;
    ll ans=0;
    for(i=0;i<n;i++)
    {
        sum-=arr[i];
        ans+= sum*arr[i];
        sum%=mod;
        ans%=mod;
    }
    ans+=mod;
    ans%=mod;
    cout<<ans;

    return 0;
}

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

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;
 
const ll INF = 1LL<<60;
const int MINF = 1e9;
const int MOD = 1e9+7;

using vi = vector<int>;
using vii = vector<vi>;

template<typename T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

template<typename T>
T GCD(T a,T b){ return b ? GCD(b,a%b) : a ;}
template<typename T>
T LCM(T a,T b){ return a*b / GCD(a,b) ;}

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

int main() {
    string s,t;cin >> s >> t;
    int a,b;cin >> a >> b;
    string target;cin >> target;
    if(target == s)a--;
    else b--;
    cout << a << ' ' << b << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {

//    	File file = new File("test.txt");
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);
    	int D = sc.nextInt();
    	int N = sc.nextInt();
    	sc.close();
    	int num = (int)Math.pow(100, D);
    	if (N == 100) N++;
    	int ans = num * N;
    	if(D == 0) System.out.println(N);
    	else System.out.println(ans);
    }

}


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

int main(){

  string s;
  int n;
  typedef vector < int > vec;
  map < string, vec > mp;
  vector < string > v;
  
  while(cin >> s >> n){
    mp[s].push_back(n);
    v.push_back(s);
  }

  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());

  for(int i=0;i<v.size();i++){
    sort(mp[v[i]].begin(), mp[v[i]].end());
    cout << v[i] << endl;
    for(int j=0;j<mp[v[i]].size()-1;j++) cout << mp[v[i]][j] << " ";
    cout << mp[v[i]][mp[v[i]].size()-1] << endl;
  }

}

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

using namespace std;

int main() {
  int n, m, x, a[100], s = 0, e = 0;
  cin >> n >> m >> x;
  for (int i = 0; i < m; i++) {
    cin >> a[i];
    a[i] < x ? s++ : e++;
  }
  cout << min(s, e) << '\n';
  return 0;
}

Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import Data.List

main :: IO ()
main = do
  [a, b] <- f
  unless (a == 0 && b == 0) $ do
    print $ solve a b
    main
  where
    f = map read <$> words <$> getLine

solve :: Int -> Int -> Int
solve a b = minimum $ do
  (x0, x1) <- divs a
  (y0, y1) <- divs b
  let [i, j, k, l] = sort [x0, x1, y0, y1]
  return $ (j - i) ^ 2 + (k - j) ^ 2 + (l - k) ^ 2

divs :: Int -> [(Int, Int)]
divs x = f 1 []
  where
    f d as
      | d ^ 2 > x = as
      | x `mod` d == 0 = f (d + 1) ((d, x `div` d) : as)
      | otherwise = f (d + 1) as



Measured memory_bytes: 5572
function Main(input) {
  input = input.split("\n");
  var N = parseInt(input[0].split(" ")[0], 10);
  var nums = input[1].split(" ").map((n) => parseInt(n, 10));

  while (true) {
    var num = N.toString().split("");

    if (num.every((n) => nums.indexOf(parseInt(n, 10)) == -1)) {
      break;
    } else {
      N++;
    }
  }

  console.log(N);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 13216
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<(n);++i)
#define rep2(i,a,b) for (ll i=(a);i<(b);++i)
#define debug(x) cout << #x << '=' << x << endl
#define all(v) (v).begin(),(v).end()
const ll MOD=1e9+7;
//const ll MOD=998244353;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,M,V,P; cin >> N >> M >> V >> P;
    vector<ll> A(N),sum(N+1,0);
    rep(i,N) cin >> A[i];
    sort(all(A)); reverse(all(A));
    rep(i,N) sum[i+1]=sum[i]+A[i];
    int ans=P;
    rep2(i,P,N){
        if (N-i+P-1>=V){
            ans+=(A[P-1]<=A[i]+M);
            continue;
        }
        ll v=(V-(N-i+P-1))*M;
        v+=sum[i]-sum[P-1];
        v-=A[P-1]*(i-P+1);
        if (v<=0) ans+=(A[P-1]<=A[i]+M);
        else ans+=(A[P-1]+(v-1)/(i-P+1)+1<=A[i]+M);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define NIL NULL

struct Node{
  int key;
  struct Node *right;
  struct Node *left;
  struct Node *parent;
};

struct Node *root;

void insert(int);
void inorder(struct Node *);
void preorder(struct Node *);

int main(){
  int n,i,num;
  char order[10];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",order);
    if(order[0]=='i'){
      scanf("%d",&num);
      insert(num);
    } else if(order[0]=='p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}

void insert(int num){
  struct Node *y=NIL;
  struct Node *x=root;
  struct Node *z;
  z=(struct Node *)malloc(sizeof(struct Node));
  z->key=num;
  z->left=NIL;
  z->right=NIL;
  while(x!=NIL){
    y=x;
    if(z->key < x->key){
      x=x->left;
    } else {
      x=x->right;
    }
  }
  z->parent=y;
  if(y==NIL){
    root=z;
  } else {
    if(z->key < y->key){
      y->left=z;
    } else {
      y->right=z;
    }
  }
}

void inorder(struct Node *u){
  if(u==NIL)return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(struct Node *u){
  if(u==NIL)return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


    



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

int main(void)
{
  int N,A,B,i,sum=0,a,b,c,d,e;

  scanf("%d %d %d",&N,&A,&B);
  

  for(i=1;i<=N;i++)
  {
    a=i/10000;
    if(a<0) a=0;
    
    b=i/1000-a*10;
    if(b<0) b=0;
    
    c=i/100-a*100-b*10;
    if(c<0) c=0;
    
    d=i/10-a*1000-b*100-c*10;
    if(d<0) d=0;
    
    e=i-a*10000-b*1000-c*100-d*10;
    if(e<0) e=0;
    
    if(a+b+c+d+e>=A && a+b+c+d+e<=B)
    {
      sum=sum+i;
    }
  }
  

  printf("%d",sum);
  
  return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cmath>
#include <cstdint>
#include <cinttypes>
#include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>
#include <numeric>

using namespace std;

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

    vector<int> weights(n);
    for(int& w : weights){
        cin >> w;
    }

    int total = accumulate(weights.begin(), weights.end(), 0);

    int sum = 0;
    int i = 0;
    for(i = 0 ; i < n ; i++){
        sum += weights[i];
        if(sum * 2 > total){
            break;
        }
    }

    int more = sum * 2 - total;
    int less = total - sum * 2 + weights[i] * 2;
    cout << min(more, less) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>
#include <bits/stdc++.h>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long ll;
using namespace std;
typedef std::pair<ll, ll> mp;
#define fi first
#define se second
#define MOD 1000000007
inline ll read()
{
	ll x = 0, f = 1; char ch = getchar();
	while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); }
	while (isdigit(ch)) { (x *= 10) += ch - '0'; ch = getchar(); }
	return x * f;
}

const int maxk = 100, mod = 1000000007;
ll fib[maxk], res; int mx;
std::vector<mp> excellent[maxk];

int main() {
	int k = 1;
	fib[0] = fib[1] = 1;
	ll lim = 1000000000000000000;
	while(fib[k] + fib[k - 1] <= lim) {
		++ k;
		fib[k] = fib[k - 1] + fib[k - 2];
	}

	excellent[1].push_back(mp(1, 2));
	for(int i = 2; i <= k; i ++) {
		for(mp p : excellent[i - 1])
			excellent[i].push_back(mp(p.second, p.first + p.second));
		excellent[i].push_back(mp(fib[i + 1], fib[i + 1] + fib[i - 1]));
	}

 int T = read();
	while (T--)
	{
		ll x = read(), y = read(); mx = 1, res = 0;
		if (x > y) swap(x, y);
		while (mx+2 <= k && fib[mx+1] <= x && fib[mx+2] <= y) mx++;
		for (pair<ll, ll> p : excellent[mx])
		{
			if (p.fi <= x && p.se <= y)
				(res += (y - p.se) / p.fi + 1) %= MOD;
			if (p.se <= x)
				(res += (x - p.se) / p.fi + 1) %= MOD;
		}
		if (mx == 1) res += x;
		printf("%d %lld\n", mx, res);
	}
}

Measured memory_bytes: 4424
#include <iostream>


using namespace std;


int main() 
{
 int w, h, x, y, r;
    cin >> w >> h >> x >> y >> r;
    
    if(x-r >= 0 && y-r >= 0  && w-r-x >=0 && h-r-y >=0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}







Measured memory_bytes: 3116
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <algorithm>
using namespace std;

int main()
{
	int N = 0;
	cin >> N;
	vector<int> A(N + 1);
	vector<int> B(N);
	for (int i = 0; i < N + 1; ++i)
	{
		cin >> A[i];
	}
	for (int i = 0; i < N; ++i)
	{
		cin >> B[i];
	}
	unsigned long long count = 0;
	int f_i_i, f_i_i1;
	for (int i = 0; i < N; ++i)
	{
		if (i == 0)
		{
			f_i_i = min(A[0], B[0]);
		}
		else
		{
			f_i_i = min(A[i] - f_i_i1, B[i]);
		}

		f_i_i1 = min(A[i + 1], B[i] - f_i_i);

		count += (f_i_i + f_i_i1);
	}

	cout << count;
}



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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define fi first
#define se second
#define setpre(x) cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ cout << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , ";
    logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 100005;

/* ...o(^-^)o... */
int main(){
    int n; cin >> n;
    string s; cin >> s;
    int o[] = {0, 3, 1, 2};
    int x[] = {1, 2, 0, 3};
    string sr[] = {"SS", "SW", "WS", "WW"};
    rep(t, 4){
        int u = t; vector<int> v;
        rep(i, n){
            v.push_back(u);
            if(s[i] == 'o') u = o[u];
            else u = x[u];
        }
        if(u != t) continue;
        string ans = "";
        rep(i, n){
            if(v[i] % 2) ans += "W";
            else ans += "S";
        }
        out(ans); return 0;
    }
    out(-1);
}


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

typedef long long ll;
const ll INF = 1000000000000000000;

int main() {
    ll N, M, R;
    cin >> N >> M >> R;
    vector<ll> r(R);
    for (int i = 0; i < R; i++) {
        cin >> r[i];
        r[i]--;
    }

    vector<vector<ll>> dist(N, vector<ll>(N, INF));
    for (int i = 0; i < M; i++) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        dist[a][b] = min(dist[a][b], c);
        dist[b][a] = min(dist[b][a], c);
    }

    for (int k = 0; k < N; k++) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }

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

    ll res = INF;
    do {
        ll sum = 0;
        for (int i = 0; i < R - 1; i++) {
            sum += dist[r[i]][r[i + 1]];
        }
        res = min(res, sum);
    } while (next_permutation(r.begin(), r.end()));

    cout << res << endl;
    return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
 
template<class T>
T gcd(T x,T y){return y?gcd(y,x%y):x;}
 
int main()
{
	int T; scanf("%d",&T);
	unsigned long int A,B,C,D;
	for(;0<T;T--)
	{
		scanf("%ld%ld%ld%ld",&A,&B,&C,&D);
		if(A<B||D<B||C<A%B||C<B-gcd(B,D)) puts("No");
		else puts("Yes");
	}
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
const long long INF = 1e9 + 7;
using namespace std;
map<int, int> mp;
int main()
{
	string s;
	cin >> s;
	if (((s.at(0) == '1' && (s.at(1) == '0' || s.at(1) == '1' || s.at(1) == '2')) || (s.at(0) == '0' && s.at(1) != '0')) && ((s.at(2) == '1' && (s.at(3) == '0' || s.at(3) == '1' || s.at(3) == '2')) || (s.at(2) == '0' && s.at(3) != '0'))) {
		cout << "AMBIGUOUS" << endl;
	}
	else if (!((s.at(0) == '1' && (s.at(1) == '0' || s.at(1) == '1' || s.at(1) == '2')) || (s.at(0) == '0' && s.at(1) != '0')) && ((s.at(2) == '1' && (s.at(3) == '0' || s.at(3) == '1' || s.at(3) == '2')) || (s.at(2) == '0' && s.at(3) != '0'))) {
		cout << "YYMM" << endl;
	}
	else if (((s.at(0) == '1' && (s.at(1) == '0' || s.at(1) == '1' || s.at(1) == '2')) || (s.at(0) == '0' && s.at(1) != '0')) && !((s.at(2) == '1' && (s.at(3) == '0' || s.at(3) == '1' || s.at(3) == '2')) || (s.at(2) == '0' && s.at(3) != '0'))) {
		cout << "MMYY" << endl;
	}
	else {
		cout << "NA" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <algorithm>
#include <string>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <vector>
#include <functional>
#include <cassert>
#include <cmath>
#include <map>
#include <set>
#include <queue>

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	long long N;
	cin >> N;
	cout << (N * (N - 1)) / 2 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cfenv>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>

using namespace std;
using ll = long long;

int main(){
  bool reverse_flag = false;
  string s;
  cin >> s;

  deque<string> S;
  S.emplace_back(s);

  int Q;
  cin >> Q;

  for(int i = 0; i < Q; ++i){
    int T;
    cin >> T;
    if(T == 1){
      reverse_flag = !reverse_flag;
    } else if(T == 2){
      int F;
      string C;

      cin >> F >> C;

      if(reverse_flag){
        if(F == 1){
          S.emplace_back(C);
        }else if(F == 2){
          S.emplace_front(C);
        }
      } else{
        if(F == 1){
          S.emplace_front(C);
        }else if(F == 2){
          S.emplace_back(C);
        }
      }
    }
  }

  string ans = "";

  for(auto itr = S.begin(); itr != S.end(); ++itr){
    ans += *itr;
  }

  if(reverse_flag){
    reverse(ans.begin(), ans.end());
  }
  
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 12128
#include <bits/stdc++.h>
#include <ext/numeric>

using namespace std;
using namespace __gnu_cxx;

#define all(v)   v.begin(), v.end()
#define endl "\n"
#define pb push_back
#define F first
#define S second
#define THINK_TWICE_CODE_ONCE cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
#define isOdd(n)    (n&1)
#define LLMAX LLONG_MAX
#define LLMIN LLONG_MIN
#define IMN INT_MIN
#define IMX INT_MAX
#define pow(n, m) power((ll)n, (ll)m)
#define numOfDigits(n)  ((n)? (ll)(log10(n)+1) : 1)
#define mem(x, val)    memset(x, val, sizeof(x))
#define MOD 1000000007

typedef long long ll;
typedef long double ld;
typedef double dd;
typedef string str;
typedef pair<int, int> pii;


int main()
{
    THINK_TWICE_CODE_ONCE
    //freopen("test cases\\.txt", "r", stdin) ;
    int n, m; cin>>n>>m;
    vector<vector<int>>v (n+1);
    for(int i = 0;i<m; i++){
        int a, b; cin>>a>>b;
        v[a].pb(b);
        v[b].pb(a);
    }
    for(int i =1; i<=n; i++){
        cout<<v[i].size()<<endl;
    }
	return 0;

}


Measured memory_bytes: 256
use std::io::Write;

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn main() {
    let n: usize = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        let s = s.trim_right().to_owned();
        s.parse().unwrap()
    };

    let p: Vec<usize> = {
        let mut v: Vec<usize> = Vec::new();
        for _ in 0..n {
            let v_i = {
                let mut s = String::new();
                std::io::stdin().read_line(&mut s).unwrap();
                let s = s.trim_right().to_owned();
                s.parse().unwrap()
            };
            v.push(v_i)
        }
        v
    };

    let mut indices = vec![0; n + 1];
    for (i, &x) in p.iter().enumerate() {
        indices[x] = i;
    }

    let mut dp = vec![1; n + 1];
    for i in 2..(n + 1) {
        if indices[i - 1] < indices[i] {
            dp[i] = dp[i - 1] + 1;
        } else {
            dp[i] = 1;
        }
    }

    let mut max = 0;
    for i in 1..(n + 1) {
        if dp[i] > max {
            max = dp[i];
        }
    }

    println!("{}", n - max);
}


Measured memory_bytes: 10492
#include<iostream>
using namespace std;
bool find(int a){
	for(int i=2;i*i<=a;i++){
		if(a % i == 0){
			return false;
		}
	}
	return true;
}
int main(){
	int a;
	cin>>a;
	while(1){
		if(find(a) == true){
			cout<<a;
			return 0;
		}
		a++;
	}
}

Measured memory_bytes: 256
using System;
class fifty{
  public static void Main(){
    String str = Console.ReadLine();
    checklist c = new checklist();
    int kind=0,count=0,p=0;
    char[] list = new char[str.Length+1];
    for(int i=0; i<str.Length; i++){
      if(!c.check(list,str[i])){
        kind++;
        list[p] = str[i];
        p++;
      }
    }
    for(int i=0; i<str.Length; i++){
      if(str[0].Equals(str[i])){
        count++;
      }
    }
    if(count == 2 && kind == 2){
      Console.WriteLine("Yes");
    }
    else{
      Console.WriteLine("No");
    }
  }
}

class checklist{
  public bool check(char[] list, char c){
    for(int i=0; i<list.Length; i++){
      if(list[i].Equals(c)){
        return true;
      }
    }
    return false;
  }
}


Measured memory_bytes: 11092
#include<stdio.h>
#include<math.h>
int main(void)
{
    int N,T,A,H[1001];
    int i,i_ans;
    float d,T_i;

    scanf("%d %d %d",&N,&T,&A);
    i=1;
    while(i<=N)
    {
       scanf("%d",&(H[i]));
       i++;
    }

    i=1;
    d=100000000000;
    while(i<=N)
    {
       T_i=T-H[i]*0.006;
       if(fabsf(A-T_i)<d){
           d=fabs(A-T_i);
           i_ans=i;
       }
       i++;
    }

    printf("%d\n",i_ans);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=1e5+5;
vector< pair<ll,ll> > adj[N];
ll vis[N],dist[N],n,m;
void dfs(ll u,ll d){
    if(vis[u]==1){
        if(dist[u]!=d){
            cout<<"No";
            exit(0);
        }
        return;
    }
    vis[u]=1;
    dist[u]=d;
    for(auto &node:adj[u])dfs(node.first,d+node.second);
}
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cin>>n>>m;
    for(ll i=0;i<m;i++){
        ll x,y,d;cin>>x>>y>>d;
        adj[x].push_back({y,d});
        adj[y].push_back({x,-d});
    }
    for(ll i=1;i<=n;i++)if(!vis[i])dfs(i,0);
    cout<<"Yes";
}

Measured memory_bytes: 16384
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define Int int32_t
#define all(c) c.begin(), c.end()
#define FAST ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define pii pair< int , int >
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define bitcnt(n) __builtin_popcountll(n)
#define setpre(n) cout << fixed << setprecision(n)
#define tr(c) for(auto x : c )cout << x << " ";
#define ol(c , s , e ) for(int pos=s; pos<e ; pos++) cout << c[pos] << " ";
#define PI acos(-1l)
const int M = 1000000007;
const int N=3e5+5;
const int INF = 2e18+5;
//#define rohit
#ifdef rohit
template<typename... T >
void bug(T... __VA_ARGS__) {
    ((cerr << __VA_ARGS__ << " ") , ...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", bug(__VA_ARGS__) , cerr << endl;
#endif

void solve(){
    int a[6];
    for(int i=1; i<=5; i++){
        cin >> a[i];
    }
    for(int i=1; i<=5 ;i++){
        if(a[i]!=i){
            cout << i;
            return;
        }
    }
}


signed main(){
    FAST;
    //TODO: check test cases.
    int tc=1;
//    cin >> tc;
    for(int t = 1 ; t <= tc ; t++){
        solve();
    }
}
/* Extra Cares
 * 1)In graphs or dp problems sometimes long long creates MLE.
 * 2)Check whether int to long long typecasting is commented or not?
 * 3)Check overflows.
*/

Measured memory_bytes: 3636
N, M = map(int, input().split())
edges = [[] for i in range(N)]
for i in range(M):
    s, t = map(int, input().split())
    edges[s - 1].append(t - 1)

def calc():
    steps = [0 for i in range(N)]
    for i in range(N - 2, -1, -1):
        steps[i] = 1 / len(edges[i]) * sum(steps[node] for node in edges[i]) + 1

    return steps

steps = calc()

best = steps[0]

for i in range(N - 1):
    if len(edges[i]) == 1: continue
    highest = max(edges[i], key=lambda n: steps[n])
    edges[i].remove(highest)
    best = min(best, calc()[0])
    edges[i].append(highest)

print(best)


Measured memory_bytes: 62396
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int a,b,k;
    cin >> a >> b >> k;
    int ans;
    int j=0;
    for (int i=min(a,b);i>0;i--) {
        if (a%i==0 && b%i==0) j++;
        if (j==k) {
            ans=i;
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

import static java.lang.System.*;

public class Main {
    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int N = ni();
        int[] a = niarr(N);

        int cnt = 0;
        for (int i = 1; i < N; i++) {
            if (a[i - 1] == a[i]) {
                cnt++;
                i++;
            }
        }
        out.print(cnt);
    }

    static int ni() {
        return sc.nextInt();
    }

    static long nl() {
        return sc.nextLong();
    }

    static String ns() {
        return sc.next();
    }

    static int[] niarr(int N) {
        int[] a = new int[N];
        for (int i = 0; i < N; i++) {
            a[i] = sc.nextInt();
        }
        return a;
    }

    static long[] nlarr(int N) {
        long[] a = new long[N];
        for (int i = 0; i < N; i++) {
            a[i] = sc.nextLong();
        }
        return a;
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
int main(){
        int n; cin >> n;
        long long int sum = 0;
        for (int x = 1; x <= n; ++x){
            if (x % 3 == 0 || x % 5 == 0) continue;
            sum += x;

        }
        cout << sum << endl;
    return 0;
}



Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int  x,y,z,k;
	cin>>x>>y>>z>>k;
	long long a[x],b[y],c[z];
	for(long long i=0;i<x;++i)
	cin>>a[i];
	for(long long i=0;i<y;++i)
	cin>>b[i];
	for(long long i=0;i<z;++i)
	cin>>c[i];
	sort(a,a+x,greater<long long>());
	sort(b,b+y,greater<long long>());
	sort(c,c+z,greater<long long>());
	long long t[k*k*3],ti=0;
	for(long long i=0;i<x;++i)
	for(long long j=0;j<y;++j)
	for(long long l=0;l<z;++l)
	{
		if((i+1)*(j+1)*(l+1)<=k)
		{
			t[ti]=a[i]+b[j]+c[l];
			++ti;
			continue;
		}
		break;
	}
	sort(t,t+ti,greater<long long>());
	for(long long i=0;i<k;++i)
	cout<<t[i]<<endl;
	return 0;
}

Measured memory_bytes: 3072
using System;

namespace ITP_6_B{
    public class Program{
        public static void Main(string[] args){
            bool[,] result = new bool[4,13];

            int count = int.Parse(Console.ReadLine());
            string temp = null;
            for(int i=0; i<count; i++){
                temp = Console.ReadLine();
                string[] key = temp.Split(' ');
                result[ConvertMark(key[0]),int.Parse(key[1])-1] = true;
            }
            //????????????
            for(int i=0; i<4; i++){
                for(int k=0; k<13; k++){
                    if(!result[i,k]){
                        int lank = k+1;
                        Console.WriteLine(revertMark(i)+" "+lank);
                    } 
                }
            }
        }
        private static int ConvertMark(string mark){
            switch(mark){
                case "S": return 0;
                case "H": return 1;
                case "C": return 2;
                case "D": return 3;
                default : return -1;
            }
        }

        private static string revertMark(int mark){
            switch(mark){
                case 0: return "S";
                case 1: return "H";
                case 2: return "C";
                case 3: return "D";
                default : return null;
            }
        }
    }
}

Measured memory_bytes: 9144
from collections import defaultdict
import sys
input = sys.stdin.readline

class UnionFind:
    def __init__(self, N):
        self.parent = list(range(N))
        self.rank = [0] * N
        self.size = [1] * N

    def find(self, x):
        r = x
        while self.parent[r] != r:
            r = self.parent[r]
        while self.parent[x] != r:
            x, self.parent[x] = self.parent[x], r
        return r

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
            self.size[y] += self.size[x]
        else:
            self.parent[y] = x
            self.size[x] += self.size[y]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def get_size(self, x):
        return self.size[self.find(x)]

N, K, L = map(int, input().split())
uf1 = UnionFind(N+1)
for _ in range(K):
    p, q = map(int, input().split())
    uf1.unite(p, q)
uf2 = UnionFind(N+1)
for _ in range(L):
    r, s = map(int, input().split())
    uf2.unite(r, s)
cnt = defaultdict(int)
for i in range(1, N+1):
    cnt[(uf1.find(i), uf2.find(i))] += 1
ans = [cnt[(uf1.find(i), uf2.find(i))] for i in range(1, N+1)]
print(*ans)

Measured memory_bytes: 105552
#include <stdio.h>
#include<string.h>
int main(){
  
   char str[10] ;
   scanf("%s",&str);

   int length = strlen(str);
   int count = 0 , i;
   
   for(i = 0 ; i<length ; i++){
       if(str[i]>=65 && str[i]<=90){
           count++;
       }
   }
   //printf("%d",size);
   int count2 = 0;
   if(str[0] == 'A' && count==2){
       for(i = 2 ; i<length-1 ; i++){
           if(str[i]=='C'){
               count2++;
               break;
           }
       }
     if(count2!=0){
       printf("AC");
   	 }else{
       printf("WA");
   	 }
   }else{
     printf("WA");
   }

}

Measured memory_bytes: 128
data class Edge(val f: Int, val t: Int, val d: Long)
fun main(args: Array<String>) {
    val N = nextInt()
    val XY = Array(N) { listOfLong(-1) }
    val Sx = (0 until N).sortedBy { XY[it][0] }
    val Sy = (0 until N).sortedBy { XY[it][1] }
    val Edges = mutableListOf<Edge>()
    for (n in 1 until N) {
        val fx = Sx[n]
        val tx = Sx[n - 1]
        val dx = XY[fx][0] - XY[tx][0]
        Edges.add(Edge(fx, tx, dx))
        val fy = Sy[n]
        val ty = Sy[n - 1]
        val dy = XY[fy][1] - XY[ty][1]
        Edges.add(Edge(fy, ty, dy))
    }
    Edges.sortBy { it.d }
    var ans = 0L
    val uf = UnionFind(N)
    for ((t, f, d) in Edges) {
        if (uf.unite(t, f)) ans += d
    }
    println(ans)
}


fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)
fun listOfInt(vararg deltas: Int) = listOfString().map { Integer.parseInt(it) }.mapIndexed { index, int -> int + deltas[index % deltas.size] }
fun listOfLong(offset: Long = 0L) = listOfString().map { it.toLong() + offset}

class UnionFind(n: Int) {
    var rank: IntArray
    var par:  IntArray
    var size: IntArray
    init {
        this.rank = IntArray(n) { 0 }
        this.par  = IntArray(n) { it }
        this.size = IntArray(n) { 1 }
    }
    fun union(x: Int, y: Int): Boolean {
        var rx = this.root(x)
        var ry = this.root(y)
        if (rx == ry) return false
        if (this.rank[rx] < this.rank[ry]) {
            val w = rx
            rx = ry
            ry = w
        } else if (this.rank[rx] == this.rank[ry]) {
            this.rank[rx] += 1
        }
        this.par[ry] = rx
        this.size[rx] += this.size[ry]
        return true
    }
    fun find(x: Int): Int {
        if (this.par[x] == x) return x
        else {
            this.par[x] = this.find(this.par[x])
            return this.par[x]
        }
    }
    fun isSame(x: Int, y: Int) = this.root(x) == this.root(y)
    fun size(x: Int): Int = this.size[this.find(x)]
    fun root(x: Int): Int = this.find(x)
    fun unite(x: Int, y: Int) = this.union(x, y)
}


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

typedef long long ll;
typedef pair<ll,int> P;
int n;
vector<P> A;
ll dp[2005][2005];
ll nex[2005][2005];
ll ans;
int main() {

  cin >> n;


  
  for(int i = 0; i < n; i++) {
    ll a;
    cin >> a;

    A.push_back(P(a,i));
  }

  sort(A.begin(),A.end(),greater<P> ());

  // for(int i = 0; i < n; i++) cout << A[i].first <<" "<<A[i].second<< endl;

  for(ll i = 0; i < n; i++) {
    for(ll j = 0; j <= i+1; j++) {
      ll k = i - j + 1;
      if(j == 0) {
	nex[j][k] = dp[j][k-1]+abs(n-k-A[i].second)*A[i].first;
	continue;
      }
      if(k == 0) {
	nex[j][k] = dp[j-1][k]+abs(A[i].second-j+1)*A[i].first;
	continue;
      }
      nex[j][k] = max(dp[j-1][k]+abs(A[i].second-j+1)*A[i].first,dp[j][k-1]+abs(n-k-A[i].second)*A[i].first);
    }
    for(ll j = 0; j <= i + 1; j++) {
      ll k = i - j + 1;
      dp[j][k] = nex[j][k];
    }
    /* cout << i << endl;
     for(int ii = 0; ii <= i+1; ii++) {
       int j = i - ii + 1;
    cout <<"dp["<<ii<<"]["<<j<<"] = "<< dp[ii][j] << endl;
    }*/
  }
 
  for(int i = 0; i <= n; i++) {
    int j = n - i;
    ans = max(ans,dp[i][j]);
    //cout <<"dp["<<i<<"]["<<j<<"] = "<< dp[i][j] << endl;
  }
  cout << ans << endl;
    
}
  


Measured memory_bytes: 48996
def myAnswer(S:list) -> int:
   N = 0
   counter = 0
   for n,s in enumerate(S):
      if(s == "W"):
         counter += n - N
         N += 1
         

   return counter

def modelAnswer():
   tmp=1
def main():
   S = list(input())
   print(myAnswer(S[:]))
if __name__ == '__main__':
   main()

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

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

    // start
    string a, b, c;
    cin >> a >> b >> c;
    if (a.at(a.size() - 1) == b.at(0) && b.at(b.size() - 1) == c.at(0))
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    // end

    return 0;
}


Measured memory_bytes: 256
import itertools
import math
import sys
import heapq
from collections import Counter
from collections import deque
from fractions import gcd
from functools import reduce
sys.setrecursionlimit(4100000)
from functools import lru_cache
INF = 1 << 60

#ここから書き始める
a, b = map(int, input().split())
ans1 = 0
while True:
    if int(ans1 * 8 / 100) == a and int(ans1 / 10) == b:
        break
    if int(ans1 * 8 / 100) > a or int(ans1 / 10) > b:
        ans1 = -1
        break
    ans1 += 1
print(ans1)


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


int main() {
    int N;
    cin >> N;
    ll ans = 0;
    for (int i = 1; i < N; i++) {
        ans += (N-1)/i;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
// typedef long long ll;
// typedef pair<int,int> P;
// typedef pair<int,P> P1;
// typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
// #define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
// vector<pair<string,P> >vec;

// for(int i = 0 ; i <= 9-0 ; i++){
// 	for(int j = 0 ; j <= 9-0 ; j++){
// 		edge e = {j,c[i][j]};
// 		G[i].push_back(e);
// 	}
// }
#define MAX_V 300003
#define INF 1000000001
typedef long long ll;
struct edge { ll to, cost; };
typedef pair<ll, ll> P; // firstは最短距離、secondは頂点の番号
vector<edge> G[MAX_V];
ll d[MAX_V];
void dijkstra(ll s) {
	// greater<P>を指定することでfirstが小さい順に取り出せるようにする
	priority_queue<P, vector<P>, greater<P> > que;
	fill(d, d + MAX_V, INF);
	d[s] = 0;
	que.push(P(0, s));
	while (!que.empty()) {
		P p = que.top(); que.pop();
		int v = p.second;
		if (d[v] < p.first) continue;
		for (int i = 0; i < G[v].size(); i++) {
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}

int main(){	
	long long T;
	long long S;
	long long M;
	long long N;
	scanf("%lld",&N);
	scanf("%lld",&M);
	vector<long long> v(M-1+1);
	vector<long long> u(M-1+1);
	for(int i = 0 ; i <= M-1 ; i++){
		scanf("%lld",&u[i]);
		scanf("%lld",&v[i]);
		// edge e1 = {u[i]*3,1};
		// G[v[i]*3+1].push_back(e1);
		edge e2 = {v[i]*3+1,1};
		G[u[i]*3].push_back(e2);
		// edge e3 = {u[i]*3+1,1};
		// G[v[i]*3+2].push_back(e3);
		edge e4 = {v[i]*3+2,1};
		G[u[i]*3+1].push_back(e4);
		// edge e5 = {u[i]*3+2,1};
		// G[v[i]*3].push_back(e5);
		edge e6 = {v[i]*3,1};
		G[u[i]*3+2].push_back(e6);
	}
	scanf("%lld",&S);
	scanf("%lld",&T);
	dijkstra(S*3);
	// cout << d[0] << " " << d[3] << " " << d[6] << " " << d[9] << " " << d[12] << " " << d[15] << " " << d[18] << endl; 
	if (d[T*3] != INF) printf("%lld\n",d[T*3]/3); else printf("-1\n");
	
	return 0;
}



Measured memory_bytes: 20608
#include<iostream>
using namespace std;
int main(){
    int n,a,i,c=0;
    cin>>n;
    for(i=1;n--;i++){
        cin>>a;
        if(i!=a){
            c++;
        }
    }
    if(c>=0 && c<=2){
        cout<<"YES";
    }
    else{
        cout<<"NO";
    }
    return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <string>
#include <unordered_map>
#include <cstring>
#include <chrono>
#include <vector>
#include <map>
#include <random>
#include <set>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <stdio.h>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <deque>
#include <cassert>
#include <stack>
using namespace std;
 
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define ll long long
#define y1 abcde
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>

const int mod = 1e9 + 7;
const int inf = 2e9;
const int N = 1e5 + 15;
int n, dp[2][N];
vector <int> g[N];

// dp[painted_black][i]

inline int add(int a, int b) {
    if(a + b >= mod)
        return a + b - mod;
    return a + b;
}

inline int multiply(int a, int b) {
    return ((ll)a * b) % mod;
}

void dfs(int v, int p = -1) {
    dp[0][v] = dp[1][v] = 1;
    for(int to : g[v])
        if(to != p) {
            dfs(to, v);
            dp[1][v] = multiply(dp[1][v], dp[0][to]);
            dp[0][v] = multiply(dp[0][v], add(dp[0][to], dp[1][to]));
        }
}

main() {
    scanf("%d", &n);
    for(int i = 1; i < n; ++i) {
        int u, v;
        scanf("%d %d", &u, &v);
        g[u].pb(v);
        g[v].pb(u);
    }
    dfs(1);
    printf("%d\n", add(dp[1][1], dp[0][1]));
    return 0;
}

Measured memory_bytes: 13440
from collections import deque
N, D, A = map(int, input().split())
ls = []
for i in range(N):
  x,h = map(int, input().split())
  h = h//A if h%A==0 else h//A+1
  ls += [(x,h)]
ls.sort(key=lambda x:x[0])
deq = deque([])
ans = 0
acc = 0
for i in range(N):
  x, h = ls[i]
  while deq and deq[0][0]<x:
    y, d = deq.popleft()
    acc -= d
  n = max(0,h-acc)
  ans += n
  acc += n
  if n:
    deq += [(x+2*D,n)]
print(ans)

Measured memory_bytes: 79704
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;

int main(){
    long long A,B,M;
    cin >> A >> B >> M;
    long long a[A+1],b[B+1];
    for(int i=1;i<A+1;i++){
        cin >> a[i];
    }
    for(int i=1;i<B+1;i++){
        cin >> b[i];
    }
    long long x[M],y[M],c[M];
    for(int i=0;i<M;i++){
        cin >> x[i] >> y[i] >> c[i];
    }

    long long min_a,min_b;
    min_a=a[1];
    for(int i=1;i<A+1;i++){
        if(min_a>=a[i]){
            min_a = a[i];
        }
    }
    min_b=b[1];
    for(int i=1;i<B+1;i++){
        if(min_b>=b[i]){
            min_b = b[i];
        }
    }

    long long price[M];
    for(int i=0;i<M;i++){
        price[i] = a[x[i]]+b[y[i]]-c[i];
    }
    long long min_price=price[0];
    for(int i=0;i<M;i++){
        if(min_price>=price[i]){
            min_price = price[i];
        }
    }

    cout << min(min_a+min_b,min_price) << endl;
}

Measured memory_bytes: 4992