akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int a[n];
  vector<int> b(n);
  long long int ans = 0;
  int cnt = 0;
  for(int i = 0;i < n;i++){
    cin >> a[i];
    if(a[i] < 0)cnt++;
    b[i] = abs(a[i]);
    ans += b[i];
  }
  sort(b.begin(),b.end());
  if(cnt % 2 == 1)ans -= 2*b[0];
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include<stdio.h>
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
int main(){
	int n;
	scanf("%d",&n);
	int M=-1e8,m=1e8;
	long s=0;
	while(n--){
		int t;
		scanf("%d",&t);
		M=max(M,t);
		m=min(m,t);
		s+=t;
	}
	printf("%d %d %ld\n",m,M,s);
}


Measured memory_bytes: 2112
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <cassert>
#include <numeric>
#include <string>
#include <cstring>
#include <cmath>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long int int64;

int DX[4] = {-1, 0, 0, 1};
int DY[4] = {0, -1, 1, 0};

const int N = 1005;
char f[N][N];

int dist[N][N];

    
int n, m;
bool inF(int x, int y)
{
    return x >= 0 && x < n && y >= 0 && y < m;
}

int main(int,  char **)
{
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif


    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; i++)
        scanf("%s", f[i]);

    memset(dist, -1, sizeof dist);
    vector <pair <int, int>> qu;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
            if (f[i][j] == '#')
            {
                dist[i][j] = 0;
                qu.emplace_back(i, j);
            }
    for (int i = 0; i < (int) qu.size(); i++)
    {
        int x = qu[i].first, y = qu[i].second;
        for (int d = 0; d < 4; d++)
        {
            int nx = x + DX[d], ny = y + DY[d];
            if (!inF(nx, ny) || dist[nx][ny] != -1) continue;
            dist[nx][ny] = dist[x][y] + 1;
            qu.emplace_back(nx, ny);
        }
    }
    int ans = -1;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
            ans = max(ans, dist[i][j]);
    printf("%d\n", ans);


	return 0;
}




Measured memory_bytes: 15468
def main():
  
  f = "" # 前回のステップの文字 "<" or ">" 
  ans = 0 # Answer
  count = 0 # Ai
  continuous = 0 # ">" が何回連続するか
  
  for m in input():
    if m=="<":
      if f==">" and count>0:
        # 清算
        ans-=count*continuous
        count=0
      count+=1
        
    else:
      if f=="<":
        # セット
        continuous=0
      count-=1
      continuous+=1
      if count==-1:
        ans+=continuous
        count=0
        continue

    ans+=count
    f=m

  print(ans)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 4116
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using boost::multiprecision::cpp_int;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, int> pii;

const ll INF = LLONG_MAX;
const ll MOD = 1e9+7;

// https://math.nakaken88.com/textbook/cp-binary-exponentiation-and-recursive-function/
ll modPow(ll a, ll n, int P) {
  if (n == 1) return a % P;
  if (n % 2 == 1) return (a * modPow(a, n - 1, P)) % P;
  ll t = modPow(a, n / 2, P);
  return (t * t) % P;
}

int main() {
    // input, ready
    int S,W;
    cin >> S >> W;
    // resolve

    // output
    if (S <=W) cout << "unsafe" << endl;
    else cout << "safe" << endl;

    return 0;
}


Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int[] ans = new int[1001];
		for (int i = 1; i < 1000; ++i) {
			int sum = i;
			for (int j = i + 1;; ++j) {
				sum += j;
				if (sum > 1000) break;
				ans[sum]++;
			}
		}
		while (true) {
			int N = sc.nextInt();
			if (N == 0) break;
			System.out.println(ans[N]);
		}
	}
}

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

ll pow(int n) {
    ll ans = 1;
    rep(i,n) ans *= 2;
    return ans;
}

