akhauriyash/Code-Regression huggingface dataset:
from itertools import accumulate
import sys
sdin = sys.stdin.readline

n,c = map(int, sdin().split())
x_cw = [0]
v_cw = [0]
for _ in range(n):
    x, v =  map(int, sdin().split())
    x_cw.append(x)
    v_cw.append(v)
    
v_cw_acc = list(accumulate(v_cw))    

# 反時計回りの距離と栄養価
x_ccw = [0]
v_ccw = [0]
for i in range(n):
    x_ccw.append(c-x_cw[n-i])
    v_ccw.append(v_cw[n-i])
    
v_ccw_acc = list(accumulate(v_ccw))

# cw, ccwそれぞれでの各寿司ナンバーまでのmaxを求める
total_cw_max = [0]
total_ccw_max = [0]
for i in range(1,n+1):
    tmp_cw = v_cw_acc[i] - x_cw[i]
    total_cw_max.append(max(total_cw_max[-1], tmp_cw))
    
    tmp_ccw = v_ccw_acc[i] - x_ccw[i]
    total_ccw_max.append(max(total_ccw_max[-1], tmp_ccw))
    
# b側を固定する
ans_b_static = 0
for b in range(n,-1, -1):
    tmp_b_static = total_cw_max[n-b] + v_ccw_acc[b] - 2*x_ccw[b]
    ans_b_static = max(ans_b_static, tmp_b_static)
    
# a側を固定する
ans_a_static = 0
for a in range(n, -1, -1):
    tmp_a_static = total_ccw_max[n-a] + v_cw_acc[a] - 2*x_cw[a]
    ans_a_static = max(ans_a_static, tmp_a_static)
    
# その大きい方が答え
print(max(ans_a_static, ans_b_static))

Measured memory_bytes: 33176
use proconio::input;

use std::io::{stdout, Write, BufWriter};

fn main() {
    let out = stdout();
    let mut out = BufWriter::new(out.lock());

    input! {s: String}
    let s_u8_vec = s.as_bytes();
    let left_small = "<".as_bytes()[0];
    let mut a:Vec<usize> = Vec::new();
    a.resize(s_u8_vec.len() + 1, 0);
    let mut symbol_count:usize = 0;
    for i in 0..=s_u8_vec.len() {
        if i < s_u8_vec.len() && s_u8_vec[i] == left_small {
            a[i] = symbol_count;
            symbol_count += 1;
        } else if symbol_count > 0 {
            a[i] = symbol_count;
            symbol_count = 0;
        }
    }
    symbol_count = 0;
    for i in (0..=s_u8_vec.len()).rev() {
        if i > 0 && s_u8_vec[i - 1] != left_small {
            a[i] = symbol_count;
            symbol_count += 1;
        } else if symbol_count > 0 {
            a[i] = symbol_count.max(a[i]);
            symbol_count = 0;
        }
    }
    writeln!(out, "{}", a.iter().sum::<usize>()).unwrap();
}


Measured memory_bytes: 6876
/*
  Author: Alokit Kumar
  */
  #include<bits/stdc++.h>
  using namespace std;
  #define int long long
  int32_t main()
  {
    int t,n,i,j,k,l=0,l1,r,d,s1;
    cin>>n;
    for(i=1;i<=n;i++)
    { s1=0;
      for(j=1;j*j<=i;j++)
      {
        for(k=1;k*k<=(i-j*j);k++)
        {
          l=-3*j*j-3*k*k-2*k*j+4*i;
          if(l>=0)
          {
            double x=sqrt(l);
            l1=x;
            if(l1==x)
            {
              if((l1-k-j)>0) s1++;
            }
          }
        }
      }
      cout<<s1<<"\n";
    }
  }

Measured memory_bytes: 3604
from heapq import heapify,heappush,heappop
N,K=map(int,input().split())
sushi=[]
for i in range(N):
  t,d=map(int,input().split())
  sushi.append((d,t-1))
sushi.sort(key=lambda x:-x[0])
inf=float("inf")
oishisa=[-inf]*(N+1)
neta=[0]*N
heaps=[[] for i in range(N)]
S=[]
heapify(S)
for i in range(N):
  heapify(heaps[i])
a,k=0,0
for d,t in sushi[:K]:
  a+=d
  neta[t]+=1
  if neta[t]==1:
    k+=1
  heappush(heaps[t],d)

oishisa[k]=a
for i in range(N):
  if neta[i]>=2:
    d=heappop(heaps[i])
    heappush(S,(d,i))
for d,t in sushi[K:]:
  if len(S)==0:
    break
  if neta[t]==0:
    neta[t]+=1
    d_,t_=heappop(S)
    neta[t_]-=1
    if neta[t_]>=2:
      d__=heappop(heaps[t_])
      heappush(S,(d__,t_))
    heappush(heaps[t],d)
    oishisa[k+1]=oishisa[k]+d-d_
    k+=1
ans=0
for i in range(N+1):
  ans=max(oishisa[i]+i*i,ans)
print(ans)

Measured memory_bytes: 89432
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

vl factor(ll n) {
  vl res;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      res.push_back(i);
      if(n / i != i) res.push_back(n / i);
    }
  }
  return res;
}

int main() {
  ll n;
  cin >> n;
  vl a(n);
  rep(i, n) cin >> a[i];
  ll ans = 0;
  sort(all(a));
  vb v(1e6 + 1, false);
  rep(i, n) {
    auto f = factor(a[i]);
    bool ok = true;
    for(auto j : f)
      if(v[j]) ok = false;
    v[a[i]] = true;
    if(ok) ans++;
    if(i != n - 1 && a[i] == a[i + 1] && ok) ans--;
  }
  cout << ans << endl;
}


Measured memory_bytes: 4792
//#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,tune=native")
#include<bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(),(x).end()
#define I(x, a) for(auto x : (a))
#define ins insert
#define F(i, l, r) for(auto i = (l); i < (r); i++)
#define DF(i, l, r) for(auto i = (l); i >= (r); i--)
#define E(i, l, r) for(auto i = (l); i <= (r); i++)
#define pb push_back
#define X first
#define Y second
#define mp make_pair
#define ret return
#define brk break
#define cont continue
#define move fjgjgjgjghd

