akhauriyash/Code-Regression huggingface dataset:
#include <climits>
#include <cmath>
#include <algorithm>
#include <array>
#include <iostream>
#include <vector>
using namespace std;
int main(int, char**)
{
	long N;
	cin >> N;
	vector<long> a(N);
	for (long i = 0; i < N; ++i)
	{
		cin >> a[i];
	}
	if ((N & 1) == 1)
	{
		long tmp = 0;
		for (long i = 1; i < N; ++i)
		{
			tmp ^= a[i];
		}
		cout << (a[0] == tmp ? "Yes" : "No") << endl;
	}
	else
	{
		long tmp = 0;
		for (long i = 0; i < N; ++i)
		{
			tmp ^= a[i];
		}
		cout << (tmp == 0 ? "Yes" : "No") << endl;
	}
	return 0;
}


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

bool out(int x,int y){
	if(10<=x&&x<=70&&10<=y&&y<=70){
		return true;
	}
	return false;
}

int main(){
	int dx[6]={1,0,-1,-1,0,1};
	int dy[6]={0,-1,-1,0,1,1};
	int n,t;
	while(cin>>t>>n&&t){
		int board[200][200]; rep(i,200)rep(j,200) board[i][j]=INF;
		rep(i,n){
			int x,y; cin>>x>>y;
			board[x+100][y+100]=-1;
		}
		int sx,sy; cin>>sx>>sy;
		board[sx+100][sy+100]=0;
		queue<pair<int,int>> q;
		q.push(make_pair(sx+100,sy+100));

		int cnt=1;
		while(q.size()){
			pair<int,int> p=q.front();
			q.pop();
			int nowx=p.first,nowy=p.second;
			if(board[nowx][nowy]==t) continue;
			rep(i,6){
				int nex=nowx+dx[i],ney=nowy+dy[i];
				if(board[nex][ney]==INF){
					board[nex][ney]=board[nowx][nowy]+1;
					cnt++;
					q.push(make_pair(nex,ney));
					// cout<<nex<<" "<<ney<<endl;
				}
			}
		}
		cout<<cnt<<endl;
	}
    return 0;
}



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

string n;
int k;
int len;
long long ans = 0;
long long com(long long a, long long b) {
  if (a < 0) {
    return 0;
  } if (b == 0) {
    return 1;
  } else if (b == 1) {
    return a;
  } else if (b == 2) {
    return a * (a - 1) / 2;
  } else {
    return a * (a - 1) * (a - 2) / 6;
  }
}
long long p9(long long a) {
  if (a == 0) {
    return 1;
  }
  return 9LL * p9(a - 1);
}

void f(int idx, bool small_than_n, int rest, bool equal0) {
  if (idx == len) {
    if (rest == 0 && !equal0) {
      ++ans;
    }
    return;
  }
  if (rest == 0) {
    ++ans;
    return;
  }
  if (small_than_n) {
    if (equal0) {
      f(idx+1, true, rest, true);
      ans += p9(rest) * com(len - idx - 1, rest - 1);
    } else {
      ans += p9(rest) * com(len - idx, rest);
    }
    return;
  }
  if (n[idx] == '0') {
    f(idx+1, false, rest, false);
  } else {
    f(idx+1, true, rest, equal0);
    for (int i=1; i<n[idx]-'0'; i++) {
      f(idx+1, true, rest-1, false);
    }
    f(idx+1, false, rest-1, false);
  }
}
int main() {
  cin>>n;
  cin>>k;
  len = n.length();
  f(0, false, k, true);
  cout<<ans<<endl;
}

Measured memory_bytes: 256
while True:
    (H, W) = [int(x) for x in input().split()]
    if H == W == 0:
        break
    
    for hc in range(H):
        if hc == 0 or hc == H -1:
            print('#' * W)
        else:
            print('#' + '.' * (W -2) + '#')
    print()

Measured memory_bytes: 7672
#include <iostream>
#include <iomanip>
#include <cassert>

#include <cstring>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <limits>
#include <queue>
#include <unordered_map>
#include <list>
#include <set>
#include <numeric>
using namespace std;

using ll = long long;

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

