akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n) for (int i=1; i < (int)(n); i++)
#define rrep(i, n) for (int i=((int)(n)-1); i>=0; i--)
#define rreps(i, n) for (int i=((int)(n)-1); i>0; i--)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using lint = long long;
using p = pair<int, int>;
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() {
  int x;
  scanf("%d", &x);
  string s = x >= 30 ? "Yes" : "No";
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 3696
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define NMAX 100000
int main() {
    int N,M;
    cin>>N>>M;
    vector<int> H(N);
    bitset<NMAX> bit;
    for (int i = 0; i < N; i++){
        cin>>H[i];
    }
    for (int i = 0; i <M; i++){
        int a,b;
        cin>>a>>b;a--;b--;
        if(H[a]>=H[b])bit.set(b);
        if(H[a]<=H[b])bit.set(a);
    }
    cout<<N-bit.count()<<endl;
}

Measured memory_bytes: 3740
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll MOD=1e9+7;
const ll MOD2=998244353;
const ll N=55;
const ld pi=3.14159265359;
const ll M=(1LL<<20)+5;
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define setp setprecision
#define lwb lower_bound
#define SZ(a) (ll)a.size()

ll dp[N][M],vis[N],x,y,n,m,a[N],b[N],ans;
ll bit[N];
vector<ll> v[N];
vector<pll> e;

void fil(ll nd,ll p,ll c){
	vis[nd]=c;
	for(auto i:v[nd]){
		if(i!=p)fil(i,nd,c);
	}
}

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>n;
	REP(i,n-1){
		cin>>x>>y;
		e.pb(mp(x,y));
		v[x].pb(y);v[y].pb(x);
	}
	cin>>m;
	REP(i,m)cin>>a[i]>>b[i];
	REP(i,n-1){
		fil(e[i].X,e[i].Y,0);fil(e[i].Y,e[i].X,1);
		REP(j,m)if(vis[a[j]]!=vis[b[j]])bit[j]|=(1LL<<i);
	}
	REP(i,(1LL<<m)){
		ll c=1,base=0,ti=0;
		REP(j,m)if(i&(1LL<<j))base|=(bit[j]),c*=-1;
		REP(j,n-1)if(!(base&(1LL<<j)))ti++;
		ans+=(c*(1LL<<ti));
	}
	cout<<ans<<"\n";
	return 0;
}



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        private static int Calculate(int[] array)
        {
            int N = array.Length;
            int min = int.MaxValue;
            for (int i = 0; i < N; ++i)
            {
                int t1 = array[i];
                for (int j = i + 1; j < N; ++j)
                {
                    int t2 = array[j];
                    int t = Math.Abs(t2 - t1);
                    min = Math.Min(Math.Min(t, 24 - t), min);
                }
            }
            return min;
        }

        private static int Max(int[] array1, int[] array2)
        {
            int N = array2.Length;
            int max = 0;
            for (int i = 0; i < (1 << N); ++i)
            {
                var array3 = new int[N];
                for (int j = 0; j < N; ++j)
                {
                    array3[j] = (i & (1 << j)) == 0 ? array2[j] : 24 - array2[j];
                }
                max = Math.Max(Calculate(Enumerable.Union(array1, array3).ToArray()), max);
            }
            return max;
        }

        private static int Solve(int N, int[] D)
        {
            int[] counts = new int[13];
            foreach (int d in D) { ++counts[d]; }
            if (counts[0] > 0) { return 0; }
            var list1 = new List<int> { 0 };
            var list2 = new List<int>();
            for (int i = 0; i <= 12; ++i)
            {
                switch (counts[i])
                {
                case 0:
                    break;
                case 1:
                    if (i < 12)
                    {
                        list2.Add(i);
                    }
                    else
                    {
                        list1.Add(i);
                    }
                    break;
                case 2:
                    if (i < 12)
                    {
                        list1.Add(i);
                        list1.Add(24 - i);
                    }
                    else
                    {
                        return 0;
                    }
                    break;
                default:
                    return 0;
                }
            }
            return Max(list1.ToArray(), list2.ToArray());
        }
        
        static void Main(string[] args)
        {
            int N = ReadInt();
            int[] D = ReadInts();
            Console.WriteLine(Solve(N, D));
        }
    }
}


Measured memory_bytes: 13396
N = int(input())
D, X = map(int, input().split())

ans = 0

for i in range(N):
    A = int(input())

    if A == 1:
        ans += D
    else:
        for j in range(D):
            if (j+1) % A == 1:
                ans += 1

print(X+ans)

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

int main(){
	int N;
	cin >> N;
	int A[N];
	for(int i=0;i<N;i++) {
		cin >> A[i];
		A[i]-=i+1;
	}
	sort(A,A+N);
	int  b=(N%2? A[N/2]:(A[N/2-1]+A[N/2])/2);
	long long ans=0;
	for(int i=0;i<N;i++) ans+=abs(A[i]-b);

	cout << ans << endl;
	

}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    static int h;
    static int w;
    static int c;
    static int ans;
    static int count;
    static int[] color_order;
    static int[][] map;
    static int[][] tmp;

    public static void main(String[] args) throws java.io.IOException {

        Scanner sc = new Scanner(System.in);
        while (true) {
            h = sc.nextInt();
            w = sc.nextInt();
            c = sc.nextInt();
            if ((h | w | c) == 0)
                break;
            ans =0;
            map = new int[h][w];
            tmp = new int[h][w];
            for (int i = 0; i < h; i++)
                for (int j = 0; j < w; j++)
                    map[i][j] = sc.nextInt();
            color_order = new int[5];
            for (int i = 1; i <= 6; i++) {
                for (int j = 1; j <= 6; j++) {
                    for (int k = 1; k <= 6; k++) {
                        for (int l = 1; l <= 6; l++) {
                            color_order[0] = i;
                            color_order[1] = j;
                            color_order[2] = k;
                            color_order[3] = l;
                            color_order[4] = c;
                            for (int m = 0; m < h; m++)
                                for (int n = 0; n < w; n++)
                                    tmp[m][n] = map[m][n];
                            count =0;
                            ele();
                            ans = Math.max(ans,count);
                        }
                    }
                }

            }
            System.out.println(ans);

        }
    }

    public static void ele() {
        for (int i = 0; i < 5; i++) {
            if (tmp[0][0] == color_order[i])
                continue;
            flip(0,0,tmp[0][0],color_order[i]);
        }
        solve(0,0);
    }

    public static void flip(int x, int y, int from,int to) {
        int dx[] = { 1, 0, -1, 0 };
        int dy[] = { 0, 1, 0, -1 };
        tmp[y][x] = to;
        for (int i = 0; i < 4; i++) {
            int nx = x + dx[i];
            int ny = y + dy[i];
            if(nx>=0&&ny>=0&&ny<h&&nx<w&&tmp[ny][nx] == from){
                flip(nx,ny,tmp[ny][nx],to);


                }
            }
        }
    public static void solve(int x,int y){

        int dx[] = { 1, 0, -1, 0 };
        int dy[] = { 0, 1, 0, -1 };
        count++;
        tmp[y][x] =0;
        for (int i = 0; i < 4; i++) {
            int nx = x + dx[i];
            int ny = y + dy[i];
            if(nx>=0&&ny>=0&&ny<h&&nx<w&&tmp[ny][nx]!=0&&c== tmp[ny][nx] ){
                solve(nx,ny);


                }
            }
    }
}

