akhauriyash/Code-Regression huggingface dataset:
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <numeric>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 10e8;
const int MAX_V = 201;
int a[4];
int c[10];
bool use[10];
int t[10][10];

int rec(int n) {

	if (n == 1) return 0;
	int &v = c[n];
	if (~v != 0) return v;

	v = INF;
	for (size_t i = 0; i < 10; i++)
	{
		if (i == n) continue;
		if (use[i]) continue;
		use[i] = true;
		v = min(v, t[n][i] + rec(i));
		use[i] = false;
	}
	return v;
}
void wall(){

	for (size_t i = 0; i < 10; i++)
	{
		c[i] = -1;
	}
	int h, w;
	cin >> h >> w;
	for (size_t i = 0; i < 10; i++)
	{
		for (size_t j = 0; j < 10; j++)
		{
			cin >> t[i][j];
		}
	}

	for (size_t k = 0; k < 10; k++)
	{
		for (size_t i = 0; i < 10; i++)
		{
			for (size_t j = 0; j < 10; j++)
			{
				t[i][j] = min(t[i][j], t[i][k] + t[k][j]);
			}
		}
	}


	int a[201][201];
	int res = 0;
	for (size_t i = 0; i < h; i++)
	{
		for (size_t j = 0; j < w; j++)
		{
			int a;
			cin >> a;
			if (a == -1) continue;
			res += t[a][1];
			//use[a] = true;
			//res += rec(a);
			//use[a] = false;
		}
	}
	cout << res << endl;
}
int main() {
	wall();
	return 0;
}



Measured memory_bytes: 256
import bisect
N=int(input())
L=sorted(list(map(int,input().split())))

ans=0
for i in range(N-2):
  for j in range(i+1,N-1):
    ans+=bisect.bisect_left(L,L[i]+L[j])-j-1
    # ans+=bisect.bisect_left(L,L[i]+L[j],j+1)-j-1
print(ans)

Measured memory_bytes: 3316
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <utility>
#include <functional>

using namespace std;

int main() {
	string s, t;
	cin >> s;
	t = s;
	reverse(t.begin(), t.end());
	if (s == t) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
*s, = map(ord, input())
l = len(s)
ans = l
for c in range(95, 123):
    res = 0
    cnt = 0
    for i in range(l):
        if s[i] == c:
            res = max(res, cnt)
            cnt = 0
        else:
            cnt += 1
    res = max(res, cnt)
    ans = min(ans, res)
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <deque>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <iomanip>
using namespace std;

int main()
{
    int num;
    int box[100010];
    cin >> num;
    for(int i=0;i<num;i++){
        cin >> box[i];
    }
    int ans = 0,currentans =0;;
    for(int i=1;i<num;i++){
        if(box[i]<=box[i-1]){
            currentans ++;
        }else{
            if(ans<currentans){
                ans = currentans;
            }
            currentans = 0;
        }
    }
    if(ans<currentans){
        ans = currentans;
    }
    printf("%d\n",ans);
    return 0;
}

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

int grp(int x) {
    if (x == 1 || x == 3 || x == 5 || x == 7 || x == 8 || x == 10 || x == 12) return 1;
    if (x == 4 || x == 6 || x == 9 || x == 11) return 2;
    return 3;
}

int main() {
    int x, y;
    scanf("%d %d", &x, &y);
    if (grp(x) == grp(y)) puts("Yes");
    else puts("No");
}

Measured memory_bytes: 256
/*
 *  Lang    : C++
 *  Author  : little_angel
 */

#include <bits/stdc++.h>

using namespace std;
#define int long long

int a[10000001];

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    a[1] = 1;
    for (int i = 2; i < 10000001; ++i) {
        a[i]++;
        for (int j = i; j < 10000001; j += i) {
            a[j]++;
        }
    }
    for (int i = 2; i < 10000001; ++i) {
        a[i] = a[i] * i + a[i - 1];
    }
    int n;
    cin >> n;
    cout << a[n] << endl;
}

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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(ll i = (m); i < (n); ++i)

#define INF 1e9

int main(){
  int N, T;
  cin >> N >> T;
  vector<int> A(N);
  REP(i, N){
    cin >> A[i];
  }
  int mdiff = -1, mina = A[0];
  FOR(i, 1, N){
    mina = min(mina, A[i]);
    mdiff = max(mdiff, A[i] - mina);
  }
  int ans = 0;
  mina = A[0];
  FOR(i, 1, N){
    mina = min(mina, A[i]);
    if(mdiff == A[i] - mina){
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
if !ENV['RUBY_THREAD_VM_STACK_SIZE']
  exec({'RUBY_THREAD_VM_STACK_SIZE'=>'1000000000'}, '/usr/bin/ruby', $0)
else
  n, m = gets.split.map(&:to_i)
  @edge = []
  @maxes = []
  def dp(x)
    return @maxes[x] if @maxes[x]
    @maxes[x] = @edge[x]&.map{ |v| dp(v) + 1 }&.max || 0
  end

  m.times do
    u, v = gets.split.map(&:to_i)
    if @edge[u].nil?
      @edge[u] = [v]
    else
      @edge[u] << v
    end
  end
  ans = 0
  (1..n).each { |u| ans = dp(u) if dp(u) > ans }
  puts ans
end


Measured memory_bytes: 108620
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using static System.Console;
using System.Numerics;

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {
            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }


        public static long gcd(long x, long y)
        {
            if (y < x) gcd(y, x);
            while (y != 0)
            {
                var z = x % y;
                x = y;
                y = z;
            }
            return x;
        }
        public static long keta(long x)
        {
            var z = 1;
            while (x > 0)
            {
                x /= 10;
                z++;
            }
            return z;
        }
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var nk = Reads();
            var n = nk[0];
            var k = nk[1];
            var a = Reads();
            long c = 1;
            long s = k;
            while (s<n)
            {
                s += (k - 1);
                c++;
            }
            WriteLine(c);
          
            Console.Out.Flush();
        }
    }
}



