akhauriyash/Code-Regression huggingface dataset:
n, k = map(int, input().strip().split())
hs = sorted([int(input()) for _ in range(n)])

ans = 1e15

for i in range(n - k + 1):
    h_max = hs[i + k - 1]
    h_min = hs[i]
    ans = min(h_max - h_min, ans)

print(ans)


Measured memory_bytes: 8280
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int[] t=new int [n];
		int[] x=new int [n];
		int[] y=new int [n];
		int[] d=new int [n];

		for(int i=0;i<n;i++) {
			t[i]=sc.nextInt();
			x[i]=sc.nextInt();
			y[i]=sc.nextInt();
		}
		d[0]=x[0]+y[0];
		if(t[0]<d[0]||(t[0]+d[0])%2==1) {
			System.out.println("No");
			return;
		}
		for(int i=n-1;i>=1;i--) {
			t[i]-=t[i-1];
			d[i]=Math.abs(x[i]-x[i-1])+
					Math.abs(y[i]-y[i-1]);
			if(t[i]<d[i]||(t[i]+d[i])%2==1) {
				System.out.println("No");
				return;
			}
		}
		System.out.println("Yes");
		return;



		}
	}


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

int main() {
  int n, a, b, p, l=0, m=0, r=0;
  cin >> n >> a >> b;
  for(int i = 0; i < n; i++) {
    cin >> p;
    if(p <= a) l++;
    else if(a < p and p <= b) m++;
    else r++;
  }
  cout << min({l, m, r}) << "\n";
}

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

const ll N = 1e5+3;
ll m[N] = {0} ;

int main() {
	// your code goes here
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
	
	ll n,q,n1,n2,sum,val;
	cin>>n;
	//int a[n];
	sum = 0;
	//int m[10001] = {0};
	for(int i=0;i<n;i++){
	    cin>>val;
	    sum = sum + val;
	    m[val]++;
	}
	cin>>q;
	for(int i=0;i<q;i++){
	    cin>>n1>>n2;
	    
	    sum += (n2-n1)*m[n1];
	    cout<<sum<<"\n";
	    m[n2] += m[n1];//if  not present or zero scenario
	    m[n1] = 0;
	}
	
	return 0;
}


Measured memory_bytes: 4432
#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS

#include <bits/stdc++.h>
using namespace std;
#define error(args...)                       \
{                                            \
    cerr<<"LINE "<<__LINE__;                 \
    string _s = #args;                       \
    replace(_s.begin(), _s.end(), ',', ' '); \
    stringstream _ss(_s);                    \
    istream_iterator<string> _it(_ss);       \
    err(_it, args);                          \
    cerr<<endl;                              \
}
void err(istream_iterator<string> it)
{
} 
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
  cerr<<' '<< *it << " = " << a ;
  err(++it, args...);
}

typedef long long ll;
const ll MOD = 1e9 + 7;
const int N = 2e5 + 1, M = 1e6, OO = 0x3f3f3f3f;
ll p[N];
double xpx[N];
int main()
{
  
  int n,k;
  scanf("%d%d",&n,&k);
  for(int i=0;i<n;++i)
  {
    scanf("%d",p+i);
    xpx[i]=(p[i]*(p[i]+1)/2.0)/(p[i]*1.0);
  }
  double curr=0,mx=0;
  int l=0,r=k;
  for(int i=0;i<k;++i) curr+=xpx[i];
  mx=curr;
  while(l<r && r<n)
  {
    curr-=xpx[l++];
    curr+=xpx[r++];
    mx=max(mx,curr);
  }
  printf("%.12lf\n",mx);
  
  #ifdef _LOCAL_DEFINE
  cerr << (double)clock() * 1.0 / CLOCKS_PER_SEC << endl;
  #endif
  return 0;
}

Measured memory_bytes: 3328
import math

A, B, H, M = map(int, input().split())

h_p = (H + M / 60) * 30
m_p = M * 6

ang = abs(h_p - m_p)

ans = math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(math.radians(ang)))
print(ans)

Measured memory_bytes: 9500
#include <stdio.h>
int main(void){
    int h,n,a,i,sum=0;
    scanf("%d%d",&h,&n);
    for(i=0;i<n;i++){
        scanf("%d",&a);
        sum+=a;
    }
    if(sum>=h) printf("Yes");
    else printf("No");
    return 0;
}

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

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

using ll = long long;
using P = pair<int,int>;


int main()
{
    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    rep(i, n) cin >> c[i];
    sort(all(a));
    sort(all(c));


    ll ans = 0;
    rep(i, n){
        ll aa = lower_bound(all(a), b[i]) - a.begin();
        ll cc = c.end() - upper_bound(all(c), b[i]);

        ans += aa * cc;
    }

    cout << ans << "\n";


    return 0;
}


Measured memory_bytes: 1408
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)


using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;



int main(){
    int n;
    cin >> n;
    VEC(int, a, n);
    sort(ALL(a));
    ll res = INF * INF;
    REP(i, -100, 100){
        ll sum = 0;
        rep(j, n){
            sum += ((i - a[j]) * (i - a[j]));
        }
        res = min(res, sum);
    }
    cout << res << endl;
}

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

#define REP(i, s, e) for(int i = (int)(s); i < (int)(e); ++i)
#define rep(i, n) REP(i, 0, n)

