akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

//#define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* cpp template {{{ */

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define rep(i, n) REPS(i, 0, n)
#define REP0(i,n) for (ll i = 0; i <= (ll)(n); ++i)
#define REP1(i,n) for (ll i = 1; i <= (ll)(n); ++i)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; cin >> x; return x;}
inline ll IN() {ll x; cin >> x; return x;}
inline vs split(const string& t, char c) {vs v; stringstream s(t); string b; while(getline(s, b, c)) v.eb(b); return v;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << endl;}
template <typename T> inline void print(const T& x) {cout << x << '\n';}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {for (auto&& p : v) print(p);}
template <typename T> inline void print(const vector<T>& v, string s = " ") {rep(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) is >> x;
  //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいいです。
  return is;
}
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
  for(int i=0; i<vec.size(); i++){
    os << vec[i] << ( i+1 == vec.size() ? "" : " " );
  }
  return os;
}
/* }}} */

signed main() 
{
  int a,b;
  cin >> a >> b;
  print((a+b+1)/2);
  return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::*;
use std::f64::consts::*;
use std::f64;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        a: i32,
        b: i32,
        c: i32,
    }
    if (a == b && b == c && a % 2 == 0) {
        println!("-1");
        return;
    }
    let (mut a, mut b, mut c) = (a, b, c);
    let mut cnt = 0;
    let mut a_half = 0;
    let mut b_half = 0;
    let mut c_half = 0;
    loop {
        if a % 2 > 0 || b % 2 > 0 || c % 2 > 0 {
            break;
        }
        cnt += 1;
        a_half = a / 2;
        b_half = b / 2;
        c_half = c / 2;
        a = b_half + c_half;
        b = a_half + c_half;
        c = a_half + b_half;
    }
    println!("{}", cnt);
}