Measured memory_bytes: 26932
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N; cin >> N; 
	pair<int, int> P[100010]; 
	int A[100010], B[100010]; 
	map<int, int> M; 
	for(int i = 0; i < N; i++){
		cin >> A[i]; P[i].second = A[i]; 
	}
	for(int i = 0; i < N; i++){
		cin >> B[i]; P[i].first = B[i]; 
	}
	sort(A, A+N); sort(B, B+N); 
	sort(P, P+N); 
	for(int i = 0; i < N; i++){
		if(B[i] < A[i]){
			cout << "No" << endl; return 0; 
		}
	}
	for(int i = 0; i < N-1; i++){
		if(B[i] >= A[i+1]){
			cout << "Yes" << endl; return 0; 
		}
	}
	vector<int> loop; 
	loop.push_back(0); 
	bool used[100010] = {}; 
	used[0] = true; 
	for(int i = 0; i < N; i++) M[A[i]] = i; 
	for(int i = 0; i < N; i++){
		int a = loop.back(); 
		int b = M[P[a].second]; 
		if(used[b]) break; 
		loop.push_back(b); 
		used[b] = true; 
	}
	if(loop.size() == (int) N) cout << "No" << endl; 
	else cout << "Yes" << endl; 
}

Measured memory_bytes: 7168
N,M=map(int,input().split())
AB=[list(map(int,input().split())) for _ in range(N)]
AB.sort(key=lambda AB:AB[0])
ans=0
for i in range(N):
    if M>=AB[i][1]:
        ans+=AB[i][0]*AB[i][1]
        M-=AB[i][1]
    else:
        ans+=AB[i][0]*M
        break
print(ans)

Measured memory_bytes: 29020
from collections import OrderedDict, deque, Counter


def solve():
    N = int(input())
    A = list(map(int, input().split(" ")))
    count_dict = Counter(A)

    cnt = 0
    for key, value in count_dict.items():
        if key > value:
            cnt += value
        else:
            cnt += value - key

    print(cnt)


solve()

Measured memory_bytes: 18672
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons;
import std.math, std.numeric;


void main() {
    readln.chomp.count!"a == '1'".writeln;
}








void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


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

#define IOS                               \
	ios_base::sync_with_stdio(false); \
	cin.tie(0);                       \
	cout.tie(0);                      \
	cin.exceptions(cin.failbit);
#define int long long int //Comment when Unnecessary
#define ll long long
#define sz(a) (int)((a).size())
#define all(a) a.begin(), a.end()
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define pii pair<int, int>
#define vi vector<int>
#define F first
#define S second
#define endl "\n" // Remove on Interactive

const int N = 300009;
const int mod = 1000000007;

int t, n, m;
string s;

int32_t main()
{
	IOS;

	cin >> n;
	m = 0;
	rep(i,	1,n+1)
	{
		if(i%3!=0 and i%5!=0)
		{
			m+=i;
		}
	}
	cout<<m<<endl;
	return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

int main(){
  int N;
  cin>>N;
  cout<<N*N*N<<endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	void house(){
		int house[][][] = new int[4][3][10];
		Scanner s = new Scanner(System.in);
		int cnt = s.nextInt();
		for(int i = 0;i < cnt;i++){
			int b = s.nextInt();
			int f = s.nextInt();
			int r = s.nextInt();
			int v = s.nextInt();
			house[b-1][f-1][r-1]+=v;
		}
		for(int i = 0;i < 4;i++){
			for(int j = 0;j < 3;j++){
				for(int k = 0;k < 10;k++){
					System.out.print(" " + house[i][j][k]);

				}
				System.out.println("");
			}
			if(i < 3)System.out.println("####################");
		}
	}
	public static void main(String args[]){
		Main m = new Main();
		m.house();
	}
}

Measured memory_bytes: 28756
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n, d;
    cin >> n >> d;
    long long dd = d * d;
    long long p, q;
    int i;
    int count=0;
    for(i=0;i<n;i++){
        cin >> p >> q;
        if(p*p+q*q<=dd){
            count++;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n - 1; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define RFOR(i, start, end) for (int i = start - 1; 0 <= i; i--)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using namespace std;
constexpr int INF32       = 1'050'000'000;
constexpr long long INF64 = 4'000'000'000'000'000'000;
constexpr int MOD7        = 1'000'000'007;
constexpr int MOD9        = 1'000'000'009;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}
void scan() {}
template <class H, class... T> void scan(H &&head, T &&... args) {
    std::cin >> head;
    scan(std::forward<T>(args)...);
}
template <class T> void scan(std::vector<T> &v) {
    for (auto &&i : v) {
        scan(i);
    }
}

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

    int N;
    scan(N);
    string s;
    scan(s);
    int ans = N;
    FOR(i, 1, N) {
        if (s[i - 1] == s[i])
            ans--;
    }
    print(ans);

    return 0;
}

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

int main(){
  string s;
  cin>>s;
  
  bool a=0,b=0;
  for(int i=0;i<s.size();i++){
    if(s.at(i)=='C')
      a=1;
    if(s.at(i)=='F' && a==1)
      b=1;
  }
  if(a==1 && b==1)
    cout <<"Yes"<< endl;
  else
    cout <<"No"<< endl;
}

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

using namespace std;

#define MOD 1000000007
#define ll long long int

const int maxn = 2020;

ll dp[maxn][maxn];

void pre() {
    for (int i = 0; i < maxn; i++) dp[i][0] = 1;
    for (int i = 1; i < maxn; i++) {
        for (int j = 1; j < maxn; j++) {
            dp[i][j] = (dp[i - 1][j] + dp[i - 1][j - 1]) % MOD;
        }
    }
}

int main() {
  pre();
  int n, k;
  scanf("%d %d", &n, &k);
  for(int i = 1; i <= k; i++) {
    long long x = dp[n - k + 1][i];
    long long y = dp[k - 1][i - 1];
    printf("%lld\n", (x * y) % MOD);
    //cout << (x * y) % MOD << '\n';
  }
}


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

int main() {
  int a, b, h, m;
  cin >> a >> b >> h >> m;

  double h_angle = 2 * M_PI * (h + m / 60.0) / 12.0;
  double m_angle = 2 * M_PI * m / 60;

  complex<double> p1 = (double)a * (cos(h_angle) + 1i * sin(h_angle));
  complex<double> p2 = (double)b * (cos(m_angle) + 1i * sin(m_angle));
  double ret = sqrt(norm(p1 - p2));

  // double x1 = a * cos(h_angle);
  // double y1 = a * sin(h_angle);
  // double x2 = b * cos(m_angle);
  // double y2 = b * sin(m_angle);

  // double x = x2 - x1;
  // double y = y2 - y1;

  // double ret = sqrt(x * x + y * y);

  // cout << ret << endl;
  printf("%20.20lf\n", ret);
  return 0;
}


Measured memory_bytes: 3992
class BinaryTree {
  constructor(n) {
    this.nodes = [];
    for (let i = 0; i < n; i++) this.nodes[i] = {id: i + 1, parentId: -1, leftId: -1, rightId: -1}
  }

  get root() { return this.nodes.find(n => n.parentId === -1); }

  find(id) { return this.nodes[id - 1]; }

  getByPostorder() {
    let res = [];
    const postorder = (id) => {
      if (id === -1) return;
      let n = this.find(id);
      postorder(n.leftId);
      postorder(n.rightId);
      res.push(id);
    };
    postorder(this.root.id);
    return res;
  }
}

(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());
  const preOrder = lines.shift().split(' ').map(Number);
  const inOrder = lines.shift().split(' ').map(Number);

  let tree = makeTree(preOrder, inOrder);
  console.log(tree.getByPostorder().join(' '));
})();

