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

int main() {
  int n;
  cin >> n;
  
  vector<int> a(n);
  for(int i=0; i<n; i++)
    cin >> a.at(i);
  
  int x = 1;
  int t = -1;
  for(int i=0; i<n; i++) {
    x = a.at(x-1);
    if(x == 2) {
      t = i + 1;
      break;
    }
  }
  cout << t << endl;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>

int comp(const void * elem1, const void * elem2)
{
  int f = *((int *)elem1);
  int s = *((int *)elem2);
  if (f > s) return 1;
  if (f < s) return -1;
  return 0;
}

int main(int argc, char *argv[])
{
  int array[3] = {};

  scanf("%d %d %d", &array[0], &array[1], &array[2]);
  qsort(array, 3, sizeof(int), comp);
  printf("%d\n", array[2]*10+array[1]+array[0]);

  return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<vector<int>> g(n, vector<int>(n, -1));
  rep(i, n) {
    int a;
    cin >> a;
    rep(j, a) {
      int x, y;
      cin >> x >> y;
      x--;
      g[i][x] = y;
    }
  }

  int ans = 0;
  rep(i, 1 << n) {
    vector<int> d(n);
    rep(j, n) if (i >> j & 1) d[j] = 1;
    bool ok = true;
    rep(j, n) if (d[j]) {
      rep(k, n) {
        if (g[j][k] == -1) continue;
        if (g[j][k] != d[k]) ok = false;
      }
    }
    if (ok) ans = max(ans, __builtin_popcount(i));
  }
  cout << ans << endl;
  return 0;
}


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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
#define MOD 1000000007
int main() {
	int n = ri();
	std::string s;
	std::cin >> s;
	int dp[n][n];
	memset(dp, 0, sizeof(dp));
	dp[0][0] = 1;
	dp[0][1] = MOD - 1;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (j) {
				dp[i][j] += dp[i][j - 1];
				if (dp[i][j] >= MOD) dp[i][j] -= MOD;
			}
			if (i + 1 == n || !dp[i][j]) continue;
			if (s[i] == '>') {
				dp[i + 1][0] += dp[i][j];
				if (dp[i + 1][0] >= MOD) dp[i + 1][0] -= MOD;
				dp[i + 1][j + 1] -= dp[i][j];
				if (dp[i + 1][j + 1] < 0) dp[i + 1][j + 1] += MOD;
			} else {
				dp[i + 1][j + 1] += dp[i][j];
				if (dp[i + 1][j + 1] >= MOD) dp[i + 1][j + 1] -= MOD;
				if (i + 2 < n) {
					dp[i + 1][i + 2] -= dp[i][j];
					if (dp[i + 1][i + 2] < 0) dp[i + 1][i + 2] += MOD;
				}
			}
		}
	}
	int res = 0;
	for (int i = 0; i < n; i++) {
		res += dp[n - 1][i];
		if (res >= MOD) res -= MOD;
	}
	std::cout << res << std::endl;
	return 0;
}


Measured memory_bytes: 35456
package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
)

const Inf = 1 << 60

func main() {
	H, W, K := ReadInt(), ReadInt(), ReadInt()
	x1, y1, x2, y2 := ReadInt()-1, ReadInt()-1, ReadInt()-1, ReadInt()-1
	x1, y1 = y1, x1
	x2, y2 = y2, x2
	c := make([]string, H)
	for y := 0; y < H; y++ {
		c[y] = ReadString()
	}

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

	toID := func(x, y, dir int) int {
		return 4*(W*y+x) + dir
	}
	splatID := func(id int) (x, y, dir int) {
		return id / 4 % W, id / 4 / W, id % 4
	}

	dist := make([]int, W*H*4)
	for i := 0; i < W*H*4; i++ {
		dist[i] = Inf
	}

	q := Heap{}
	for i := 0; i < 4; i++ {
		q = append(q, State{
			Cost: 0,
			ID:   toID(x1, y1, i),
		})
	}
	for len(q) > 0 {
		now := q.pop()
		x, y, dir := splatID(now.ID)
		if c[y][x] == '@' {
			continue
		}
		if dist[now.ID] <= now.Cost {
			continue
		}
		dist[now.ID] = now.Cost
		for i := 0; i < 4; i++ {
			q.push(State{
				Cost: (now.Cost + K - 1) / K * K,
				ID:   toID(x, y, i),
			})
		}
		nx := x + dx[dir]
		ny := y + dy[dir]
		if 0 <= nx && nx < W && 0 <= ny && ny < H {
			q.push(State{
				Cost: now.Cost + 1,
				ID:   toID(nx, ny, dir),
			})
		}
	}
	ans := Inf
	for i := 0; i < 4; i++ {
		id := toID(x2, y2, i)
		if dist[id] < ans {
			d2 := (dist[id] + K - 1) / K
			if d2 < ans {
				ans = d2
			}
		}
	}
	if ans < Inf {
		fmt.Println(ans)
	} else {
		fmt.Println(-1)
	}
}

type State struct {
	Cost, ID int
}

type HeapElement = State
type Heap []HeapElement

func (h Heap) Less(i, j int) bool    { return h[i].Cost < h[j].Cost }
func (h Heap) Len() int              { return len(h) }
func (h Heap) Swap(i, j int)         { h[i], h[j] = h[j], h[i] }
func (h *Heap) Push(x interface{})   { *h = append(*h, x.(HeapElement)) }
func (h *Heap) Pop() (x interface{}) { *h, x = (*h)[:len(*h)-1], (*h)[len(*h)-1]; return }
func (h *Heap) push(v HeapElement)   { heap.Push(h, v) }
func (h *Heap) pop() HeapElement     { return heap.Pop(h).(HeapElement) }

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 110056
N, M, Q = map(int, input().split())
LR = [tuple(map(int, input().split())) for _ in range(M)]
PQ = [tuple(map(int, input().split())) for _ in range(Q)]

Acum = [[0 for _ in range(N + 1)] for _ in range(N + 1)]
for l, r in LR:
  Acum[l][r] += 1
