akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){
    int n; cin >> n;
    vector<vector<int>> Q;

    int cx = 0, cy = 0, bt = 0;bool fg = true;
    rep(i, n){
        int t, x, y; cin >> t >> x >> y;
        int dist = abs(x-cx) + abs(y-cy), time = t - bt;
        if(dist > time || dist%2 != time%2){
            fg = false; break;
        }
        bt = t; cx = x; cy = y;    
    }
    if(fg) cout << "Yes" << ln;
    else cout << "No" << ln;
}


Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#define mod 1000000007
#define eps 1e-9
#define PI 3.14159265358979323846
#define F first
#define S second
#define ll long long
#define pb push_back
#define mp make_pair
#define Fr(i,a,b) for(int i=a;i<=b;i++)
#define RF(i,a,b) for(int i=a;i>=b;i--)
#define pii pair<ll,int>
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define vpii vector<pii>
using namespace std;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
  
 
    int t=1;
    //cin>>t;
    while(t--){
        ll n,k;
        cin>>n>>k;
        vi a;
        vector<ll>b;
        int x,y;
        ll sum=0;
        Fr(i,0,n-1){
            cin>>x>>y;
            a.pb(x);
            b.pb(y);
            sum+=y;
        }
        vvi dp(n+1,vi(sum+1,INT_MAX));
        dp[0][0]=0;
        int ans=-1;
        Fr(i,1,n){
            Fr(j,0,sum){
                dp[i][j]=dp[i-1][j];
                if(j-b[i-1]>=0&&dp[i-1][j-b[i-1]]!=INT_MAX){
                    dp[i][j]=min(dp[i][j],dp[i-1][j-b[i-1]]+a[i-1]);
                }
                if(dp[i][j]<=k){
                    ans=max(ans,j);
                }
            }
        }
        cout<<ans<<endl;
    }
    return 0;
} 

Measured memory_bytes: 80256
A,V=list(map(int,input().split()))
B,W=list(map(int,input().split()))
T=int(input())
if A==B:
    print("YES")
    exit()
if A>B:
    h0 = -1*V * T + A
    h1 = -1*W * T + B
    if h0 <= h1:
        print("YES")
    else:
        print("NO")
else:
    h0 = V * T + A
    h1 = W * T + B
    if h0 >= h1:
        print("YES")
    else:
        print("NO")


Measured memory_bytes: 9200
n,m = map(int, input().split())
ns =[]
for i in range(n):
    ns.append(list(map(int, input().split())))
ns = sorted(ns, key=lambda x: x[0])
cnt = 0
yen = 0
for i in range(n):
    if cnt + ns[i][1] <= m:
        cnt += ns[i][1]
        yen += ns[i][0]*ns[i][1]
    else:
        yen += (m-cnt) * ns[i][0]
        break
print(yen)
    


Measured memory_bytes: 29792
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long 
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define all(x) (x).begin(),(x).end()
#define forn(i, a, b) for (int i=a; i<(signed)(b); ++i)
#define pb push_back
 
 
// debug templates 
#define debug(x)       cerr<< #x <<" : "<< x << endl;
#define debuga(A,N)    cerr<< #A <<" : [";for(int i = 0; i<N;i++) cerr<<A[i]<<" "; cerr<<"]\n";
#define debuga2(A,N,M) cerr<< #A << " : \n"; for(int i=0;i<N;i++){cerr<<"[";for(int j=0;j<M;++j) cerr<<A[i][j]<<" ";cerr<<"]\n";}
#define debugp(p)      cerr<< #p <<" : "<<"("<<(p).first<<","<<(p).second<<")\n";
#define debugv(v)      cerr<< #v <<" : "<<"[";for(int i = 0; i< (v).size(); i++) cerr<<v[i]<<" "; cerr<<"]\n";
#define debugv2(v)     cerr<< #v << " : \n"; for(int i=0;i<v.size();i++){cerr<<"[";for(int j=0;j<(v[0].size());++j) cerr<<v[i][j]<<" ";cerr<<"]\n";}
#define debugs(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin(); itr!=m.end();itr++) cerr<<*itr<<" "; cerr<<"]\n";
#define debugm(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin();itr!=m.end(); itr++) cerr<<"("<<itr->first<<","<<itr->second<<") ";cerr<<"]\n";
 

void solve(){
	int n; cin >> n;
	int a[n];
	forn(i,0,n) cin >> a[i];
	int dp[n];
	memset(dp,inf,sizeof(dp));
	dp[0] = 0;
	forn(i,1,n){
		if(i == 1) dp[i] = abs(a[i] - a[i-1]);
		else{
			dp[i] = min({dp[i],abs(a[i-1] - a[i]) + dp[i-1], abs(a[i-2] - a[i]) + dp[i-2]});
		}
	}
	debuga(dp,n);
	cout << dp[n-1];
}
 
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	solve();
	return 0;
}
 


Measured memory_bytes: 4372
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define per(i,m) for(long long i=m-1; i>=0; i--)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define ROF(i,n,m) for(long long i=n-1; i>=m; i--)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
typedef pair<ll, ll> LP;

ll POW(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW(x*x%MOD,n/2);
  return x*POW(x,n-1)%MOD;
}

ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}
 
ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}
 
ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}
 
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
 
ll modinv(ll a) {
    ll x, y;
    extGCD(a, MOD, x, y);
    return mod(x, MOD);
}
 
ll COM(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI(m)%MOD*modinv(KAI(n)%MOD*KAI(m-n)%MOD)%MOD;
}

ll DEC(ll x,ll m,ll n)
{
  return x%POW(m,n+1)/POW(m,n);
}

ll keta(ll x,ll n)
{
  if(x==0)return 0;
  return keta(x/n,n)+1;
}

ll DIV(ll x,ll n)
{
  if(x==0)return 0;
  return x/n+DIV(x/n,n);
}