function makeTree(preOrder, inOrder) {
  let tree = new BinaryTree(preOrder.length);
  const innerMakeTree = (p, i) => {
    let midId = p[0];
    let midIdx = i.indexOf(midId);
    if (midIdx > 0) {
      tree.find(midId).leftId = p[1];
      tree.find(p[1]).parentId = midId;
      innerMakeTree(p.slice(1, midIdx + 1), i.slice(0, midIdx))
    }
    if (midIdx < i.length - 1) {
      tree.find(midId).rightId = p[midIdx + 1];
      tree.find(p[midIdx + 1]).parentId = midId;
      innerMakeTree(p.slice(midIdx + 1), i.slice(midIdx + 1))
    }
  }
  innerMakeTree(preOrder, inOrder);
  return tree;
}



Measured memory_bytes: 15392
#include <bits/stdc++.h>
#define ll long long int
#define fr(i, a, b) for (ll i = a; i < b; i++)
#define pb(v, a) v.push_back(a)
#define Sort(v) sort(v.begin(), v.end())
#define For(m) for (auto it = m.begin(); it != m.end(); it++)
#define mod 1000000007
#define PI 3.14159265358979323846
#define sz(s) (ll)s.size()
#define pii pair<ll,ll>
#define ppii pair<ll,pii>
#define fast                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
using namespace std;
const ll MAXN = 2e6 + 5;

int main()
{
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif
    fast
    string a,b;
    cin >> a >> b;
    ll ans=0;
    fr(i,0,3)
    {
      ans+=(a[i]==b[i]);
    }
    cout << ans;
  return 0;
}


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

namespace AtCoder.C
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var (N, K) = Read2Longs();
            var A = ReadLongs();

            var sb = new StringBuilder();
            for (var i = K; i < N; i++)
            {
                if (A[(int)(i - K)] < A[(int)i])
                {
                    sb.AppendLine("Yes");
                }
                else
                {
                    sb.AppendLine("No");
                }
            }

            return sb.ToString().Trim();
        }

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