int main()
{
	int H, W, K;
	cin >> H >> W >> K;

	vector<vector<char>> c(H, vector<char>(W));

	rep(i, H)
	{
		rep(j, W)
		{
			cin >> c[i][j];
		}
	}

	int H2 = 1 << H;
	int W2 = 1 << W;

	int ans = 0;
	rep(i, H2)
	{
		rep(j, W2)
		{
			vector<bool> raw(H, true);
			vector<bool> col(W, true);

			int i2 = i;
			rep(k, H)
			{
				if ((i2 & 0x1) == 1)
				{
					raw[k] = false;
				}

				i2 >>= 1;
			}

			int j2 = j;
			rep(k, W)
			{
				if ((j2 & 0x1) == 1)
				{
					col[k] = false;
				}

				j2 >>= 1;
			}

			int count = 0;
			rep(k, H)
			{
				if (raw[k])
				{
					rep(l, W)
					{
						if (col[l])
						{
							if (c[k][l] == '#')
							{
								++count;
							}
						}
					}
				}
			}

			if (K == count)
			{
				++ans;
			}
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 3628
local s = io.read()
local t = {}
local n = #s
for i = 1, n do
  table.insert(t, s:sub(i, i) == "B")
end
local cnt = 0
local curcnt = 0
for i = n, 1, -1 do
  if t[i] then
    cnt = cnt + curcnt
    t[i] = false
  else
    curcnt = curcnt + 1
  end
end
print(cnt)


Measured memory_bytes: 2748
n,*a=map(int,open(0))
d={}
for i in a[:n]:d[i]=0
for i in a[n:]:d[i]=1
a,c=1,0
for i in sorted(d):
  if((c>0)!=d[i])*c:a=a*abs(c)%(10**9+7)
  c+=d[i]or-1
print(a)

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

int main() {
  int n; cin >> n;
  deque<int> A(n);
  for (int i = 0; i < n; ++i) cin >> A[i];
  sort(A.begin(), A.end());
  auto try_A = [&](deque<int> A) {
    deque<int> B;
    B.push_back(A.back());
    A.pop_back();
    for (int i = 0; i < n - 1; i += 2) {
      if (i % 4 == 0) {
        B.push_back(A.front()); A.pop_front();
        if (A.size()) B.push_front(A.front()), A.pop_front();
      }
      else {
        B.push_back(A.back()); A.pop_back();
        if (A.size()) B.push_front(A.back()), A.pop_back();
      }
    }
    LL ans = 0;
    for (int i = 0; i < n - 1; ++i) ans += abs(B[i] - B[i + 1]);
    return ans;
  };
  LL ans = try_A(A);
  reverse(A.begin(), A.end());
  cout << max(ans, try_A(A)) << '\n';
}


Measured memory_bytes: 1108
def solv(S):
    c = []
    for i in range(25, 0, -1):
        for j in range(i-1, -1, -1):
            if S[i] > S[j]:
                c.append(S[:j]+S[i])
    print(sorted(c)[0])
    return


alph = "abcdefghijklmnopqrstuvwxyz"
S = input()
for c in S:
    alph = alph.replace(c, "")
if alph != "":
    print(S+alph[0])
else:
    alph = "abcdefghijklmnopqrstuvwxyz"
    if S == alph[::-1]:
        print(-1)
    else:
        solv(S)


Measured memory_bytes: 3064
n = int(input())
odd = [i for i in range(1, n + 1) if i % 2 == 1]
cnt = 0
for o in odd:
    divisor = [i for i in range(1, n + 1) if o % i == 0]
    if len(divisor) == 8:
        cnt += 1
print(cnt)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        long long int n,a,b,low=0,mid,high,count=0,i;
        cin>>n>>a>>b;
        high=(1e18)/(b+1);
        vector<long long int> v(n);
        for(int i=0;i<n;i++)
            cin>>v[i];
        while(low+1<high)
        {
            count=0;
            mid=(low+high)/2;
            for(int x=0;x<v.size();x++)
            {
                i=v[x];
                if(i>mid*b)
                    (i-mid*b)%(a-b)?count+=(i-mid*b)/(a-b)+1:count+=(i-mid*b)/(a-b);
            }
         //   cout<<low<<" "<<mid<<" "<<high<<" "<<count<<endl;
            if(count<=mid)
                high=mid;
            else
                low=mid;
        }
        cout<<high;
    }

Measured memory_bytes: 1024
import bisect
import heapq
import itertools
import math
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18


def get_factors(n):
    """
    素因数分解
    :param int n:
    :rtype: list of int
    """
    if n <= 1:
        return []

    ret = []
    while n > 2 and n % 2 == 0:
        ret.append(2)
        n //= 2
    i = 3
    while i <= math.sqrt(n):
        if n % i == 0:
            ret.append(i)
            n //= i
        else:
            i += 2
    ret.append(n)
    return ret


N = int(sys.stdin.readline())
MOD = 10 ** 9 + 7

factors = []
for n in range(2, N + 1):
    factors.extend(get_factors(n))
# https://juken-mikata.net/how-to/mathematics/number-of-divisor.html
# 素数の指数 + 1 の積
#: :type: np.ndarray
counts = np.bincount(factors)
ans = 1
for e in counts[counts > 0]:
    ans = ans * (e + 1) % MOD
print(ans)


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

using namespace std;

#define eb emplace_back
#define ii pair<int, int>
#define OK (cerr << "OK" << endl)
#define debug(x) cerr << #x " = " << (x) << endl
#define ff first
#define ss second
#define int long long
#define tt tuple<int, int, int>
#define all(x) x.begin(), x.end()
#define Matrix vector<vector<int>>
#define Mat(n, m, v) vector<vector<int>>(n, vector<int>(m, v))
#define endl '\n'
#define double long double

constexpr int INF = 2e18;
constexpr int MOD = 1e9 + 7;
constexpr int MAXN = 2e5 + 3;

// #define MULTIPLE_TEST_CASES
void solve() {
  int n;
  cin >> n;
  int k;
  cin >> k;

  vector<int> arr(n);
  for (int &x : arr) {
    cin >> x;
  }

  double cur = 0;
  double last = 0;
  for (int i = 0; i < n; ++i) {
    if (i >= k) {
      last = cur;
      cur -= log(arr[i - k]);
    }
    cur += log(arr[i]);
    if (i >= k) {
      cout << (cur > last ? "Yes" : "No") << endl;
    }
  }
}

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

  int t = 1;
#ifdef MULTIPLE_TEST_CASES
  cin >> t;
#endif
  while (t--)
    solve();
}

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


int main(){
  int n;cin>>n;
  int h[n];
  int b[n];
  
  for (int i=0;i<n;i++)
    cin>>h[i];
  b[0]=0;b[1]=abs(h[1]-h[0]);
  for (int i=2;i<n;i++)
    b[i]=min(b[i-1]+abs(h[i]-h[i-1]),b[i-2]+abs(h[i]-h[i-2]));
  cout<<b[n-1]<<endl;
  
 return 0;
}


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

int main(){
    int lens,lent;
    bool flag=true,flg=false;
    string s,t,ans,tmp="";
    cin >> s >> t;
    ans = s;
    lens = s.size();
    lent = t.size();
    for(int i=0;i<lens;i++)
        tmp+='z';
    for(int j=0;j<=lens-lent;j++){
        ans = s;
        flag = true;
        for(int i=0;i<lent;i++)
            if(s.at(lens-i-j-1)!='?'&&s.at(lens-i-j-1)!=t.at(lent-i-1)){
                flag=false;
            }
            else 
                ans.at(lens-i-j-1)=t.at(lent-i-1);
        if(flag){
                flg=true;
                replace(ans.begin(),ans.end(),'?','a');
                if(tmp>ans)
                    tmp = ans;
//                goto OUT;
//            cout << ans << endl;

        }
    }
    if(!flg){
        cout << "UNRESTORABLE" << endl;
        return 0;
    }
//    OUT:;
        cout << tmp << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define INF 1e9
#define MOD 1000000007
#define All(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;

ll mod_pow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

ll binomial(ll n,ll k){
    ll N=1,K=1;
    for(int i=1;i<=k;i++){
        K*=i;
        K%=MOD;
    }
    for(int i=n;i>=n-k+1;i--){
        N*=i;
        N%=MOD;
    }
    return N*mod_pow(K,MOD-2,MOD)%MOD;

}

int main(void){
    ll n,a,b;
    cin>>n>>a>>b;
    ll ans=mod_pow(2,n,MOD);
    ans=ans-1-binomial(n,a)-binomial(n,b);
    ans%=MOD;
    if(ans<0)ans+=MOD;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Threading;

class Program
{
    static void Main(string[] args)
    {
        var l = Console.ReadLine().Split(' ')
            .Select(x => long.Parse(x)).ToArray();
        var a = l[0]; var b = l[1]; var k = l[2];
        var f = false;
        if (k % 2 == 0) k /= 2;
        else
        {
            k = (k - 1) / 2;
            f = true;
        }
        for (var i = 0; k > i; i++)
        {
            if (a % 2 != 0)
            {
                a--;
            }
            b += a / 2;
            a -= a / 2;
            if (b % 2 != 0)
            {
                b--;
            }
            a += b / 2;
            b -= b / 2;
        }
        if (f)
        {
            if (a % 2 != 0)
            {
                a--;
            }
            b += a / 2;
            a -= a / 2;
        }
        Console.WriteLine($"{a} {b}");
    }
}

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

int main()
{
	string s1, s2, s3;
	cin >> s1 >> s2 >> s3;
	char dif = 'A' - 'a';

	printf("%c%c%c\n", s1[0] + dif, s2[0] + dif, s3[0] + dif);
}


Measured memory_bytes: 256
program sequence_sum;
var
  n, x, m, num: int64;
  i, offset, period, rem: integer;
  a: array[0..100000] of int64;
  b: array[0..100000] of integer;
begin
  read(n, x, m);
  if n = 1 then
  begin
    writeln(x);
    halt(0);
  end;
  a[1] := x;
  b[x] := 1;
  for i := 2 to m + 1 do
  begin
    x := (x * x) mod m;
    a[i] := a[i - 1] + x;
    if i = n then
    begin
      writeln(a[i]);
      halt(0);
    end;
    if b[x] > 0 then
    begin
      offset := b[x] - 1;
      period := i - offset - 1;
      break;
    end;
    b[x] := i;
  end;
  num := (n - offset) div period;
  rem := n - offset - num * period;
  writeln((a[offset + period] - a[offset]) * num + a[offset + rem]);
end.

Measured memory_bytes: 1384
# U - Grouping
n = int(input())
a = [tuple(map(int,input().split())) for _ in range(n)]

memo = [-1 for _ in range(2**n)]

# f(s):うさぎsをグループ分けしたときの得点の最大値。
# sのすべての部分集合tについて、f(t)+f(t|s)を計算してその最大値を求める。

def f(s):
  if memo[s] != -1:
    return memo[s]
  # now:sをグループ分けせず1グループとしたときの得点。
  now = 0
  for i in range(n-1):
    for j in range(i+1,n):
      if (s>>i)&1 == 1 and (s>>j)&1 == 1:
        now += a[i][j]
  ret = now
  # tをsの部分集合とするが、t=sは除くため、最初はt = (s-1)&sとする。
  t = (s-1)&s
  # t = (t-1)&sとすると、sのすべての部分集合tを順に列挙できる。
  # また、tをsの部分集合としたとき、tの補集合はt xor sとなる。
  while(t > 0):
    ret = max(ret,f(t)+f(t^s))
    t = (t-1)&s
  memo[s] = ret
  return ret

print(f(2**n-1))

Measured memory_bytes: 77672
#include<bits/stdc++.h>
using namespace std; 
typedef long long ll; 
#define endl "\n"
#define pb push_back
int main(){
  ll x,k,d;
  cin>>x>>k>>d; 
  ll ans=(k*d);
  if(x<0){
   x*=(-1);
  }
  if(k==0 or d==0){
   cout<<x; 
    return 0;
  }
  if(ans<=x and ans>0){
    x-=ans; 
    cout<<x;
    return 0;
  }
  ll f=x/d;
  ll g=f+1;
  ll ans2=abs(x-f*d);
  k-=f; 
  if(g<=k){
    if(abs(x-g*d)<ans2){
      ans2=abs(x-g*d);
      k--; 
    }
  }
  if(k%2==0){
    cout<<ans2;
  }
  else{
    ll ans3=min(abs(ans2-d),(ans2+d));
    cout<<ans3; 
  }
  
  return 0;
}

Measured memory_bytes: 3632
from collections import deque
import sys
input = sys.stdin.readline

n = int(input())
a = [0]*n
b = [0]*n

for i in range(n):
    a[i], b[i] = map(int, input().split())

a.sort()
b.sort()

if n%2!=0 :
    l = a[int(n/2)]
    u = b[int(n/2)]
    ans = u - l + 1
else:
    l = a[int(n/2-1)] + a[int(n/2)]
    u = b[int(n/2-1)] + b[int(n/2)]
    ans = u - l +1

print(ans)



Measured memory_bytes: 25616
input = raw_input
x, y = map(int, input().split(" "))

b = y 
flag = False
if y % 2 == 0:
    b = y // 2 - x
    a = x - b
    if b >= 0 and a >= 0:
        flag = True

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

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

// template {{{
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); (i) += 1)
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); (i) -= 1)

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

