akhauriyash/Code-Regression huggingface dataset:
#define w 200001
i;x;y;p;main(n,m,j){
  long int k,a[w],A[w],b[w],B[w];
  scanf("%d%d%ld",&n,&m,&k);
  for(;x<n;){
    scanf("%ld",&a[x]);
    A[x+1]=A[x]+a[x];
    x++;
  }
    
  for(;y<m;y++){
    scanf("%ld",&b[y]);
    B[y+1]=B[y]+b[y];
  }
  int mo=m;
        
  for(;i<=n;i++){
    if(A[i]>k)break;
            
    for(j=mo;j>=0;j--){
      if(A[i]+B[j]<=k){
        if(i+j>p)p=i+j;
        mo=j;
        break;
      }
    }
  }
  printf("%d",p);
}

Measured memory_bytes: 7892
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<string.h>
#include<algorithm>
#include <cmath>

using namespace std;

long long i,j,N,n,m,a0,a1,p;
long long k;
vector<long long> A;

int main()
{
  p=1000000007;
  cin >> N;
  A.assign(N,0);
  for(i=0;i<N;i++)
  {
    cin>>A[i];
  }
  
  k=0;
  n=1;
  for(i=0;i<60;i++)
  {
    a0=0;
    a1=0;
    for(j=0;j<N;j++)
    {
      if((n&A[j])==0)
      {
        a0++;
      }
      else
      {
        a1++;
      }
    }
    m=n%p;
    a0=(a0*a1)%p;
    k+=(m*a0)%p;
    n=n*2;
  }
  k=k%p;
  cout <<k;
  
  
}

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

