akhauriyash/Code-Regression huggingface dataset:
def solve square
  n = square.size
  area = n * n
  center = n / 2
  targetx = center
  targety = center + 1
  square[targety][targetx] = 1
  used = 1

  while used < area do
    targetx += 1
    targety += 1
    while !(targetx < n && targety < n && square[targety][targetx] == -1) do
      #1
      if targetx >= n
        targetx = 0
      elsif targetx < 0
        targetx = n - 1
      end

      if targety >= n
        targety = 0
      end

      #2
      if square[targety][targetx] != -1
        targetx -= 1
        targety += 1
      end

    end
    square[targety][targetx] = used + 1
    used += 1
  end
end

def printSquare square
  square.each do |array|
    array.each do |i|
      printf "%4d", i
    end
    printf "\n"
  end
end

while n = $stdin.gets.to_i do
  break if n == 0
  square = Array.new(n).map{Array.new(n, -1)}
  solve square
  printSquare square
end

Measured memory_bytes: 6104
n = int(input())
arr = list(map(int, input().split()))
arr.sort(reverse=True)
ans = arr[0]
i = 1
j = 1
while i < n-1:
    ans += arr[j]
    #print (arr[j])
    if i % 2 == 0:
        j += 1
    i += 1
print (ans)

Measured memory_bytes: 31432
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define x first
#define y second
#define mod 1e9+7
#define f(i,a,b) for(ll i=a;i<b;i++)
#define rof(i,a,b) for(ll i=a;i>b;i--)

ll lcm(ll a, ll b){
    return a / __gcd(a, b) * b;
}
//memset can initialize to 0 or -1 ONLY
// memset(a,0,sizeof(a[0][0])*n*n); //2D array
//memset(a, 0, sizeof(a));  //1D array
//memset(str, 't', sizeof(str)); // string
void solve()
{
  string s;cin>>s;
  
  bool palin =true,palin1=true,palin2=true;
  int st=0,e=s.length()-1;
  int n=s.length();
  while(st!=e)
  {
      if(s[st]!=s[e])
      {
          palin=false;
      
          break;
      }
      st++;e--;
      
  }
  
  st=0;e=(n-1)/2 -1;
    while(st<e)
  {
      if(s[st]!=s[e])
      {
          palin1=false;
      
          break;
      }
      st++;e--;
      
  }
  
  st=(n+3)/2 -1;e=s.length()-1;
  
      while(st<e)
  {
      if(s[st]!=s[e])
      {
          palin2=false;
      
          break;
      }
      st++;e--;
      
  }
 // cout<<palin<<palin1<<palin2<<" ";
  if(palin&&palin1&&palin2)
  cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


int main()
{

ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll t=1;
   // cin>>t;
    while(t--)
    {
    
    solve();
    
    }

}


Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import numpy as np

N, M, C = map(int, input().split())
B = [int(x) for x in input().split()]
A = [[int(x) for x in input().split()] for _ in range(N)]

print(((np.dot(A, B) + C) > 0).sum())

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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
  dp[i] 最大の高さをiとしたときの最大スコア
  dp[h[k]] = a[k] + maxdp[t] (t = 0 ... h[k]-1)
  segtree
  }*/

class segtree
{
public:
  int n;
  vector<int> dat;

  segtree(int n_)
  {
    n = 1;
    while(n < n_) n *= 2;
    dat.resize(2*n, 0);
  }

  void update(int k, int v)
  {
    k += n-1;
    dat[k] = v;
    while(k > 0){
      k = (k-1)/2;
      dat[k] = max(dat[k*2+1], dat[k*2+2]);
    }
  }

  int query(int a, int b, int k, int l, int r)
  {
    if(r <= a or b <= l) return 0;
    if(a <= l and r <= b) return dat[k];

    int vl = query(a, b, k*2+1, l, (l+r)/2);
    int vr = query(a, b, k*2+2, (l+r)/2, r);
    return max(vl, vr);
  }

  int query(int a, int b)
  {
    return query(a, b, 0, 0, n);
  }
};

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

  vi h(n), a(n);
  rep(i, 0, n) cin >> h[i];
  rep(i, 0, n) cin >> a[i];

  segtree st(n+1);
  rep(i, 0, n){
    int ma = st.query(0, h[i]);
    st.update(h[i], ma + a[i]);
  }

  int ans = st.query(0, n+1);
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 7424
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		for (int i = 1;; i++) {
			int x = sc.nextInt();
			if (x == 0)
				break;
			System.out.printf("Case %d: %d\n", i, x);

		}
	}
}


Measured memory_bytes: 65948
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<string.h>
#include<stdlib.h>
#include<math.h>

#define PI 3.1415926535898

using namespace std;

int main()
{
	int a,b,x;
	double y,ans,t;
	cin>>a>>b>>x;
	int v=a*a*b;
	if(x>=0.5*v)
	{
		y=(double)(2*v-2*x)/(a*a);
		t=(double)(a/y);
		ans=90-(double)atan(t)*180/PI;
	}else
	{
		y=(double)2.0*x/(a*b);
		t=(double)(y/b);
		ans=90-atan(t)*180/PI;
	}
	printf("%.10lf\n",ans);
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <cstdlib>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}