Measured memory_bytes: 12000
#include<iostream>
using namespace std;
int main(void){
    int i,month=0;
    int day[100]={};
    while(cin >> i)                 day[i-1]++;
    for(i=0; i<100; i++)            month=max(month,day[i]);
    for(i=0; i<100; i++){
        if(day[i] == month)         cout << (i+1) << endl;
    }
}


Measured memory_bytes: 3016
# ARC090C - Candies (ABC087C)
def main():
    N = int(input())
    A = tuple(tuple(map(int, input().rstrip().split())) for _ in range(2))
    dp = [[0] * N for _ in range(2)]  # dp[i][j] := max score on point (i, j)
    dp[0][0] = A[0][0]
    for i in range(2):
        for j in range(N):
            if i == 0 and j == 0:
                continue
            if i:
                dp[i][j] = max(dp[i - 1][j] + A[i][j], dp[i][j - 1] + A[i][j])
            else:
                dp[i][j] = dp[i][j - 1] + A[i][j]
    print(dp[-1][-1])


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
type 'a tree =
    Leaf
  | Node of 'a tree * 'a * 'a tree

let empty : 'a tree = Leaf
          
let rec insert : ('a -> 'b) -> 'a -> 'a tree -> 'a tree = fun f x t ->
  match t with
    Leaf -> Node (Leaf, x , Leaf)
  | Node (l, y, r) ->
     if f x < f y then
       Node (insert f x l, y, r)
     else
       Node (l, y, insert f x  r)

let rec print_tree_int t =
  match t with
    Leaf -> ()
  | Node (l, (x, i), r) ->
     print_tree_int l;
     print_int i;
     print_char ' ' ;
     print_tree_int r
                
let i_inp_list : unit -> (int * int) list = fun () ->
  let inp_split = Str.split (Str.regexp " ") (input_line stdin) in
  List.mapi (fun i x -> (int_of_string x, i + 1)) (inp_split)
  
let () =
  let _ = Scanf.sscanf (input_line stdin) "%d" (fun a -> a) in
  let l = i_inp_list () in
  let ans = List.fold_left (fun t x -> insert (fun (a, b) -> a) x t) empty l in
  print_tree_int ans;
  print_newline ()


Measured memory_bytes: 19900
X=[list(map(int,input().split()))for i in range(3)]
b=[int(input())for i in range(int(input()))]
for i in range(3):
 X[i]=[1 if i in b else 0 for i in X[i]]
print("Yes" if 3<=max(*[sum(i)for i in X],*[sum([x[i] for x in X])for i in range(3)],X[0][0]+X[1][1]+X[2][2],X[0][2]+X[1][1]+X[2][0]) else "No")

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

int main()
{
    int x,y,z,k,i,j;
    cin >> x >> y >> z >> k;
    vector<long long> a(x);
    vector<long long> b(y);
    vector<long long> c(z);
    for(i = 0;i < x;++i){
        cin >> a.at(i);
    }
    for(i = 0;i < y;++i){
        cin >> b.at(i);
    }
    for(i = 0;i < z;++i){
        cin >> c.at(i);
    }
    vector<long long> ab;
    for(i = 0;i < x;++i){
        for(j = 0;j < y;++j){
            ab.push_back(a.at(i)+b.at(j));
        }
    }
    sort(ab.begin(),ab.end(),greater<long long>());
    vector<long long> abc;
    for(i = 0;i < min(k,x*y);++i){
        for(j = 0;j < z;++j){
            abc.push_back(ab.at(i)+c.at(j));
        }
    }
    sort(abc.begin(),abc.end(),greater<long long>());
    for(i = 0;i < k;++i){
        cout << abc.at(i) << endl;
    }
    return 0;
}

Measured memory_bytes: 43368
#include<iostream>
#include <complex>
#include <vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<list>
#include <iterator>
#include <utility>
#include <numeric>
using namespace std;

#define intt long long

intt gcd(intt m, intt n)
{
	// 引数に０がある場合は０を返す
	if ((0 == m) || (0 == n))
		return 0;

	// ユークリッドの方法
	while (m != n)
	{
		if (m > n) m = m - n;
		else         n = n - m;
	}
	return m;
}
intt lcm(intt m, intt n)
{
	// 引数に０がある場合は０を返す
	if ((0 == m) || (0 == n))
		return 0;

	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}