int main() {
    string s,t;
    cin>>s>>t;
    int n=s.size();
    for (int i=n-t.size();i>=0;i--) {
        int f=1;
        for (int j=0;j<t.size();j++)
            f&=s[i+j]==t[j]||s[i+j]=='?';
        if (f) {
            for (int j=0;j<t.size();j++)
                s[i+j]=t[j];
            for (int j=0;j<s.size();j++)
                if (s[j]=='?')
                    s[j]='a';
            cout<<s<<endl;
            return 0;
        }
    }
    cout<<"UNRESTORABLE\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

typedef vector<vector<int> > B;

bool checkQs(vector<int>& queen, int r, int c) {
    for(int i=0; i<8; ++i) {
        if(queen[r]==i) return false; // yoko
        if(queen[i]==c) return false; // tate
        if(r+c-i>=0 && r+c-i<8 && queen[r+c-i]==i) return false; // cross
        if(r-c+i>=0 && r-c+i<8 && queen[r-c+i]==i) return false; // cross
    }
    return true;
}

int main() {
    vector<int> queen(8,-1);

    int k;
    cin >> k;
    for(int i=0; i<k; ++i) {
        int r,c;
        cin >> r >> c;
        queen[r]=c;
    }

    queue<pair<int,vector<int> > > q;

    if(queen[0]!=-1) {
        q.push(make_pair(1,queen));
    } else {
        for(int i=0; i<8; ++i) {
            if(checkQs(queen,0,i)) {
                queen[0]=i;
                q.push(make_pair(1,queen));
                queen[0]=-1;
            }
        }
    }

    while(true) {
        pair<int, vector<int> > p=q.front(); q.pop();
        int nowr=p.first;
        queen=p.second;
        if(nowr==8) break;
        if(queen[nowr]!=-1) {
            q.push(make_pair(nowr+1,queen));
        } else {
            for(int i=0; i<8; ++i) {
                if(checkQs(queen,nowr,i)) {
                    queen[nowr]=i;
                    q.push(make_pair(nowr+1,queen));
                    queen[nowr]=-1;
                }
            }
        }
    }

    for(int i=0; i<8; ++i) {
        for(int j=0; j<8; ++j) {
            cout << (queen[i]==j?'Q':'.');
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3144
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int n,k,A[200001],p,ans=0;
int solve(int x){
    if(A[x]<=p) return 1;
    return 0;
}
int ok,ng;
int search(){
    while(abs(ok-ng)>1){
        int mid=(ok+ng)/2;
        if(solve(mid)) ok=mid;
        else ng=mid;
    }
}
int main(){
    cin>>n;
    rep(i,n) cin>>A[i];
    cin>>k;
    rep(i,k){
        cin>>p;
        ok=0,ng=n;
        search();
        if(A[ok]==p) ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3480
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long LL;
#define MAXN 2000
LL a[MAXN+5];
LL b[MAXN+5][MAXN+5];
LL abs(LL x)
{
	return x>=0 ? x:-x; 
}
LL min(LL x,LL y)
{
	return x<y ? x : y;
}
LL read()
{
	LL x=0,f=1;
	char c=getchar();
	while('0'>c||c>'9'){if(c=='-') f=-1;c=getchar();}
	while('0'<=c&&c<='9'){x=x*10+c-'0';c=getchar();}
	return x*f;
}
int main()
{
	int n;
    LL x,sum = 1LL << 60LL;
    n=read(),x=read();
    for(int i = 1;i <= n;i++) a[i]=read();
    for(int i = 1;i <= n;i++){
        b[i][0] = a[i];
        for(int k = 1;k <= n - 1;k++){
            int pos = i - k;
            if(pos <= 0) pos = n - abs(pos);
            b[i][k] = min(b[i][k - 1],a[pos]);
        }
    }
    for(int k = 0;k <= n - 1;k++){
        LL ans = 0;
        for(int i = 1;i <= n;i++){
            ans += b[i][k];
        }
        sum = min(sum,ans + x * k);
    }
   printf("%lld\n",sum);
}

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

using ll = long long;
using namespace std;

int main(void){
  ll x, a, b;
  cin >> x >> a >> b;

  ll c = -a + b;
  if(c <= 0){
    cout << "delicious" << endl;
  }else if(c <= x){
    cout << "safe" << endl;
  } else cout << "dangerous" << endl;

  return 0;

}



Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int a[40] = {1,2,3,4,5,6,7,8,9,10,12,14,15,16,18,20,21,24,25,27,28,30,32,35,36,40,42,45,48,49,54,56,63,64,72,81};

int main()
{
	int n;
	while(cin >> n){
		int flag = 1;
		for(int i = 0; i < 36; i++){
			if(n == a[i]){
				flag = 0;
				cout << "Yes" << endl;
			}
		}
		if(flag)
			cout << "No" << endl;
	}
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
const long long MOD=1e9+7;
const double PI=3.14159265359;
 
 
 
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int n;
    cin>>n;
    
    //long long w=1e10, v=2e10;
    //cout<<abs(v-w)<<endl;
    
    long long x=0, y=0, t=0;
    for(int i=0; i<n; i++){
        long long xn, yn, tn;
        cin>>tn>>xn>>yn;
        long long ts=abs(yn-y)+abs(xn-x);
        
        if(ts>(tn-t)){
            cout<<"No";
            return 0;
        }
        
        
        
        if(ts%2 != (tn-t)%2){
            cout<<"No";
            return 0;
        }
        x=xn,y=yn,t=tn;
        
        
    }
    cout<<"Yes";
    
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ll long long
#define lld long double
#define MOD 1000000007
#define inf 1000000000000000000ll
#define pii pair<int,int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
ll power(ll x,ll y, ll md=inf){ll res = 1;x%=md;while(y){if(y&1)res = (res*x)%md;x *= x; if(x>=md) x %= md; y >>= 1;}return res;}
 
using namespace std;


#define endl '\n'
#define int ll

signed main() {
	fast;

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

	pii v[200002];
	for(int i=0;i<h;i++) cin>>v[i].f>>v[i].s;

	map<int,int> mp;
	for(int i=1;i<=w;i++) mp[i] = 0;

	map<int,int> mini = {{0,w}};

	for(int i=0;i<h;i++) {
		int l = v[i].f;
		int r = v[i].s;

		auto it = mp.lower_bound(l);
		int mn = inf;

		while(it!=mp.end() && it->f <= r) {
			mn = min(mn, r+1-(it->f)+(it->s));
			auto it1 = it++;
			mini[it1->s]--;
			if(mini[it1->s]==0) mini.erase(it1->s);
			mp.erase(it1);
		}

		if(r+1<=w && mn<inf) {
			if(mp.count(r+1)) {
				if(mp[r+1] > mn) {
					mini[mp[r+1]]--;
					if(mini[mp[r+1]]==0) mini.erase(mp[r+1]);
					mini[mn]++;
					mp[r+1] = mn;
				}
			}
			else {
				mp[r+1] = mn;
				mini[mn]++;
			}
		}

		if(mini.size()) cout<<mini.begin()->f+i+1<<endl;
		else cout<<-1<<endl;

	}
}

Measured memory_bytes: 19240
#include<iostream>
using namespace std;
int main()
{
    int n,i,t,a[1000],q,b,e,k;
    cin>>n;
    for(i=0;i<n;i++)
        cin>>a[i];
    cin>>q;
    for(i=1;i<=q;i++)
        {cin>>b>>e>>k;
        int count=0;
      for(t=b;t<e;t++)
      {

          if(k==a[t])
            count++;
      }
      cout<<count<<endl;
}
return 0;
}




Measured memory_bytes: 3100
#!/usr/local/bin/python3
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n = f()[0]
    a = f()

    mi = sum(a)

    for i in range(n-1):
        if a[i]!=a[i+1]:
            mi = min(mi, abs(sum(a[:i+1])-sum(a[i+1:])))
    
    print(mi)

solve()


Measured memory_bytes: 3060
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define LL_INF 9000000000000000000
#define LL_MINF -9000000000000000000
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int main(){
    int N;
    cin >> N;
    int sum = 0;
    for(int i = 0; i < N; i++){
        int l, r;
        cin >> l >> r;
        sum += r - l + 1;
    }
    cout << sum << endl;
}


Measured memory_bytes: 3636
#include<cstdio>
#include<iostream>
#include<string>
using namespace std;
main(){
  int n,o=0,b1=0,b2=0,b3=0,p[40],i,l=0;
  string str;
  cin >> n;
  p[0]=0;
  while(n>l){
    cin >> str;
    if(str=="HIT"){
      b1++;
      if(b1>1){
	b2++;
	b1=1;
	if(b2>1){
	  b3++;
	  b2=1;
	  if(b3>1){
	    p[l]++;
	    b3=1;
	  }
	}
      }
    }
    if(str=="HOMERUN"){
      p[l]++;
      if(b1==1){
	p[l]++;
	b1=0;
      }
      if(b2==1){
	p[l]++;
	b2=0;
      }
      if(b3==1){
	p[l]++;
	b3=0;
      }
    }
    if(str=="OUT"){
      o++;
      if(o%3==0){
	l++;
	b1=0;
	b2=0;
	b3=0;
	p[l]=0;
      }
    }
  }
  for(i=0;i<l;i++){
    cout << p[i] << endl;
  }
}

Measured memory_bytes: 1208
#include "bits/stdc++.h"
#define all(v) (v).begin(), (v).end()
using namespace std;
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define int long long
#define lson rt << 1, l, mid
#define rson rt << 1 | 1, mid + 1, r
#define lll __int128
#define pii pair<int, int>
#define fi first
#define se second

#define mp make_pair
signed main()
{

	int a[200];
	int ans=1e18;
	int n;cin>>n;
	rep(i,1,n){
		cin>>a[i];
	}
	rep(i,1,100){
		int tmp=0;
		rep(j,1,n){
			tmp += (a[j]-i)*(a[j]-i);
		}
		ans=min(ans,tmp);
	}
	cout<<ans<<endl;

		getchar();
	getchar();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef pair<int, int> P;

signed main(){
    int R, W, c, r;
    while(1){
        cin >> R >> W >> c >> r;
        if(R + W + c + r == 0) break;
        for(int i = 0;;i++){
            if(R + r * i >= c * W){
                cout << i << endl;
                break;
            }
        }
    }
}

Measured memory_bytes: 3092
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]A - Lucky 7
            var N = Console.ReadLine();

            if (N.Contains('7'))
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}

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

main()
{
    int n,w;
    cin>>n>>w;
    int dp[n+1][w+1];
    memset(dp,0,sizeof dp);
    vector<int> weight(n+1),values(n+1);
    for(int i=1;i<=n;i++)
    {
        cin>>weight[i]>>values[i];
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=w;j++)
        {
            if(j<weight[i])
            {
                dp[i][j] = dp[i-1][j];   
            }
            else
            {
                dp[i][j] = max(dp[i-1][j],dp[i-1][j-weight[i]]+values[i]);
            }
        }
    }
    cout<<dp[n][w];
}

Measured memory_bytes: 79104
N=int(input())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
C=list(map(int, input().split()))

answer=sum(B)
for i in range(N-1):
    if A[i]+1==A[i+1]:
        answer+=C[A[i]-1]
print(answer)


Measured memory_bytes: 38384
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = nextInt(scanner);
        long[] a = new long[n];
        long p = 1;
        boolean isZero = false;
        for (int i = 0; i < n; i++) {
            a[i] = Long.parseLong(scanner.next());
            if (a[i] == 0) {
                isZero = true;
            }
        }
        if (isZero) {
            System.out.println(0);
            return;
        }
        try {
            for (int i = 0; i < n; i++) {
                p = Math.multiplyExact(p, a[i]);
            }
        }catch (Exception e) {
            System.out.println(-1);
            return;
        }
        if (p > 1000000000000000000L) {
            System.out.println(-1);
            return;
        }
        System.out.println(p);


    }

    public static int nextInt(Scanner scanner) {
        return Integer.parseInt(scanner.next());
    }

}





Measured memory_bytes: 61036
x = int(input())
if x in range(400,600):
    print(8)
elif x in range(600,800):
    print(7)
elif x in range(800,1000):
    print(6)
elif x in range(1000,1200):
    print(5)
elif x in range(1200,1400):
    print(4)
elif x in range(1400,1600):
    print(3)
elif x in range(1600,1800):
    print(2)
elif x in range(1800,2000):
    print(1)
   


Measured memory_bytes: 9160
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++)cin >> a[i];
	sort(a.begin(), a.end());
	cout << abs(a[n - 1] - a[0]) << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, S; cin >> N >> S;
	vector<int> v(N); rep(i, 0, N) { cin >> v[i]; }
	int sum(0);
	int ans(INF);
	int r(0); int l(0);
	while (r < N) {
		while (r < N&&sum < S) {
			sum += v[r++];
		}
		// [l,r)
		if (sum >= S)chmin(ans, r - l);
		while (l < r&&sum >= S) {
			chmin(ans, r - l);
			sum -= v[l++];
		}
	}



	cout << (ans == INF ? 0 : ans) << endl;
	return 0;
}

Measured memory_bytes: 3344
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) *b;
}