#define X real()
#define Y imag()

using D = double;
using P = complex<D>;
using G = vector<P>;

const D EPS = 1e-10;
namespace std {
  bool operator < (const P& a, const P& b) {
    return a.X != b.X ? a.X < b.X : a.Y < b.Y;
  }
};

struct L : array<P, 2> {
  L () = default;
  L(const P& a, const P& b) {
    front() = a;
    back() = b;
  }
  P vec() const {
    return back() - front();
  }
};
D dot(const P& a, const P& b) {
  return (conj(a)*b).X;
}
D cross(const P& a, const P& b) {
  return (conj(a)*b).Y;
}
int ccw(P a, P b, P c) {
  b -= a;
  c -= a;
  if(cross(b, c) > 0) return +1; // ccw
  if(cross(b, c) < 0) return -1; // cw
  if(dot(b, c) < 0) return +2; // L c-a-b
  if(norm(b) < norm(c)) return -2; // L a-b-c
  return 0;
}

bool intersectLL(const L& l, const L& m) {
  return abs(cross(l.vec(), m.vec())) > EPS ||
    abs(cross(l[1] - l[0], m[0] - l[0])) < EPS;
}

P projection(const L& l,const P& p) {
  D t = dot(p-l[0], -l.vec()) / norm(-l.vec());
  return l[0] + t*(-l.vec());
}
P refrection(const L& l, const P& p) {
  return p  + 2.0 * (projection(l, p) - p);
}

D area(const G& g) {
  int n = g.size();
  D s = 0.0;
  rep(i, n) {
    int j = (i+1)%n;
    s += cross(g[i], g[j]);
  }
  return abs(s) / 2.0;
}

vector<string> split(const string& s, char c = ' ') {
  stringstream ss(s);
  vector<string> ret;
  string t;
  while(getline(ss, t, c)) ret.push_back(t);
  return ret;
}
int main() {
  cout << fixed << setprecision(1);  
  int testcase = 0;
  int n = 0;
  while(cin >> n) {
    if(n == 0) break;
    G g;
    rep(i, n) {
      D x, y;
      cin >> x >> y;
      g.emplace_back(x, y);
    }
    cout << ++testcase << " " << area(g) << endl;
  }
  return 0;
}



Measured memory_bytes: 3108
#include<iostream>

using namespace std;

int main(int argc, char **argv) {
    int a, b, c, count;

    cin >> a >> b >> c;

    if (a + b >= c) count = c + b;
    else    count = a + 2 * b + 1;

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
//kuch motivational line which i cannot think of coz i lack motivation

#include<bits/stdc++.h>//works like magic, but at cost
using namespace std;

#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define int long long
#define mod 100000009
void solve() { 
    int n,m;
    cin>>n>>m;
    int sum = 0;
    float a[n];
    for(int i=0; i<n; i++){
        cin>>a[i];
        sum+=a[i];
    }
    
    sort(a,a+n,greater<int>());
    
    for(int i=0; i<m; i++){
        
        float val = (1 / (float)(4*m))*sum;
        
        if(a[i]<val){
            cout<<"No"<<endl;
            return;
        }
        
    }
    cout<<"Yes"<<endl;
}

int32_t main() {
    fastio;
    int t = 1;
    // cin>>t;
    while(t--)solve();
    return 0;
}

Measured memory_bytes: 256
/*
          , -- 、
        /;;;;;;', 　　　
        i二二二i
      , ' 　    ヽ ???
     i　ﾉﾉﾉﾉﾉﾍ .', 　　
     〉ﾘi' ﾟ ヮﾟﾉﾚく　 WAyon..........
  ○⊂}〈lﾄ--ｲl〉{つ● 　　
      ,ｒ/ー i-ヽヽ 　　　
     ｀｀i_ﾗi_ﾗ
*/

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
const int INF=(int)1e12;
const int mod=(int)1e9+7;
#define all(a) (a).begin(),(a).end()
typedef vector<vector<int>> graph;

#define pb push_back

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

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



signed main () {
    int n;cin >>n;
    cout <<(n>=30?"Yes":"No")<<endl;
}





Measured memory_bytes: 3592
//mangesh2102000

#include <bits/stdc++.h>
using namespace std;

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define int long long int 
#define ld long double
#define pb push_back
#define tr(c,it) for(auto it = (c).begin(); it != (c).end(); ++it)
#define F first
#define S second
#define mod 1000000000

int n;
int h[100005];
int dp[100005];

int solve1(int c)
{
    if(dp[c]!=-1)
        return dp[c];

    if(c==1)
        return dp[1]=0;

    if(c==2)
        return dp[c] = solve1(c-1)+abs(h[c]-h[c-1]); 

    if(c>2)
    return dp[c] = min(solve1(c-1)+abs(h[c]-h[c-1]),solve1(c-2)+abs(h[c]-h[c-2]));

    return -1;
}

void solve(int t)
{
    cin >> n;

    for(int i=1;i<=n;i++)
    {
        cin >> h[i];
        dp[i] = -1;
    }

    solve1(n);

    cout << dp[n];

    //cout << "Case #" << t << ": " << ;
}   


int32_t main()
{
    IOS;
    int t;
    t=1;
    for(int i=1;i<=t;i++)
    {
        solve(i);
    }

    return 0;
}

Measured memory_bytes: 3328
#include <stdio.h>
int main(void)
{
int x,y;

while(1){
 scanf("%d %d",&x,&y);
    if( x == 0 && y == 0 ) break;
   if( x >= y )
      printf("%d %d\n",y,x);
    if( x < y )
      printf("%d %d\n",x,y);
}

return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

int main(int argc, char const *argv[])
{
	double x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	cout << setprecision(10) << sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1)) << endl;
	return 0;
}