int main()
{
  ll n,h[120],m,k[120],t,ans;
  m=0;
  t=0;
  ans=0;
  cin >> n;
  rep(i,n)k[i]=0;
  rep(i,n)cin >> h[i];
  rep(i,n)m=max(m,h[i]);
  while(m>0)
  {
  rep(i,n)if(h[i]==m)k[i]=1;
  if(k[0]==1)t++;
  FOR(i,1,n)if(k[i]==1&&k[i-1]==0)t++;
  ans+=t;
    t=0;
  rep(i,n)k[i]=0;
  rep(i,n)if(h[i]==m)h[i]-=1;
    m-=1;
  }
  printf("%lld",ans);
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn gcd(mut a: i32, mut b: i32) -> i32 {
    while b != 0 {
        let r = a % b;
        a = b; b = r;
    }
    a
}
fn lcm(x: i32, y: i32)->i32{
    return x /gcd(x, y) * y;
}
fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input!{
        n: usize,
        p: [i32; n],
    }
    let mut count = 0;
    for i in 1..(n + 1){
        if p[i - 1] != i as i32{
            count+=1;
        }
    }
    let ans = if count <= 2{"YES"}else{"NO"};
    puts!("{}\n", ans);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}

Measured memory_bytes: 8572
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll> 
#define P pair<ll,ll>
#define ALL(a) (a).begin(),(a).end()
#define YESNO(i) if((i)) puts("YES");else puts("NO");
#define YesNo(i) if((i)) puts("Yes");else puts("No");
#define yesno(i) if((i)) puts("yes");else puts("no");
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll s,w;cin>>s>>w;
  if(s<=w) puts("unsafe");else puts("safe");
  return 0;
}


Measured memory_bytes: 3656
import java.util.Scanner;

/**
 * Created by dizzyvn on 6/24/17.
 */
public class Main {
    public static void main(String[] args){
        // input
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n+1];
        for (int i = 1; i <= n; i++) {
            a[i] = sc.nextInt();
        }

        // process
        int count = 0;
        boolean[] flag = new boolean[n+1];

        int pos = 1;

        while (pos != 2 && !flag[pos]) {
            flag[pos] = true;
            pos = a[pos];
            count++;
        }

        // output
        if (pos == 2) {
            System.out.println(count);
        } else {
            System.out.println(-1);
        }
    }
}

Measured memory_bytes: 51144
a,b= map(int,input().split())
ans = ""
if(a>b):
    for i in range(a):
        ans += str(b)
    print(ans)
elif(a<b):
    for i in range(b):
        ans += str(a)
    print(ans)
else:
    for i in range(a):
        ans += str(a)
    print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<cmath>
#include<cstdio>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
using ll =long long;
using P = pair<int,int>;

int main(){
    string n;
    cin >> n;
    rep(i,3){
        if(n[i]=='7'){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define MAIN 100010
#define INF 0x3f3f3f3f
using namespace std;
int main()
{
    int n,data[MAIN]= {},ans=0;
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        cin>>data[i];
        ans+=abs(data[i]-data[i-1]);
    }
    ans+=abs(data[n+1]-data[n]);
    //cout<<ans<<endl;
    int jump[MAIN];
    for(int i=1; i<=n; i++)
        jump[i]=abs(data[i+1]-data[i-1]);
    for(int i=1; i<=n; i++)
    {
        int tmp=ans;
        tmp-=(abs(data[i]-data[i-1])+abs(data[i+1]-data[i]));
        tmp+=jump[i];
        cout<<tmp<<endl;
    }
    return 0;
}


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

const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];

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

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    COMinit();
    int N, K; cin >> N >> K;
    vector<long long> A(N);
    for(int i=0; i<N; ++i) cin >> A[i];
    sort(begin(A), end(A));

    long long res = 0;
    for(int j=0; j<=N-K; ++j) {
        res = (res + COM(K - 1 + j, K - 1) * A[K - 1 + j] % MOD) % MOD;
        res = (res + MOD) % MOD;
        res = (res - COM(N - 1 - j, K - 1) * A[j] % MOD) % MOD;
        res = (res + MOD) % MOD;
    }
    cout << res << endl;
}

Measured memory_bytes: 12928
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, o, n) for (auto i = (o); (i) < (n); ++(i))
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (auto i = (n)-1; (i) >= 0; --i)
#define REPI(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define REPIR(itr, v) for (auto itr = v.rbegin(); itr != v.rend(); ++itr)
#define fi first
#define se second
#define ll long long
#define V2(name, h, w) vector<vector<int> > name((h), vector<int>(w));
int main(){
	string S; cin >> S;
	REP(i, S.size()){
		if(i%2 == 0) cout << S[i];
	} 
  cout << endl;
}