vector<ll> fact, factinv, inv;
ll mod = 1e9 + 7;
void prenCkModp(ll n) {
	fact.resize(n + 5);
	factinv.resize(n + 5);
	inv.resize(n + 5);
	fact.at(0) = fact.at(1) = 1;
	factinv.at(0) = factinv.at(1) = 1;
	inv.at(1) = 1;
	for (ll i = 2; i < n + 5; i++) {
		fact.at(i) = (fact.at(i - 1) * i) % mod;
		inv.at(i) = mod - (inv.at(mod % i) * (mod / i)) % mod;
		factinv.at(i) = (factinv.at(i - 1) * inv.at(i)) % mod;
	}

}
ll nCk(ll n, ll k) {
	return (fact.at(n) * ((factinv.at(k) * factinv.at(n - k)) % mod)) % mod;
}
int modPow(long long a, long long n, long long p) {
	if (n == 0) return 1; // 0乗にも対応する場合
	if (n == 1) return a % p;
	if (n % 2 == 1) return (a * modPow(a, n - 1, p)) % p;
	long long t = modPow(a, n / 2, p);
	return (t * t) % p;
}

int main() {
	ll N, A, B;
	cin >> N >> A >> B;
	ll an = modPow(2, N, mod);
	ll X = 1;
	ll Y = 1;
	rep(i, A) {
		X *= (N - i);
		X %= mod;
		Y *= (i + 1);
		Y %= mod;
	}

	Y = modPow(Y, mod - 2, mod);
	an -= (X * Y) % mod;

	X = 1;
	Y = 1;
	rep(i, B) {
		X *= (N - i);
		X %= mod;
		Y *= (i + 1);
		Y %= mod;
	}

	Y = modPow(Y, mod - 2, mod);
	an -= (X * Y) % mod;
	while (an-1 < 0) {
		an += mod;
	}
	cout << an-1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,t,m,n,a)vector<vector<t> > name(m,vector<t> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<int>(n,a)));
typedef long long ll;
const int INF = 100000000;
const long INF64 = 1000000000000000ll;
const ll MOD = 998244353LL;
std::vector<int> enum_div(int n)//nの約数を列挙
{
	std::vector<int> ret;
	for(int i=1 ; i*i<=n ; ++i)
	{
		if(n%i == 0)
		{
			ret.push_back(i);
			if(i!=1 && i*i!=n)
			{
				ret.push_back(n/i);
			}
		}
	}
	return ret;
}
int main(){
	int n;
	std::cin >> n;
	std::vector<int> a;
	a=enum_div(n*2);
	//a.pb(1);
	a.pb(n*2);
	sort(all(a));
	
	if((n==3||a.size()>=2)&&a.size()%2==0&&a[a.size()/2]-a[a.size()/2-1]==1){
		std::cout << "Yes" << std::endl;
		std::cout << a[a.size()/2] << std::endl;
		vvector(ans,int,a[a.size()/2-1],a[a.size()/2],0);
		int k=1;
		rep(i,a[a.size()/2-1])rep(j,a[a.size()/2]){
			if(i>=j){ans[i][j]=k;
			k++;}
		}
		k=1;
		rep(j,a[a.size()/2])rep(i,a[a.size()/2-1]){
			if(ans[i][j]==0){ans[i][j]=k;
			k++;}
		}
		rep(j,a[a.size()/2]){
			std::cout << a[a.size()/2-1] <<" " ;
			rep(i,a[a.size()/2-1])std::cout << ans[i][j] <<" ";
			std::cout  << std::endl;
		}
		exit(0);
	}else std::cout << "No" << std::endl;
}


Measured memory_bytes: 2176
import sys
read = sys.stdin.read
from itertools import permutations
def main():
    def warshall_floyd(d):
        for k in range(n):
            for i in range(n):
                for j in range(n):
                    d[i][j] = min(d[i][j], d[i][k] + d[k][j])
        return d

    n, m, r = map(int, input().split())
    rs = tuple(map(int, input().split()))
    d = [[10**9] * n for _ in range(n)]
    m = map(int, read().split())
    mmm = zip(m, m, m)
    for s, t, dis in mmm:
        s -= 1
        t -= 1
        d[t][s] = d[s][t] = dis
    for j1 in range(n):
        d[j1][j1] = 0
    res = warshall_floyd(d)
    rsp = tuple(permutations(rs))
    result = float('inf')
    for rspe in rsp:
        res_t = 0
        for i1 in range(r - 1):
            res_t += res[rspe[i1]-1][rspe[i1+1]-1]
        result = min(result, res_t)
    print(result)

if __name__ == '__main__':
    main()


Measured memory_bytes: 81020
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;

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

	cin >> N >> K;
	vector<long long int>a(N);
	vector<long long int>b(N);
	long long int max_a = 0;
	for (int i = 0; i < N; i++) {
		cin >> a[i] >> b[i];
		max_a = max(max_a, a[i]);
	}
	priority_queue<long long int>PQ;
	for (int i = 0; i < N; i++) {
		if (b[i] > max_a) {
			PQ.push(b[i]);
		}
	}
	while (K > 0 && !PQ.empty()) {
		K -= PQ.top();
		PQ.pop();
		M++;
	}
	if (K > 0) {
		M += K / max_a + !!(K%max_a);
	}
	cout << M << endl;
	return 0;
}

Measured memory_bytes: 2936
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); i++)
#define REP1(i,a,b) for(int i=a; i<=(int)(b); i++)
#define ALL(x) begin(x),end(x)
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}

LL dp[15];
LL ans=0, pw2[15];
LL solve(string &s, int i) {
    if ( i>=s.length() ) return 0;
    if ( dp[i] ) return dp[i];
    LL x=0, res=0;
    int n=s.length();
    for(int j=i; j<s.length(); j++) {
        x=x*10+(s[j]-'0');
        LL p=(n-j-2>=0? pw2[n-j-2] : 1);
        res+=x*p+solve(s,j+1);
    }
    return dp[i]=res;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin >> s;
    pw2[0]=1;
    for(int i=1; i<15; i++) pw2[i]=pw2[i-1]*2;
    solve(s,0);
    // for(int i=0; i<s.length(); i++) cout << dp[i] << endl;
    cout << dp[0] << '\n';
    return 0;
}