int main() {
    ll H; cin >> H;
    ll count = 0;
    while(H != 1) {
        if(H%2 != 0) {
            H--;
            H /= 2;
            count++;
        } else {
            H /= 2;
            count++;
        }
        //cout << H << endl;
    }
    //cout << count << endl;
    cout << pow(count+1)-1 << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<string>
#include<stack>
#include<algorithm>
#include<cstdio>
#include<map>
#include<cmath>
#include<queue>
#include<iomanip>
#include<cstring>
#include<list>
#include<typeinfo>
#include<vector>

using namespace std;

struct point
{
    int x;int y;
}a[20];

struct vectors
{
    int a;int b;
}vec[1000];

int m;
int vis[20];
int maxn,cnt;

void judge()
{
    int ans = 0;
    for(int i=0;i<cnt;i++)
    {
        for(int j=i+1;j<cnt;j++)
        {
            if(vec[i].a*vec[j].b==vec[j].a*vec[i].b)
                ans++;
        }
    }
    maxn=max(maxn,ans);
}

void dfs(int temp)
{
    while(vis[temp])
        temp++;
    if(temp>=m)
    {
        judge();
        return;
    }
    vis[temp]=1;
    for(int i=0;i<m;i++)
    {
        if(!vis[i]&&i!=temp)
        {
            vis[i] = 1;
            vec[cnt].a = a[temp].x - a[i].x;
            vec[cnt].b= a[temp].y - a[i].y;
            cnt++;
            dfs(temp+1);
            cnt--;
            vis[i] = 0;
        }
    }
    vis[temp] = 0;
}


int main()
{
    cnt = 0;
    scanf("%d",&m);
    for(int i=0;i<m;i++)
        scanf("%d%d",&a[i].x,&a[i].y);
    maxn = 0;
    dfs(0);
    cout << maxn << endl;
}



Measured memory_bytes: 3240
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <algorithm>
#include <vector>
#include <cstring>
#include <stack>
#include <cctype>
#include <utility>
#include <map>
#include <string>
#include <climits>
#include <set>
#include <sstream>
#include <utility>
#include <ctime>
#include <cassert>
#include <fstream>
using namespace std;
typedef long long LL;
#define MS(A) memset(A, 0, sizeof(A))
#define MSV(A,a) memset(A, a, sizeof(A))
#define MP make_pair
#define PB push_back
#define getcx getchar_unlocked
#define INF (int(1e9))
#define INFL (LL(1e18))
#define EPS 1e-12
#define chkbit(s, b) (s & (1<<b))
#define setbit(s, b) (s |= (1<<b))
#define chk(a) cerr << endl << #a << " : " << a << endl
#define chk2(a,b) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << endl
#define chk3(a,b,c) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << endl
#define chk4(a,b,c,d) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << "\t" << #d << " : " << d << endl
#define rep(i, a, n) for(i=a;i<n;i++)
#define rev(i, a, n) for(i=a;i>=n;i--)
#define rep_itr(itr, c) for(itr = (c).begin(); itr != (c).end(); itr++)
#define MOD 1000000007
#define MAX 100005

int main() {

	int a;
	cin>>a;

	cout<<(a + a*a + a*a*a)<<endl;

	return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define ll long long
#define str string
#define optimizator ios_base::sync_with_stdio(0);
using namespace std;
int main(){
	optimizator;
	int n,m,cnt=0;
	cin>>n>>m;
	int a[n];
	for(int i=0; i<n; i++){
		cin>>a[i];
		if(a[i]>=m)
		{
		cnt++;
		}
	}
	cout<<cnt;
}

Measured memory_bytes: 640
#include<queue>
#include<vector>
#include<utility>
#include<functional>

namespace ProconLib{
    template<class graph_t,typename cost_t,cost_t INF=cost_t(1e15)>
    std::vector<cost_t> Dijkstra(int s,const graph_t& g){
        int n=g.size();
        std::vector<cost_t> res(n,INF);
        std::vector<char> used(n,0);
        res[s]=0;
        std::priority_queue<std::pair<cost_t,int>,std::vector<std::pair<cost_t,int>>,std::greater<>> que;
        que.push(std::make_pair(cost_t(0),s));
        while(!que.empty()){
            auto p=que.top(); que.pop();
            cost_t dist=p.first;
            int v=p.second;
            if(used[v]) continue;
            used[v]=true;
            for(int i=0;i<g[v].size();i++){
                cost_t tdist=dist+g[v][i].weight;
                if(tdist<res[g[v][i].to]){
                    res[g[v][i].to]=tdist;
                    que.push(std::make_pair(tdist,g[v][i].to));
                }
            }
        }
        return res;
    }

    // using Weight=long long;
    // struct Edge{
    //     int to;
    //     Weight weight;
    // };
    // using Edges=vector<Edge>;
    // using Graph=vector<Edges>;
}
// AOJ(ALDS1_12_C)
#include<iostream>
using namespace std;
using namespace ProconLib;
using Weight=long long;
struct Edge{
    int to;
    Weight weight;
};
using Edges=vector<Edge>;
using Graph=vector<Edges>;
int main(){
    int n;
    cin>>n;
    Graph g(n);
    for(int i=0;i<n;i++){
        int u,k;
        cin>>u>>k;
        for(int j=0;j<k;j++){
            Edge e;
            cin>>e.to>>e.weight;
            g[u].push_back(e);
        }
    }
    auto d=Dijkstra<Graph,Weight>(0,g);
    for(int i=0;i<n;i++){
        cout<<i<<" "<<d[i]<<endl;
    }

    return 0;
}



Measured memory_bytes: 11968
// Easy Linear Programming

func main() {
    let abck = readLine()!.split(separator: " ").map{Int($0)!}
    // 1がa枚、０がb枚、-1がc枚ある、k枚選ぶ時の最大値を求める
    let k = abck[3]
    let (a,b,_) = (abck[0], abck[1], abck[2])
    if a >= k {
        print(k)
    } else if a + b >= k {
        print(a)
    } else {
        let result = a - (k - a - b)
        print(result)
    }
}

main()

Measured memory_bytes: 8236
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<long long, long long>;
const long long INF = 1001001001;
const long long MOD = 1000000007;
const double EPS = 1e-10;
struct Edge { int from, to; long long cost; };
using Graph = vector<vector<Edge>>;

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

    int n;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a,a+n,greater<ll>());
    ll ans=0;
    int cnt=1;
    for(int i=0;i<n;i++){
        if(i==0){
            ans+=a[i];
            cnt++;
            if(cnt==n)break;
        }else{
            ans+=a[i];
            cnt++;
            if(cnt==n)break;
            ans+=a[i];
            cnt++;
            if(cnt==n)break;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 5204
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		int a = n / 100;
		int c = n % 10;
		int b = (n - 100 * a - c) / 10;

		if(a == 7 || b == 7 || c == 7) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 35820
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n:String = read();
    let mut sum = 0;
    for c in n.chars() {
        sum += c.to_digit(10).unwrap();
    }
    if sum  % 9 == 0 {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 2308
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;

int add (string a, string b)
{
	reverse (a.begin(), a.end() );
	reverse (b.begin(), b.end() );

	while (a.length() != b.length()){
		if (a.length() > b.length()){
			b += '0';
		}else if (a.length() < b.length() ){
			a += '0';
		} // end if
	} // end while

	int i;
	string res = "";
	int carry = 0;

	for (i = 0; i < a.length(); ++i){
		int an = a[i] - '0';
		int bn = b[i] - '0';
		if (carry == 1){
			++an;
		} // end if
		if (an + bn >= 10){
			carry = 1;
		}else{
			carry = 0;
		} // end if
		res += ((an + bn) % 10) + '0';
	} // end for

	if (carry == 1){
		res += carry + '0';
	} // end if
/*
	reverse (res.begin(), res.end() );
	cout << res << endl;
*/	
	return res.length();
}

int main()
{
//	cut here before submit 
//	freopen("testcase.add", "r", stdin);
	string str = "";
	string a,b;

	while (getline (cin, str )){
		stringstream ssn(str);
		ssn >> a >> b;
		int res = add (a,b);
		cout << res << endl;	
	} // end while
		
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<vector>
#include<math.h>
#include<algorithm>
#include<stdio.h>

using namespace std;

int factorial(int n){
    if(n == 1) return 1;
    return n * factorial(n-1);
}

int main(void){
    int n; cin >> n;
    vector<int> x(n);
    vector<int> y(n);

    vector<vector<double>> dp(n, vector<double>(n));

    vector<int> a(n);
    for(int i = 0;i < n;i++) a[i] = i+1;

    double ans = 0;

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

    do{
        for(int i = 0;i < n-1;i++){
            //cout << "i:" << i << " a[i]:" << a[i] << " a[i+1]:" << a[i+1] << endl;
            if(dp[a[i]-1][a[i+1]-1] == 0){
                double temp = 1;
                temp = sqrt(pow(x[a[i]-1] - x[a[i+1]-1], 2) + pow(y[a[i]-1] - y[a[i+1]-1], 2));
                dp[a[i]-1][a[i+1]-1] = temp;
                //cout << "temp:" << temp << endl;
            }
            
            ans += dp[a[i]-1][a[i+1]-1];
            
        }
    }while(next_permutation(a.begin(), a.end()));

    //cout << ans << endl;
    printf("%.10lf\n", ans/factorial(n));

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
ll n,c,i,x[101010],v[101010],tem,ma1[101010],ma2[101010],has;
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>c;
	for(i=1;i<=n;i++)
		cin>>x[i]>>v[i];
	for(i=1;i<=n;i++)
	{
		tem+=v[i];
		ma1[i]=max(ma1[i-1],tem-x[i]);
		has=max(has,ma1[i]);
	}
	tem=0;
	for(i=n;i>=1;i--)
	{
		tem+=v[i];
		ma2[i]=max(ma2[i+1],tem-(c-x[i]));
		has=max(has,ma2[i]);
	}
	for(i=1;i<n;i++)
	{
		has=max(has,ma1[i]+ma2[i+1]-x[i]);
	}
	for(i=n;i>=2;i--)
	{
		has=max(has,ma2[i]+ma1[i-1]-(c-x[i]));
	}
	cout<<has<<"\n";
}

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

int main(){
    int n;
    cin >> n;
    int odd[1000000];
    int even[1000000];
    for(int i=0;i<1000000;i++){
        odd[i] = 0;
        even[i] = 0;
    }
    for(int i=0;i<n/2;i++){
        int tmp1,tmp2;
        cin >> tmp1 >> tmp2;
        odd[tmp1]++;
        even[tmp2]++;
    }
    int max_odd=0,smax_odd =0,max_even = 0,smax_even = 0;
    int i_odd,si_odd,i_even,si_even;
    for(int i=1;i<100001;i++){
        if(max_odd <= odd[i]){
            smax_odd = max_odd;
            max_odd = odd[i];
            i_odd = i;
        }
        else if(smax_odd <= odd[i]){
            smax_odd = odd[i];
        }
        if(max_even <= even[i]){
            smax_even = max_even;
            max_even = even[i];
            i_even = i;
        }
        else if(smax_even <= even[i]){
            smax_even = even[i];
        }
    }
    if(i_odd == i_even){
        if(max_odd+smax_even <= max_even+smax_odd){
            max_odd = smax_odd;
        }
        else{
            max_even = smax_even;
            
        }
    }

    cout << n-max_even - max_odd << endl;
    return 0;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);

int main(int argc, char* argv[])
{
  int n, k;
  cin >> n >> k;
  vector<ll> v(n);
  rep(i, n) cin >> v[i];

  ll ans = 0;
  for (int l = 0; l <= k; l++) {
    if (l > n) continue;
    for (int r = 0; r <= k-l; r++) {
      if (l + r > n) continue;
      ll sum = 0;
      vector<ll> minus; minus.reserve(n);
      // 価値を求める
      for (int a = 0; a < l; a++) {
        sum += v[a];
        if (v[a] < 0) minus.push_back(v[a]);
      }
      for (int a = 0; a < r; a++) {
        sum += v[n-1-a];
        if (v[n-1-a] < 0) minus.push_back(v[n-1-a]);
      }

      // 価値がマイナスのものを，価値が低い順に最大で k - (l+r) 回捨てる
      sort(ALL(minus));
      for (int a = 0; a <k-(l+r); a++) {
        if (a >= minus.size()) break;
        sum -= minus[a];
      }
      chmax(ans, sum);
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
A, B, C = map(int, input().split())
tmpA, tmpB, tmpC = A, B, C

ans = 0
while tmpA%2 == 0 and tmpB%2 == 0 and tmpC%2 == 0:
    ans += 1
    nxtA = (tmpB + tmpC) // 2
    nxtB = (tmpA + tmpC) // 2
    nxtC = (tmpA + tmpB) // 2
    tmpA, tmpB, tmpC = nxtA, nxtB, nxtC
    if nxtA == A and nxtB == B and nxtC == C:
        ans = -1
        break

print(ans)


Measured memory_bytes: 3060
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

#include <bits/stdc++.h>

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;

const int MXN = 2e5, IINF = 1e9 + 10, INF = 1e18 + IINF + 10, MOD = 1000000007;
const ld PI = 4.0 * atanl(1.0), PREC = .000001;
const char nl = '\n';

#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto& a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define rall(x) x.end(), x.begin()
#define lb lower_bound
#define ub upper_bound
#define sz(x) (int)(x).size()
#define ins insert

int n, m, t, a[MXN];

void fast() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); }

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

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

int main() {
  fast();
  int a, b, c, x;
  int ans = 0;
  cin >> a >> b >> c >> x;
  for (int i = 0; i <= a; ++i) {
    for (int j = 0; j <= b; ++j) {
      for (int k = 0; k <= c; ++k) {
        if ((i * 500) + (j * 100) + (k * 50) == x) ++ans;
      }
    }
  }
  cout << ans;

  return 0;
}



Measured memory_bytes: 3644
import java.util.*;
import java.io.*;
public class Main {

	static Scanner inp= new Scanner(System.in);
	static PrintWriter out= new PrintWriter(System.out);
	public static void main(String args[]) {		    	
	   	Main g=new Main();
	   	g.main();
	   	out.close();
	}

	boolean vis[];
	int n;
	ArrayList<Integer> list[];
	
	//Main
	void main() {
		
		n=inp.nextInt();
		list=new ArrayList[n];
		vis=new boolean[n];
		for(int i=0;i<n;i++) {
			list[i]=new ArrayList<Integer>();
		}
		int m=inp.nextInt();
		while(m-->0) {
			int x=inp.nextInt()-1;
			int y=inp.nextInt()-1;
			list[x].add(y);
			list[y].add(x);
		}
		int gg=0;
		for(int i=0;i<n;i++) {
			if(!vis[i]) {
				gg=Math.max(gg,dfs(i));
			}
		}
		System.out.println(gg);
	}
    
    int dfs(int i) {
    	vis[i]=true;
    	int c=0;
    	for(int x: list[i]) {
    		if(!vis[x]) c+=dfs(x);
    	}
    	return c+1;
    }
		
}


Measured memory_bytes: 109780
import java.util.Scanner;

public class Main {

	static int coinCount;
	static double[] coinProbabilityArray;
	static double[][] dp;

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		coinCount = scan.nextInt();
		coinProbabilityArray = new double[coinCount];

		for (int i = 0; i < coinCount; i++) {

			coinProbabilityArray[i] = scan.nextDouble();
		}

		dp = new double[coinCount + 1][coinCount + 1];

		for (int i = 0; i < coinCount + 1; i++) {

			for (int j = 0; j < coinCount + 1; j++) {

				dp[i][j] = dpMethod(i, j);
			}
		}

		double answer = 0;

		for (int i = coinCount; coinCount / 2 < i; i--) {

			answer += dp[i][coinCount - i];
		}

		println(answer);

	}

	public static double dpMethod(int i, int j) {

		if (coinCount - 1 < i + j - 1) {
			return 0;
		}

		if (i == 0 && j == 0) {

			return 1;
		}

		if (i == 0) {

			return dp[i][j - 1] * back(coinProbabilityArray[i + j - 1]);

		} else if (j == 0) {

			return dp[i - 1][j] * coinProbabilityArray[i + j - 1];

		} else {

			return dp[i - 1][j] * coinProbabilityArray[i + j - 1]
					+ dp[i][j - 1] * back(coinProbabilityArray[i + j - 1]);
		}
	}

	public static double back(double coinProbability) {
		return 1 - coinProbability;
	}

	public static void println(Object target) {
		System.out.println(target);
	}
}


Measured memory_bytes: 126180
#include <stdio.h>
#include <string.h>
int main()
{
    int num;
    char str[3];

    scanf("%s",str);
    num = strlen(str);

    if(num == 2){
        printf("%s",str);
    }else{
        printf("%c%c%c",str[2],str[1],str[0]);
    }

    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

using ld = double;
int n;
ld dp[305][305][305];

ld memo_rec(int One, int Two, int Three){
    if(dp[One][Two][Three] != -1)   return dp[One][Two][Three];
    if(One + Two + Three == 0)  return dp[One][Two][Three] = 0.0;
    
    ld res = n;
    if(One > 0) res += memo_rec(One - 1, Two, Three) * One;
    if(Two > 0) res += memo_rec(One + 1, Two - 1, Three) * Two;
    if(Three > 0)   res += memo_rec(One, Two + 1, Three - 1) * Three;
    res *= 1.0 / (One + Two + Three);

    return dp[One][Two][Three] = res;
}

int main(){
    cin >> n;
    vector<int> cnt(4, 0);
    for(int i = 0; i < n; ++i){
        int a;
        cin >> a;
        ++cnt[a];
    }
    
    for(int i = 0; i <= 300; ++i){
        for(int j = 0; j <= 300; ++j){
            for(int k = 0; k <= 300; ++k){
                dp[i][j][k] = -1;
            }
        }
    }

    cout << fixed << setprecision(15);
    cout << memo_rec(cnt[1], cnt[2], cnt[3]) << endl;
}

Measured memory_bytes: 219392
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
using namespace std;
void solve(){
    int n, d, x, y, ans = 0;
    cin >> n >> d;
    for(int i = 0; i < n; i++){
        cin >> x >> y;
        if(x * x + y * y <= d * d)ans++;
    }
    cout << ans << endl;
}
main(){
    ios_base::sync_with_stdio(0);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}
		

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#include<unordered_map>
#define ll long long int
#define pb emplace_back
#define mp make_pair
#define mod 1000000007
#define For(i,n) for(ll i=0;i<n;i++)
using namespace std;
unordered_map<int, bool>lo;
 
int main()
{
    ll n;
    cin>>n;
    ll a[n];
    ll four=0;
    ll two=0;
    ll odd=0;
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]%4==0)
        {
            four++;
        }
        else if(a[i]%2==0)
        {
            two++;
        }
        else
        {
            odd++;
        }
    }
    if(odd>four&&two!=0)
    {
        cout<<"No";
        return 0;
    }
    if(two==0&&odd>four)
    {
        if(odd-1>four)
        {
            cout<<"No";
        }
        else
        {
            cout<<"Yes";
        }
    }
    else
    {
        cout<<"Yes";
    }
        
	
	return 0;
}      

Measured memory_bytes: 1024
module Main (main) where

import Control.Applicative

main :: IO ()
main = do
  [x,y] <- (map read . words) <$> getLine 
  putStrLn $ comp x y

comp :: Integer -> Integer -> String
comp x y
  | x == y = "a == b"
  | x > y  = "a > b"
  | x < y  = "a < b"

Measured memory_bytes: 3548
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();

		long result = Long.MAX_VALUE;

		result = Math.min(result, Math.abs(a/2 - a + a/2)*b*c);
		result = Math.min(result, Math.abs(b/2 - b + b/2)*a*c);
		result = Math.min(result, Math.abs(c/2 - c + c/2)*b*a);

		System.out.println(result);
	}

}


Measured memory_bytes: 27024
#include <iostream>
#include <string>
#include <cstdio>
#include <sstream>
using namespace std;

int main()
{
  int n;
  string str, tmp, tmp2;
  
  while (cin >> n, n){
    cin >> str;
    for (int i = 0; i < n; i++){
      int ct = 1;
      tmp2 = "";
      for (int j = 0; j < str.size(); j++){
        if (str[j] == str[j + 1]){
          ct++;
        }
        else {
          stringstream ss;
          ss << ct << str[j];
          tmp2 += ss.str();
          ct = 1;
        }
      }
      str = tmp2;
    }
    cout << str << endl;
  }
  return (0);
}

Measured memory_bytes: 1356
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>

using namespace std;
typedef long long ll;

int main()
{
	int N, K;
	scanf("%d%d", &N, &K);

	ll res = 0;

	for (int b = 1; b <= N; b++) {
		if (b - K <= 0)
			continue;
		int p = N / b;
		int r = N % b;
		res += (ll)p * (ll)(b - K);
		if (r - K + 1 >= 0)
			res += (ll)(r - K + 1);
		if (K == 0)
			res--;
	}

	printf("%lld\n", res);

	return 0;
}


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

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

ll modadd(ll a, ll b){
  return (a + b) % MOD;
}
ll modmult(ll a, ll b){
  return (a * b) % MOD;
}

int main(){
  ll n;
  cin >> n;
  cin.ignore();
  vector <ll> a;
  ll tmp;
  ll kinds = 0; // 色の種類数
  for(ll i = 0; i < n; i++){
    cin >> tmp;
    a.push_back(tmp);
    if(tmp == 0){
      ++kinds;
    }
  }

  // x_i >= y_i >= z_i 割り当て方3通り
  ll x = 0, y = 0, z = 0;
  ll ans = 1;
  tmp = 0;
  
  for(ll i = 0; i < n; i++){
    tmp = 0;
    if(a[i] == x){
      ++tmp;
      ++x;
      if(a[i] == y){
        ++tmp;
      }
      if(a[i] == z){
        ++tmp;
      }
    } else if(a[i] == y){
      ++tmp;
      ++y;
      if(a[i] == z){
        ++tmp;
      }
    } else if(a[i] == z){
      ++tmp;
      ++z;
    }
    ans = modmult(ans, tmp);
  }

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


Measured memory_bytes: 1400
#include <iostream>
#include <set>

using namespace std;

int main() {
  set<string> used;
  char end;

  int n;
  cin >> n;

  string s;
  cin >> s;
  end = s[s.size()-1];
  used.insert(s);

  bool result = true;
  for (int i = 1; i < n; i++) {
    cin >> s;
    if (end != s[0] || used.find(s) != used.end()) {
      result = false;
      break;
    }

    end = s[s.size()-1];
    used.insert(s);
  }

  if (result) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
# coding: UTF-8
import itertools
import numpy as np

N = int(input())
Info = []
for i in range(N):
    A = int(input())
    for j in range(A):
        x, y = map(int, input().split())
        Info.append((i, x - 1, y))

# 何人目かを正直者か優しくない人かを判断するためのnp.array
A = np.array(list(itertools.product([0, 1], repeat=N)), np.bool)

for i, x, y in Info:
    bl = (~A[:, i]) | (A[:, x] == bool(y))
    A = A[bl]
answer = A.sum(axis=1).max()
print(answer)

Measured memory_bytes: 18368
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k,l = 1e9;
    cin >> n >> k;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    for(int j = n - 1; j - k + 1 >= 0; j--){
        if(l > a[j] - a[j - k + 1])
        l = a[j] - a[j - k + 1];
    }

    cout << l << endl;
}


Measured memory_bytes: 640
#!/usr/bin/env python3
import sys


def solve(N: int, S: str):
    r = 0
    g = 0
    b = 0
    sub = 0
    for i in range(N):

        # RGBそれぞれの個数をカウント
        if S[i] == "R":
            r += 1
        elif S[i] == "G":
            g += 1
        else:
            b += 1
        
        # 条件2に一致しないケースをカウント
        for j in range(i + 1, N):
            if 2 * j - i >= N:
                break
            if S[i] != S[j] and S[j] != S[2 * j - i] and S[i] != S[2 * j - i]:
                sub += 1

    print(r * g * b - sub)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9252
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
 
namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());
			Dictionary<int, int>[] to = new Dictionary<int, int>[n];
			Edge[] edge = new Edge[n - 1];
			for (int i = 0; i < n; i++) {
				to[i] = new Dictionary<int, int>();
			}

			int first = 0;
			for (int i = 0; i < n - 1; i++) {
				var temp = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
				int a = temp[0] - 1;
				int b = temp[1] - 1;
				to[a].Add(b, -1);
				to[b].Add(a, -1);

				edge[i] = new Edge {
					From = a,
					To = b
				};

				if (i == 0) {
					first = a;
				}
			}

			int num = to.Max(x => x.Count);

			var q = new Queue<ToColor>();
			q.Enqueue(new ToColor { To = first, Color = -1 });
			while (q.Count > 0) {
				var next = q.Dequeue();
				int color = next.Color == -1 ? 0 : (next.Color + 1) % num;
				foreach (var nn in to[next.To].Keys.ToArray()) {
					if (to[next.To][nn] == -1) {
						to[next.To][nn] = color;
						to[nn][next.To] = color;
						q.Enqueue(new ToColor { To = nn, Color = color });
						color = (color + 1) % num;
					}
				}
			}

			var sb = new StringBuilder();
			sb.AppendLine(num.ToString());
			for (int i = 0; i < n - 1; i++) {
				sb.AppendLine((to[edge[i].From][edge[i].To] + 1).ToString());
			}

			Console.Write(sb.ToString());
		}
	}


	public class Edge
	{
		public int From { get; set; }
		public int To { get; set; }
	}

	public class ToColor
	{
		public int To { get; set; }
		public int Color { get; set; }
	}
}