Measured memory_bytes: 512
def main():
    n = int(input())
    a = [list(map(int, input().split())) for i in range(n)]

    total = sum([sum(a[i]) for i in range(n)])
    for k in range(n):
        for i in range(n):
            if k == i:
                continue
            for j in range(n):
                if i == j or k == j:
                    continue
                if a[i][j] > a[i][k] + a[k][j]:
                    print(-1)
                    exit()
    for i in range(n):
        for j in range(n):
            for k in range(n):
                if i == k or j == k:
                    continue
                if a[i][j] == a[i][k] + a[k][j]:
                    total -= a[i][j]
                    break

    print(total//2)


if __name__ == '__main__':
    main()


Measured memory_bytes: 45788
#include "bits/stdc++.h"
 
using ll = long long;
using namespace std;


void solveCase() {
   int n;
   cin >> n;
   vector <int> a(n);
   for(auto &e: a) cin >> e;

   vector <vector <int>> dp(n, vector <int> (2));
   dp[0][0] = 1;
   dp[0][1] = 1;

   // 0 -> increasing
   for(int i = 1; i < n; i++) {
      if(a[i] > a[i - 1]) {
         dp[i][0] = dp[i - 1][0];
         dp[i][1] = min(dp[i - 1][0], dp[i - 1][1]) + 1;
      } else if(a[i] < a[i - 1]){
         dp[i][1] = dp[i - 1][1];
         dp[i][0] = min(dp[i - 1][0], dp[i - 1][1]) + 1;
      } else {
         dp[i][0] = dp[i - 1][0];
         dp[i][1] = dp[i - 1][1];
      }
   }
   cout << min(dp[n - 1][0], dp[n - 1][1]) << endl;
}

int main() {
   cin.tie(0);
   cin.sync_with_stdio(0);
   
   int testcase = 1;
   // cin >> testcase;
 
   for(int i = 0; i < testcase; i++) {
      solveCase();
   }
 
   return 0;
}

Measured memory_bytes: 8980
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char s[5];
    cin>>s;
    int i=0;
    int flag=0;
    while(s[i]!='\0')
    {
        if(s[i]=='7')
        {
            flag=1;
        }
        i++;
    }
    if(flag==1)
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 3620
#define NDEBUG

#include <unordered_map>
#include <functional>
#include <algorithm>
#include <iostream>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <utility>
#include <random>
#include <string>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <tuple>
#include <set>
#include <map>

// [0, max)
#define FOR0(var, max) for (sl (var) = 0; (var) < (max); ++(var))
// [min, max)
#define FORi(var, min, max) for (sl (var) = (min); (var) < (max); ++(var))
// [min, max)
#define FORi_INV(var, min, max) for (sl (var) = (max) - 1; (var) + 1 > (min); --(var))

#define FORITER(var, iter) for (auto (iter) = (var).begin(); (iter) != (var).end(); (iter)++)
#define FORITER_INV(var, iter) for (auto (iter) = (var).rbegin(); (iter) != (var).rend(); (iter)++)

// a < b < c
#define LTLT(a, b, c) (((a) < (b)) && ((b) < (c)))
// a <= b < c
#define LELT(a, b, c) (((a) <= (b)) && ((b) < (c)))
// a < b <= c
#define LTLE(a, b, c) (((a) < (b)) && ((b) <= (c)))
// a <= b <= c
#define LELE(a, b, c) (((a) <= (b)) && ((b) <= (c)))

#ifndef NDEBUG
#  define MASSERT(cond) m_assert(cond, __LINE__, #cond);
#else
#  define MASSERT(...)
#endif

using namespace std;

using uc = unsigned char;
using ui = unsigned int;
using ul = unsigned long long int;
using ull = __uint128_t;

using sc = signed char;
using si = signed int;
using sl = signed long long int;
using sll = __int128_t;

using ld = long double;

void m_assert(const bool& cond, const sl& line, const char *condstr) {
  if (!cond) {
    cerr << "Assertion Failed: " << condstr << " at line " << line << endl;
    exit(1);
  }
}

namespace std {
  template <>
  struct is_integral<__int128_t> {
    constexpr static bool value = true;
  };
};

static sl N, K;

void solve(void) {
  ld x = log(N) / log(K);
  if (x - floor(x) < 1e-6) {
    x += 0.5;
  }
  cout << ceil(x) << endl;
}

int main(void) {
  cin >> N >> K;
  solve();
  return 0;
}

Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main(){
    int n;
    cin >> n;
    
    long long a;
    long long minValue = 1000000;
    long long maxValue = -1000000;
    long long sum = 0;
    
    for(int i = 0; i < n; i++){
        cin >> a;
        
        sum += a;
        if(a < minValue) minValue = a;
        if(a > maxValue) maxValue = a;
        
    }
    
    cout << minValue << " " << maxValue << " " << sum << endl;
    
    return 0;
}


Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;cin >> s;
    int n=s.size();
    vector<int> c(2);
    for(int i=0;i<n;i++){
        c[s[i]-'0']++;
    }
    cout << 2*min(c[0],c[1]) << endl;
}

Measured memory_bytes: 640
#include<iostream>
        using namespace std;
        int main()
        {
            // 整数の入力
            int X,Y,Z;
            cin >> X >> Y;
            switch (X){
              case 1:
                Z += 300000;
                if (Y == 1){
                  Z += 400000;
                }
                break;
              case 2:
                Z += 200000;
                break;
              case 3:
                Z += 100000;
                break;
              default:
                break;
            }
            switch (Y){
              case 1:
                Z += 300000;
                break;
              case 2:
                Z += 200000;
                break;
              case 3:
                Z += 100000;
                break;
              default:
                break;
            }
            // 出力
            cout << Z << endl;
            return 0;
        }

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <queue>
using namespace std;

#define W 50
#define H 50
#define INF 19980725

struct P
{
  int x;
  int y;
  int w;
  P ( int x, int y, int w ) { this->x = x; this->y = y; this->w = w; }
  int operator> ( const P &p ) const { return ( this->w > p.w ); }
};

static int w, h;
static int d[ W ][ H ];
static int k_operafan[ W ][ H ];

int
main (
  int   argc,
  char *argv[ ]
  )
{
  priority_queue<P, vector<P>, greater<P> > lis;
  int i, j;

  scanf ( "%d%d", &h, &w );
  for ( j = 0; j < h; ++j )
  for ( i = 0; i < w; ++i )
  {
    char ch;

    scanf ( " %c", &ch );
    d[ i ][ j ] = ch - '0';
  }

  for ( i = 0; i < w; ++i )
  for ( j = 0; j < h; ++j )
    k_operafan[ i ][ j ] = INF;

  lis.push ( P ( 0, 0, d[ 0 ][ 0 ] ) );
  while ( !lis.empty ( ) )
  {
    const P p = lis.top ( );
    lis.pop ( );

    if ( k_operafan[ p.x ][ p.y ] != INF ) continue ;
    k_operafan[ p.x ][ p.y ] = p.w;
    if ( p.x == w - 1 && p.y == h - 1 ) break ;

    if ( p.x + 1 < w && k_operafan[ p.x + 1 ][ p.y ] == INF )
      lis.push ( P ( p.x + 1, p.y, p.w + d[ p.x + 1 ][ p.y ] ) );
    if ( p.y + 1 < h && k_operafan[ p.x ][ p.y + 1 ] == INF )
      lis.push ( P ( p.x, p.y + 1, p.w + d[ p.x ][ p.y + 1 ] ) );
  }
  printf ( "%d\n", k_operafan[ w - 1 ][ h - 1 ] );

  return ( EXIT_SUCCESS );
}