int main() {
	intt N, M;
	string S, T;
	intt L;
	vector<intt> Ni, Mi;
	Ni.reserve(500000);
	Mi.reserve(500000);
	Ni.push_back(1);
	Mi.push_back(1);
	cin >> N >> M;
	cin >> S;
	cin >> T;
	intt num = 1;


	L = lcm(N, M);
	if (S[0] != T[0]) {
		cout << -1 << endl;
		return 0;
	}

	for(intt i = 1;i < N;i++){
		Ni.push_back(L / N*i + 1);

	}
	for (intt i = 1; i < M; i++) {

		Mi.push_back(L / M*i + 1);
	}



	if (Ni.size() < Mi.size()) {
		vector<intt> temp = Ni;
		string temps = T;
		Ni = Mi;
		Mi = temp;
		T = S;
		S = temps;
	}

	
	intt k = 1;
	for (intt i = 1; i < Mi.size(); i++) {
		
		for (k; k < Ni.size(); k++) {
			if (Mi[i] == Ni[k]) {
				if (T[i] != S[k]) { 
					cout << -1 << endl;
					return 0; 
				}
				else {
					if(k!=0)k -= 1;
					break;
				}
			}
			else if (Mi[i] < Ni[k]) {
				if (k != 0)k -= 1;
				break;
			}

		}

	}

	cout << L << endl;

	return 0;




}

Measured memory_bytes: 5632
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>
#include <numeric>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using ll = long long int;
using ul = unsigned long long int;
const ll LL_MAX (1LL<<60);
const ll MOD (1000000007);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
   
    ll n, q; 
    cin >> n >> q;
    string s;
    cin >> s;
    vector<ll> l(q), r(q);
    rep(i,0,q) cin >> l[i] >> r[i];
    rep(i,0,q) --l[i], --r[i];

    vector<ll> acm(n+1, 0);
    rep(i,0,n) 
    {
        if (s[i]=='A' && s[i+1]=='C')
            acm[i+1] = acm[i]+1;
        else
            acm[i+1] = acm[i];
    }

    rep(i,0,q)
        cout << acm[r[i]] - acm[l[i]] << endl;


    return 0;
}


Measured memory_bytes: 3408
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < n;i++)
#define rev(i, n) for(int i = n;i >= 0;i--)
#define Rep(i, m, n) for(int i = m;i < n;i++)
#define repeatrev(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define itn int
const int MAX = 510000;


using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef priority_queue<int> Pr;

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a[4];
    int A;
    cin >> A;
    rep(i, 4) {
        a[3 - i] = A % 10;
        A /= 10;
    }
    int g = 7 - a[0];
    int cal = a[1] + a[2] + a[3];
    if(cal - 2 * a[1] == g)cout << a[0] << "-" << a[1] << "+" << a[2] << "+" << a[3] << "=7" << endl;
    else if(cal - 2 * a[2] == g)cout << a[0] << "+" << a[1] << "-" << a[2] << "+" << a[3] << "=7" << endl;
    else if(cal - 2 * a[3] == g)cout << a[0] << "+" << a[1] << "+" << a[2] << "-" << a[3] << "=7" << endl;
    else if(cal - 2 * a[1] - 2 * a[2] == g)cout << a[0] << "-" << a[1] << "-" << a[2] << "+" << a[3] << "=7" << endl;
    else if(cal - 2 * a[1] - 2 * a[3] == g)cout << a[0] << "-" << a[1] << "+" << a[2] << "-" << a[3] << "=7" << endl;
    else if(cal - 2 * a[2] - 2 * a[3] == g)cout << a[0] << "+" << a[1] << "-" << a[2] << "-" << a[3] << "=7" << endl;
    else if(cal - 2 * a[1] - 2 * a[2] - 2 * a[3] == g)cout << a[0] << "-" << a[1] << "-" << a[2] << "-" << a[3] << "=7" << endl;
    else cout << a[0] << "+" << a[1] << "+" << a[2] << "+" << a[3] << "=7" << endl;
}

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

using namespace std;

#define int long long

inline int read(){
	int x=0,f=1;
	char p=getchar();
	while(!isdigit(p)){
		if(p=='-') f=-1;
		p=getchar();
	}
	while(isdigit(p)) x=(x<<3)+(x<<1)+(p^48),p=getchar();
	return x*f;
}

const int maxn=4005,N=2001,mod=1e9+7;

int n,A[200005],B[200005],f[maxn][maxn],ans,cheng[20005],inv[20005];