Measured memory_bytes: 256
//***********************
//Author:kibi11
//Quarantine Days
//***********************

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define MOD 1000000007
#define dd double
#define fr(i, n) for(int i = 0; i < n; i++)
#define fr1(i,a,b) for(int i=a;i<b;i++)
#define frr(i,a,k) for(int i=a;i>=k;i--)
#define same int t;cin>>t;while(t--)
#define check(x) cout << (#x) << " is " << (x) << endl;
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define f first
#define s second
#define XOX
#define pi = 3.14159265358979323846

//////////////////////////////////////////////////////////////////////////
/////////////////DEBUGING ZONE//////////////////////////////

vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
///////////////////////////////////////////////////////////////////////////
 
ll powermod(ll base, ll exp, ll mod) {
	ll result = 1;
	while (exp != 0) {
		if ((exp % 2) == 1) {
			result = (result * base) % mod;
		}
		base = (base * base) % mod;
		exp /= 2;
	}
	return result;
}

///////////////////////////////////////////////////////////////////////////
//Fuctions if any:





///////////////////////////////////////////////////////////////////////////
int main() 
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int tt = clock();
//ios_base& scientific (ios_base& str);

int n;
cin>>n;
string s;
cin>>s;
int r=0;
int w=0;
for(auto a: s)
{
	if(a=='R')
	{
		r++;

	}
	else
	{
		w++;
	}
}
int wrong=0;
fr(i,r)
{
	if(s[i]=='W')
	{
		wrong++;
	}
}
int wro=0;
fr1(i,r,s.size())
{
	if(s[i]=='R')
	{
		wro++;
	}
}
if(wro==wrong)
cout<<wrong<<endl;
else
{
	cout<<max(wro,wrong)<<endl;
}
cerr << "TIME = " << (double) 1.0 * (clock() - tt) / CLOCKS_PER_SEC << " seconds" << endl;
return 0;
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ASC(x) sort(ALL((x)))
#define DESC(x) sort(ALL((x)),greater<ll>())
#define REV(x) reverse(ALL((x)))
#define pb push_back

mat divideH(ll n, ll H)
{
    mat D(2);
    D[0].pb(1);
    REP(i,0,H-1) {
        if((n >> (H-i-2)) & 1 == 1) {
            D[0].pb(i+2);
            D[1].pb(i+1);
        }
    }
    D[1].pb(H);

    return D;
}


int main()
{
    ll H, W, K;
    cin >> H >> W >> K;
    vector<string> S(H);
    REP(i,0,H) cin >> S[i];

    mat C(H+1, vec(W+1, 0));
    REP(i,0,H) {
        REP(j,0,W) {
            C[i+1][j+1] = C[i+1][j] + C[i][j+1] - C[i][j] + (S[i][j] - '0');
        }
    }

    ll mi = H + W - 2;
    REP(d,0,1<<(H-1)) { // max 512
        mat D = divideH(d, H);
        ll left = 1, right;
        ll cnt = 0;
        bool g = true;
        REP(j,1,W+1) { // max 1000
            bool f = true;
            right = j;
            REP(i,0,SZ(D[0])) { // max 10
                ll top = D[0][i], bottom = D[1][i];
                if(C[bottom][right] + C[top-1][left-1] - C[bottom][left-1] - C[top-1][right] > K) {
                    f = false;
                    break;
                }
            }
            if(left == right && !f) {
                g = false;
                break;
            }
            else if(!f) {
                --j;
                ++cnt;
                left = j + 1;
            }
        }

        if(g) {
            mi = MIN(mi,cnt+SZ(D[0])-1);
            /*
            REP(i,0,H-1) divH[i] = (d >> (H-i-2)) & 1;

            cout << "divH : ";
            REP(i,0,H-1) cout << divH[i] << " ";
            cout << endl;
            cout << "divW : ";
            REP(i,0,W-1) cout << divW[i] << " ";
            cout << endl;
            cout << SZ(D[0]) - 1 << " " << cnt << " " << cnt + SZ(D[0]) - 1 << endl;
            cout << endl;*/
        }

    }

    PR(mi);

    return 0;
}

/*



*/

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