Measured memory_bytes: 1056
#include <deque>
#include <iostream>
#include <string>

using namespace std;

int main() {
	
	string s;
	deque <int> x;

	while(cin >> s) {
		x.clear();
		for(int i=0; i<10; i++) {
			x.push_back(s[i]-48);
		}
		while(x.size()!=1) {
			for(int i=0; i<x.size()-1; i++) {
				if(x[i]+x[i+1]<=9)
					x[i]+=x[i+1];
				else
					x[i]+=x[i+1]-10;
				if(i==x.size()-2)
					x.pop_back();
			}
		}
			cout << x[0] << endl;
	}

	return 0;

}

Measured memory_bytes: 0
#include<algorithm>
#include<iostream>
#include<vector>

using namespace std;

constexpr int MAX_N = 100000;
vector<int> pre_order(MAX_N, -1);//pre_order[i]:=??±???????????¢?´¢??§???????????????i????????£?????¨??????timer
vector<int> post_order(MAX_N, -1);//post_order[i]:=??±???????????¢?´¢??§???????????????i????????£?????¨??????timer
vector<int> parent(MAX_N, -1);//parent[i]:=??±???????????¢?´¢??§??¨????§????????????¨???????????????i??????
vector<bool> visited(MAX_N, false);//??±???????????¢?´¢???????????§????¨?????????????????????°???????´?????????????

vector<vector<int>> G(MAX_N);

void add_edge(int s, int t) {
	G[s].emplace_back(t);
	G[t].emplace_back(s);
}

void dfs(const vector<vector<int>>& G, int u = 0, int prev_u = -1, int timer = 1) {
	pre_order[u] = timer;
	post_order[u] = timer;
	++timer;

	//u????¨????????????¨????????¢
	visited[u] = true;


	for (auto&& v:G[u]) {
		//u?????£??\??????????????????v == G[u][i] ???????¨?
		if (!visited[v]) {

			//v?????????u??§?¢??????????
			parent[v] = u;

			//v??\????????±???????????¢?´¢????????????
			dfs(G, v, u, timer);

			//u???post_order?????´??°??????
			post_order[u] = min(post_order[u], post_order[v]);
		}

		//u?????£??\??????????????????v?????¢?¨?????????¢?´¢??§??´????????§????????£??????????????¨?????????
		else if (v != prev_u) {
			post_order[u] = min(post_order[u], pre_order[v]);
		}
	}
}

vector<int> articulation_points(const vector<vector<int>>& G, int G_sz, int root = 0) {
	dfs(G, root);
	vector<int> ans;
	vector<bool> used(G_sz, false);
	int root_child = 0;
	for (int j = 0; j < G_sz; ++j) {
		if (parent[j] == root)++root_child;
		if (root_child == 2) {
			ans.emplace_back(root);
			break;
		}
	}
	for (int i = 1; i < G_sz; ++i) {
		if (parent[i] != root
			&&pre_order[parent[i]] <= post_order[i]
			&& !used[parent[i]]) {

			ans.emplace_back(parent[i]);
			used[parent[i]] = true;
		}
	}
	sort(ans.begin(), ans.end());
	return ans;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N, E;cin >> N >> E;
	int s, t;
	for (int i = 0; i < E; ++i) {
		cin >> s >> t;
		add_edge(s, t);
	}
	vector<int>ans = articulation_points(G, N);
	for (auto&& v : ans) {
		cout << v << endl;
	}
}

Measured memory_bytes: 6136
#include<cstdio>
#include<cmath>
double xa,ya,ra,xb,yb,rb;
double dist(){
    return sqrt((xa-xb)*(xa-xb)+(ya-yb)*(ya-yb));
}
int main(){
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%lf%lf%lf%lf%lf%lf",&xa,&ya,&ra,&xb,&yb,&rb);
        if(dist()+rb<ra) printf("2\n");
        else if(dist()+ra<rb) printf("-2\n");
        else if(dist()>ra+rb) printf("0\n");
        else printf("1\n");
    }
}

Measured memory_bytes: 0
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N;
char S[300][300];
char T[300][300];