Measured memory_bytes: 50588
#include <bits/stdc++.h>
using namespace std;
std::string replaceAll(std::string &replacedStr, std::string from, std::string to) {
    unsigned int pos = replacedStr.find(from);
    int toLen = to.length();
 
    if (from.empty()) {
        return replacedStr;
    }
 
    while ((pos = replacedStr.find(from, pos)) != std::string::npos) {
        replacedStr.replace(pos, from.length(), to);
        pos += toLen;
    }
    return replacedStr;
}
int main() {


//long long a,b;
//int *num=new int[4];
//char *s=new char[3];
string s;
cin >> s;
int res=0;
for(int i=0;i<s.length();i++){
for(int j=0;j<s.length();j++){
if(i<j && s[i]=='C' && s[j]=='F')res++;
}
}

if(res>=1)
cout << "Yes";
else
cout << "No";


}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define ll long long
#define INF 0x3f3f3f3f 
#define MEM(x,y) memset(x,y,sizeof(x))
#define int long long
#define rep(i , a , b) for(int i = a ; i <= b ; i ++)
#define P pair<int,int>
#define  sc(a) scanf("%lld",&a)
#define pf(a) printf("%lld ",a)
using namespace std;
const int maxn = 1 << 16;
struct node
{
    int p1;
    int d1;
    bool operator<(const struct node& a1)const
    {
        return d1 > a1.d1;
    }
};
int du[16];
int eg[16][16];
int d[maxn];
bool vis[maxn];
int n, m, s, ed, fir;
void dijkstra()
{
    priority_queue<node> que;
    for (int i = 0; i < (1<<n); i++)
    {
        d[i] = -1;
        vis[i] = false;
    }
    d[s] = fir;
    node n1;
    n1.p1 = s;
    n1.d1 = d[s];
    que.push(n1);
    while (!que.empty())
    {
        node ans = que.top();
        que.pop();
       int u = ans.p1;
        if (vis[u]) continue;
        vis[u] = true;
        if (u == ed) break;
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < i; j++)
            {
                if (eg[i][j] != -1)
                {
                    int v = u ^ (1 << i);
                    v = v ^ (1 << j);
                    if (d[v] == -1 || d[u] + eg[i][j] < d[v])
                    {
                        d[v] = d[u] + eg[i][j];
                        node n2;
                        n1.p1 = v;
                        n1.d1 = d[v];
                        que.push(n1);
                       
                    }
                }
            }
        }
    }
}
signed main()
{
    while (scanf("%d", &n) != EOF && n)
    {
        sc(m);
        rep(i, 0, n - 1)
        {
            du[i] = 0;
            rep(j, 0, n - 1)
                eg[i][j] = -1;
        }
        fir = 0;
        int q, w, e;
        rep(i, 0, m - 1)
        {
            cin >> q >> w >> e;
            du[q]++;
            du[w]++;
            fir += e;
            if (eg[q][w] == -1 || eg[q][w] > e)
                eg[q][w] = eg[w][q] = e;
        }
        s = 0;
        rep(i, 0, n - 1)
        {
            ed = ed | (1 << i);
            if (du[i] % 2 == 0)
                s = s | (1 << i);
        }
        dijkstra();
        cout << d[ed] << endl;
    }

    return 0;

}



Measured memory_bytes: 4264
N, M, C = map(int, input().split())
B = [int(x) for x in input().split()]
cnt = 0
for i in range(N):
  S = sum([int(x) * B[i] for i, x in enumerate(input().split())]) + C
  cnt += 1 if S > 0 else 0
print(cnt)

Measured memory_bytes: 3060
N, L, *a = map(int, open(0).read().split())
for i, (n, m) in enumerate(zip(a, a[1:]), 1):
    if n + m >= L:
        print('Possible')
        print('\n'.join(c for it in (range(1,i), range(N-1,i,-1), [i]) for c in map(str, it)))
        break
else:
    print('Impossible')

Measured memory_bytes: 14732
import java.util.Scanner;

public class Main {
    
    private static final int FLOOR = 3;
    private static final int ROOMS = 10;
    
    public static void main (String... args) {
        int[][] w1 = new int[FLOOR][ROOMS]; // matrixで表記
        int[][] w2 = new int[FLOOR][ROOMS]; // matrixで表記
        int[][] w3 = new int[FLOOR][ROOMS]; // matrixで表記
        int[][] w4 = new int[FLOOR][ROOMS]; // matrixで表記
        
        Scanner scanner = new Scanner(System.in);
        int count = Integer.parseInt(scanner.nextLine());
        
        for (int i=0; i<count; i++) {
            String[] numbers = scanner.nextLine().split(" ");
            int w = Integer.parseInt(numbers[0]);
            int f = Integer.parseInt(numbers[1]) - 1; // indexに使う
            int r = Integer.parseInt(numbers[2]) - 1; // indexに使う
            int person = Integer.parseInt(numbers[3]);
            
            switch (w) {
                case 1: 
                    w1[f][r] = w1[f][r] + person;
                    break;
                case 2:
                    w2[f][r] = w2[f][r] + person;
                    break;
                case 3:
                    w3[f][r] = w3[f][r] + person;
                    break;
                case 4:
                    w4[f][r] = w4[f][r] + person;
                    break;
            }
        }
        outputMatrix(w1);
        System.out.println("####################");
        outputMatrix(w2);
        System.out.println("####################");
        outputMatrix(w3);
        System.out.println("####################");
        outputMatrix(w4);
    }
    
    private static void outputMatrix(int[][] matrix) {
        for (int i=0; i<FLOOR; i++) {
            for (int j=0; j<ROOMS; j++) {
                System.out.print(String.format(" %d", matrix[i][j]));
            }
            System.out.println();
        }
    }
}


Measured memory_bytes: 27520
n = int(input())
count = 0
ans = 0
for i in range(3,n+1,2):
    for j in range(1,i+2,2):
        if i%j == 0:
            count += 1
    if count == 8:
        ans += 1
        count = 0
    else:
        count = 0
print(ans)