typedef long long ll;
typedef unsigned long long ull;
typedef long double dbl;
typedef pair<int, int> pii;

const int W = (int)1e5 + 5;

int tc = 0;
ll dp[2][W];
int n, maxw;
int w[W], v[W];


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> maxw;
	F(i, 0, n)cin >> w[i] >> v[i];
	F(i, 0, n){
		memcpy(dp[tc], dp[1 - tc], W * sizeof(ll));
		F(cw, w[i], maxw + 1){
			dp[tc][cw] = max(dp[tc][cw], dp[1 - tc][cw - w[i]] + v[i]);
		}
		tc ^= 1;
	}
	cout << *max_element(dp[1 - tc], dp[1 - tc] + W) << endl;
	return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<fstream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<cmath>
#include<cctype>
#include<vector>
#include<limits.h>
#include<queue>
using namespace std;

typedef long long ll;
int main()
{
    ll ans[6010]= {0};
    int x,y,z,n,fir,i,j,k;
    ll a[1010],b[1010],c[1010];

    scanf("%d%d%d%d",&x,&y,&z,&n);
    for(i=0; i<x; i++)
        scanf("%lld",&a[i]);
    for(i=0; i<y; i++)
        scanf("%lld",&b[i]);
    for(i=0; i<z; i++)
        scanf("%lld",&c[i]);
    sort(a,a+x,greater<long long>());
    sort(b,b+y,greater<long long>());
    sort(c,c+z,greater<long long>());
    fir=0;
    for(i=0; i<x; i++)
    {
        if(i>=n)
            break;
        for(j=0; j<y; j++)
        {
            if(j>=n)
                break;

            for(k=0; k<z; k++)
            {
                if(k>=n)
                    break;
                ans[fir]=a[i]+b[j]+c[k];
                if(ans[fir]<=ans[n])
                    break;
                else
                    fir++;
                if(fir==n)
                {
                    sort(ans,ans+2*n);
                    fir=0;
                }
            }

        }
    }
    sort(ans,ans+2*n);
    for(i=2*n-1; i>=n; i--)
        printf("%lld\n",ans[i]);
    return 0;
}


Measured memory_bytes: 384
#include <queue>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#define FOR(i, n) for(int i = 0; i < n; i++) 
using namespace std;

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

void load() {
}

const int MAXN = 1010;
int n, m;
vector<int> graf[MAXN];

vector<int> bfs(int s) {
	queue<int> q;
	vector<int> parent(n, -1);
	q.push(s);
	while (!q.empty()) {
		int x = q.front(); q.pop();
		for (int sus : graf[x]) {
			if (parent[sus] == -1) {
				parent[sus] = x;
				if (sus == s) {
					vector<int> sol;
					do {
						sol.push_back(sus);
						sus = parent[sus];
					} while (sus != s);
					return sol;
				}
				q.push(sus);
			}
		}
	}
	vector<int> v;
	return v;
}

void solve() {
	scanf("%d%d", &n, &m);
	FOR(i, m) {
		int u, v; scanf("%d%d", &u, &v); u--; v--;
		graf[u].push_back(v);
	}
	vector<int> sol;
	FOR(i, n) {
		vector<int> v = bfs(i);
		if (v.size() > 0 && (sol.empty() || v.size() < sol.size())) sol = v;
	}
	if (sol.empty()) {
		printf("-1\n");
	} else {
		printf("%d\n", (int)sol.size());
		for (int y : sol) printf("%d\n", y+1);
	}
}

int main() {
	load();
	solve();
	return 0;
}


Measured memory_bytes: 256
<?php /*atcoder.php*/

$at = new Atcoder();
$at->main();
unset($at);

class Atcoder{
	private function lineIn(){
		$buf = fgets(STDIN);
		return $this->killNewLine($buf);
	}
	private function killNewLine($buf = null){
		$buf = str_replace("\r\n", "", $buf);
		$buf = str_replace("\n", "", $buf);
		$buf = str_replace("\r", "", $buf);
		return $buf;
	}

	public function main(){
		$s = $this->lineIn();
		
		if(1200 > $s){
			echo "ABC\n";
		}elseif(2800 > $s){
			echo "ARC\n";
		}else{
			echo "AGC\n";
		}
	}
}
?>


Measured memory_bytes: 4732
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := iScan()
	fmt.Println(10 - n/200)
}


Measured memory_bytes: 1772
#include<stdio.h>
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using lb=long double;
using db=double;
const ll mod=1e9+7;
#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 mp make_pair
#define INF 1e10+7
int n;
const long double pi=2*asin(1.0);
const int maxn = 100005;
vector<int>v[maxn];
int color[maxn];
int main()
{
    queue<int>q;
    int n;
    cin>>n;
    int x,y;
    for(int i=0;i<n-1;i++)
    {
        scanf("%d%d",&x,&y);
        v[x].push_back(y);
        v[y].push_back(x);
    }
    color[1]=1,color[n]=2;
    q.push(1);
    q.push(n);
    int cnt[3]={0,0};
    while(!q.empty())
    {
        int t=q.front();
        q.pop();
        cnt[color[t]]++;
        for(int i=0;i<v[t].size();i++)
        {
            if(color[v[t][i]])continue;
            color[v[t][i]]=color[t];
            q.push(v[t][i]);
        }
    }
    if(cnt[1]>cnt[2])
        cout<<"Fennec"<<'\n';
    else
        cout<<"Snuke"<<'\n';
    return 0;
}   


Measured memory_bytes: 6272
S = input()
N = len(S)
op_cnt = N - 1

for i in range(2 ** op_cnt):
    op = ["+"] * op_cnt
    for j in range(op_cnt):
        if (i >> j) & 1:
            op[j] = "-"
    op.append("")
    ans = []
    for num,ops in zip(S,op):
        ans.append(num)
        ans.append(ops)
    ans = [_ for _ in ans if _ != ""]
    ans = ''.join(ans)
    if eval(ans) == 7:
        print(ans + '=7')
        break