bool ok() {
  rep(x, N) rep(y, N) if (T[x][y] != T[y][x]) return false;
  return true;
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N;
  rep(y, N) rep(x, N) cin >> S[x][y];
  int s = 0;
  rep(d, N) {
    rep(x, N) rep(y, N) T[(x+d)%N][y] = S[x][y];
    if (ok()) s++;
  }
  cout << s*N << "\n";
  return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define ll long long
#define min(a,b) (a)<(b)?(a):(b)
#define max(a,b) (a)>(b)?(a):(b)

int N;

void string(char *s,char max){
	int n=strlen(s);
	if( n==N ){
		printf("%s\n",s);
	}else{
		for(char c='a';c<=max;c++){
			*(s+n) = c;
			if(c==max) string(s,max+1);
			else string(s,max);
		}
		*(s+n)=0;
	}
}

int main(){
	scanf("%d",&N);
	char s[N+1]; rep(i,0,N+1) s[i]=0;
	string(s,'a');
	return 0;
}

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

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

int main(){
    string s; cin >> s;

    int sz = s.size();

    ll all_pat = pow(2, sz - 1);

    ll ans = 0;
    reverse(s.begin(), s.end());
    rep(pat, all_pat){
        ll d = 1;
        
        for(int i = 0; i < sz - 1; i ++){
            ans += (s.at(i) - '0') * d;
            if((pat >> i) & 1) d = 1;
            else d *= 10;
        }

        ans += (s.at(sz - 1) - '0') * d;
    }

    cout << ans << endl;
}

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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];
    int m = 0;
    rep(i, n) m = max(m, a[i]);
    vi prime(m+1);
    for (int i=2; i<=m; ++i) {
        if (prime[i]!=0) continue;
        for (int j=i; j<=m; j+=i) prime[j] = i;
    }
    int res = a[0];
    rep1(i, n-1) res = gcd(res, a[i]);
    if (res != 1) {
        cout << "not coprime" << endl;
        return 0;
    }
    vector<bool> exist(m+1);
    rep(i, n) {
        if (a[i] == 1) continue;
        while (a[i] > 1) {
            if (exist[prime[a[i]]]) {
                cout << "setwise coprime" << endl;
                return 0;
            }
            else {
                exist[prime[a[i]]] = true;
                int tmpa = a[i];
                while (tmpa%prime[a[i]]==0) tmpa /= prime[a[i]];
                a[i] = tmpa;
            }
        }
    }
    cout << "pairwise coprime" << endl;
    return 0;
}


Measured memory_bytes: 11076
#include<stdio.h>
int a[50][50],w,h;
void sima(int x,int y) {
  int i,j;
  a[y][x]=0;
  for(i=-1;i<=1;i++){
    for(j=-1;j<=1;j++){
      if(x+i>=0 && x+i<w && y+j>=0 && y+j<h){
	if(a[y+j][x+i]==1) sima(x+i,y+j); 
      }
    }
  }
}
int main(){

  int i,j,count;
  while(1){
    count=0;

  scanf("%d%d",&w,&h);
  if(w==0 && h==0) break;

  for(i=0;i<h;i++){
    for(j=0;j<w;j++){
      scanf("%d",&a[i][j]);
    }
  }

  for(i=0;i<h;i++){
    for(j=0;j<w;j++){
      if(a[i][j]==1){
	count++;
	sima(j,i);
      }
    }
  }   
  printf("%d\n",count);
  }

    return 0;
  }

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

using ll = long long;

void solve(void){
  int a, b, c; cin >> a >> b >> c;

  int sum = a;
  while (sum <= b * a) {
    if (sum % b == c) {
      cout << "YES" << endl;
      return;
    }
    sum += a;
  }

  cout << "NO" << endl;
}

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

Measured memory_bytes: 256
import java.util.Scanner;
class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
      	String a = "ACL";
        String b = "";
      	for(int i=0; i < K; i++){
        	b = b + a;
        }
      System.out.println(b);
    }
}

Measured memory_bytes: 39236
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { reader: s.lock() };
    let n: usize = sc.read();
    let mut candidates = vec![n];
    let mut cur = 10;
    for _ in 0..17 {
        let p = n / cur * cur;
        if p > 0 {
            candidates.push(p - 1);
        }
        cur *= 10;
    }
    let mut ans = vec![];
    for &candidate in candidates.iter() {
        let mut c = candidate;
        let mut sum = 0;
        while c > 0 {
            sum += c % 10;
            c /= 10;
        }
        ans.push(sum);
    }
    ans.sort();
    ans.reverse();
    println!("{}", ans[0]);
}

pub struct Scanner<R> {
    reader: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .reader
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define N 200000
typedef long long LL;
using namespace std;
int r[N], X, k, Q;

int calc(LL x) {
    if (x > X) x = X;
    if (x < 0) x = 0;
    return x;
}

int main() {
    cin >> X >> k;
    for(int i = 1; i <= k; i++) scanf("%d", &r[i]);
    cin >> Q;
    int p = 1, L = 0, R = X, ty = -1;
    LL now = 0;
    while (Q--) {
        int t, a;scanf("%d%d", &t, &a);
        while (p <= k && r[p] <= t) {
            int tmp = (r[p] - r[p - 1]) * ty;
            L = calc((LL)L + tmp), R = calc((LL)R + tmp), now = now + tmp;
            p++, ty *= -1;
        }
        int det = t - r[p - 1], ret = now + a;
        if (ret > R) ret = R;
        if (ret < L) ret = L;
        ret = calc((LL)ret + det * ty);
        printf("%d\n", ret);
    }
}


Measured memory_bytes: 1536
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
	Scanner in = new Scanner(System.in);
	StringBuilder sb = new StringBuilder();
	int n = in.nextInt();
	Integer[] a = new Integer[n];
	for (int i = 0; i < n; i++) {
	    a[i] = in.nextInt();
	}
	for (int i = 0; i < n; i++) {
	    int v = a[i];
	    int j = i - 1;
	    while (j >= 0 && a[j] > v) {
		a[j + 1] = a[j];
		j--;
	    }
	    a[j + 1] = v;
	    sb.setLength(0);
	    for (int k = 0; k < n; k++) {
		sb.append(a[k]);
		sb.append(" ");
	    }
	    System.out.println(sb.toString().trim());
	}

    }
}



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



int main() {
	int N;
	string S;
	bool flag=false;

	cin >> N;


	for (int i = 0; i < N; i++)
	{
		cin >> S;
		if (S == "Y") flag = true;
	}

	if (flag)
		cout << "Four";
	else cout << "Three";

}

Measured memory_bytes: 256
i = false