struct edge {
	ll ind;
	ll to;
	ll d;
};


///////////////////////////



int main() {

	string s;
	cin >> s;

	rep(i, 5) cout << s[i];
	cout << " ";
	rep(i, 7) cout << s[6 + i];
	cout << " ";
	rep(i, 5)cout << s[14 + i];
	

	system("PAUSE");
}


Measured memory_bytes: 504
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    LL x,y; cin >> x >> y;
    LL ans = 0;

    if(y == 0){
        if(x > 0){
            cout << x+1 << endl;
            return 0;
        }
        else{
            cout << abs(x) << endl;
            return 0;
        }
    }
    //if(x == 0){
    //    cout << abs(y) << endl;
    //    return 0;
    //}
    if(x >= 0 && y >= 0){
        if(y > x){
            cout << y-x << endl;
            return 0;
        }
        else if(y == x){
            cout << 0 << endl;
            return 0;
        }
        else{
            ans = (-y+x)+2;
            cout << ans << endl;
            return 0;
        }
    }
    else if(x >= 0 && y < 0){
        if(x < -y){
            cout << -y-x+1 << endl;
            return 0;
        }
        else if(x == -y){
            cout << 1 << endl;
            return 0;
        }
        else{
            cout << x + y + 1 << endl;
        }
    }
    else if(x < 0 && y >= 0){
        if(-x < y){
            cout << y + x + 1 << endl;
            return 0;
        }
        else if(-x == y){
            cout << 1 << endl;
            return 0;
        }
        else{
            cout << -x-y+1 << endl;
            return 0;
        }
    }
    else{
        if(-x < -y){
            cout << -y - (-x) +2 << endl;
            return 0;
        }
        else if(-x == -y){
            cout << 0 << endl;
        }
        else{
            cout << -x - (-y) << endl;
        }
    }


}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int N,M,A,i,sum;
    sum=0;
    scanf("%d %d",&N,&M);
    for(i=1;i<=M;i++)
    {
        scanf("%d",&A);
        sum=sum+A;
    }
    if(sum<=N)
    {
        printf("%d\n",N-sum);
    }
    else
    {
        printf("-1\n");
    }
    return 0;
}