Measured memory_bytes: 47852
#include <bits/stdc++.h>
using namespace std;
typedef int64_t i64;

int main() {
  int N;
  cin >> N;
  
  vector<tuple<string, i64, int>> data(N);
  
  for(int i=0;i<N;i++){
    string city;
    i64 point;
    cin >> city >> point;
    data.at(i) = make_tuple(city, 100 - point, i);
  }
  
  sort(data.begin(), data.end());
  
  for(int i=0;i<N;i++){
  	cout << get<2>(data.at(i)) + 1 << endl;
  }
  
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String args[]){

        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
       
        int ones = N % 10;

        if(ones == 2 || ones == 4 || ones == 5 || ones == 7 || ones == 9 ){
            System.out.println("hon");
        }
        else if(ones == 0 || ones == 1 || ones == 6 || ones == 8){
            System.out.println("pon");
        }else if(ones == 3){
            System.out.println("bon");
        }
        sc.close();
     
    }
    
}

Measured memory_bytes: 35680
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            new Program().Solve(new MyInputStream(Console.In, ' '));
            Console.Out.Flush();
        }

        public void Solve(MyInputStream cin)
        {
            var val = cin.ReadInt() * 100 + cin.ReadInt() * 10 + cin.ReadInt();
            if (val % 4 == 0) WriteLine("YES");
            else WriteLine("NO");
        }
    }

    public class MyInputStream
    {
        private readonly System.IO.TextReader _stream;
        private char separator = ' ';
        private Queue<string> inputStream;
        public MyInputStream(System.IO.TextReader s, char separator = ' ')
        {
            this.separator = separator;
            this._stream = s;
            inputStream = new Queue<string>();
        }
        public string Read()
        {
            if (inputStream.Count != 0) return inputStream.Dequeue();
            string[] tmp = _stream.ReadLine().Split(separator);
            for (int i = 0; i < tmp.Length; ++i)
                inputStream.Enqueue(tmp[i]);
            return inputStream.Dequeue();
        }
        public string ReadLine() { return _stream.ReadLine(); }
        public int ReadInt() { return int.Parse(Read()); }
        public long ReadLong() { return long.Parse(Read()); }
        public double ReadDouble() { return double.Parse(Read()); }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read(); return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt(); return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong(); return ret;}
    }
}



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