Measured memory_bytes: 9076
/*やったぜ。　投稿者：変態糞土方 (8月16日（水）07時14分22秒)

昨日の8月15日にいつもの浮浪者のおっさん（60歳）と先日メールくれた汚れ好きの土方のにいちゃん

（45歳）とわし（53歳）の3人で県北にある川の土手の下で盛りあったぜ。

今日は明日が休みなんでコンビニで酒とつまみを買ってから滅多に人が来ない所なんで、

そこでしこたま酒を飲んでからやりはじめたんや。

3人でちんぽ舐めあいながら地下足袋だけになり持って来たいちぢく浣腸を3本ずつ入れあった。

しばらくしたら、けつの穴がひくひくして来るし、糞が出口を求めて腹の中でぐるぐるしている。

浮浪者のおっさんにけつの穴をなめさせながら、兄ちゃんのけつの穴を舐めてたら、

先に兄ちゃんがわしの口に糞をドバーっと出して来た。

それと同時におっさんもわしも糞を出したんや。もう顔中、糞まみれや、

3人で出した糞を手で掬いながらお互いの体にぬりあったり、

糞まみれのちんぽを舐めあって小便で浣腸したりした。ああ～～たまらねえぜ。

しばらくやりまくってから又浣腸をしあうともう気が狂う程気持ちええんじゃ。

浮浪者のおっさんのけつの穴にわしのちんぽを突うずるっ込んでやると

けつの穴が糞と小便でずるずるして気持ちが良い。

にいちゃんもおっさんの口にちんぽ突っ込んで腰をつかって居る。

糞まみれのおっさんのちんぽを掻きながら、思い切り射精したんや。

それからは、もうめちゃくちゃにおっさんと兄ちゃんの糞ちんぽを舐めあい、

糞を塗りあい、二回も男汁を出した。もう一度やりたいぜ。

やはり大勢で糞まみれになると最高やで。こんな、変態親父と糞あそびしないか。

ああ～～早く糞まみれになろうぜ。

岡山の県北であえる奴なら最高や。わしは163*90*53,おっさんは165*75*60、や

糞まみれでやりたいやつ、至急、メールくれや。

土方姿のまま浣腸して、糞だらけでやろうや。*/
#include "bits/stdc++.h"
#include <numeric>
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define llMAX numeric_limits<long long>::max()
#define intMAX numeric_limits<int>::max()
#define llMIN numeric_limits<long long>::min()
#define intMIN numeric_limits<int>::min()
#define d_5 100000
#define d9_7 1000000007
#define vll vector<vector<long long>>
#define vl vector<long long>
#define vi vector<int>
#define vii vector<vector<int>>
#define pb push_back
#define pf push_front
#define ld long double
ll judge2(ll n){
  ll ans=1;
  while(!(n<ans && ans<=2*n)){
    ans*=2;
  }
  return ans-n;
}

int main(void){
  ll n;
  cin>>n;
  vl a(n);
 multiset<ll> evens;
  rep(i,n){
    cin>>a[i];
    ll tmp=a[i];
    evens.insert(tmp);
  }
  ll cnt=0;
    while(evens.size()>1){
      auto last = evens.end();
      last--;
      ll tmp=*last;
      if(evens.find(judge2(tmp))!=evens.end()){
        if(judge2(tmp) == tmp ){
          if(*evens.find(judge2(tmp)) == *(++evens.find(judge2(tmp))) ||*evens.find(judge2(tmp)) == *(--evens.find(judge2(tmp)))  ){
            cnt++;
            evens.erase(evens.find(judge2(tmp)));

          }
        }else{
        cnt++;
        evens.erase(evens.find(judge2(tmp)));

        }
      }
      evens.erase(evens.find(tmp));
    }
  cout<<cnt<<endl;
  return 0;
}


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

int main() {
  string S, Sc = "";
  cin >> S;
  for (int i = 0; i < S.size()/2; i++) {
    Sc += "hi";
  }
  if (S == Sc) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m; i<n; i++)
#define co(n) cout << n << endl
using namespace std;
int main(){
  char x, y;
  cin >> x >> y;
  if(x>y) co(">");
  else if(x<y) co("<");
  else co("=");

  return 0;
}


Measured memory_bytes: 256
import itertools
N, K = map(int, input().split())
t = 0
for i in range(K,N+2):
    st = int((i*(0+i-1))/2)
    ed = int((i*(N-i+N+1))/2)
    t += (ed - st + 1)
    t %= 10**9 + 7
print(t)

Measured memory_bytes: 9172
import sys
from heapq import heapify, heappop, heappush

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

def dijkstra(start):
    INF = 10 ** 10
    dist = [INF] * (N+1)
    dist[start] = 0
    que = [(0,start)]
    while que:
        d, prev = heappop(que)
        if dist[prev] < d:
            continue
        for next in graph[prev]:
            d1 = d + 1
            if dist[next] > d1:
                dist[next] = d1
                heappush(que, (d1, next))
    return dist

N, X, Y = lr()
answer = [0] * N # 1-indexed
graph = [[] for _ in range(N+1)] # 1-indexed
for i in range(1, N):
    graph[i].append(i+1)
    graph[i+1].append(i)
graph[X].append(Y)
graph[Y].append(X)

dist_X = dijkstra(X)
dist_Y = dijkstra(Y)
for i in range(1, N):
    for j in range(i+1, N+1):
        d = min(j-i, dist_X[i] + dist_X[j], dist_Y[i] + dist_Y[j])
        answer[d] += 1

print(*answer[1:], sep='\n')


Measured memory_bytes: 4080
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N = INT()

if N%2 == 0:
	print(N*(N-1)//2 - N//2)
	for i, j in combinations(range(1, N+1), 2):
		if i+j == N+1:
			continue
		print(i, j)

else:
	print(N*(N-1)//2 - (N-1)//2)
	for i, j in combinations(range(1, N+1), 2):
		if i+j == N:
			continue
		print(i, j)



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

#define REP(i,n) for(int i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template <class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
int w, h;
int id(int i, int j, int k) {
	return h * w*k + w * i + j;
}

tuple<int, int, int> rid(int ind) {
	return tuple<int,int,int>(ind % (h*w) / w, ind%w, ind / (h*w));
}

struct Edge {
	int  form, to, cost;
};

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

	while (cin >> w >> h, w) {
		vvi v(h, vi(w));
		REP(i, h)REP(j, w)cin >> v[i][j];
		vi c(4);
		REP(i, 4)cin >> c[i];
		vi d(h*w * 4, INF);
		vector<vector<Edge>> g(h*w * 4);

		REP(i, h*w * 4) {
			int x, y, z;
			tie(x, y, z) = rid(i);
			REP(j, 4) {
				int cost;
				if (v[x][y] == j) {
					cost = 0;
				}
				else {
					cost = c[j];
				}
				int nx, ny, nz;
				nz = (z - j + 4) % 4;
				nx = x + dx[nz * 2], ny = y + dy[nz * 2];
				if (nx < 0 || ny < 0 || nx >= h || ny >= w)continue;
				g[i].push_back(Edge{ i, id(nx, ny, nz),cost });
			}
		}
		
		priority_queue<pii, vector<pii>, greater<>> q;
		d[id(0, 0, 1)] = 0;
		q.push({ 0,id(0,0,1) });
		while (!q.empty()) {
			auto p = q.top(); q.pop();
			if (p.first > d[p.second])continue;
			REP(i, g[p.second].size()) {
				if (d[g[p.second][i].to] > d[p.second] + g[p.second][i].cost) {
					d[g[p.second][i].to] = d[p.second] + g[p.second][i].cost;
					q.push({ d[g[p.second][i].to],g[p.second][i].to });
				}
			}
		}
		int ans = INF;
		REP(i, 4)chmin(ans, d[id(h - 1, w - 1, i)]);
		cout << ans << endl;
	}

}


Measured memory_bytes: 3264
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x,a,b;
  cin>>x>>a>>b;
  int m = abs(x-a);
    int n = abs(x-b);
  if(m>n)
  cout << 'B' <<endl;
  else cout << 'A' << endl;
}

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

