akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<bool>> vvbool;

const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const double PI = 3.14159265358979323846264338327950288;
//========================================================================

int gcd(int a, int b);

int main() {
	
	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	//==================================
	
	
	int N, K;
	cin >> N >> K;

	vint A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}


	if (N == 1) {

		if (A[0] == K) {
			cout << "POSSIBLE";

		}

		else {
			cout << "IMPOSSIBLE";
		}


	}
	else {

		int gc = gcd(A[0], A[1]);

		for (int i = 0; i < N; i++) {
			gc = gcd(gc, A[i]);
		}
		

		sort(A.begin(), A.end());


		if (K % gc == 0 && K <= A[N-1]) {
			cout << "POSSIBLE";
		}
		else {
			cout << "IMPOSSIBLE";
		}

	}





}



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

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

	return b;
}


Measured memory_bytes: 640
dicpos = {}
dicneg = {}

N = int(input())
for i in range(N):
  buf = [0]
  for s in input():
    if s=="(":
      buf.append(buf[-1] + 1)
    else:
      buf.append(buf[-1] - 1)
  low = min(buf)
  last = buf[-1]
  if last>0:
    if low in dicpos:
      dicpos[low].append(last)
    else:
      dicpos[low] = [last]
  else:
    if low-last in dicneg:
      dicneg[low-last].append(-last)
    else:
      dicneg[low-last] = [-last]
neg_sorted = sorted(dicneg.items(), key=lambda x:x[0], reverse=True)
pos_sorted = sorted(dicpos.items(), key=lambda x:x[0], reverse=True)
#print(neg_sorted)
#print(pos_sorted)
summ = 0
flag = 0
for i in pos_sorted:
  if flag == 1:
    break
  for j in i[1]:
    if summ + i[0] < 0:
      flag = 1
      print("No")
      break
    summ += j
summ2 = 0
if flag == 0:
  for i in neg_sorted:
    if flag == 1:
      break
    for j in i[1]:
      if summ2 + i[0] < 0:
        flag = 1
        print("No")
        break
      summ2 += j
if flag == 0:
  if summ == summ2:
    print("Yes")
  else:
    print("No")

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

int main() {
  int n=0, a=0, alice=0, bob=0;
  cin >> n;
  
  vector<int> vec(n);
  
  for (int i=0; i<n; i++) {
    cin >> a;
    vec.at(i) = a;
  }
  
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  
  for (int i=0; i < vec.size(); i++) {
    if (i%2 == 0) alice += vec.at(i);
    else bob += vec.at(i);
  }
  
  
  cout << alice - bob << endl;
  
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
template<typename T> using v = vector<T>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
void dumplist_debug(T list) {
#ifdef MY_DEBUG
    each(e, list) cout << e << " ";
    printf("\n");
#endif
}

inline ll inl() {
    ll x;
    cin >> x;
    return x;
}

inline string ins() {
    string x;
    cin >> x;
    return x;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

struct stx {
    ll s, t, x;

    stx(ll s, ll t, ll x) : s(s), t(t), x(x) {}
};

int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
#pragma clang diagnostic pop
#endif

        ll n = inl(), q = inl();
        v<stx> v;
        rep(i, n) {
            ll s, t, x;
            cin >> s >> t >> x;
            stx temp(s, t, x);
            v.eb(temp);
        }
        set<P> set1;
        rep(i, q) {
            ll d = inl();
            set1.insert(P(d, i));
        }
        auto comp = [](stx &a, stx &b) {
            if (a.x == b.x) {
                if (a.s == b.s) return a.t < b.t;
                return a.s < b.s;
            }
            return a.x < b.x;
        };
        sort(all(v), comp);

        vl ans(q, -1);
        rep(i, n) {
            ll s = v[i].s, x = v[i].x, t = v[i].t;
            auto it = set1.lower_bound(P(s - x, -1));
            while (it != set1.end()) {
                if (t - x <= it->F) break;
                ans[it->S] = x;
                set1.erase(it++);
            }
        }
        rep(i, q) cout << ans[i] << endl;


#ifdef MY_DEBUG
    }
#endif
    return 0;
}

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

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

using namespace std;

int countBit(int a)
{
  a = (a & 0x5555) + ((a & 0xAAAA) >> 1);
  a = (a & 0x3333) + ((a & 0xCCCC) >> 2);
  a = (a & 0x0F0F) + ((a & 0xF0F0) >> 4);
  a = (a & 0x00FF) + ((a & 0xFF00) >> 8);
  return a;
}