// constexpr i32 mod   = 998244353;
constexpr i32 mod   = 1e9 + 7;
constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(int x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// }}}

void solver() {
    int n = input();
    vector< int > ls(n);
    cin >> ls;

    whole(sort, ls);

    int ans = 0;
    range(i, 0, n) range(j, i + 1, n) range(k, j + 1, n) {
        if (ls[i] == ls[j]) continue;
        if (ls[j] == ls[k]) continue;
        if (ls[i] + ls[j] > ls[k]){
            ans++;
        }
    }

    cout << ans << endl;
}

signed main(int argc, char *argv[]) {
    solver();
}


Measured memory_bytes: 3656
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;
import java.math.BigInteger;
 
public class Main implements Runnable {
	
	static int mod = 1000000007;
	
    public static void main(String[] args) {
    	new Thread(null, new Main(), "", 1024 * 1024 * 1024).start();
    }
    
    public void run() {
    	PrintWriter out = new PrintWriter(System.out);
        FastScanner sc = new FastScanner();
        
        char[] s = sc.next().toCharArray();
        
        if(s[0] == s[1] || s[1]==s[2] || s[2] == s[3]){
        	out.println("Bad");
        }
        else{
        	out.println("Good");
        }
        
        
        out.flush();
    }
}


class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}
	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}
	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}
	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}
	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}
	public int[] nextintArray(int n){
		int[] a = new int[n];
		for(int i=0;i<n;i++){
			a[i] = nextInt();
		}
		return a;
	}
	public long[] nextlongArray(int n){
		long[] a = new long[n];
		for(int i=0;i<n;i++){
			a[i] = nextLong();
		}
		return a;
	}
	public Integer[] nextIntegerArray(int n){
		Integer[] a = new Integer[n];
		for(int i=0;i<n;i++){
			a[i] = nextInt();
		}
		return a;
	}
	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 23380