while true
  cost = gets.to_i/10 #????°????0????¬±??¶??????
  break if cost==0

  puts "" if i
  i = true
  
  m1,m5,m10,m50 = gets.split(" ").map{|s| s.to_i}

  n = m1+5*m5+10*m10+50*m50 #?????????n = m1+m5+m10+m50??¨??????????????§?????????????????????????????£???????????°???????????????????????¨????????£????????????????????????????????¨??¨10???????????¨?????????????????°???????????????????????¨??????????????§????????????????????????????????????

  for i in 0..m1
    for j in 0..m5
      for k in 0..m10
        for l in 0..m50
          change = i + j*5 + k*10 + l*50 - cost
          if change >= 0
            mm1 = m1-i+change%5
            mm5 = m5-j+(change%10)/5
            mm10 = m10-k+(change%50)/10
            mm50 = m50-l+(change/50)
            nn = mm1+mm5+mm10+mm50
            a1,a5,a10,a50,n = i,j,k,l,nn if n>nn
          end
        end
      end
    end
  end

  puts "10 #{a1}" if a1!=0
  puts "50 #{a5}" if a5!=0
  puts "100 #{a10}" if a10!=0
  puts "500 #{a50}" if a50!=0
end

Measured memory_bytes: 8788
from sys import stdin
import itertools
N,M,Q=list(map(int, (stdin.readline().strip().split())))
q=[]
num_list=[]
number=[]
score=[0]
daburi=[]
for i in range(1,M+1):number.append(i)
for _ in range(Q):
    a,b,c,d=list(map(int, (stdin.readline().strip().split())))
    q.append([a,b,c,d])
def dfs(num_list,i):
    if i==M and len(num_list)<N:
        return
    if len(num_list)!=N:
        a=num_list.copy()
        num_list.append(number[i])
        dfs(num_list,i)
        dfs(a,i+1)
    else:
        ans=0
        for a,b,c,d in q:
            if num_list[b-1]-num_list[a-1]==c:
                ans+=d
        score[0]=max(ans,score[0])



dfs(num_list,0)
print(score[0])


Measured memory_bytes: 9116
#include<cstdio>
#include<iostream>
#include<stack>

using namespace std;

int main(void){

	char inp;
	stack<char> data;
	int flag,flag2;

	while(1){
		flag=0,flag2=0;
		while(!data.empty()) data.pop();
		while(1){
			inp=getchar();
			switch(inp){
				case '(':
					data.push('(');
					break;
				case '[':
					data.push('[');
					break;
				case ')':
					if(data.empty()==1){
						flag=1;
						break;
					}
					if(data.top()=='(') data.pop();
					else flag=1;
					break;
				case ']':
					if(data.empty()==1){
						flag=1;
						break;
					}
					if(data.top()=='[') data.pop();
					else flag=1;
					break;
				default:
					break;
			}
			if(inp=='.') break;
			flag2=1;
		}
		if(flag2==0) break;
		if(flag==0&&data.empty()==1) cout<<"yes"<<endl;
		else cout<<"no"<<endl;
		getchar();
	}

	return 0;
}

Measured memory_bytes: 1152
use proconio::input;
use proconio::marker::*;
use proconio::fastout;

#[fastout]
fn main() {
    input! {
    x: i64
    }
    let mut al = vec![(0, 0)];
    let mut a:i64 = 1;
    let mut je:i64 = 1;
    let mut ans = (0, 0);

    while je <= x{
        let a5:i64 = a.pow(5);
        al.push((a, a5));
        al.push((-a, -a5));
        a += 1;
        je = 5 * a.pow(4) - 10 * a.pow(3) + 10 * a.pow(2) - 5 * a + 1;
    }
    al.sort_by_key(|&k| k.0);
    let mut b:i64 = 0;
    while ans == (0,0) {
        let b5:i64 = b.pow(5);
        let rp = x + b5;
        let rm = x - b5;
        match  al.binary_search_by_key(&rp, |&(a, b)| b) {
            Ok(v) => ans = (al[v].0, b),
            Err(_) => (),
        }
        match  al.binary_search_by_key(&rm, |&(a, b)| b) {
            Ok(v) => ans = (al[v].0, -b),
            Err(_) => (),
        }
        b += 1;
    }
    println!("{} {}", ans.0, ans.1)
}


Measured memory_bytes: 2156
#include <bits/stdc++.h>
using namespace std;
int n, k, a[1010], ans;
int main() {
    cin >> n >> k;
    for (int i = 0; i < n; i ++) cin >>a[i];
    sort(a, a+n);
    for (int i = 0; i < k; i ++) ans += a[i];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3636
using System;

public class hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var x = int.Parse(line[0]);
        var y = int.Parse(line[1]);
        getAns(x, y);
    }
    static void getAns(int x, int y)
    {
        if (x == 0 && y == 0) { Console.WriteLine(1); return; }
        if (x == 1 && y == 0) { Console.WriteLine(2); return; }
        var xmax = 0; var xmin = 0; var ymax = 0; var ymin = 0;
        var c = 3;
        var p = 3;
        var pre1 = 1; var pre2 = 1;
        while (true)
        {
            var w = pre1 + pre2;
            if (p == 0) xmin -= w;
            else if (p == 1) ymin -= w;
            else if (p == 2) xmax += w;
            else ymax += w;
            if (x <= xmax && x >= xmin && y <= ymax && y >= ymin)
            { Console.WriteLine(c); return; }
            pre1 = pre2;
            pre2 = w;
            c++;
            if (c > 3) c = 1;
            p++;
            if (p > 3) p = 0;
        }
    }
}



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

int k;

int solve(int *arr,int n,int *dp )
{
if(n <0) return INT_MAX;
if(n==1) return 0;
if(n==2) return abs(arr[1]-arr[0]);

if(dp[n]==-1)
{
    int ans=INT_MAX;
for(int i=1;i<=k;i++)
{
int first=abs(arr[n-1]-arr[n-i-1])+solve(arr,n-i,dp);
ans= min(first,ans);
}
dp[n]=ans;
}

return dp[n];

}