int sign(int x) {
    if (x >= 0)
        return 1;
    else
        return -1;
}

int main() {
    int x, y;
    cin >> x >> y;

    int ans = abs(abs(x) - abs(y));
    if (x == 0) {
        if (y < 0)
            ans++;
    } else if (y == 0) {
        if (x > 0)
            ans++;
    } else if (sign(x) == sign(y)) {
        if (x > y)
            ans += 2;
    } else {
        ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3616
open Scanf
open Printf
open List

let read_int () = scanf " %d" (fun x -> x)

let rec read_ints n =
  if n = 0
  then []
  else let a = scanf " %d" (fun x -> x) in a :: read_ints (n-1)

let () =
  let (c11::c12::c13::_) = read_ints 3 in
  let (c21::c22::c23::_) = read_ints 3 in
  let (c31::c32::c33::_) = read_ints 3 in
  let ok = ref true in
  ok := !ok && (c11-c12 = c21-c22) && (c21-c22 = c31-c32);
  ok := !ok && (c12-c13 = c22-c23) && (c22-c23 = c32-c33);
  ok := !ok && (c11-c21 = c12-c22) && (c12-c22 = c13-c23);
  ok := !ok && (c21-c31 = c22-c32) && (c22-c32 = c23-c33);
  print_endline (if !ok then "Yes" else "No") 


Measured memory_bytes: 384
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    ll D;
    cin >> D;

    vector<ll> c(26);
    rep(0, i, 26)
    {
        cin >> c.at(i);
    }

    vector<vector<ll>> s(D, vector<ll>(26, 0));
    rep(0, i, D)
    {
        rep(0, j, 26)
        {
            cin >> s.at(i).at(j);
        }
    }

    ll t;
    ll score = 0;
    vector<ll> d(26, 0);
    vector<ll> ans(D);
    rep(0, i, D)
    {
        cin >> t;
        t--;
        score += s.at(i).at(t);

        rep(0, j, 26)
        {
            d.at(j)++;
        }
        d.at(t) = 0;

        rep(0, j, 26)
        {
            score -= c.at(j) * d.at(j);
        }
        ans.at(i) = score;
    }

    rep(0, i, D)
    {
        cout << ans.at(i) << endl;
    }
}


Measured memory_bytes: 3588
N,K = map(int, input().split())
D = list(map(int, input().split()))

CANUSE = [x for x in filter(lambda x: not x in D, range(0,10))]


candidates = []
q = [("")]
# print(CANUSE)

while q:
    s = q.pop()
    if len(s) >= 6:
        continue
    if ( int(s) if s != "" else 0 )  >= N:
        candidates.append(int(s))
        continue

    for ch in CANUSE:
        q.append( s+str(ch) ) 

print(min(candidates))
    
    
    




Measured memory_bytes: 42844
#include <iostream>
using namespace std;
#define MAX 100000
typedef long long llong;
int n,k;
llong T[MAX];

int check(llong);
int solve();

int main(){
    cin >> n >> k;
    for(int i=0;i<n;i++) cin >> T[i];
    llong ans=solve();
    cout << ans << endl;
}

int check(llong P){
    int i=0;

    for(int j=0;j<k;j++){
        llong s=0;

        while(s+T[i]<=P){
            s+=T[i];
            i++;
            if(i==n) return n;
        }

    }

    return i;
}

int solve(){
    llong left=0;
    llong right=100000*10000;
    llong mid;

    while(right-left>1){
        mid=(left+right)/2;
        int v=check(mid);
        if(v>=n) right=mid;
        else left=mid;
    }

    return right;
}


Measured memory_bytes: 3844
#include <iostream>
#include <string>
#include <cmath>

int main() {
    std::string a, b;
    std::cin >> a >> b;

    uint64_t n = std::stoull(a + b);
    bool is_square = false;
    for (uint64_t i = 0; i <= 100100; i++) {
        if (i * i == n) {
            is_square = true;
            break;
        }
    }

    if (is_square) {
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No" << std::endl;
    }

    return 0;
}

Measured memory_bytes: 3632
class Point:
    def __init__(self, x, y):
        self.x = x
        self.y = y
        self.state = 0
        self.cost = -1

    def __str__(self):
        return str(self.cost)

    def __repr__(self):
        return str(self.cost)


def show(points):
    for row in points:
        print(*row)


def maxp(points):
    mp = 0
    for row in points:
        for cell in row:
            mp = max(cell.cost, mp)
    return mp


h, w = map(int, input().split())
s = ["#" * (w + 2)] + ["#" + input() + "#" for _ in range(h)] + ["#" * (w + 2)]
ans = 0


for sy in range(h):
    for sx in range(w):
        p = [[Point(x, y) for x in range(w)] for y in range(h)]
        next_search = [(sx, sy)]
        p[sy][sx].cost = 0
        while next_search:
            x, y = next_search.pop(0)
            t = p[y][x]
            if t.state == -1:
                continue
            t.state = -1
            if s[y + 1][x + 1] == "#":
                continue
            if s[y + 1][x] == ".":
                u = p[y][x - 1]
                u.cost = t.cost + 1 if u.cost == -1 else min(t.cost + 1, u.cost)
                next_search.append((x - 1, y))
            if s[y + 1][x + 2] == ".":
                u = p[y][x + 1]
                u.cost = t.cost + 1 if u.cost == -1 else min(t.cost + 1, u.cost)
                next_search.append((x + 1, y))
            if s[y][x + 1] == ".":
                u = p[y - 1][x]
                u.cost = t.cost + 1 if u.cost == -1 else min(t.cost + 1, u.cost)
                next_search.append((x, y - 1))
            if s[y + 2][x + 1] == ".":
                u = p[y + 1][x]
                u.cost = t.cost + 1 if u.cost == -1 else min(t.cost + 1, u.cost)
                next_search.append((x, y + 1))
        ans = max(maxp(p), ans)
print(ans)


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

using namespace std;

#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007

typedef long long ll;

void solve() {
    string s, t;
    cin >> s >> t;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] != t[i]) {
            cout << "No" << endl;
            return;
        }
    }
    cout << "Yes" << endl;
}

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