N = int(input())
A = list(map(int, input().split()))
A.sort()
B = [False] * (A[-1]+1)

for a in A:
    B[a] = True

for i in range(len(A)-1):
    a = A[i]
    if B[a] == True:
        if A[i] == A[i+1]:
            B[a] = False
        for x in range(2*a, len(B), a):
            B[x] = False

print(sum(B))

Measured memory_bytes: 32068
import scala.io.StdIn.readLine

object Main{
  def main(args : Array[String]): Unit ={
    val Array(n, m) : Array[Int] = readLine().split(' ').map(_.toInt)
    val can : Array[Int] = readLine().split(' ').map(_.toInt)
    val SLV = new SOLVE(n, can)
    println(SLV.solve(n))
  }
}

class SOLVE(private val n : Int, private val can : Array[Int]){
  val caned : Array[Int] = can.sorted
  val COST : Array[Int] = Array(0, 2, 5, 5, 4, 5, 6, 3, 7, 6)
  val DP : Array[Int] = Array.fill(n + 10)(-1)
  DP(0) = 0

  def MakeReversing(k : Int): String ={
    def getNextString(u : Int): (Char, Int) ={
      var res1 : Char = '\n'
      var res2 : Int = 114514
      for(ele <- caned;if(u >= COST(ele))){
        if(DP(u) - DP(u - COST(ele)) == 1) {
          res1 = ('0' + ele).toChar
          res2 = COST(ele)
        }
      }
      (res1, res2)
    }
    var search : Int = k
    var res : String = ""
    while(search > 0){
      val (a, b) : (Char, Int) = getNextString(search)
      search -= b
      res = res + a
    }
    res
  }
  def solve(k : Int): String ={
    for(i <- 0 until k; j <- can){
      val idx : Int = i + COST(j)
      if(DP(idx) < DP(i) + 1) DP(idx) = DP(i) + 1
    }
    MakeReversing(k)
  }
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m; cin>>n>>m;
    vector<vll> v(3, vll(n));
    rep(i,n)rep(j,3) cin>>v[j][i];
    ll ans=0;
    rep(c,8){
        vll t;
        rep(i,n){
            ll sum=0;
            rep(j,3){
                int sgn = (c>>j&1)?1:-1;
                sum+=sgn*v[j][i];
            }
            t.pb(sum);
        }
        sort(rall(t));
        ll cand=0;
        rep(i,m) cand+=t[i];
        chmax(ans,cand);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
  int n,a,b,ans=0; cin >> n >> a >> b;
  for(int i=1;i<=n;i++){ 
    int c = i; 
    int sum = 0;
    while(c>0){
      sum += c%10;
      c = c/10;
    }
    if(sum>=a && sum<=b) ans += i; 
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int n;
    while(cin>>n,n){
        vector<vector<int>>d(n+2,vector<int>(n+1,INF));
        rep(i,n)rep(j,n+1)cin>>d[i][j];
        vi dp((1<<(n))+1,INF);
        dp[0]=0;
        for(int s=0; s<(1<<(n));s++){
            for(int v=0;v<n;v++){
                if(!(s>>v&1)){
                    int mini=d[v][0];
                    for(int u=0; u<n;u++){
                        if(s>>u&1)cmin(mini,d[v][u+1]);
                    }
                    cmin(dp[s|1<<v],dp[s]+mini);
                }
            }
        }
        
        cout<<dp[(1<<(n))-1]<<endl;
    }
}

Measured memory_bytes: 3428
#include <cstdio>
#include <cstring>
#include <cassert>
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <iterator>
#include <queue>
#include <utility>

using namespace std;

struct P {
    int x, y;
    P(int x, int y) : x(x), y(y) {}
};
bool operator<(const P& a ,const P& b) {
    return a.x == b.x ? a.y < b.y : a.x < b.x;
}
bool operator==(const P& a, const P& b) {
    return a.x == b.x && a.y == b.y;
}
ostream& operator<<(ostream& os, const P& p) {
    os << "P(" << p.x << "," << p.y << ")";
    return os;
}
struct L {
    P a, b;
    L(P a, P b) : a(a), b(b) {}
};

int N;
map<P, int> M;
map<P, int> U;
vector<L> F;
#define UNDEF 0
#define HEAD 1
#define FEET 2
bool input() {
    cin >> N; if (N == 0) return false;
    M.clear(); U.clear(); F.clear();
    for (int i = 0; i < N; i++) {
        int x, y; char d;
        cin >> x >> y >> d;
        if (d == 'x') {
            M[P(x, y)] = i;
            M[P(x + 1, y)] = i;
            F.push_back(L(P(x, y), P(x + 1, y)));
        } else {
            M[P(x, y)] = i;
            M[P(x, y + 1)] = i;
            F.push_back(L(P(x, y), P(x, y + 1)));
        }
    }
    return true;
}

int R(int s) {
    if (s == HEAD) return FEET;
    if (s == FEET) return HEAD;
    assert(0);
}

const int dy[] = {0, 1, 0, -1},
          dx[] = {1, 0, -1, 0};
bool Set(const P& a, int s) {
    //cout << a << " " << s << endl;
    int index = M[a];
    const P& b = (F[index].a == a ? F[index].b : F[index].a);
    for (int i = 0; i < 4; i++) {
        P n(a.x + dx[i], a.y + dy[i]);
        if (n == b) continue;
        if (M.count(n) == 0) continue;
        if (U[n] == R(s)) return false;
    }
    for (int i = 0; i < 4; i++) {
        P n(b.x + dx[i], b.y + dy[i]);
        if (n == a) continue;
        if (M.count(n) == 0) continue;
        if (U[n] == s) return false;
    }
    U[a] = s;
    U[b] = R(s);
    for (int i = 0; i < 4; i++) {
        P n(a.x + dx[i], a.y + dy[i]);
        if (n == b) continue;
        if (M.count(n) == 0) continue;
        //cout << n << endl;
        if (U[n] == UNDEF) {
            if (!Set(n, s)) {
                U[a] = UNDEF;
                U[b] = UNDEF;
                return false;
            }
        }
    }
    for (int i = 0; i < 4; i++) {
        P n(b.x + dx[i], b.y + dy[i]);
        if (n == a) continue;
        if (M.count(n) == 0) continue;
        if (U[n] == UNDEF) {
            if (!Set(n, R(s))) {
                U[a] = UNDEF;
                U[b] = UNDEF;
                return false;
            }
        }
    }
    return true;
}

void solve() {
    for (int i = 0; i < N; i++) {
        if (U[F[i].a] != UNDEF) continue;
        if (Set(F[i].a, HEAD)) continue;
        if (Set(F[i].a, FEET)) continue;
        cout << "No" << endl;
        return;
    }
    cout << "Yes" << endl;
}

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

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

typedef long long ll;
ll n, l;
string a[110];

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

    cin>>n>>l;
    for(ll i=1; i<=n; i++){
        cin>>a[i];
    }
    sort(a+1,a+1+n);
    for(ll i=1; i<=n; i++){
        cout<<a[i];
    }


}


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

int main(){
  int K, A, B;
  cin >> K >> A >> B;
  int M=A/K;
  if(A%K==0 || M*K+K<=B){
    cout << "OK" << endl;
  }
  else{
    cout << "NG" << endl;
  }
}

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

int main(){
	int a;
	cin>>a;
	long long b[11111];
	b[0]=2;
	b[1]=1;
	if (a==1)
	cout<<1<<endl;
	else{
	for(int i=2;i<=a;i++)
	{
		b[i]=b[i-1]+b[i-2];
	}
	cout<<b[a];
	}
	return 0;
}

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

#define PI 3.141592653589793

int main(){

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false); 