int32_t main()
{
    int n; cin>>n;
    cin>>k;
    int arr[n];
    int dp[n+1];
    for(int i=0;i<=n;i++) dp[i]=-1;
    for(int i=0;i<n;i++) cin>>arr[i];

    int ans=solve(arr,n,dp);
    cout<<ans<<endl;


    return 0;
}

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

int main(){
  string S;
  cin >> S;
  
  if ("Sunny" == S){
    cout << "Cloudy" << endl;
  }
  else if ("Cloudy" == S){
    cout << "Rainy" << endl;
  }
  else if ("Rainy" == S){
    cout << "Sunny" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll                long long int
#define ld                long double
#define pb                push_back
#define mk                make_pair
#define in(i,a,n)         for(ll i=0;i<n;++i) cin>>a[i];
#define out(i,a,n)        for(ll i=0;i<n;++i) cout<<a[i]<<" ";
#define sz(c)             (ll)c.size()
#define all(c)            c.begin(), c.end()
#define rall(c)           c.rbegin(), c.rend()
#define loop(i,a,b)       for(ll i=a;i<b;i++)
#define rloop(i,a,b)      for(ll i=a;i>b;i--)
#define F                 first
#define S                 second
#define copy(a,b)         copy(all(a),back_inserter(b));
#define intersect(a,b,w)    set_intersection(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define union(a,b,w)      set_union(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define diff(a,b,w)       set_difference(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define symdiff(a,b,w)    set_symmetric_difference(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define deb(x) cout << #x << " " << x << endl
#define inf INT_MAX
const ll N = 200010;
const ll MOD = 998244353;
ll mod(ll n) {
    return (n % MOD + MOD) % MOD;
}

void solve(){
    ll n;
    string s;
    set<string> myset;
    cin >> n;
    while(n--){
        cin >> s;
        myset.insert(s);
    }
    cout << sz(myset) << "\n";
}

int main(){
    //fin fout
    fast
    ll T = 1; //cin >> T;
    loop(i, 0, T) solve();
}


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

using namespace std;
typedef long long lint;

#define RPT(i, b, e) for (int i = (b); i <= (e); i++)
#define RPT0(i, n) RPT(i, 0, n - 1)
#define RPT1(i, n) RPT(i, 1, n)
#define EACH(it, v) for (const auto& it : v)
#define ALL(v) v.begin(), v.end()

void resolve()
{
    int N;
    cin >> N;

    lint ans = 0;
    RPT1(i, N) ans += (i % 3 != 0 && i % 5 != 0) ? i : 0;
    cout << ans << endl;
}

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


Measured memory_bytes: 3640
fun main(args: Array<String>){
    val N = readLine()!!.toInt()
    val pair = Array((N+1)/2){ mutableSetOf<Int>() }
    if(N % 2 == 0){
        for(i in 1..N/2){
            pair[i - 1].add(i)
            pair[i - 1].add(N - i + 1)
        }
    }else{
        for(i in 1..(N - 1)/2){
            pair[i - 1].add(i)
            pair[i - 1].add(N - i)
        }
        pair[(N+1)/2 - 1].add(N)
    }

    val v = mutableListOf<Pair<Int, Int>>()
    for(i in 0 until pair.size - 1){
        pair[i].forEach { p1 ->
            pair[i+1].forEach { p2 ->
                v.add(Pair(p1, p2))
            }
        }
    }
    if(pair.size > 2){
        pair[pair.size - 1].forEach { p1 ->
            pair[0].forEach { p2 ->
                v.add(Pair(p1, p2))
            }
        }
    }

    println(v.size)
    println(v.map { "${it.first} ${it.second}" }.joinToString(separator = "\n"))
}

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

typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;
const double pi = 3.141592653589793238;

// a と b の最大公約数を返す関数
long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}


int main() {
  unsigned long long K, A, B;
  cin >> K >> A >> B;

  unsigned long long res = 0;
  if(B <= A+1 || K <= A) { // １円との交換レートが引くもしくは同じ
    cout << K + 1 << endl;
    return 0;
  } else if(K > A){
    res = B + ( (K - (A - 1)) / 2 - 1) * (B-A) + ( (K - (A - 1)) % 2 );
    cout << res << endl;
    return 0;
  }


}

//384626433 + (384626433 - 35897932) * ( (314159265 - (35897932 - 1)) / 2 - 1) + ( (314159265 - (35897932 - 1)) % 2)


Measured memory_bytes: 256
//Classic
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pi pair<int,int>
#define vp vector<pi>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define For(i,a,b) for(ll i=a;i<b;i++)
#define endl "\n"
#define debug(x) cout<<"AA Baju Smit------> "<<#x<<" -> "<<x<<endl
#define all(x) x.begin(),x.end()
#define mint map<int,int>
#define mod 1000000007
#define ciN cin
#define X INT_MAX
#define N INT_MIN
////////////////////////////////////////////////////////////////

void jabru() {
	ll a, b, c, d; cin >> a >> b >> c >> d;
	ll ans = a * c;
	ans = max(ans, a * c);
	ans = max(ans, b * d);
	ans = max(ans, b * c);
	ans = max(ans, a * d);
	cout << ans << endl;
}

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


int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t;
	//cin >> t;
	t = 1;
	while (t--)
		jabru();


	return 0;
}





///////////////////////////////////////////////////////////////////////////////////////////
//Kai baju bhai???


Measured memory_bytes: 3644
# ABC107C - Candles (ARC101C)
def main():
    _, k = map(int, input().split())
    x = tuple(map(int, input().split()))
    print(min(r - l + min(abs(l), abs(r)) for l, r in zip(x, x[k - 1 :])))


if __name__ == "__main__":
    main()

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