Measured memory_bytes: 3620
def ABC152C():
    N = int(input())
    P = list(map(int, input().split()))
    min = 0
    cnt = 0
    for i in range(0, N):
        if i == 0:
            cnt += 1
            min = P[i]

        elif P[i] <= min:
            cnt += 1
            min = P[i]
    print(cnt)

ABC152C()


Measured memory_bytes: 24744
N, M = map(int, input().split())
p = [0] * M
S = [0] * M
for i in range(M):
    line = input().split()
    p[i] = int(line[0])
    S[i] = line[1]

AC = [False for _ in range(N)]
WA = [0 for _ in range(N)]
for i in range(M):
    if AC[p[i] - 1]:
        pass
    else:
        if S[i] == "AC":
            AC[p[i] - 1] = True
        else:
            WA[p[i] - 1] += 1

n_AC = sum(AC)
n_WA = 0
for i in range(N):
    if AC[i]:
        n_WA += WA[i]

print(" ".join([str(n_AC), str(n_WA)]))


Measured memory_bytes: 14896
#include<bits/stdc++.h>
using namespace std;
int main(){
  long N;
  int M, l, sum=0;
  cin >> N >> M;
  for(int i=0;i<M;i++){
    cin >> l;
    sum += l;
  }
  cout << ((N>=sum)?N-sum:-1) << endl;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef string::const_iterator State;
class ParseError{};

int letter(State& begin,const int& a,const int& b,const int& c,const int& d){
    char let = *begin;
    begin++;
    switch(let){
        case 'a':
            return a;
        case 'b':
            return b;
        case 'c':
            return c;
        case 'd':
            return d;
        default:
            throw ParseError();
    }
}

int Hash(State& begin,const int& a,const int& b,const int& c,const int& d){
    if(*begin == '['){
        begin++;
        char op = *begin;
        begin++;
        int hash1 = Hash(begin,a,b,c,d);
        int hash2 = Hash(begin,a,b,c,d);
        begin++;
        switch(op){
            case '+':
                return hash1 | hash2;
            case '*':
                return hash1 & hash2;
            case '^':
                return hash1 ^ hash2;
            default:
                throw ParseError();
        }
    }
    return letter(begin,a,b,c,d);
}

void solve(string S,string P){
    State begin = S.begin();
    int hash = Hash(begin,P[0]-'0',P[1]-'0',P[2]-'0',P[3]-'0');
    int res = 0;
    vector<int> v;
    for(int i = 0;i < 10;i++)v.push_back(i);
    for(auto a:v)for(auto b:v)for(auto c:v)for(auto d:v){
        begin = S.begin();
        if(hash == Hash(begin,a,b,c,d))res++;
    }
    cout << hash << ' ' << res << endl;
}

int main(){
    string S,P;
    while(true){
        cin >> S;
        if(S == ".")return 0;
        cin >> P;
        solve(S,P);
    }
}


Measured memory_bytes: 3104
N = int(input())

pndic= {2:0}
for L in range(3,N+1):
    chk = True
    for L2 in pndic.keys():
        if L%L2 == 0: chk = False
    if chk: pndic[L] = 0

for i in range(1,N+1):
    for p in pndic.keys():
        tmp = 0
        while i % p == 0:
            i //= p
            tmp += 1
        pndic[p] += tmp

ans = 1
for v in pndic.values():
    ans *= v+1
    ans %= 10**9+7

print(ans)

Measured memory_bytes: 3064
k=int(input())
li=list(map(int,input().split(" ")))
x=li[0]
y=li[1]
z=-1

for i in range(x,y+1):
    if(i%k==0):
        z=1
        break
if(z==1):
    print("OK")

else:
    print("NG")    

Measured memory_bytes: 9044
from collections import deque
N = int(input())
a = []
for i in range(N):
    a.append(int(input()))
a.sort()
d = deque(a)
ans = deque([d.popleft()])
cur = 0
while d:
    if cur%2 == 0:
        ans.appendleft(d.pop())
        if len(d) != 0:
            ans.append(d.pop())
        cur += 1
    else:
        ans.appendleft(d.popleft())
        if len(d) != 0:
            ans.append(d.popleft())
        cur += 1
p = 0
for x, y in zip(list(ans), list(ans)[1:]):
    p += abs(x-y)

d = deque(a)
ans = deque([d.pop()])
cur = 1
while d:
    if cur%2 == 0:
        ans.appendleft(d.pop())
        if len(d) != 0:
            ans.append(d.pop())
        cur += 1
    else:
        ans.appendleft(d.popleft())
        if len(d) != 0:
            ans.append(d.popleft())
        cur += 1
q = 0
for x, y in zip(list(ans), list(ans)[1:]):
    q += abs(x-y)
print(max(p, q))

Measured memory_bytes: 17332
import scala.math._

object Main {
  val sc = new java.util.Scanner(System.in)
  def rank(d: Double) = d match {
    case x if x < 0.2 => 3
    case x if x < 0.6 => 2
    case x if x < 1.1 => 1
    case _ => 0
  }
  def main(args: Array[String]) {
    val c = Array.ofDim[Int](2, 4)
    while(sc.hasNext) {
      val l, r = sc.nextDouble
      c(0)(rank(l)) += 1
      c(1)(rank(r)) += 1
    }
    c.transpose.map(_.mkString(" ")).foreach(println)
  }
}

Measured memory_bytes: 46120
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=998244353;
int main(){
    ll n,a,b;cin>>n>>a>>b;
    if((b-a)%2==0)cout<<(b-a)/2<<endl;
    else{
        cout<<min(a-1,n-b)+1+(b-a-1)/2<<endl;
    }
}

Measured memory_bytes: 256
//Be Name Khoda
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma optimize O3
using namespace __gnu_pbds;
using namespace std;
template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T> using ordered_multiset =  tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long int LL;
typedef LL ll;
typedef long double ld;
typedef string str;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef stringstream strs;
 
#define X first
#define Y second
#define PB push_back
#define For(i,a,b) for (int i=a;i<b;i++)
#define Ford(i,a,b) for (int i=a;i>=b;i--)
#define smax(a,b) a=max(a,b)
#define smin(a,b) a=min(a,b)
#define SZ(a) ((ll)a.size())
#define ER(a) cout << #a << ' ' << a << endl
#define LB(a,n,x) (lower_bound(a,(a)+(n),x)-(a))
#define RET(x) { cout << x; exit(0); } 
const ll M=2e3+5,LG=32,SM=600+5,inf=1e18+5;
ll mod=1e9+7;
 
str jad[M];

int main()
{
    ll n,m;
    cin >> n >> m;
    For(i,0,n) cin >> jad[i];
    For(i,0,n)
    {
        For(j,0,m)
        {
            if (i!=n-1 && (j&1)) cout << '#';
            else if (i==0) cout << '#';
            else cout << jad[i][j];
        } 
        cout << '\n';
    }
    cout << '\n';
    For(i,0,n)
    {
        For(j,0,m)
        {
            if (i!=0 && !(j&1)) cout << '#';
            else if (i==n-1) cout << '#';
            else cout << jad[i][j];
        } 
        cout << '\n';
    }
}    


Measured memory_bytes: 1024
#include <bits/stdc++.h>
const char nl = '\n';
using namespace std;
typedef long long ll;
typedef long double ld;
typedef complex<ld> pt;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m; cin >> n >> m;
    string s, t; cin >> s >> t;
    ll len = (ll) n * m / __gcd(n, m);
    unordered_map<ll, int> dumb;
    for (int i = 0; i < n; i++) {
        dumb[len/n*i] = i;
    }
    for (int i = 0; i < m; i++) {
        if (dumb.count(len/m*i) && s[dumb[len/m*i]] != t[i]) {
            puts("-1");
            return 0;
        }
    }
    cout << len << nl;
    return 0;
}