inline int power(int a,int b) {
	int ans=1;
	while(b){
		if(b&1) ans=ans*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ans;
}

inline int C(int n,int m){
	return cheng[n]*inv[m]%mod*inv[n-m]%mod;
}

signed main(){
	n=read();
	for(int i=1;i<=n;i++) A[i]=read(),B[i]=read(),f[N-A[i]][N-B[i]]++;
	for(int i=1;i<=4002;i++) for(int j=1;j<=4002;j++) f[i][j]=(f[i][j]+f[i][j-1]+f[i-1][j])%mod;
	for(int i=1;i<=n;i++) ans=(ans+f[N+A[i]][N+B[i]])%mod;
	cheng[0]=cheng[1]=1;
	for(int i=2;i<=20000;i++) cheng[i]=cheng[i-1]*i%mod;
	inv[20000]=power(cheng[20000],mod-2);
	inv[0]=inv[1]=1;
	for(int i=19999;i>=2;i--) inv[i]=inv[i+1]*(i+1)%mod;
	for(int i=1;i<=n;i++) ans=(ans-C(2*(A[i]+B[i]),2*A[i]) %mod +mod)%mod;
	cout<<(ans*inv[2]%mod)<<endl;
	return 0;
}


Measured memory_bytes: 129024
Rect = []
cnt = 0
while True:
    H, W = map(int, input().split())
    if (H, W) == (0, 0):
        break
    Rect.append((H, W))
    cnt += 1

for i in range(cnt):
    print("#"*Rect[i][1])
    for j in range(Rect[i][0]-2):
        print("#"+"."*(Rect[i][1]-2)+"#")
    print("#"*Rect[i][1])
    print()



Measured memory_bytes: 5628
def solve(H, W, s):
    from collections import deque, defaultdict
    dotcount = sum([sum([c == "." for c in row]) for row in s])
    s = [row + "#" for row in s]
    s.append("#" * (W + 1))
    distance = defaultdict(lambda:9999999999999)
    q = deque()
    q.append((0, 0, 0))
    distance[0, 0] = 0
    while q:
        x, y, d = q.popleft()
        for dx, dy in ((-1, 0), (+1, 0), (0, -1), (0, +1)):
            nx, ny, nd = x + dx, y + dy, d + 1
            if s[ny][nx] == "." and nd < distance[nx, ny]:
                distance[nx, ny] = nd
                q.append((nx, ny, nd))
    if distance[W - 1, H - 1] == 9999999999999:
        return -1
    return dotcount - distance[W - 1, H - 1] - 1

H, W = [int(_) for _ in input().split()]
s = [input() for y in range(H)]

print(solve(H, W, s))



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

string s, t;

bool check(int x){
    for (int i = 0; i < t.size(); i++){
        if (!(t[i] == s[i+x] || s[i+x] == '?')) 
        return false;
    }
    return true;
}

int main(){
    cin >> s >> t;
    bool d = false;
    for (int i = s.size()- t.size(); i >= 0 ; i--){
        if (check(i)){
            for (int j = 0; j < t.size(); j++) s[i+j] = t[j];
            for (int j = 0; j < s.size(); j++)
                if (s[j] == '?') s[j] = 'a';
            d = true;
            cout << s;
            break;
        }
    }
    if (!d) cout << "UNRESTORABLE";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}


int main(){FIN

    ll n; cin>>n;
    vll a(n); REP(i,n) cin>>a[i];
    vll b(n);
    if (n%2==0){
        REP(i,(n+2)/2 - 1){
            b[i] = a[n-1 - 2*i];
        }
        REP(i, n/2){
            b[i+n/2] = a[2*i];
        }
    }

    if (n%2!=0){
        REP(i, n/2+1){
            b[i] = a[n-1 - 2*i];
        }
        REP(i, n/2){
            b[i+n/2+1] = a[2*i+1];
        }
    }
    REP(i,n) cout<<b[i]<<' ';
    cout<<endl;
    return 0;
}


Measured memory_bytes: 6348
#include <bits/stdc++.h>
#define ff { ios_base::sync_with_stdio(false);cin.tie(NULL);}
using namespace std;

typedef long long ll;
 ll  p=1e9+7; 

 int main() {
        ff;
       
       ll x;
       cin>>x;
      
      
      for(ll i=-1001;i<=1001;i++){
          for(ll j=-1001;j<=1001;j++){
              if(pow(i,5)-pow(j,5)==x){
                  cout<<i<<" "<<j<<endl;
                  return 0;
              }
          }
          
      }
       
      
       
      
          
    return 0;
}


Measured memory_bytes: 4080
n, d = map(int, input().split(' '))
a = [list(map(int,input().split(' '))) for i in range(n)]
res = 0
for i in range(n-1):
    for j in range(i+1, n):
        count = 0
        for k in range(d):
            count += (a[i][k]-a[j][k])**2
        count = count**(1/2)
        if (count.is_integer()) is True:
            res += 1
print(res)

Measured memory_bytes: 3064
Module _20190422

    Sub Main()

        Dim sRead As String = Console.ReadLine()

        Dim iBWorld As Integer = sRead.Split(" ")(0)
        Dim iSpeed As Integer = sRead.Split(" ")(1)

        Dim iResult As Decimal = Math.Round(iBWorld / iSpeed, 10, MidpointRounding.AwayFromZero)

        Console.WriteLine(iResult)

    End Sub

End Module

Measured memory_bytes: 13140
#include <bits/stdc++.h>
 using namespace std;
 
int main(void)
{
    string S,K;
 
    cin >> S;
    cin >> K;
 
    if(K.substr(0,S.length()) == S) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3560
let N = Int(readLine()!)!

var a = 0
var b = 0
var c = 0

for _ in 0..<N {
  let inp = readLine()!.split(separator: " ").map { Int($0)! }
  let a1 = inp[0]
  let b1 = inp[1]
  let c1 = inp[2]
  let _a = a
  let _b = b
  let _c = c
  a = max(_b, _c) + a1
  b = max(_a, _c) + b1
  c = max(_a, _b) + c1
}

print(max(max(a, b), c))

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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; typedef pair<ll, ll> P;
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; }
template<typename A,size_t N,typename T>void Fill(A(&array)[N],const T &val){fill((T*)array, (T*)(array+N), val);}
const int inf = INT_MAX / 2; const ll INF = LLONG_MAX / 2;
//template end

vector<vector<int>> g;
int add,que[200010],ans[200010];
int dfs(int v,int pre){
    add+=que[v];
    ans[v]+=add;
    for(int nxt:g[v])if(nxt!=pre){
        dfs(nxt,v);
    }
    add-=que[v];
}

int main(){
    int n,q; scanf("%d%d",&n,&q);
    g.resize(n);
    rep(i,0,n-1){
        int u,v; scanf("%d%d",&u,&v);
        u--; v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    rep(i,0,q){
        int p,x; scanf("%d%d",&p,&x); p--;
        que[p]+=x;
    }
    add=0; Fill(ans,0);
    dfs(0,-1);
    rep(i,0,n)printf("%d ",ans[i]);
    return 0;
}


Measured memory_bytes: 24064
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0;i<(n);++i)
#define per(i, n) for(int i=(n)-1;i>=0;--i)
#define repa(i, n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
const ll MOD = (ll)1e9+7;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

ll modpow(ll x, ll b){
	ll res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

ll modinv(ll x){
	return modpow(x, MOD-2);
}

int main(){
	int n;
	cin >> n;
	vector<int> line(n+1);
	int size = 0;
	rep(i, n){
		int key;
		cin >> line[i+1];
	}

	for(int i=1;i<=n;++i){
		printf("node %d: key = %d, ", i, line[i]);
		if(i/2){
			printf("parent key = %d, ", line[i/2]);
		}
		if(i*2<=n){
			printf("left key = %d, ", line[i*2]);
		}
		if(i*2+1<=n){
			printf("right key = %d, ", line[i*2+1]);
		}
		cout << endl;
	}

	return 0;
}



Measured memory_bytes: 3216
#!/usr/bin/perl
my ($n,$m) = map { $_ - 0 } split(/\s+/,<STDIN>);
my @py = ();
my @ord = ();
for(my $i=0;$i<$m;$i++){
  my @a = map { $_ - 0 } split(/\s+/,<STDIN>);
  push(@a,'');
  push(@py,\@a);
  push(@ord,$i);
}
my @ord2 = sort { $py[$a]->[1] <=> $py[$b]->[1] } @ord;
my @pre = ();
$#pre = $n;

foreach my $o ( @ord2 ){
  $pre[$py[$o]->[0]] ++;
  $py[$o]->[2] = sprintf("%06d%06d",$py[$o]->[0],$pre[$py[$o]->[0]]);
}
for(my $i=0;$i<$m;$i++){
  print "$py[$i]->[2]\n";
}


Measured memory_bytes: 37876
def abc177_b():
    """
    シンプルに全探索でよい、ということだそうだよ。
    探索はsのほうに対して、インデックスをずらしながら何文字が一致するかを。
    """
    s = input()
    t = input()

    # 最大値はt文字分すべて置き換えが必要な場合
    ans = len(t)

    for i in range(len(s) - len(t) + 1):
        cnt = 0
        # s[i]からスタートして、tと何文字一致しない場所を数える(書き換えが必要な場所)
        for _s, _t in zip(s[i:], t):
            if _s != _t:
                cnt += 1

        ans = min(ans, cnt)

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

Measured memory_bytes: 9048
use std::cmp;
use std::fmt::Debug;
use std::str::FromStr;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where
    T: FromStr,
    <T as FromStr>::Err: Debug,
{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim()
        .split_whitespace()
        .map(|c| T::from_str(c).unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_as_string() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main() {
    let x: i32 = read_as_vec()[0];
    if 30 <= x {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 2068
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    string s; cin >> s;
    int g = 0, p = 0;
    for(int i=0; i<s.size(); i++){
        if(s[i] == 'g') g++;
        else p++;
    }

    cout << (g-p)/2 << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;
 
template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)
 
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;


typedef pair<int, int> P;

int main() {
    int N; cin >> N;
    vector<vector<P>> X(N);
    rep(i,N) {
        int A; cin >> A;
        rep(j,A) {
            int x, y; cin >> x >> y;
            x--;
            X[i].push_back(P(x, y));
        }
    }
    
    int res = 0;
    rep(bits, pow(2,N)) {
        int cnt = 0;
        vector<int> B(N);
        rep(i,N) {
            if (bits & (1 << i)) {
                B[i] = 1;
                cnt ++;
            } 
        }
        // debug(B.begin(), B.end());

        bool flg = true;
        rep(i,N) rep(j,X[i].size()) {
            int x = X[i][j].first;
            int y = X[i][j].second;
            if (B[x] != y & B[i]) {
                flg = false;
                break;
            } 
        }

        if (flg) res = max(cnt, res);
        // cout << res << endl;
    }

    cout << res << endl;
    return 0;
}


Measured memory_bytes: 512
n=gets.chomp.to_i
a=gets.split.map(&:to_i)

a=a.sort.reverse
freq, b={}, []
a.each do |e|
  if freq.has_key?(e)
    freq[e]+=1
    b.push(e) if freq[e]%2==0
    break if b.size==2
  else
    freq[e]=1
  end
end

if b.size==2
  puts b[0]*b[1]
else 
  puts 0
end

Measured memory_bytes: 15472
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>

using namespace std;

string s, t;
unordered_map<char, char> m1, m2;

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

	int n = s.length();
	for (int i = 0; i < n; ++i) {
		if (m1.count(s[i]) && m1[s[i]] != t[i]) {
			cout << "No" << endl;
			return 0;
		}

		if (m2.count(t[i]) && m2[t[i]] != s[i]) {
			cout << "No" << endl;
			return 0;
		}
		
		m1[s[i]] = t[i];
		m2[t[i]] = s[i];
	}

	cout << "Yes" << endl;

	return 0;
}

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

constexpr int lim = 1e5;
int par[lim+1];
int rnk[lim+1];
int size[lim+1];

void init(int n){
  for(int i=1; i<=n; i++){
    par[i] = i;
    rnk[i] = 1;
    size[i] = 1;
  }
}

int find(int x){
  if(par[x] == x) return x;
  else return par[x] = find(par[x]);
}

void unite(int x, int y){
  x = find(x);
  y = find(y);
  if(x == y) return;

  if(rnk[x] < rnk[y]){
    par[x] = y;
    size[y] += size[x];
  }
  else{
    par[y] = x;
    size[x] += size[y];
    if(rnk[x] == rnk[y]) rnk[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}

int main(){
  int n, m; cin >> n >> m;
  vector<vector<int>> g(m+1);

  for(int i=1; i<=n; i++){
    int k; cin >> k;
    for(int j=0; j<k; j++){
      int l; cin >> l;
      g[l].push_back(i);
    }
  }
  
  init(n);

  for(int i=1; i<=m; i++){
    for(int j=1; j<g[i].size(); j++){
      unite(g[i][j-1], g[i][j]);
    }
  }

  for(int i=1; i<=n; i++){
    if(size[i] == n){
      cout << "YES" << endl;
      return 0;
    }
  }

  cout << "NO" << endl;

  return 0;
}


Measured memory_bytes: 4608
#include <cmath>
#include <vector>
#include <queue>
#include <iostream>
#include <bits/stdc++.h>
#define lli long long int
#define mp make_pair
#define pb push_back
using namespace std;

const lli mod = 1e9 + 7;

lli power(lli x, lli y) {
    // x %= mod;
    if (y == 0) return 1;
    // return ((y % 2 == 1 ? x : 1) * power(x * x, y / 2)) % mod;
    return ((y % 2 == 1 ? x : 1) * power(x * x, y / 2));
}

vector <long long int> primeNumbers;

void SieveOfEratosthenes(int n){
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime));
    for (int p=2; p*p<=n; p++){ 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
    for (int p=2; p<=n; p++){
      if (prime[p]){
        primeNumbers.push_back(p);
      }
    }        
}

#define MAXN 100005
// vector < vector < int >  > v(MAXN);
// int visit[MAXN];
// int d[MAXN];
// int deg[MAXN];

// void dfs(int index, int parent){
//   visit[index] = 1;
//   for(int i = 0;i<v[parent].size();i++){
//     int node = v[parent][i];
//     if(visit[node]) continue;
//     else if (!binary_search(v[index].begin(),v[index].end(),node)){
//       visit[node] = 1;
//       dfs(node,index);
//     }
//   }
// }
void pre(){
}

void solve(){

  int n,k;
  cin>>n>>k;

  int a[n];
  for(int i = 0;i<n;i++) cin>>a[i];

  //dp[i][j] is the number of ways to distribute j candies to i people
  long long int dp[n+1][k+1];
  memset(dp,0,sizeof(dp));

  dp[0][0] = 1;
  for(int i = 1;i<=k;i++){
    dp[0][i] = 0;
  }
  for(int i = 1;i<=n;i++){
    dp[i][0] = 1;
  }
  for(int i = 1;i<=n;i++){
    long long int sum[k+1] = {0};
    //getting the prefix sum array
    for(int j = 1;j<=k;j++){
      sum[j] = sum[j-1] + dp[i-1][j];
    }
    // for(int i = 0;i<=n;i++){
    //   cout<<sum[i]<<' ';
    // }
    // cout<<endl;

    for(int j = 1;j<=k;j++){
      int lowest = j - min(a[i-1],j);
      int highest = j;
      dp[i][j] = sum[highest] - sum[lowest] + dp[i-1][lowest];
      dp[i][j] %= mod;
    }
  }
  // cout<<endl;
  // for(int i = 0;i<=n;i++){
  //   for(int j = 0;j<=k;j++){
  //     cout<<dp[i][j]<<' ';
  //   }
  //   cout<<endl;
  // }
  cout<<dp[n][k];
}
 
 
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  #ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
  #endif
 
  int t;
  // cin>>t;
  // scanf("%d",&t);
  t = 1;
  pre();
  while(t--){
    // cout<<
    solve();
 
    if(t>0){
      cout<<endl;
      // printf("\n");
    } 
  }
 
 
  cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n";
 
  return 0;
}


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

int f(int a) {
  int res = 0;
  while(a != 0) {
    res += a % 10;
    a /= 10;
  }
  return res;
}
int main() {
  int N;
  cin >> N;
  if (N % f(N) == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define INF 1000000000000
#define MOD 1000000007
using ll = long long;

string to_ternary(ll n,ll k){
  ll res = 0,keta = 1;
  while(n>0){
    res+=n%3*keta;
    n/=3;
    keta*=10;
  }
  string st_res = to_string(res);
  int l =st_res.size();
  for(int i = 0; i < k-l; i++)st_res = '0'+st_res;
  return st_res;
}

ll to_753(string ter){
  vector<int> sft = {7,5,3};
  int l = ter.size();
  ll res = 0;
  for(int i = 0; i < l; i++){
    int index = (int)(ter.at(i)-'0');
    res += sft.at(index)*pow(10,l-1-i);
  }
  return res;
}

int main(){
  ll n,nc;
  cin >> n;
  nc = n;
  int k = 0;
  while(nc>0){
    nc/=10;
    k++;
  }
  ll res = 0;

  for(ll keta = 3; keta < k+1; keta++){
    //長さketaの{0,1,2}からなるstring
    for(ll i = 0; i < pow(3,keta); i++){
      string ter = to_ternary(i,keta);
      set<char> tmp;
      for(auto c:ter)tmp.insert(c);
      if(tmp.size()!=3)continue;//1回以上現れてない
      if(to_753(ter)<=n){
        res++;
      }
    }
  }
  cout<<res<<endl;
  return 0;
}


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

#define INF 1e15

/*
 *範囲のminimumを取得
 */
//区間[l, r)
struct segtree {
	vector<long long> data;
	long long n;
	segtree(long long nin){
		n = pow( 2, ceil( log(nin) / log(2) ) );
		long long size = 2 * n - 1;
		this->data.resize(size, INF);
	}

	//API for update val
	void update(long long idx, long long val){
		update(idx, val, 0, 0, n);
	}

	long long update(long long idx, long long val, long long node_id, long long left, long long right){
		//if query idx is within range return val
		if( !( left <= idx && idx < right ) ){
			return data[node_id];
		}
		if( left + 1 < right ) {
			//when node range is not 1, get update children val and update node data
			long long mid = (left + right) / 2 ;
			long long L = update(idx, val, 2 * node_id + 1, left, mid);
			long long R = update(idx, val, 2 * node_id + 2, mid, right);
			data[node_id] = min(L, R);
		} else {
			//when node range is 1, update node data
			data[node_id] = min(data[node_id], val);
		}
		return data[node_id];
	}
	
	//API for get value of [l, r)
	long long get(long long l, long long r){
		return get(l, r, 0, 0, n);
	}

	/*
	 *internaly used function
	 *query_l: query left range
	 *query_r: query right range
	 *node_id: node id of 
	 *node_l:  node left range 
	 *node_r:  node right range
	 */
	long long get(long long query_l, long long query_r, long long node_id, long long node_l, long long node_r){
		//query range is outside of node range: return INF
		if( query_r <= node_l || node_r <= query_l ){
			return INF;
		}
		//query range is within node range: return node val
		if( query_l <= node_l && node_r <= query_r ){
			return data[node_id];
		}
		long long mid = (node_l + node_r) / 2;
		long long L = get(query_l, query_r, 2 * node_id + 1, node_l, mid);
		long long R = get(query_l, query_r, 2 * node_id + 2, mid, node_r);
		return min(L, R);
	}
};

long long N, M;
//                 l           r         c
vector<pair<pair<long long, long long>, long long> >LRC;

int main(){
	cin >> N >> M;
	for(long long i = 0; i < M; i++){
		long long l, r, c;
		cin >> l >> r >> c;l--;r--;
		LRC.push_back(make_pair(make_pair(l, r), c));
	}
	sort(LRC.begin(), LRC.end());
	segtree sg(N+5);
	sg.update(0, 0);

	for(long long i = 0; i < M; i++){
		long long left = LRC[i].first.first;
		long long right = LRC[i].first.second;
		long long cost = LRC[i].second;

		long long cur = sg.get(left, right + 1);
		sg.update(right, cur + cost);
	}
	long long ans = sg.get(N-1, N);
	if(ans == INF){
		cout << -1 << endl;
	}else{
		cout << ans << endl;
	}
}


Measured memory_bytes: 5488
#include <iostream>
#include <algorithm>

using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)

int calc(int x) {
	int sum = 0;
	while (true) {
		sum += x % 10;
		x /= 10;
		if (x == 0) {
			break;
		}
	}
	return sum;
}
int main() {
	int N, A, B; cin >> N >> A >> B;

	int sum = 0;
	rep(i, 1, N + 1) {
		int C = calc(i);
		if (A <= C && C <= B) {
			sum += i;
		}
	}

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <cstdlib>
#include <utility>
#include <cctype>
#include <algorithm>
#include <bitset>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <cmath>
#define LL long long
#define LB long double
#define x first
#define y second
#define Pair pair<int,int>
#define pii pair<double,double>
#define pb push_back
#define pf push_front
#define mp make_pair
#define LOWBIT(x) x & (-x)
using namespace std;

const int MOD=1e9+7;
const LL LINF=2e16;
const int INF=1e9;
const int magic=348;
const double eps=1e-10;
const double pi=acos(-1);

inline int getint()
{
    char ch;int res;bool f;
    while (!isdigit(ch=getchar()) && ch!='-') {}
    if (ch=='-') f=false,res=0; else f=true,res=ch-'0';
    while (isdigit(ch=getchar())) res=res*10+ch-'0';
    return f?res:-res;
}

int n;
vector<int> v[100048];int col[100048],d[100048],need[100048];
//0: leaf reachable; 1: leaf unreachable
int dp[100048][2],dp2[100048];
char s[100048];
int haswhite[100048];
int ans,maxminus=0;
int cnt=0;

inline void dfs(int cur,int father)
{
	haswhite[cur]=col[cur];
	int i,y;
	for (i=0;i<int(v[cur].size());i++)
	{
		y=v[cur][i];
		if (y!=father)
		{
			dfs(y,cur);
			if (haswhite[y]) haswhite[cur]=1;
		}
	}
}

inline void solve(int cur,int father)
{
	int i,y;bool isleaf=true;
	for (i=0;i<int(v[cur].size());i++)
	{
		y=v[cur][i];
		if (y!=father && haswhite[y])
		{
			isleaf=false;
			solve(y,cur);
		}
	}
	if (isleaf)
	{
		dp[cur][0]=1+(need[cur]==1?1:-1);
		dp[cur][1]=-INF;
		dp2[cur]=dp[cur][0];
		if (cnt>1) maxminus=max(maxminus,dp2[cur]);
		return;
	}
	dp[cur][0]=-INF;dp[cur][1]=dp2[cur]=1+(need[cur]==1?1:-1);
	int nmax=-INF,ymax=-INF;
	for (i=0;i<int(v[cur].size());i++)
	{
		y=v[cur][i];
		if (y!=father && haswhite[y])
		{
			dp[cur][0]=max(dp[cur][0],dp[y][0]+1+(need[cur]==1?1:-1));
			dp[cur][1]=max(dp[cur][1],dp[y][1]+1+(need[cur]==1?1:-1));
			dp2[cur]=max(dp2[cur],nmax+max(dp[y][0],dp[y][1])+1+(need[cur]==1?1:-1));
			dp2[cur]=max(dp2[cur],ymax+dp[y][1]+1+(need[cur]==1?1:-1));
			nmax=max(nmax,dp[y][1]);ymax=max(ymax,dp[y][0]);
		}
	}
	maxminus=max(maxminus,dp2[cur]);
	maxminus=max(maxminus,max(dp[cur][0],dp[cur][1]));
}

int main ()
{
	//freopen ("tree.in","r",stdin);
	//freopen ("tree.out","w",stdout);
	int i,j,x,y;
	n=getint();
	for (i=1;i<=n-1;i++)
	{
		x=getint();y=getint();
		v[x].pb(y);v[y].pb(x);
	}
	scanf("%s",s+1);
	int root=-1;
	for (i=1;i<=n;i++) {col[i]=(s[i]=='W');if (col[i] && root==-1) root=i;}
	if (root==-1)
	{
		printf("0\n");
		return 0;
	}
	dfs(root,-1);ans=0;
	for (i=1;i<=n;i++)
		if (haswhite[i])
			for (j=0;j<int(v[i].size());j++)
				if (haswhite[v[i][j]]) ans++,d[i]++;
	for (i=1;i<=n;i++) if (haswhite[i]) cnt++,need[i]=(d[i]%2)^col[i],ans+=need[i];
	solve(root,-1);
	printf("%d\n",ans-maxminus);
	return 0;
}


Measured memory_bytes: 14336
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;
const int di[4] = { -1, 0, 1, 0 };
const int dj[4] = { 0, -1, 0, 1 };
int main() {
    int n;
    cin >> n;
    vector<int> a(n * n);
    vector<vector<int>> dist(n, vector<int>(n));
    vector<vector<int>> exist(n, vector<int>(n, 1));
    for (int i = 0, x = 0, y = 0; i < n * n; i++, y = (y + 1) % n) {
        cin >> a[i];
        a[i]--;
        dist[x][y] = min({ x, y, n - x - 1, n - y - 1 });
        if ((i + 1) % n == 0) {
            x++;
        }
    }
    // queue<pair<int, int>> q;
    vector<pair<int, int>> q;
    vector<vector<bool>> inq(n, vector<bool>(n));
    int ans = 0;
    for (int id : a) {
        int i = id / n, j = id % n;
        ans += dist[i][j];
        exist[i][j] = 0;
        // q.emplace(i, j);
        q.clear();
        q.emplace_back(i, j);
        // while (!q.empty()) {
        for (int k = 0; k < (int)q.size(); k++) {
            // int mi, mj;
            // tie(mi, mj) = q.front();
            int mi = q[k].first;
            int mj = q[k].second;
            // q.pop();
            inq[mi][mj] = false;
            int val = dist[mi][mj] + exist[mi][mj];
            for (int d = 0; d < 4; d++) {
                int ni = mi + di[d], nj = mj + dj[d];
                if (ni >= 0 && nj >= 0 && ni < n && nj < n &&
                    val < dist[ni][nj]) {
                    dist[ni][nj] = val;
                    if (!inq[ni][nj]) {
                        q.emplace_back(ni, nj);
                        inq[ni][nj] = true;
                    }
                }
            }
        }
    }
    cout << ans << '\n';
}

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

#define debug_input freopen("stdin.in", "r", stdin)
#define debug_output freopen("stdout.out", "w", stdout)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define FORALL(i, n) for(int i = 0; i < n; i++)
#define FORD(i, a, b) for(int i = a; i >= b; i--)
#define SORT(a) sort(a.begin(), a.end())
#define REV(a) reverse(a.begin(), a.end())
#define NP(a) next_permutation(a.begin(), a.end())
#define ALL(a) a.begin, a.end()
#define mp make_pair
#define pb push_back
#define endl "\n"
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	ll ans = -1e18;

	ans = max(ans, a * c);
	ans = max(ans, a * d);
	ans = max(ans, b * c);
	ans = max(ans, b * d);

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

ll a[111111];
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n,k; cin>>n>>k;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	ll ans=ll(1e18);
	for(int i=0;i<n;i++)
	{
		int l=i; int r=i+k-1;
		if(r>=n) continue;
		if(a[l]<=0&&a[r]<=0)
		{
			ans=min(ans,abs(a[l]));
		}
		else if(a[l]>=0&&a[r]>=0)
		{
			ans=min(ans,a[r]);
		}
		else
		{
			ans=min(ans,min(abs(a[l]),abs(a[r]))+a[r]+abs(a[l]));
		}
	}
	cout<<ans<<'\n';
}


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


#define M 1000000007
#define pb push_back
#define mp make_pair
#define s second
#define f first
#define mod 998244353
#define sz(v) (int)(v).size()

#define pii pair<int, int>
#define vi vector<int>
#define ll long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)

ll add(ll a,ll b)
{
	a%=M;
	b%=M;
	ll p = (a+b)%M;
	return (p+M)%M;
}

ll mul(ll a,ll b)
{
	a%=M;
	b%=M;
	ll p = (a*b)%M;
	return (p+M)%M;
}


int main()
{
	fastio;
	ll x,y,z;
	cin>>x>>y>>z;
	cout<<z<<" "<<x<<" "<<y<<endl;
    return 0;
}





Measured memory_bytes: 3632
#include <stdio.h>

int main()
{
  int a, b, tmp, r;

  scanf("%d %d", &a, &b);

  if(a < b)
    {
      tmp = a;
      a = b;
      b = tmp;
    }
  r = a % b;
  while(r != 0)
    {
      a = b;
      b = r;
      r = a % b;
    }
  printf("%d\n", b);

  return 0;
}

Measured memory_bytes: 592
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n = 0,total = 0;
	int s1,s2;
	cin >> s1 >> s2;
	if(s2 == 1){
		cout << 0;return 0;
	}
	total = s1;
	n = 1;
	while(s2 > total){
		total += (s1 - 1);
		n++;
	}
	cout << n;
}

Measured memory_bytes: 256
def slove():
    import sys
    input = sys.stdin.readline
    s = str(input().rstrip('\n'))
    cnt = 0
    for i in range(len(s)):
        if i == 0:
            if s[i] != "A":
                print("WA")
                exit()
        elif 2 <= i <= len(s) - 2:
            if s[i] == "C":
                cnt += 1
            else:
                if s[i] != s[i].lower():
                    print("WA")
                    exit()
        else:
            if s[i] != s[i].lower():
                print("WA")
                exit()
    if cnt == 1:
        print("AC")
    else:
        print("WA")


if __name__ == '__main__':
    slove()


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

using namespace std;

int n, m, d[100] = {}, ans = 0;
string s[100], t[100];

int main() {
    map<string, int> mp;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> s[i];
        if (mp.count(s[i])) {
            mp[s[i]]++;
        } else {
            mp[s[i]] = 1;
        }
    }
    cin >> m;
    for (int i = 0; i < m; i++) {
        cin >> t[i];
        if (mp.count(s[i])) {
            mp[t[i]]--;
        } else {
            mp[t[i]] = -1;
        }
    }
    for (auto x : mp) {
        if (x.second > ans) ans = x.second;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
n, p = map(int, input().split())


def factorization_in_prime_number(x):
    prime_factor = []
    degree = 0
    while x % 2 == 0:
        x //= 2
        degree += 1
    if degree:
        prime_factor.append((2, degree))
    m = int(x**.5) + 1
    for i in range(3, m, 2):
        degree = 0
        while x % i == 0:
            x //= i
            degree += 1
        if degree:
            prime_factor.append((i, degree))
    if x != 1:
        prime_factor.append((x, 1))
    return prime_factor


ans = 1
factor = factorization_in_prime_number(p)
for f, d in factor[::-1]:
    ans *= f ** (d//n)
print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.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;
    if(s=="ABC")cout<<"ARC"<<endl;
    else cout<<"ABC"<<endl;
}

Measured memory_bytes: 3592
var l,n,ans,i  :integer;

begin
  ans:=0;
  readln(n,l);
  for i:=1 to n do inc(ans,l+i-1);
  if l>0 then writeln(ans-l)
  else if l>-n then writeln(ans)
  else writeln(ans-l-n+1)
end.


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

int main() {
	long long N, K, A[15], count = 0, sum = 0, Max = 0, ans = pow(10, 18);
	cin >> N >> K;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	for (long long i = 0; i < pow(2, N - 1); i++) {
		count = 1, Max = A[0], sum = 0;
		long long X = i;
		for (int j = 1; j < N; j++) {
			if (X % 2 == 1) {
				if (Max >= A[j]) {
					sum += Max - A[j] + 1;
					Max++;
				}
				else Max = A[j];
				count++;
			}
			else if (A[j] > Max) Max = A[j];
			X /= 2;
		}
		if (count >= K) ans = min(ans, sum);
	}
	cout << ans << endl;
}

Measured memory_bytes: 512