int main()
{
  int n, m;
  cin >> n >> m;
  int mask[10] = {};

  int big = 1;
  REP(i, n - 1)
  {
    big = big << 1;
    big++;
  }

  REP(i, m)
  {
    int k;
    cin >> k;
    REP(j, k)
    {
      int s;
      cin >> s;
      mask[i] += (1 << (s - 1));
    }
  }

  int p[10];

  REP(i, m)
  {
    cin >> p[i];
  }

  int result = 0;
  REP(i, big + 1)
  {
    bool flag = true;
    REP(j, m)
    {
      int c = countBit(i & mask[j]);
      if (c % 2 != p[j])
      {
        flag = false;
        break;
      }
    }
    if (flag)
    {
      result++;
    }
  }

  cout << result << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef    pair<int,int> pii;
typedef    pair<int,pii> ppi;
typedef    pair<pii,int> pip;
typedef    long long int ll;
typedef    unsigned long long int ull;
typedef    pair<ll,ll> pll;
typedef    vector<int> VI;
typedef    vector<pii> Vii;
typedef    vector<VI> VVI;// 2D
//typedef    priority_queue<int> PQ;// MaxHeap
typedef    priority_queue<int,VI,greater<int> > PQ;// MinHeap
//int Dx[] ={-1,0, 0,1};
//int Dy[] ={ 0,1,-1,0};
//int Dx8[]={-1,-1,-1,0,1,1, 1, 0};
//int Dy8[]={-1, 0, 1,1,1,0,-1,-1};
//int Kx[] ={2,1,-1,-2,-2,-1, 1, 2};
//int Ky[] ={1,2, 2, 1,-1,-2,-2,-1};

// code starts from here
#define pi acos(-1.0)
const int MAX=1e6+10,MOD=1e9+7;
void solve(){
    int n,k;cin >> k;
    string s;cin>>s;
    n = s.size();
    if(n<=k){
        cout<<s<<endl;
        return;
    }
    for(int i=1;i<=n;i++){
        if(i>k)break;
        else cout<<s[i-1];
    }
    cout<<"..."<<endl;
}
int main (){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    while(t--)solve();
    return 0;
}



Measured memory_bytes: 3612
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int preT = 0;
        int preX = 0;
        int preY = 0;

        for (int i=0; i<N; i++) {
            int postT = sc.nextInt();
            int postX = sc.nextInt();
            int postY = sc.nextInt();

            int dt = postT - preT;
            int dist = Math.abs(postX - preX) + Math.abs(postY - preY);
            if ((dt < dist) || ((dist - dt) % 2 != 0)) {
                System.out.println("No");
                return;
            }

            preT = postT;
            preX = postX;
            preY = postY;
        }

        System.out.println("Yes");
    }
}

Measured memory_bytes: 58572
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        Integer[] l = new Integer[n];
        Arrays.setAll(l, i -> Integer.parseInt(sc.next()));
        sc.close();

        // 主処理
        Arrays.sort(l, Collections.reverseOrder());
        int result = 0;
        for (int i = 0; i < l.length - 2; i++) {
            for (int j = i + 1; j < l.length - 1; j++) {
                for (int k = j + 1; k < l.length; k++) {
                    if (l[i] < l[j] + l[k]) {
                        result++;
                    }
                }
            }
        }

        // 出力
        System.out.println(result);
    }
}


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

using namespace std;

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    long long n,prod=1,sum=1;
    cin>>n;
    while(n!=0)
    {
       n=n/2;
       sum=sum+(prod*2);
       prod=prod*2;
    }
    cout<<sum-prod<<endl;
    return 0;
}


Measured memory_bytes: 256
from collections import defaultdict, deque

N, M = map(int, input().split())

dic = defaultdict(set)
for _ in range(M):
    A, B = map(int, input().split())
    dic[A].add(B)
    dic[B].add(A)


colors = [0]*(N+1)

def dfs():
    que = deque([(1, 1)])

    while len(que):
        v, color = que.popleft()
        colors[v] = color
        for to in list(dic[v]):
            if (color == colors[to]):
                return False
            if (colors[to] == 0):
                que.append((to, -color))
                
    return True


flag = dfs()
b = colors.count(1)