Measured memory_bytes: 4260
#ifndef Local
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/STACK:1024000000,1024000000")
#endif

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define popCnt(x) (__builtin_popcountll(x))
typedef long long Long;

const int N = 2e6 + 5;
const int MOD = round(1e9 + 7);

int acc[N];
int arr[N];

int cnt[N][2];
int pw2[N];

int cnt_zeroes[N];
int last_occ[N];
int nxt_occ[N];

void build() {
  pw2[0] = 1;
  for (int i = 1; i < N; ++i) {
    pw2[i] = 2LL * pw2[i - 1] % MOD;
  }
}

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef Local
  freopen("test.in", "r", stdin);
#else
#define endl '\n'
#endif

  build();

  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> arr[i];
    acc[i] = acc[i - 1] ^ arr[i];

    cnt_zeroes[i] = cnt_zeroes[i - 1] + (acc[i] == 0);
    nxt_occ[last_occ[acc[i]]] = i;
    last_occ[acc[i]] = i;
  }

  if (acc[n] == 0) {
    for (int i = 1; i < N; ++i) {
      cnt[i][0] = 1;
    }
  }

  for (int i = n; i >= 1; --i) {
    if (i == last_occ[acc[i]]) {
      cnt[acc[i]][1] = 1;
      continue;
    }
    if (acc[i] != 0) {
      int cnt_zeroes = ::cnt_zeroes[nxt_occ[i]] - ::cnt_zeroes[i];
      cnt[acc[i]][0] = (cnt[acc[i]][0] + 1LL * cnt_zeroes * cnt[acc[i]][1])
        % MOD;
      cnt[acc[i]][1] = (cnt[acc[i]][1] + cnt[acc[i]][0]) % MOD;
    }
  }

  Long res = 0;
  if (acc[n] == 0) {
    res = pw2[cnt_zeroes[n] - 1];
    for (int i = 1; i < N; ++i) {
      res = (res + cnt[i][1]) % MOD;
    }
  } else {
    res = cnt[acc[n]][1];
  }

  cout << res << endl;
}


Measured memory_bytes: 43136