for i in range(1, N + 1):
  for j in range(1, N + 1):
    Acum[i][j] += Acum[i][j - 1]
for j in range(1, N + 1):
  for i in range(1, N + 1):
    Acum[i][j] += Acum[i - 1][j]
#for i in range(N + 1):
#  print(Acum[i])
  
for p, q in PQ:
  print(Acum[q][q] - Acum[p - 1][q] - Acum[q][p - 1] + Acum[p - 1][p - 1])

Measured memory_bytes: 104152
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> C(26, 53);
	for(int i=0; i<n; i++) {
		string S;
		cin >> S;
		sort(S.begin(), S.end());
		char tmp = 'a';
		int tmpi = 0;
		for(int j=0; j<26; j++) {
		    int count = 0;
			while(tmpi < S.size() && S[tmpi] == tmp) {
				count++;
				tmpi++;
			}
			if(C[j] > count) C[j] = count;
			tmp++;
		}
	}
	char tmp = 'a';
	string ret;
	for(int i=0; i<26; i++) {
	   for(int j=0; j<C[i]; j++)
	      ret += tmp;
	   tmp++;
	}
	cout << ret << endl;
	return 0;
}


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

int main() {
  int n;
  int a[110];
  cin >> n;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }

  long long res = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i+1; j < n; j++) {
      for (int k = j+1; k < n; k++) {
        if (a[i] == a[j] || a[i] == a[k] || a[j] == a[k]) continue;
        if (a[i]+a[j] >a[k] && a[j]+a[k] > a[i] && a[i]+a[k] > a[j]) res++;
      }
    }
  }

  cout << res << endl;

  return 0;
}



Measured memory_bytes: 3760
import Data.Bool
import qualified Data.ByteString.Char8 as C
import Data.List
import qualified Data.Map.Strict as M

main = C.interact $ put . sol . get

get = fmap (unfoldr (C.readInt . C.dropWhile (==' '))) . C.lines

put = C.pack . show

sol :: [[Int]] -> Int
sol ([n,ma,mb]:abcs) = bool (minimum $ M.elems mp) (-1) (M.null mp)
  where
  mp = M.filterWithKey (\[a,b] _ -> a*mb==b*ma) . M.deleteMin $
    foldr f (M.singleton [0,0] 0) abcs
  f [a,b,c] = M.unionWith min <*>
    M.map ((+) c) . M.mapKeysMonotonic (zipWith (+) [a,b])

Measured memory_bytes: 19580
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define rrep(i,n) for (ll i = (n)-1; i >=0; --i)
#define ALL(a) a.begin(),a.end()
#define pb push_back
#define dame { puts("-1"); return 0;}
#define show(x) cerr<<#x<<" = "<<x<<endl;

using namespace std;
using ll = long long;
using ld = long double;
using pi = pair<ll, ll>;

typedef vector<ll> vl;
typedef vector<pi> vp;
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 (a>b) { a=b; return 1; } return 0; }


// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const ll mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} c(200005);



int main() {
  ll h,w;
  cin >> h>>w;

  ll dp[1001][1001];

  queue<pi> q;
  rep(i, h){
    string tmp;
    cin >> tmp;
    rep(j, w){
      if(tmp[j]=='#'){
	dp[i][j] = 0;
	q.push({i, j});
      }
      else dp[i][j] = 1e8+1;
    }
  }

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

  ll ans = 0;
  while(!q.empty()){
    pi x = q.front();
    q.pop();
    rep(i, 4){
      if((x.fi+dy[i])<0 || (x.fi+dy[i])>=h || (x.se+dx[i])<0 || (x.se+dx[i])>=w) continue;
      if(dp[x.fi+dy[i]][x.se+dx[i]] < 1e8) continue;
      q.push({x.fi+dy[i], x.se+dx[i]});
      dp[x.fi+dy[i]][x.se+dx[i]] = dp[x.fi][x.se] + 1;
      chmax(ans, dp[x.fi+dy[i]][x.se+dx[i]]);
    }
    
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 27572
import math
a, b, c = map(int, input().split())
D = b / a
if a > b:
    print(0)
elif D == c:
    print(c)
elif D > c:
    if c > D:
        print(math.floor(D))
    else:
        print(c)
else:
    print(math.floor(D))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
int A,B,C;
cin>>A>>B>>C;
if(A==B&&B!=C){
cout<<"Yes"<<endl;
}else if(B==C&&C!=A){
cout<<"Yes"<<endl;
}else if(C==A&&A!=B){
cout<<"Yes"<<endl;
}
else{
cout<<"No"<<endl;
}
}


Measured memory_bytes: 256
MOD1 = 13
MOD2 = 10 ** 9 + 7

S = input()
N = len(S)
dp = [[0 for _ in range(MOD1)] for _ in range(N)]

if S[0] == '?':
    for k in range(10):
        dp[0][k % MOD1] += 1
else:
    dp[0][int(S[0]) % MOD1] += 1

for i in range(N-1):
    if S[i+1] == '?':
        for j in range(MOD1):
            for k in range(10):
                tmp_j = (j * 10 + k) % MOD1
                dp[i+1][tmp_j] += dp[i][j]
                dp[i + 1][tmp_j] %= MOD2
    else:
        for j in range(MOD1):
            tmp_j = (j * 10 + int(S[i+1])) % MOD1
            dp[i+1][tmp_j] += dp[i][j]
            dp[i + 1][tmp_j] %= MOD2

print(dp[-1][5] % MOD2)


Measured memory_bytes: 66524
using System;
namespace _1{
    class program
    {
  
        static void Main()
        {
            string[] c = Console.ReadLine().Split();
            int a, b;
            a = int.Parse(c[0]);
            b = int.Parse(c[1]);
            if(a < b)
            {
                Console.WriteLine("a < b");
            }
            else if(a > b)
            {
                Console.WriteLine("a > b");
            }
            else
            {
                Console.WriteLine("a == b");
            }
           
        }
    }
}


Measured memory_bytes: 15964
from collections import deque


def bfs(start):
    distance = [None] * n
    q = deque([start])
    distance[start] = 0
    while q:
        pos = q.popleft()
        d = distance[pos]
        for next_pos, cost in graph[pos]:
            if distance[next_pos] is not None:
                continue
            distance[next_pos] = d + cost
            q.append(next_pos)
    d = max(distance)
    return distance.index(d), d
  
def tree_diameter():
    ind, _ = bfs(0)
    ind2, d = bfs(ind)
    return d

n = int(input())
info = [list(map(int, input().split())) for i in range(n - 1)]
graph = [[] for i in range(n)]
for i in range(n - 1):
    a, b = info[i]
    a -= 1
    b -= 1
    cost = 1
    graph[a].append((b, cost))
    graph[b].append((a, cost))


if tree_diameter() % 3 == 1:
    print("Second")
else:
    print("First")

Measured memory_bytes: 124708
#include <stdio.h>
#include <cmath>
#include <bits/stdc++.h>



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)