Measured memory_bytes: 2100
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		char[] ch = s.toCharArray();
		int ans = 0;
		for (int i = 0; i < 3; i++) {
			if(ch[i] == '1') {
				ans++;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 21840
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(X, Y):
    def f(x):
        if x == 3:
            return 100000
        elif x == 2:
            return 200000
        elif x == 1:
            return 300000
        return 0

    b = 400000 if X == 1 and Y == 1 else 0
    return f(X) + f(Y) + b


def main():
    X, Y = read_int_n()
    print(slv(X, Y))


if __name__ == '__main__':
    main()


Measured memory_bytes: 6604
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1000000000;

int bingo[3][3];

int main()
{
   rep(i,3)
   rep(j,3)cin >> bingo[i][j];
   int n;
   cin >> n;
   bool is[3][3] = {};
  
   rep(i,n)
   {
      int b;
      cin >> b;
      rep(j,3)
      {
         rep(k,3)
         {
            if(bingo[j][k]==b)
            {
               is[j][k]=1;
            }
         }
      }
   }
  
   bool ans = false;
   if(is[0][0]&&is[0][1]&&is[0][2])ans = true;
   if(is[1][0]&&is[1][1]&&is[1][2])ans = true;
   if(is[2][0]&&is[2][1]&&is[2][2])ans = true;
   if(is[0][0]&&is[1][0]&&is[2][0])ans = true;
   if(is[0][1]&&is[1][1]&&is[2][1])ans = true;
   if(is[0][2]&&is[1][2]&&is[2][2])ans = true;
   if(is[0][0]&&is[1][1]&&is[2][2])ans = true;
   if(is[0][2]&&is[1][1]&&is[2][0])ans = true;
   if(ans)
   {
      cout<<"Yes"<<endl;
   }
   else
   {
      cout<<"No"<<endl;
   }
   
   return 0;
}

Measured memory_bytes: 256
import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

n = int(input())
m = 10**5
G = [[] for i in range(2*m)]
for i in range(n):
    x,y = map(int, input().split())
    x,y = x-1, y-1
    G[x].append(m+y)
    G[m+y].append(x)

from collections import deque
used = [0]*(2*m)
def dfs(i):
    q = deque([i])
    x = 0
    y = 0
    edge = 0
    while q:
        cur = q.pop()
        if used[cur]:
            continue
        used[cur] = 1
        if cur<m:
            x += 1
        else:
            y += 1
        edge += len(G[cur])
        for to in G[cur]:
            if used[to] == 0:
                q.append(to)
    return x*y-edge//2

ans = 0
for i in range(2*m):
    if used[i]:
        continue
    ans += dfs(i)
print(ans)


Measured memory_bytes: 65228
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<ll, ll>;
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

int n;
ll dp[15][15];
const ll INF = 1e18;

int main() {
    while(1) {
        cin >> n;
        if(n == 0) break;
        for(int i = 0; i < 10; ++i) {
            for(int j = 0; j < 10; ++j) {
                if(i == j) dp[i][j] = 0;
                else dp[i][j] = INF;
            }
        }
        set<int> town;
        for(int i = 0; i < n; ++i) {
            int a, b; ll c; cin >> a >> b >> c;
            town.insert(a); town.insert(b);
            dp[a][b] = c; dp[b][a] = c;
        }
        for(int k = 0; k < 10; ++k) {
            for(int i = 0; i < 10; ++i) {
                for(int j = 0; j < 10; ++j) {
                    chmin(dp[i][j], dp[i][k]+dp[k][j]);
                }
            }
        }

        ll ans = INF;
        int anstown = 0;
        for(auto x : town) {
            ll sum = 0;
            for(auto y : town) sum += dp[x][y];
            if(ans > sum) {
                ans = sum;
                anstown = x;
            }
        }
        cout << anstown << " " << ans << endl;
    }
}


Measured memory_bytes: 3088
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <iomanip>

using namespace std;


int main(void) {
	int num;
	cin >> num;
	string str = "ABC";

	if (num >= 1000) {
		str = "ABD";
	}
	
	cout << str;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
//#include <regex>

/* g++ -g -std=c++0x */
/* g++ -g -std=c++11 */

using namespace std;

// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

const int maxn = 1e5+5;
int A[maxn];

int main()
{
    int N;
    while (cin >> N) {
        FOR(i,0,N)
            cin >> A[i];
        sort(A,A+N);
        int k = 0, ans = 0;
        FOR(i,0,N) {
            const int x = A[N-1] - A[i];
            const int y = min(x,A[N-1]-x);
            if (y > k)
                k = y, ans = i;
        }
        cout << A[N-1] << ' ' << A[ans] << endl;
    }
    return 0;
}


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

const int INF = 1012345678;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;

typedef pair<ii, iii> int5;

const int dx[] = {0,1,0,-1};
const int dy[] = {1,0,-1,0};

vector<char> c[1000005];
vector<ii> dist[4][1000005];

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

    int x1, y1, x2, y2;
    scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
    x1 --; y1 --; x2 --; y2 --;

    for(int i = 0; i < H; i ++){
        c[i].assign(W+5, 0);
        for(int j = 0; j < 4; j ++){
            dist[j][i].assign(W+5, ii(INF, INF));
        }

        for(int j = 0; j < W; j ++){
            char x;
            scanf(" %c", &x);
            c[i][j] = x;
        }
    }

    priority_queue<int5, vector<int5>, greater<int5> > pq;
    for(int d = 0; d < 4; d ++){
        dist[d][x1][y1] = ii(1, 0);
        pq.push(int5(ii(1, 0), iii(x1, y1, d)));
    }
    while(!pq.empty()){
        int5 temp = pq.top(); pq.pop();
        iii u = temp.second;
        int x, y, dir1;
        tie(x, y, dir1) = u;

        ii d = temp.first;

        if(d > dist[dir1][x][y]){continue;}
        if(x == x2 && y == y2){
            //printf("x=%d y=%d dir1=%d dist=ii(%d, %d)\n", x, y, dir1, temp.first, temp.second);
        }

        for(int k = 0; k < 4; k ++){
            int nx = x + dx[k];
            int ny = y + dy[k];
            if(nx >= 0 && nx < H && ny >= 0 && ny < W && c[nx][ny] == '.'){
                // This is valid

                ii newDist;
                if(k == dir1){
                    if(d.second == K){
                        newDist = ii(d.first+1, 1);
                    }else{
                        newDist = ii(d.first, d.second+1);
                    }
                }else{
                    newDist = ii(d.first+1, 1);
                }

                if(newDist < dist[k][nx][ny]){
                    dist[k][nx][ny] = newDist;
                    pq.push(int5(newDist, iii(nx, ny, k)));
                }
            }
        }
    }


    ii ans = ii(INF, INF);
    for(int d = 0; d < 4; d ++){
        ans = min(ans, dist[d][x2][y2]);
    }

    if(ans.first == INF){
        printf("-1");
    }else{
        printf("%d", ans.first);
    }

    return 0;
}


Measured memory_bytes: 157948
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    string s;
    cin >> s;
    int n = s.size();
    ll tot = 0;
    for (int i = 0; i < (1 << (n - 1)); i++) {
        ll val = 0;
        ll cur = s[0] - '0';
        for (int j = 1; j < s.size(); j++) {
            if (i & (1 << (j - 1))) {
                val += cur;
                cur = s[j] - '0';
            }
            else {
                cur = 10 * cur + (s[j] - '0');
            }
        }
        val += cur;
        tot += val;
    }
    cout << tot;
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

const INF = 1000000000

func minInt(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func dijkstra(adj [][]int, cost []int) {
	visited := make([]bool, 10)
	visited[1] = true
	s := 1
	for {
		for i := 0; i <= 9; i++ {
			cost[i] = minInt(cost[i], cost[s]+adj[i][s])
		}
		next := -1
		minCost := INF
		for i := 0; i <= 9; i++ {
			switch {
			case visited[i]:
				continue
			case cost[i] < minCost:
				next = i
				minCost = cost[i]
			}
		}
		if next == -1 {
			break
		}
		visited[next] = true
		s = next
	}
}

func main() {
	var h, w int
	fmt.Scan(&h, &w)

	adj := make([][]int, 10)
	for i := range adj {
		line := make([]int, 10)
		for j := range line {
			fmt.Scan(&line[j])
		}
		adj[i] = line
	}

	wall := make([][]int, h)
	for i := range wall {
		line := make([]int, w)
		for j := range line {
			fmt.Scan(&line[j])
		}
		wall[i] = line
	}

	cost := make([]int, 10)
	for i := range cost {
		if i != 1 {
			cost[i] = INF
		} else {
			cost[i] = 0
		}
	}

	dijkstra(adj, cost)
	ans := 0
	for _, line := range wall {
		for _, v := range line {
			if v != -1 {
				ans += cost[v]
			}
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
long long n;
int main()
{
 //freopen(".in","r",stdin);
 //freopen(".out","w",stdout);
 cin>>n;
 for(int i=n; i>0; i/=10)
 if(i%10==9)
 {
 	cout<<"Yes"<<endl;
 	return 0;
 }
 cout<<"No"<<endl;
 return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;
using pll=pair<ll,ll>;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define MOD 1000000007

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; }

int main() {
	string s;
	cin >> s;
	string t;
	rep(i, s.length()) {
		if(s[i] == 'B' && t.length() != 0) {
			string v;
			rep(j,t.length()-1) {
				v += t[j]; 
			}
			t = v;
		}
		else if(s[i] == '0' || s[i] == '1') t += s[i];
	}
	cout << t << endl;

  return 0;
}


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


#define ll          long long
#define uint        unsigned int 
#define ld          long double
#define SAM         ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define mod         1000000007
#define mxn         200005
#define pb          push_back
#define pii         pair<int,int>
#define f           first
#define s           second
#define sz(x)       (int)x.size()
#define all(x)      x.begin(),x.end()

using namespace std;

/*mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int power(int a,int n)
{
    a %= mod;
    if(n == 1) return a;
    if(n == 0) return 1;
    if(n%2) return (a*(power((a*a)%mod,n/2)%mod))%mod;           //n is odd
    return power((a*a)%mod,n/2)%mod;                             //n is even
}

const int inf = (int) 1e18;

int inverse(int x)
{
    return power(x,mod-2)%mod;     //Fermat's little theorem
}*/

int main()
{
    SAM;
    int n,x,t;
    cin>>n>>x>>t;
    
    if(n<=x)
    {
        cout<<t;
        return 0;
    }
    
    int total=t;
    int temp=x;
    while(x<n)
    {
        x+=temp;
        total+=t;
    }
    
    cout<<total;
    
    return 0;
}




Measured memory_bytes: 3648
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std;
// dfmt on

void main()
{
    long N = lread();
    auto T = new long[](N);
    auto X = new long[](N);
    auto Y = new long[](N);
    foreach (i; 0 .. N)
        scan(T[i], X[i], Y[i]);
    long t;
    long x, y;
    foreach (i; 0 .. N)
    {
        long d = abs(x - X[i]) + abs(y - Y[i]);
        if ((T[i] - t) < d)
        {
            writeln("No");
            return;
        }
        if (((T[i] - t) - d) & 1)
        {
            writeln("No");
            return;
        }
        t = T[i];
        x = X[i];
        y = Y[i];
    }
    writeln("Yes");
}


Measured memory_bytes: 6836
#pragma region
#pragma GCC target("avx2")
#pragma GCC optimize("03")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std; typedef long double ld; typedef long long ll;
typedef unsigned long long ull;
#define endl "\n"
#define MP make_pair
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORR(x,arr) for(auto& x:arr)
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define VPII vector<PII>
#define VPLL vector<PLL>
#define FI first 
#define SE second
#define ALL(x) (x).begin(), (x).end()
constexpr int INF=1<<30; constexpr ll LINF=1LL<<60; constexpr ll mod=1e9+7; constexpr int NIL = -1;
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
#pragma endregion
//-------------------
const int MX = 200000+7;
ll a[MX];

int main(){
    cin.tie(0); ios::sync_with_stdio(false); //cout << fixed << setprecision(15);
    int n; cin >> n;
    FOR(i,0,n-1) {
        cin >> a[i];
    }
    sort(a, a+n);
    ll sm = a[n-1];
    int cur_n = n-2;
    
    for(int i=n-2; i>=0; i--) {
        if(cur_n >= 2) {
            sm += a[i]*2;
            cur_n -= 2;
        } else if(cur_n == 1) {
            sm += a[i];
            cur_n -= 1;
            break;
        } else {
            break;
        }
    }
    cout << sm << endl;
    return 0;
}


Measured memory_bytes: 5204
# -*- coding: utf-8 -*-

import sys
import math


debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        for line in sys.stdin:
            lines.append(line.strip())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    x = int(lines[0])
    

    return (x, )


def solve(x):
    
    result = None
    for c in range(1, 9):
        if 2000 - 200 * c <= x and x <= 2000 - 200 * (c-1) - 1:
            result = c
            break

    return result
    


def main():
    # 出力
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r, sep='')
    else:
        print("%s" % result, sep='')

if __name__ == '__main__':

    main()
	

Measured memory_bytes: 62064
n = int(input())
s = list(map(int, input().split()))
max_val = 0
for diff in range(1, n):
    visited = set()

    j = n - 1 - diff
    i = diff

    val = 0
    while i < n - 1 - diff and j > diff :
        if j in visited or i in visited or j == i:
            break
        visited.add(j)
        visited.add(i)
        val += s[j] + s[i]
        i += diff
        j -= diff
        if max_val < val:
            max_val = val
print(max_val)

Measured memory_bytes: 134356
#include <stdio.h>  
#include <algorithm>  
#include <bitset>
#include <cassert>
#include <ctime>  
#include <cmath>  
#include <cstdlib>  
#include <cstring>  
#include <functional>  
#include <iostream>  
#include <deque>  
#include <stack>
#include <queue>  
#include <vector>  
#include <map>  
#include <set>  
#include <string>  
#include <unordered_map>  
#include <unordered_set>  

using namespace std;

#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define endl '\n'

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

const ll INF = 1e18;
const int MAXN = 3e5 + 5;

ll a, b, c;

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> a >> b >> c;
	if(c-a-b<0) cout << "No";
	else if((a+b-c)*(a+b-c) > 4*a*b) cout << "Yes";
	else cout << "No";
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
        #define ll  long long int
        #define fast    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
        #define mod 1000000007
        using namespace std;
    
        int main()
            {fast;
            ll t =1;
            //cin>>t;

        while(t--){
            double d, t, s;
            cin>>d>>t>>s;

            if(d/t <= s){
                cout<<"Yes";
            }
            else
            {
                cout<<"No";
            }
            
            
        }
                return 0;
        }

Measured memory_bytes: 3716
v, e = map(int, input().split())

INF = 10 ** 18
d = [[INF]*v for _ in range(v)]

for i in range(e):
    frm, to, dis = map(int, input().split())
    d[frm][to] = dis

for i in range(v):
    d[i][i] = 0

    
for k in range(v):
    for i in range(v):
        for j in range(v):
            d[i][j] = min(d[i][j], d[i][k] + d[k][j])
            
neg = 0

for i in range(v):
    for j in range(v):
        if d[i][j] + d[j][i]<0:
            neg = 1
            
if neg:
    print('NEGATIVE CYCLE')
else:
    for i in range(v):
        d[i] = [d[i][j] if d[i][j]<INF//10 else 'INF' for j in range(v)]
        print(*d[i])


Measured memory_bytes: 6436
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

template<class T> ostream& operator<<(ostream &os, vector<T> V) {
 os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
	return os << "(" << P.first << "," << P.second << ")";}

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif


#define ll long long
#define ld long double
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define I insert 
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define vi vector<int>
#define pii pair<int, int>
#define vpii vector< pii >


const int mod=998244353;
inline int mul(int a,int b){return (a*1ll*b)%mod;}
inline int add(int a,int b){a+=b;if(a>=mod)a-=mod;return a;}
inline int sub(int a,int b){a-=b;if(a<0)a+=mod;return a;}
inline int power(int a,int b){int rt=1;while(b>0){if(b&1)rt=mul(rt,a);a=mul(a,a);b>>=1;}return rt;}
inline int inv(int a){return power(a,mod-2);}
inline void modadd(int &a,int &b){a+=b;if(a>=mod)a-=mod;} 


const int M = 3e5+15;
int fact[M], ifact[M];

void pre(){
	int i,j;
	fact[0]=1;
	for(i=1;i<M;i++){
		fact[i]= mul(fact[i-1], i);
	}
	ifact[M-1]= inv(fact[M-1]);
	for(i=M-2;i>=0;i--){
		ifact[i] = mul(i+1, ifact[i+1]);
	}
}

inline int ncr(int x, int y){
	return mul(fact[x], mul(ifact[y], ifact[x-y]));
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout<<setprecision(25);
	ll N, A, B, K;
	pre();
	cin>>N>>A>>B>>K;
	int ans =0 ;
	for(ll i=0;i<=N;i++){
		ll rem = K - i*A;
		if(rem<0 || (rem%B)!=0) continue;
		ll cb = rem/B; if(cb>N) continue;
		// if(cb+i < N) continue;
		// trace(i, cb);
		int cur = mul(ncr(N, i), ncr(N, cb));
		ans = add(ans, cur);
	}
	cout<<ans<<"\n";

}


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

int N, W, w[100], v[100];

/**
 * dp[i+1][j]:i番目までの品物を容量j以下に収めた時の価値の最大値 
 **/
ll dp[102][100001] = {0}; 

int main(){
    cin >> N >> W;
    rep(i, N) cin >> w[i] >> v[i];

    for(int i = 0; i <= N; i++) {
        for(int j = 0; j <= W; j++) {
            if (j < w[i]) {
                dp[i+1][j] = dp[i][j]; 
            } else {
                dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]] + v[i]);
            }
        }
    }

    cout << dp[N+1][W] << endl;

    return 0;
}

Measured memory_bytes: 79104
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC160D
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int N = int.Parse(input[0]);
            int X = int.Parse(input[1]);
            int Y = int.Parse(input[2]);
            int[] k = new int[N - 1];
            int saitan = 0;
            for(int i = 1; i <= N - 1; i++)
            {
                for(int j = i + 1; j <= N; j++)
                {
                    saitan = kyori(i, j, X, Y);
                    k[saitan - 1] += 1;
                }
            }
            for (int i = 0; i < N - 1; i++)
            {
                Console.WriteLine(k[i]);
            }

        }
        static int kyori(int i, int j, int X, int Y)
        {
            int kyori = 0;
            kyori = Math.Min(Math.Min(Math.Abs(i - j), Math.Abs(i - X) + 1 + Math.Abs(j - Y)), Math.Abs(i - Y) + 1 + Math.Abs(j - X));
            return (kyori);
        }
    }
}