Measured memory_bytes: 3252
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXN=10005;
int n,k,ans,t,la=2;
int ansn,Ans1[MAXN],Ans2[MAXN];
void Print(){
	printf("%d\n",ansn);
	for(int i=1;i<=ansn;i++)
		printf("%d %d\n",Ans1[i],Ans2[i]);
}
int main(){
	scanf("%d%d",&n,&k);
	if((n-1)*(n-2)/2<k){
		printf("-1\n");
		return 0;
	}
	for(int i=2;i<=n;i++){
		ansn++;
		Ans1[ansn]=1;
		Ans2[ansn]=i;
	}
	t=(n-1)*(n-2)/2-k;
	for(int i=2;i<=n;i++)
		for(int j=i+1;j<=n;j++){
			if(t==0){
				Print();
				return 0;
			}
			t--;
			ansn++;
			Ans1[ansn]=i;
			Ans2[ansn]=j;
		}
	Print();
}

Measured memory_bytes: 256
from collections import defaultdict,deque
n=int(input())
edges=[tuple(map(int,input().split())) for _ in range(n-1)]
q,k=map(int,input().split())
xy=[tuple(map(int,input().split())) for _ in range(q)]

stack=[-1]*(n+1)
stack[k]=0
ed=defaultdict(list)
wt=defaultdict(int)
for e in edges:
  ed[e[0]].append(e[1])
  ed[e[1]].append(e[0])
  wt[(e[0],e[1])]=e[2]
  wt[(e[1],e[0])]=e[2]
ce=deque([(k,x) for x in ed[k]])
ne=deque()
while True:
  while ce:
    e=ce.pop()
    stack[e[1]]=stack[e[0]]+wt[e]
    for v in ed[e[1]]:
      if stack[v]<0:
        ne.append((e[1],v))
  if not ne:
    break
  ce.extend(ne)
  ne.clear()

for que in xy:
  print(stack[que[0]]+stack[que[1]])

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

int main() {
  int N;
  cin >> N;
  int total = 0;

  int continuous = false;

  for(int i=0;i<N;i++) {
    int a;
    cin >> a;
    if(!continuous && a == i+1) {
      continuous = true;
      total++;
    } else {
      continuous = false;
    }
  }

  cout << total << endl;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author anand.oza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AFavoriteSound solver = new AFavoriteSound();
        solver.solve(1, in, out);
        out.close();
    }

    static class AFavoriteSound {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int a = in.nextInt(), b = in.nextInt(), c = in.nextInt();

            out.println(Math.min(c, b / a));
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }
}



Measured memory_bytes: 25172
//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//~ #pragma GCC target ("avx2")
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")
#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;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define shandom_ruffle random_shuffle

using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
const int nax=5007;
const ll mod=1000*1000*1000+7;

int n, a, b;

void dod(ll &a, ll b)
{
	if ((a+=b)>=mod)
		a-=mod;
}

void sdod(ll &a, ll b)
{
	a=(a+b)%mod;
}

ll dpjuz[nax];
ll dpzer[nax][nax];
ll dpjed[nax][nax];

ll pch[nax];

int main()
{
	scanf("%d%d%d", &n, &a, &b);
	if (a>b)
		swap(a, b);
	if (b==1)
	{
		ll ret=1;
		for (int i=1; i<=n; i++)
			ret=(ret*2)%mod;
		printf("%lld\n", ret);
		return 0;
	}
	dpjed[0][0]=1;
	for (int i=0; i<n; i++)
	{
		dod(pch[i+1], pch[i]);
		dod(dpjed[i+1][1], pch[i]);
		for (int j=0; j<b; j++)
		{
			//~ debug() << "robie " << i << " " << j;
			{//dok 1
				if (j+1==b)
					dod(dpjuz[i+1], dpjed[i][j]);
				else
					dod(dpjed[i+1][j+1], dpjed[i][j]);
			}
			
			{//dok 0
				//~ dod(dpjed[i+1][0], dpjed[i][j]);
				//~ if (i+a<=n)
					//~ dod(dpjed[i+a][0], mod-dpjed[i][j]);
					
				dod(pch[i+1], dpjed[i][j]);
				if (i+a<=n)
					dod(pch[i+a], mod-dpjed[i][j]);
			}
			
			{//dok a 0
				if (i+a<=n)
				{
					if (j+a>=b)
						dod(dpjuz[i+a], dpjed[i][j]);
					else
						dod(dpzer[i+a][j+a], dpjed[i][j]);
				}
			}
			
			if (j+1==b)
			{
				dod(dpjuz[i+1], dpzer[i][j]);
				dod(dpjuz[i+1], dpzer[i][j]);
			}
			else
			{
				dod(dpzer[i+1][j+1], dpzer[i][j]);
				dod(dpjed[i+1][j+1], dpzer[i][j]);
			}
			//~ debug() << i << " " << j << " " << imie(dpjed[i][j]) << imie(dpzer[i][j]);
			//~ debug();
		}
	}
	//~ debug() << range(dpjuz+1, dpjuz+1+n);
	for (int i=1; i<=n; i++)
	{
		dod(dpjuz[i], dpjuz[i-1]);
		dod(dpjuz[i], dpjuz[i-1]);
	}
	printf("%lld\n", dpjuz[n]);
	return 0;
}