int main(void){
    int a,b,c,x,y;
    cin >> a >> b >> c >> x >> y;
    int ans = 0;

    if(a+b > 2*c){
        while(x > 0 && y > 0){
            ans += 2*c;
            x--;
            y--;
        }
        while(x > 0){
            ans += min(a, 2*c);
            x--;
        }
        while(y > 0){
            ans += min(b, 2*c);
            y--;
        }
    }else{
        ans += a*x + b*y;
    }
    
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import java.io.PrintWriter

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any) = pw.print(s)
fun println(s: Any) = pw.println(s)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val N = nextInt()
    val H = nextIntList().toTypedArray()
    var ans = 0
    for (i in H.indices) {
        while (H[i] > 0) {
            ans++
            for (j in i until H.size) {
                if (H[j] == 0) break
                H[j]--
            }
        }
    }
    println(ans)
}

Measured memory_bytes: 37788
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

ll H , W;

int main(){
    cin >> H >> W;
    ll ans = min(W % 3 == 0 ? 0 : H , H % 3 == 0 ? 0 : W);
    rep(i,1,H) {
        ll Mn = i * W , Mx = i * W;
        Mn = min(Mn , (W >> 1) * (H - i));
        Mx = max(Mx , ((W + 1) >> 1) * (H - i));
        ans = min(Mx - Mn , ans);
    }
    rep(i,1,W) {
        ll Mn = i * H , Mx = i * H;
        Mn = min(Mn , (H >> 1) * (W - i));
        Mx = max(Mx , ((H + 1) >> 1) * (W - i));
        ans = min(Mx - Mn , ans);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

constexpr ll D = 1e16;

ll digit(ll t){
    ll res=0;
    while(t){
        res += t%10;
        t/=10;
    }
    return res;
}

int main(){
    ll k;
    cin >> k;

    set<ll> cand;
    ll base = 0;
    for(ll i=0;i<=13;i++){  // 下i桁が9
        for(int j=0;j<=1000;j++){
            cand.insert(j*(base+1)+base);
            if(j*(base+1)+base >= D) break;
        }
        base = base * 10 + 9;
    }
    cand.erase(0);

    //int cnt = 20;
    //for(auto v : cand){
    //    cout << v << endl;
    //    if(--cnt==0) return 0;
    //}

    vector<ll> v(cand.begin(),cand.end());
    vector<pair<ll,ll>> val(cand.size());
    for(int i=0;i<cand.size();i++) val[i] = make_pair(v[i],digit(v[i]));

    vector<bool> valid(cand.size(),true);
    for(int i=cand.size()-2;i>=0;i--){
        if(val[i].fi * val[i+1].se > val[i].se * val[i+1].fi){
            val[i] = val[i+1];
            valid[i] = false;
        }
    }

    set<ll> ans;
    for(int i=0;i<valid.size();i++){
        if(valid[i]){
            ans.insert(v[i]);
        }
    }

    for(auto a : ans){
        cout << a << endl;
        if(--k == 0) break;
    }
} 


Measured memory_bytes: 1152
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int N;
    cin>>N;
    int d[300000];
    for(int i=0;i<N;i++)
    {
        cin>>d[i];
    }
    int D = 0;
    for (int i = 0; i < N-1; i++)
    {D=max(D,d[i]);
    if(D<10)
    {
        cout<<"no"<<endl;
        return 0;
    }
    D-=10;
        /* code */
    }
    D=0;
    for (int i = N-1; i>0; i--)
    {D=max(D,d[i]);

    if(D<10)
    {
        cout<<"no"<<endl;
        return 0;
    }
    D-= 10;
        /* code */
    }
    
    cout<<"yes"<<endl;
    return 0;
    
}


Measured memory_bytes: 4272
#include<iostream>//pck2016-4
#include<algorithm>
using namespace std;
int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    int w,h,c;
    int ans=0;
    cin>>w>>h>>c;
    int m=min(w,h);
    bool flag=true;
    while(flag){
        if(w%m==0&&h%m==0){
            ans=(w/m)*(h/m)*c;
            flag=false;
        }
        m--;
    }
    cout<<ans<<"\n";
    return(0);
}


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