Measured memory_bytes: 1728
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
int n,w[N],head[N],nxt[N];
void add(int f,int t){
	static int cnt=0;
	w[++cnt]=t;
	nxt[cnt]=head[f];
	head[f]=cnt;
}
//问题等价于给点标号,若k(u)=k(v),则(u,v)路径上存在一点x使得k(x)>k(v) 
//贪心选择最小的标号 
int S[N],ans;
void dfs(int x,int fa){
	int K=0;
	for (int i=head[x];i;i=nxt[i]){
		int v=w[i];
		if (v==fa) continue;
		dfs(v,x);
		for (int i=0;i<20;i++)
		if ((S[x]&S[v])>>i&1) K=max(K,i+1);
		S[x]|=S[v];
	}
	while (S[x]>>K&1) K++;
	ans=max(ans,K);
	S[x]&=~((1<<K)-1);
	S[x]|=(1<<K);
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<n;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		add(u,v);add(v,u);
	}
	dfs(1,0);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 7168
inf = 10**15
mod = 10**9+7
n, k = map(int, input().split())
s = input()
count = 0
flag = False
for c in s:
    if c == 'R':
        if flag == False:
            flag=True
    else:
        if flag == True:
            count+=1
            flag=False
if s[-1]=='R' and count > 0:
    count+=1

if k >= count:
    print(n-1)
elif k == count-1:
    if s[0] == 'R' and s[-1] == 'R':
        print(n-1)
    elif s[0] == 'R' or s[-1] == 'R':
        print(n-2)
    else:
        print(n-3)
else:
    if s[0] == 'R' and s[-1] == 'R':
        print(n - 3 - (count - 2 - k) * 2)
    elif s[0] == 'R' or s[-1] == 'R':
        print(n - 2 - (count - 1 - k) * 2)
    else:
        print(n - 1 - (count - k) * 2)


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

int main() {
  int n;

  cin >> n;

  vector<int> a(n+1);
  vector<int> ans(n+1);

  for(int i = 2; i <= n; i++) 
    cin >> a[i];
  
  for(int i = 2; i <= n; i++)
    ans[a[i]]++;

  for(int i = 1; i<= n; i++)
    cout << ans[i] << endl;

  return 0;
}


Measured memory_bytes: 4780
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
 
#define MOD (long long int)(1e9+7)
#define ll long long int


int main(void){
	
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(a+b<c+d){
		cout<<"Right"<<endl;
	}else if(a+b>c+d){
		cout<<"Left"<<endl;
	}else{
		cout<<"Balanced"<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace         std;
#define                 int long long
#define                 pb push_back
#define                 mp make_pair
#define st(arr,a)       memset(arr,a,sizeof arr)
#define                 nl cout<<endl
#define                 real signed
#define                 endl '\n'              
#define bitcount(x)     __builtin_popcountll(x)
const int MOD = 1000000007ll;
#define forn(i,a,b)     for(int i=a;i<=b;i++)
#define rfor(i,a,b)     for(int i=a;i>=b;i--)
#define all(x)          x.begin() , x.end()
#define pi pair<int,int>
#define X first
#define Y second
#define N 1014159
#define  vi vector<int>
#define  v  vector




signed solve()
{
    int n,d;
    cin>>n>>d;
    int arr[n+10][d+10];
    forn(i,1,n)forn(j,1,d)cin>>arr[i][j];
    int ans = 0;
    forn(i,1,n)forn(j,i+1,n)
    {
        int a = 0;
        forn(k,1,d)
        {
            a+=(arr[i][k] - arr[j][k])*(arr[i][k] - arr[j][k]);
        }
        int x = sqrt(a);
        if(x*x == a)ans++;
    }
    cout<<ans;
}


signed main() 
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); 
    int t = 1;
    //cin>>t;
    while(t--)
    {
        solve();
    }



    return 0;

}

//       g++ -g c.cpp ; ./a.exe

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Linq;
using System.Diagnostics;
using System.Globalization;
using static System.Console;
using static System.Math;


namespace abc95_b
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] input = ReadLine().Split().Select(int.Parse).ToArray();
            int n = input[0];
            int sum = input[1];
            int min=int.MaxValue;
            int count=0;

            for(int i=0; i<n; i++)
            {
                var tmp = int.Parse(ReadLine());
                if(tmp <= min) min=tmp;
                sum -= tmp;
                count++;
            }

            while(min <= sum)
            {
                sum -= min;
                count++;
            }
            WriteLine(count);
        }
    }
}

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

int main() {
  int N;
  cin>>N;
  vector<long>A(N);
  for(int i=0; i<N;i++){
      cin>>A.at(i);  
  }
  vector<long>B(N);
  B.at(0)=0;
  for(int i=1; i<N;i++){
    B.at(i)=2*A.at(i-1)-B.at(i-1);
  }
  long a;
  for(int i=0; i<N;i++){
    a=a+A.at(i)-B.at(i);
  }
  for(int i=0; i<N;i++){
    if(i%2==0){
      B.at(i)+=a;
    }
    else{
      B.at(i)-=a;
    }
  }
  

  for(int i=0; i<N;i++){
    cout<<B.at(i);
    cout<<" ";
  }
  cout<<endl;
}

Measured memory_bytes: 2944
n = input()
n = int(n)
v = list()
k = 0
l = 0
a = input().split()
for i in range(n):
  p = int(a[k])
  v.append(p)
  k += 1
c = list()
b = input().split()
for i in range(n):
  q = int(b[l])
  c.append(q)
  l += 1