Measured memory_bytes: 395072
import java.io.*;
import java.util.*;

public class Main implements Runnable {
    static ContestScanner in;
    static Writer out;
    public static void main(String[] args) {
        new Thread(null, new Main(), "", 16 * 1024 * 1024).start();
    }

    public void run() {
        Main main = new Main();
        try {
            in = new ContestScanner();
            out = new Writer();
            main.solve();
            out.close();
            in.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    void solve() throws IOException {
        int n = in.nextInt();
        int[] a = new int[n + 1];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }
        if (a[0] > 0) {
            System.out.println(-1);
            return;
        }
        long cnt = 0;
        for (int i = 0; i < n; i++) {
            if (a[i] + 1 == a[i + 1]) {

            } else if (a[i] >= a[i + 1]) {
                cnt += a[i];
            } else {
                System.out.println(-1);
                return;
            }
        }
        System.out.println(cnt);
    }
}

class Writer extends PrintWriter{
    public Writer(String filename)throws IOException
    {super(new BufferedWriter(new FileWriter(filename)));}
    public Writer()throws IOException {super(System.out);}
}
class ContestScanner implements Closeable {
    private BufferedReader in;private int c=-2;
    public ContestScanner()throws IOException
    {in=new BufferedReader(new InputStreamReader(System.in));}
    public ContestScanner(String filename)throws IOException
    {in=new BufferedReader(new InputStreamReader(new FileInputStream(filename)));}
    public String nextToken()throws IOException {
        StringBuilder sb=new StringBuilder();
        while((c=in.read())!=-1&&Character.isWhitespace(c));
        while(c!=-1&&!Character.isWhitespace(c)){sb.append((char)c);c=in.read();}
        return sb.toString();
    }
    public String readLine()throws IOException{
        StringBuilder sb=new StringBuilder();if(c==-2)c=in.read();
        while(c!=-1&&c!='\n'&&c!='\r'){sb.append((char)c);c=in.read();}
        return sb.toString();
    }
    public long nextLong()throws IOException,NumberFormatException
    {return Long.parseLong(nextToken());}
    public int nextInt()throws NumberFormatException,IOException
    {return(int)nextLong();}
    public double nextDouble()throws NumberFormatException,IOException
    {return Double.parseDouble(nextToken());}
    public void close() throws IOException {in.close();}
}


Measured memory_bytes: 47448
package main

// https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/all/ALDS1_9_B

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() (int, error) {
	return strconv.Atoi(nextString())
}

func main() {
	scanner.Split(bufio.ScanWords)

	h, _ := nextInt()
	arr := make([]int, h)
	for i := range arr {
		arr[i], _ = nextInt()
	}

	for i := range arr {
		fmt.Printf("node %d: key = %d, ", i+1, arr[i])
		if i != 0 {
			fmt.Printf("parent key = %d, ", arr[(i-1)/2])
		}
		if i < len(arr)/2 {
			fmt.Printf("left key = %d, ", arr[2*i+1])
			if 2*(i+1) < len(arr) {
				fmt.Printf("right key = %d, ", arr[2*(i+1)])
			}
		}
		fmt.Println("")
	}
}



Measured memory_bytes: 1112
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>

#define rep(i,n) for(int i=0;i<n;i++)
#define dup(x,y) (((x)+(y)-1)/(y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;

int main() {
	int A, B, C;
	cin >> A >> B >> C;
	int ans = 0;
	if(A-B > C) cout << 0 << endl;
	else cout << (C-(A-B)) << endl;
	
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;



int main(void) {

    int n;
    cin>>n;
    cout<<ceil(n/2.0)<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


	int N, M;
	cin >> N >> M;
	int A[300][300];
	int R[300][300];
	rep(i, N) rep(j, M) {
		cin >> A[i][j];
		A[i][j]--;
		R[i][A[i][j]] = j;
	}

	bool C[300][310] = {};
	int doko[300] = {};
	int kotae = 1e9;
	rep(j, M) {
		int B[300] = {};
		rep(i, N) B[A[i][doko[i]]]++;
		auto saidaip = max_element(B, B + M);
		kotae = min(kotae, *saidaip);
		int kesu = saidaip - B;
		rep(i, N) {
			C[i][R[i][kesu]] = true;
			while (C[i][doko[i]]) doko[i]++;
		}
	}

	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <cmath>
#include <bitset>
using namespace std;

typedef long long ll;
typedef pair<int,int> Pi;
const ll inf = 1e18 + 1;
const ll limit = 1e9;

int main() {
    int a,b; cin >> a >> b;
    bool ok = false;
    int ans;
    for (int i = 1; i <= (b + 1) * 10; i++) {
        int res1 = i * 8 / 100;
        int res2 = i / 10;
        if (res1 == a && res2 == b) {
            ok = true;
            ans = i;
            break;
        }
    }
    if (ok) cout << ans << "\n";
    else cout << -1 << "\n";
}   
 

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

//typedef
//------------------------------------------
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define PB push_back
#define MP make_pair
#define SORT(c) sort((c).begin(),(c).end())
#define COUT(x) cout<<x<<endl

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double PI = acos(-1.0);
const LL MOD = 1e9 + 7;
const ULL INF= 1e20;

//function
//--------------------------------------------
LL gcd(LL, LL);
bool isEven(LL);

int main() {
	int a, b;
	cin >> a >> b;
	if (a <= b)COUT(a);
	else COUT(a - 1);
	return 0;
}

LL gcd(LL a, LL b) {
	if (a == 0 || b == 0)return 0;
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	else gcd(b, a % b);
}
bool isEven(LL a) {
	return !((bool)(a % 2));
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		List<Integer> A = new ArrayList<>();
		List<Integer> B = new ArrayList<>();
		List<Integer> C = new ArrayList<>();
		for (int i = 0; i < N; i++) {
			A.add(scanner.nextInt());
		}
		for (int i = 0; i < N; i++) {
			B.add(scanner.nextInt());
		}
		for (int i = 0; i < N - 1; i++) {
			C.add(scanner.nextInt());
		}
		scanner.close();
		int score = 0;
		int tmp = 0;
		for (int i = 0; i < N; i++) {
			int num = A.get(i);
			int current_score = B.get(num - 1);
			score += current_score;
			if (i != 0 && tmp + 1 == num) {
				score += C.get(tmp - 1);
			}
			tmp = num;
		}
		System.out.println(score);
	}
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> V(N), C(N);
  for(auto* v: {&V, &C}) for(auto& i: *v) cin >> i;
  auto ans = 0;
  for(auto bit = 1; bit < (1 << N); ++bit) {
    auto X = 0, Y = 0;
    for(auto i = 0; i < N; ++i) if((bit >> i) & 1) {
      X += V[i];
      Y += C[i];
    }
    ans = max(ans, X - Y);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static AtCoder.Io;
 
namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            var s = ReadStringArray();
            Console.WriteLine($"{string.Concat(s.Select(v => char.ToUpper(v[0])))}");
        }
    }
 
    public static class Io
    {
        public static string ReadString() => Console.ReadLine();
        public static string[] ReadStringArray() => ReadString().Split(' ');
        public static int ReadInt() => int.Parse(ReadString());
        public static long ReadLong() => long.Parse(ReadString());
        public static int[] ReadIntArray() => ReadStringArray().ParseInt().ToArray();
        public static long[] ReadLongArray() => ReadStringArray().ParseLong().ToArray();
        public static IEnumerable<int> ParseInt(this IEnumerable<string> source) => source.Select(int.Parse);
        public static IEnumerable<long> ParseLong(this IEnumerable<string> source) => source.Select(long.Parse);
    }
}

Measured memory_bytes: 13268
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        
        int H = sc.nextInt();
        int W = sc.nextInt();
        String[] S = new String[H];
        for(int i = 0; i < H; i++) S[i] = sc.next();