using i64 = long long;

#define REP(i, stop) for (int i = 0, i##_len = stop; i < i##_len; ++i)

const int cm = 1 << 17;
char cn[cm], *ci = cn + cm, ct;
inline char getc() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int read() {
	int r = 0;
	if (ci - cn + 16 > cm) while ((ct = getc()) & 16) r = r * 10 + ct - '0';
	else while ((ct = *ci++) & 16) r = r * 10 + ct - '0';
	return r;
}

// x shoud be greater than or equal to zero
inline void write(i64 x) {
	char d[20];
	int i = 0;
	while (true) {
		d[i] = x % 10 + 48;
		x /= 10;
		++i;
		if (x <= 0) break;
	}
	while (i--) {
		putchar(d[i]);
	}
}

int A[100001];
signed main() {
	int n = read();
	REP(i, n + 1) {
		A[i] = read();
	}
	i64 s = 0;
	int a0;
	int a1 = A[0];
	REP(i, n) {
		a0 = a1;
		a1 = A[i + 1];
		int b = read();
		int m = a0 < b ? a0 : b;
		s += m;
		b -= m;
		m = a1 < b ? a1 : b;
		s += m;
		a1 -= m;
	}
	write(s);
}


Measured memory_bytes: 640
import java.util.*;
public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		String t = sc.next();
		System.out.println(t.endsWith("s") ? t+"es" : t+"s");
		sc.close();			
	}

	public static void main(String args[]) {
		solve();
	}

}