int main(void){

	int N; cin >> N;

	if(N%2 == 0) cout << N << endl;
	else cout << 2*N << endl;

	return 0;

}


Measured memory_bytes: 256
import * as fs from 'fs';

//in
//
//out
//
const main = (inp: string) => {

    const h: number = parseInt(inp.split('\n')[0].split(' ')[0]);
    const w: number = parseInt(inp.split('\n')[0].split(' ')[1]);
    const hh: number = parseInt(inp.split('\n')[1].split(' ')[0]);
    const ww: number = parseInt(inp.split('\n')[1].split(' ')[1]);
    console.log((h - hh) * (w - ww));
};

main(fs.readFileSync('/dev/stdin', 'utf8').trim());


Measured memory_bytes: 7372
#include<iostream>
using namespace std;
int d[1<<18],a,b,c,n,q;
void m(int l,int r,int k){
	if(r<=a||b<=l)return;
	if(a<=l&&r<=b)d[k]+=c;
	else{m(l,(l+r)/2,k*2+1);m((l+r)/2,r,k*2+2);}
}
int main(){
	cin>>a>>q;n=4;
	while(n<a)n*=2;a=n*2;
	while(a--)d[a]=0;
	while(q--){
		cin>>a;
		if(a){
			cin>>a;a+=n-1,b=d[a];
			while(a)a=(a-1)/2,b+=d[a];
			cout<<b<<endl;
		}
		else{cin>>a>>b>>c;b++;m(0,n,0);}
	}
	return 0;
}

Measured memory_bytes: 4112
def main():
    S = input()
    N = len(S)
    count = 0
    list_ = []
    for i in range(len(S)):
        if len(list_) == 0:
            list_.append(S[i])
        else:
            if S[i] != list_[-1]:
                count += 2
                list_.pop(-1)
            else:
                list_.append(S[i])
    print(count)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3956
// Ver19.03
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF (1 << 29) * 2
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  ll w, h, n;
  ll x, y, a;
  ll ww = 0, hh = 0;
  scanf("%lld%lld%lld", &w, &h, &n);
  for (int i = 0; i < n; i++)
  {
    scanf("%lld%lld%lld", &x, &y, &a);
    if (a == 1)
      ww = MAX(ww, x);
    if (a == 2)
      w = MIN(w, x);
    if (a == 3)
      hh = MAX(hh, y);
    if (a == 4)
      h = MIN(h, y);
  }
  printf("%lld\n", MAX(0, (h - hh)) * MAX(0, (w - ww)));
  return 0;
}

Measured memory_bytes: 128
main = interact $ sol . fmap read . words

sol [sx,sy,tx,ty] = u y ++ r x ++ d y ++ l x ++
  l 1 ++ u (y+1)  ++ r (x+1) ++ d 1 ++ r 1 ++ d (y+1) ++ l (x+1) ++ u 1
  where
  x = tx-sx
  y = ty-sy

u n = replicate n 'U'
d n = replicate n 'D'
l n = replicate n 'L'
r n = replicate n 'R'


Measured memory_bytes: 1020
#include<stdio.h>
int main(){
    int n,k;
    int a[1000];
    int b[1];
    int sum=0;
    scanf("%d %d",&n,&k);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(a[i]>a[j]){
                b[0]=a[i];
                a[i]=a[j];
                a[j]=b[0];
            }else{
                continue;
            }
        }
    }
    for(int i=0;i<k;i++){
        sum=sum+a[i];
    }
    printf("%d\n",sum);
}

Measured memory_bytes: 1728
from collections import deque

N, M = map(int, input().split())
edges = []

for _ in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    edges.append((a, b))

ans = 0
for removeEdge in range(M):
    confilm = [False for _ in range(N)]
    que = deque([])
    que.append(0)

    while que:
        now = que.popleft()
        confilm[now] = True
        for i, (a, b) in enumerate(edges):
            if i == removeEdge:
                continue
            if a == now:
                if not confilm[b]:
                    que.append(b)
            if b == now:
                if not confilm[a]:
                    que.append(a)
    if False in confilm:
        ans += 1

print(ans)

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  unordered_map<int, int> mp;

  for (int i = 2; i <= n; ++i) {
    int t = i;
    int j = 2;
    while (t > 1) {
      if (t % j == 0) {
        mp[j]++;
        t /= j;
      } else {
        j++;
      }
    }
  }

  ll ans = 1;
  for (auto m : mp) ans = ans * (m.second + 1) % MOD;

  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