	int a,b,h,m;
  	cin >> a >> b >> h >> m;
  	double s=2*PI*abs(60*h-11*m)/double(60*12);
 	s=min(s,2*PI-s);
 	cout << fixed << setprecision(10) << sqrt(a*a+b*b-double(2*a*b*cos(s)));
}

Measured memory_bytes: 4196
#include <iostream>
using namespace std;
int main()
{
int big1;
cin >> big1;
int big2=0;
int big3=0;
int input;
for(int i=2;i<=10;i++)
{cin >> input;
if(input>=big1 && input>=big2 && input>=big3)
{big3=big2;
big2=big1;
big1=input;}
else if(input>=big2 && input>=big3)
{big3=big2;
big2=input;}
else if(input>=big3)
{big3=input;}
}
cout << big1 << endl << big2 << endl << big3 << endl;
return 0;
}


Measured memory_bytes: 2992
import math
S = int(input())
X1 = 0
Y1 = 0
X2 = 0
Y2 = 0
X3 = 0
Y3 = 0
if  S <= 10 ** 9:
    X2 = S
    Y3 = 1
elif S == 1000000000000000000:
    X2 = int(math.sqrt(S))
    Y3 = X2
else:
    X2 = int(math.sqrt(S) + 1)
    Y3 = X2
    s = X2 ** 2  - S #残りの面積
    for i in range(1, int(math.sqrt(s) + 1)):
        if s%i == 0 and s//i <= 10 ** 9 and i <= 10 ** 9:
            X3 = i
            Y2 = s//i
            break