int main(){
  int n;
  string p;
  bool a = true;
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> p;
    if(p == "Y"){
      a = false;
    }
  }
  if(a){
    cout << "Three" << endl;
  }else{
    cout << "Four" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
    int n;
    cin >> n;
    vector<int>v(n);
    vector<int>s(n);
    for(int i=0;i<n;i++){
        cin >> v[i];   
        s[v[i]]++;
    }   
    int mi = *min_element(v.begin(),v.end());
    int ma = *max_element(v.begin(),v.end());
    bool flag = 1;
    for(int i=mi+1;i<=ma;i++){
        if(s[i]<2){
            flag = 0;
        }
    }
    
    if(ma%2==0){
        if(mi!=ma/2){
            flag = 0;
        }
        if(s[mi]!=1){
            flag = 0;
        }
    }else{
        if(mi!=(ma/2+1)){
            flag = 0;
        }
        if(s[mi]!=2){
            flag = 0;
        }
    }
    if(flag){
        cout << "Possible" << endl;
    }else{
        cout << "Impossible" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
// author : ayush_nishad
// Road to Expert since : 30 Aug 2020
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pb push_back
#define in insert
#define F first
#define S second
#define mod 1000000007
#define endl '\n'
#define all(x)  x.begin(),x.end()
#define w(x) int x;cin>>x; while(x-->0)
#define memset(a,b) memset(a,b,sizeof(a))
#define debug(x) cout << "[ " << #x  << " : " << x << " ]" << endl;

void fast()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
}
/*
think fast
think simple
*/
const int inf = 1e18;
void mysol()
{
	int n; cin >> n;
	vector<int> x(n), y(n);
	for (int i = 0; i < n; i++)
	{
		cin >> x[i] >> y[i];
	}
	int m1 = -inf, m2 = inf;
	for (int i = 0; i < n; i++)
	{
		m1 = max(m1, x[i] + y[i]);
		m2 = min(m2, x[i] + y[i]);
	}
	int ans1 = abs(m1 - m2);
	m1 = -1e9; m2 = 1e9;
	for (int i = 0; i < n; i++)
	{
		m1 = max(m1, x[i] - y[i]);
		m2 = min(m2, x[i] - y[i]);
	}
	int ans2 = abs(m1 - m2);
	cout << max(ans1, ans2);
}

int32_t main()
{
	fast();
	// w(t)
	{
		mysol();
	}
	//cerr << sizeof(dp)*(1e-6) << " megabytes\n";
	return 0;
}


Measured memory_bytes: 6344
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<functional>
#include<set>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define LOWER(a,x) lower_bound(ALL(a), x) - a.begin() - 1;
#define COUNT(a,x)  upper_bound(ALL(a), x) - lower_bound(ALL(a), x);
#define MCOUNT(a,x,y) upper_bound(ALL(a), y) - lower_bound(ALL(a), x);
#define SCAN(x) scanf("%lld",&x);
#define INF INT64_MAX
#define MOD 1000000007
#define pb push_back
#define F first
#define S second
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef map<ll, ll> MAP;
typedef set<ll> SET;
ll n = 0, m = 0, ans = 0, sum = 0, cnt = 0, tmp = 0, ma = 0, mi = 0;
string s;
bool flag, ok;
ll dx[4] = { 1,-1,0,0 }, dy[4] = { 0,0,1,-1 };
ll ddx[9] = { 1,-1,0,0,1,1,-1,-1,0 }, ddy[9] = { 0,0,1,-1,1,-1,1,-1,0 };
#pragma endregion
#define MAX 111111



int main(void) {
  cin >> n >> m;
  vll a;
  FOR(i, 0, n) {
	cin >> tmp;
	a.pb(tmp);
  }
  FOR(i, 1, n) {
	if (a[i] + a[i - 1] >= m) {
	  tmp = a[i];
	  a[i] = max(0LL, m - a[i - 1]);
	  ans += tmp - a[i];
	}
	if (a[i - 1] > m) {
	  ans += a[i - 1] - m;
	}
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1400
n,m = gets.split.map(&:to_i)
a=Array.new(n).map{Array.new(m)}
n.times do |i|
  a[i]=gets.split
  puts a[i].join(" ") + " " + a[i].map(&:to_i).sum.to_s
end
b=Array.new(m,0)
n.times do |i|
  m.times do |k|
    b[k] = b[k]+a[i][k].to_i
  end
end
puts b.map(&:to_s).join(" ") + " " + b.map(&:to_i).sum.to_s



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

char map[105][105];
int n, m, x, y, ans = 0, a[105][105], b[105][105];
short f[105][105][105][105];

int max(int x, int y) { return x > y ? x : y; }
int min(int x, int y) { return x < y ? x : y; }

int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%s", map[i] + 1);
    for (int j = 1; j <= m; j++) {
      a[i][j] = a[i][j - 1] + (map[i][j] == 'o');
      b[i][j] = b[i - 1][j] + (map[i][j] == 'o');
      if (map[i][j] == 'E') x = i, y = j;
    }
  }
  for (int i = x; i >= 1; i--)
    for (int j = y; j >= 1; j--) {
      for (int k = x; k <= n; k++)
        for (int l = y; l <= m; l++) {
          if (i > 1 && i - 1 > k - x)
            ans = max(ans, f[i - 1][j][k][l] =
                               max(f[i - 1][j][k][l],
                                   f[i][j][k][l] + a[i - 1][min(l, m - y + j)] -
                                       a[i - 1][max(j - 1, l - y)]));
          if (k < n && n - k > x - i)
            ans = max(ans, f[i][j][k + 1][l] =
                               max(f[i][j][k + 1][l],
                                   f[i][j][k][l] + a[k + 1][min(l, m - y + j)] -
                                       a[k + 1][max(j - 1, l - y)]));
          if (j > 1 && j - 1 > l - y)
            ans = max(ans, f[i][j - 1][k][l] =
                               max(f[i][j - 1][k][l],
                                   f[i][j][k][l] + b[min(k, n - x + i)][j - 1] -
                                       b[max(i - 1, k - x)][j - 1]));
          if (l < m && m - l > y - j)
            ans = max(ans, f[i][j][k][l + 1] =
                               max(f[i][j][k][l + 1],
                                   f[i][j][k][l] + b[min(k, n - x + i)][l + 1] -
                                       b[max(i - 1, k - x)][l + 1]));
        }
    }
  printf("%d", ans);
}


Measured memory_bytes: 227712
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.10f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e10;
const ll MAX_N = 1010;

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];

void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; i++) {
		fac[i] = fac[i - 1] * i;
	}
}

// 二項係数計算
long long COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	if (n > k * 2) {

	}
	return fac[n] / (fac[k] * fac[n - k]);
}

ll dp[201010][2];
ll dx[4] = { 0,0,-1,1 };
ll dy[4] = { -1,1,0,0 };