#define int long long
#define vel vector<long long>
#define vvel vector<vel>
#define vvvel vector<vvel>
void mmin(int &a, int b) { a = min(a, b); }
void mmax(int &a, int b) { a = max(a, b); }
void sor(vel &v) { sort(v.begin(), v.end()); }
int zero() { return 0; }
void swap(vel &que, vel &pos, int i, int j) {
	int x = que[i];
	int y = que[j];
	pos[x] = j;
	pos[y] = i;
	que[i] = y;
	que[j] = x;
}
void down(vel &que, vel &pos,vel &va,int n) {
	int i = 1;
	while (i * 2 <= n) {
		if (i * 2 == n) {
			swap(que,pos, i, 2 * i);
			i = 2 * i;
		}
		else {
			if (va[que[2 * i]] < va[que[2 * i + 1]]) {
				swap(que, pos, i, 2 * i);
				i = 2 * i;
			}
			else {
				swap(que, pos, i, 2 * i + 1);
				i = 2 * i + 1;
			}
		}
	}
}
void up(vel &que, vel &pos, vel &va, int i, int n) {
	while (i > 1) {
		int j = i / 2;
		if (va[que[i]] < va[que[j]]) {
			swap(que, pos, j, i);
			i = j;
		}
		else {
			i = 0;
		}
	}
}
signed main() {
	int n, m, c;
	cin >> n >> m >> c;
	vel to(m);
	vel fr(m);
	vel dw(m);
	vel cowa(n, 0);
	for (int i = 0; i < m; i++) {
		cin >> fr[i] >> to[i] >> dw[i];
		fr[i]--; to[i]--;
		cowa[fr[i]]++; cowa[to[i]]++;
	}
	vvel wa(n);
	vvel wac(n);
	for (int i = 0; i < n; i++) {
		vel nan(cowa[i]);
		wa[i] = nan;
		wac[i] = nan;
	}
	vel cour(n, 0);
	for (int i = 0; i < m; i++) {
		int fr1 = fr[i];
		int to1 = to[i];
		wa[fr1][cour[fr1]] = to1;
		wac[fr1][cour[fr1]] = dw[i];
		wa[to1][cour[to1]] = fr1;
		wac[to1][cour[to1]] = dw[i];
		cour[fr1]++;
		cour[to1]++;
	}
	int ma1 = 100001;
	ma1 *= ma1;
	vel dij(n, ma1);
	vel va(n, ma1);
	vel que(n + 1);
	vel pos(n);
	for (int i = 1; i <= n; i++) {
		que[i] = i - 1;
		pos[i - 1] = i;
	}
	dij[0] = 0;
	for (int i = 0; i < n; i++) {
		int fr2 = que[1];
		va[fr2] = ma1;
		down(que,pos,va,n);
		for (int nu = 0; nu < cowa[fr2]; nu++) {
			int to2 = wa[fr2][nu];
			if (dij[to2] > dij[fr2] + wac[fr2][nu]) {
				dij[to2] = dij[fr2] + wac[fr2][nu];
				va[to2] = dij[fr2] + wac[fr2][nu];
				up(que, pos, va, pos[to2],n);
			}
		}
	}
	vel sodij = dij;
	sor(sodij);
	vel qdij(n);
	for (int i = 0; i < n; i++) {
		qdij[i] = dij[i] * n + i;
	}
	sor(qdij);
	vel rank(n);//i no rank ha rank[i]
	for (int i = 0; i < n; i++) {
		int num = qdij[i] % n;
		rank[num] = i;
	}
	vel couco(n,0);
	for (int i = 0; i < m; i++) {
		int fr1 = fr[i];
		int to1 = to[i];
		int co1 = dw[i];
		couco[max(rank[fr1], rank[to1])] += co1;
	}
	int ans = sodij[n - 1] * c;
	int ba = ans;
	for (int i = n - 2; i >= 0; i--) {
		ba += couco[i + 1];
		ba -= (sodij[i + 1] - sodij[i])*c;
		mmin(ans, ba);
	}
	cout << ans << endl;
	return 0;
}



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

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

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

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

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

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

    string ans = "";
    while (N > 0) {
        int n = N % 26;
        N /= 26;
        if (n == 0) N--, n = 26;
        char c = 'a' + n - 1;
        ans.push_back(c);
    }

    reverse(ans.begin(), ans.end());
    cout << ans << endl;
}