        for(int i = 0; i < W + 2; i++){
            System.out.print("#");
        }
        System.out.println("");
        for(int i = 0; i < H; i++){
            System.out.println("#" + S[i] + "#");
        }
        for(int i = 0; i < W + 2; i++){
            System.out.print("#");
        }
    }
}


Measured memory_bytes: 22996
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <climits>
#include <utility>
typedef long long ll;
using namespace std;

int main(int argc, char *argv[]) {
  const int INF = 1 << 30;
  const int dx[4] = {1,0,-1,0};
  const int dy[4] = {0,1,0,-1};

  int h, w, i, j;
  int ch, cw, dh, dw;

  cin >> h >> w;
  cin >> ch >> cw;
  ch--, cw--;
  cin >> dh >> dw;
  dh--, dw--;

  vector<string> s(h);
  for(i=0;i<h;i++){
    cin >> s[i];
  }

  vector<vector<int> > ans(h,vector<int>(w,INF));

  priority_queue<pair<int,pair<int,int> > > q;

  q.push({0,{ch,cw}});
  ans[ch][cw] = 0;

  int dist;
  int x, y, nx, ny;

  while(!q.empty()){
    dist = q.top().first * -1;

    x = q.top().second.first;
    y = q.top().second.second;
    q.pop();

    if(dist>ans[x][y]) continue;

    for(i=0;i<4;i++){
      nx = x + dx[i];
      ny = y + dy[i];
      if(nx<0||h<=nx||ny<0||w<=ny){
        continue;
      }

      if(s[nx][ny]=='.'&&ans[nx][ny]>dist){
        ans[nx][ny] = dist;
        q.push({dist*-1,{nx,ny}});
      }
    }

    for(i=-2;i<=2;i++){
      for(j=-2;j<=2;j++){
        nx = x + i;
        ny = y + j;
        if(nx<0||h<=nx||ny<0||w<=ny){
          continue;
        }

        if(ans[nx][ny]>dist+1&&s[nx][ny]=='.'){
          ans[nx][ny] = dist + 1;
          q.push({(dist+1)*-1,{nx,ny}});
        }
      }
    }
  }

  if(ans[dh][dw]==INF){
    cout << -1 << endl;
  }
  else{
    cout << ans[dh][dw] << endl;
  }

  return 0;
}


