akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
using namespace std;

int main() {
    string s;
    cin >> s;
    int n = s.length();
    vector <int> ans(n, 1);
    vector <int> des(n, 0);
    for (int i = 0; i < n; i++) {
        des[i] = i;
    }
    int L = n - 1;
    for (int i = n - 1; i >= 0; i--) {
        if (s[i] == 'L') {
            L = i;
        } else {
            des[i] = L;
        }
    }
    int R = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'R') {
            R = i;
        } else {
            des[i] = R;
        }
    }
    for (int i = 0; i < n; i++) {
        if (abs(des[i] - i) % 2 == 0) {
            ans[des[i]]++;
            ans[i]--;
        } else {
            ans[i]--;
            if (s[i] == 'L') {
                ans[des[i] + 1]++;
            } else {
                ans[des[i] - 1]++;
            }
        }
    }
    for (int i = 0; i < n; i++) {
        cout << ans[i] << " ";
    }
    return 0;
}


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

unsigned xor128() {
	static unsigned x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	unsigned t = x ^ (x << 11);
	x = y; y = z; z = w;
	return w = w ^ (w >> 19) ^ (t ^ (t >> 8));
}

namespace randomized_binary_search_tree
{
	using T = ll;
	const T id = 0;
	T op(T l, T r) {
		return l + r;
	}

	struct node {
		T val, all;
		node *lch, *rch;
		int size;
		node(T v, node* l = nullptr, node* r = nullptr)
			: val(v), all(v), lch(l), rch(r), size(1) {}
	};

	int count(node *t) { return t ? t->size : 0; }
	T que(node *t) { return t ? t->all : id; }

	node *update(node *t) {
		t->size = count(t->lch) + count(t->rch) + 1;
		t->all = op(op(que(t->lch), t->val), que(t->rch));
		return t;
	}
	node *merge(node *l, node *r) {
		if (!l || !r) return !l ? r : l;
		if (xor128() % (l->size + r->size) < (unsigned)l->size) {
			l->rch = merge(l->rch, r);
			return update(l);
		}
		r->lch = merge(l, r->lch);
		return update(r);
	}
	pair<node*, node*> split(node *t, int k) {
		if (!t) return make_pair(nullptr, nullptr);
		if (k <= count(t->lch)) {
			pair<node*, node*> s = split(t->lch, k);
			t->lch = s.second;
			return make_pair(s.first, update(t));
		}
		pair<node*, node*> s = split(t->rch, k - count(t->lch) - 1);
		t->rch = s.first;
		return make_pair(update(t), s.second);
	}
	node *insert(node *t, int k, T v) {
		pair<node*, node*> s = split(t, k);
		node *r = merge(s.first, new node(v));
		r = merge(r, s.second);
		return r;
	}
	void update_val(node *t, int k, T v) {
		if (!t) return;
		int c = count(t->lch);
		if (k < c)
			update_val(t->lch, k, v);
		else if (k > c)
			update_val(t->rch, k - (c + 1), v);
		else
			t->val = v;
		t->all = op(op(que(t->lch), t->val), que(t->rch));
	}
	T find(node *t, int l, int r) {
		if (!t) return id;
		if (r <= 0 || count(t) <= l) return id;
		if (l <= 0 && count(t) <= r) return t->all;
		int c = count(t->lch);
		return op(find(t->lch, l, r), op(l <= c && c < r ? t->val : id, find(t->rch, l - (c + 1), r - (c + 1))));
	}
	int count_lower(node *t, T v) {
		if (!t) return 0;
		if (t->val < v) return count(t->lch) + 1 + count_lower(t->rch, v);
		if (t->val == v) return count(t->lch);
		return count_lower(t->lch, v);
	}
}

using namespace randomized_binary_search_tree;

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int Q;
	cin >> Q;
	node *tree = nullptr;
	ll off = 0;
	int sz = 0;
	while (Q--) {
		int com;
		cin >> com;
		if (com == 1) {
			int a, b;
			cin >> a >> b;
			off += b;
			tree = insert(tree, count_lower(tree, a), a);
			++sz;
		}
		else {
			int p = (sz - 1) / 2;
			ll v = find(tree, p, p + 1);
			ll ls = find(tree, 0, p + 1);
			ll rs = find(tree, p + 1, sz);
			ll val = v * (p + 1) - ls + rs - (v * (sz - p - 1)) + off;
			cout << v << ' ' << val << '\n';
		}
	}
	return 0;
}


Measured memory_bytes: 9600
open System

let input() =
    Console.ReadLine().Split()
    |> Array.toList
    |> List.map int32

let interval a b = seq { a..(b - 1) }

[<EntryPoint>]
let main argv =
    let [ N; x ] = input()
    let mutable a = input() |> List.toArray
    let mutable ans = 0L
    if a.[0] > x then
        ans <- int64 (a.[0] - x)
        a.[0] <- x
    for i in interval 0 (N - 1) do
        if a.[i] + a.[i + 1] > x then
            ans <- ans + int64 (a.[i + 1] + a.[i] - x)
            a.[i + 1] <- x - a.[i]
    printfn "%d" ans
    0 // return an integer exit code


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

using namespace std;