Measured memory_bytes: 3612
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<set>
#include<stdio.h>
#include<ctype.h>
using namespace std;
int main()
{
	int ans = 0;
	for (int i = 0; i < 3; i++)
	{
		int a;
		cin >> a;
			ans += a;
	}
	if (ans >= 22)
	{
		cout << "bust" << endl;
	}
	else
	{
		cout << "win" << endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; typedef long double ld; typedef long long ll;
typedef unsigned long long ull;
#define MP make_pair
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORR(x,arr) for(auto& x:arr)
#define VI vector<int>
#define PII pair<int, int>
#define FI first 
#define SE second
#define ALL(x) (x).begin(), (x).end()
const int INF=1<<30; const ll LINF=1LL<<60 ; const ll MOD=1e9+7 ;
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 n;
int a,b,c,d,e,k;

int main(){
    cin >> a >> b >> c >> d>> e >> k;
    if(e-a <= k) cout <<  "Yay!";
    else cout << ":(";
    return 0;
}


Measured memory_bytes: 764
a,b,k = input().split()
a=int(a)
b=int(b)
k=int(k)
if a==b:
  print(a)
if b-a < k:
  k=b-a
x=[i for i in range(a,a+k)]
y=[i for i in range(b,b-k,-1)]
z=x+y
z.sort()
z=set(z)
z=list(z)
z.sort()
for i in range(len(z)):
    print(z[i])



Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <numeric>
#include <stack>
#include <cstring>
#include <math.h>
using namespace std;

int n;
int c[26];
long long mo = 1000000007;
char s[100010];

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

    for (int i = 0; i < n; ++i) c[s[i] - 'a']++;

    long long ans = 1;
    for (int i = 0; i < 26; ++i) {
        ans = ans * (c[i] + 1) % mo;
    }

    cout << (ans + mo - 1) % mo << endl;

    return 0;
}

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

using namespace std;

int main(){

	int N; cin >> N;
	int cur=0, min=N, count=0;

	for(int i=0; i<N; ++i){
		cin >> cur;
	       	if(cur<=min){
			++count;
			min = cur;
		}
	}

	cout << count << endl;

	return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define rrep(i,n) for(int i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using ll = long long;
using namespace std;
typedef pair<int,int> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int xa,ya,xb,yb;

int main(){
    cin >> xa >> ya >> xb >> yb;
    int x = xb - xa;
    int y = yb - ya;
    cout << xb - y << " " << yb + x << " " << xa - y << " " << ya + x << '\n';
}

Measured memory_bytes: 256
/*
    NEVER GIVE UP!
    THE EXPERT IN ANYTHING WAS ONCE A BEGINNER
*/
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define f(i,a,b) for(ll i=a; i<=b; i++)
#define fi(i,a,b) for(ll i=a; i>=b; i--)
#define fa(x,b) for(auto x:b)
#define TC ll test_case; cin>>test_case; for(ll number=1 ; number <= test_case ; number ++ )
#define vll vector<ll>
#define pb push_back
#define pll pair<ll,ll>
#define mp make_pair
#define ff first
#define ss second
#define sz(a) (ll)(a).size()
#define sp(x) cout << fixed << setprecision(x);
#define ReadFile freopen("input.txt","r",stdin)
#define WriteFile freopen("output.txt","w",stdout)
#define endl "\n"

const ld pi = acos(-1);
const ll M=1e9+7,N=1e7+5,INF=1e18;

void solve()
{
    ll s,w;
    cin >> s >> w;
    if(w>=s)
        cout << "unsafe" << endl;
    else 
        cout << "safe" << endl;
}

int32_t main()
{
    FIO
    solve();
    return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<cstring>
#include<cstdio>

using namespace std;

int main(){
    int n;
    int ans=0;
    scanf("%d",&n);
    int ret=999;
    for (int i=1;i<=n;i++){
        int x;
        scanf("%d",&x);
        ans+=x;
        if (x%10 !=0 ) ret=min(ret,x);
    }
    if (ret==999){
        if (ans%10==0) ans=0;
    }
    else{
        if (ans%10==0) ans-=ret;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fastio     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define all(x)     (x).begin() , (x).end()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define endl       '\n'
#define MAX        1000000
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
typedef long long int ll;
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}


const ll mod = 1e9+7;
const double eps = 1e-9;
const double pi = acos(-1);


const int maxN=102;
int arr[maxN];
int n;

ll cost(int e) {
    ll c=0;
    for(int i=0;i<n;++i) {
        c+=(arr[i]-e)*(arr[i]-e);
    }
    return c;
}

void solve(){
    cin>>n;
    for(int i=0;i<n;i++) {
        cin>>arr[i];
    }
    ll ans=numeric_limits<ll>::max();
    for(int j=-100;j<=100;j++) {
        ans=min(ans,cost(j));
    }
    cout<<ans<<"\n";
}





int main(){
    fastio
    int test=1;
    while(test--)
        solve();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>                                                   //---------------------------------------------------------------
                                                                    
# define ll long long   
# define ld long double                                               
# define mod 1000000007                                                   
# define MAX 100005
# define pi 3.141592653589793238                                                                                  //shortcut keys
                                                                                
# define pb push_back                                                                     
# define mp make_pair 
# define all(x) x.begin(),x.end()                                                      
                                                                  
# define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);        //---------------------------------------------------------------                                       
using namespace std;

ll power(ll x,ll y,ll m){            //power(x,y)=x^y  %m;
	if(y==0)return 1;
	int ll a=power(x,y/2,m);
	if(y%2){
		return (a*((a*x)%m))%m;
	}
	else{
		return (a*a)%m;
	}
}
ll mod_inverse(ll x,ll m){
	return power(x,m-2,m);
}
ll fact(ll n,ll m){
	if(n<=1)return 1;
	return (fact(n-1,m)*n)%m;
}
ll ncr(ll n,ll r,ll m){
	ll n1=1,d1=1,d2=1;
	n1=fact(n,m);d1=fact(r,m);d2=fact(n-r,m);
	ll ans=mod_inverse((d1*d2)%m,m);
	ans=(ans*n1)%m;
	return ans;
}
int main()
{
	ll n;
	cin>>n;
	ll sum=0;
	for(int i=1;i<=n;i++){
		if(i%3==0||i%5==0)continue;
		sum+=i;
	}
	cout<<sum<<'\n';
	return 0;
}




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

int main() {
    int mod=1e9+7;
    int n;cin>>n;
    int a[n],b[n];
    cin>>a[0];
    b[0]=a[0];
    for (int i=1;i<n;i++) {
        cin>>a[i];
        b[i]=(b[i-1]+a[i])%mod;
    }
    int ans=0;
    for (int i=1;i<n;i++)
        ans=(ans+(ll)a[i]*b[i-1])%mod;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 5188
def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()
    
    array_result.append(data.split(" "))

    flg = 1

    try:

        while flg:

            data = input()
            if(data != ""):
                
                array_result.append(data.split(" "))

            else:

                flg = 0
    finally:

        return array_result

arr_data = getinputdata()

s= arr_data[0][0]
w= int(arr_data[1][0])

result=[s[i] for i in range(0,len(s),w)]

print("".join(result))

    

Measured memory_bytes: 3064
//#pragma optimization_level 3
#include <bits/stdc++.h>
#define  f               first
#define  s               second
#define  sym(s)          s = "#" + s + "#";
#define  all(x)          (x).begin(), (x).end()
#define  alll(x,n)       x+1, x+n+1
#define  newl            cout<<"\n";
#define  foo(i,a,n)      for(ll i = (a); i <= n; i++)
#define  deb1(a)         cout<<a<<"\n";
#define  deb2(a,b)       cout<<a<<" "<<b<<"\n";
#define  deb3(a,b,c)     cout<<a<<" "<<b<<" "<<c<<"\n";
#define  deb4(a,b,c,d)   cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n";
#define  debp(a)         cout<<a.f<<" "<<a.s<<"\n";
#define  debv(a)         for(auto it: a)cout<<it<<" ";newl;
#define  debm(a)         for(auto it: a)cout<<"{"<<it.f<<","<<it.s<<"}, ";newl;
#define  deb1d(a,n)      foo(i,1,n)cout<<a[i]<<" ";newl;
#define  deb2d(a,n,m)    foo(i,1,n){foo(j,1,m){cout<<a[i][j]<<" ";}newl;}

using namespace std;
using ll              =  long long;
using ld              =  long double;
const ll   MOD        =  1e+9 + 7;
const ll   INF        =  LLONG_MAX;
const int  N          =  (int)1e+6 + 8;

ll n, m, k;
ll x, y;
ll cx[N], cy[N];
set<pair<int, int>> pts;
vector<ll> r[N];

void MAIN(int tc) {
    cin >> n >> m >> k; 
    for(int i = 1; i <= k; i++){
        cin >> x >> y;
        r[x].push_back(y);
        cx[x] += 1;
        cy[y] += 1;
    }

    ll mxy = 0;
    for(int i = 1; i <= N - 1; i++) {
        sort(all(r[i]));
        mxy = max(mxy, cy[i]);
    }

    set<ll> besty;
    for(int i = 1; i <= N - 1; i++) {
        if(mxy == cy[i]){
            besty.insert(i);
        }
    }

    ll res = 0;
    for(int x = 1; x <= N - 1; x++) {
        ll tr = cx[x];
        ll nop = 0;
        for(auto y: r[x]){
            if(besty.count(y) > 0) nop += 1;
        }
        if(nop < besty.size()) res = max(res, tr + mxy);
        else res = max(res, tr + mxy - 1);
    }

    cout<<res;
}

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

    int test_cases = 1;
    //cin>>test_cases;
    for (int i = 1; i <= test_cases; i++) {
        MAIN(i);
    }
}

Measured memory_bytes: 55168
#include<bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i,k,n) for (ll i = k; i < (ll)(n); ++i)
#define MAX 500000001000000000
#define MOD 1000000007
typedef long long  ll;

using namespace std;

int ans, cnt;

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

	int N, M;
	string s, t;
	map<string, int> m;

	cin >> N;
	rep(i, N) {
		cin >> s;
		m[s]++;
	}
	cin >> M;
	rep(i, M) {
		cin >> t;
		m[t]--;
	}

	for (auto p : m) {
		ans = max(ans, p.second);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SIZE 12
#define BT (1<<10)
#define MOD 998244353
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

char mp[SIZE][SIZE];
int dp[SIZE][SIZE];
int dp2[SIZE][SIZE];
int C[SIZE][SIZE];
int bit[SIZE];
int bit2[SIZE];
int rt[SIZE];

void make()
{
	for(int i=0;i<SIZE;i++)
	{
		C[i][i]=C[i][0]=1;
		for(int j=1;j<i;j++) C[i][j]=(C[i-1][j-1]+C[i-1][j])%MOD;
	}
	rt[0]=1;
	for(int i=1;i<SIZE;i++) rt[i]=rt[i-1]*2%MOD;
	//dp[0][0]=1;
	for(int i=0;i<SIZE;i++) for(int j=0;j<SIZE;j++) if(i==0||j==0) dp[i][j]=1;
	for(int i=1;i<SIZE;i++)
	{
		for(int j=1;j<SIZE;j++)
		{
			dp[i][j]=0;
			for(int k=1;k<=i;k++)
			{
				ll way=C[i][k]*rt[k]%MOD*(ll) dp[i-k][j]%MOD;
				if(k%2==0) way=MOD-way;
				dp[i][j]+=way;
				if(dp[i][j]>=MOD) dp[i][j]-=MOD;
			}
			for(int k=1;k<=j;k++)
			{
				ll way=C[j][k]*rt[k]%MOD*(ll) dp[i][j-k]%MOD;
				if(k%2==0) way=MOD-way;
				dp[i][j]+=way;
				if(dp[i][j]>=MOD) dp[i][j]-=MOD;
			}
			for(int k=1;k<=i;k++)
			{
				for(int l=1;l<=j;l++)
				{
					ll way=C[i][k]*C[j][l]%MOD*(ll) dp[i-k][j-l]%MOD*2LL%MOD;
					if((k+l)%2==0) way=MOD-way;
					dp[i][j]+=way;
					if(dp[i][j]>=MOD) dp[i][j]-=MOD;
				}
			}
		}
	}
	
	for(int i=0;i<SIZE;i++) for(int j=0;j<SIZE;j++) if(i==0||j==0) dp2[i][j]=rt[i+j];
	for(int i=1;i<SIZE;i++)
	{
		for(int j=1;j<SIZE;j++)
		{
			dp2[i][j]=0;
			for(int k=1;k<=i;k++)
			{
				ll way=C[i][k]*rt[k]%MOD*(ll) dp2[i-k][j]%MOD;
				if(k%2==0) way=MOD-way;
				dp2[i][j]+=way;
				if(dp2[i][j]>=MOD) dp2[i][j]-=MOD;
			}
			for(int k=1;k<=j;k++)
			{
				ll way=C[j][k]*rt[k]%MOD*(ll) dp2[i][j-k]%MOD;
				if(k%2==0) way=MOD-way;
				dp2[i][j]+=way;
				if(dp2[i][j]>=MOD) dp2[i][j]-=MOD;
			}
			for(int k=1;k<=i;k++)
			{
				for(int l=1;l<=j;l++)
				{
					ll way=C[i][k]*C[j][l]%MOD*(ll) dp2[i-k][j-l]%MOD*2LL%MOD;
					if((k+l)%2==0) way=MOD-way;
					dp2[i][j]+=way;
					if(dp2[i][j]>=MOD) dp2[i][j]-=MOD;
				}
			}
		}
	}
}
int main()
{
	make();
	int n,m;
	scanf("%d %d",&n,&m);
	for(int i=0;i<n;i++)
	{
		scanf("%s",&mp[i]);
		for(int j=0;j<m;j++) if(mp[i][j]=='#') bit[i]|=(1<<j),bit2[j]|=(1<<i);
	}
	int ret=dp[n][m];
	for(int S=1;S<(1<<n);S++)
	{
		for(int T=1;T<(1<<m);T++)
		{
			bool up=true;
			for(int i=0;i<n;i++)
			{
				if(S>>i&1)
				{
					if((T&bit[i])==T||(((1<<m)-bit[i]-1)&T)==T)
					{
						//if(S==3&&T==3) printf("%d\n",i);
						up=false;
					}
				}
			}
			for(int i=0;i<m;i++)
			{
				if(T>>i&1)
				{
					if((S&bit2[i])==S||(((1<<n)-bit2[i]-1)&S)==S)
					{
						//if(S==3&&T==3) printf("%d\n",i);
						up=false;
					}
				}
			}
			if(up)
			{
				int w=0,h=0;
				for(int i=0;i<n;i++) if(S>>i&1) w++;
				for(int j=0;j<m;j++) if(T>>j&1) h++;
				//printf("%d %d : %d\n",w,h,dp[n-w][m-h]);
				ret+=dp2[n-w][m-h];
				if(ret>=MOD) ret-=MOD;
			}
		}
	}
	printf("%d\n",ret);
	return 0;
}

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

#define ALL(a)  (a).begin(),(a).end()

int main(){
  int N; cin >> N;
  string S; cin >> S;
  S.erase(unique(ALL(S)),S.end());
  cout << S.size() << endl;
  return 0;
}


Measured memory_bytes: 3744
private data class City(var index: Int = 0, var prov: Int = 0, var year: Int = 0, var label: String = "")

fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(" ").map { it.toInt() }

    // 市 i ( 0 ~ m) y 年に誕生し， n この内の一つ p 県に属する
    // y はすべて異なる
    // すべての市に認識番号を振る
    // ・ p(6桁 0 埋め) + pの中での x 番目(6桁0埋め）

    // すべて入れたらソートでOK or 優先度付き tree にする？
    // 出力は入れた順番で

    // ソートした後に何番目のものが表示対象だったか覚えておかなくてはいけないか

    // キューを作っておくか
    // すべてのデータを 県番号 -> 県内での年数　でソート， -> 認識番号付与 -> 入力番号でソート -> 出力

    // 方針の妥当性： MlogM + M + MlogM, M<10^5 -> 10^6 くらい
    // TLE: 2119 ms 方針はあっているが実装としてどこか余計な部分が存在
    // 1. 出力を joinToString したことで若干早くなったがまだ足りない
    // 2. ソートを全体で行うのではなく個別に行うようにする？？ -> 出力順を入力順に戻すにはどうすればよいか？？ -> flatMap & sort で？？
//
//    val d = Array(m) {City()}
//    for ( i in 0 until m) {
//        val (p, y) = readLine()!!.split(" ").map { it.toInt() }
//        d[i].index = i
//        d[i].prov = p
//        d[i].year = y
//    }
//
//    d.sortBy { it.year }
//
//    val ord = Array(n+1){0}
//
//    for ( c in d) {
//        ord[c.prov] += 1
//        c.label = "%06d%06d".format(c.prov, ord[c.prov])
//    }
//
//    d.sortBy { it.index } // ここのソートを無くすことはできないか？？
//
//    println(d.map { it.label }.joinToString("\n"))

    val d = Array(n) { mutableListOf<City>() }
    for (i in 0 until m) {
        val (p, y) = readLine()!!.split(" ").map { it.toInt() }
        d[p - 1].add(City(index = i, year = y))
    }

    for ( i in 0 until n) {
        d[i].sortBy{ it.year }
        for ( j in 0 until d[i].size) {
            d[i][j].label = "%06d%06d".format(i+1, j+1)
        }
    }

    val ans = d.toMutableList().flatten().sortedBy { it.index }

    println(ans.map { it.label }.joinToString("\n"))
}

Measured memory_bytes: 144344
(let* ((W (read))
       (a (read))
       (b (read))
       (lst1 (cons a (+ a W)))
       (lst2 (cons b (+ b W))))

  (format t "~A~%"
          (cond ((< (cdr lst1) (car lst2)) (- (car lst2) (cdr lst1)))
                ((< (cdr lst1) (car lst2)) 0)
                ((< (car lst1) (cdr lst2)) 0)
                (t (- (car lst1) (cdr lst2))))))


Measured memory_bytes: 11492
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define si(X) scanf("%d", &(X))
#define sll(X) scanf("%lld",&(X))
#define INFL 0x3f3f3f3f3f3f3f3fLL
const ll mod = 1e9 + 7;

ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll expo(ll base,ll pow){ll ans = 1;
   while(pow!=0){if(pow&1==1){ans = ans*base;ans = ans%mod;}
   base *= base;base%=mod;pow/=2;}return ans;}
ll inv(ll x){return expo(x,mod-2);}
int dx[8] = {1 , 0 , -1 , 0 , 1 , -1 , -1 , 1};    // last 4 diagonal
int dy[8] = {0 , 1 , 0 , -1 , 1 , 1 , -1 , -1};
/*---------------------------------------------------------------------------------------------------------------------*/

const int M = 2e5 + 5;

ll dp[M];
int arr[M];

int main(){

	int n;
	si(n);

	string str;
	cin >> str;

    dp[0] = 1;
    arr[str[0] - 'a'] = 1;
    ll ans = 1;

	for(int i = 1 ; i < n ; i++){
        int id = str[i] - 'a';

        ll temp = 1;
        for(int j = 0 ; j < 26 ; j++){
            if(j == id) continue;
            //cout<<j<<"  "<<arr[j]<<endl;
            temp *= (1 + arr[j]);
            temp %= mod;
        }
        dp[i] = temp;
        arr[id] ++;

        ans += dp[i];
        ans %= mod;

	}


	cout<<ans;





}






































Measured memory_bytes: 1280
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define EACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
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; }
template<class Value>using vec = vector< Value >;
using ll = long long;
using P = pair< long long, long long >;
#define fi first
#define se second
#define el endl
#pragma endregion

void Main();

int main(){
    std::cin.tie(nullptr);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}

void Main(){
    int N;
    cin >> N;
    vec<ll> X(N+1);
    vec<ll> SX(N+1);
    FOR(i, N, 0){
        cin >> X[i];
        SX[i] = X[i];
    }
    sort(ALL(SX));
    int D1 = SX[N/2];
    int D2 = SX[N/2+1];
    REP(i, N){
        if(X[i]>D1){
            cout << D1 << el;
        }else{
            cout << D2 << el;
        }
    }

}



Measured memory_bytes: 5376
#include <stdio.h>

int main(void)
{
	int num;
	char ope[2];
	int result;
	
	scanf("%d", &result);
	while (1) {
		scanf("%s", ope);
		
		if (ope[0] == '='){
			break;
		}
		
		scanf("%d", &num);
		
		switch (ope[0]){
		  case '+':
		     result += num;
			 break;
			 
		  case '-':
		     result -= num;
			 break;

		  case '*':
		     result *= num;
			 break;

		  case '/':
		     result /= num;
			 break;
		}
	}
	printf("%d\n", result);
	return (0);
}

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

N = int(input())
aN = list(map(int, input().split()))

sum1 = 0
cnt1 = 0
for i in range(N):
    sum1 += aN[i]
    if i % 2 == 0:
        if sum1 >= 0:
            tmp = abs(sum1) +1
            cnt1 += tmp
            sum1 -= tmp
    else:
        if sum1 <= 0:
            tmp = abs(sum1) +1
            cnt1 += tmp
            sum1 += tmp

sum1 = 0
cnt2 = 0
for i in range(N):
    sum1 += aN[i]
    if i % 2 == 1:
        if sum1 >= 0:
            tmp = abs(sum1) +1
            cnt2 += tmp
            sum1 -= tmp
    else:
        if sum1 <= 0:
            tmp = abs(sum1) +1
            cnt2 += tmp
            sum1 += tmp

# 開始を偶奇それぞれでやって、良かった方を出力
print(min(cnt1, cnt2))

Measured memory_bytes: 14468
import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mat = lambda x, y, v: [[v]*y for _ in range(x)]
ten = lambda x, y, z, v: [mat(y, z, v) for _ in range(x)]
mod = 1000000007
sys.setrecursionlimit(1000000)

N, M = rl()
A = rl()
Q = []
for i in range(M):
	b, c = rl()
	Q.append((b, c))

A.sort()
Q = sorted(Q, key=lambda x: -x[1])

ans = 0
cur = 0
for b, c in Q:
	j = bisect_left(A, c)
	if j <= cur: continue
	n = min(j-cur, b)
	ans += n*c
	cur += n
if cur < N:
	ans += sum(A[cur:])
print(ans)



Measured memory_bytes: 92988
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * Created by darshan on 5/29/19.
 */
public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
        StringTokenizer st;

        int n = Integer.parseInt(br.readLine());
        int size = 1 << n;
        st = new StringTokenizer(br.readLine());
        int[][] maxPair = new int[size][2];
        for (int i = 0; i < size; i++) {
            maxPair[i][0] = Integer.parseInt(st.nextToken());
        }

        for (int i = 0; i < n; i++) {
            int twoPowerI = 1 << i;
            for (int j = 0; j < size; j++) {
                if ((j & twoPowerI) != twoPowerI) {
                    merge(maxPair[j], maxPair[j | twoPowerI]);
                }
            }
        }

        int max = 0;
        for (int i = 1; i < size; i++) {
            max = Math.max(max, maxPair[i][0] + maxPair[i][1]);
            out.println(max);
        }
        out.close();
    }

    private static void merge(int[] from, int[] to) {
        int[] temp = new int[4];
        temp[0] = from[0];
        temp[1] = from[1];
        temp[2] = to[0];
        temp[3] = to[1];
        Arrays.sort(temp);
        to[0] = temp[3];
        to[1] = temp[2];
    }
}


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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif

    ll N, T;
    cin >> N >> T;
    Vl t(N);
    for (ll i = 0; i < N; i++) {
        cin >> t[i];
    }

    ll ans = T;
    for (ll i = 1; i < N; i++) {
        if (t[i] - t[i - 1] >= T)
            ans += T;
        else {
            ans += t[i] - t[i - 1];
        }
    }

    cout << ans << "\n";

    return 0;
}

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

int main() {
  string s;
  cin >> s;
  if(s[1]=='B') cout << "ARC" << endl;
  else cout << "ABC" << endl; 
  return 0;
  
}

Measured memory_bytes: 3624
//D
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;

    void calc()
    {
        cin = new Scanner();
        long A, B;
        A = cin.nextLong();
        B = cin.nextLong();
        Console.WriteLine(solve(A, B));
    }

    //bool debug = true;

    Dictionary<long, long> dic = new Dictionary<long, long>();

    long solve(long A, long B)
    {
        int pos = 60;
        long ans = 0;

        while (pos >= 0)
        {
            if ((A >> pos) % 2 != (B >> pos) % 2) break;
            pos--;
        }
        if (pos < 0)
        {
            //if (debug) Console.WriteLine(A + " " + B + " " + 1);
            return 1;
        }
        if(pos == 0)
        {
            //if (debug) Console.WriteLine(A + " " + B + " " + 2);
            return 2;
        }

        A %= (1L << (pos));
        B %= (1L << (pos));

        int pos2 = 60;
        while (pos2 >= 0)
        {
            if ((B >> pos2) % 2 == 1) break;
            pos2--;
        }

        long low = A;
        long high = (1L << (pos2 + 1));

        ans += (1L << pos) - low;
        if (high > low) ans += (1L << pos);
        else ans += high + (1L << pos) - low;

        return ans;
    } 
}


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();

        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

}

Measured memory_bytes: 13268
import scala.io.StdIn.readLine
import scala.collection.mutable.ArrayBuffer

object Main {
  def main(args:Array[String]) = {
    var n = 0
    val b = new ArrayBuffer[String]
    while({n=readLine.trim.toInt;n}!=0) {
      val a = Array.ofDim[Int](n,n)
      var (i,j,m) = (n/2+1,n/2,1)
      a(i)(j) = m
      m += 1
      i += 1
      j += 1
      while(m<=n*n) {
        if(j>=n) j=0 else if(j<0) j=n-1
        if(i>=n) i=0
        if(a(i)(j)!=0) {
          i += 1
          j -= 1
        } else {
          a(i)(j) = m
          m += 1
          i += 1
          j += 1
        }
      }
      b+=a.map(s=>s.map("%4d".format(_)).mkString).mkString("\n")
    }
    println(b.mkString("\n"))
  }
}

Measured memory_bytes: 45572