int main() {
    int n;
    cin >> n;
    long long a[n], b[n];
    for (int i = 0; i < n; i++) cin >> a[i] >> b[i];

    long long cnt = 0;
    for (int i = n - 1; i >= 0; i--) {
        a[i] += cnt;
        if (a[i] % b[i] != 0) cnt += b[i] - a[i] % b[i];
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 1792
package main

import (
	"fmt"
)

func main() {
	var k, s, ans int
	fmt.Scan(&k, &s)

	for i := 0; i < k+1; i++ {
		for j := 0; j < k+1; j++ {
			t := s - i - j
			if 0 <= t && t <= k {
				ans++
			}
		}
	}
	if ans != 0 {
		fmt.Println(ans)
	}
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
//T+N
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
template<class T> inline void fix(T &x) {if(x >= mod | x <= -mod) {x %= mod;} if(x < 0) {x += mod;}}
#define out(x) cout << __LINE__ << ": " << (#x) << " = " << (x) << endl

const ll MAX_N = 2e5 + 20;

struct rollbackFen {
	ll sz;
	vector<ll> tree;
	stack<vector<pair<ll, ll> > > changes;
	rollbackFen(ll _sz) {
		sz = _sz;
		tree.resize(sz + 10);
	}
	void upd(ll ind, ll val) {
		vector<pair<ll, ll> > curr;
		if(ind == 0) {return;}
		for(; ind <= sz; ind += ind & (-ind)) {
			if(val > tree[ind]) {
				curr.push_back({ind, tree[ind]});
				tree[ind] = val;
			}
		}
		changes.push(curr);
	}
	ll ans(ll ind) {
		ll ans = 0;
		for(; ind > 0; ind -= ind & (-ind)) {
			ans = max(ans, tree[ind]);
		}
		return ans;
	}
	ll ans() {
		return ans(sz);
	}
	void roll() {
		vector<pair<ll, ll> > curr = changes.top(); changes.pop();
		for(ll i = 0; i < curr.size(); i ++) {
			tree[curr[i].first] = curr[i].second;
		}
	}
};

rollbackFen lis(MAX_N);

void add(ll x) {
    lis.upd(x, lis.ans(x - 1) + 1);
}

void remove() {
    lis.roll();
}

vector<ll> g[MAX_N];
ll arr[MAX_N];
ll ans[MAX_N];

void dfs(ll x, ll p) {
    add(arr[x]);
    ans[x] = lis.ans();
    for(auto it : g[x]) {
        if(it == p) {continue;}
        dfs(it, x);
    }
    remove();
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll n;
    cin >> n;
    vector<ll> c;
    for(ll i = 1; i <= n; i ++) {
        cin >> arr[i];
        c.push_back(arr[i]);
    }
    sort(c.begin(), c.end());
    c.resize(unique(c.begin(), c.end()) - c.begin());
    for(ll i = 1; i <= n; i ++) {
        arr[i] = lower_bound(c.begin(), c.end(), arr[i]) - c.begin();
        arr[i] ++;
    }
    for(ll i = 0; i < n - 1; i ++) {
        ll a, b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    dfs(1, 0);
    for(ll i = 1; i <= n; i ++) {
        cout << ans[i] << endl;
    }
    return 0;
}



Measured memory_bytes: 44680
from logging import *
basicConfig(level=DEBUG, format='%(levelname)s: %(message)s')
disable(CRITICAL)

def solve():
    P.sort(reverse = True)
    M.sort()
    debug('k {} n {}'.format(k,n))
    debug('P {}'.format(P))
    debug('M {}'.format(M))
    can_positive = False
    if len(P) > 0:
        if k < n: can_positive = True
        else: can_positive = len(M)%2 == 0
    else: can_positive = k%2 == 0

    if can_positive:
        debug('positive')
        P.sort()
        M.sort(reverse = True)
        p0 = []
        if k%2: p0.append(P.pop())
        ar = []
        while len(P) >= 2: ar.append(P.pop() * P.pop())
        while len(M) >= 2: ar.append(M.pop() * M.pop())
        ar.sort(reverse = True)
        debug('p0 {}'.format(p0))
        debug('ar {}'.format(ar))
        debug('ar[:k] {}'.format(ar[:(k-k%2)//2]))
        return p0 + ar[:(k-k%2)//2]
    else: # can negative
        debug('negative')
        return sorted(P+M, key=lambda x: abs(x))[:k]


n, k = map(int, input().split())
P, M = [], [] # plus, minus
for a in map(int, input().split()):
    if a < 0: M.append(a)
    else: P.append(a)
ans, MOD = 1, 10**9 + 7
for a in solve(): ans *= a; ans %= MOD
ans += MOD; ans %= MOD
print(ans)


Measured memory_bytes: 34852
#D問題

#warshall_floyd法
def warshall_floyd(dist):
    #dist[i][j]: iからjへの最短距離
    for k in range(N):
        for i in range(N):
            for j in range(N):
                dist[i][j] = min(dist[i][j],dist[i][k] + dist[k][j])
    return dist

N,M,R=map(int,input().split())
r=list(map(int,input().split()))

dist = [[float("inf") for i in range(N)] for i in range(N)] 
#dist[u][v] : 辺uvのコスト(存在しないときはinf)
for i in range(M):
    a,b,c = map(int,input().split())
    dist[a-1][b-1] = c
    dist[b-1][a-1] = c
for i in range(N):
    dist[i][i] = 0 #自身のところに行くコストは０
dist=warshall_floyd(dist)

ever=[]
MIN=100000000
def ans_func(ever):
    global R
    global r
    global dist
    global MIN
    
    if len(ever) == R:
        if R == 2:
            kari=dist[ever[0]][ever[1]]
            MIN=min(MIN,kari)
        else:
            kari=0
            for i in range(R-1):
                kari+=dist[ever[i]][ever[i+1]]
            MIN=min(MIN,kari)
    else:
        i=0
        for i in range(R):
            if r[i]-1 in ever:
                pass
            else:
                ever.append(r[i]-1)
                ans_func(ever)
                ever.remove(r[i]-1)
    return
ans_func(ever)
print(MIN)
    

Measured memory_bytes: 63448