u = 0
count = 0
for i in range(n):
  g = v[count]-c[count]
  count += 1
  if g > 0:
    u += g
print(u)
  
  
  

Measured memory_bytes: 3064
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
	   int d = sc.nextInt();
      int cnt1 = 0;
      int cnt2 = 0;
      while(a>0){
         cnt1++;
         a-=d;
      }
      while(c>0){
         cnt2++;
         c-=b;
      }
      if(cnt1>=cnt2){
         System.out.println("Yes");
      }else{
         System.out.println("No");
      }
	}
}


Measured memory_bytes: 35764
//Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define endl '\n'
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
bool sortbysec(const pair<ll,ll>&a,const pair<ll,ll>&b)
{
    return (a.second<b.second);
}

int main()
{
    ios;
    string s,t;
    cin>>s>>t;
    int k=t.size();
        int mn=k;
    for(int i=0;i<s.size()-k+1;i++)
    {
        int cnt=0;
        string m="";
        for(int j=i;s[j];j++)
        {

            m+=s[j];
            cnt++;
            if(cnt==k)
                break;
        }
        int c=0;
       for(int l=0;t[l];l++)
       {
           if(m[l]!=t[l])
            c++;
       }
       mn=min(mn,c);
    }
    cout<<mn<<endl;
}



Measured memory_bytes: 3640
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = long long;
using PAIR = pair<int64, int64>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 3e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<endl;
#define zero(n) cout<<setfill('0')<<right<<setw(n)
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)
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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

signed main() {
  INIT;
  VAR(int, n,a,b,c,d);
  VAR(string,s);

  if (n==4) {
    OUT("Yes")BR;
    //return 0;
  }

  bool ok = true;
  REP(i,n-1){
    if (i<min(a,b)-1) continue;
    if (i>max(c,d)-1) continue;
    ok &= (!(s[i]=='#' && s[i+1]=='#'));
  }

  if((b-a)*(d-c) < 0) {
    bool triple = false;
    REP(i,n-2){
      if (i<max(a,b)-2) continue;
      if (i>min(c,d)-2) continue;
      triple |= (s[i]=='.' && s[i+1]=='.' && s[i+2]=='.');
    }
    ok &= triple;
  }

  OUT(ok?"Yes":"No")BR;
  
  return 0;
}


Measured memory_bytes: 592
from collections import deque

N = int(input())
ans = 0
q = deque([7, 5, 3])

while q:
    s = q.pop()
    str_s = str(s)
    ok = True
    ok &= "7" in str_s
    ok &= "5" in str_s
    ok &= "3" in str_s
    ok &= s <= N
    if ok:
        ans += 1
    if len(str_s) < 9:
        q.append(10*s + 3)
        q.append(10*s + 5)
        q.append(10*s + 7)

print(ans)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template < typename T > string tost( const T& n ) { ostringstream stm; stm << n; return stm.str();}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
int const INF = 1001001001;


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

int N;
cin >> N;
vi A(N);
rep(i,N) cin >> A[i];
int cnt = 0;
rep(i,N) if(A[i] % 2 == 1) cnt++;
if(cnt % 2 == 0) cout << "YES" << endl;
else cout << "NO" << endl;
return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<stack>
#include<queue>
#include<cstdlib>
#include<string>
#include<unordered_map>
#include<vector>
#include<list>
#include<map>
#include<set>
#define fi first
#define se second
#define pb push_back
#define me(a,b) memset(a,b,sizeof(a))
#define INIT() std::ios::sync_with_stdio(false)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int>P;
const int MAX_N=200000+5;
const int MAX_M=100000+5;
const int INF=0x7fffffff;
const int inf=1000000000;
const double EPS=1e-6;
const ull base=123;
const ll mod=1e9+7;
const double pi=4*atan(1.0);
int main()
{
    int n;
    cin>>n;
    if(n>=30)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}


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

int main(){
	int n;
	cin>>n;
	
	int ans = n %10;
	
	if(ans == 2|| ans==4||ans==5||ans==7|| ans ==9){
		cout<<"hon";
	}else if(ans == 0||ans ==1||ans==6||ans==8){
		cout<<"pon";
	}else 
		cout<<"bon";
	}
 


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<algorithm>
#include<set>
#include<queue>
#include<stack>
#include<list>
#include<iostream>
#include<fstream>
#include<numeric>
#include<string>
#include<vector>
#include<cstring>
#include<map>
#include<iterator>

using namespace std;
#define EPS 1e-9
#define MAX 505
#define pb push_back
#define mp make_pair
#define ins insert
#define fi first
#define se second
#define pi acos(-1.0)
#define mod 100000007
#define inf 2147483647
#define ll long long int
#define sss stringstream
#define oss ostringstream
#define iss istringstream
#define llu long long unsigned

#define _sq(a) (a)*(a)
#define sz(a) ((int)a.size())
#define gcd(a,b)    __gcd(a,b)
#define lcm(a,b) ((a)*((b)/gcd(a,b)))
#define _max3(a,b,c) max(a, max(b,c))
#define _min3(a,b,c) min(a, min(b,c))
#define FOR(i, n) for(i=0; i<(int)n; i++)
#define FOR1(i, n) for(i=1; i<=(int)n; i++)
#define mem(a) memset(a, 0, sizeof(a))
#define _set(a) memset(a,-1,sizeof(a))
#define FORI(i, a, b) for(i=a; i>=(int)b; i--)
#define FORab(i, a, b) for(i=a; i<=(int)b; i++)
#define popcount(n) __builtin_popcount(n)
#define popcountl(n) __builtin_popcountll(n)
#define sort_rev(a) sort(a.rbegin(), a.rend())
#define sort_all(a) sort(a.begin(), a.end())
#define dis_twopoints(x1,y1,x2,y2) sqrt(_sq(x1-x2) + _sq(y1-y2))
#define foreach(i,n) for(__typeof((n).begin())i =(n).begin();i!=(n).end();i++)