Measured memory_bytes: 9476
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N,A,B;cin >> N >> A >> B;
  cout << min(A*N,B) << endl;
  return 0;
}


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

struct Vertex {
    vector<pll> node;
};

Vertex V[100005];
ll C[100005];

int main() {
    ll N, M, R;
    cin >> N >> M >> R;
    REP(i, M) {
        ll a, b, c;
        cin >> a >> b >> c;
        V[a].node.push_back(pll(b, c));
    }
    REP(i, N) {
        C[i] = INF;
    }

    priority_queue<pll, vector<pll>, function<bool(pll, pll)>> q([](pll a, pll b) { return a.second > b.second; });

    q.push(pll(R, 0));
    while (!q.empty()) {
        pll t = q.top();
        q.pop();

        if (C[t.first] <= t.second)
            continue;
        C[t.first] = t.second;
        REP(i, V[t.first].node.size()) {
            pll n = V[t.first].node[i];
            ll c = t.second + n.second;
            if (C[n.first] <= c)
                continue;
            q.push(pll(n.first, c));
        }
    }

    REP(i, N) {
        if (C[i] == INF)
            cout << "INF" << endl;
        else
            cout << C[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 21532
import java.util.Scanner;
import java.util.ArrayList;


class Main{
	public static void main(String[] args){
		Solve s = new Solve();
		s.solve();
	}	
}

class Solve{
	Solve(){}

	void solve(){
		Scanner in = new Scanner(System.in);

		int n = in.nextInt();
		int [][] ar = new int[n][n];

		for(int i = 0; i < n; i++){
			int u = in.nextInt() - 1, k = in.nextInt();
			for(int j = 0; j < k; j++){
				int v = in.nextInt() -1;
				ar[u][v] = 1;
			}
		}

		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				if(j != 0) System.out.print(" ");
				System.out.print(ar[i][j]);
			}
			System.out.println("");
		}

	}
}

Measured memory_bytes: 34640
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <ctime>
using namespace std;
 
#define rep(i,a,n) for(int i=a; i<n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 999999999
 
#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
 
typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long int ll;
 
typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;
 
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int const MOD = 1000000007;
 
namespace std {
    bool operator<(const P a, const P b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}
 
int main() {
    double a,b;
    cin >> a >> b;
    printf("%.8f\n", a * b / 3.305785);
    return 0;
}

Measured memory_bytes: 1236
#include<bits/stdc++.h>
#define LL lon long

using namespace std;

string s;
string str1,str2;
static const int MOD=10000;
int M;
int mem[501][10][3][3][500];

int cal(int n,int p,int pp,int f,int mod){
    int res=0;
    if(n==s.size()){
        if(mod==0)return 1;
        else return 0;
    }
    if(mem[n][p][pp][f][mod]!=-1)return mem[n][p][pp][f][mod];
    int t=9;
    if(f!=1)t=s[n]-'0';
    for(int i=0;i<=t;++i){
        if(pp==1&&p>=i)continue;
        else if(pp==0&&p<=i)continue;
        else if(pp==2&&p!=0&&p==i)continue;

        int b;
        if(pp==2){
            if(p==0)b=2;
            else if(p<i)b=0;
            else b=1;
        }
        else if(pp==1)b=0;
        else b=1;

        int k;
        if(f==1)k=1;
        else if(i!=s[n]-'0')k=1;
        else k=0;

        int temp=mod*10+i;
        res+=cal(n+1,i,b,k,temp%M);
    }
    return mem[n][p][pp][f][mod]=res%MOD;
}

int main(){
    int vr=0;
    int vl=0;
    cin>>str1>>str2>>M;
    for(int i=str1.size()-1;i>=0;i--){
        if(str1[i]=='0'){
            str1[i]='9';
        }
        else{
            str1[i]--;
            break;
        }
    }
    s=str1;
    memset(mem,-1,sizeof(mem));
    vl=cal(0,0,2,0,0);
    s=str2;
    memset(mem,-1,sizeof(mem));
    vr=cal(0,0,2,0,0);
    cout<<(vr-vl+MOD)%MOD<<endl;

    return 0;
}

Measured memory_bytes: 89352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define INF 1000000000
#define MOD 1000000007

void solve() {
    unordered_set<string> s;
    int n;
    cin >> n;
    rep(i,0,n) {
        string tmp;
        cin >> tmp;
        s.emplace(tmp);
    }
    cout << sz(s); 
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t = 1;
    //cin >> t;
    while (t--)
        solve();
    return 0;
}



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

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

  vector<int> d(N);
  for (int i = 0; i < N; i++) cin >> d[i];

  long long total = 0;

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < i; j++) {
      total += (long long)(d[i] * d[j]);
    }
  }

  cout << total << endl;
}

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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using Pi = pair<int, int>;
using Tapris = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n;
  cin >> n;
  vint l(n), r(n);
  rep(i, n) cin >> l[i] >> r[i];
  sort(all(l));
  reverse(all(l));
  sort(all(r));
  int ans = 0;
  int sum = 0;
  rep(i, n) {
    sum += 2*l[i];
    chmax(ans, sum);
    sum -= 2*r[i];
    chmax(ans, sum);
  }
  sum = 0;
  rep(i, n) {
    sum -= 2*r[i];
    chmax(ans, sum);
    sum += 2*l[i];
    chmax(ans, sum);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1920
def insertionSort(A, N):
    for i in range(N):
        v = A[i]
        j = i - 1
        while j >= 0 and A[j] > v:
            A[j + 1] = A[j]
            j -= 1
        A[j + 1] = v
        B = A.copy()
        for t in range(N):
            B[t] = str(B[t])
        print(" ".join(B))


n = int(input())
a = list(map(int, input().split()))
insertionSort(a, n)


Measured memory_bytes: 5600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pll = pair<ll, ll>;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, m, n) for(ll i = m; i > n; i--)
#define Rep(i, m, n) for(ll i = m; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define lmax(x, y) max<ll>(x, y)
#define lmin(x, y) min<ll>(x, y)
#define tmax(x, y, z) lmax((x), lmax((y), (z)))
#define tmin(x, y, z) lmin((x), lmin((y), (z)))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define ZERO(a) memset(a, 0, sizeof(a))
const ll INF = 1LL << 60;
const ll MM = 1000000000; const ll MOD = MM + 7; const ll MMM=9223372036854775807;//2^63 -1
#define ADD(a,b) a = (a + ll(b)) % MOD
#define MUL(a,b) a = (a * ll(b)) % MOD
ll GCD(ll x, ll y){ if(y == 0) return x; else return GCD(y, x % y);}
ll LCM(ll x, ll y){ return x / GCD(x, y) * y;}
template<class T> inline bool chmin(T& a, T b){ if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b){ if(a < b){ a = b; return true;} return false;}
template<typename A, size_t N, typename T> void FILL(A (&array)[N], const T &val){ fill( (T*)array, (T*)(array+N), val );}
// struct edge{ ll from, to, cost; };
// struct edge{ ll to, cost; };
// using Graph = vector<vector<ll>>;  // 重み無し
// using Graph = vector<edge>;  // 辺
// using Graph = vector<vector<edge>>;  // 重み付き
ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
ll ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1};