//long longしか使わない
//素数は1より大きい
int main() {
	ll n, k;
	cin >> n >> k;
	vector<ll>a(n);
	rep(i, n) {
		cin >> a[i];
	}
	ll res = 0;
	ll ans = 0;
	rep(i, n) {
		for (ll j = 0;j < i;++j) {
			if (a[i] > a[j])res++;
		}
		for (ll j = i + 1;j < n;++j) {
			if (a[i] > a[j])ans++;
		}
	}
	ll total = ans + res;
	ans *= k;
	ans %= MOD;
	ll res2 = ((k - 1) * k / 2) % MOD;
	res2 *= total;
	res2 %= MOD;
	ans += res2;
	ans %= MOD;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3620
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        new Main().run();
    }

    private void run() {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] h = new int[N];
        int[] dp = new int[N];
        for(int i = 0; i < N; i++) {
            h[i] = scanner.nextInt();
            dp[i] = Integer.MAX_VALUE;
        }

//        // もらうDP
//        dp[1] = Math.abs(h[0] - h[1]);
//        for(int i = 2; i < N; i++) {
//            dp[i] = Math.min(Math.abs(h[i] - h[i-1]) + dp[i-1], Math.abs(h[i] - h[i-2]) + dp[i-2]);
//        }
        // 配るDP
        dp[0] = 0;
        for(int i = 0; i < N-2; i++) {
            dp[i+1] = Math.min(Math.abs(h[i] - h[i+1]) + dp[i], dp[i+1]);
            dp[i+2] = Math.min(Math.abs(h[i] - h[i+2]) + dp[i], dp[i+2]);
        }
        dp[N-1] = Math.min(Math.abs(h[N-2] - h[N-1]) + dp[N-2], dp[N-1]);

        System.out.println(dp[N-1]);
    }
}


Measured memory_bytes: 48848
import java.util.Scanner;

class Main {

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int s = scanner.nextInt();
    if (s == 1 || s == 2) {
      System.out.println(4);
      return;
    }
    int cnt = 0;
    while (s != 1) {
      if (s % 2 == 0) {
        s /= 2;
      } else {
        s = s * 3 + 1;
      }
      cnt++;
    }
    System.out.println(cnt + 2);

  }

}


Measured memory_bytes: 23380
n=int(input())
l=list(map(int, input().split()))
power=[1]
for i in range(n+1):
    power.append(power[-1]*2)


imsi=0   
for i in range(n+1):
    imsi+=l[i]*power[n-i]


if(imsi<=power[n]):
    sum=0
    for i in range(n+1):
        sum+=l[i]
    yuksum=[sum]
    for i in range(n+1):
        yuksum.append(yuksum[-1]-l[i])

    x=1
    parent=1
    for i in range(n+1):
        if i==0:
            pass
        else:
            if (2*parent-l[i])>yuksum[i+1]:
                x+=yuksum[i+1]+l[i]
                parent=yuksum[i+1]
            else:
                x+=2*parent
                parent=2*parent-l[i]
    print(x)
else:
    print("-1")

Measured memory_bytes: 709864
package main

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