print(b*(N-b) - M if (flag) else N*(N-1)//2 - M)


Measured memory_bytes: 96728
solve :: [Integer] -> Integer -> Integer -> Integer -> Integer
solve [] _ _ acc = acc
solve (x:xs) end_of_water t acc
  | end_of_water <= x = solve xs (x+t) t (acc+t)
  | otherwise          = solve xs (x + t) t (acc - (end_of_water - x) + t)

main = do
     nt <- words <$> getLine
     let n = read $ (nt !! 0) :: Integer
     let t = read $ (nt !! 1) :: Integer
     -- putStrLn $ show $ n
     -- putStrLn $ show $ t

     ts_str <- words <$> getLine
     let ts = map (\s -> read s :: Integer) ts_str
     let ans = solve ts 0 t 0
     putStrLn $ show $ ans
     return ()


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define Abs(x)((x) < 0 ? (x) * -1 : (x))
#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y) - 1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define nepit(x) for (__typeof((x).rbegin()) it = (x).rbegin(); it != (x).rend(); it++)
#define All(x) (x).begin(),(x).end()
#define Mem0(x) memset(x, 0, sizeof(x))
#define Mem1(x) memset(x, -1, sizeof(x))
#define End '\n'
#define Out(x) cout<<(x)<<End
template<typename T> inline bool Max(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool Min(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T> >;

#define pb push_back
#define mp make_pair
#define X first
#define Y second

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

#define LOCAL 0

int main()
{
#if LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, i;

    cin >> n >> i;

    Out(n - i + 1);

    return 0;
}


Measured memory_bytes: 256
def dfs(n,k,a)
  return nil if n<0
  if k==K.size
    return n.zero? ? a : nil
  end
  c=S[K[k]]
  r1=dfs(n-K[k], k, a+[c])
  r2=dfs(n, k+1, a)
  return r2 unless r1
  return r1 unless r2
  return r1 if r2.size < r1.size
  return r2 if r1.size < r2.size
  r1.sort.reverse.to_s < r2.sort.reverse.to_s ? r2 : r1
end

B=[0,2,5,5,4,5,6,3,7,6]

N,M=gets.split.map(&:to_i)
A=gets.split.map(&:to_i)

S=Hash.new{|h,k|h[k]=0}
A.each do |a|
  S[B[a]]=[S[B[a]],a].max
end
K=S.keys.sort

n,r=N.divmod(K[0])
m=[10,n-1].min
n-=m
r+=K[0]*m
until n.zero?
  n-=1
  r+=K[0]
  ok=dfs(r,0,[])
  next unless ok
  ok.sort!.reverse!
  i=0
  ok.each do |c|
    i+=1 if S[K[0]]<c
  end
  print ok[0...i]*""
  print S[K[0]].to_s*n
  print ok[i..-1]*""
  puts
  exit
end


Measured memory_bytes: 3836
import java.util.*;

public class Main{
    public static void main(String[]args){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int m=sc.nextInt();
        long ans=0;
        Map <Long,Long>map=new TreeMap<>();
        for(int i=0;i<n;i++){
            long a=sc.nextLong();
            long b=sc.nextLong();
            if(map.get(a)!=null){
                map.put(a,b+map.get(a));
            }else{
                map.put(a,b);
            }
        }
        for(long key:map.keySet()){
            if(map.get(key)<=m){
                ans+=key*map.get(key);
                m-=map.get(key);
            }else{
                ans+=key*m;
                break;
            }
        }
        System.out.println(ans);

    }
}

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

void tekichu(string s, string t){
    int cnt = 0;
    for(int i=0;i<3;i++){
        if(s.at(i)==t.at(i)){
            cnt += 1;
        }
    }
    cout << cnt << endl;
}

int main(){
    string s,t; cin >> s >> t;
    tekichu(s,t);
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  const int maxA = 60, maxN = 60;
  int N;
  while (cin >> N) {
    vector<int> a(N), b(N);
    for (int i = 0; i < N; i++) {
      cin >> a[i];
    }
    for (int i = 0; i < N; i++) {
      cin >> b[i];
    }
    bool reachable[maxA][maxA][maxA];
    memset(reachable, false, sizeof(reachable));
    for (int i = 0; i < maxA; i++) {
      for (int j = 0; j < maxA; j++) {
        reachable[0][i][i] = true;
      }
    }
    for (int k = 1; k < maxA; k++) {
      for (int i = 0; i < maxA; i++) {
        for (int j = 0; j < maxA; j++) {
          reachable[k][i][j] =
              reachable[k - 1][i][j] | reachable[k - 1][i % k][j];
        }
      }
    }
    bool ok = true;
    for (int i = 0; i < N; i++) {
      ok &= reachable[maxA - 1][a[i]][b[i]];
    }
    if (!ok) {
      cout << -1 << endl;
      continue;
    }
    bool available[maxA][maxN][maxA];
    memset(available, false, sizeof(available));
    for (int i = 0; i < N; i++) {
      available[0][i][a[i]] = true;
    }
    ll res = 0, ks = 0;
    for (int k = maxA - 1; k >= 1; k--) {
      bool need = false;
      for (int i = 0; i < N; i++) {
        bool found = false;
        for (int a = 0; a < maxA; a++) {
          if (available[ks][i][a] && reachable[k - 1][a][b[i]]) {
            found = true;
            break;
          }
        }
        if (!found) {
          need = true;
          break;
        }
      }
      if (need) {
        for (int i = 0; i < N; i++) {
          for (int a = 0; a < maxA; a++) {
            available[ks + 1][i][a] |= available[ks][i][a];
            available[ks + 1][i][a % k] |= available[ks][i][a];
          }
        }
        ++ks;
        res += 1ll << k;
      }
    }
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 768
from itertools import combinations_with_replacement, combinations

def gen_dict(nums):
    r = {}
    for i in nums:
        if i in r.keys():
            r[i] += 1
        else:
            r[i] = 1
    return r

def has_more_4(num_dict):
    for i in num_dict.values():
        if i > 4: return True
    return False

def gen_conseq3(nums):
    r = []
    for i in range(1, 8):
        for j in range(i, i+3):
            if j not in nums: break
        else:
            r.append((i, i+1, i+2))
    return r

def gen_same(n, num_dict):
    r = []
    for i, v in num_dict.items():
        if v >= n: r.append(i)
    return r

def gen_prec(c1s, c2s, c3):
    r = []
    for i in c1s:
        for j in i:
            r.append(j)
    for i in c2s:
        for j in range(3): r.append(i)
    for j in range(2):
        r.append(c3)
    return sorted(r)

while True:
    try: line = input()
    except EOFError: break
    
    founds = []
    for i in range(1, 10):
        ln = line + str(i)
        nums = sorted(list(map(int, ln[:])))
        num_dict = gen_dict(nums)
        if has_more_4(num_dict):
            continue
        conseq_3s = gen_conseq3(nums)
        same_3s = gen_same(3, num_dict)
        same_2s = gen_same(2, num_dict)
        was_found = False
        for r in range(1, 5):
            if was_found: break
            for c1s in combinations_with_replacement(conseq_3s, r):
                if was_found: break
                for c2s in combinations(same_3s, 4-r):
                    if was_found: break
                    for c3 in same_2s:
                        pred = gen_prec(c1s, c2s, c3)
                        if pred == nums:
                            founds.append(str(i))
                            was_found = True
    if founds:
        print(' '.join(founds))
    else:
        print(0)



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

int main(){
  string w;
  cin >> w;
  vector<int> a(26);
  for(int i=0;i<w.size();i++){a.at(w.at(i)-97)++;}
  string ans="Yes";
  for(int i=0;i<26;i++){
    if(a.at(i)%2==1)
      ans="No";
  }
  cout << ans << endl;
}

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

using namespace std;

int main(){
  int N, M;
  cin >> N >> M;
  
  vector<vector<int>> V(N,vector<int>(N,0));
  
  for(int i = 0; i < M; i++){
    int a, b;
    cin >> a >> b;
    a--, b--;
    V[a][b]++;
    V[b][a]++;
  }
  for(int i = 0; i < N; i++){
    int t = 0;
    for(int j = 0; j < N; j++){
      t += V[i][j];
    }
    cout << t << endl;
  }
}


Measured memory_bytes: 256
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    if (n < 1000) {
        cout << "ABC\n";
    } else {
        cout << "ABD\n";
    }

    return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		FastScanner in = new FastScanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskD solver = new TaskD();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskD {
		long ans;

		public void solve(int testNumber, FastScanner in, PrintWriter out) {
			int n = in.nextInt();
			int W = in.nextInt();
			int[] w = new int[n];
			int[] v = new int[n];
			for (int i = 0; i < n; i++) {
				w[i] = in.nextInt();
				v[i] = in.nextInt();
			}
			List<Integer>[] vs = new List[4];
			for (int i = 0; i < vs.length; i++) {
				vs[i] = new ArrayList<>();
			}
			for (int i = 0; i < n; i++) {
				vs[w[i] - w[0]].add(v[i]);
			}
			for (int i = 0; i < vs.length; i++) {
				Collections.sort(vs[i]);
				Collections.reverse(vs[i]);
			}
			ans = 0;
			rec(w[0], 0, 0, 0L, W, vs);
			out.println(ans);
		}

		private void rec(int w0, int curList, int curPos, long curSum, int w, List<Integer>[] vs) {
			ans = Math.max(ans, curSum);
			if (curList == vs.length) {
				return;
			}
			rec(w0, curList + 1, 0, curSum, w, vs);
			if (curPos < vs[curList].size()) {
				int nw = w - (w0 + curList);
				if (nw >= 0) {
					rec(w0, curList, curPos + 1, curSum + vs[curList].get(curPos), nw, vs);
				}
			}
		}

	}

	static class FastScanner {
		private BufferedReader in;
		private StringTokenizer st;

		public FastScanner(InputStream stream) {
			in = new BufferedReader(new InputStreamReader(stream));
		}

		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					String rl = in.readLine();
					if (rl == null) {
						return null;
					}
					st = new StringTokenizer(rl);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

	}
}



Measured memory_bytes: 21972
#include <iostream>

int main() {
    int a, b, c, tmp;
    std::cin >> a; std::cin >> b; std::cin >> c;
    if (a > b) {
        tmp = a;
        a = b;
        b = tmp;
    }
    if (a > c) {
        tmp = a;
        a = c;
        c = tmp;
    }
    if (b > c) {
        tmp = b;
        b = c;
        c = tmp;
    }
    std::cout << a << ' ' << b << ' ' << c << '\n';
    return 0;
}



Measured memory_bytes: 3092
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <iostream>
#include <sstream>
#include <string>
#include <iomanip>
#include <set>
#include <map>

using namespace std;

#define EPS 1e-14
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) FOR(i, 0, n)
#define PI 2*acos(0.0)
#define ALL(a) (a).begin(),(a).end()
#define DEBUG(x) cout<<#x <<": "<< x << "\n"
#define DEBUG_ARR(a) REP(i, size(a)){ cout << #a << "[" << i << "]: " << a[i] << "\n"; }
const int VX[] = { 0, 1, 0, -1 };
const int VY[] = { 1, 0, -1, 0 };
const long MOD = 1000000007;

int main() {
	//	--- I/O 高速化 ---
	cin.tie(0);
	ios::sync_with_stdio(false);
	// --- ここまで ---

	long long N;
	cin >> N;

	int min = log10(N) + 1;
	for (long long i = 1; i <= sqrt(N); i++) {
		if (N % i == 0) {
			long long A = i;
			long long B = N / i;

			if (max(floor(log10(A)) + 1, floor(log10(B)) + 1) < min) {
				min = max(floor(log10(A)) + 1, floor(log10(B)) + 1);
			}
			else if (max(floor(log10(A)) + 1, floor(log10(B)) + 1) > min) {
				break;
			}
		}
	}
	cout << min << endl;

	return 0;
}



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

int main(){
    int n;
    while(cin >> n, n){
        cin.ignore();
        map<string, int> dic;
        for(int i=0; i < n; i++){
            string s;
            getline(cin, s);
            s += " ";
            while(s.size() != 0){
                string word = s.substr(0, s.find_first_of(" "));
                s = s.substr(s.find_first_of(" ")+1);
                dic[word]--;
            }
        }
        vector<pair<int, string> > v;
        map<string, int>::iterator it = dic.begin();
        while(it != dic.end()){
            v.push_back(make_pair((*it).second, (*it).first));
            it++;
        }
        sort(v.begin(), v.end());

        string initial;
        cin >> initial;
        bool isFirst = true;
        int count = 0;
        for(int i=0; i < v.size(); i++){
            if(v[i].second.substr(0, 1) == initial){
                if(isFirst){ cout << v[i].second; isFirst = false;}
                else cout << " " << v[i].second;
                count++;
            }
        }
        if(count == 0) cout << "NA" << endl;
        else cout << endl;

        dic.clear();
    }
}

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

using namespace std;
using ll = long long;

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

int main(){
    int m;
    cin >> m;
    cout << 48-m << endl;


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
signed main(void){
    long double t1, t2; cin>>t1>>t2;
    long double a1,a2; cin>>a1>>a2;
    long double b1,b2; cin>>b1>>b2;
    if(t1*a1+t2*a2 == t1*b1+t2*b2) {cout<<"infinity"<<endl; return 0;}
    if(t1*a1+t2*a2<t1*b1+t2*b2){
        swap(a1,b1); swap(a2,b2);
    }
    int ans = 0;
    if(a1*t1 - b1*t1 < 0){
    long double p = t1*a1+t2*a2 - (t1*b1+t2*b2);
    long double x = max( (t1*a1 - t1*b1)/(-p), (t1*a1 - t1*b1)/(p));
    long double y = ceil(x);
    ans = y * 2;
    ans--;
    if( x == y) ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
using namespace std;
#define ll long long
const long long mod = 1e9 + 7;

int main() {
	ll n, ans = 0;
	ll p[30];
	cin >> n;
	for (int i = 0; i < n; i++)cin >> p[i];
	for (ll i = 1; i < n - 1; i++) {
		if ((p[i - 1] < p[i] && p[i] < p[i + 1]) || (p[i + 1] < p[i] && p[i] < p[i - 1]))ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<set>
#include <stdlib.h> 
using namespace std;

int main(){
  int N;
  cin >> N;
  int D[N];
  for (int n=0; n <N ; n++)cin >> D[n];
  set<int> ans;
  for (int i = 0; i < N; i++)
  {
    ans.insert(D[i]);
  }
  cout<< ans.size() << "\n";
  return 0;
}

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

using namespace std;

using int64 = long long;


int N;
string S;
int64 dp[19][19];

int64 rec(string &a, string &b, int idx, int x, int y) {
  if(idx == N) return 1;
  if(~dp[x][y]) return dp[x][y];
  int64 ret = 0;
  if(x < a.size() && S[N + idx] == a[x]) ret += rec(a, b, idx + 1, x + 1, y);
  if(y < b.size() && S[N + idx] == b[y]) ret += rec(a, b, idx + 1, x, y + 1);
  return dp[x][y] = ret;
}

int main() {

  cin >> N;
  cin >> S;

  map< pair< string, string >, int > add;
  for(int i = 0; i < (1 << N); i++) {
    string x, y;
    for(int j = 0; j < N; j++) {
      if((i >> j) & 1) x += S[j];
      else y += S[j];
    }
    ++add[{x, y}];
  }
  int64 ret = 0;
  for(auto p : add) {
    string a, b;
    tie(a, b) = p.first;
    while(a.size() < N) a += "?";
    reverse(begin(b), end(b));
    while(b.size() < N) b += "?";
    reverse(begin(b), end(b));

    string x, y;
    for(int i = 0; i < a.size(); i++) {
      if(a[i] == '?') x += b[i];
    }
    reverse(begin(x), end(x));
    for(int i = 0; i < b.size(); i++) {
      if(b[i] == '?') y += a[i];
    }

    reverse(begin(y), end(y));
    memset(dp, -1, sizeof(dp));


    ret += rec(x, y, 0, 0, 0) * p.second;

  }
  cout << ret << endl;
}

Measured memory_bytes: 46080
X, N = map(int, input().split())
p = list(map(int, input().split()))
ans = 10000
flg = 200
for i in range(X - 100, X + 101):
    if i in p:
        continue
    if flg > abs(X - i):
        flg = abs(X - i)
        ans = i
print(ans)


Measured memory_bytes: 9172
a,b,c,d = map(int,input().split())
def getmax(a,b):
    if a>b:
        return a
    else:
        return b
def getmin(a,b):
    if a<b:
        return a
    else:
        return b
if (a>0 and b>0 and c<0 and d<0) or (a<0 and b<0 and c>0 and d>0):
    x = getmin(a,b)
    y = getmax(c,d)
    max = x*y
    x = getmax(a,b)
    y = getmin(c,d)
    min = x*y
    if max > min:
        print(max)
    else:
        print(min)
else:
    x = getmax(a,b)
    y = getmax(c,d)
    max = x*y
    x = getmin(a,b)
    y = getmin(c,d)
    min = x*y
    if max > min:
        print(max)
    else:
        print(min)


Measured memory_bytes: 9244
n = int(input())
ws = list(map(int, input().split(' ')))
s = sum(ws)
tmp = 0
anss = [0 for _ in range(n)]

for t in range(n):
	tmp += ws[t]
	anss[t] = s - (2 * tmp)
	if(anss[t] == 0):
		print(anss[t])
		break
	elif(anss[t] < 0):
		if(anss[t-1] > abs(anss[t])):
			print(abs(anss[t]))
		else:
			print(anss[t-1])
		break

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD (long long)(1e9+7)
int main(){
	ll a,b;
	cin>>a>>b;
	if(a>=b+b-1){
		cout<<"YES"<<endl;
	}
	else cout<<"NO"<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
	using namespace std;
	#define sim template < class c
	#define ris return * this
	#define dor > debug & operator <<
	#define eni(x) sim > typename \
	enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
	sim > struct rge { c b, e; };
	sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
	sim > auto dud(c* x) -> decltype(cerr << *x, 0);
	sim > char dud(...);
	struct debug {
	#ifdef LOCAL
	~debug() { cerr << endl; }
	eni(!=) cerr << boolalpha << i; ris; }
	eni(==) ris << range(begin(i), end(i)); }
	sim, class b dor(pair < b, c > d) {
	ris << "(" << d.first << ", " << d.second << ")";
	}
	sim dor(rge<c> d) {
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
	}
	#else
	sim dor(const c&) { ris; }
	#endif
	};
	#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
	#define deb debug()
	#define lel(...) deb << " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
	#define ll long long
	#define all(x) (x).begin(), (x).end()
	// 
using namespace std;
 
const int N = 50010;
ll mod = 998244353;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;} 


int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, x, y;
	cin >> n >> x >> y;
	vector<int> ans(n + 1);
	vector<vector<int>> tab(n + 1);
	for (int a = 1; a < n; a++) {
		tab[a].push_back(a + 1);
		tab[a + 1].push_back(a);
	}
	tab[x].push_back(y);
	tab[y].push_back(x);
	queue<int> q;
	vector<int> dis(n + 1);
	for (int a = 1; a <= n; a++) {
		q.push(a);
		dis[a] = 1;
		while (!q.empty()) {
			int w = q.front();
			q.pop();
			for (int v : tab[w]) {
				if (dis[v] == 0) {
					dis[v] = dis[w] + 1;
					q.push(v);
					ans[dis[v] - 1]++;
				}
			}
		}
		dis = vector<int>(n + 1, 0);
	}
	for (int a = 1; a < n; a++) {
		cout << ans[a] / 2 << endl;
	}

	
	
	return 0;
}

Measured memory_bytes: 384
h,w = map(int,input().split())
map_input = [[1 if j=='#' else 0 for j in list(input())] for i in range(h)]

h_li = [0]*h
w_li = [0]*w

for i in range(h):
    for j in range(w):
        h_li[i]+=map_input[i][j]
        w_li[j]+=map_input[i][j]

for i in range(h):
    if h_li[i]==0:
        continue
    tmp=[]
    for j in range(w):
        if w_li[j]==0:
            continue
        tmp.append(map_input[i][j])
    print(''.join(['.' if k==0 else '#' for k in tmp]))

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

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

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

class Prints {
private:
    class __Prints {
    public:
        __Prints(const char* sep, const char* term) : sep(sep), term(term) {}
        template <class... Args>
        void operator()(Args&&... args) const { print(std::forward<Args>(args)...); }

    private:
        const char *sep, *term;
        void print() const { std::cout << term; }
        void print_rest() const { std::cout << term; }
        template <class T, class... Tail>
        void print(T&& head, Tail&&... tail) const { std::cout << head, print_rest(std::forward<Tail>(tail)...); }
        template <class T, class... Tail>
        void print_rest(T&& head, Tail&&... tail) const { std::cout << sep << head, print_rest(std::forward<Tail>(tail)...); }
    };

public:
    Prints() {}
    __Prints operator()(const char* sep = " ", const char* term = "\n") const { return __Prints(sep, term); }
    template <class T>
    void print_vec(const std::vector<T>& vec, const char* sep = " ", const char* term = "\n") const {
        const size_t sz = vec.size();
        for (size_t i = 0; i < sz; i++) std::cout << vec[i] << (i == sz - 1 ? term : sep);
    }
};

Prints prints;

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    ll N, C, K;
    cin >> N >> C >> K;
    Vl T(N);
    for (ll i = 0; i < N; i++) {
        cin >> T[i];
    }
    sort(T.begin(), T.end());
    ll ans = 0;
    ll tb = -1;
    ll cnt = 0;
    for (ll i = 0; i < N; i++) {
        if (tb < T[i] || cnt >= C) {
            ++ans;
            tb = T[i] + K;
            cnt = 1;
        }
        else {
            ++cnt;
        }
    }
    prints()(ans);
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    cout << setprecision(18) << fixed;
    solve();
    cout << flush;
    return 0;
}

Measured memory_bytes: 3992
#include<bits/stdc++.h>
using namespace std;
#define INFTY 1<<20
typedef long long int ll;
const int MOD=1000000007;
using Graph = vector<vector<int>>;
#define rep(i,n) for (int i = 0; i < (n); ++i)
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main(){
  string s;cin>>s;
  int n = s.length();
  int c0=0,c1=0;
  rep(i,n){
    if(s[i]=='1')c1++;
    else c0++;
  }
  int ans= min(c0,c1);
  cout<<ans*2;
  return 0;
}

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

int main(){
  int N,X;
  cin>>N>>X;
  vector<int> m(N);
  int i;
  
  for(i=0;i<N;i++){
   cin>>m[i];
  }
  
  int min=m[0];
  
  for(i=0;i<N;i++){
    X-=m[i];
    if(m[i]<min){
      min=m[i];
    }
  }
  
  int count=0;
  while(X>=min){
    X-=min;
    count++;
  }
  cout<<N+count<<endl;
}
  
  


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

int main() {
  int N;
  scanf ("%d " ,&N );
  vector<int64_t> A(N+1);
  A.at(0) = 2;
  A.at(1) = 1;
  
  for (int i = 0; i < N - 1; i++ ) {
    A.at(i + 2) = A.at(i + 1) + A.at(i);
  }
  
  printf("%lld \n ", A.at(N));
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>
#include <cmath>
#include <stack>
#include <random>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());



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

  ll n, a, b, c, d, e;
  cin >> n >> a >> b >> c >> d >> e;
  ll mi = a;
  chmin(mi, b);
  chmin(mi, c);
  chmin(mi, d);
  chmin(mi, e);

  ll ans = n/mi;
  if (n%mi) ans++;
  cout << ans+4 << endl;

}


Measured memory_bytes: 256
N = int(input())
X = list(map(int,input().split()))
ans = []
for i in range(min(X),max(X)+1):
    cnt = 0
    for j in X:
        cnt += (j-i)**2
    ans.append(cnt)#少なくとも1回は追加させるためこの位置にかく
        
print(min(ans))            
        

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

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

const long long MOD = 1000000007;

int main(){
  int n;
  string s;
  cin >> n;
  vector<vector<int>> st(n,vector<int>(10,0));
  vector<string> x(n);
  rep(i,n){
    cin >> s;
    rep(j,10){
      st.at(i).at(j) = s.at(j)-'a';
    }
    sort(st.at(i).begin(),st.at(i).end());
    string t;
    rep(j,10){
      if(st.at(i).at(j)<10) t = t + to_string(0) + to_string(st.at(i).at(j));
      else t = t + to_string(st.at(i).at(j));
    }
    x.at(i) = t;
    //cout << t << endl;
  }
  sort(x.begin(),x.end());
  //rep(i,n) cout << x.at(i) << endl;
  ll ans=0,a=0,l=1;
  for(int i=0;i<n-1;i++){
    if(x.at(i+1)==x.at(a) && i!=n-2){
      l++;
      continue;
    }
    else{
      if(i==n-2 && x.at(i+1)==x.at(a)) l++; 
      a=i+1;
      if(l==2) ans+=1;
      else if(l>2) ans+=l*(l-1)/2;
      l=1;
    }
    //cout << l << endl;
  }
  cout << ans << endl;
}


Measured memory_bytes: 14464
#include <bits/stdc++.h>
#include <vector>
using namespace std;
 
int main(){
  int n,z=0;
  cin >> n;
  
  vector<long long> a(n);
  for(int i=0;i<n;i++){
    cin >> a.at(i);
    if(a.at(i)==0) z++;
  }if(z>0){
    cout<<0<<endl;
    return 0;
  }
  long long sum=1;
  for(int i=0;i<n;i++){
  if( a[i]<= (1000000000000000000/sum)) {
    sum *= a.at(i);
  }else  {
    cout << -1 << endl;
    return 0;
  }
  }
  cout << sum << endl; 
  return 0;
}

Measured memory_bytes: 3992
//125 2020.3.19 
#include<iostream>
using namespace std;
int main ()
{ 
	int n,v[50],c[50],ba=0;
	cin>>n;
	for(int t=0;t<n;t++)
	{ 
		cin>>v[t];
	} 	
	for(int t=0;t<n;t++)
	{ 
		cin>>c[t];
	} 
	for(int t=0;t<n;t++)
	{ 
		if(c[t]<v[t])
			ba=ba+v[t]-c[t];
	} 
	cout<<ba;
	return 0;
} 

Measured memory_bytes: 256
#include<iostream>
#include<cctype>
#include<cstdio>
using namespace std;

int main(){
  char ch;
  char seq[1200];

  for(int i = 0; i<1200; i++){
    scanf("%c", &ch);
    if(islower(ch)){
      printf("%c", toupper(ch));
    }
    else if(isupper(ch)){
      printf("%c", tolower(ch));
    }
    else{
      printf("%c", ch);
    }
    if (ch == '\n') break;
  }



  /*
  for(int i = 0; i<1200; i++){
    if(islower(ch)){
      cout << toupper(ch);
    }
    else if(isupper(ch)){
      cout << tolower(ch);
    }
    else{
      cout << ch;
    }
  }
  */


  return 0;
}

Measured memory_bytes: 3108
#include<stdio.h>

int main(){
  int i,j,key,nq,ns,as[10000],aq[500],c=0;

  scanf("%d",&ns);
  for(i=0;i<ns;i++) scanf("%d",&as[i]);
  
  scanf("%d",&nq);
  for(i=0;i<nq;i++) scanf("%d",&aq[i]);

  for(j=0;j<nq;j++){
    as[ns]=key=aq[j];
    for(i=0;as[i]!=key;i++){}
    if(i!=ns) c++;
  }

  printf("%d\n",c);

  return 0;
}
  
  



Measured memory_bytes: 2108
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>

using namespace std;

int dp[1000][1000] = {};
int INF = 999999999;

int main(){
	int N, M;
	int D[1000] = {}, C[1000] = {};
	cin >> N >> M;
	for (int i = 0; i < N; i++){
		cin >> D[i];
	}
	for (int i = 0; i < M; i++){
		cin >> C[i];
	}

	for (int i = 0; i <= N; i++){
		for (int j = i; j <= M; j++){
			if (i == 0 || j == 0) dp[i][j] = 0;
			else{
				int tmp1 = INF;
				for (int k = i-1; k < j; k++){
					int tmp2 = dp[i-1][k];
					if (tmp1>tmp2){
						tmp1 = tmp2;
					}
				}
				if (tmp1 == INF) tmp1 = 0;
				dp[i][j] = tmp1+(C[j-1]*D[i-1]);
			}
		}
	}
	/*
	for (int i = 0; i <= N; i++){
		for (int j = 0; j <= M; j++){
			cout << dp[i][j] << " ";
		}
		cout << endl;
	}
	*/

	int tmp = INF;
	for (int i = 0; i <= M; i++){
		if (tmp > dp[N][i]&& dp[N][i]!=0)tmp = dp[N][i];
	}

	cout << tmp << endl;
	
}

Measured memory_bytes: 6212
def d_maze_master(INF=float('inf')):
    from collections import deque
    H, W = [int(i) for i in input().split()]
    Maze = [list(input()) for _ in range(H)]

    def bfs(start_row, start_col):
        """迷路の (start_row, start_col) マスから最も遠いマスへの移動回数"""
        diff = ((-1, 0), (0, 1), (1, 0), (0, -1))

        def is_inside(row, col):
            return 0 <= row < H and 0 <= col < W

        queue = deque([(start_row, start_col)])
        dist = [[INF for _ in range(W)] for _ in range(H)]
        dist[start_row][start_col] = 0
        while queue:
            row, col = queue.pop()
            for dr, dc in diff:
                nr, nc = row + dr, col + dc
                if is_inside(nr, nc) and Maze[nr][nc] != '#' and dist[nr][nc] == INF:
                    queue.appendleft((nr, nc))
                    dist[nr][nc] = dist[row][col] + 1
        ret = -1
        for row in range(H):
            for col in range(W):
                if dist[row][col] != INF:
                    ret = max(ret, dist[row][col])
        return ret

    ans = 0
    for start_row in range(H):
        for start_col in range(W):
            if Maze[start_row][start_col] != '#':
                ans = max(ans, bfs(start_row, start_col))
    return ans

print(d_maze_master())

Measured memory_bytes: 3316
import java.util.HashSet;
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        var scaner = new Scanner(System.in);

        var x = scaner.nextInt();
        var n = scaner.nextInt();

        var set = new HashSet<>();
        for (int i = 0; i < n; i++) {
            set.add(scaner.nextInt());
        }
        var ans = x;
        for (int i = 0; i < 101; i++) {
            var up = x+i;
            var down = x-i;
            if (!set.contains(down)) {
                ans = down;
                break;
            }
            if (!set.contains(up)) {
                ans = up;
                break;
            }

        }

        System.out.println(ans);

        scaner.close();
    }

}


Measured memory_bytes: 35892
s = input()
if s == "RRR":
  print(3)
elif s == "SSS":
  print(0)
elif s[0] == "R" and s[1] == "R":
  print(2)
elif s[2] == "R" and s[1] == "R":
  print(2)
else:
  print(1)

Measured memory_bytes: 8796
#include<stdio.h>

int main() {
	int a, b, sum, digit;

	while (scanf("%d %d", &a, &b)!=EOF) {
		digit = 0;
		sum = a + b;
		while (sum > 0) {
			sum /= 10;
			digit++;
		}
		printf("%d\n", digit);
	}

	return 0;
}

Measured memory_bytes: 600
def main():
    class UnionFind:
        def __init__(self, N):
            """
            N:要素数
            root:各要素の親要素の番号を格納するリスト.
                ただし, root[x] < 0 ならその頂点が根で-root[x]が木の要素数.
            rank:ランク
            """
            self.N = N
            self.root = [-1] * N
            self.rank = [0] * N

        def find(self, x):
            """頂点xの根を見つける"""
            if self.root[x] < 0:
                return x
            else:
                while self.root[x] >= 0:
                    x = self.root[x]
                return x

        def union(self, x, y):
            """x,yが属する木をunion"""
            # 根を比較する
            # すでに同じ木に属していた場合は何もしない.
            # 違う木に属していた場合はrankを見てくっつける方を決める.
            # rankが同じ時はrankを1増やす
            x = self.find(x)
            y = self.find(y)
            if x == y:
                return
            elif self.rank[x] > self.rank[y]:
                self.root[x] += self.root[y]
                self.root[y] = x
            else:
                self.root[y] += self.root[x]
                self.root[x] = y
                if self.rank[x] == self.rank[y]:
                    self.rank[y] += 1

        def same(self, x, y):
            """xとyが同じグループに属するかどうか"""
            return self.find(x) == self.find(y)

    import sys
    n, q = map(int, sys.stdin.buffer.readline().split())
    uf = UnionFind(n)
    for _ in range(q):
        t, u, v = map(int, sys.stdin.buffer.readline().split())
        if t:
            print(int(uf.same(u, v)))
        else:
            uf.union(u, v)


main()


Measured memory_bytes: 75708
#pragma region include
#include <stdio.h>
#include <string>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <map>
#include <set>
#pragma endregion
using namespace std;

#pragma region 定数
#define INF_VAL (2147483647 - 1)
#define INF_VAL_MINUS -INFVAL
#pragma endregion

#pragma region マクロ
// 配列の長さを取得する(ただし関数内ではポインタサイズに注意)
#define SIZE_OF_ARRAY(array) sizeof(array) / sizeof(*array)

// for文
#define forn(i, size) for (long long(i) = 0; (i) < (size); (i)++)
#define for0(size) for (long(i) = 0; (i) < (size); (i)++)

// ソート
#define Sort(array, length) sort(array, array + length)
#define SortDESC(array, length) sort(array, array + length, greater<>())

// 配列の最大値、最小値取得
#define MAX_OF_ARRAY(array, length) *max_element(array, array + length)
#define MIN_OF_ARRAY(array, length) *min_element(array, array + length)

// 結果出力系
#define YES                    \
    {                          \
        cout << "YES" << endl; \
        return 0;              \
    }
#define NO                    \
    {                         \
        cout << "NO" << endl; \
        return 0;             \
    }
#define Yes                    \
    {                          \
        cout << "Yes" << endl; \
        return 0;              \
    }
#define No                    \
    {                         \
        cout << "No" << endl; \
        return 0;             \
    }
#pragma endregion

#pragma region Utility
#pragma region 配列要素の合計値を取得
template <typename T>
T getSum(T array[], int length)
{
    T sum = 0;
    for (int i = 0; i < length; i++)
    {
        sum += array[i];
    }
    return sum;
}
#pragma endregion

#pragma region ToString(int)
string ToString(int i)
{
    char buffer[1000];
    sprintf(buffer, "%d", i);
    return string(buffer);
}
#pragma endregion

#pragma region 10進数からN進数(<= 10) へ変換
string convertToN(long n, int base)
{
    string ans = "";
    while (n != 0)
    {
        int temp = n % base; // 1桁取得
        ans = ToString(temp) + ans;
        n /= base;
    }
    return ans;
}
#pragma endregion
#pragma endregion

int main()
{
    // 標準入力から値を取得
    string S, T, U;
    int A, B;
    cin >> S >> T;
    scanf("%d %d", &A, &B);
    cin >> U;

    if (S == U)
    {
        A--;
    }
    else
    {
        B--;
    }
    
    // 結果出力
    //printf("%s %s\n", S.c_str(), T.c_str());
    printf("%d %d\n", A, B);
    //printf("%s\n", U.c_str());
}


Measured memory_bytes: 256