Measured memory_bytes: 27032
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    N = int(input())
    #N, K = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    N-=1
    ans=""
    while N>=0:
        #print(N)
        N,d=divmod(N,26)
        N-=1
        ans=num2alp(d)+ans
    print(ans)


    

if __name__ == "__main__":
    main()

Measured memory_bytes: 72776
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

int main()
{
    int n;
    string s;
    cin >> n >> s;
    int unopen = 0;
    int unclosed = 0;
    string ans;
    ans.assign(s.begin(), s.end());
    for (char c : s)
    {
        if (c == ')' && unclosed <= 0)
        {
            unopen++;
        }
        if (c == '(')
        {
            unclosed++;
        }
        if (c == ')' && unclosed > 0)
        {
            unclosed--;
        }
    }
    rep(i, unopen)
    {
        ans = "(" + ans;
    }
    rep(i, unclosed)
    {
        ans += ")";
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
///
// File:  cgl_1_c.cpp
// Author: ymiyamoto
//
// Created on Mon Oct 23 00:28:22 2017
//
#include <cmath>
#include <cstdint>
#include <iomanip>
#include <iostream>

using namespace std;

struct vector_t {
  double x;
  double y;

  vector_t(double a, double b) : x(a), y(b)
  {
  }

  double norm2()
  {
    return x * x + y * y;
  }

  double dot(vector_t a)
  {
    return x * a.x + y * a.y;
  }

  double cross(vector_t a)
  {
    return x * a.y - y * a.x;
  }

  vector_t operator*(double a)
  {
    return vector_t(a * x, a * y);
  }
};

struct point_t {
  double x;
  double y;

  point_t operator+(const point_t a)
  {
    return point_t({x + a.x, y + a.y});
  }

  void print()
  {
    cout << fixed << setprecision(10) << x << " " << y << endl;
  }

  point_t operator+(const vector_t vec)
  {
    return point_t({x + vec.x, y + vec.y});
  }

  vector_t operator-(const point_t p)
  {
    return vector_t({x - p.x, y - p.y});
  }

  point_t project(point_t p1, point_t p2)
  {
    vector_t vec1(x - p1.x, y - p1.y);
    vector_t vec2(p2.x - x, p2.y - y);
    return point_t({x, y}) + vec1 * (vec1.dot(vec2) / vec1.norm2());
  }

  point_t reflect(point_t p1, point_t p2)
  {
    point_t proj = project(p1, p2);
    return p2 + (proj - p2) * 2.0;
  }
};

#define EPS 1e-10
#define equals(x, y) (fabs(x - y) < EPS)

int32_t main()
{
  double x, y;
  cin >> x >> y;
  point_t p0({x, y});
  cin >> x >> y;
  point_t p1({x, y});

  uint32_t q;
  cin >> q;
  for (uint32_t i = 0; i < q; i++) {
    cin >> x >> y;
    point_t p2({x, y});
    if ((p1 - p0).cross(p2 - p0) > EPS) {
      cout << "COUNTER_CLOCKWISE" << endl;
    } else if ((p1 - p0).cross(p2 - p0) < -EPS) {
      cout << "CLOCKWISE" << endl;
    } else if ((p1 - p0).dot(p2 - p0) < -EPS) {
      cout << "ONLINE_BACK" << endl;
    } else {
      if ((p1 - p0).norm2() < (p2 - p0).norm2()) {
        cout << "ONLINE_FRONT" << endl;
      } else {
        cout << "ON_SEGMENT" << endl;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 3236
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 100;
int f[maxn],sum[maxn];


int find(int x){
    return f[x] == x ? x : f[x] = find(f[x]);
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,m;cin >> n >> m;
    for(int i = 0;i <= n;i++) f[i] = i,sum[i] = 0;
    while(m--){
        int a,b;cin >> a >> b;
        int fa = find(a),fb = find(b);
        if(fa != fb){
            f[fa] = fb;
        }
    }
    for(int i = 1;i <= n;i++) sum[find(f[i])]++;
    int ans = -1;
    for(int i = 1;i <= n;i++) ans = max(ans,sum[i]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 11444
h1, m1, h2, m2, k = map(int, input().split())

h = h2 - h1
m = m2 - m1

if m < 0:
    h -= 1
    m = 60 - m1 + m2

ans = 60*h + m - k
if ans < 0:
    ans = 0
print(ans)

Measured memory_bytes: 9180
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#include <cctype>
#include <locale>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
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;}
typedef pair<int,int> P;
typedef pair<long long,long long> Pll;
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ
//vector<vector<ll>> dp(n,vector<ll>(n))


signed main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    string s; cin >> s;
    int w; cin >> w;
    string ans="";
    rep(i,s.size()){
        if(i%w==0) ans+=s[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define LL long long
using namespace std;
LL N, M;
int main()
{
#ifdef hk_cnyali
	freopen("A.in", "r", stdin);
	freopen("A.out", "w", stdout);
#endif
	scanf("%lld%lld", &N, &M);
	LL Ans = abs(abs(N) - abs(M));
	if (N * M < 0) ++Ans;
	else if (N > M)
	{
		Ans += 2;
		if (N == 0 || M == 0) Ans--;
	}
	cout<<Ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD (long long)(1E9+7)
#define rep(i, n) for(int i = 0; i < n; i++)

using namespace std;

int main(){
	int n,m;
	cin >>n >> m;
  	vector<int> a(m);
  	rep(i,n) {
      	int k,b;
    	cin >> k; 
      	rep(j, k) {
        	cin >> b;
          	a[b-1]++;
        }
    }
  	int count=0;
  	rep(i, m)
    	if(a[i] == n)
    		count++;
	cout << count << endl;
}


Measured memory_bytes: 256
//AGC 003-A
#define _USE_MATH_DEFINES

#include <iostream>
#include <cmath>
#include <stdlib.h>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cstring>
#include <numeric>
#include <string>
#include <map>
#include <sstream>
using namespace std;

int main() {
	string S;
	vector<int> Count(4, 0);
	cin >> S;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == 'N') Count[0]++;
		if (S[i] == 'S') Count[1]++;
		if (S[i] == 'W') Count[2]++;
		if (S[i] == 'E') Count[3]++;
	}
	if (Count[0] * Count[1] == 0 && Count[0] + Count[1]>0) cout << "No" << endl;
	else if (Count[2] * Count[3] == 0 && Count[2] + Count[3]>0) cout << "No" << endl;
	else cout << "Yes" << endl;
}


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

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

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

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

ll tmax(ll a, ll b, ll c)
{
    return std::max(a, std::max(b, c));
}
ll tmin(ll a, ll b, ll c)
{
    return std::min(a, std::min(b, c));
}

ll solve(ll H, ll W)
{
    ll m = INF;
    FOR(i, H, 1)
    {
        ll s0 = i * W;
        ll h = H - i;
        {
            ll s1 = h * (W / 2);
            ll s2 = h * (W / 2 + W % 2);
            m = std::min(tmax(s0, s1, s2) - tmin(s0, s1, s2), m);
        }
        {
            ll s1 = (h / 2) * W;
            ll s2 = (h / 2 + h % 2) * W;
            m = std::min(tmax(s0, s1, s2) - tmin(s0, s1, s2), m);
        }
    }
    return m;
}

int main()
{
    int H, W;
    cin >> H >> W;
    ll min = std::min(solve(W, H), solve(H, W));
    cout << min << endl;
    return 0;
}

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

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

 for (int i = 1; i < N; i++) {
   for (int j = 1; j < N; j++) {
     int k = N - i * j;
     if (k > 0) count++;
     else break;
   }
 }
  
 cout << count << endl;
     



}
  


Measured memory_bytes: 3600
from string import ascii_lowercase
def inpl(): return list(map(int, input().split()))
N = int(input())
A = input()
B = input()
C = input()

ans = 0
for i in range(N):
    if A[i] == B[i] == C[i]:
        pass
    elif A[i] == B[i] or B[i] == C[i] or C[i] == A[i]:
        ans += 1
    else:
        ans += 2
print(ans)

Measured memory_bytes: 38512
#include <stdio.h>

int main() {
  if (getchar() == '1') {
    printf("Hello World\n");
    return 0;
  }
  else {
    int a=0, b=0;
    scanf("%d %d", &a, &b);
    printf("%d\n", a+b);
    return 0;
  }
}


Measured memory_bytes: 128
s = gets.chomp
t = gets.chomp

s_hash = {}
t_hash = {}
('a'..'z').each do |c|
  s_hash[c] = nil
  t_hash[c] = nil
end

result = true
0.upto(s.length).each do |i|
  cs = s[i]
  ct = t[i]

  if s_hash[cs].nil?
    s_hash[cs] = ct
  else
    if s_hash[cs] != ct
      result = false
      break
    end
  end
  if t_hash[ct].nil?
    t_hash[ct] = cs
  else
    if t_hash[ct] != cs
      result = false
      break
    end
  end
end
puts result ? 'Yes' : 'No'


Measured memory_bytes: 3964
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // 受け取り
        Scanner sc = new Scanner(System.in);
        int songCount = sc.nextInt();
        String[] songName = new String[songCount];
        int[] songLength = new int[songCount];
        
        for(int i=0;i<songCount;i++){
            songName[i] = sc.next();
            songLength[i] = sc.nextInt();
        }
        String finalSong = sc.next();
        
        // 計算
        int sleepNumber = 0;
        for(int i=0;i<songCount;i++){
            if(songName[i].equals(finalSong)){
                sleepNumber = i;
            }
        }
        
        int sleepSum = 0;
        for(int i=sleepNumber+1;i<songCount;i++){
            sleepSum += songLength[i];
        }
        System.out.println(sleepSum);
    }
}


Measured memory_bytes: 21196
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<iomanip>
#include<cstring>
#define initdp(a,b) for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=-1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define inf 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 1000005
#define mid(l,r) l+(r-l)/2
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
void mad(ll &a,ll b){a=(a+b)%mod;if(a<0)a+=mod;}
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}

void solve(){
	ll n,k;
	cin>>n>>k;
	ll ans=n;
	while(1){
		ll dif=min(n%k,abs(n-k));
		if(n>dif)n=dif;
		else break;
	}
	cout<<n;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t;
	//cin>>t;
	t=1;
	while(t--){
		solve();
	}
}

Measured memory_bytes: 256
def main():
    import sys
    import time
    from collections import deque
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    N = int(input())
    P = [int(a) for a in input().strip().split()]
    G = [[min(n, N-n-1,i, N-i-1) for i in range(N)] for n in range(N)]
    Gflag = [[1] * N for _ in range(N)]
    ans = 0

    vecs = [(1, 0), (0, 1), (-1, 0), (0, -1)]

    for p in P:
        row, col = (p-1) // N, (p-1) % N
        ans += G[row][col]
        Gflag[row][col] = 0
        q = deque([(G[row][col], row, col)])
        while q:
            cost, row, col = q.popleft()
            if row > 0:
                if G[row-1][col] > cost + Gflag[row][col]:
                    G[row-1][col] = cost + Gflag[row][col]
                    q.append((cost+Gflag[row][col], row-1, col))
            if row < N-1:
                if G[row+1][col] > cost + Gflag[row][col]:
                    G[row+1][col] = cost + Gflag[row][col]
                    q.append((cost+Gflag[row][col], row+1, col))
            if col > 0:
                if G[row][col-1] > cost + Gflag[row][col]:
                    G[row][col-1] = cost + Gflag[row][col]
                    q.append((cost+Gflag[row][col], row, col-1))
            if col < N-1:
                if G[row][col+1] > cost + Gflag[row][col]:
                    G[row][col+1] = cost + Gflag[row][col]
                    q.append((cost+Gflag[row][col], row, col+1))

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

Measured memory_bytes: 165964
#include <stdio.h>


int main() {
int i,j=0;
int n,b,k=0;
int adj[101][101];
int m[101][101];

scanf("%d",&n);
for(i=0;i<n;i++){
for(j=0;j<100;j++){
scanf("%d",&adj[i][j]);
k++;
if(adj[i][1]==k-2) break;
      
}
k=0;
}
for(i=0;i<n;i++){
for(j=0;j<n;j++){
m[i][j]=0;
}
}
for(i=0;i<n;i++){
for(j=2;j<=n;j++){
b=adj[i][j];
m[i][b-1]=1;
}
}
for(i=0;i<n;i++){
for(j=0;j<n;j++){
printf("%d",m[i][j]);
if(j!=n-1)printf(" ");
}
printf("\n");
}
  
return 0;
}

Measured memory_bytes: 676
#include <iostream>
#include <vector>
#include <set>

using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;

    vector<int> p(n);
    for (int &x : p) cin >> x;

    vector<int> a(n);
    a[0] = 1;
    for (int i = 1; i < n; ++i)
    {
        if (p[i - 1] < p[i])
        {
            a[i] = a[i - 1] + 1;
        }
        else
        {
            a[i] = 1;
        }
    }

    int ans = 1;

    int c = 0;
    if (a[k - 1] == k) c = 1;

    set<int> s;
    for (int i = 0; i < k; ++i) s.insert(p[i]);

    for (int i = k; i < n; ++i)
    {
        s.insert(p[i]);

        if (a[i] >= k)
        {
            if (c == 0) ++ans;
            c = 1;
        }
        else
        {
            const int min = *s.begin();
            const int max = *s.rbegin();

            if (min != p[i - k] || max != p[i])
            {
                ++ans;
            }
        }

        s.erase(p[i - k]);
    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;


//repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define euc_dis(x, y) sqrt(x*x + y*y)

#define MOD 1e9+7
#define sp ' '


using ll = long long;


ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll b, ll e, ll m){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    string s;
    cin >> s;
    int n = s.size();
    string str = '#' + s + "##";


    for(int i = 0; i < n; ++i){
        if(str[i] == str[i+1]){
            cout << i << sp << i+1 << endl;
            return 0;
        }
        else if(str[i] == str[i+2]){
            cout << i << sp << i+2 << endl;
            return 0;
        }
    }

    cout << "-1 -1" << endl;
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#include <ctime>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <bitset>
#include <list>
#include <cstdio>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <cmath>
#include <tuple>
#include <cassert>
#include <array>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using ti = tuple<int, int, int>;

#define REP(i,m,n) for(int i=(m); i<(n); i++)
#define RREP(i,n,m) for(int i=(n);i>=(m); i--)
#define pb push_back
#define mp make_pair
#define debug(x) cerr << #x << ": " << x << endl
// #define int long long 

const double eps=1e-14;
const int mod = 1e9 + 7;
const int inf = ((1<<30)-1);
const ll linf = (1LL<<60);
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

struct mint 
{
  ll x;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    if(n<=999) cout << "ABC";
    else cout << "ABD";
    return 0;
}


Measured memory_bytes: 256