print (X1, Y1, X2, Y2, X3, Y3)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

void inft(){
	printf("infinity\n");
	exit(0);
}
void zero(){
	printf("0\n");
	exit(0);
}

int main(){
	ll t1, t2, a1, a2, b1, b2;
	scanf("%lld%lld%lld%lld%lld%lld", &t1, &t2, &a1, &a2, &b1, &b2);

	ll c1 = b1-a1, c2 = b2-a2;
	if((c1>0 && c2>0) || (c1<0 && c2<0)) zero();
	if(c1 < 0) {
		c1 *= -1;
		c2 *= -1;
	}

	ll d = c1*t1 + c2*t2, e = c1*t1;
	if(d == 0) inft();
	if(d > 0) zero();
	c1 = abs(c1), c2 = abs(c2), d = abs(d), e = abs(e);

	DEBUG("c1=%lld c2=%lld d=%lld e=%lld\n", c1, c2, d, e);
	ll ans = t1*c1/d;
	ans *= 2;
	ans ++;
	if(t1*c1%d == 0) ans--;
	printf("%lld\n", ans);

	// ll ans1 = max(-t1*c1/d, 0LL), ans2 = max(e/(-d), 0LL), ans3 = 0, ans4 = 0;
	// if(0 <= t2 && t2 * c2 < e) ans3 = 1;
	// if(t1*c1%d == 0) ans4 = 1;
	// DEBUG("%lld %lld %lld %lld\n", ans1, ans2, ans3, ans4);
	// ll ans = ans1 + ans2 + ans3 - ans4;
	// printf("%lld\n", ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) x.begin(),x.end()
#define ll long long
#define f first
#define s second
using namespace std;

int main()
{
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    map  < int , int > m;
    int n;
    cin >> n;
    for( int i = 0; i < n; i++)
    {
        int b;
        cin >> b;
        m[b]++;
    }
    if(m.size()!=n)
    {
        cout << "NO";
    }
    else
    {
        cout << "YES";
    }
}


Measured memory_bytes: 9600
N = int(input())
A = list(map(int, input().split()))
max = A[0]
min = 0
sum = 0
for i in range(N-1):
    if(A[i+1]>max):
        max = A[i+1]
    else:
        sum += max - A[i+1]
        
        

print(sum)

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

int main(){
  int n;
  char s[100006];
  int f = 0;
  int fi = -1;
  int en = -1;

  scanf("%s", s);
  n = strlen(s);

  int i;
  for(i = 0;i < n - 1;i++){
    if(s[i] == s[i + 1]){
      f = 1;
      fi = i + 1;
      en = i + 2;
    }
  }

  if(f == 0){
    for(i = 0;i < n - 2;i++){
      if(s[i] == s[i + 2]){
        f = 1;
        fi = i + 1;
        en = i + 3;
      }
    }
  }

  printf("%d %d\n", fi, en);

  return 0;
}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            var S = int.Parse(ReadLine());
            var list = new List<long>();
            foreach (var item in Calc(S))
            {
                if (list.Contains(item))
                {
                    WriteLine(list.Count + 1);
                    break;
                }
                else list.Add(item);
            }
        }

        static IEnumerable<long> Calc(int s)
        {
            long num = s;
            for (int i = 0; ; i++)
            {
                if (i == 0) yield return s;
                num = num % 2 == 0 ? num / 2 : 3 * num + 1;
                yield return num;
            }
        }
    }
}


Measured memory_bytes: 11220
#include <bits/stdc++.h>
#define rep(i,n)  for(int i = 0; i < n; i++)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.rbegin(), cont.rend()
#define unique(a)       sort((a).begin(), a.end()), (a).erase(unique((a).begin(), (a).end()),(a).end())
#define fastio          ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define PB push_back
#define endl "\n"

using namespace std;

typedef long long LL;
typedef long double LD;
typedef vector<int> VI;

LL gcd(LL a, LL b)
{
	if (!a)return b; return gcd(b%a, a);
}
double intlog(double base, double x) {
	return (double)((double)log(x) / (double)log(base));
}

int main()
{
	float a, b;
	cin >> a >> b;
	int i = 0;
	while (1)
	{
		if (((a - 1)*i +1) >= b) {
			cout << i << endl;
			return 0;
		}
		i++;
	}



}













Measured memory_bytes: 256
#include <iostream>
#include <cstdio>

using namespace std;

int main(void){
    int i,j,k,l;
    int n;
    char n_tmp;
    char moji;
    char t[1000];
    
    while(true){
        if((moji=cin.get())==EOF)break;
        if(moji=='\n'){
            cout<<'\n';
            continue;
        }
        if(moji=='@'){
            n_tmp=cin.get();
            n=(int)n_tmp-'0';
            moji=cin.get();
            for(i=0;i<n;i++){
                cout<<moji;
            }
            continue;
        }
        cout<<moji;
    }
    return(0);
}

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

using namespace std;

//using Matrix = vector< vector<int> >;
typedef long long ll;
typedef pair<int, int> P;
//const int INF = 1e9 + 10;
const ll INF = 1e18 + 10LL;
int dx[5] = {0, 0, 1, -1, 0}, dy[5] = {1, -1, 0, 0, 0};
const double EPS = 1e-10;
bool cmp(P a, P b) { return a.second < b.second; } //End sort (Interval scheduling problem)
ll MOD = 1e9 + 7;

int N, K;
ll h[100010];

ll dp[100100];

ll rec(int i) {
	if (dp[i] < INF) return dp[i];

	if (i == 0) return 0;

	ll res = INF;
	for (int j = 1; j <= K; j++) res = min(res, rec(i - j) + abs(h[i] - h[i - j]));

	return dp[i] = res;
}