func main() {
	sc := NewScanner()

	n := sc.NextInt()
	fmt.Printf("%+v\n", 24-n+24) // output for debug
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			result = append(result, v)
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	result = append(result, v)

	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


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

#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;

using namespace std;

int main (void) {
    ll N, ans;
    scanf("%lld",&N);

    ll a[N],b[N],c[N-1];
    REP(int,i,0,N) scanf("%lld",&a[i]);
    REP(int,i,0,N) scanf("%lld",&b[i]);
    REP(int,i,0,N-1) scanf("%lld", &c[i]);
    ans = 0;
    ll prev = 1000000;
    REP(int,i,0,N){
        ans += b[a[i]-1];
        if ( a[i] - prev == 1 ){
            ans += c[prev-1];
        }
        prev = a[i];
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	string s,t;
	cin>>s>>t;
	for(int i=0;i<sz(s);i++)
	{
		if(s[i]!=t[i])
		{
			cout<<"No\n";
			return 0;
		}
	}
	cout<<"Yes\n";
	return 0;
}

Measured memory_bytes: 3640
import java.util.*;
import java.lang.*;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int h = scanner.nextInt();
		int w = scanner.nextInt();
		int n = scanner.nextInt();
		int sr = scanner.nextInt();
		int sc = scanner.nextInt();
		String s = scanner.next();
		String t = scanner.next();
		boolean end = false;
		int usafe = 1;
		int dsafe = h;
		for (int i = n - 1; i >= 0; i--) {
			if (s.charAt(i) == 'U') {
				usafe++;
			} else if (s.charAt(i) == 'D') {
				dsafe--;
			}
			if (usafe > dsafe) {
				end = true;
				break;
			}
			if (i > 0) {
				if (t.charAt(i - 1) == 'U') {
					dsafe = Math.min(dsafe + 1, h);
				} else if (t.charAt(i - 1) == 'D') {
					usafe = Math.max(usafe - 1, 1);
				}
			}
		}
		int lsafe = 1;
		int rsafe = w;
		for (int i = n - 1; i >= 0; i--) {
			if (s.charAt(i) == 'L') {
				lsafe++;
			} else if (s.charAt(i) == 'R') {
				rsafe--;
			}
			if (lsafe > rsafe) {
				end = true;
				break;
			}
			if (i > 0) {
				if (t.charAt(i - 1) == 'L') {
					rsafe = Math.min(rsafe + 1, w);
				} else if (t.charAt(i - 1) == 'R') {
					lsafe = Math.max(lsafe - 1, 1);
				}
			}
		}
		if (sr >= usafe && sr <= dsafe && sc >= lsafe && sc <= rsafe && !end) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}

Measured memory_bytes: 27784
#include <bits/stdc++.h>
#define int long long
#define len(x) x.size()
#define rep(i,a) for(int i=0;i<a;i++)
#define f(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int N = 105;
int grid[N][N];
int dp[N][N];
int h, w;

signed main(){
	scanf("%lld %lld", &h, &w);
	string s;
	rep(i, h){
		cin >> s;
		rep(j, w){
			grid[i][j] = (s[j]=='#');
			dp[i][j] = 1e9 + 1;
		}
	}
	dp[0][0] = grid[0][0];
	rep(i, h){
		rep(j, w){
			if(i > 0)
				dp[i][j] = min(dp[i][j], dp[i - 1][j] + (grid[i][j] == 1 && grid[i - 1][j] == 0));
			if(j > 0)
				dp[i][j] = min(dp[i][j], dp[i][j - 1] + (grid[i][j] == 1 && grid[i][j - 1] == 0));
		}
	}
	printf("%lld ", dp[h - 1][w - 1]);

	return 0;
}


Measured memory_bytes: 384
/*
 * Author : Andrew J
*/
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
using ll = long long;
using ii = pair <int , int>;
void in(int &x);
const int N = 1e5 + 10;
int n, k;
int a[105];
bool dp[N], vis[N];

bool f(int left) {
  if (left == 0) return 1;
  bool &sol = dp[left];
  if (vis[left]) return sol;
  vis[left] = 1;
  bool nxt = 0;
  for (int i = 1 ; i <= n ; i++) {
    if (left >= a[i]) {
      nxt |= f(left - a[i]);
    }
  }
  sol = !nxt;
  return sol;
}

int main() {
  in(n); in(k);
  for (int i = 1 ; i <= n ; i++) {
    in(a[i]);
  }
  puts(f(k) ? "Second" : "First");
  return 0;
}

void in(int &x){
	bool neg = false;
	register int c;
	x = 0;
	c = getchar();
	if(c == '-'){
		neg = true;
		c = getchar();
	}
	for (; c > 47 && c < 58; c = getchar())
	x = (x << 1) + (x << 3) + c - 48;
	if (neg) x *= -1;
}


Measured memory_bytes: 8512
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int main(void)
{
    LL n,k;
    cin>>n>>k;
    if(k == 0)
        cout<<n*n<<endl;
    else
    {
        LL sum = 0;
        for(int i = k; i <= n; i++)
        {
            LL u_int = n/i;
            sum += u_int*(i - k);
            if(n%i >= k)
                sum += n%i - k + 1;
        }
        cout<<sum<<endl;
    }
    return 0;
}


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

int main(){ 
 int N; cin >> N; ll K; cin >> K;
  vector<ll> A(N); for(int i = 0; i < N; i++){ cin >> A[i];}
  vector<ll> S(N+1,0);
  
  for(int i = 0; i < N; i++){ S[i+1] = S[i]+A[i];}
  for(int i = 0; i <= N; i++){ S[i] -= i;}
  for(int i = 0; i <= N; i++){ S[i] %= K;} 
  
  map<ll,ll> mp;
  ll ans = 0; queue<int> Q;
  for(int i = 0; i <= N; i++){ 
    
    //次にansにカウントしていく
    ans += mp[S[i]];
    // mpに追加
    mp[S[i]]++;
    Q.push(S[i]);
    if(Q.size() == K){ mp[Q.front()]--; Q.pop();}
  }
  
  cout << ans << endl; return 0;
}
  
  
    
  

Measured memory_bytes: 16640
// @author : Shubham Kalani

#include<bits/stdc++.h>

#define ll long long
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
#define len(a) (int)a.size()
#define all(a) (a).begin(), (a).end()
#define pq priority_queue
#define FASTIO  ios::sync_with_stdio(false); cin.tie(0);

using namespace std ;

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
   return '"' + s + '"';
}

string to_string(const char* s) {
   return to_string((string) s);
}

string to_string(bool b) {
   return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
   bool first = true;
   string res = "{";
   for (int i = 0; i < static_cast<int>(v.size()); i++) {
         if (!first) {
            res += ", ";
         }
   first = false;
   res += to_string(v[i]);
   }
   res += "}";
   return res;
}

template <size_t N>
string to_string(bitset<N> v) {
   string res = "";
   for (size_t i = 0; i < N; i++) {
         res += static_cast<char>('0' + v[i]);
   }
   return res;
}

template <typename A>
string to_string(A v) {
   bool first = true;
   string res = "{";
   for (const auto &x : v) {
         if (!first) {
               res += ", ";
         }
    first = false;
    res += to_string(x);
   }
   res += "}";
   return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
   return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
   return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
   return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
   cerr << " " << to_string(H);
   debug_out(T...);
}

#ifndef ONLINE_JUDGE
#define debug(...) cerr<<"LINE ("<< __LINE__ << ") : [" << #__VA_ARGS__ << "] -> ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void solve(int id){
    int a, b;
    cin >> a >> b;
    if(a == 2 || b == 2){
        cout << "No" ; 
    }else{
        cout << "Yes"; 
    }
}

int main(){
   FASTIO 
   //freopen("in1.txt" , "r" , stdin) ; 

   int T = 1;
   //cin >> T ;
   for (int id = 1; id <= T; ++id){
      solve(id);
   }

   cerr << "\n\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
   return 0 ;
}




Measured memory_bytes: 3776
#include<iostream>
#define MAX_N 100
using namespace std;

int n, u, k, v;
int Adj[MAX_N][MAX_N];