int main(){
    string s; cin >> s;
    cout << s.substr(0, s.size()-8) << endl;
}


Measured memory_bytes: 3596
import sys
import math
import collections
import bisect
import itertools

# import numpy as np

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))


# ===CODE===

def main():
    s = list(input())

    g = 0
    p = 0
    ans = 0

    for i in range(len(s)):
        if p + 1 <= g:
            a = "p"
            p += 1
        else:
            a = "g"
            g += 1

        if a == s[i]:
            continue
        elif a == "p":
            ans += 1
        else:
            ans -= 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 10112
#include<bits/stdc++.h>
using namespace std;
 
using ll = long long ;
using ld=long double;
 
int main(){
    int n;
    cin>>n;
    int b[n-1];
    for(int i=0;i<n-1;i++)
    cin>>b[i];
    ll sum=b[0];
    for(int i=1;i<n-1;i++){
        if(b[i-1]>b[i])
        b[i-1]=b[i];
    }
    for(int i=0;i<n-1;i++){
        sum+=b[i];
    }
    
    cout<<sum;
    return 0;
}

Measured memory_bytes: 256
use std::io;

fn main() {
    loop {
        let mut input = String::new();
        io::stdin().read_line(&mut input).unwrap();

        let mut iter = input.split_whitespace().map(|w| w.parse::<i32>().unwrap());
        let x = iter.next().unwrap();
        let y = iter.next().unwrap();

        if x == 0 && y == 0 { break; }
        match x < y {
            true  => println!("{} {}", x, y),
            false => println!("{} {}", y, x),
        }
    }
}



Measured memory_bytes: 5036
#include<iostream>
#include<cmath>
#include<complex>
#include<cstdio>

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)

typedef complex<double> P;
typedef pair<P, P> L;
const double EPS = 1e-8;

#define X real()
#define Y imag()
enum CCW{FRONT = 1, RIGHT = 2, BACK = 4, LEFT = 8, ON = 16};
bool eq(double a, double b) {return abs(a - b) < EPS;}
int sig(double r) {return (r < -EPS) ? -1 : (r > EPS) ? 1: 0;}

P vec(L a) {return a.second - a.first;}

double dot(P a, P b) {return a.X * b.X + a.Y * b.Y;}
double cross(P a, P b) {return a.X * b.Y - a.Y * b.X;}
int ccw(const P a, P b, P x) {
  b -= a;
  x -= a;
  double cr = cross(b, x);
  if (eq(cr, 0)) {
    if (dot(b, x) < 0) return BACK;
    if (abs(b) < abs(x)) return FRONT;
    return ON;
  }
  return (cr > 0) ? LEFT : RIGHT;
}
bool iSS(L a, L b) {
  int cwaf = ccw(a.first, a.second, b.first);
  int cwbf = ccw(b.first, b.second, a.first);
  int cwas = ccw(a.first, a.second, b.second);
  int cwbs = ccw(b.first, b.second, a.second);
  if ((cwaf | cwas | cwbf | cwbs) & ON) return true;
  return ((cwaf | cwas) & (cwbf | cwbs)) == (LEFT | RIGHT);
}