using ll = long long;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORE(i, a, b) for (int i = (a); i <= (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repe(i, n) for (int i = 0; i <= (n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define SP cout << fixed << setprecision(10)
typedef pair<int, int> P;
const int inf = (int)1e9;
const int mod = (int)1e9 + 7;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

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

    int p, q, r;
    cin >> p >> q >> r;

    cout << p + q + r - max(p, max(q, r)) << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*; 
import java.io.*;
 
class Main {
 
  /*public static String StringPeriods(String str) {
    boolean flag = false;
    String ans = "";
    for(int i=0;i<str.length();i++){
      String temp = str;
      String substr = str.substring(0,i);
      temp = temp.replaceAll(substr, "");
      if(temp.equals("")) {
    	  flag = true;
    	  ans = substr;
    	  break;
      }
    }
    if(flag) {
    	str = ans;
    }else {
    	str = "-1";
    }
    // code goes here  
    return str;
  }*/
 
  public static void main (String[] args) {  
    // keep this function call here     
    Scanner sc = new Scanner(System.in);
   int N=sc.nextInt();
   Map<Integer,Integer> map = new HashMap<Integer,Integer>();
   int[] A= new int[N];
   for(int i=0;i<N;i++) {
	   A[i]=sc.nextInt();
	   if(!map.containsKey(A[i])) {
		   map.put(A[i],1);
	   }else {
		   map.put(A[i],map.get(A[i])+1);
	   }
   }
   long anstemp = 0;
   for(Integer key:map.keySet()) {
	   long v = map.get(key);
	   anstemp+=(v*(v-1)/2);
	}
   for(int i=0;i<N;i++) {
	   long ans = anstemp;
	   long v = map.get(A[i]);
	   ans -= (v*(v-1)/2);
	   ans += ((v-1)*(v-2)/2);
	   System.out.println(ans);
   }
   
  }
}

Measured memory_bytes: 108512
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

int rsum,lsum,dis;
int a[100050];
string str;

void solve(int sum)
{
    a[dis+rsum-1]=a[dis+rsum]=sum/2;
    if(sum%2==1){
        if(lsum>rsum){
            a[dis+rsum]++;
        }
        else{
            a[dis+rsum-1]++;
        }
        int Max=max(lsum,rsum);
        if(Max%2==0)
            swap(a[dis+rsum],a[dis+rsum-1]);
    }
}
int main()
{
    rsum=0,lsum=0,dis=0;
    getline(cin,str);
    int len=str.length();//cout<<len<<endl;
    fill(a,a+len,0);
    str+="s";//cout<<str<<endl;
    for(int i=0;i<len;i++)
    {
        if(str[i]=='R')
            rsum++;
        if(str[i]=='L'){
            lsum++;
            if(str[i+1]!='L')
            {
                solve(rsum+lsum);
                rsum=0;lsum=0;dis=i+1;
            }
        }


    }
    for(int i=0;i<len;i++){
        if(i)
            cout<<" ";
        cout<<a[i];
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 1024
import java.io._
import java.util.StringTokenizer

import scala.collection.mutable
import scala.util.Sorting
import math.{abs, max, min}
import scala.collection.mutable.{ArrayBuffer, ListBuffer}
import scala.reflect.ClassTag

object Main {
  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val sc = new InputReader(System.in)
    val x, y = sc.nextInt()

    def sign(a: Int) = a >= 0

    val ans = if (x < y && sign(x) == sign(y)) y - x
    else if (x < 0 && y == 0) -x
    else if (x > 0 && y == 0) x + 1
    else if (sign(x) != sign(y)) abs(abs(y) - abs(x)) + 1
    else abs(abs(y) - abs(x)) + 2

    out.println(ans)
  }

  def main(args: Array[String]): Unit = {
    solve()
    out.flush()
  }


  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  def rep(n: Int)(f: Int => Unit): Unit = {
    var i = 0
    while(i < n) { f(i); i += 1 }
  }
  def rep_r(n: Int)(f: Int => Unit): Unit = {
    var i = n - 1
    while(i >= 0) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    rep(n)(i => res(i) = f(i))
    res
  }

  implicit class ArrayOpts[A](val as: Array[A]) extends AnyVal {
    // todo Orderingだとboxing発生するので自作Orderを用意したい
    def maxByOpt[B: Ordering](f: A => B): Option[A] = {
      if (as.nonEmpty) Some(as.maxBy(f)) else None
    }

    def grpBy[K](f: A => K): mutable.Map[K, ArrayBuffer[A]] = {
      val map = mutable.Map.empty[K, ArrayBuffer[A]]
      rep(as.length)(i => map.getOrElseUpdate(f(as(i)), ArrayBuffer()) += as(i))
      map
    }

    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      var sum = num.zero
      rep(as.length)(i => sum = num.plus(sum, f(as(i))))
      sum
    }

    def minByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {
      limit(f, ixRange)(cmp.lt)
    }

    def maxByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {
      limit(f, ixRange)(cmp.gt)
    }

    private def limit[B](f: A => B, ixRange: Range)(cmp: (B, B) => Boolean): (A, B) = {
      var limA = as(ixRange.head)
      var limB = f(limA)

      for (i <- ixRange.tail) {
        val a = as(i)
        val b = f(a)
        if (cmp(b, limB)) {
          limA = a
          limB = b
        }
      }
      (limA, limB)
    }
  }

  implicit class IterableOpts[A](val as: Iterable[A]) extends AnyVal {
    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      as.foldLeft(num.zero)((acc, a) => num.plus(acc, f(a)))
    }
  }
}


Measured memory_bytes: 26696
#include <iostream>
#include <queue>
#include <utility>
using namespace std;

const int INF = 1e9 + 7;
const int K = 1e5;
int dp[K];

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

	int k;
	cin >> k;
	for (int i = 0; i < k; ++i) dp[i] = INF;

	priority_queue<pair<int, int>> que;
	dp[1] = 1;
	que.push({-1, 1});

	while(! que.empty()) {
		auto pr = que.top();
		que.pop();
		int c = -pr.first;
		int v = pr.second;
		if (dp[v] < c) continue;
		
		int t = (10 * v) % k;
		if (dp[t] > c) {
			dp[t] = c;
			que.push({-c, t});
		}

		t = (t + 1) % k;
		if (dp[t] > c+1) {
			dp[t] = c+1;
			que.push({-(c+1), t});
		}
	}

	cout << dp[0] << '\n';
}

Measured memory_bytes: 1276
import math
import itertools

INF = 10**9+7

n,k = map(int,input().split())
ab = {}
for i in range(1,int(10e5+1)):
	ab[i] = 0
for i in range(n):
	a,b = map(int,input().split())
	ab[a] += b

def solve():
	global n,k,ab
	for ky,v in ab.items():
		if(v<k): k -= v
		else: return ky

def sgn(n):
	if(n>0): return 1
	if(n<0): return -1
	return 0

print(solve())

Measured memory_bytes: 99036
PROGRAM ATCODER
implicit none
character(len=10) :: s, ans
character :: a,b
integer :: i,len
  
read(*,*) s

ans = ""
a = "0"
b = "1"

len = len_trim(s)
do i = 1, len
	if (s(i:i) == a) then
    	ans = trim(ans) // a
    else if(s(i:i) == b) then
    	ans = trim(ans) // b
    else if(s(i:i) == "B") then
        ans = ans(1:len_trim(ans)-1)
    end if
end do

write(*,'(a)') trim(ans)

END PROGRAM ATCODER

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

int GCD(int a, int b)
{
    int r = a % b;
    while (r != 0)
    {
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

int main(void)
{
    int k, p[200];
    int ans = 0, dig;
    scanf("%d", &k);

    for (int i = 1; i <= k; i++)
        for (int j = 1; j <= k; j++)
            for (int h = 1; h <= k; h++)
                ans += GCD(GCD(i, j), h);

    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 1692
def main():
    H, W = (int(i) for i in input().split())
    c = [input() for j in range(H)]
    from collections import deque
    dist = [[-1]*W for i in range(H)]

    def bfs(sy, sx):
        que = deque()
        dist[sy][sx] = 0
        que.append((sy, sx))
        d = ((1, 0), (0, 1), (-1, 0), (0, -1))
        while que:
            uy, ux = que.popleft()
            for dy, dx in d:
                next_y = uy + dy
                next_x = ux + dx
                if not(0 <= next_y < H and 0 <= next_x < W):
                    continue
                if dist[next_y][next_x] != -1:
                    continue
                if c[next_y][next_x] == '#':
                    continue
                dist[next_y][next_x] = dist[uy][ux] + 1
                que.append((next_y, next_x))

    bfs(0, 0)
    if dist[H-1][W-1] == -1:
        return print(-1)
    ans = H*W - (dist[H-1][W-1] + 1)
    for h in range(H):
        for w in range(W):
            if c[h][w] == "#":
                ans -= 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 40304
using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int numberof2 = 0;
            var integer = int.Parse(Console.ReadLine());
            if (integer < 1000 || 9999 < integer)
            {
                Console.WriteLine("ERROR: Please input the number from 1000 to 9999.");
                return;
            }
            for (var digit = 0; digit < 4; digit++)
            {
                if (integer % 10 == 2)
                {
                    numberof2++;
                }
                integer /= 10;
            }
            Console.WriteLine("{0}", numberof2);
        }
    }
}


Measured memory_bytes: 11092
n,m=map(int,input().split())
arr=[list(map(int,input().split())) for _ in range(m)]
if n==1:
  for i in range(10):
    tmp=str(i)
    flag=True
    for j in range(m):
      if tmp[arr[j][0]-1]!=str(arr[j][1]):
        flag=False
    if flag==True:
      print(i)
      break
  else:
    print(-1)
else:
  for i in range(10**(n-1),10**n):
    tmp=str(i)
    flag=True
    for j in range(m):
      if tmp[arr[j][0]-1]!=str(arr[j][1]):
        flag=False
    if flag==True:
      print(i)
      break
  else:
    print(-1)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <queue>
using namespace std;

int main() {
  int h, w;
  cin >> h >> w;
  string s[h];
  for (int i = 0; i < h; i++) {
    cin >> s[i];
  }
  int dx[4] = {-1, 1, 0, 0};
  int dy[4] = {0, 0, -1, 1};
  queue<pair<int, int>> q;
  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#') continue;
      vector<vector<int>> dist(h, vector<int>(w, -1));
      dist[i][j] = 0;
      q.push(make_pair(i, j));
      while (!q.empty()) {
        int x = q.front().first;
        int y = q.front().second;
        int c = dist[x][y];
        q.pop();
        for (int k = 0; k < 4; k++) {
          int kx = x+dx[k];
          int ky = y+dy[k];
          if (kx<0 || kx>=h || ky<0 || ky>=w) continue;
          if (dist[kx][ky] < 0 && s[kx][ky] == '.') {
            dist[kx][ky] = c+1;
            ans = max(ans, c+1);
            q.push(make_pair(kx, ky));
          }
        }
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
N,M = map(int,input().split())
Ai = list(map(int,input().split()))
Ai.sort(reverse=True)

tot = sum(Ai)
thre = tot/(4*M)

flag = 1
for i in range(M):
  if(Ai[i]<thre):
    flag=0
    break;

if(flag):
  print('Yes')
else:
  print('No')


Measured memory_bytes: 38448
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
A3 = list(map(int, input().split()))
N = int(input())
B = []
for n in range(N):
    B.append(int(input()))
ans='No'

def judge(A, B):
    for i in range(3): 
        if A[i] in B:
            A[i] = 1
        else:
            A[i] = 0

judge(A1, B)
judge(A2, B)
judge(A3, B)

if sum(A1)==3 or sum(A2)==3 or sum(A3)==3:
    ans = 'Yes' 
for i in range(3):
    if A1[i] + A2[i] + A3[i] == 3:
        ans = 'Yes'
if A1[0] + A2[1] + A3[2] == 3 or A1[2] + A2[1] + A3[0] == 3:
    ans = 'Yes'

print(ans)


Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main()
{
    int A ,B ,n,o,c;
    cin >> A >> B ;
    n= A+B ;
    o= A-B ;
    c=A*B ;
    if (n>=o && n >=c)
        cout << n << endl ;
    else if (o>=n && o>=c)
        cout << o<< endl ;
    else 
        cout << c << endl ;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

vector<vector<int>> G;
int cnt = 0;
void dfs(int cur, int par, int s, int g) {
//    cout << "dfs:" << cur << endl;
    if(cur == g) {
        cnt++;
        return;
    }
    for(int v: G[cur]) {
        if(par != v) {
            if(v == s) return;
            dfs(v, cur, s, g);
        }
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int N, M;
    cin >> N >> M;
    G.resize(N);
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].pb(b);
        G[b].pb(a);
    }
    int six = 0;
    int four = 0;
    vector<int> F;
    rep(i, N) {
        if(G[i].size() % 2 == 1) {
            output("No");
            return 0;
        }
        if(G[i].size() >= 6) {
            six++;
            four++;
        }
        else if(G[i].size() >= 4) {
            four++;
            F.pb(i);
        }
    }
    if(six == 0 && four == 2) {
        int s = F[0];
        int g = F[1];
        for(int v: G[s]) {
            dfs(v, s, s, g);
        }
//        output(cnt);
        if(cnt == 4) {
            output("No");
            return 0;
        }
    }
    if(six >= 1 || four >= 2){
        output("Yes");
    }
    else {
        output("No");
    }
    
    return 0;
}


Measured memory_bytes: 7296
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

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

    ll a[n];
    rep(i, 0, n){
        cin >> a[i];
    }

    ll sum[n + 1];
    ll sum_p[n + 1];
    sum[0] = 0;
    sum_p[0] = 0;
    rep(i, 1, n + 1){
        sum[i] = sum[i - 1] + a[i - 1];
        sum_p[i] = sum_p[i - 1];
        if(a[i - 1] >= 0){
            sum_p[i] += a[i - 1];
        }
    }

    ll ans = 0;
    rep(i, 0, n - k + 1){
        ans = max(sum_p[n] - (sum_p[i + k] - sum_p[i]), ans);
        ans = max(sum_p[n] - (sum_p[i + k] - sum_p[i]) + (sum[i + k] - sum[i]), ans);
    }

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


Measured memory_bytes: 2688
//大文字->小文字 tolower(),逆はtoupper()
//int a = stoi(c); 文字列をintへ
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
//stack<ll> s;
//s.push(要素);s.top();s.pop();
//queue<ll> q;
//q.push(要素);q.front();q.pop();
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// x,yの最大公約数
ll gcd(ll x, ll y) {
	ll r;
	while (x%y) {
		r = x % y;
		x = y;
		y = r;
	}
	return y;
}

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

int main() {
	ll K; cin >> K;
	ll ans = 0;
	for (int a = 1; a <= K; a++) {
		for (int b = 1; b <= K; b++) {
			for (int c = 1; c <= K; c++) {
				ans += gcd(a,gcd(b,c));
			}
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 3636
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
while(1){
int i,j,r,c,cnt,ans=0,sum,l;
static int t[10][10000];
scanf("%d%d",&r,&c);
if(r==0&&c==0)return 0;
for(i=0;i<r;i++){
for(j=0;j<c;j++){
scanf("%d",&t[i][j]);
}
}
for(l=0;l<(1<<r);l++){
sum=0;
for(j=0;j<c;j++){
cnt=0;
for(i=0;i<r;i++){
cnt+=(t[i][j]!=((l>>i)&0x01));
}
sum+=max(r-cnt,cnt);
}
ans=max(ans,sum);
}
printf("%d\n",ans);
}
return 0;
}



Measured memory_bytes: 3528
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  int x[200],y[200];
  x[0]=y[0]=0;
  while(cin>>n,n){
    for(int i=1;i<n;++i){
      int num,d,dx[]={-1,0,1,0},dy[]={0,-1,0,1};
      cin>>num>>d;
      x[i]=x[num]+dx[d];
      y[i]=y[num]+dy[d];
    }
    int maxx=0,minx=10000,maxy=0,miny=10000;
    for(int i=0;i<n;++i){
      maxx=max(maxx,x[i]);
      minx=min(minx,x[i]);
      maxy=max(maxy,y[i]);
      miny=min(miny,y[i]);
    }
    cout<<maxx-minx+1<<" "<<maxy-miny+1<<endl;
  }
  return 0;
}
    

Measured memory_bytes: 3056
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;

int main(){
  int n,m;
  cin >> n >> m;
  if(n%3==0||m%3==0||(n+m)%3==0){
    cout << "Possible" << endl;
  } else {
    cout << "Impossible" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <numeric>
#include <cmath>
#include <cstdlib>

typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

using namespace std;

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

    int year, month, day;

    year = stoi(s.substr(0, 4));
    month = stoi(s.substr(5, 2));
    day = stoi(s.substr(8, 2));

    if (year < 2019 || (year == 2019 && month < 4) || (year == 2019 && month == 4 && day <= 30)) {
        cout << "Heisei" << endl;
    }
    else {
        cout << "TBD" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>

using namespace std;

int main(int argc, char* argv[])
{
  int N;
  cin >> N;
  vector<int> b(4, 0); // initial count of dishes; b[j] is the number of dishes with j sushi
  for (int i=0; i<N; i++) {
    int a;
    cin >> a;
    b[a]++;
  }
  
  // v(i, j, k) = expected number of operation 
  // when remaining are i dishes with 1 sushi, j dishes with 2 and k dishes with 3
  vector< vector< vector<double> > > v(N+1);
  for (int i=0; i<=N; i++) {
    v[i].resize(N+1);
    for (int j=0; j<=N; j++) {
      v[i][j].resize(N+1, 0);
    }
  }
  
  v[0][0][0] = 0;
  for (int k=0; k <= N; k++) {
    for (int j=0; j <= N; j++) {
      for (int i=0; i <= N; i++) {
        if (i + j + k > N) continue; // state that never happens
        if (i==0 && j==0 && k==0) continue;
        double ijk = (double)(i+j+k);
        double tmp = double(N) / ijk;
        if (i > 0) tmp += v[i-1][j][k] / ijk * double(i);
        if (j > 0) tmp += v[i+1][j-1][k] / ijk * double(j);
        if (k > 0) tmp += v[i][j+1][k-1] / ijk * double(k);
        v[i][j][k] = tmp;
      }
    }
  }


  cout << setprecision(16) << v[b[1]][b[2]][b[3]] << "\n";

  return 0;
}


Measured memory_bytes: 216192
#include<stdio.h>

int solve(int,int);

int A[20];
int n;

int main(){
  int q,m,i,j;
  int k[200],M[200];

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }

  scanf("%d",&q);

  for(j=0;j<q;j++){
    scanf("%d",&M[j]);
  }

   for(j=0;j<q;j++){
     if(solve(0,M[j])==1) k[j]=0;
     else k[j]=1;
   }  

  for(j=0;j<q;j++){
    if(k[j]==0) printf("yes\n");
    else printf("no\n");
  }
  
  return 0;
}


  int solve(int i,int m){
    int res;
    if(m==0) return 1;
    if(i>=n) return 0;

    res = solve(i+1,m)|| solve(i+1,m-A[i]);
    return res;
  }

Measured memory_bytes: 580
#
# abc085 a
#
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """2017/01/07"""
        output = """2018/01/07"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """2017/01/31"""
        output = """2018/01/31"""
        self.assertIO(input, output)


def resolve():
    print(input().replace("7", "8", 1))


if __name__ == "__main__":
    # unittest.main()
    resolve()


Measured memory_bytes: 16180
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#include <unistd.h>
#include <stdio.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
//printf("%.10f\n", N);
/*
ll fibo(ll n){
    if(memo[n] != 0)return memo[n];
    if(n <= 1)return n;
    else return memo[n] = fibo(n - 1)+ fibo(n - 2);
}*/
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/
/*
    cout << fixed << setprecision(15);
    */
int main(){
    ll N;
    cin >> N;
    usleep(1998999);
    if(N % 2 == 0)cout << N << endl;
    else cout << 2 * N << endl;
}

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

using namespace std;

map<string, int>mp;
vector<string>v;
vector<vector<int> > pos;
const int N = 20000;
typedef struct psi{
	string first;
	int second;
}psi;

bool operator >(const psi &a, const psi &b){
	
	if(a.first < b.first){

		return true;
	}else if(a.first > b.first){
		return false;
	}
	
	return a.second < b.second;
}

bool operator <(const psi &a, const psi &b){
	return !(a > b);
}

priority_queue<psi>pq;

int main (){
	string s;
	int k;
	
	cin >> s;
	cin >> k;
	
	pos.resize(30);
	
	for(int i = 0 ; i < s.length() ; i++){
		string tmp = "";
		tmp += s[i];
		
		pq.push({tmp, i});	
	}
	
	int taked = 0;
	
	while(taked < k){
		string u = pq.top().first;
		int i = pq.top().second;
		pq.pop();
		
		if(mp[u] == 0)
			taked++;
			
		mp[u] = 1;
		
		if(i < s.length() - 1){
			i++;
			u += s[i]; 
			pq.push({u, i});
		}
		
	}
	
	int cnt = 0;
	
	for(map<string, int>::iterator it = mp.begin() ; it != mp.end() ; it++){
		cnt++;
		
		if(cnt == k){
			cout << it->first << endl;
			break;
		}
	}	
	
	return 0;
}

Measured memory_bytes: 640
//g++  5.4.0

#include <iostream>
#include <vector>
using namespace std;

long long int n;
long long int cnt = 0;
void dfs(long long int num, int has3, int has5, int has7)
{
    if(num > n) return;
    if(has3+has5+has7 == 3){
        //cout << num << endl;
        cnt++;
    }

    dfs(num*10+3, 1, has5, has7);    
    dfs(num*10+5, has3, 1, has7);
    dfs(num*10+7, has3, has5, 1);
}

int main()
{
    cin >> n;
    long long int num = 0;
    dfs(num, 0, 0, 0);
    cout << cnt << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

import numpy as np

L,N = map(int,input().split())
X = np.array([input() for _ in range(N)], dtype=np.int64)

def F(X):
    max_cost = L-X[0]
    # 負方向を初手で、正方向に密
    Xcum = X.cumsum()
    # 等個数ずつとる場合
    M = N//2
    if M > 0:
        arr = 4*Xcum[:M] + 2*L*np.arange(1,M+1) - 2*Xcum[1:2*M+1:2] - X[:M]
        max_cost = max(max_cost, arr.max())
    # 負にn+1個、正にn個
    M = (N-1)//2
    if M > 0:
        arr = (Xcum[:M] + L*np.arange(1,M+1) - Xcum[2:M+M+2:2] + Xcum[1:M+1])*2 - X[1:M+1] + L
        max_cost = max(max_cost,arr.max())
    return max_cost

answer = max(F(X), F(L-X[::-1]))
print(answer)

Measured memory_bytes: 37636
#include<stdio.h>
int main(){
	unsigned short usW_D_set;            	/* 使用できる最大値格納用変数 */
	unsigned long ulW_D_tag;            	/* 目標値格納用変数 */
	signed short ssW_D_mid;            	/* 計算用変数 */
	unsigned short usW_C_i, usW_C_j;           	/* ループ変数 */
	unsigned short usW_C_num_count = 0;  	/* 目標を満足する値のカウンタ */

	/* 数値の入力、演算を無限ループ */
	while(1){
		/* 使用できる最大値、目標値の入力 */
		scanf("%d %ld", &usW_D_set, &ulW_D_tag);
		
		/* 終了処理 */
		if(usW_D_set == 0 && ulW_D_tag == 0){
			break;
		}
		/* カウンタをリセット */
		usW_C_num_count = 0;
		
		/* 目標を満足する値をカウント */
		for(usW_C_i = 1;usW_C_i < usW_D_set;usW_C_i++){
			for(usW_C_j = usW_C_i;usW_C_j <= usW_D_set;usW_C_j++){
				/* usW_C_i + usW_C_j と目標値の差をssW_D_midに代入 */
				ssW_D_mid = ulW_D_tag - (usW_C_i + usW_C_j);
				/* ssW_D_misがusW_C_iとusW_C_jの間にある場合カウント*/
				if(ssW_D_mid > usW_C_i && ssW_D_mid < usW_C_j){
					usW_C_num_count++;
				}
			}
		}
		
		/* 結果の出力 */
		printf("%d\n", usW_C_num_count);
		
	}
	
	return 0;
}



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

int main() {

    // input from txt （提出時にこの箇所は削除すること）
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());
    int64_t X;
    cin >> X;
    int64_t money = 100;
    int cnt = 0;
    while(money < X){
        int64_t Y = money*0.01;
        money += Y;
        cnt++;
    }
    cout << cnt << endl;
    
}



Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int n, m, ans;
vector<int> a[100021];
priority_queue<int> q;
int main () {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		if (x > m) {
			continue;
		} else {
			a[m - x + 1].push_back(y);
		}
	}
	for (int i = 1; i <= m; i++) {
		for (int j = 0; j < a[i].size(); j++) {
			q.push(-a[i][j]);
			ans += a[i][j];
		}
		while (q.size() > i) {
			ans += q.top();
			q.pop();
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 6268
import sys,os,io
input = sys.stdin.readline
#input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
N = int(input())
A = [list(map(int, input().split())) for _ in range(N)]
y_to_i = [0]*(N+1)
for i,(x,y) in enumerate(A):
  y_to_i[y] = i
A.sort()
ans = [0]*N
from bisect import *
rem_max = N
cum_min = N+1
lis = []
for x,y in A:
  cum_min = min(cum_min, y)
  lis.append(y)
  if len(lis)==rem_max-cum_min+1:
    for y1 in lis:
      ans[y_to_i[y1]] = len(lis)
    rem_max = cum_min-1
    lis = []
    cum_min = N+1
print(*ans, sep='\n')


Measured memory_bytes: 118384
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  ll x;
  cin >> x;
  ll ans = x / 11 * 2;
  x %= 11;
  if(x == 0){

  }else if(x <= 6){
    ans++;
  }else{
    ans += 2;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
class FarmvilleDiv2
{
     public:
     int minTime(vector<int>  time , vector<int>  cost ,  int budget )
     {
         return 1;
     }
};
int main()
{
 
  int n , k;
  cin>>n>>k;
  int a[n];
  int ans=1;
  int pos;
  for(int i =0;i<n;i++)
  {
      cin>>a[i];
      if(a[i]==1) pos=i;
  }
  n-=k;
  while(true)
  {
      if(n<=0) break;
      ans++;
      n-=k-1;
      
  }
  cout << ans << endl;
}
 


Measured memory_bytes: 640
#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 INF 500000001000000000
#define MOD 1000000007
typedef long long  ll;

using namespace std;
typedef pair<int, int> P;

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

	ll N,Q;
	cin >> N >> Q;

	string S;
	cin >> S;

	vector<int> d(N);
	d[0] = 0;
	rep(i,N-1){
		if(S[i] == 'A' && S[i+1] == 'C') d[i+1]++;
	}

	vector<int> imos(N);
	imos[0] = d[0];
	repk(i,1,N){
		imos[i] = imos[i-1] + d[i];
	}

	vector<int> l(Q),r(Q);
	rep(i,Q){
		cin >> l[i] >> r[i];
		l[i]--;
		r[i]--;
	}

	// rep(i,N){
	// 	cout << imos[i] << " ";
	// }
	// cout << endl;

	rep(i,Q){
		cout << imos[r[i]] - imos[l[i]] << endl;
	}

	return 0;
}

Measured memory_bytes: 2640
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <cstring>
#include <ctime>
#include <unordered_map>
#include <iomanip>
using namespace std;

#define fi first
#define se second
#define pb push_back

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;

int N,M,v[200010]; vector<int> g[200010];

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
    cin >> N >> M;

    int i;
    for (i=1; i<=M; i++){
        int x,y;
        cin >> x >> y;
        g[x].push_back(y);
        g[y].push_back(x);
    }

    for (int nxt : g[1])
        v[nxt]++;
    for (int nxt : g[N])
        v[nxt]++;

    bool ans=0;
    for (i=1; i<=N; i++)
        if (v[i]==2) ans=1;

    cout << (ans ? "POSSIBLE\n" : "IMPOSSIBLE\n");
    return 0;
}


Measured memory_bytes: 12784
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;

typedef long long int64;

int main()
{
	static bool noprime[1000001] = {false};
	
	noprime[0] = true;
	for(int i = 2; i * i <= 1000000; ++i) {
	
		if(!noprime[i]) {
		
			for(int j = i * 2; j <= 1000000; j += i)
				noprime[j] = true;
		}
	}

	while(true) {
	
		int n, x;
		int v[30];
		
		scanf("%d%d", &n, &x);
		if(n == 0 && x == 0)
			break;
		for(int i = 0; i < n; ++i)
			scanf("%d", v + i);
			
		static bool dp1[1000001], dp2[1000001];
		bool *prev = dp1;
		bool *next = dp2;
		
		fill(dp1, dp1 + (x + 1), 0);
		fill(dp2, dp2 + (x + 1), 0);
		
		for(int i = 0; i < n; ++i) {
			
			next[0] = prev[0] = true;
		
			for(int c = 1; c <= x; ++c)
				next[c] = prev[c];
			
			for(int c = v[i]; c <= x; ++c)
				next[c] = (next[c] || next[c - v[i]]);
				
			swap(next, prev);
		}
		
		int ans = -1;
		
		for(int i = x; i > 0; --i) {
		
			if(!noprime[i] && prev[i]) {
				ans = i;
				break;
			}
		}
		
		if(ans < 0)
			printf("NA\n");
		else
			printf("%d\n", ans);
	}
	
	return 0;
}

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

using namespace std;

#define ll long long
#define endl '\n'
#define pb push_back
#define inf 1e12

int const N = 1e3+5;

int main ()
{
    string s; cin >> s;
    bool playable = true;
    for (int i = 0; i < s.size() && playable; i++)
    {

        if (s[i] == 'U' || s[i] == 'D')
            continue;

        if (i%2 == 1 && s[i] == 'L')// even
            continue;

        if (i%2 == 0 && s[i] == 'R')
            continue;

        playable = false;
    }
    cout << (playable ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

struct Node_struct{int id, p, d, c, s;};
typedef struct Node_struct Node;
Node node[200000];

void dfs(int pos, int dep);

void root2(int par, int ro);

int main(){
  int i, j, k;
  int N;
  int id, sib, child;
  int root = 0;
  scanf("%d", &N);
  for(int i=0;i<N;i++) node[i].p = node[i].c = node[i].s = -1;

  for(i=0;i<N;i++){
    scanf("%d %d", &id, &k);
    node[id].id = id;
    for(j=0;j<k;j++){
      scanf("%d", &child);
      node[child].p = id;
      if(j == 0) node[id].c = child, sib = child;
      else node[sib].s= child;
      sib = child;
    }
  }


  for(i=0;i<N;i++) if(node[i].p == -1) root = i;
  dfs(root, 0);

  for(i=0;i<N;i++){
    printf("node %d: parent = %d, depth = %d, ", node[i].id, node[i].p, node[i].d);
    if(node[i].p == -1) printf("root, ");
    else if(node[i].c == -1) printf("leaf, ");
    else printf("internal node, ");
    printf("[");
    root2(node[i].c, 1);

  printf("]\n");
}


  return 0;
}

void root2(int par, int ro){
  if(par==-1){
    return;
  }
  if(ro){
    printf("%d",par);
  }else {
    printf(", %d",par);
  }
  if(node[par].s!=-1){
    root2(node[par].s,0);
  }
}


void dfs(int pos, int dep){
  node[pos].d = dep;
  if(node[pos].c != -1) dfs(node[pos].c, dep + 1);
  if(node[pos].s != -1) dfs(node[pos].s, dep);
}



Measured memory_bytes: 3656
import java.util.Scanner;



public class Main {

	public static void main(String[] args) {



		Solve s= new Solve();
		s.solve();

	}
}


class Solve{
	 Scanner sc = new Scanner(System.in) ;

	 void solve() {
		 int N=sc.nextInt();
		 int[] w=new int[N];
		 int S1,S2;
		 int res=10000000;
		 for(int i=0;i<N;i++) {
			 w[i]=sc.nextInt();
		 }
		 for(int i=0;i<N;i++) {
			 S1=0;
			 S2=0;
			 for(int j=0;j<=i;j++) {
				 S1+=w[j];
			 }
			 for(int k=i+1;k<N;k++) {
				 S2+=w[k];
			 }
			 if(res>Math.abs(S1-S2)) {
				 res=Math.abs(S1-S2);
			 }
		 }


		 System.out.println(res);
	 }



	 }

Measured memory_bytes: 23892
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num = Integer.parseInt(sc.nextLine());
		String strings = sc.nextLine();

		if (strings.length() <= num) {
			System.out.println(strings);
		} else {
			System.out.println(strings.substring(0, num) + "...");
		}

	}
}

Measured memory_bytes: 38664
r,g,b=map(int,input().split())
K=int(input())
cnt=0
for i in range(100):
    if g<=r:
        g=g*2
        cnt+=1
    elif b<=g:
        b=b*2
        cnt+=1

if cnt<=K:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 61640
n = int(input())
def query(b, e, t):
    m = (e+b+1)//2
    print(m)
    res = input()[0]
    if ((m-b)%2 == 0) == (res == t):
        query(m, e, res)
    else:
        query(b, m-1, t)
print(0)
query(0, n-1, input()[0])


Measured memory_bytes: 3660
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
#define DBG(X) cout<<#X<<" : "<<X<<endl;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);

//0156

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

int d[110][110];

bool isOutOfRange(int x, int y, int w, int h){
    if(x < 0 || x >= w || y < 0 || y >= h) return true;
    return false;
}

string s[110];

int main(){
    int x, y;
    int sx, sy;
    while(cin>>x>>y && x && y){
        rep(i, y) cin>>s[i];
        rep(i, y) rep(j, x){
            if(s[i][j] == '&'){
                sx = j;
                sy = i;
            }
            d[i][j] = INF;
        }
        //cout<<y<<" "<<x<<endl;
        priority_queue<pair<int, pii> > q;
        q.push(mp(0, mp(sy, sx)));
        d[sy][sx] = 0;
        pair<int, pii> p;
        int ans = INF;
        while(!q.empty()){
            p = q.top(); q.pop();
            //cout<<" "<<p.fi<<" ("<<p.se.fi<<", "<<p.se.fi<<endl;
            rep(i, 4){
                int nx = p.se.se + dx[i];
                int ny = p.se.fi + dy[i];
                if(isOutOfRange(nx, ny, x, y)){
                    ans = min(ans, -p.fi);
                    break;
                }
                int c = -p.fi + ((s[p.se.fi][p.se.se]!='#'&&s[ny][nx]=='#')?1:0);
                if(d[ny][nx] <= c) continue;
                d[ny][nx] = c;
                q.push(mp(-c, mp(ny, nx)));
            }
            if(ans != INF) break;
        }
        cout<<ans<<endl;
        // rep(i, y){
        //     rep(j, x){
        //         cout<<" "<<d[i][j];
        //     }
        //     cout<<endl;
        // }
    }
}

Measured memory_bytes: 1400
#include <cstdio>
#include <cstdlib>

int gcd(int, int);

int main(){
    int n,X;
    scanf("%d %d",&n,&X);
    int x[n];
    for(int i = 0; i < n; i++){
        scanf("%d",&x[i]);
    }

    if(n == 1){
        printf("%d\n",abs(x[0] - X));

        return 0;
    }

    int ans = gcd(abs(x[0] - X), abs(x[1] - x[0]));
    for(int i = 1; i + 1 < n; i++){
        ans = gcd(ans, abs(x[i + 1] - x[i]));
    }
    printf("%d\n",ans);

    return 0;
}

int gcd(int a, int b){
    int r,p;
    if(a < b){
        p = a;
        a = b;
        b = p;
    }

    r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
 
    return b;
}

Measured memory_bytes: 512
#include <cstdio>

int binarySearch(int *S, int key, int left, int right){
	int mid;
	if(left > right) return 0;
	else{
		mid = left + (right - left)/2;
		if(S[mid]==key) return 1;
		else if(S[mid] < key) return binarySearch(S, key, mid+1, right);
		else return binarySearch(S, key, left, mid-1);
	}

}

int main(){
	int i,n,q,count,key;
	int *S;
	count=0;
	scanf("%d", &n);
	S = new int[n];
	for(i=0;i<n;i++){
		scanf("%d", &S[i]);
	}
	scanf("%d", &q);
	for(i=0;i<q;i++){
		scanf("%d", &key);
		count += binarySearch(S, key, 0, n-1);
	}

	printf("%d\n", count);
	return 0;
}

Measured memory_bytes: 3016
#include<stdio.h>

int main(void){
	int a, b, c;
	int ans;
	
	scanf("%d %d %d", &a, &b, &c);
	
	ans = (c-(a-b));
	if(ans > 0)
		printf("%d\n", (c-(a-b)) );
	else
		printf("0\n");

	return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <cstring>

using namespace std;

char x[222222];
int len;

int main(void) {
  scanf("%s", x);
  len = strlen(x);

  int res = len;
  int s = 0;
  for (int i = 0; i < len; i++) {
    if (x[i] == 'S') {
      s += 1;
    } else {
      if (s > 0) {
        s -= 1;
        res -= 2;
      } else {
        s = 0;
      }
    }
  }

  printf("%d\n", res);
  return 0;
}


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

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

typedef long long ll;

int main() {
    int n,m,q;cin>>n>>m>>q;
    int a[n][n];
    
    rep(i,n)rep(j,n)a[i][j]=0;
    
    int tmp_r,tmp_l;
    rep(i,m){
        cin>>tmp_l>>tmp_r;
        --tmp_l,--tmp_r;
        ++a[tmp_l][tmp_r];
    }

    int b[n][n];
    rep(i,n)rep(j,n)b[i][j]=a[i][j];
    rep(i,n)rep(j,n-1)b[i][j+1]+=b[i][j];
    
    int ql,qr;
    rep(i,q){
        int ans = 0;
        cin>>ql>>qr;
        --ql,--qr;
      ans = b[qr][qr];
        REP(j,ql,qr)ans+=b[j][qr];
//      if(ql!=0)REP(j,ql,qr+1)ans-=b[ql-1][j];

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

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

int main()
{
    int A1, A2, A3;
    cin >> A1 >> A2 >> A3;

    if (22 <= A1+A2+A3) {
        cout << "bust";
    } else {
        cout << "win";
    }
    
    return 0;
}


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

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

struct Node {
	vector<int> link;
	bool passed = false;
};

Node nodes[9];
vector<int> route;
int N, M;



int main() {
	int ans = 0;

	cin >> N >> M;

	// 順列用
	for (int i = 0; i < N; i++) {
		route.push_back(i + 1);
	}

	for (int i = 0; i < M; i++) {
		int a, b;
		cin >> a >> b;
		nodes[a].link.push_back(b);
		nodes[b].link.push_back(a);
	}

	do {
		for (int i = 1; i <= N; i++) {
			nodes[i].passed = false;
		}


		bool flag = true;
		for (size_t r = 0, length = route.size(); r < length; ++r) {

			if (route[r] != route[length - 1]) {
				if (nodes[route[r]].passed || find(nodes[route[r]].link.begin(), nodes[route[r]].link.end(), route[r + 1]) == nodes[route[r]].link.end()) {
					flag = false;
					break;
				}
			}

			nodes[route[r]].passed = true;
		}

		if (flag) ans++;

	} while (next_permutation(route.begin() + 1, route.end()));

	cout << ans << endl;

	return 0;
}

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

const ll MOD = 1000000007;

int main(){
  int n;
  cin >> n;
  vector<ll> a(n);
  ll sum = 0;
  ll par = 0;
  rep(i,n){
    cin >> a[i];
    par += a[i]*a[i];
    par %= MOD;
    sum += a[i];
    sum %= MOD;
  }
  ll ans = (sum*sum)%MOD;
  ans -= par;
  ans *= 500000004;
  ans %= MOD;
  ans = (ans+MOD)%MOD;
  cout << ans << endl;
}


Measured memory_bytes: 4836
l, r = gets.strip.split(" ").map(&:to_i)

ans = 2019

l.upto(l + 2019) do |i|
  break if i > r

  (i + 1).upto(i + 2020) do |j|
    break if j > r

    m = ((i % 2019) * (j % 2019)) % 2019
    ans = m if m < ans
  end
end

puts ans


Measured memory_bytes: 1788
#include <stdio.h>

int main()
{
  int n;

  scanf("%d",&n );
  if(n/100 == 7)
    printf("Yes");
  else if( (n%100)/10 == 7)
    printf("Yes");
  else if( (n%100)%10 == 7)
    printf("Yes");
  else
    printf("No");

  return 0;
}


Measured memory_bytes: 1676
import math

def A():
    a, b = [int(x) for x in input().split()]
    print(math.ceil((a + b)/2))

def B():
    a = ''.join(sorted(list(input()), key=lambda x:ord(x)))
    b = ''.join(sorted(list(input()), key=lambda x:-ord(x)))
    if a < b:
        print('Yes')
    else:
        print('No')

def C():
    N = input()
    A = [x for x in input().split()]
    counter = {}

    for a in A:
        if(a in counter):
            counter[a] += 1
        else:
            counter[a] = 1
    remove_count = 0
    for key in counter:
        if counter[key] - int(key) >= 0:
            remove_count += counter[key] - int(key)
        else:
            remove_count += counter[key]
    print(remove_count)
C()


Measured memory_bytes: 20980