void initialize(){
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			Adj[i][j] = 0;
		}
	}
}

void check_adj(){
	Adj[u][v] = 1;
}

void print_adj(){
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			cout << Adj[i][j];
			if(j == n - 1) cout << endl;
			else cout << " ";
		}
	}
}

int main(void){
	cin >> n;
	initialize();
	for(int i = 0; i < n; i++){
		cin >> u;
		u--;
		cin >> k;
		for(int j = 0; j < k; j++){
			cin >> v;
			v--;
			check_adj();
		}
	}
	print_adj();

	return 0;
}

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll F[100];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    F[0] = F[1] = 1;
    FOR(i, N + 1, 2) {
        F[i] = F[i - 1] + F[i - 2];
    }
    cout << F[N] << endl;
    return 0;
}


Measured memory_bytes: 3132
#include <iostream>
using namespace std;
#define MAX 45

int main(){
  int fibo[MAX];
  int n;
  fibo[0] = fibo[1] = 1;
  for(int i = 2; i < MAX; i++)
    fibo[i] = fibo[i-1] + fibo[i-2];

  cin >> n;
  cout << fibo[n] << endl;
}

Measured memory_bytes: 1160
import java.util.Scanner;

class Main{
    public static void main(String[] args){
		Scanner scanner = new Scanner(System.in);
		int i = 0;
    	while(true){
    		int x = scanner.nextInt();
    		if(x == 0) break;
    		System.out.println("Case "+(i+1)+": "+x);
    		i++;
    	}
    }
}

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

int main() {
	
	int n; cin >> n;
	int sum = 0;
	vector<int> s(n);
	vector<int> c;
	for (int i = 0; i < n; i++) {
		cin >> s[i];
		sum += s[i];
		if (s[i] % 10 != 0) {
			c.push_back(s[i]);
		}
	}
	if (c.size() == 0) {
		cout << 0 << endl;
		return 0;
	}
	sort(c.begin(), c.end());
	if (sum % 10 == 0) {
		sum -= c[0];
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}

ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

ll n, m, p, a, b;
double t[10];

struct edge {
	ll to;
	double cost;
};

struct PP {
	double dis;
	ll pos;
	ll num;

	PP(double _dis, ll _pos, ll _num) :dis(_dis), pos(_pos), num(_num) {}

	bool operator<(const PP& p) const { return dis < p.dis - EPS; }
	bool operator>(const PP& p) const { return dis - EPS > p.dis; }
	bool operator<=(const PP& p) const { return dis < p.dis + EPS; }
	bool operator>=(const PP& p) const { return dis + EPS > p.dis; }
};

double d[100][1 << 9];
vector<edge> G[100];//各頂点からの辺
priority_queue<PP, vector<PP>, greater<PP>> que;

void dijkstra(ll start) {
	rep(i, 100)rep(j, (1 << 9))d[i][j] = INF;
	d[start][0] = 0;
	que.push(PP(0, start, 0));

	while (!que.empty()) {
		PP p = que.top();
		que.pop();
		ll v = p.pos;
		ll nn = p.num;
		if (d[v][nn] < p.dis)continue;
		for (int i = 0; i < G[v].size(); i++) {
			edge e = G[v][i];
			rep(j, n) {
				if ((1 << j)&nn)continue;
				double ncost = e.cost / t[j];
				ll nnum = nn | (1 << j);
				if (d[e.to][nnum] > d[v][nn] + ncost) {
					d[e.to][nnum] = d[v][nn] + ncost;
					que.push(PP(d[e.to][nnum], e.to, nnum));
				}
			}
		}
	}
}

void clear() {
	while (!que.empty())que.pop();
	rep(i, 100)G[i].clear();
}

int main() {
	while (cin >> n >> m >> p >> a >> b&&n + m + p + a + b) {
		clear();
		rep(i, n)cin >> t[i];
		sort(t, t + n);
		reverse(t, t + n);
		rep(i, p) {
			ll x, y;
			double z;
			cin >> x >> y >> z;
			G[x].push_back({ y,z });
			G[y].push_back({ x,z });
		}
		dijkstra(a);
		double mincost = INF;
		rep(i, (1 << n)) {
			//cout << i << " " << dk.d[b][i] << endl;
			mincost = min(mincost, d[b][i]);
		}
		if (mincost == INF)cout << "Impossible" << endl;
		else printf("%.10lf\n", mincost);
	}
}


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

using namespace std;

#define mp make_pair
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define allarr(a) a , a + n
#define ll long long
#define pb push_back
#define fastio ios_base::sync_with_stdio(false) ; cin.tie(NULL); cout.tie(NULL)
typedef pair<int, int> pi;
typedef pair<ll,ll> pll; 
typedef pair<int,pi> trp ;
typedef vector<pi> vpi;
typedef vector<pll> vpll ; 
ll _abs (ll x ) { return (x>0?x:-x); }

const int N = 1e5+5   ;

int dp[N][3] ;  // max fun at day i new activity day with j 
int fun[N][3] , n ;  // FUN AT DAY i activitiy j 
int solve (int i , int l ){
    int& r  =dp[i][l] ; 
    if( r != -1 )return r; 
    if( i== n )return 0 ; 
    for(int j=0;j<3;j++)if(l!=j)r=max(fun[i][j]+solve(i+1,j),r); 
    return r ; 
}
int main(){
    cin>> n ; 
    for(int i =0 ; i < n ;i++ ){
        cin>>fun[i][0]>>fun[i][1]>>fun[i][2]; 
    }
    // base case 
    memset(dp,-1,sizeof dp ) ; cout<<solve(0,3)<<endl; return 0 ; 
    for(int i=0;i<3;i++)dp[0][i] = fun[0][i]; 
    for(int i=1;i<n;i++){
        for(int j = 0 ; j < 3 ; j++ ){// new activity
            for(int k=0;k<3;k++){// last activity
                if( j != k ) // cant be same activity twice
                    dp[i][j] = max(dp[i][j] , dp[i-1][k] + fun[i][j]); 
            }
        }
    }
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl; 
}

Measured memory_bytes: 10368
using System;
using System.Collections.Generic;

namespace abc114_c
{
	class Program
	{
		static void Main(string[] args)
		{
			List<string>[] list = new List<string>[10];
			list[0] = new List<string> { "" };
			for (int i = 1; i < 10; i++)
			{
				list[i] = new List<string>();
				foreach (var item in list[i - 1])
				{
					list[i].Add(item + "3"); list[i].Add(item + "5"); list[i].Add(item + "7");
				}
			}
			int n = int.Parse(Console.ReadLine());
			int ret = 0;
			for (int i = 3; i < 10; i++)
			{
				foreach (var item in list[i])
				{
					int a = 0; int b = 0; int c = 0;
					for (int j = 0; j < item.Length; j++)
					{
						switch (item[j])
						{
							case '3': { a++; break; }
							case '5': { b++; break; }
							case '7': { c++; break; }
						}
					}
					if (int.Parse(item) <= n && a > 0 && b > 0 && c > 0) ret++;
				}
			}
			Console.WriteLine(ret);
		}
	}
}


Measured memory_bytes: 13792
// D - 3N Numbers
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VL = vector<ll>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define irp(i,s,e) for(int i=(s);i>(e);--i)
#define pq priority_queue

int main(){
	int N;
	cin>>N;
	int N2 = N*2;
	int N3 = N*3;
	VL A(N3);
	rp(a, 0, N3) cin>>A[a];

	VL F(N+1);
	pq<int> fque;
	rp(a, 0, N){
		fque.push(-A[a]);
		F[0] += A[a];
	}
	for(int a=N, f=0; f<N; ++f, ++a){
		fque.push(-A[a]);
		F[f+1] = F[f] + A[a] - (-fque.top());
		fque.pop();
	}

	VL B(N+1);
	pq<int> bque;
	irp(a, N3-1, N2-1){
		bque.push(A[a]);
		B[N] += A[a];
	}
	for(int a=N2-1, b=N; b>0; --b, --a){
		bque.push(A[a]);
		B[b-1] = B[b] + A[a] - (bque.top());
		bque.pop();
	}

	ll maxfb = LLONG_MIN;
	rp(i, 0, N+1) maxfb = max(maxfb, F[i]-B[i]);
	cout<< maxfb <<endl;
}

Measured memory_bytes: 5368
n, m = [int(i) for i in input().split()]
forward = [0 for i in range(n)]
backward = [0 for i in range(n)]
for i in range(m):
    a, b = [int(_) for _ in input().split()]
    if a == 1:
        forward[b] = 1
    elif  b == 1:
        forward[a] = 1
    elif a == n:
        backward[b] = 1
    elif b == n:
        backward[a] = 1
flag = False
for i in range(n):
    if forward[i] == 1 and backward[i] == 1:
        flag = True
        break
if flag:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Measured memory_bytes: 6320
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i = 0; i < n; i++)
#define rep2(i,start,end) for(ll i = start; i < end; i++)
#define dwn(i,n) for(int i = n; i >= 0; i--)
#define dwn2(i,start,end) for(ll i = start; i >= end; i--)
#define pll pair<ll,ll>
#define mk(x,y) make_pair(x,y)
#define pdl pair<double, ll>
const ll N = 4e5 + 200;
const ll INF = 9999999999;
const ll mod = 1e9 + 7;