Measured memory_bytes: 3064
n=int(input())
s=input()
l=[]
count=0
for i in s:
    if i=='A':
        l=['A']
    elif i=='B' and l==['A']:
        l.append('B')
    elif i=='C' and l==['A','B']:
        l=[]
        count+=1
    else:
        l=[]
print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using stkll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
#ifndef ONLINE_JUDGE
    #define debug(x) cerr << #x << ": " << x << endl;
#else
    #define debug(x)
#endif

// BIT
// verify: https://judge.yosupo.jp/problem/static_range_sum

// 計算量はすべてO(logN)
// bit.add(i, val) a[i] += val
// bit.sum(l, r) [l, r) の合計
// bit.lower_bound(w) a[0] + ... + a[r] >= w となる最小のr
template <typename T>
class BIT {
    public:
    int N;
    vector<T> dat;

    public:
        BIT(int N) : N(N) { dat.assign(N, 0); }

    void add(int k, T val) {
        for (int x = k; x < N; x |= x + 1) {
            dat[x] += val;
        }
    }

    // [0, k)
    T sum(int k) {
        if (k >= N) k = N - 1;
        T ret = 0;
        for (int x = k - 1; x >= 0; x = (x & (x + 1)) - 1) {
            ret += dat[x];
        }
        return ret;
    }

    // [l, r)
    T sum(int l, int r) { return sum(r) - sum(l); }

    T get(int k) {
        assert(0 <= k && k < N);
        return sum(k + 1) - sum(k);
    }