//If Long Long (mask & (1LL << k))
#define check(mask, k) (mask & (1 << k))
#define set1(mask, k) (mask | (1 << k))
#define set0(mask ,k) (mask & (~(1<<k)))

#define SD(a) scanf("%d",&a)
#define SLF(a) scanf("%lf",&a)
#define SC(a) scanf("%c",&a)
#define SS(a) scanf("%s",a)
#define SLLD(a) scanf("%lld", &a)
#define Si64(a) scanf("%I64d", &a)

#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
int main()
{
    unsigned long long int a,b,n,t,r,gcd,lcm;
    while(cin>>a>>b)
    {
        r=1;
        n=a*b;
        if(b>a)
        {
            t=a;
            a=b;
            b=t;
        }
        while(r!=0)
        {
            r=a%b;
            a=b;
            b=r;
            gcd=a;
        }
        if(a==b)
        {
            gcd=a;
        }
        lcm=n/gcd;
        cout<<gcd<<" "<<lcm<<endl;
    }
    return 0;
}

Measured memory_bytes: 1152
#include <math.h>
#include <bits/stdc++.h>
#include <deque>
#include <string>
#include <vector>
#include <algorithm>
#define ll long long int
#define l long double
#define pi 3.14159265358979323846
#define mod 1000000007
#define vali 1000000000000000000
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    ll s=n%1000;
    if(s==0)
    cout<<"0"<<endl;
    else
    {
        ll s1=n/1000+1;
        cout<<1000*s1-n<<endl;
    }
}