double dLP(L l, P x) {return abs(cross(vec(l), x - l.first)) / abs(vec(l));}
double dSP(L s, P x) {
  if (dot(vec(s), x - s.first) <= 0) return abs(x - s.first);
  if (dot(-vec(s), x - s.second) <= 0) return abs(x - s.second);
  return dLP(s, x);
}
double dSS(L a, L b) {return iSS(a, b) ? 0 : min(min(dSP(a, b.first), dSP(a, b.second)), min(dSP(b, a.first), dSP(b, a.second)));}

P s, g;
double ax, ay, bx, by, h;

double f(L seg, double h) {
  double a = 0, b = 1111;
  L l = make_pair(s, g);
  double d = dSS(seg, l);
  //cout << d << endl;
  while (a < b - 1e-8) {
    double m = (a + b) / 2;
    if (m < d) a = m;
    else if (m < h) b = m;
    else if (m - sqrt(max(m * m - d * d, 0.)) > h) a = m;
    else b = m;
  }
  return a;
}

int main() {
  int n;
  for (;;) {
    cin >> n;
    if (n == 0) break;
    cin >> s.X >> s.Y >> g.X >> g.Y;
    double res = 1e40;
    rep (i, n) {
      cin >> ax >> ay >> bx >> by >> h;
      res = min(res, f(make_pair(P(ax, ay), P(ax, by)), h));
      res = min(res, f(make_pair(P(ax, ay), P(bx, ay)), h));
      res = min(res, f(make_pair(P(bx, by), P(ax, by)), h));
      res = min(res, f(make_pair(P(bx, by), P(bx, ay)), h));
      if (sig(ax - s.X) * sig(bx - s.X) <= 0 && sig(ay - s.Y) * sig(by - s.Y) <= 0) res = 0;
      if (sig(ax - g.X) * sig(bx - g.X) <= 0 && sig(ay - g.Y) * sig(by - g.Y) <= 0) res = 0;
    }
    printf("%.12lf\n", res);
  }
}

Measured memory_bytes: 0
using System;
class c
{
    static void Main()
    {
        var inp = int.Parse(Console.ReadLine());
        int ans = 0;
        for (int i = 1; i <= 9; i++)
        {
            if (111 * i >= inp)
            {
                ans = 111 * i;
                break;
            }
        }
        Console.WriteLine(ans);
    }
}

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

using namespace std;

#define ll long long
#define endl "\n"

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    string s;
    cin >> s;
    int i,sum=0;
    for(i=0;i<s.size();i++) {
        char ch = s[i];
        int x=ch-'0';
        sum+=x;
    }
    if(sum==0 || sum%9==0) cout << "Yes";
    else cout << "No";
}

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

typedef long long ll;
using namespace std;

#define REP(i, a, b) for(int i=(a); i<(b); i++)
#define rep(i, n) REP(i, 0, n)
const int INF=1e9;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define pb(x) push_back(x)
#define rsort(x) sort(x, greater<>());
#define sum(v) accumulate(ALL(v),0)

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<int> a(n+1);
    vector<int> b(n);
    rep(i, n+1) {
        cin>>a[i];
    }
    rep(i, n) {
        cin>>b[i];
    }
    ll ans = 0;
    reverse(ALL(a));
    reverse(ALL(b));
    dbg(a);
    dbg(b);
    rep(i,n){
        int defeat =min(b[i],a[i]+a[i+1]);
        if(defeat>a[i]){
            a[i+1] = a[i+1]-(defeat-a[i]);
        }
        ans += defeat;
    }
    cout << ans << endl;
    return  0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

int main(){
  int N;
  cin >> N;
  int a[N];
  rep(i,N) cin >> a[i];
  int mmax=0;
  int pmax=0;
  int mind, pind;
  rep(i,N){
    if(a[i]<0){
      if(mmax > a[i]){
	mmax=a[i];
	mind=i;
      }
    }
    else if(a[i]>0){
      if(pmax < a[i]){
	pmax=a[i];
	pind=i;
      }
    }    
  }
  rep1(i,N-1) {
    if(a[i-1] <= a[i]){
      //      cout << i;
      if(i==N-1){
	cout << 0 << endl;
	return 0;
      }
    }
    else {
      break;
    }
  }
  if(mmax==0 && pmax==0){
    cout << 0 << endl;
    return 0;
  }
  //cout << mmax << " " << pmax << endl;
  vector<pair<int, int> > ans;  
  if(abs(mmax) < abs(pmax)){
    rep(i,N){
      if(a[i] < 0){
	ans.pb(mp(pind,i));
	a[i]+=a[pind];
      }
    }
    rep1(i,N-1){
      if(a[i-1] > a[i] ){
	ans.pb(mp(i-1,i));
	a[i]+=a[i-1];
      }
    }
  }
  else{
    rep(i,N){
      if(a[i] > 0){
        ans.pb(mp(mind,i));
	a[i]+=a[mind];
      }
    }
    for(int i=N-1; i>0; i--){
      if(a[i-1] > a[i] ){
	ans.pb(mp(i,i-1));
	a[i-1]+=a[i];
      }
    }
  }
  cout << ans.size() << endl;  
  rep(i,ans.size()){
    cout << ans[i].first + 1 << " " << ans[i].second + 1 << " " << endl;
  }
  
  return 0;

}


Measured memory_bytes: 256