    // a[0] + a[1] + ... + a[r] >= w なる最小のr
    int lower_bound(int w) {
        if (w <= 0) return -1;
        int x = 0;
        int k = 1;
        while (k * 2 <= N) k *= 2;
        for (; k > 0; k /= 2) {
            if (x + k <= N && dat[x + k - 1] < w) {
                w -= dat[x + k - 1];
                x += k;
            }
        }
        return x;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    ll N; cin >> N;
    string S; cin >> S;
    ll Q; cin >> Q;
    // サイズN+1にしないとsumが正しくとれない
    vector<BIT<ll>> bit(30, BIT<ll>(N+1));

    rep(i, N) {
        ll j = S[i] - 'a';
        bit[j].add(i, 1);
    }

    rep(i,Q) {
        ll q;
        cin >> q;
        if(q == 1) {
            ll j; char c;
            cin >> j >> c;
            j--;
            ll i1 = S[j] - 'a';
            ll i2 = c - 'a';
            bit[i1].add(j, -1);
            bit[i2].add(j, 1);
            S[j] = c;
        }
        else {
            ll l, r;
            cin >> l >> r;
            l--, r--;
            ll ans = 0;
            rep(j, 26) if(bit[j].sum(l, r+1) >= 1) ans++;
            cout << ans << endl;
        }
    }

}


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

int n, m, q;
vector<int> a, b, c, d;
int max_sum = 0;

int f(vector<int> &la, int ln)
{
    if(ln == n){
        int sum = 0;
        for (int i = 0; i < q; i++)
        {
            if(la[b[i]-1] - la[a[i]-1] == c[i]){
                sum += d[i];
            }
        }
        return sum;
    }else{
        int s = 1;
        if(ln > 0){
            s = la[ln-1];
        }
        for (int i = s; i <= m; i++)
        {
            la[ln] = i;
            int r = f(la, ln+1);
            max_sum = max(r, max_sum);
        }
        return max_sum;
    }
}

void Main()
{
    cin >> n >> m >> q;
    a.resize(q);
    b.resize(q);
    c.resize(q);
    d.resize(q);
    for (int i = 0; i < q; i++)
    {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    vector<int> la(n);
    int ans = f(la, 0);
    
    cout << ans << endl;
}

int main(int argc, char **argv)
{
    Main();
    return 0;
}


Measured memory_bytes: 3648
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using Pair = pair<int64_t, int64_t>;
constexpr int64_t kInf = INT64_MAX / 2L;

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

  constexpr int64_t kN = 26;
  int64_t D;
  cin >> D;
  vector<int64_t> C(kN + 1, 0);
  for (int64_t c = 1; c <= kN; ++c) {
    cin >> C[c];
  }
  vector<vector<int64_t>> S(D + 1, vector<int64_t>(kN + 1));
  for (int64_t d = 1; d <= D; ++d) {
    for (int64_t c = 1; c <= kN; ++c) {
      cin >> S[d][c];
    }
  }
  vector<vector<int64_t>> last(D + 1, vector<int64_t>(kN + 1, 0));
  vector<int64_t> contests(D + 1);
  for (int64_t d = 1; d <= D; ++d) {
    cin >> contests[d];
  }

  auto Score = [&](const int64_t day) -> int64_t {
    int64_t score = 0;
    for (int64_t d = 1; d <= day; ++d) {
      last[d] = last[d - 1];
      last[d][contests[d]] = d;
      score += S[d][contests[d]];
      for (int64_t c = 1; c <= kN; ++c) {
        score -= C[c] * (d - last[d][c]);
      }
    }
    return score;
  };

  auto OutputResults = [&]() {
    for (int64_t d = 1; d <= D; ++d) {
      cout << contests[d] << endl;
    }
  };

  for (int64_t d = 1; d <= D; ++d) {
    int64_t best_score = INT64_MIN;
    int64_t best_conte = -1;
    for (int64_t c = 1; c <= kN; ++c) {
      contests[d] = c;
      int64_t temp_score = Score(d);
      if (temp_score > best_score) {
        best_score = temp_score;
        best_conte = c;
      }
    }
    contests[d] = best_conte;
  }

  int64_t prev_score = Score(D);
  constexpr int64_t kIgnoreBunbo = 5;
  constexpr int64_t kIgnoreBunshi = 0;
  constexpr int64_t kMaxConsecutiveWorse = 3;

  vector<int64_t> best_contests;
  int64_t best_score = INT64_MIN;
  int64_t consecutive_worse = 0;
  vector<int64_t> better_contests;
  for (int64_t i = 0; i < 190000; ++i) {
    const int64_t day_candidate_1 = (rand() % D) + 1;
    const int64_t day_candidate_2 = (rand() % D) + 1;
    const int64_t original_contest = contests[day_candidate_1];
    const int64_t contest_candidate = (rand() % kN) + 1;
    if (day_candidate_1 == day_candidate_2) {
      contests[day_candidate_1] = contest_candidate;
    } else {
      swap(contests[day_candidate_1], contests[day_candidate_2]);
    }
    const int64_t temp_score = Score(D);
    if (temp_score > prev_score) {
      // KEEP
      consecutive_worse = 0;
      better_contests = contests;
      if (temp_score > best_score) {
        best_score = temp_score;
        best_contests = contests;
      }
    } else if ((rand() % kIgnoreBunbo) <= kIgnoreBunshi && temp_score > prev_score * 0.97 &&
               consecutive_worse <= kMaxConsecutiveWorse) {
      // KEEP
      ++consecutive_worse;
    } else {
      if (day_candidate_1 == day_candidate_2) {
        contests[day_candidate_1] = original_contest;
      } else {
        swap(contests[day_candidate_1], contests[day_candidate_2]);
      }
    }
    if (temp_score < best_score * 0.9) {
      contests = best_contests;
    }
  }

  contests = best_contests;
  OutputResults();
  return 0;
}


Measured memory_bytes: 3844
#include<bits/stdc++.h>
using namespace std;
#define LL long long
int a,b;
LL Ans=1e9;
int main() {
	scanf("%d%d",&a,&b);
	for(int i=a; i<=min(b,a+5000); i++) {
		for(int j=i+1; j<=min(b,a+5000); j++)
			Ans=min(1LL*i*j%2019,Ans);
	}
	printf("%lld",Ans);
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {
	times := make([]int, 3)
	for i := 0; i < 3; i++ {
		fmt.Scan(&times[i])
	}
	sort.Sort(sort.IntSlice(times))
	fmt.Println(times[0] + times[1])
}

Measured memory_bytes: 512
#include <cmath>
#include <iostream>
#include <string>
#include <vector> 
#include <algorithm>
#include <numeric>
#include <map>   
#include <stdio.h>

#define FOR(i,a,b) for(i=(a);i<(b);++i) 
#define FORR(i,a,b) for(i=(a);i>(b);--i)
#define REP(i,n) for(i=0;i<(n);++i)
#define REPR(i,n) for(i=(n);i>0;--i)
#define PB push_back
#define ull unsigned long long
#define ll long long
#define INT_MAX 2147483647
#define LL_MAX 9223372036854775807
#define sortR(a,b) sort(a, b, greater<int>())

using namespace std;

int main() {
	ll N,A,B,C,D,E,MIN;
	vector<ll> a(5);
	cin >> N >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];
	sort(a.begin(), a.end());
	MIN = a[0];
	cout << (N-1+MIN) / MIN + 4;
	return 0;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

#define REP(i,x,y) for(int i=(x);i<(y);i++)
#define RREP(i,x,y) for(int i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
//#define int long long

using namespace std;

// conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

#define dump(x)  cout << #x << " = " << (x) << endl
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

typedef long long ll;

const ll MOD = 1e9 + 7;

class BGraphPartition {
public:
	void solve(std::istream& in, std::ostream& out) {
	    int N;
	    in >> N;
	    vector<pair<int, int>> edges;
	    vector<unordered_set<int>> edgeSet(N);
	    REP(i,0,N) {
	        REP(j,0,N) {
	            char edge;
	            in >> edge;
	            if (edge == '1') {
	                edges.push_back({i, j});
	                edgeSet[i].insert(j);
	            }
	        }
	    }

	    // check bipartile graph
	    vector<int> nodeGroup(N, -1);
	    nodeGroup[0] = 0;
	    queue<int> que;
	    que.push(0);
	    while (!que.empty()) {
	        int current = que.front();
	        que.pop();
	        for (const auto& next : edgeSet[current]) {
	            if (nodeGroup[next] != -1) {
	                if (nodeGroup[current] == nodeGroup[next]) {
	                    out << -1 << "\n";
	                    return;
	                } else {
	                    continue;
	                }
	            }
	            nodeGroup[next] = nodeGroup[current] == 0 ? 1 : 0;
	            que.push(next);
	        }
	    }

	    vector<vector<int>> dp(N, vector<int>(N, 1e5));
	    REP(i,0,N) {
	        dp[i][i] = 0;
	    }
	    for (const auto& edge : edges) {
	        dp[edge.first][edge.second] = 1;
	    }

	    REP(k,0,N) {
	        REP(i,0,N) {
	            REP(j,0,N) {
	                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
	            }
	        }
	    }
        int d = 0;
        REP(i,0,N) {
	        REP(j,0,N) {
	            if (dp[i][j] == INT_MAX) continue;
	            d = max(d, dp[i][j]);
	        }
	    }
        out << d+1 << "\n";
	}
};


int main() {
	BGraphPartition solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

#define fi first
#define se second

const long maxn = 1e3 + 10;
const int Move[4][2] = {-1,0,1,0,0,1,0,-1};
char mp[maxn][maxn];
int step[maxn][maxn];
bool vis[maxn][maxn];
int n,m;

bool check(int x,int y) {
    if(x < 0 || y < 0|| x >= n || y >= m || vis[x][y] || mp[x][y] == '#') return false;
    return true;
}

int BFS() {
    queue<pair<int ,int> > q;
    q.push(make_pair(0,0));
    step[0][0] = 1;
    vis[0][0] = true;
    while (!q.empty()) {
        pair<int ,int> t = q.front();
        q.pop();
        for(int i = 0;i < 4;i++) {
            int tox = t.fi + Move[i][0];
            int toy = t.se + Move[i][1];
            if(tox == n - 1 && toy == m - 1) return step[t.fi][t.se] + 1;
            if(check(tox,toy)) {
                vis[tox][toy] = true;
                step[tox][toy] = step[t.fi][t.se] + 1;
                q.push(make_pair(tox,toy));
            }
        }
    }
    return -1;
}


int main(){
    
    cin>>n>>m;
    int cnt = 0;
    for(int i = 0;i < n;i++)
        for(int j = 0;j < m;j++) {
            cin>>mp[i][j];
            if(mp[i][j] == '#') cnt++;
        }
    int res = BFS();
    if(res == -1) {
        cout<<"-1"<<endl;
    } else {
        cout<<n*m - res - cnt<<endl;
    }
    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<cstring>

using namespace std;

int main(){
    long long n, add[15][15];
    cin >> n;
    memset(add, 0, sizeof(add));
    for(int i=1;i<=n;i++){
        long long tmp = i;
        long long bot = tmp%10, top;
        while(tmp>0){
            top = tmp%10;
            tmp/=10;
        }
        add[top][bot]++;
    }
    long long cnt=0;
    for(int i=1;i<=n;i++){
        long long tmp = i;
        long long bot = tmp%10, top;
        while(tmp>0){
            top = tmp%10;
            tmp/=10;
        }
        cnt += add[bot][top];
    }
    cout << cnt << endl;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m; cin>>n>>m;
    map<ll,ll> cnt;
    rep(i,n){
        ll a; cin>>a;
        cnt[a]++;
    }
    rep(i,m){
        ll b,c; cin>>b>>c;
        cnt[c]+=b;
    }
    int num=0;
    ll ans=0;
    RITR(itr,cnt){
        while(num<n && itr->se>0){
            ans += itr->fi;
            itr->se--;
            num++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 12800
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

string s;
ll dp[100005][13];

int main(void){
	cin >> s;
	dp[0][0]=1;
	int n=s.size();
	for(int i=0;i<n;i++){
		for(int j=0;j<13;j++){
			if(s[i]=='?'){
				for(int v=0;v<=9;v++){
					dp[i+1][(j*10+v)%13]+=dp[i][j];
					dp[i+1][(j*10+v)%13]%=MOD;
				}
			}else{
				int v=(s[i]-'0');
				dp[i+1][(j*10+v)%13]+=dp[i][j];
				dp[i+1][(j*10+v)%13]%=MOD;
			}
		}
		
	}
	printf("%lld\n",dp[n][5]);
	return 0;
}


Measured memory_bytes: 10624
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

int N;
vector<lint> a;

int main()
{
    cin >> N;
    a.resize(N);
    for (auto &v : a) cin >> v;
    sort(a.begin(), a.end());

    vector<lint> b(N, 0);
    for (int i=1; i<N; i++) b[i] = (a[i] - a[0]) / (N+1);
    lint res = accumulate(b.begin(), b.end(), 0LL);

    for (int i=0; i<N; i++) a[i] = a[i] - N * b[i] + (res - b[i]);
    sort(a.begin(), a.end());
    // for (auto v : a) cout << v << " ";
    // cout << endl;
    if (a[0] > N)
    {
        lint dif = a[0]-N;
        res += dif * N;
        for (auto &v : a) v -= dif;
    }
    lint border = N;
    // cout << res << endl;
    // for (auto v : a) cout << v << " ";
    while (a.back() >= border)
    {
        a.back() -= (N+1);
        sort(a.begin(), a.end());
        border--;
        res++;
    }
    cout << res << endl;
}

Measured memory_bytes: 256
n = int(input())
data_red = [list(map(int,input().split())) for _ in range(n)]
data_blue = [list(map(int,input().split())) for _ in range(n)]

data_blue.sort()
data_red.sort(key=lambda x:x[1],reverse=True)

ans = 0
avail = [True for _ in range(n)]
for a,b in data_blue:
    for i,cd in enumerate(data_red):
        if avail[i] and cd[0] < a and cd[1] < b:
            ans += 1
            avail[i] = False
            #print(a,b,*cd)
            break

print(ans)

Measured memory_bytes: 39024
#include "bits/stdc++.h"

using namespace std;

#define sp(x) cout<<setprecision(x);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define print(s) cout<<(s)<<endl
#define lint long long
#define yes "Yes"
#define no "No"

typedef pair<int, int> P;

struct cont{
    int dist, x, y; //そこまでの距離、（ｘ、ｙ）：座標
};
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h,w; cin>>h>>w;
    vector<string> s(h);
    REP(i,h) cin>>s[i];
    int dir[5] = {0,1,0,-1,0};
    queue<cont> q;
    vector<vector<int> > mas(h,vector<int>(w,-1));
    REP(i,h){
        REP(j,w){
            if(s[i][j]=='#'){
                mas[i][j] = 0;
                q.push({0,j,i});
            } 
        }
    }
    int ans = 0;
    while(q.size()){
        int dist = q.front().dist,
                x = q.front().x,
                y = q.front().y;
            q.pop();    
        ans = max(ans,dist); 
            REP(i,4){
                if(y+dir[i+1]>=0 && x+dir[i]>=0 && y+dir[i+1]<h && x+dir[i]<w){                
                    if(mas[y+dir[i+1]][x+dir[i]] != -1) continue;
                    if(s[y+dir[i+1]][x+dir[i]]=='.'){
                        q.push({dist+1,x+dir[i],y+dir[i+1]});
                        mas[y+dir[i+1]][x+dir[i]] = dist+1;
                    }
                }
            }
    }
    print(ans);
    return 0;
}

Measured memory_bytes: 17424
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
using namespace std;
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; }
const long long INF = 1LL << 60;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
    int n;
    cin>>n;
    double t,a;
    cin>>t>>a;
    vector<double> h(n);
    int bangou=1001;
    double absmin=100000;
    rep(i,n){
        cin>>h.at(i);
        double mean=t-h.at(i)*0.006;
        if(absmin>abs(a-mean)){
            absmin=abs(a-mean);
            bangou=i+1;
        }
    }
    cout<<bangou<<endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define MOD 1000000007
#define INF 11234567890
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

int A, B;

int main()
{
	in >> A >> B;
	if (A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0) { out << "Possible" << std::endl; }
	else { out << "Impossible" << std::endl; }
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
long long int a[200000];
int main(void)
{
	int i,n;
	long long int m,x,y,z;
	x=0;
	y=0;
	z=0;
	m=10000000000;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		x+=a[i];
	}
	for(i=1;i<n;i++){
		x=x-a[n-i+1];
		y=y+a[n-i+1];
		z=x-y;
		if(z<0) z=z*-1;
		if(z<m) m=z;
	}
	printf("%lld\n",m);
	return 0;
}

Measured memory_bytes: 1664
from collections import Counter
n=int(input())
a=list(map(int, input().split()))
b=Counter(a)
c=[0,0]
for i in b.keys():
    if b[i]>=2: c.append(i)
    if b[i]>=4: c.append(i)
c.sort()
print(c[-1]*c[-2])

Measured memory_bytes: 18600
n,t=map(int,input().split())
ct=[list(map(int,input().split())) for i in range(n)]
c=10000000000000000
for i in range(n):
    if ct[i][1]<=t:
        c=min(c,ct[i][0])
print(c if c!=10000000000000000 else "TLE")

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <stdio.h>
#include <math.h>


using namespace std;

typedef long long ll;

typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<ll> vll;

typedef pair<int, int> P;
#define mp(x, y) make_pair(x, y)

typedef queue<int> qi;
typedef queue<string> qs;


#define rep(i, n) for(int i=0; i<(n); ++i)
#define repp(i, a, b) for(int i = (a); i <= (b); i++)
#define repm(i, n) for(int i=n; i >= 0; i--)

#define all(v) v.begin(), v.end()
//sort( all(v) )　などと使える

int main(void) {
    int a; cin >> a;
    cout << a + a * a + a * a * a << endl;
 }

Measured memory_bytes: 3640
#include <stdio.h>

int main(){
  int n, m, k, i, a[200], b[100], c[100], d[200], e[200], j;

  scanf("%d",&n);
  scanf("%d",&m);
  for(j = 1 ; j < 2*n+1 ; j++){
    a[j-1] = j;
  }
  for(i = 0 ; i < m ; i++){
    scanf("%d",&k);
    if(k == 0){
      for(j = 0 ; j < n ; j++){
	b[j] = a[j];
	c[j] = a[j+n];
      }
      for(j = 0 ; j < n ; j++){
	a[2*j] = b[j];
	a[2*j+1] = c[j];
      }
    }
    if(k <= 2*n-1 && k >= 1){
      for(j = 0 ; j < k ; j++){
	d[j] = a[j];
      }
      for(j = 0 ; j < 2*n-k ; j++){
	e[j] = a[j+k];
      }
      for(j = 0 ; j < 2*n-k ; j++){
	a[j] = e[j];
      }
      for(j = 0 ; j < k ; j++){
	a[j+2*n-k] = d[j];
      }
    }
  }
  for(i = 0 ; i < 2*n ; i++){
    printf("%d\n",a[i]);
  }

    return 0 ;

}

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

int main()
{
    int n,k;
    cin>>n>>k;
    int A[n];
    for(int i=0;i<n;i++)
    {
        cin>>A[i];
    }
    sort(A,A+n);
    int ans=0;
    for(int i=0;i<k;i++)
        ans+=A[i];
        cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3596
import sys,math
sys.setrecursionlimit(10**9)
from collections import defaultdict
 
IA = lambda: map(int,input().split())
IAS= lambda: map(str,input().split())


s=input()

if len(s)==6 and s[3]==s[2] and s[5]==s[4]:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
//二項係数の計算
int nCr(int A, int B) {
    ll ans = 1;
    for (int i = 0; i < B; i++) {
        ans *= A - i;
    }
    for (int i = 0; i < B; i++) {
        ans /= i + 1;
    }
    return ans;
}
int main() {
    int x;
    cin>>x;
    if(x==0){
        cout<<1<<endl;
    }
    else{
        cout<<0<<endl;
    }
}



Measured memory_bytes: 3632
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int a, b, c, d, e, min1, min2;

    a = sc.nextInt();
    b = sc.nextInt();
    c = sc.nextInt();
    d = sc.nextInt();
    e = sc.nextInt();

    min1 = a;
    if(min1 > b)min1 = b;
    if(min1 > c)min1 = c;
    min2 = d;
    if(min2 > e)min2 = e;

    out.println(min1 + min2 - 50);

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

Measured memory_bytes: 17356
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  string s;
  cin >> s;
  if(sz(s)%2 == 1) {
      cout<<"No"<<endl;
      return 0;
    }
  for(int i =0;i<sz(s);i+=2){
    if(!(s[i] == 'h' && s[i+1] == 'i')){
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
  return 0;
}

Measured memory_bytes: 256
/*
ID: alec3
LANG: C++14
PROG:
*/

#include <bits/stdc++.h>

#define check(x) cout<<(#x)<<": "<<x<<" ";
#define io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ss second
#define ff first
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define ld long double
#define all(c) (c).begin(), (c).end()
#define FOR(i, a, b) for (int i = a; i < b; i++)

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

int pct(int x) { return __builtin_popcount(x); }
bool absComp (int i, int j) { return (abs(i) < abs(j)); }


const ll MOD = 1e9+7;
void add(ll &a, ll b){
    a = (a+b) % MOD;
}
void mul(ll &a, ll b){
    a = a*b % MOD;
}
int main()
{
    io;
    int n, k;
    cin >> n >> k;

   vector<ll> a, apos, aneg;
    for(int i=0; i<n; i++){
        int it;
        cin >> it;
        a.push_back(abs(it));

        if(it > 0)
            apos.push_back(it);
        if(it < 0)
            aneg.push_back(abs(it));
    }
    int szp = apos.size(), szn = aneg.size();

    ll ans = 1;
    if(szp + szn/2*2 >= k && (k%2 == 0 || szp > 0)){

        sort(apos.rbegin(), apos.rend());
        sort(aneg.rbegin(), aneg.rend());

        if(k%2) ans = apos[0];

        vector<ll> v;
        for(int i = k % 2; i + 1 < szp; i += 2)
            v.push_back(apos[i]*apos[i+1]);
        for(int i = 0; i+1 <szn; i += 2)
            v.push_back(aneg[i]*aneg[i+1]);

        sort(v.rbegin(), v.rend());
        for(int i = 0; i < k /2; i++)
            mul(ans, v[i] % MOD);

    }
    else {
        sort(a.begin(), a.end());
        FOR (i, 0, k)
            mul(ans, a[i]);
        ans = (MOD - ans) % MOD;
    }
    cout << ans << endl;

    return 0;
}


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

#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)
typedef long long ll;
int a[4][4];
int c[4][4];
int b[200];
int n;

void solve()
{
    for (int i = 1; i <= 3; i++)
        for (int j = 1; j <= 3; j++)
            cin >> a[i][j];
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> b[i];
    sort(b + 1, b + n + 1);
    // diagonal
    // row
    // column
    int cnt = 0;
    for (int i = 1; i <= n; i++){
        int cur = b[i];
        bool f = 0;
        for (int j = 1; j <= 3; j++){
            for (int k = 1; k <= 3; k++){
                if (a[j][k] == cur) {
                    a[j][k] = -1;
            }
        }
    }
    }
    if ((a[1][1] == -1 && a[2][2] == -1 && a[3][3] == -1) || 
            (a[1][3] == -1 && a[2][2] == -1 && a[3][1] == -1)){
        cout << "Yes";
        return;
    }
   for (int i = 1; i <= 3; i++){
       int row = 0, col = 0;
         for (int j = 1; j <= 3; j++){
                if (a[i][j] == -1)
                    row++;
                if (a[j][i] == -1)
                    col++;

         }
         if (row == 3 || col == 3){
            cout << "Yes";
            return;
         }
    }
   cout << "No";
}


int main()
{
    solve();
    return (0);
}





Measured memory_bytes: 3632
import qualified Data.ByteString.Char8 as BS
import Data.Maybe
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

readInt = fst . fromJust . BS.readInt

readIntList = map readInt . BS.words

getInt = readInt <$> BS.getLine

getIntList = readIntList <$> BS.getLine

search v n n' = do
  p <- VUM.read v (n - 1)
  if p == 0
    then do
      if n == 1
        then return 0
        else search v (n - 1) n'
    else
      if p == n'
        then do
          VUM.write v (n - 1) 0
          return p
        else
          if n == 1
            then return 0
            else search v (n - 1) (n' - 1)

simulate v xs n n' = do
  x <- search v n n'
  if x == 0
    then print (-1)
    else do
      let xs' = x : xs
      if n' == 1
        then do
          mapM_ print xs'
        else simulate v xs' n (n' - 1)

main = do
  n <- getInt
  bs <- getIntList
  v <- VU.thaw (VU.fromList bs)
  simulate v [] n n


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

typedef long long LL;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
typedef vector<pii> vpi;
typedef vector<pll> vpl;

#define fast ios_base::sync_with_stdio(0),cin.tie(0)
#define temp template<typename T>
#define debug(x) cerr<<"Line "<<__LINE__<<": "<<#x<<" = "<<x<<'\n'
#define itr(it,x) for(__typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define rep(i,a,b) for(int i=a;i<=(int)b;i++)
#define repr(i,a,b) for(int i=a;i>=(int)b;i--)
#define cas(n) printf("Case %d:",(int)n)
#define mem(x,v) memset(x,v,sizeof(x))
#define read(x) freopen(x,"r",stdin)
#define write(x) freopen(x,"w",stdout)
#define all(x) x.begin(),x.end()
#define aut(x,v) for(auto &x:v)
#define ini(n) scanf("%d",&n)
#define inl(n) scanf("%lld",&n)
#define ind(n) scanf("%lf",&n)
#define ins(n) scanf("%s",n)
#define insn(n) scanf(" %[^\n]",n)
#define outi(n) printf("%d",(int)n)
#define outl(n) printf("%lld",(LL)n)
#define outd(n,p) printf("%.*lf",p,(double)n)
#define outs(n) printf("%s",n)
#define sz(x) (int)x.size()
#define nl printf("\n")
#define sp printf(" ")
#define pb push_back
#define mp make_pair
#define xx first
#define yy second

const int inf=0x3f3f3f3f;
const int mod=1000000007;
const int mx=100005;
const LL  infL=0xf3f3f3f3f3f3f3f;
const double eps=1e-9;
const double pi=acos(-1.0);

int main()
{
    //read("in.txt"),write("out.txt");
    int c=1000;
    string x;
    cin>>x;
    rep(i,0,sz(x)-3)
    c=min(c,abs(753-stoi(x.substr(i,3),nullptr,10)));
    outi(c),nl;
    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    char[] ns = scanner.next().toCharArray();
    int N = ns.length;
    int[] digits = new int[N];
    for (int i = 0; i < N; i++) digits[i] = ns[i] - '0';
    int K = scanner.nextInt();

    long res = 0;
    for (List<Integer> l : comb(N, K)) {
      int r;
      if (l.get(0) == 0) {
        switch (K) {
          case 1:
            r = digits[0];
            break;
          case 2:
            if (allzero(digits, 0, l.get(1))) {
              r = (digits[0] - 1) * 9 + digits[l.get(1)];
            } else {
              r = digits[0] * 9;
            }
            break;
          case 3:
            if (allzero(digits, 0, l.get(1))) {
              if (allzero(digits, l.get(1), l.get(2))) {
                r = (digits[0] - 1) * 9 * 9;
                if (digits[l.get(1)] > 0) {
                  r += (digits[l.get(1)] - 1) * 9 + digits[l.get(2)];
                }
              } else {
                r =((digits[0] - 1) * 9 + digits[l.get(1)]) * 9;
              }
            } else {
              r = digits[0] * 9 * 9;
            }
            break;
          default:
            throw new IllegalStateException();
        }
      } else {
        r = 1;
        for (int i = 0; i < K; i++) r *= 9;
      }
      res += r;
    }
    System.out.println(res);
  }

  private static boolean allzero(int[] digits, int i, int j) {
    i++;
    for (; i < j; i++) if (digits[i] != 0) return false;
    return true;
  }

  private static List<List<Integer>> comb(int n, int k) {
    return combiter(0, n, k);
  }

  private static List<List<Integer>> combiter(int s, int n, int k) {
    if (s > n) return new ArrayList<>();
    if (k == 0) {
      List<List<Integer>> res = new ArrayList<>();
      res.add(new ArrayList<>());
      return res;
    }
    List<List<Integer>> res = new ArrayList<>();
    List<List<Integer>> a = combiter(s + 1, n, k - 1);
    for (List<Integer> aa : a) {
      aa.add(0, s);
      res.add(aa);
    }
    List<List<Integer>> b = combiter(s + 1, n, k);
    res.addAll(b);
    return res;
  }
}


Measured memory_bytes: 95944
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (int i = 0; i < n; i++)
#define IREP(i, n) for (int i = n - 1; i >= 0; i--)
#define REPEACH(i,k) for(auto& i:k)
#define all(a) a.begin(),a.end()
#define MOD 1000000007
#define int long long
using namespace std;
typedef long long ll;

const ll INF = 1LL << 60;

signed main() {
	int n;
	cin >> n;
	cout << n*n*n << endl;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
c = 1
i = 0
while i < N - 1:
    if A[i] < A[i + 1]:
        while True:
            i += 1
            if i == N - 1:
                break
            if A[i] > A[i + 1]:
                c += 1
                i += 1
                break
    elif A[i] > A[i + 1]:
        while True:
            i += 1
            if i == N - 1:
                break
            if A[i] < A[i + 1]:
                c += 1
                i += 1
                break
    elif A[i] == A[i + 1]:
        i += 1
print(c)

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

int main(){
    int n ; cin >> n ;
    vector<int> a(n) ;
    for(int i=0;i<n;i++) cin >> a.at(i) ;
    int cnt = 0 ;
    for(int i=0;i<n-1;i++){
        int mn = i ;
        for(int j=i+1;j<n;j++){
            if(a.at(mn)>a.at(j)) mn = j ;
        }
        if(i!=mn){
            cnt++ ;
            int sub = a.at(i) ;
            a.at(i) = a.at(mn) ;
            a.at(mn) = sub ;
        }
    }
    for(int i=0;i<n;i++){
        cout << a.at(i) ;
        if(i==n-1) cout << endl ;
        else cout << " " ;
    }
    cout << cnt << endl ;
}


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

#define int long long
const int INF = 1e9;

int t0[17];
int t[17][17];
int N;
int dp[1<<17];

int dfs(int bit) {
	//cout << bit << endl;
	if ( bit == (1<<N)-1 ) return 0;
	if ( dp[bit] >= 0 ) return dp[bit];

	int ret = INF;
	for ( int i = 0; i < N; i++ ) {
		if ( (1<<i)&bit ) continue;
		int mi = t0[i];
		for ( int j = 0; j < N; j++ ) {
			if ( (1<<j)&bit ) mi = min(mi, t[i][j]);
		}
		ret = min(ret, dfs(bit|(1<<i))+mi);
	}

	return dp[bit] = ret;	
}

signed main() {
	while ( cin >> N, N ) {
		fill_n(dp, 1<<17, -1);		
		for ( int i = 0; i < N; i++ ) {
			cin >> t0[i];
			for ( int j = 0; j < N; j++ ) cin >> t[i][j];
		}

		cout << dfs(0) << endl;
	}
	return 0;
}



Measured memory_bytes: 4104
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using ull = unsigned long long;
using vll = vector<ll>;
using vi = vector<int>;
using vchar = vector<char>;
using vstr = vector<string>;
using pll =  pair<ll,ll>;

const ll mod = 1000000007;
const ll inf = 1000000000000000;

#define pi acos(-1)
#define pb push_back
#define test int TEST;cin>>TEST;while(TEST--)
#define all(x) x.begin(),x.end()
#define vsort(x) sort(all(x))
#define vrev(x) reverse(all(x));
#define vrevsort(xx) sort(xx.rbegin(),xx.rend())
#define min3(a,b,c) min(a,min(b,c))
#define min4(a,b,c,d) min(a,min(b,min(c,d)))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
#define max3(a,b,c) max(a,max(b,c))
#define max4(a,b,c,d) max(a,max(b,max(c,d)))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define opsp(x) cout<<x<<' '
#define opy cout<<"YES\n"
#define opn cout<<"NO\n"
#define flush fflush(stdout)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,a,b) for(int i=a;i<=b;i++)
#define reprev(i,a,b) for(int i=a;i>=b;i--)


void solve(){
	ll n;
        ll m;
        ll x,mna,mnb;
        cin >> n >> m >> x;
        
        vector<ll> a(n);
        mnb=mna=INT_MAX;
        for(int a_i = 0; a_i <n; a_i++){
           cin >> a[a_i];
           mna=min(mna,a[a_i]);
        }
        
        vector<ll> b(m);
        for(ll b_i =0; b_i <m; b_i++){
           cin >> b[b_i];
           mnb=min(mnb,b[b_i]);
        }
        if(x<mna && x<mnb) {cout<<0;return;}
        ll sum=0,count=0,i=0,j=0;        
        
        while(i<n && sum+a[i]<=x){   
            sum+=a[i];
            i++;
        }
        count=i;        
       
        while(j<m && i>=0){            
            sum+=b[j];             
            j++;
            while(sum>x && i>0){
                i--;
                sum-=a[i];
            }
            if(sum<=x && i+j>count)
                count=i+j;
        }
        cout<<count<<endl;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    //test{solve();}
	solve();
    return 0;
}


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

int main() {
    char c[3][3];
    for (int i = 0; i < 3; ++i) {
        for (int j = 0; j < 3; ++j) {
            std::cin >> c[i][j];
        }
    }

    std::printf("%c%c%c\n", c[0][0], c[1][1], c[2][2]);

    return 0;
}


Measured memory_bytes: 256