int main(void){
	cin>>N>>K;
	for (int i = 0; i < N; i++) cin>>h[i];

	for (int i = 0; i < 100100; i++) dp[i] = INF;

	cout<< rec(N - 1) <<endl;
	
	return 0;
}

Measured memory_bytes: 6528
main = do
  line <- getLine
  let
    [n,m] = map read $ words line :: [Int]
    inmat i mat
      | i < n      = do
        line <- getLine
        inmat (i+1) (mat ++ [(map read $ words line :: [Int])])
      | otherwise  = do
        invec 0 [] mat
    invec i vec mat
      | i < m      = do
        line <- getLine
        invec (i+1) (vec ++ [(read $ head $ words line :: Int)]) mat
      | otherwise  = do
        mlt vec mat
    mlt vec mat
      | length mat /= 0  = do
        putStrLn $ show $ dotp vec (head mat)
        -- putStrLn $ (show vec) ++ (show mat)
        mlt vec (tail mat)
      | otherwise        = do
        putStr ""
    dotp a b = dotp_ a b 0
    dotp_ a b sum 
      | length a /= 0 && length b /= 0  = dotp_ (tail a) (tail b) (sum+((head a)*(head b)))
      | otherwise                       = sum
    in
      inmat 0 []



Measured memory_bytes: 7536
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	// AtCoder Beginner Contest 129
	// https://atcoder.jp/contests/abc129/tasks
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		String s = sc.next();
		
		for (int i = 0; i < 3; i++) {
			if (s.charAt(i) == s.charAt(i+1)) {
				System.out.println("Bad");
				System.exit(0);
			}
		}
		System.out.println("Good");
	}
	
	static class FastReader { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() { 
            br = new BufferedReader(new InputStreamReader(System.in)); 
        } 
  
        String next() { 
            while (st == null || !st.hasMoreElements()) { 
                try { 
                    st = new StringTokenizer(br.readLine()); 
                } catch (IOException  e) { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() { 
            String str = ""; 
            try{ 
                str = br.readLine(); 
            } catch (IOException e) { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
}


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

using namespace std;

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

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define rep(i, n) REP(i, 0, n)
const int INF=1e9;
const int MOD =  1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define ALL(v) v.begin(), v.end()
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define pb(x) push_back(x)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbgmap(mp) for (auto i = mp.begin(); i != mp.end(); ++i) { cout << i->first <<":"<<i->second << endl;}
#define sum(v) accumulate(ALL(v),0)
#define lb(v, c) lower_bound((v).begin(), (v).end(), c) - (v).begin()
#define ub(v, c) upper_bound((v).begin(), (v).end(), c) - (v).begin()

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s, t;
    cin>>s>>t;
    ll tlength=t.size();
    ll slength=s.size();
    vector<vector<ll>> smp(30);
    rep(i, slength) {
        smp[s[i]-'a'].pb(i+1);
    }

    ll ans=0;
    ll now=0;
    ll loc=0;
    rep(i, tlength) {
        vector<ll> &v = smp[t[i]-'a'];
        if(v.size()<=0){
            cout << -1 << endl;
            return 0;
        }else{
            auto itr = upper_bound(ALL(v), now);
            if(itr==v.end()){
                loc = *v.begin();
                ans += slength;
            }else{
                loc = *itr;

            }
            //dbg(loc);
            now=loc;
        }

    }
    ans += loc;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1736
import math

#整数 N が与えられます。
#N 以下の正の整数のうち、(先頭に 0 をつけずに十進法で表記したときの) 桁数が奇数であるようなものの個数を求めてください

#11 9
#136 46
#100000 90909

#N/10 + 1で桁数が求まる

N = int(input())
ans = 0

for i in range(1,N+1,1):
    #print(i,":",int(math.log10(i)))
    if (int(math.log10(i)) + 1)%2==1:
        ans = ans+1
        #print("add")
        
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;
ll mod = 1e9 + 7;
struct matrix{
    int h,w;
    vector<vector<ll> > mat;
    matrix(){}
    matrix(int h,int w,ll val):h(h),w(w),mat(h,vector<ll>(w,val) ){}
    matrix(int h,int w):h(h),w(w),mat(h,vector<ll>(w) ){}
    matrix(int n):h(n),w(n),mat(n,vector<ll>(n,0) ){}
    matrix(vector<vector<ll> > mat):h(mat.size() ),w(mat[0].size() ),mat(mat){}
    //単位行列
    void eye(){
	if(h!=w)return ;
	for(int i=0;i<h;i++)for(int j=0;j<w;j++)if(i==j)mat[i][j] = 1;
	else mat[i][j] = 0;
    }
    //演算子
    matrix operator + (matrix a){
	vector<vector<ll> > res(h,vector<ll>(w,0) );
	for(int i=0;i<h;i++)
	    for(int j=0;j<w;j++){
		res[i][j] = (mat[i][j] + a.mat[i][j])%mod;
	    }
	return matrix(res);
    }
    matrix operator - (matrix a){
	vector<vector<ll> > res(h,vector<ll>(w,0) );
	for(int i=0;i<h;i++)
	    for(int j=0;j<w;j++){
		res[i][j] = (mat[i][j] - a.mat[i][j])%mod;
	    }
	return matrix(res);
    }
    matrix operator * (matrix a){
	vector<vector<ll> > res(h,vector<ll>(a.w,0)  );
	for(int i=0;i<h;i++)
	    for(int j=0;j<a.w;j++)
		for(int k=0;k<w;k++) {
		    res[i][j] += mat[i][k]*a.mat[k][j];
		    res[i][j] %= mod;
		}
	return matrix(res);
    }

    ll sum(){
	ll res = 0;
	for(int i=0;i<h;i++)for(int j=0;j<w;j++) {
	    res += mat[i][j];
	    res %= mod;
	}
	return res;
    }
};



int main(){
    ll n,k;
    cin>>n>>k;
    vector<matrix> dp( 62 , matrix(n) );
    vector<vector<ll> > a(n,vector<ll>(n,0) );
    for(int i=0;i<n;i++)for(int j=0;j<n;j++) cin>>a[i][j];
    dp[0] = a;
    for(int i=1;i<62;i++){
	dp[i] = dp[i-1] * dp[i-1];
    }
    matrix res = matrix(n);
    res.eye();
    for(int i=0;i<62;i++){
	if( (k>>i)&1 ) res = res * dp[i];
    }
    cout<<res.sum()<<endl;
    return 0;
}


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

using namespace std;

const int N = 1e5 + 20;
int a[N], dp[N];
int INF = 0x3f3f3f3f;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	
	memset(dp, INF, sizeof dp);
	int n, k;
	cin >> n >> k;
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	dp[1] = 0;
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= k && i - j >= 1; j++) {
			dp[i] = min(dp[i], dp[i - j] + abs(a[i - j] - a[i]));
		}
	}
	cout << dp[n] << "\n";

	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
    using namespace std;
    using ll = long long;
    using ld = long double;
     
    signed main() {
    #ifdef LOCAL
      assert(freopen("a.in", "r", stdin));
    #endif
      ll k, a, b;
      cin >> k >> a >> b;
      if (a >= k) {
        cout << 1 << '\n';
        return 0;
      }
      if (b >= a) {
        cout << -1 << '\n';
        return 0;
      }
      k -= a;
      ll d = a - b;
      cout << 1 + 2 * ((k + d - 1) / d) << '\n';
    }

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
#define INF 1200000000



int main(){
    long long N;
    cin>>N;
    long long  cnt=0;

    if(N%2==1){
        cout<<0<<endl;
        return 0;
    }
    else{
        long long five=10;
        while(1){
            if(N/five==0)break;
            cnt+=N/five;
            five*=5;
        }
    }
    
    cout<<cnt<<endl;
    
}




Measured memory_bytes: 256
n = int(input())
h = [int(x) for x in input().split()]
l = [0, abs(h[1] - h[0])]
for i in range(1, n - 1):
    l.append(min(l[i-1] + abs(h[i-1] - h[i+1]),
                 l[i] + abs(h[i] - h[i+1])))
print(l[-1])

Measured memory_bytes: 13928
K,S = map(int, input().split())
n = 0
for i in range(max(S-2*K,0),min(K+1,S+1)):
    X = i
    for j in range(max(S-i-K,0),min(K+1,S-i+1)):
        Y = j
        Z = S - i - j
        n += 1
print(n)

Measured memory_bytes: 3060
import sys
sys.setrecursionlimit(10**6)

N = int(input())
A = list(map(int,input().split()))
dp = [-1]*(N+2)
dp[0] = 0
dp[1] = abs(A[1] - A[0])


def rec(i):
  if dp[i] != -1:
    return dp[i]
  dp[i] = min(rec(i-1) + abs(A[i-1] - A[i]), rec(i-2) + abs(A[i-2] - A[i]))
  return dp[i]

print(rec(N-1))

Measured memory_bytes: 94096
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>
#include <iomanip>

#define int long long
#define REP(i,a,n) for(int i=a;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define REV(i,a,n) for(int i=n;i>=a;--i)
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define show(n) cerr<<#n<<" = "<<n<<endl
#define showp(n) cerr<<n.fs<<", "<<n.sc<<endl
#define shows(n) for(auto z:n){cerr<<z<<", ";}cerr<<endl
#define showsp(n) for(auto z:n){cerr<<z.fs<<" "<<z.sc<<", "}cerr<<endl

#define yes puts("Yes")
#define no puts("No")
#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int,int>;

inline void io(){cin.tie(0);ios::sync_with_stdio(false);cout.tie(0);cout<<fixed<<setprecision(20);}
inline int  in(){int n;scanf("%lld",&n);return n;}
inline void out(int n){printf("%lld\n",n);}

const int INF=1LL<<55;
const int MOD=1000000007;
const double EPS=1e-8;

int n;

signed main(){
    io();
    cin>>n;
    if(n&1){
        cout<<n*2<<endl;
    }else{    
        cout<<n<<endl;
    }


    return 0;
}



Measured memory_bytes: 888
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

int main(){
    double a,b; cin>>a>>b;
    for(int i=1;i<1001;i++){
        if(int(i*0.08)==a&&int(i*0.1)==b){
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
k, n = map(int, input().split())
a = list(map(int, input().split()))
fst = a[0]
a.append(k+fst)
dis= []
for i in range(n):
    dis.append(a[i+1]-a[i])
print(sum(dis)-max(dis))

Measured memory_bytes: 32292
#include <bits/stdc++.h>
using namespace std;
int main(){
  while (1){
    string S;
    getline(cin, S);
    if (S == "."){
      break;
    }
    int N = S.size();
    bool ok = true;
    stack<char> st;
    st.push('@');
    for (int i = 0; i < N; i++){
      if (S[i] == '('){
        st.push('(');
      }
      if (S[i] == '['){
        st.push('[');
      }
      if (S[i] == ')'){
        if (st.top() != '('){
          ok = false;
          break;
        } else {
          st.pop();
        }
      }
      if (S[i] == ']'){
        if (st.top() != '['){
          ok = false;
          break;
        } else {
          st.pop();
        }
      }
    }
    if (st.size() != 1){
      ok = false;
    }
    if (ok){
      cout << "yes" << endl;
    } else {
      cout << "no" << endl;
    }
  }
}


Measured memory_bytes: 3084