int main(){
	char c;
	cin>>c;
	printf("%c",c+1);


	return 0;
}





Measured memory_bytes: 256
from bisect import bisect_left as bil
N, K, *V = map(int, open(0).read().split())


k = min(N, K)
ans = 0
for i in range(k+1):
    for j in range(k-i+1):
        U = V[:i]+V[-j:] if j != 0 else V[:i]
        U.sort()
        z = min(bil(U, 0), K-i-j)
        sm = sum(U[z:])

        if ans < sm:
            ans = sm

print(ans)


Measured memory_bytes: 3188
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <math.h> // sqrt
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <iomanip> // setprecision
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long>>;
using pii = pair<int, int>;
using psi = pair<string, int>;

void count (vector<string> &data, string str) {
    int ans = 0;
    for (string s : data) {
        if (s == str) {
            ans++;
        }
    }
    cout << str << " " << "x" << " " << ans << endl;
}

int main() {
    int N;
    cin >> N;
    vector<string> data(N);
    for (int i = 0; i < N; i++) {
        cin >> data.at(i);
    }
    count(data, "AC");
    count(data, "WA");
    count(data, "TLE");
    count(data, "RE");
}

Measured memory_bytes: 6420
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
    public static void main (String[] args) throws FileNotFoundException {

        Scanner sc =  new Scanner(System.in);

        int k = sc.nextInt();
        int n = sc.nextInt();
        int[] a = new int[n];
        int[] res = new int[n];
        for (int i =0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        for (int i = 1; i < n; i++) {
            res[i] = a[i] - a[i - 1];
        }
        res[0] = (k - a[n - 1]) + a[0];

        int in = 0;
        for (int i = 1; i < n; i++) {
            if (Math.max(res[in], res[i]) == res[i]) {
                in = i;
            }
        }
        System.out.println(k - res[in]);
    }
}


Measured memory_bytes: 85128