Measured memory_bytes: 3624
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp15
{
    class Class40
    {
        static void Main()
        {
            var hw = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int h = hw[0], w = hw[1];
            string[] s = new string[h];
            string top = "";
            for (int i = 0; i < w + 2; i++) top += "#";

            for(int i = 0; i < h; i++)
            {
                s[i] = Console.ReadLine();
                s[i] += "#";
                s[i] = s[i].Insert(0, "#");
            }

            Console.WriteLine(top);
            for (int i = 0; i < h; i++)
                Console.WriteLine(s[i]);
            Console.WriteLine(top);
        }
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int main () {
	int n, m, x;
	cin >> n >> m >> x;
	int grid[n][m];
	int cost[n];
	int ans = 1000000000;
	for(int i = 0; i < n; i++) {
		cin >> cost[i];
		for(int j = 0; j < m; j++) {
			cin >> grid[i][j];
		}
	}
	for(int i = 1; i < (1 << n); i++) {
		int temp[m];
		for(int j = 0; j < m; j++) temp[j] = 0;
		int cst = 0;
		for(int j = 0; j < n; j++) {
			if(i & (1 << j)) {
				cst += cost[j];
				for(int k = 0; k < m; k++) temp[k] += grid[j][k];
			}
		}
		bool flag = true;
		for(int j = 0; j < m; j++) {
			if(temp[j] < x) flag = false;
		}
		if(flag) {
			ans = min(ans, cst);
		}
	}
	if(ans == 1000000000) cout << "-1" << "\n";
	else cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 3184
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define loop3(i,j,k,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)
#define loop4(i,j,k,l,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)for(int l=0; l<a; l++)if(i!=l&&j!=l&&k!=l)
#define rep1(i,a) for(int i=1; i<=a; i++)

#define scnd1(a) scanf("%d", &a)
#define scnd2(a,b) scanf("%d%d", &a,&b)
#define scnd3(a,b,c) scanf("%d%d%d", &a,&b,&c)
#define scnd4(a,b,c,d) scanf("%d%d%d%d", &a,&b,&c,&d)

#define cin1(a) cin >> a;
#define cin2(a,b) cin >> a >> b;
#define cin3(a,b,c) cin >> a >> b >> c;
#define cin4(a,b,c,d) cin >> a >> b >> c >> d;
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define prtd1(a) printf("%d\n", a)
#define prtd2(a,b) printf("%d %d\n", a,b)
#define prtd3(a,b,c) printf("%d %d %d\n", a,b,c)
#define prtd4(a,b,c,d) printf("%d %d %d %d\n", a,b,c,d)

#define mem(a,n) memset( a, n, sizeof(a))
#define INF 1000000000
typedef long long ll;

vector<ll> A, B, C;

int main() {
    int N;
    cin >> N;
    
    ll x;
    rep(i,N){ cin >> x; A.push_back(x);}
    rep(i,N){ cin >> x; B.push_back(x);}
    rep(i,N){ cin >> x; C.push_back(x);}
    
    sort(A.begin(),A.end());
    sort(B.begin(),B.end());
    sort(C.begin(),C.end());
    
    ll ans=0;
    rep(i,N){
        ans += (lower_bound(A.begin(),A.end(),B[i])-A.begin()) * (N-(upper_bound(C.begin(),C.end(),B[i])-C.begin()));
    }
    
    cout1(ans);
    
}

Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define reg(i,a,b) for(int i=a;i<=b;i++)
#define reh(i,a,b) for(int i=a;i>b;i--)
#define in(x) scanf("%d",&x)
#define fro freopen("D:\\testdata.in", "r", stdin)
#define il inline
#define lson(q) q<<1
#define rson(q) q<<1|1
using namespace std;
typedef long long ll;
const int mx=1e5+10;


int main(){
	int a;
	cin>>a;
	cout<<3*a*a<<endl; 
	
	return 0;
}




Measured memory_bytes: 256
n=int(input())
p=tuple(map(int,input().split()))
q=tuple(map(int,input().split()))
import itertools
s=tuple([i+1 for i in range(n)])
a=list(itertools.permutations(s))

x=a.index(p)
y=a.index(q)
print(abs(x-y))


Measured memory_bytes: 8052
#include<stdio.h>
#include<stdlib.h>

typedef struct{
  char mark;
  int num;
}Card;

void BubbleSort(Card [], int);
void SelectionSort(Card [], int);
int compareArray(Card **, Card [], int [], int, int);
void printResult(Card [], Card [], int, int, int);

int main(){
  int n, pair=0;
  Card *A, *B;
  Card **order;
  int *idxnum;
  int number[9]={0};
  int Astable, Bstable;
  int ind, ex;
  int i, j;

  scanf("%d",&n);

  A = (Card *)malloc(n*sizeof(Card));
  B = (Card *)malloc(n*sizeof(Card));
 
  for(i=0; i<n; i++){
    scanf(" %c%d",&A[i].mark ,&A[i].num);
    B[i] = A[i];
    number[A[i].num - 1]++;
  }

  for(i=0; i<9; i++){
    if(number[i]>=2)
      pair++;
  }

  order = (Card **)malloc(pair*sizeof(Card *));
  idxnum = (int *)malloc(pair*sizeof(int));

  ind = 0;
  for(i=0; i<9; i++){
    if(number[i]>=2){
      order[ind] = (Card *)malloc(number[i]*sizeof(Card));

      ex = 0;
      for(j=0; j<n; j++){
	if(A[j].num == (i+1)){
	  order[ind][ex] = A[j];
	  ex++;
	}
      }
      idxnum[ind] = ex;
      ind++;
    }

    if(ind>=pair)
      break;
  }
  
  BubbleSort(A,n);
  SelectionSort(B,n);

  Astable = compareArray(order, A, idxnum, pair, n);
  Bstable = compareArray(order, B, idxnum, pair, n);
 
  printResult(A,B,n,Astable,Bstable);
  
  free(A);
  free(B);
  for(i=0; i<pair; i++)
    free(order[i]);
  free(order);
  free(idxnum);
  return 0;
}

void BubbleSort(Card C[], int n){
  Card tmp;
  int i, j;

  for(i=0; i<n; i++){
    for(j=n-1; j>i; j--){
      if(C[j].num < C[j-1].num){
	tmp = C[j];
	C[j] = C[j-1];
	C[j-1] = tmp;
      }
    }
  }
}

void SelectionSort(Card C[], int n){
  int minj;
  Card tmp;
  int i, j;

  for(i=0; i<n; i++){
    minj = i;

    for(j=i; j<n; j++){
      if(C[j].num < C[minj].num)
	minj = j;
    }

    tmp = C[i];
    C[i] = C[minj];
    C[minj] = tmp;
  }
}

int compareArray(Card **order, Card C[], int idx[], int pair, int n){
  int i, j, k;
  int cnt=0;

  for(i=0; i<n; i++){
    for(j=0; j<pair; j++){
      if(order[j][0].num == C[i].num){
	for(k=0; k<idx[j]; k++){
	  if(order[j][k].mark != C[i++].mark)
	    return 0;
	}
      }
    }
  }

  return 1;
}

void printResult(Card A[], Card B[], int n, int Astable, int Bstable){
  int i;
  
  for(i=0; i<n; i++){
    printf("%c%d",A[i].mark ,A[i].num);
    if(i<n-1)
      printf(" ");
  }
  printf("\n");

  if(Astable==1)
    printf("Stable\n");
  else
    printf("Not stable\n");
  
  for(i=0; i<n; i++){
    printf("%c%d",B[i].mark ,B[i].num);
    if(i<n-1)
      printf(" ");
  }
  printf("\n");

  if(Bstable==1)
    printf("Stable\n");
  else
    printf("Not stable\n");
}



Measured memory_bytes: 2124
{-# LANGUAGE BangPatterns #-}

import qualified Data.Vector.Unboxed as V
import Data.Array.IArray (listArray, accumArray, (!))
import Data.Array.MArray
import Data.Array.ST (STUArray, runSTUArray)
import Data.Array.Unboxed (UArray)
import Data.List (sortOn, sortBy, unfoldr, partition,minimumBy)
import Data.Char (isSpace)
import Control.Monad.ST (ST)
import Control.Monad.Trans.State (StateT(..))
import Control.Arrow ((***))
import qualified Data.ByteString.Char8 as B

import Debug.Trace (trace)

-- utility functions

tr x = trace (show x) x

--   Input functions
readInt = B.readInt . B.dropWhile isSpace

readInts :: Int -> B.ByteString -> [Int]
readInts n = take n . unfoldr readInt

readIntsV :: Int -> B.ByteString -> V.Vector Int
readIntsV n = V.unfoldrN n readInt

readIntsA :: Int -> B.ByteString -> UArray Int Int
readIntsA n bs = runSTUArray $ do
  arr <- newArray_ (0,n-1)
  go arr 0 bs
  return arr
  where
    go :: STUArray s Int Int -> Int -> B.ByteString -> ST s ()
    go arr i bs
      | i==n = return ()
      | otherwise = do
        let Just (x,bs') = readInt bs
        writeArray arr i x
        go arr (i+1) bs'

readTsV :: Int -> B.ByteString -> V.Vector (Int,Int)
readTsV n = V.unfoldrN n $ runStateT ((,) <$> StateT readInt <*> StateT readInt)

readTs :: Int -> B.ByteString -> [(Int,Int)]
readTs n = take n . unfoldr readT where
  readT = runStateT ((,) <$> StateT readInt <*> StateT readInt)

-- main

calcSum ts = go ts 1 where
  go [] _ = []
  go ((p,c):ts) i = (p, i*p + (c`div`100)) : go ts (i+1)

inf = 10^10

minimumOn p = minimumBy f where
  f x y = p x `compare` p y

solv ts g = minimum.map fst.filter ((>=g).snd) $ go ts 1 where
  go [] _ = [(0,0)]
  go ((p,s):ts) i = concat [solveAll, solveSome, solveNothing]
    where
      solveAll = ((+p) *** (+s)) <$> go ts (i+1)
      solveSome :: [(Int,Int)]
      solveSome = solveSome' i <$> go ts (i+1)
      solveSome' i (num, point)
        | point >= g = (inf,0)
        | p>=need = (num+need, point+i*need)
        | otherwise = (inf, 0)
        where need = (g-point+(i-1)) `div` i
      solveNothing = go ts (i+1)

main = do
  [d,g] <- map read . words <$> getLine
  ts <- readTs d <$> B.getContents
  print $ solv (calcSum ts) (g`div`100)


Measured memory_bytes: 4604
import java.util.Scanner;
public class Main {
	public static void main(String[]args) {
		Scanner teclado = new Scanner (System.in);
		int a;
		int b;
		a=teclado.nextInt();
		b=teclado.nextInt();
		
		
		if(((a*2)-1) > a+b &&  (((a*2)-1)) > ((b*2)-1) ){
			System.out.println((a*2)-1);
		}else if(((b*2)-1) > a+b && ((b*2)-1) >((a*2)-1) ) {
			System.out.println((b*2)-1);			
		}else {
			System.out.println(a+b);
		}
	}
	
}


Measured memory_bytes: 20948
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll          long long
#define pb          push_back
#define INF         9223372036854775807
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define lower(u)    transform(u.begin(), u.end(), u.begin(), ::tolower);//convert string u to lowercase;
#define upper(u)    transform(u.begin(), u.end(), u.begin(), ::toupper);
using namespace std;

using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define N  100005

void solve()
{
    double a,b,h,m;
    cin>>a>>b>>h>>m;
    double pi=2;
    pi=pi*acos(-1.0);
    
    // pi=pi*2.0;
    // cout<<pi<<endl;
    h=h/((double)12.0);
    m=m/((double)60.0);
    h+=m/12;
    double theta=(h-m)*pi;
    // cout<<theta<<endl;
    double c=a*a+b*b-2.0*a*b*cos(theta);
    c=sqrt(c);
    cout<<setprecision(12)<<c<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 4112
import Data.List
import Control.Monad

main :: IO ()
main = do
 n <- map read . words <$> getLine :: IO [Int]
 as <- map read . words <$> getLine :: IO [Int]
 
 forM_ (map snd $ sortOn fst $ zip as [1..length as]) $ \a -> putStr ((show a) ++ " ")

Measured memory_bytes: 48508
import java.util.*;

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

    public static void main(String[]$) {
        int n = scanner.nextInt();
        int[] t = new int[n + 1];
        for (int i = 0; i < n; i++)
            t[i + 1] = t[i] + scanner.nextInt() * 2;
        int[] s = new int[t[n] + 2];
        for (int i = 0; i < n; i++)
            Arrays.fill(s, t[i] + 1, t[i + 1] + 1, scanner.nextInt() * 2);
        for (int i = 0; i <= t[n]; i++)
            s[i + 1] = Math.min(s[i + 1], s[i] + 1);
        for (int i = t[n]; i >= 0; i--)
            s[i] = Math.min(s[i], s[i + 1] + 1);
        double ans = 0;
        for (int i = 0; i <= t[n]; i++)
            ans += Math.min(s[i], s[i + 1]) + Integer.compare(s[i + 1], s[i]) / 2d;
        System.out.println(ans / 4);
    }
}

Measured memory_bytes: 22100
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>

int a, b, c;

int main()
{
    std::ios::sync_with_stdio(0);
    std::cin.tie(0);
    std::cin >> a >> b >> c;
    std::cout << std::min(b / a, c) << "\n";
    return 0;
}

Measured memory_bytes: 256
//author : Himanshu Shukla
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ll long long
#define ln "\n"
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); }
ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }

const ll MOD = 1e9 + 7;

struct Job
{
	int deadline, duration, idx;

	bool operator<(Job o) const
	{
		return deadline < o.deadline;
	}
};

int func(vector<Job> jobs)
{
	sort(jobs.begin(), jobs.end());

	set<pair<int, int>> s;
	vector<int> schedule;
	for (int i = jobs.size() - 1; i >= 0; i--)
	{
		int t = jobs[i].deadline - (i ? jobs[i - 1].deadline : 0);
		s.insert(make_pair(jobs[i].duration, jobs[i].idx));
		while (t && !s.empty())
		{
			auto it = s.begin();
			if (it->first <= t)
			{
				t -= it->first;
				schedule.push_back(it->second);
			}
			else
			{
				s.insert(make_pair(it->first - t, it->second));
				t = 0;
			}
			s.erase(it);
		}
	}
	return schedule.size();
}

vector<Job> arr;

int main()
{
	FASTIO;
	int n;
	cin >> n;
	Job j;
	int dur, dead;
	for (int i = 0; i < n; i++)
	{
		cin >> dur >> dead;
		j.deadline = dead;
		j.duration = dur;
		j.idx = i;
		arr.push_back(j);
	}
	int numb = func(arr);
	if (numb == n)
		cout << "Yes" << ln;
	else
		cout << "No" << ln;
	return 0;
}


Measured memory_bytes: 11376