Measured memory_bytes: 38584
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;
int main()
{
  string S;
  cin >> S;
  int N = S.size();
  int ans = 999;
  for (int i = 0; i <= N - 3; i++)
  {
    int num = (S[i] - '0' /*文字=>数字*/) * 100 + (S[i + 1] - '0') * 10 + S[i + 2] - '0';
    ans = min(ans, abs(num - 753));
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
  long long  n,a,b;
  cin>>n>>a>>b;
  long long sum=a+b;
  long long times= n/sum;
  long long rem=n%sum;
  long long ans=0;
  for(int i=0;i<times;i++){
    ans+=a;
  }
  if(rem>=a) ans+=a;
  else ans+=rem;
  cout<<ans<<endl;
} 
  


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define INF 1e+9
using namespace std;

signed main(){
	int n,a[100000],ma = 0,b = INF;
	cin >> n;
	for(int i = 0;i < n;i++){
		cin >> a[i];
		ma = max(ma,a[i]);
	}
	bool flag = false;
	for(int i = 0;i < n;i++){
		if(!flag && a[i] == ma) flag = true;
		else if(min(abs(b - ma / 2),abs(b - (ma + 1) / 2)) > min(abs(a[i] - ma / 2),abs(a[i] - (ma + 1) / 2))) b = a[i];
	}
	cout << ma << " " << b << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
typedef long long ll;

using namespace std;

int main()
{
    string n;
    ll sum=0,i;
    cin>>n;
    for(i=0; i<n.size(); i++)
    {
        sum=sum+n[i]-'0';
    }
    if(sum%9==0)
    {
        cout<<"Yes"<<endl;
    }
    else if(sum%9!=0)
    {
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 3344
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>
#include <functional>
#include <random>
//#include <boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)
#define llrep(i, n) for(ll i = 0; i < n; ++i)
#define llREP(i, m, n) for(ll i = m; i < n; ++i)
#define llrrep(i,n) for(ll i = n; i >= 0; --i)
#define llRREP(i, m, n) for(ll i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;
using pil = std::pair<int, long long>;
using pli = std::pair<long long, int>;
using plpii = std::pair<long long, std::pair<int, int>>;
using pdd = std::pair<double, double>;
using pis = std::pair<int, std::string>;

const long long INF = 1000000000000000001;
const long long _MOD_ = 1000000000000000009;
const long long _MOD = 1000000007;
const long long MOD = 998244353;
const int ALPHABET = 27;
const double pi = 3.14159265358979;

using namespace std;
//namespace mp = boost::multiprecision;

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

	string l;
	cin >> l;
	ll* sum = new ll[l.length() + 1];
	sum[0] = 1;
	REP(i, 1, l.length() + 1) {
		sum[i] = 2 * sum[i - 1] + sum[i - 1];
		sum[i] %= _MOD;
	}

	ll ans = 0;
	ll t = 1;
	rep(i, l.length()) {
		if (l[i] == '1') {
			if(t != 1) ans += ((sum[l.length() - 1 - i] - 1) * t) % _MOD;
			else ans += sum[l.length() - 1 - i];
			ans %= _MOD;
			ans += 2 * t;
			ans %= _MOD;

			t *= 2;
			t %= _MOD;
		}
	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 4536
inf = 10**15


def main():
    import sys
    input = sys.stdin.readline

    N = int(input())
    X = []
    Y = []
    P = []
    for _ in range(N):
        x, y, p = map(int, input().split())
        X.append(x)
        Y.append(y)
        P.append(p)

    dx = [[inf] * N for _ in range(1<<N)]
    dy = [[inf] * N for _ in range(1<<N)]
    for i in range(1 << N):
        Xline = [0]
        Yline = [0]
        for j in range(N):
            if i>>j&1:
                Xline.append(X[j])
                Yline.append(Y[j])
        for j in range(N):
            for x, y in zip(Xline, Yline):
                dx[i][j] = min(dx[i][j], abs(x - X[j]))
                dy[i][j] = min(dy[i][j], abs(y - Y[j]))

    ans = [inf] * (N+1)
    beki = [1<<j for j in range(N)]
    for i in range(3**(N-1)):
        M = i
        k = 0
        ix = iy = 0
        J = []
        for j in range(N-1):
            M, m = divmod(M, 3)
            if m == 0:
                J.append(j)
            elif m == 1:
                k += 1
                ix += beki[j]
            else:
                k += 1
                iy += beki[j]
        for x in range(3):
            kk = k
            ix_ = ix
            iy_ = iy
            if x == 0:
                J.append(N-1)
            elif x == 1:
                kk += 1
                ix_ += beki[N-1]
            else:
                kk += 1
                iy_ += beki[N-1]
            cost = 0
            for j in J:
                p = P[j]
                cost += min(dx[ix_][j], dy[iy_][j]) * p
            ans[kk] = min(ans[kk], cost)
    for c in ans:
        print(c)


if __name__ == '__main__':
    main()


Measured memory_bytes: 89156